全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 ) {$ ^1 ]& k0 q8 G6 [6 {; D

3 g1 x2 {: C+ X2 @* u9 N  D在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    " x& z& c' U( O9 w
  2. treenode item = parnode(1);3 q( h/ K+ t# Q
  3. int port = parval(2);
复制代码
 : a8 ]6 E1 R% k! e) F# J5 K- I, G9 w: ~! d
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。' v7 @/ Z, S" P8 u, P1 P" {; Y9 t
在接下来的代码中可以直接引用这三个已经声明好了的变量。
0 q* Q0 V( _" B0 G  d$ U) y对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。# Z  F7 w  f* i" A- Q
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
! o4 U6 _' y( ?9 A9 `' T$ O1 |
1 ]" v) b. y9 y8 U. v$ ctreenode
4 c& l2 ]  E9 X8 p' q; wVariable Types& E4 c* y7 |& \( K! A7 p
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.& U' C) C8 l; ?( N
Type Description 9 u1 o- T9 p. t1 c2 Z( r
int  integer type  
( A- O( j- Z- J. Tdouble  double precision floating point type  
5 G" |+ m  j+ h: B8 ^string  text string  
3 C# }- J! N* btreenode  reference to a Flexsim node or object  
) D6 t7 K' ^! _flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。0 E, O; q6 t# G5 ?3 u; C

, N; Y& E5 A5 X& Fcurrent<no parentheses> , f- h0 W6 \( z4 k
Description:  
: h1 |) ]* l; R1 _; F9 C# SDeprecated. 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 H, j6 |2 q; v6 H# o7 Y" g. P- w不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
. z6 N! G) N, @/ Y# v' y不解:
$ {  o$ }  |: X$ G2 i' s1.used...with....是什么意思?
0 M, `" p' D" @/ I4 k6 f. x) J以前current是必须和setcurrent一起使用的吗?8 V! d% R% V- a* }
' |1 E9 _6 ^) e3 z
2.as any other variable type是什么意思?8 i8 }7 m: w6 `, j: [5 Q
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

9 Q3 S5 g, F/ A$ s4 K! eExample:
) v3 W; C- c; \; x
  1. treenode current = rank(model(),3);
    # J  q+ i6 _, @, b3 s
  2. pt(getname(current));
复制代码
 # x- D+ O. D+ W2 R0 W
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  
$ d3 A6 W% E$ F$ A/ _) L3 B% L8 h! s' Z5 i2 A$ z( s+ N
3 c: e7 q7 P) R9 s) Q! }: i8 v1 c
ownerobject(node thenode)3 ~( u* w( Z& f  [* H
Description:0 q6 V0 ?# y( K% ?! h( M% G
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.3 T! J) X& F: q3 S6 h# @
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.
- h/ v, d. u  {, u8 f" D" }4 B该函数返回参数节点所在的实体。. y3 b% c8 U* O. X! P
- f5 p0 K8 Z) s% p
Example:
. ^6 w: K( a/ F% _6 w+ @
  1. string objname = getname(ownerobject(c));
复制代码
 
+ g" d7 M2 i6 [: iThis 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);
复制代码
 
; v+ z" y6 h6 W5 GThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.3 C7 E! [1 [% C4 P7 h2 E# E
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。3 t) a$ k2 F8 W$ R! }

' v2 z7 ~2 H& l9 Q, ]& cc<no parentheses>
/ r; J0 R2 w. V3 ]% V5 _; P) aDescription:  6 b( a$ d+ W+ p5 }
This command is used to reference the active node during a function's execution.
- S! G8 [5 Q+ u5 q5 z# ]  \6 @' K$ mIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.
4 \, \2 h* K: ?2 j  R  ]If the function is an event function, c returns a reference to the object that contains the event. % d, E( B3 C) m* c0 T1 V
c在函数执行的过程中指向活动实体。
, `& A6 F8 q- a如果是节点型函数,c指向函数所在实体,
  I" R( h3 I/ |8 e如果是事件型函数,c指向事件所在实体。5 ]9 w" D; C! i! A- r
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
* b0 V% U& a9 n! I" W% g8 q
) M; ?7 u& |1 ^, f6 Msetcurrent(thing)
; l9 y$ c& V4 o
Description: Deprecated. Do not use.
3 m5 @7 f1 u( \$ C; M9 AExample: /
  u: b* p- h0 @* U$ K此命令不再使用。3 v, A; R* J' y/ d
! B4 R' J) S' E! k1 N6 i& A
item<no parentheses> + L. s5 T4 s) T+ [
Description:  # p5 [% g# e+ u8 [0 d8 k1 S' J3 w3 T
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. 0 _; z6 p+ L! V1 x
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
7 U1 z0 i) v% h+ f1 j# D. x# FExample: 
  1. treenode item = rank(model(),3);" v8 O! F$ G( }& e: m4 s
  2. pt(getname(item));
复制代码
 4 R3 ~9 ~6 T; _* R( v
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
# z  @! m, }/ g% {# l, F% l& }
0 u6 W- i/ [' E3 P, ~/ t' D
5 N8 m: v" ~; i, X5 p9 T: t( qsetitem(thing)
9 Y% l& a- @5 a9 G
Description: Deprecated. Do not use.
9 J' z3 a" p" W* f$ RExample: /
) m6 K7 a, t6 L此命令不再使用。
# @7 o: h; F) g& B' b
* Q9 u. V5 m5 Tparnode(num index)
, g  A, \% a6 IDescription:  4 ^+ f8 _3 m) l
This command is used inside a function that is called by the nodefunction() command.' s/ O: x8 y! w% K4 w3 e" K7 k. C
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
" a0 V' A% ]8 W- L+ t) QIt returns the parameter passed to nodefunction specified by index as a node (or treenode). 2 E- B, D0 a. c2 J$ J  a
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
9 _( P. F3 B' ^4 V9 @  D7 @节点和树节点有何不同?1 F" w% X+ B  y) v) N! }- m$ _
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
7 F" P% G  Q; w# oparnode,parval,parstr这三个命令真是让人搞不懂啊...3 s0 e4 D& C  Y* p
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 6 J9 @' Z3 o, n7 e: X  l, X
Example: 9 g. u9 G6 ^: g- n2 F* v5 n: i
If a trigger/field is called with: . ~( b/ F' K- H7 `, k6 h3 q3 v/ @
nodefunction(thefuncnode, item)
5 N  p; ~* V# v  s; ethen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:
  1. treenode item = parnode(1);
复制代码
  ; u9 L% I, S7 _9 H# l
' u7 E$ G8 C% ?+ E3 a
port<no parentheses>8 [: H4 P" k4 ]2 T! H0 E  ]8 o
Description: 2 O& [6 }7 F2 b3 e; B
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. 6 B: F: c0 `  j" W: W
Example:
( C0 C9 n6 g7 K! _3 r, I
  1. int port = parval(3);
    8 O# i" E1 B6 }
  2. pd(port);
复制代码
 % r$ a4 t3 s- L) V5 T7 _
This sets port to parval(3) and then prints the value to the output console.3 G* C4 L( F0 w/ t3 B
' V3 j1 X4 H2 t1 O  W( X7 I
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite
. v  W+ T. _# d6 {: `4 N( A; `
* V7 b4 R- n4 e. R
3 d6 x! }# C- V: g" ~( p& T首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
8 f! W5 p0 |* s5 {; V    首先在GUI中,它是这样的,如下图:
& J0 l/ t- e: ^/ y! m& J而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-5-12 07:08 , Processed in 0.079577 second(s), 14 queries .

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

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