全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
) L0 t- D" Q, [5 |. h
" V1 i9 V$ u& [" K: Z/ M, a+ C6 i; L" p在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    5 h- q, U) Z- a& v' R6 O8 H! k, B8 s
  2. treenode item = parnode(1);
    - K" z- j# s0 I
  3. int port = parval(2);
复制代码
 
8 h1 {$ J' m' @: r意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
7 v5 t8 m! e' W: i" V( C在接下来的代码中可以直接引用这三个已经声明好了的变量。
! P7 S! K4 h4 e: {1 _对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。7 m% V% K0 p# ^) ~
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
7 K' ^" {' Z' K2 R8 h6 t0 d* m- C
treenode
; L/ ?; _0 {8 a* ZVariable Types
2 w6 D  F9 M+ o. z1 w6 AFlexsim 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.
+ R$ ?- G9 A: [8 B, u/ Y+ O' R$ c7 o% nType Description
, d. D$ U. x! L+ m& S# w- f+ L2 jint  integer type  & H) [! S. e- G
double  double precision floating point type  
! x7 U4 _6 \0 I1 F7 {. P( sstring  text string  
1 I" {' Z8 P8 ~) S" Ktreenode  reference to a Flexsim node or object  " p: l/ l: s3 B$ z8 K# Y! I
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。2 e. e, e; @, g" U  k+ I

) ]( P- l6 T! ], }0 V( Y: ecurrent<no parentheses>
$ T9 e: K- q7 ~) X+ m$ gDescription:  1 m. u$ ]1 b+ J
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.
+ [# N  G, y$ c3 G- |  m$ j不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。4 S- K  t7 u  T, l; s( r+ H
不解:
* Y/ ~! U: h" F1.used...with....是什么意思?8 C- |  [$ J" P- X1 J
以前current是必须和setcurrent一起使用的吗?
! A, l6 ^! l1 M8 G! t( E8 K2 c2 T. O  n% h
2.as any other variable type是什么意思?8 d! @  y9 j; x
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
4 h6 H; ^5 u9 [) Y$ r0 f$ O
Example: 4 O3 g, |, h! n- |! x
  1. treenode current = rank(model(),3);
    0 ?8 {- K. j/ |
  2. pt(getname(current));
复制代码
 
+ E0 h- @! I, L2 j% _5 T% z1 dThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  
- w/ {. |3 q/ t! S+ x" P) ~/ c7 f" b. i; A8 ~

3 l" x4 j9 A9 S+ m# C8 f( Wownerobject(node thenode)% ]$ M/ g, d8 \& q3 a0 t
Description:& g, `7 m1 y' ]& n' S: b
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.$ t6 B) Q9 U! R3 c) H) V" I
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./ q' p. R2 F; l& f2 Q5 c* y) A* m
该函数返回参数节点所在的实体。- i# K) C2 l. v& z1 M7 ?  `

1 w7 j* Y+ \$ u8 o3 WExample: 2 ^) W# K/ V# ?5 \, ~+ k1 a
  1. string objname = getname(ownerobject(c));
复制代码
 
! }, S: W6 p7 a) x" GThis 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);
复制代码
 
; {- Y& M4 d7 v( `9 [8 yThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.8 p- Y% y% E8 j6 }( t; v2 G
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。  E* f$ ~$ u4 s4 M& \

2 s" e9 }9 `! c* K+ P8 R$ `8 \  u6 Lc<no parentheses>
* q4 q; n' ?1 k1 \Description:  
. X4 T; w8 O8 ?This command is used to reference the active node during a function's execution.
- j5 r  O- z6 y- \) B, q2 D. kIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.4 d8 n5 V% g; K, n9 a
If the function is an event function, c returns a reference to the object that contains the event. 4 }6 W  }  S4 f# Z9 `
c在函数执行的过程中指向活动实体。
5 B1 y  |; Y$ z/ c如果是节点型函数,c指向函数所在实体,
/ x* w4 N9 L9 ^4 M$ g0 w/ t4 y9 |如果是事件型函数,c指向事件所在实体。/ w) e+ _: l6 z. y2 B, }1 u
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
) _8 L% B5 {. X7 P$ v5 \) ^! Y0 O/ E! ~1 ~+ O9 t
setcurrent(thing)/ E7 m9 B$ `( S* }
Description: Deprecated. Do not use. . @" Z& x5 i* X
Example: /
; V: }0 @, ]0 E3 d此命令不再使用。. Z, ]2 M2 u- {/ N4 S
1 Q; R$ I" J4 L- ~5 x3 P
item<no parentheses> 9 G1 P& F8 h( a% _4 y( U6 V
Description:  4 U+ J% @* B5 Z- q, G& i9 T% ^# F: ~
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. * e$ |( d0 [+ I; z; D
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。: x2 j7 L  O* w+ b% R
Example: 
  1. treenode item = rank(model(),3);
    , Z+ \* {7 |& Q8 o. B0 I9 \; \
  2. pt(getname(item));
复制代码
 
$ v, _  m# u+ SThis sets the object that is ranked 3 in the model to item and prints its name to the output console.  
% p; ~) I* l5 C$ q& N. b: O5 u4 `" c" K. `

- j1 ]9 M, Z  H5 c6 E: e* Y* esetitem(thing)
4 ~' x# t6 D" ?- L
Description: Deprecated. Do not use. 1 o& g1 C1 l8 T$ Q1 k" ^0 ]* A
Example: /9 W6 b; C; M% i4 |
此命令不再使用。! A0 `% a2 U6 D  B# v' G/ G

1 F  k( ?# s* q0 E3 k. j2 W9 Fparnode(num index) ) @$ p% u1 L# Z* e$ a
Description:  
( M: v2 |( N$ y% @# F& p- i1 VThis command is used inside a function that is called by the nodefunction() command., g( z9 Q7 G4 F8 y3 `6 K! B
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
. {, \9 ?& Q3 F2 j" ]+ M8 C# X5 }It returns the parameter passed to nodefunction specified by index as a node (or treenode). ) R: V1 R. M- q
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
# l- n: L% X- U( y( k# N节点和树节点有何不同?2 g& ?+ R  V! ~7 f* n% ?
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
! [6 b  e- ~2 A: I' ?5 S1 E. W3 Mparnode,parval,parstr这三个命令真是让人搞不懂啊...
3 D! Q5 v& X' q; j* `Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
2 f" J" O/ p8 O! i: K4 A5 H: cExample: 5 d6 C2 k- W0 Y4 r& K( I
If a trigger/field is called with:
, `2 G8 s0 T6 z; {' X% ~nodefunction(thefuncnode, item)5 A! C6 Y4 R# v, {+ x& s
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);
复制代码
  - I( v3 i. A" j

: O. A8 Q4 d5 \/ n; kport<no parentheses>6 F0 `1 \* P$ r0 t" X0 `
Description: 2 X/ D9 [$ y4 E. W( b. _% q
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. 3 h7 Q( t: m/ n0 E# m  w+ Z8 a! G
Example:# g/ K, h9 K$ ^7 C1 a7 D
  1. int port = parval(3);: C; F) E% T( C# l4 @/ K) {7 s4 o' V
  2. pd(port);
复制代码
 2 U1 L5 T2 p  a& o
This sets port to parval(3) and then prints the value to the output console.: i' \. L# J: d7 q/ V

* ?7 H  _0 d: p( l, X, K; ?2 S% P不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite
$ R! T. C( d, g5 n6 p4 o$ Q, ]: x7 D( c. D; m" x
' M6 K' ^* e" j5 h) j0 b
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
) m& \2 Y6 h- ]0 Y4 I    首先在GUI中,它是这样的,如下图:
4 w$ B" A( y  u. d0 M而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-1 04:39 , Processed in 0.071021 second(s), 14 queries .

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

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