全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 & p0 d5 H& B/ M3 T& X) H% u$ O8 h
# q* m. Z8 g2 r) r7 x2 H
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    / Q7 I8 K; X! z5 g, k
  2. treenode item = parnode(1);
    1 P& w% O/ b6 |+ k# ]7 N3 ^
  3. int port = parval(2);
复制代码
 
6 b) U$ c1 X6 W意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。# L$ k+ A* `0 i1 ?  ]( [1 \
在接下来的代码中可以直接引用这三个已经声明好了的变量。
% Z! S$ \( G0 ?/ ^: S4 E7 U5 _对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
5 m+ A' x9 P* V% E下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
. h( V' \4 g: K/ I, r; Q/ e% U: Z, g9 f+ W( \3 b
treenode
4 K/ Z. n5 a2 O7 x, KVariable Types
: D; `" ?# Y5 X! A! pFlexsim 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.
7 y2 z" C- E, o* K* C+ x% [4 eType Description 8 L" l& N% l& Y
int  integer type  
9 D3 S% }+ K# D3 M, l: tdouble  double precision floating point type  ( Q9 x2 n6 i& S
string  text string  . m5 R' t$ `6 M) a$ n
treenode  reference to a Flexsim node or object  
4 r6 Q2 |9 j1 W* S- G8 J0 q; rflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。3 G! Q3 h9 v3 w* |3 c& w

  y0 |- |7 l; q6 X- N/ A, ocurrent<no parentheses> + p5 A$ y  M: a  c
Description:  
8 d0 K7 {% I5 d+ \! g# \1 gDeprecated. 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. 1 W1 Z3 o2 J+ ~4 L; M
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。' n3 ?. z) m, n* @( S; h
不解:
& @, W: d- u; Z8 a1.used...with....是什么意思?
) h, w3 q" {( `以前current是必须和setcurrent一起使用的吗?5 B; X9 j, E" k* P! V( _9 h
* b2 z, e0 {; P. z* ]: ?, x
2.as any other variable type是什么意思?
9 f6 X* L1 B- q* h前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

) S$ c; I- \6 E6 GExample:
% n8 }  n( C" C
  1. treenode current = rank(model(),3);
    ! G. q4 F' ]& M( h! o. K* w7 f. a
  2. pt(getname(current));
复制代码
 
& h1 ]* e$ s+ T& C/ UThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  2 ~: o0 R/ {0 L7 ?( Z; z& n) A

# q8 p0 c6 N0 Q7 u. H6 V" ]; w: n) Y* ?) V& ?' ]  y
ownerobject(node thenode)6 n: |7 l6 w! Z  y6 P; N2 g
Description:
7 y* v# f! d+ W' xThis 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.+ Q. y) k% n$ S( \( o6 W
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.* Q6 ~; i% _# d. {
该函数返回参数节点所在的实体。* w3 O4 P* J* A, M) A

6 Z+ z( k& ^4 R7 o) q, bExample: + p3 P7 O0 P6 `
  1. string objname = getname(ownerobject(c));
复制代码
 : P6 ^2 z7 e/ m# d$ `" R3 e
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);
复制代码
 # i3 o; W' F6 @' O
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
6 b/ a$ A2 u: P- L# ~这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。6 v1 P, t6 {9 w' a  w- d" d( ?
+ @0 g, v6 O+ {
c<no parentheses>
9 Z+ b: J9 x7 o7 w; R- T% iDescription:  
9 X, Z( t, P6 q! v) z4 dThis command is used to reference the active node during a function's execution.
7 h( P$ h# I9 T& M9 z3 SIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.
/ G; ?2 M2 y/ q7 @( {$ s+ R' PIf the function is an event function, c returns a reference to the object that contains the event. ( w5 m0 s7 p# U' G
c在函数执行的过程中指向活动实体。
! Q( s5 W7 |8 E- L如果是节点型函数,c指向函数所在实体,
6 B( h: x8 [5 K0 F" R, |. \如果是事件型函数,c指向事件所在实体。# h7 u, u: j" R) s; O
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
0 i, K  p3 ]( a# e6 d8 d! o5 A  c; |& b) O9 B
setcurrent(thing)% G1 ~; t2 b: z' U/ Z+ W
Description: Deprecated. Do not use.
- ~; z% z+ r. a1 f* o, Z* O! O8 hExample: /6 k; T, j5 B) a
此命令不再使用。9 A$ H1 E9 Y; v- W8 x
1 V4 d. d/ m! z
item<no parentheses> & s( l6 Q1 c" N$ ]
Description:  
: h" \: {# X6 r' r8 o* I! BDeprecated. 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.
7 L8 P5 i* D5 P0 S0 ?不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。: y( Q6 o7 |' _% ^3 a
Example: 
  1. treenode item = rank(model(),3);0 g4 ]+ ?$ C9 N; ]0 I
  2. pt(getname(item));
复制代码
 - t0 e- X7 _( Q, p; @/ N
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  2 i8 e) s- E, j8 Q

; W/ m6 r$ N, {2 r- x2 ?7 q/ q/ V" e7 }
setitem(thing)
' N' Y+ [( [* J  ~, r* I& }
Description: Deprecated. Do not use.
* d: L, |) N* n7 _; U0 ZExample: /( [9 V* q3 p9 ~! S0 w$ I; R
此命令不再使用。, E5 B, z8 e0 ]% M1 M7 i1 _( y
; L* @+ w4 r# V
parnode(num index)   k& x4 Z% M; p0 f- g3 g
Description:  8 o/ F! X+ j3 j9 D' C; V% n9 n
This command is used inside a function that is called by the nodefunction() command./ A3 n2 k3 l8 f) e4 N
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
& }% O8 A9 R  G8 wIt returns the parameter passed to nodefunction specified by index as a node (or treenode). ( {8 ~$ U" d! z" F7 o  x
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.. s& a5 u( Y3 M* d. p. \
节点和树节点有何不同?
* [9 a: r. j1 M9 I# K) [The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
8 P; S% x6 f( N5 ?) M, u0 Oparnode,parval,parstr这三个命令真是让人搞不懂啊...
0 d2 j; A8 L- E5 P0 kParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 3 X  i1 V) Y; e
Example: ! y  f: ^, n' N  L  P
If a trigger/field is called with:
# E8 ]2 k, G5 u4 N$ ]1 R- gnodefunction(thefuncnode, item)9 m) [/ ^: U# N
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);
复制代码
  
  |; E) E$ y% _" N
0 n1 M7 J* A0 G  nport<no parentheses>! b# b" ], k% {. h
Description: & [  Q# B) V% w' w; 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. + y8 ~. t% C8 p
Example:
; t9 P- W+ L. p9 m, Q1 r0 }, G% M
  1. int port = parval(3);
    5 r& X1 Q2 l+ }1 T: m" q$ u
  2. pd(port);
复制代码
 
% Z$ `1 u# K, w# n& O; w( L' \7 Y3 uThis sets port to parval(3) and then prints the value to the output console.
9 P. H. [; t2 q8 F
4 e, U' }$ W% T8 [* ~/ L" N不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite
/ F: O/ L! v# h8 Y# r7 {9 l9 w7 X4 G# I6 J% r/ z' j

0 Q/ X- z( A. }9 D首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。& G! m0 W, L5 [. X
    首先在GUI中,它是这样的,如下图:5 i/ i) e. w/ w9 g
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-6 02:12 , Processed in 0.078806 second(s), 14 queries .

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

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