全球FlexSim系统仿真中文论坛

搜索
查看: 7751|回复: 4
打印 上一主题 下一主题

flexsim代码区起始部位代码解析

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 % e' r1 k- m" D  ~$ K

* p6 i  W9 @4 j' A( _5 _- P9 G  P在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    + v; ~6 f5 m+ ]' H5 N2 `
  2. treenode item = parnode(1);
    7 I6 K" W% E9 u& a% p8 A1 T
  3. int port = parval(2);
复制代码
   C5 j! Y: [# ?1 U* X
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
& u3 ]" z7 n( |1 o+ r8 h7 l! J在接下来的代码中可以直接引用这三个已经声明好了的变量。9 d' y! T! h" O% R) _. H
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。1 n# i5 i4 {- ]- [. z' ^% F
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
# u3 U0 ?# ]' p) I/ T7 K; `" e3 |7 [( c5 @: D
treenode
/ ]3 ]+ ~* @8 b6 z7 R( E, lVariable Types
! ~# f7 f' R6 N, Y9 S1 \3 u+ hFlexsim 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.8 p: H. B: C( w2 H( ], o
Type Description $ {) T  W0 z: \2 H
int  integer type  , o6 L# C. c9 Z0 k6 C
double  double precision floating point type  ; [8 t8 L' O9 x/ ~# w+ o/ C) k: e
string  text string  
0 s' V) l8 A9 Otreenode  reference to a Flexsim node or object  $ Y: j! _5 M3 w4 V8 o
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
! T7 L, g8 w8 o) H/ |4 S3 m  S0 T1 J0 P
current<no parentheses> 9 Z8 c0 R& l6 \" i. t2 O
Description:  
" |, I6 ?1 `; PDeprecated. 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.
* s0 E* w# h5 a2 I9 Y3 f$ z& K% L不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。+ J$ F/ I4 K8 B3 [, B9 E
不解:
- \- [; W7 `7 q7 L( T! E1.used...with....是什么意思?! G6 v/ O, y  P: [
以前current是必须和setcurrent一起使用的吗?, N  s4 P. A) L% z3 o, t
' k5 k+ m3 L, ~' w" Y
2.as any other variable type是什么意思?+ O1 V' C' K$ Z+ s. {# G) ~! x
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

9 V. `) r6 d$ }8 W" D7 ?Example:
7 o1 ]  Z) f, \6 Y' J, u3 N
  1. treenode current = rank(model(),3);
    , r$ ^7 g; ?7 m) C! {
  2. pt(getname(current));
复制代码
 2 f1 O' |& G. f2 @( M: @- H6 W
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  : N9 u) H$ h3 t8 O0 f" D( w# z7 X
, k! A* Y2 z1 l, ?9 @
7 ?  [5 b6 \' w+ f$ z
ownerobject(node thenode)
0 S- `/ x$ U" m  G
Description:
  R: U1 ~) x( U2 `" qThis 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.. B5 M1 C1 G% ~* F' c1 @) 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 i  X, z+ ~& K" c该函数返回参数节点所在的实体。
- y. M7 a  e% m9 _) R, D% d' V; S- |1 r$ R: {/ L9 q6 `! K  g& Z
Example:
# ]& i: P5 L+ M8 g# G
  1. string objname = getname(ownerobject(c));
复制代码
   \3 Q) M' o2 M) O0 Z4 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);
复制代码
 
  X$ }: P- E- q  WThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.: R5 }. v; d: f9 U8 ~
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。! A1 g& b% P4 ~% _" f
6 n  ~& |$ h1 m: g. P
c<no parentheses>
5 x% e) W7 V+ Y: a( W  |/ n2 lDescription:  + ~2 X  E: {7 {6 o, K  N  M1 y! m
This command is used to reference the active node during a function's execution. 8 W" _2 E" ^+ b; L' }/ I
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.$ c" ]# \. ^" C0 V( i
If the function is an event function, c returns a reference to the object that contains the event. / h& z; F& l: X+ {
c在函数执行的过程中指向活动实体。
; n4 y+ \! {6 j如果是节点型函数,c指向函数所在实体,
% m1 |3 a8 }$ L* w如果是事件型函数,c指向事件所在实体。5 @# K/ S" z, z' }# P/ Z/ F- s6 V
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
8 u) `: D8 {, E5 P1 C
- \  ?* u5 x* h5 Z: j1 csetcurrent(thing)* u/ g: v8 y+ W: ]3 ^0 g( d
Description: Deprecated. Do not use.
  c, Q/ ?# Y& _' iExample: /
/ t; I  w5 t0 E( v+ A& E此命令不再使用。
9 s! N  A  ^7 p/ W  @) ]* j; L6 H) A5 X7 |$ p; p1 u% ^5 k1 W
item<no parentheses>
8 Y* I" W6 \! J3 h2 a9 H
Description:  
* `3 g) W2 b& m! l! ~( f2 ODeprecated. 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.
, b* T# G* M: J3 M8 v" T不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
  D: G$ K: o$ Z8 T; N# P$ KExample: 
  1. treenode item = rank(model(),3);) D! x' A- T$ V9 E1 Z, D0 _
  2. pt(getname(item));
复制代码
 3 @4 o' w  k) ?! f
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
# }2 m, P& o- B2 c, Z  e- Y1 T: c- {

( d) E4 x3 z+ Q, M% P3 gsetitem(thing)
6 p, M' w* m0 h# l
Description: Deprecated. Do not use. 2 _0 X# G9 v+ B* x  A* q& {; K
Example: /
5 E- |6 ^0 b& E此命令不再使用。
% }' s9 t( i% @( m- o$ P( Y& H
6 \" }' ?3 W5 g" T( h0 J3 ?! w9 mparnode(num index) . {5 C' Z% g0 B3 q
Description:  
9 I- Q7 [, V) E& NThis command is used inside a function that is called by the nodefunction() command.
* |: [6 s' _6 f  ]( p此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
, v# O8 e  Z2 a8 bIt returns the parameter passed to nodefunction specified by index as a node (or treenode).
) ~/ @+ r& c5 @4 H4 Q2 B2 L此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.( G% l* |5 Q6 b. ^
节点和树节点有何不同?
) o: H3 N3 l. D* {, GThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.( s8 Z$ |6 H8 X& Y7 J& f
parnode,parval,parstr这三个命令真是让人搞不懂啊...
' j( l$ ]( _  ?/ \- M1 GParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
5 t6 b9 a4 w, `# u1 UExample:
; o; m% K; r5 ]1 @2 g4 J4 zIf a trigger/field is called with: - R9 B! h# b+ v- {; z8 f
nodefunction(thefuncnode, item)  A2 k0 a/ E) T) m9 N3 Y7 \9 ?
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);
复制代码
  5 T3 U+ \, h. v! \6 l. y
- g# }+ Q( R# W: s0 i' C
port<no parentheses>9 c& B: K4 a+ T2 R% \4 K
Description:
8 _) X0 K5 f! L' k5 `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.
( z4 t8 r+ S9 W) g1 N) K) QExample:, K( j, Y8 f" l8 Q5 R. |% m
  1. int port = parval(3);
    ! q/ q- z8 M& u2 K" f* d
  2. pd(port);
复制代码
 
. n1 B7 J9 i7 U( S4 w7 hThis sets port to parval(3) and then prints the value to the output console.8 b- v4 A. w8 J% O# L# n7 y: I

4 A, l% N! @' j不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite - W  q0 W5 D3 F# @3 {; M

' x6 x: r; s& _" U% P2 A5 ?6 w# v
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。0 b' j+ c: k6 h- ~0 A
    首先在GUI中,它是这样的,如下图:) W" g+ [! e( o6 F- o9 h
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
3#
fl2014 发表于 2014-8-10 18:29:45 | 只看该作者
大神啊,解决了我多日的困惑
4#
1010265352 发表于 2014-8-11 13:56:35 | 只看该作者
额,很值得一看
5#
一骑绝尘 发表于 2014-8-20 10:01:35 | 只看该作者
C 一扫疑惑,  但parval(),parnode() 还是有点不解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|全球FlexSim系统仿真中文论坛 ( 京ICP备14043114号-2 )

GMT+8, 2025-7-16 05:19 , Processed in 0.080326 second(s), 15 queries .

Powered by Discuz! X3.3© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表