全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 # a! U0 \- ]8 {! e7 e
6 O" x& x9 B; n7 J
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);0 f6 l( o& |( t  O% T. ^7 w3 E
  2. treenode item = parnode(1);/ t5 p* f7 v: a% |3 O
  3. int port = parval(2);
复制代码
 ! u9 t0 f. F& ^- l/ U
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。. o; T/ [! J! j( J) H+ _4 r* m
在接下来的代码中可以直接引用这三个已经声明好了的变量。
( q/ E' j  T4 k& ~$ Y% u2 p对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。5 Z; ]+ v6 u; e, C/ D
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。# j# Z  m/ o; q5 Q; _( W* ^) P9 q

8 P+ v8 L) D8 C/ h7 g- T# T% ytreenode
  A( j( g. C" qVariable Types* ?/ |; _5 s+ E* z* O5 M- `: r
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.& ~8 Q) c9 w- s1 m9 V4 Y
Type Description
3 R4 b, X$ S1 {+ v" l0 }int  integer type  
3 Q! Z& B" j( J- M9 qdouble  double precision floating point type  
' s+ m2 K: g# C& \string  text string  
- O0 ~: s! t% _. w. Otreenode  reference to a Flexsim node or object  
5 t0 n1 V) E9 t" P" U' |flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。3 j3 C2 [1 [' {/ \

$ f  Q  s+ i4 E+ ?current<no parentheses>
/ r, o! F4 k7 ]6 v/ C& VDescription:  ) v9 ^5 _& h) J% o7 P
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.
& ?* |" r5 Y& l+ ^0 M9 D% W! ]不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。3 u4 {; c) \9 O! s
不解:# u3 K7 W) Y* V4 [% T% Q: |$ u$ |. r7 V
1.used...with....是什么意思?
( N4 R$ B9 T; E! x! g以前current是必须和setcurrent一起使用的吗?, x2 n8 u) G. p; ?. t# o
: t+ b, {1 ^( I' p- ^0 v
2.as any other variable type是什么意思?
1 k! B* w; x' D( A4 O) X! k前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
1 }1 l) ~( z. c$ t. ], {
Example: ' Z: v, u4 d5 [5 b9 u- b; v
  1. treenode current = rank(model(),3);, ?3 C- F. B  E' C/ N
  2. pt(getname(current));
复制代码
 5 A& S* I. E2 R; A  a5 U. N
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  
8 t' J7 O9 S3 p+ g5 |( {
0 J' X$ I$ p# `1 X- _; v9 O2 a6 l( m6 B2 m8 a1 B: D( I8 d, ?
ownerobject(node thenode)
$ q& u8 j  Z; R- ]
Description:
. J4 ~3 s" F  y, A; c4 ?8 DThis 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.1 w- C6 }" C  ]3 O
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.. M& D/ u( y9 G, V2 u( s; r0 X
该函数返回参数节点所在的实体。; G$ I$ S& }) V( C9 H0 ^) P; j

7 }. P. F0 s: l- b, K& x8 MExample:
" x4 c2 i- j0 b2 m' Y2 T9 t2 ]& Z+ t% J( K
  1. string objname = getname(ownerobject(c));
复制代码
 
! M" T( }( n- b# P4 B1 r/ qThis 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);
复制代码
 
; s* F5 e$ p( r0 ^This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
8 N" P4 T  S5 R这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。5 I' }* X4 C; O  ^
2 }1 L7 e/ c) G$ c: y: M1 q, r
c<no parentheses>& Y8 n! y- ~# k6 n, @
Description:  
* K$ C9 R5 B% v9 G" h% q8 |This command is used to reference the active node during a function's execution. & \2 q3 [/ r4 \3 i6 y
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
# H( ]' d! \5 b8 h0 Z7 J" j  U$ bIf the function is an event function, c returns a reference to the object that contains the event.
. Y6 _/ N7 h0 u% \* [% J6 T1 l5 Pc在函数执行的过程中指向活动实体。
! L! y  P$ n- D7 }! I9 e. K% s; T如果是节点型函数,c指向函数所在实体,; j1 J7 s0 |- o
如果是事件型函数,c指向事件所在实体。0 [$ g6 [9 G" h% ^" g
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
  J- n' ]& {3 \) Y# @" C/ g- J2 v4 k5 x+ K6 _2 t& ~% l1 k
setcurrent(thing)4 V' d% m1 B. w9 e# x
Description: Deprecated. Do not use.
( i* l* T/ t/ ~5 ?( {4 M+ G2 F/ vExample: /0 a5 r6 i6 [; F; ?4 j2 Y* E. {
此命令不再使用。
8 T& ]% Y6 s4 }9 S1 ~
4 J" ]* k! k3 ^6 w+ X( Q' ]item<no parentheses>
+ T" F  x# ~: ~9 x4 {6 P" x8 N0 F
Description:  
$ [* S. e5 \( z( r$ nDeprecated. 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 W" U- v! A4 h" L7 V" @/ \+ Z
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
1 f! r0 b5 g+ F- Z% {! N# S0 w/ A, lExample: 
  1. treenode item = rank(model(),3);0 i* y- s; J7 l! g0 P
  2. pt(getname(item));
复制代码
 + O) k; ]$ a% h5 z, d* ?
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
5 O! c% |& j6 r2 p. v- Z! l! n! A

& n4 }9 q+ Y% ^( b* W3 S/ vsetitem(thing)0 _. a: f4 A* E# [+ j, u
Description: Deprecated. Do not use. ( i) j7 P4 f, m( Y# c) p( a
Example: /5 ~6 A8 T- X- c) y% N5 h+ U
此命令不再使用。; k3 [" B$ d  y8 l9 e3 m* a

1 `1 r1 i) I! z6 a7 Hparnode(num index)
1 N% y# K. a, y  A8 B- TDescription:  # {  @2 b1 l  F$ D  z- a8 w
This command is used inside a function that is called by the nodefunction() command.
$ A. _( ~! p0 d; v$ ^4 p. B3 ~此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
. ]" _( j; X0 x5 Q& c4 v) LIt returns the parameter passed to nodefunction specified by index as a node (or treenode). 4 D( E, c/ P& n8 a2 ?
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
  [2 s) c) \/ M$ f8 k9 ]2 E节点和树节点有何不同?
$ r' C. u+ i% b- h& SThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.4 u8 Q5 i7 i6 F: `8 u$ T. ~# C
parnode,parval,parstr这三个命令真是让人搞不懂啊...  E3 v3 s5 o! q5 W
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. / f& |" B2 l5 D# M" s8 v% Q
Example:   H$ w0 p( x; M! L+ V) {
If a trigger/field is called with:
+ U' U6 V9 Y- p, w) M, m: }nodefunction(thefuncnode, item)
3 `4 ~% S# K8 D( zthen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:
  1. treenode item = parnode(1);
复制代码
  
2 n' T) l6 r, V& K8 ?- d* {0 A0 J5 P/ s; z! H. N: x0 V
port<no parentheses>7 M; W2 Z, Z% P6 L4 r- r
Description: $ e+ {/ K9 I% c$ a8 I( _* f
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. # w" n% l4 B1 C6 J6 E8 ], t) _
Example:9 i$ y+ r7 {$ D; O* [
  1. int port = parval(3);# p. o# }6 m, s( A! S
  2. pd(port);
复制代码
 
9 d' Z" S% ?, }This sets port to parval(3) and then prints the value to the output console.& i6 E; W) j7 X8 b& K! v; `

2 G+ s6 h' l8 O  |- t: m不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite ; q0 b# ]. l5 M7 @- F
6 S5 H. |3 H2 ^% l* G, m6 f4 t

& Q& {& C1 ]9 f# A& j7 a8 z* h首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
3 a1 a) F! e, ]! Y    首先在GUI中,它是这样的,如下图:) e. @! S( I1 L9 E3 a
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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 03:57 , Processed in 0.068682 second(s), 14 queries .

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

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