全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
( I" @# ?  k  e, o* [/ A* A/ d% w! R# _
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);$ ?6 i* ~, G5 F1 [; L. Y/ P
  2. treenode item = parnode(1);
    7 y6 X; Z2 T* y0 J4 F/ L# e1 Y
  3. int port = parval(2);
复制代码
 " e2 d% I( ]7 p# c/ R, v/ P$ Y
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
; X# O- Q$ g( z. B# q在接下来的代码中可以直接引用这三个已经声明好了的变量。4 d: G: F, I  p$ A3 Q: x6 Z
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。( _% t; W8 k1 ~1 ~
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。! U1 ^  S" `2 [. ]: A; P% |

; A0 I) @: f: P7 ttreenode
! @) P7 J+ @6 J1 G( c$ O# rVariable Types# J! R9 W0 O( a/ R2 F. w/ Y
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.- v4 J/ m7 h6 _& o- t
Type Description # w6 m1 }/ y* X
int  integer type  
% I- d( _0 y( K# r, V# \1 k/ {double  double precision floating point type  # v( E7 X1 d6 C
string  text string  * u8 G* v' B9 t/ J
treenode  reference to a Flexsim node or object  
2 V6 T  ^0 p! Yflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。% h/ t% Q/ S* V* Z& x, z$ b9 M
/ E' m8 s4 l6 `" v
current<no parentheses>
+ e9 X- C% |# ^Description:  
$ s9 k) K! m4 VDeprecated. 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 ?/ I9 s. k% y0 \9 R  ^% G# E不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。. w% N; U; G( `
不解:
) E2 s/ z6 ]& J2 h1.used...with....是什么意思?
$ J, P5 B/ }2 A' F以前current是必须和setcurrent一起使用的吗?% W% I5 B/ Y+ }/ S: e- s6 p5 @

% O! O0 B  C5 n) E1 {/ [( n. W2.as any other variable type是什么意思?
* O7 z; {' l8 s% C2 a0 ^前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

  W) k4 t; q( h) R7 S% f( B  _Example:
/ s9 p0 }& i: c' }; L% y: o
  1. treenode current = rank(model(),3);/ o. t3 O) k/ S+ ^
  2. pt(getname(current));
复制代码
 
6 V& h# K. E" a0 Z8 R0 Z' H+ U* oThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  ) k; ]2 O! B& c+ k# s

1 c  B7 P& F9 o- v$ K6 b( i6 R/ b% c0 s* g8 V
ownerobject(node thenode)
- |2 k. H( Z0 a
Description:
* O8 C) k" O- Z0 X: h" fThis 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.6 J3 z2 X1 ^. h. ?5 A
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., |" n% {$ V! Q/ G. Q& x
该函数返回参数节点所在的实体。
/ V6 Q# Y3 h- V6 u2 X; {3 V/ y5 T0 J6 K9 h/ R
Example: 6 J' e& X$ v8 w- a( p3 i
  1. string objname = getname(ownerobject(c));
复制代码
 
7 L1 t9 Y6 B; e- q! }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);
复制代码
 
# B4 ~- _5 y/ ]) {8 CThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.
& P2 `% `. ]: S2 {2 Q( T这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
: P! z" |9 f& a) a7 R7 R7 _0 b$ i# ^8 X7 t; D/ e5 {/ V& E  O
c<no parentheses>! p7 N* |2 B- E% C0 f% [
Description:  1 Q. U/ W3 m( w  h5 \
This command is used to reference the active node during a function's execution. $ i' q$ V# J! ?: ~
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
' E$ A1 V8 z1 j- O, x' HIf the function is an event function, c returns a reference to the object that contains the event.
# @/ ^: Y) x) N7 v4 j$ \c在函数执行的过程中指向活动实体。
; z& y" z3 H) l7 x2 F如果是节点型函数,c指向函数所在实体,
9 a+ m3 V5 v+ s9 M  I如果是事件型函数,c指向事件所在实体。- {( B& q% f1 z$ P' {" z4 |
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
4 J2 T7 P) P/ D8 x" s; v7 B
+ ~: g& f6 G- e+ e2 X6 A: b4 w& \/ usetcurrent(thing)
! S. h1 r2 G7 a4 I) f  M
Description: Deprecated. Do not use.
8 H5 R5 `* ?+ t* B% ^% Y; gExample: /
! `4 d- Y: p1 `  A此命令不再使用。
+ y8 Z5 l5 k( _& Q. p9 ^4 Y  \* [  p  f5 a
item<no parentheses> / z  I% D4 l$ h/ }& i7 E
Description:  . y; ]% |: H+ G7 g2 E- y% 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. ; J5 i* o5 w5 l6 D" y! ^! o% s& [
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
/ c* @0 H) L4 J$ H: B+ W: ]. wExample: 
  1. treenode item = rank(model(),3);; m, ~5 J2 F6 W3 R# l4 I# A' g1 }
  2. pt(getname(item));
复制代码
 " I4 v0 ?  h- _, E$ B
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
9 v8 C9 ~( B2 y4 N, m3 w% u! z4 y" r& j& d5 t5 Q
, I6 H0 [6 v- G4 M, @, X4 I/ c
setitem(thing)" P# Y* z* ^- W
Description: Deprecated. Do not use.
! y1 c- z2 N5 ~Example: /$ X& i4 R5 J) L) E. K6 R% A
此命令不再使用。
6 e* Q5 ]% c7 H+ d. L0 n% K% X5 r5 P1 D1 ^. O6 P7 c; j
parnode(num index) % T( U/ m- O3 ^5 {6 k2 E
Description:  
1 a; m" g  H3 U( ^" N" b9 ]8 l. |7 b8 xThis command is used inside a function that is called by the nodefunction() command.# s/ e/ ~  J2 ?0 f8 k- U- T7 c
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?$ R/ x0 b4 _' k/ p
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
" s4 [* J' X4 v/ r$ S- t- Y此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.6 F& H7 T$ w2 c7 a. V
节点和树节点有何不同?
' z) t" @, t7 f' v+ [' wThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.* H3 ^: b9 D, p
parnode,parval,parstr这三个命令真是让人搞不懂啊...
7 c! F: U: m  }5 y1 _Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. ! \4 u- I* q$ d" ~6 N
Example:
; Z' y: q! R8 n2 A! ~) qIf a trigger/field is called with: % L' j5 T$ `" r7 z, ]
nodefunction(thefuncnode, item)# w2 j' F) H% A, y  q( U. c9 K
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);
复制代码
  $ c& s9 S9 i0 j' o( K$ k% M3 J

% k2 W% ^+ w, V  Aport<no parentheses>5 U% N  T& c" r/ }: U3 Y1 ]
Description: + n9 }: ^- g+ I- m; i
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. / S: ~2 b: y2 J/ e
Example:
9 m3 G) s( U, b: I
  1. int port = parval(3);
    2 k3 U8 Q9 R; b( ?* N
  2. pd(port);
复制代码
 
4 y5 L% h3 d* Z; q2 a; d( BThis sets port to parval(3) and then prints the value to the output console.7 V! V, q8 R1 |! @

  B5 T6 ]7 h7 B5 Q) q/ L不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite . X3 N" F5 o3 K+ v
3 x0 \  t/ \) Z! \
3 X$ ~: w( E# S3 C, x9 F
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
5 @# }) B( E" u7 J7 x# O    首先在GUI中,它是这样的,如下图:
4 ~$ K  n! j1 o0 b  y4 Q1 C而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-12 10:30 , Processed in 0.068511 second(s), 14 queries .

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

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