全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
) F8 q5 x3 j3 d! z8 ^' s' o6 K. |: x" ?! n$ \$ \: g/ c2 v: j; V
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    $ c3 m3 f# j/ H2 Z
  2. treenode item = parnode(1);( N7 c- c2 O( A. n" @: X+ W: b
  3. int port = parval(2);
复制代码
 ; `. c. N! x5 ~9 X. `
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
6 P4 V1 b7 h. A9 p" Y- i1 b在接下来的代码中可以直接引用这三个已经声明好了的变量。
7 A. Y' @) u0 |! p) ]4 y6 e% d/ P9 [对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。3 W. z0 a& h/ A7 w6 |% z! Y$ X
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。5 K  F  }) s5 t0 a
6 ?* c# }6 m( ^1 ]# U& C
treenode8 Z; ]# Z% q! P) t! X! Y$ {- f
Variable Types" t- k3 b: i( I. A8 i, |/ P2 J
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." g% N* n1 z7 K3 L2 _; u* ^2 I
Type Description 5 |7 _: w8 I2 p
int  integer type  # x8 E' Y3 V! l1 V: Y' E
double  double precision floating point type  3 C1 R3 _( l% g; I0 G& M- _
string  text string  
8 d/ I& Z) w  k* I7 O8 t! j6 [treenode  reference to a Flexsim node or object  
9 m* e3 A2 G  v# f( r* u/ aflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
' _+ ~2 u' N. b. h% j6 C/ p& \$ u1 j4 V$ R+ {3 d8 b! e
current<no parentheses> . F& t  C6 M! T6 C1 C+ |7 m
Description:  : c6 H# g1 F' X$ U) q& F0 ~1 X
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. + t' `- h$ ]7 j. I8 x4 a( m
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
$ t+ C% w* a  y1 ?不解:! A& m. k: _. W8 g. O
1.used...with....是什么意思?
2 D9 _& @7 I1 e, O8 V以前current是必须和setcurrent一起使用的吗?) Y* a& T4 P7 ~( B$ k4 V, r3 x
, V$ e; K3 s( k, r# _/ p# y8 M/ i
2.as any other variable type是什么意思?! k# A" ^9 @+ ]3 b& L! V! C0 w  e
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

, a3 p; D: @$ J" d* ~Example: 4 I8 ^/ @( K3 E1 h
  1. treenode current = rank(model(),3);
    : j9 z' n. ]' g- V1 Z$ T6 `$ k
  2. pt(getname(current));
复制代码
 
# }# {; e4 ^& j- c* g  W. ^This sets the object that is ranked 3 in the model to current and prints its name to the output console.  / o: a. \$ T  @' f/ s

* K' X# [9 f# ~* H' R3 g5 [# Y# w" }' n' S0 }. r. @
ownerobject(node thenode)% e# @% z, M" p; c3 s( K9 L
Description:
9 S# T  x' Z5 ?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.
+ b/ m# J. F) x, ZThis 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.- P) A. H6 M" m% Y- a6 u: X  n: w7 `
该函数返回参数节点所在的实体。
3 [' |) U" I' `3 z: x/ @
/ Q6 w1 F& q# A4 u% @Example:
4 o& b" v$ q2 L4 }, q
  1. string objname = getname(ownerobject(c));
复制代码
 3 L7 I6 b, a, r" |/ Q- m
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);
复制代码
 5 P3 J+ z9 [7 w4 x7 T- u( m
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
6 F, _% Q0 |. A' G2 V- y这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。. n7 f9 _) J3 K0 w

0 }% A- }8 C3 Qc<no parentheses>, V4 p6 P6 I+ T* k4 G" f, |
Description:  + B3 q5 L  r* F, m
This command is used to reference the active node during a function's execution. 3 n- i/ w1 l( g  T3 _6 _
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
- b- {# y3 H) ]6 _" ~! SIf the function is an event function, c returns a reference to the object that contains the event.
/ ]: T9 n* t5 T' D% jc在函数执行的过程中指向活动实体。
5 z, r- s4 d: t# w! q' e如果是节点型函数,c指向函数所在实体,9 g: }& u, K  b, n0 w) \
如果是事件型函数,c指向事件所在实体。) m. m, b; j4 E- B
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
9 p6 S, e6 Z  k3 R# l
, P4 I3 n% ~1 r( `2 a3 esetcurrent(thing)' Z  }0 ?# [% X4 H& Q  w
Description: Deprecated. Do not use. ) F- F. U9 t3 h* t' Z
Example: /
8 }: U, T$ r9 \( U8 h; ~此命令不再使用。- r6 X. i  F+ \6 x4 M; v

; H2 ~0 `; x3 Z; N) C9 witem<no parentheses>
; I  a- V8 @! v9 @
Description:  
6 }! U( x. ^5 a6 @( ]% T) C, @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.
3 s. ^- l5 D# |1 K3 Y4 `$ ^不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
: W* B+ z) h/ m1 R+ H  X, SExample: 
  1. treenode item = rank(model(),3);0 E# e4 C. M! h0 Q& F
  2. pt(getname(item));
复制代码
 
& t7 l/ r) x7 z5 T3 jThis sets the object that is ranked 3 in the model to item and prints its name to the output console.  + L, g8 B* d+ B0 m, U) I
! m7 O9 b, T# l8 R

' j4 g1 R! W. b. W4 ?setitem(thing)5 M1 r2 k+ o% o5 \" [. w
Description: Deprecated. Do not use. . m2 L5 q% b/ u
Example: /7 X' c; ]  S) X
此命令不再使用。/ H) V: ]8 B% b. @3 P

' _, U7 `! M% F  yparnode(num index) $ O& Y8 D* b* h, A5 ]
Description:  ' f, H, Z. W7 g+ W/ E! ~
This command is used inside a function that is called by the nodefunction() command.  \: W$ O) ?: k6 o. A; e' |3 a8 e3 K
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?$ P3 F& [! A3 A4 z
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
6 ?6 z* y  D" h& a此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.# K, o1 K: D6 Y- \# U
节点和树节点有何不同?
0 g- J5 m) b7 i' jThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.2 O' F" q  \* v% L
parnode,parval,parstr这三个命令真是让人搞不懂啊...
9 S+ p' ^; J: z+ S! G/ u5 wParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.   [( U( s3 [$ I: g/ T
Example: 0 M0 x( z9 y6 {! b- Z" Z
If a trigger/field is called with:
0 a0 H; I/ O& l  nnodefunction(thefuncnode, item)
& G6 E/ o1 J% G7 |3 |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);
复制代码
  
; x1 P( E6 u% v) }. q1 I, f9 A/ S( m6 Y: F9 |! f
port<no parentheses>
: k$ N  i, l* c( {) q, xDescription: 4 I: N! u9 m0 V
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. $ q& g# v: ?8 `  [1 f
Example:
5 H" U' O0 x  i: D" E: w
  1. int port = parval(3);
    7 A6 u( v+ g& v
  2. pd(port);
复制代码
 
, m1 B+ [+ P& \% d/ N0 O9 OThis sets port to parval(3) and then prints the value to the output console.5 w# v  P* G. I% e7 N( r

8 f, k/ _9 z; p- \5 F2 |不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite
) ?2 a0 k9 R0 f6 k1 {! T
: W& M0 i9 m+ f# f* ^: [1 M  t* I+ o( T  n3 z! ^
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
- ]* O0 |* U8 I: ^    首先在GUI中,它是这样的,如下图:
! c6 Q! Z. f$ O7 h% e* j3 ?. P  [而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-9-17 04:34 , Processed in 0.090805 second(s), 15 queries .

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

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