全球FlexSim系统仿真中文论坛

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

作者: zorsite    时间: 2013-9-12 13:51
标题: flexsim代码区起始部位代码解析
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
0 l$ k/ b' K8 R* D) @* m( i- r& t& s8 l
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);" V! G7 z- P( r  s- p
  2. treenode item = parnode(1);* r0 I2 u$ b( }
  3. int port = parval(2);
复制代码
 ) u0 \+ Z$ w+ U, H
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。. ~7 q$ [/ o5 |9 {6 v
在接下来的代码中可以直接引用这三个已经声明好了的变量。
5 t* o, l2 M8 Y% `0 }对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
* f# {4 X! r2 ^0 m1 z; Q下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。( v/ {0 ^+ ~/ {* U
- g8 f- P: V0 W) p% s0 T
treenode- G/ ]( z4 x. {6 S8 h- R/ m
Variable Types
# ^. i: l1 q& r6 b2 q2 e" g, sFlexsim 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 P4 O3 y! [  l0 F3 D' y! ]9 Q8 uType Description 8 x! Q/ k* C% W
int  integer type  0 T% V+ D* ]6 l: q# R
double  double precision floating point type  3 R2 X7 |8 ?/ s" D! P' ~& G
string  text string  ( G( D# R* l; z' h- r# p
treenode  reference to a Flexsim node or object  1 C4 M* t% Q/ C7 v4 E- a* w( y
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
  i- Z2 A/ B) \( t1 n* q' u
4 o( H, p! A+ G9 ^. Gcurrent<no parentheses>
  \- ?! g6 N+ F2 _Description:  
. F1 E) q: m) P% e/ x  BDeprecated. 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.
$ z' d2 C! [* [/ r5 p# d不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
) r1 c& P9 O  `* F/ |  N/ N不解:
. P  E0 V! v8 Y. K2 D. j1.used...with....是什么意思?
7 a" t7 F3 a6 O1 q! _. s& j  e/ T以前current是必须和setcurrent一起使用的吗?7 V! A% z! V+ r8 ?
* F! x$ X4 e5 L. D6 E
2.as any other variable type是什么意思?% n% C4 E% D/ [1 q8 {9 A1 p1 s
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

8 a. T! _! d  A% k: E$ \) S" }Example:
6 \5 F) ~; n- [& Y9 k6 P' q" b
  1. treenode current = rank(model(),3);( p$ T2 y& b+ H9 \" b
  2. pt(getname(current));
复制代码
 ( J3 U- m  H& }, k3 c+ d' Y
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  9 P; X4 \5 L9 v+ S5 K/ I; X# ~

# S, v0 j5 S7 n, Y. r3 H( [: s) T, D9 D4 H0 Q: X0 H
ownerobject(node thenode)
( h& H* V7 y& F4 a1 ^3 \, ^
Description:) G; F+ w  }. ], B) @/ \( `" p/ L
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.
7 r8 n8 ~5 \* o5 i2 u( j0 C; G! U+ ~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.
9 J8 x. v+ T0 k' p5 b该函数返回参数节点所在的实体。
- B+ w" P' e0 a" h, i% v2 D) f" v
% `6 n6 M$ C4 q7 i/ U) s- VExample:
5 m5 M; S' E* u8 c+ {
  1. string objname = getname(ownerobject(c));
复制代码
 7 _( Q% e) v1 c
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);
复制代码
 % G; \) {3 v, |; O( f* \/ i; n/ x2 F
This example is present in most code fields in Flexsim, and retrieves access to the "current" object./ p5 O/ \) q! r% z/ L
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。9 c  u- x  v9 M* W

( }% A/ B4 U5 G# G2 O/ l7 ]c<no parentheses>
" n! X, x, V+ i2 d( X0 b7 KDescription:  
# S3 z2 {9 w: n7 W: |& sThis command is used to reference the active node during a function's execution. - O- k/ p8 u  O- R  d
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
( Z, Q1 p9 O+ F- |" H) U- O# O! WIf the function is an event function, c returns a reference to the object that contains the event.
) ~! {: h8 _7 c$ [' c  qc在函数执行的过程中指向活动实体。$ G, R- V/ Z9 ~. @' p0 I
如果是节点型函数,c指向函数所在实体,8 f8 N& \7 P0 L$ f- x
如果是事件型函数,c指向事件所在实体。2 O$ a0 e' e2 W( L7 y
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
2 z; g8 l0 y! Q3 D8 [
' x. @% ~2 n$ d8 `+ W- esetcurrent(thing)
: W2 q  ?# p; x
Description: Deprecated. Do not use.
" J, C2 m( n& dExample: /
+ w6 _4 F* J1 S) r9 y! m  X此命令不再使用。2 c) U7 s$ e3 E

0 g7 N' R. J7 I$ [6 w5 bitem<no parentheses>
0 \( T7 M! g/ d* z; Z& i, m% T
Description:  / {9 S- t5 C  v7 W) e. w% M
Deprecated. 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. . u: R$ V& m( {1 _1 [
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
% ^" j2 c- M' c& vExample: 
  1. treenode item = rank(model(),3);3 K" L) G( Z; N. a
  2. pt(getname(item));
复制代码
 4 b# g6 a. `3 T) e0 m
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
0 O/ Y7 }  [  d- m3 ~: i2 L$ _' w, s8 c1 v9 i2 q$ w  `4 W
' A' }1 C+ W0 i/ P, d; @
setitem(thing)6 ]& Y5 g6 Q: q9 G+ Z8 A
Description: Deprecated. Do not use. 1 M  ?4 U8 b; K8 i5 _8 O& C
Example: /! ]7 u2 X+ g- n. Q5 }' y5 C
此命令不再使用。
1 ]0 q! Q( U  _" M/ D+ O
0 J: C# @) s6 K; p- r  G. }parnode(num index)
8 }! b) k8 v, q( Z. wDescription:  
' L- A. a) b* ~% X1 y0 y% `This command is used inside a function that is called by the nodefunction() command.
3 |* o- P% {  z7 v2 D此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
  l5 L1 G4 {/ _! _5 r+ W: W% SIt returns the parameter passed to nodefunction specified by index as a node (or treenode).
: y  @' c2 P3 S# w, p此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
* {  u3 V6 q2 c5 @节点和树节点有何不同?
3 B8 H, h+ v+ }! X  FThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
/ s, u% P5 K, P/ X: |4 Wparnode,parval,parstr这三个命令真是让人搞不懂啊...
- l8 E9 f  K* H# [0 C/ VParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. + Q' `$ m# d& }3 n; ^: w3 u% U  K
Example:
; X' o6 A' U5 vIf a trigger/field is called with:
5 y# ]' i: T- c, }3 e9 t8 {6 y# xnodefunction(thefuncnode, item)5 a+ L4 l; E, T$ _; _
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);
复制代码
  
" Q7 F  P+ {0 p% [# ?9 K; z3 k( M4 P5 r1 |' z& u
port<no parentheses>
( ?0 E4 k$ Q! ~' cDescription: ! }8 I: \$ E( m# K7 r9 o% U2 F0 _
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. 2 p) z& Z  N9 _: O
Example:( U  T/ X' U, \; k0 o* g/ P) w
  1. int port = parval(3);
    2 |* N. U2 U% v
  2. pd(port);
复制代码
 
3 M2 _' I; ?) c  u- \This sets port to parval(3) and then prints the value to the output console." E/ O' t. E5 m! c
* f0 s! P6 V5 K
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
作者: 天性518    时间: 2013-9-17 13:56
1# zorsite
" J4 L& K/ t% s% x) n; x3 R4 {
6 Z4 P) H; g% f* V
, r' f* j& A8 K: Y& g- T首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。6 l2 f8 D5 i/ t- y  k
    首先在GUI中,它是这样的,如下图:[attach]1559[/attach]. D$ W( g3 S  f+ J. A; k: G1 z
而在代码框中却是这样的,如下图:[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