全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 - e% [0 q/ ^( u% {6 r9 q3 H8 Y
; ~" q' G5 U; {& M, L( p. L
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    ; T# D0 ^* l) n2 O# k5 x3 n8 u
  2. treenode item = parnode(1);2 X) |2 p3 @6 Y6 z2 a. z5 K$ K
  3. int port = parval(2);
复制代码
 
" t$ ^5 y0 L$ c5 T* i# g  |- _4 V意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。, Z" f, I* P/ C3 W: L
在接下来的代码中可以直接引用这三个已经声明好了的变量。
: N' l2 \0 L% L7 t对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
- Y. y9 I6 y5 v下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。& A. v8 L( \# K  ~9 P

# E# D0 P+ D0 ~8 b/ Dtreenode' a& b. \2 O. U6 l: v
Variable Types) r* \2 B0 O* y# b& |  K
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' X* |) r6 q& k" B2 H
Type Description - L6 x$ P5 q! Y0 f
int  integer type  
9 f7 R5 h9 ~! v! Xdouble  double precision floating point type  " }3 l' R3 C3 l; M9 ^4 X
string  text string  
# c8 d5 G9 e. J% K& r5 D9 ]treenode  reference to a Flexsim node or object  
. S& G' z" k& V/ F# pflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。/ ~( L' Z9 H# l4 \# A; t' ^
6 \! p! R8 H* `- C2 W% J; j
current<no parentheses> 3 f* j) Q6 _- i3 M0 S
Description:  , C6 ?6 X" i9 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.   }1 D+ q2 N) A9 o# k. l6 A0 }5 R
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。/ Q+ N3 I- H# b4 f" g7 P
不解:' ^# a# {7 j' g- n4 \% c
1.used...with....是什么意思?
, t; p6 k/ d* K1 d, {7 q+ K. @以前current是必须和setcurrent一起使用的吗?# D# o2 m4 U' b% ]& s: y
. j" ]2 u: {" Y
2.as any other variable type是什么意思?
5 V' {5 q9 o' R/ I5 M, m" d% }前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

' e) P! H( `, s' O6 AExample:
* U1 m( c! v6 e3 w4 e  e9 T
  1. treenode current = rank(model(),3);
    " h4 v: y; ~; r/ w
  2. pt(getname(current));
复制代码
 
" E: p3 P. m1 y+ }# n) m9 qThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  + W2 M$ n, w3 O3 l

8 Z. s3 H5 ~+ `8 d; L
& C' {  J: Z$ N' {3 I1 [+ cownerobject(node thenode)
8 @' S7 L/ P0 K0 J( r' f, Q- h
Description:: N5 _6 N0 j- w; d# ?9 a
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.# Z& D9 d% d! A/ N* J7 C; p* H( q& r
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.) j  ^, l. w- f6 z0 ?; }
该函数返回参数节点所在的实体。
( F) C& p9 N2 W* s% e% }' m, W1 ~& l; j
Example: 0 p% T: G) M7 {
  1. string objname = getname(ownerobject(c));
复制代码
 
* D' P+ a5 A( w9 G% X- o3 K& RThis 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);
复制代码
 + j6 `1 O4 J- _$ n8 ?  L
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
& B: z, E, `) {4 Q2 B; t2 Z4 l0 f: }这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。" s9 e% o! n( S, T
9 s$ U* i: ~5 c% _$ H4 q: \
c<no parentheses>" B8 I/ A$ f7 t" W* c
Description:  3 g8 s. e! a/ |& g1 D
This command is used to reference the active node during a function's execution. $ D; v8 L: G) l/ x7 V& J9 ~, A
If the function was called using nodefunction(), c returns a reference to the node on which the function is written./ h+ C0 ^7 a  }3 C5 G
If the function is an event function, c returns a reference to the object that contains the event.
) X* k" B7 Q7 }* k! D+ f- Yc在函数执行的过程中指向活动实体。
0 `( f; T0 Z) Z2 ~0 ^9 P- _如果是节点型函数,c指向函数所在实体,
7 q. Z! M( l7 }" U5 _& W% a# |" K0 h' k如果是事件型函数,c指向事件所在实体。' C' G2 S" N- X0 a" e; l) i
Example: 
  1. treenode current = ownerobject(c);
复制代码
 ' W$ v1 `, Z& ]8 k3 V( ]+ T! e

; d4 v3 I" U& I' fsetcurrent(thing). x$ S7 P+ P7 @9 z" R
Description: Deprecated. Do not use. # {, C0 y' T/ _$ e
Example: /% _' B" f4 x) J, f/ \5 r1 O$ Z% h
此命令不再使用。
3 [3 O- b+ d$ M( [) p& ?/ }
$ \8 r! p* i0 s6 t1 c* z& e2 w. zitem<no parentheses>
0 i4 y6 ~  ?6 R1 [2 i7 _- l
Description:  
! r. A5 M* d" {3 `; p- tDeprecated. 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. & H0 o) }% s2 I  o7 z& t/ Z
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。9 F( Q8 F, h5 c
Example: 
  1. treenode item = rank(model(),3);9 G" M3 B2 ^1 X2 _, Y3 _! Y7 o
  2. pt(getname(item));
复制代码
 
% ^1 X2 w1 `* ZThis sets the object that is ranked 3 in the model to item and prints its name to the output console.  9 j$ h, W6 g/ X$ j8 k) M" p0 J, ]
" s' {  A; L7 j1 X

- e. \( `+ t% qsetitem(thing)# K- T; E! s. Z  S; ?+ h  X
Description: Deprecated. Do not use. $ G2 F, ~( L4 H4 ]; l9 O; I
Example: /
$ P% D' U5 X$ P: J7 |& t0 k此命令不再使用。
; J& G5 O6 \5 D7 @  P* X
8 ^2 O1 B& n5 B; ?5 S% B1 |4 mparnode(num index)
, M9 I0 T( P: J2 m- X2 v( V: PDescription:    D# a9 E) v8 n6 H
This command is used inside a function that is called by the nodefunction() command.6 N% `, ~+ h7 U8 `2 m5 O) A
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
4 i/ @5 X* r7 }- a) g. Y& gIt returns the parameter passed to nodefunction specified by index as a node (or treenode). / W" W# q( l8 C- f
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
& ?4 Z- E. i3 i. E6 E% L节点和树节点有何不同?/ P# K6 ~8 N0 y) _8 }6 V' h- P
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.' U8 @8 A3 ~. A( j5 ~6 O
parnode,parval,parstr这三个命令真是让人搞不懂啊...4 U9 ?2 g3 s' E- a
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
; c5 i$ r6 F) Y# QExample:
" K: O+ N( P4 q9 z3 _) sIf a trigger/field is called with:
+ E5 b7 F) O; K& p! ^! Y* I- bnodefunction(thefuncnode, item)5 z' H6 F& D& B. I) E/ `& U' i
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);
复制代码
  1 J$ i$ e1 s" o, s

6 O: O- u7 z5 f/ B/ w! f5 S  @port<no parentheses>
; P  ]( l" f- [0 J) c2 U  b+ V! H9 s3 yDescription: ' y8 ~$ i3 g0 f" t; ^' W/ C
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. 8 m" M5 `1 Q9 R: h7 M( V
Example:1 J' d. q2 b' y* \
  1. int port = parval(3);* Z5 S% |% k6 \& `' N. g. j
  2. pd(port);
复制代码
 - U5 c4 f! Z0 j6 |2 a+ @1 `' D4 Q
This sets port to parval(3) and then prints the value to the output console.
, A0 A, e* t2 w! k; L, v9 }. }! k, ~/ m9 J' _5 p% O
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite 5 K% @' [: G6 b* {! |

3 R$ i4 n9 R7 T0 M, X8 R
8 C) J- J; e  Y/ E首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。7 l6 x) A& R  Y0 d; w
    首先在GUI中,它是这样的,如下图:
7 R7 O9 A& b+ |而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-6-29 13:39 , Processed in 0.062901 second(s), 14 queries .

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

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