全球FlexSim系统仿真中文论坛

标题: flexsim代码区起始部位代码解析 [打印本页]

作者: zorsite    时间: 2013-9-12 13:51
标题: flexsim代码区起始部位代码解析
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
) C' ?$ A* O; w6 @8 @8 w5 L! c; h" O, ~. c( j
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);5 e$ u9 M" q1 B
  2. treenode item = parnode(1);0 [$ G! A1 n& [8 y, {) ~
  3. int port = parval(2);
复制代码
 $ f3 s" \2 v( t4 V4 U! {' n
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。% Q; d) V3 Y1 w
在接下来的代码中可以直接引用这三个已经声明好了的变量。
' d" |, H1 {# R5 w4 z5 n" i1 J对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
. B  i* D; A0 a$ z# K7 e下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。, F( x+ G" \+ w# V- {5 _0 p
3 }& \, ?1 K* T- y& Y/ n
treenode
$ m2 a4 G  O' BVariable Types
! l1 N4 ]4 ?% M7 I- cFlexsim uses just four variable types. Each of the four types can also be used in an array structure. The following explains each of these types." r0 h0 ?6 j( [2 Z$ c0 b: h
Type Description
# Z7 b+ k+ z, |0 T1 zint  integer type  
# O% v) s" L+ k" `- Cdouble  double precision floating point type  
" E% @' p$ t$ K0 {7 e& Y5 q4 Qstring  text string  & Q  @6 w" p  ?: F
treenode  reference to a Flexsim node or object  8 e' Y9 [# D- M6 ^2 D* \
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。. D& N2 I8 F. }( @
0 p5 u) _3 K! f& a" m3 g4 @  e
current<no parentheses>
( ?+ W) l) u) F; I- ?Description:  
& \5 z3 E4 Q) |7 ?$ I* D6 c$ qDeprecated. This should not be used as a special command with the setcurrent command anymore. Instead, declare a treenode variable type as current, then use current in your code as any other variable type.
1 G0 E' M* @6 V! {" h) U不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。& J5 e7 u. Q- {
不解:
# u) a3 w6 ~5 m( {; n# @' o. _1.used...with....是什么意思?
. U3 P: P- c$ ~) \以前current是必须和setcurrent一起使用的吗?  O9 L& K" N, l) i: N

5 O; v+ M+ A; Q# A$ W2.as any other variable type是什么意思?4 m- o' e  _& _6 q& x6 ^
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
6 g  E6 F- @  I5 Y3 [- T) T& ?
Example: ( U6 ]/ o! j6 Q9 [
  1. treenode current = rank(model(),3);' M! n+ d; H% w$ C2 ?+ E% J
  2. pt(getname(current));
复制代码
 7 B1 ^9 W. J# @8 T
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  
2 F, M# h, R; j; D$ h* e5 c; s8 R, k' M
4 t; C! ^  A! |7 b: u
ownerobject(node thenode)
1 O9 }2 |1 o- R& _
Description:
( b3 I3 Z3 G3 p, I8 J' RThis command returns the node with object data attached to it that is the start of the sub-tree that thenode is in. In other words, it returns the object node that contains thenode.6 D# k- U% X4 R
This command is used in most code fields and trigger fields to set the access variable current. In these fields, c references the node that contains the code, and ownerobject(c) references the object that "owns" that node.
" l9 h2 l! G! J1 f. }该函数返回参数节点所在的实体。
9 j; }+ F/ G0 l- w
9 A: x0 R, T% l4 ?' e* o5 tExample:
$ v( E) x/ D" T2 R" a7 H
  1. string objname = getname(ownerobject(c));
复制代码
 ! h4 ^3 {' @+ C8 Q2 L% [
This sets objname to the name of the object that contains the node referenced by c. The c usually refers to the node where the code is being written.   
  1. treenode current = ownerobject(c);
复制代码
 
" _/ v4 v6 F' v. x5 QThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.
% y. m8 U& c, K这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。4 T- o- M0 F% [/ V; W

, Z9 @  t. v* J5 @c<no parentheses>
1 w. D6 i; d4 w& ]Description:  
! |( s- x# f9 R, R0 z6 Y, o4 p1 }This command is used to reference the active node during a function's execution.
0 Y- [  [+ D4 a2 P; y) tIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.5 u# Z  ]& }0 k9 y5 N# O4 j6 o
If the function is an event function, c returns a reference to the object that contains the event.
$ `  `! J6 Y# A; `6 t0 J9 nc在函数执行的过程中指向活动实体。+ ?, `- v- R6 [1 v. z8 ^9 \8 |
如果是节点型函数,c指向函数所在实体,
; ^7 L1 d: J* ]5 _8 P" ]& G如果是事件型函数,c指向事件所在实体。  \* b8 c" l- W1 y: z
Example: 
  1. treenode current = ownerobject(c);
复制代码
 * u/ K. K5 v3 ?6 V

- m( V9 ~" \- ?6 q& A  ~: F0 isetcurrent(thing)" ?+ z! I2 J, ~3 y% E9 m
Description: Deprecated. Do not use. ; s4 K0 S$ o' L; |% D' m. a
Example: /
1 V" T" o4 N3 r. L* \此命令不再使用。% C! F' W& v: f: c

' s% s  Q, e+ L) Qitem<no parentheses>
4 Z: _" l2 v8 x; D
Description:  
, ?, `. y' B" \9 k7 WDeprecated. This should not be used as a special command with the setitem command anymore. Instead, declare a treenode variable type as item, then use item in your code as any other variable type. 2 j! l3 A9 C* d' c% b
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。. M( d1 S$ F( `+ p2 \
Example: 
  1. treenode item = rank(model(),3);2 K2 h# E/ W3 ?0 t0 n
  2. pt(getname(item));
复制代码
 
& N1 F0 u; h8 J1 lThis sets the object that is ranked 3 in the model to item and prints its name to the output console.  ' {! B8 I2 Y6 C: b) ^
( A) _* H% s* |! a9 b3 n  D

* d6 t; _. J5 J! w  s5 U' Nsetitem(thing)5 v5 m% [; r+ R: v
Description: Deprecated. Do not use. 6 e# \" G6 s9 M( u
Example: /
' c! |& W; z# i5 Z此命令不再使用。
8 \  N. R7 V5 t! D& h3 t
. P4 c1 ~' }( t8 Wparnode(num index)
7 D' p  M* i3 }+ g+ [6 ^1 t+ KDescription:  8 t7 `+ B" D! d. S$ [5 y8 \: c& ~: {
This command is used inside a function that is called by the nodefunction() command.; z& B9 T! L) k
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
7 f% I& v8 \8 p3 r* k1 cIt returns the parameter passed to nodefunction specified by index as a node (or treenode). - T& X2 b6 h( ^3 P  [9 `' I
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.3 M6 v8 o3 [8 p$ z& @9 N5 |9 _
节点和树节点有何不同?/ T$ L3 a8 b0 e, T3 N- H7 K) \. |% J
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
" V, @6 |4 X% _3 zparnode,parval,parstr这三个命令真是让人搞不懂啊...
+ J5 Q. s) [3 l; F9 Z' {2 IParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. % m, _/ \' r4 b" S2 G
Example: * @$ x% c5 X" R6 c* B. U2 n+ a& q
If a trigger/field is called with: : U" c' t  E  U7 _/ p& c0 E
nodefunction(thefuncnode, item)+ }: N3 t! {* f; V9 i
then within the trigger/field, getting access to the item passed as the first additional parameter would be done with:
  1. treenode item = parnode(1);
复制代码
  $ n! k& }" h. N6 @# Z
+ J( d8 w! f! L* z$ ^; I$ v
port<no parentheses>
" a1 ?2 b, ^  _! ]Description: 6 ~3 T% |6 X0 Q/ Y4 j; o
Deprecated. This should not be used as a special command with the setport command anymore. Instead, declare an int variable type as port, then use port in your code as any other variable type.
5 r  k! k  B3 B/ w# _1 l. J+ lExample:
* V/ ~) l$ x8 W5 X. Y  R" w6 b
  1. int port = parval(3);
    : _7 g& |; c  Y3 E/ m; R" p2 o
  2. pd(port);
复制代码
 
1 c0 s; E) ?; v, J! VThis sets port to parval(3) and then prints the value to the output console.( l# M$ ]1 M% t  F1 A
" Q. t$ T  V# k8 ?6 s; U
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
作者: 天性518    时间: 2013-9-17 13:56
1# zorsite
3 n3 o  L3 L6 x* y' ]
8 p' a( E! }1 k3 `8 l& `# e3 K1 ?6 E
' R( R7 `, S; q$ `5 ?( O- _首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
( w" @$ y" Q! k$ U  t    首先在GUI中,它是这样的,如下图:[attach]1559[/attach]: I$ v* c. I- F2 U" _
而在代码框中却是这样的,如下图:[attach]1560[/attach]
作者: fl2014    时间: 2014-8-10 18:29
大神啊,解决了我多日的困惑
作者: 1010265352    时间: 2014-8-11 13:56
额,很值得一看
作者: 一骑绝尘    时间: 2014-8-20 10:01
C 一扫疑惑,  但parval(),parnode() 还是有点不解




欢迎光临 全球FlexSim系统仿真中文论坛 (http://www.flexsimasia.com/) Powered by Discuz! X3.3