全球FlexSim系统仿真中文论坛

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

作者: zorsite    时间: 2013-9-12 13:51
标题: flexsim代码区起始部位代码解析
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
* a9 d/ `2 c4 }- W  l: k
9 N+ N" ~" k% D$ X1 U/ y在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    , ^  Q1 C; P/ K/ t" C
  2. treenode item = parnode(1);
    : k' }+ |, i. O" r' s( i
  3. int port = parval(2);
复制代码
 ; l! b+ e6 u8 w8 G1 O
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。8 G, R4 y8 h# d5 A2 b
在接下来的代码中可以直接引用这三个已经声明好了的变量。
7 _. S8 J) P% y4 W对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。" m& E+ ]4 u# {# L( u3 P
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。: G6 }1 `! N6 X3 F2 ~  r/ F( M; b6 M. _
  o( ]3 \" f! `
treenode! k* n6 y) f& v. m
Variable Types
. z' ]# W% w8 ^' r0 A6 ]Flexsim 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.
  @5 I  p# |# q* V; M. T6 m  u" XType Description + [# E' ^* T2 ]! u. I
int  integer type  * N+ r% Y& N8 a3 q& X
double  double precision floating point type  , H4 @$ [5 X3 V+ x/ _1 w7 O
string  text string  3 ?6 W) F. G8 W1 A2 i8 v/ m
treenode  reference to a Flexsim node or object  ' x+ }* b3 c1 Z  N
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。5 \, U' S- s4 n+ G/ E
: k  n5 g4 E/ N$ \; K3 L1 j
current<no parentheses> 1 g* i; e- J5 D/ ^# j
Description:  : K0 ]( Q$ P+ e! q: v
Deprecated. 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. 7 }1 u0 ^1 {4 `0 L- s! e
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
0 C3 u9 o3 d/ `, m不解:
# o/ ~8 ~) b) B, T9 L. {4 h1.used...with....是什么意思?
1 Q6 r4 K; C. R! c/ R/ c0 u; v以前current是必须和setcurrent一起使用的吗?
* z2 }! b' M- j$ o" w" P! n' x* Y) l/ [7 v6 T
2.as any other variable type是什么意思?
; E2 U2 x7 f0 J) r$ G前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

! I5 t  P: ]' i" P, F2 `Example: * O$ F4 W3 ?& k$ B) @& r& J* z
  1. treenode current = rank(model(),3);; K! Y- n1 j0 m% ]$ k
  2. pt(getname(current));
复制代码
 , k, x5 s! y) {) G! w
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  0 Z. z! T, k; P) o3 }# c9 m, k

! O& ^' e( \) Z7 `. A9 t& U7 h5 ]$ ]! {, d. }7 {6 N) x, Z% ]3 ?
ownerobject(node thenode)* ^+ t# ]; a6 d( Z9 E
Description:. b: \; P6 W4 l; n! @
This 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.
( d4 |+ |0 H2 yThis 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./ z6 E* j: B$ I9 ?5 B0 g) H% X, G
该函数返回参数节点所在的实体。
3 t9 m5 M; L8 v( T& {' f2 j6 K$ d% t/ A- D, X- ~
Example: . x% S  N+ T' k6 x) v+ A
  1. string objname = getname(ownerobject(c));
复制代码
 : p! W9 I& B9 `) D& u
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);
复制代码
 2 S) o! Y6 _- U1 G0 ~& x
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
8 i/ m" k/ ^  U) i! o这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。  T) E1 C% C# g! G  v
2 k* V+ e2 U* ?. ^' O
c<no parentheses>
  _- a7 m& W& n: K8 Y0 uDescription:  * v/ B8 H1 G% A4 c8 z! R
This command is used to reference the active node during a function's execution.
6 s6 @0 f& g2 NIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.; r8 {0 t. |+ U3 e, h6 e, d) x
If the function is an event function, c returns a reference to the object that contains the event. 1 r1 Y8 b+ G3 C* u. k& V
c在函数执行的过程中指向活动实体。9 v# F, i8 |5 K+ i
如果是节点型函数,c指向函数所在实体,
" f  }# o. ^- e9 |# B. Q. ]如果是事件型函数,c指向事件所在实体。
' w# h' h( z% n0 _Example: 
  1. treenode current = ownerobject(c);
复制代码
 
/ n/ s% Q, w' W, f+ H$ j+ a( Y. J6 X- h
setcurrent(thing)4 z3 k( e8 B9 _$ m4 d- a
Description: Deprecated. Do not use.
% a8 O3 P& S; DExample: /: D! X; A- r+ c1 m- c- i7 x! _
此命令不再使用。9 D  o7 }2 u2 G* l

9 P/ X, U5 ]1 M0 m8 s4 w( v7 jitem<no parentheses>
& l9 L; x5 C, B
Description:  
& ?5 d! \4 o, J  q7 J. JDeprecated. 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.
4 b# ?& s2 A4 n# c! s不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
# Y5 s* r0 W- y, X4 h( _7 `" RExample: 
  1. treenode item = rank(model(),3);5 V# Y. n6 b8 f7 `' g
  2. pt(getname(item));
复制代码
 
  H5 u$ `; v$ `This sets the object that is ranked 3 in the model to item and prints its name to the output console.  6 r3 A$ A, M( Q" K2 T" Z$ M
8 K& |6 d: W) u$ D' J
# R9 u4 t7 f2 F- P/ N: ^8 J. O
setitem(thing)
/ C1 T, F7 e: H8 C. I8 S5 C
Description: Deprecated. Do not use. # k$ Y9 M) V/ B
Example: /& |# G/ k% @1 x! j8 H/ a$ S% y
此命令不再使用。
! l1 J. \+ h' K! T, E
, ^+ ^, c) s  H! U2 xparnode(num index)
/ {- [! W$ l+ Q' G* Q2 b" vDescription:  
& f8 x: e" Z4 I# E1 iThis command is used inside a function that is called by the nodefunction() command.
" [8 ~  H) Y. u$ T- o2 l此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?- y6 [* r' s( Q3 A+ R+ x
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
9 \+ O, O4 e% Z% N1 y, }( ]此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
5 V0 f( ?  l8 |/ g5 O1 j$ M节点和树节点有何不同?: @  b0 \+ G( O6 |3 ?
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
9 S5 O" }( e9 l9 n6 m: i2 O# t4 aparnode,parval,parstr这三个命令真是让人搞不懂啊...
6 I  h6 j/ a2 L6 }! E# W! u- k: uParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
) a0 X) J1 O! I9 p( K$ A9 KExample:
$ W5 f8 J. q8 IIf a trigger/field is called with: ; q- b6 V7 l8 z; v
nodefunction(thefuncnode, item)
5 N1 }% g, k* U1 f9 ]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);
复制代码
  
; b7 A& F* t+ R. l5 g9 V' G5 F+ @7 G" e# y
port<no parentheses>4 b* S1 c7 T5 Y0 o& d8 M
Description: ; ~, E- a* ]* W- j9 \: g/ n
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. * w4 ?, h& i/ R
Example:
* H" K/ ~/ S% }5 j
  1. int port = parval(3);9 y+ Q- w# z2 q4 w; m3 W0 m  r1 T) }
  2. pd(port);
复制代码
 
( O! b: ]8 ?: I) V9 i, W/ nThis sets port to parval(3) and then prints the value to the output console.
+ `& G/ Z) P0 T: q. m) N* q0 s' }# U- ]/ j3 V2 [8 M3 ~
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
作者: 天性518    时间: 2013-9-17 13:56
1# zorsite
9 W% j/ F9 ?; s; m& Z- ?4 r0 K- V6 `# \7 S7 A

! l+ o; R7 U+ x! V首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。! }, a/ R4 o, m; [' Q1 j2 ^
    首先在GUI中,它是这样的,如下图:[attach]1559[/attach]
! ~. b3 X' n" w3 o" k, ~% O3 m6 r而在代码框中却是这样的,如下图:[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