全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 ( ~2 S  c# I  W! F* D4 I
- T% I1 D% n' c& z6 y
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    - E# K1 ]1 x- ^) X
  2. treenode item = parnode(1);
    3 a! P% \' |/ k; L6 R
  3. int port = parval(2);
复制代码
 
! D4 b0 [7 |% o$ D意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
* L) g* d9 m  A2 _' W( F在接下来的代码中可以直接引用这三个已经声明好了的变量。, R$ i+ c+ R: I  w+ k2 Z. J
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
* p8 k* Q4 n, L+ u# ^1 {1 b下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
; i8 F* D1 e$ Y# t* k0 i- l1 S. Q7 g
treenode+ H8 G# v/ }& v; `$ d
Variable Types
$ N( x5 N, B( o+ {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.
! h- m- T( g% Y1 K( N0 sType Description
1 K, ]. [1 y% ]0 k0 Mint  integer type  4 X% ^: K8 Q/ M5 T" Q
double  double precision floating point type  4 A: w% ]5 `' q. ^0 ?- J
string  text string  # p- t3 V! I1 [$ u8 Z
treenode  reference to a Flexsim node or object  
. {8 B. l# E: B5 c; m5 q) `/ `flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
1 C0 f- K9 w# U6 Z' ~# H) }, j4 T$ V. w& i5 E% f. A- h4 u" @
current<no parentheses> ) _% W+ q% P) e) B
Description:  
" n" ]5 v, c" T( o7 F& FDeprecated. 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.
& U" `0 I+ j" @% Y+ X不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。1 i/ e6 L: G5 Q. X2 U$ p
不解:$ ?1 L" ], V* p' k, {
1.used...with....是什么意思?; q6 b' ]+ P) f
以前current是必须和setcurrent一起使用的吗?8 E2 y* L! Q1 N5 H5 o4 O) K
. O8 x1 }; Q8 x5 B0 h3 k+ @
2.as any other variable type是什么意思?$ c3 M% t$ c" x$ Z' A0 O
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
& r3 P+ e7 p' G* Q# y
Example: : I% A0 ~; W+ G
  1. treenode current = rank(model(),3);& ~( ]8 Y$ U9 O" D
  2. pt(getname(current));
复制代码
 
1 k0 y9 d; q- G9 g! pThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  2 q: n# n1 [# ^: o. r
' K8 L. W' H$ i; U0 N8 w7 I

/ P! y' V8 F1 Z; B* ?7 gownerobject(node thenode)  e, U8 I3 K- b5 R% g
Description:
) X* u1 \2 n9 W* m, lThis 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.
/ r7 q5 x$ P5 C3 _* DThis 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./ r5 r: h9 l& j; f
该函数返回参数节点所在的实体。; `* X$ m6 \4 p8 W. P6 {
$ z. S8 X- w7 r4 W, t' i
Example: # b* u4 q' [, a* w) V# N# ~
  1. string objname = getname(ownerobject(c));
复制代码
 / |: n- T3 R; ~  _' G% |# X
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);
复制代码
 ( j2 D6 ]8 s. R' ?, R
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.& |: R: K9 q# |  b+ S; z' A
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。1 Z9 f; A5 G0 |, t9 [: T
" m8 \" A2 @* x# Y+ B
c<no parentheses>4 X- P- o# e, b
Description:  ( }: M3 t8 w* x% w& K2 p' x
This command is used to reference the active node during a function's execution. 6 f( V- n0 M: Z$ b
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.( V- B3 d' ]8 W$ v- ]' r
If the function is an event function, c returns a reference to the object that contains the event.
" B- p* [/ Z* b6 a+ o: i5 ~" n( Ic在函数执行的过程中指向活动实体。' a4 S# L# t) I2 E2 B; W, l
如果是节点型函数,c指向函数所在实体,
' m# _$ x# S  @5 y8 ?# C. {如果是事件型函数,c指向事件所在实体。9 u) u. O' {" A0 C
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
% C, y3 h9 ~$ |# E! E5 X# y
7 i+ t- z$ F5 S2 ~* K4 e& {7 |setcurrent(thing)! a0 f' h- A8 Z# s& F1 H9 [% x* J& U
Description: Deprecated. Do not use. 8 u. e4 ~+ p% A# x
Example: /
* V+ Z# [+ T' R' i此命令不再使用。
4 c6 L% ~: g4 V: X( S
- ~6 C1 w' I, o; ritem<no parentheses>
! c; P5 Q- ~) S: k  h# b# L& G9 I- l
Description:  
% l$ t8 h3 Y, e* 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. / e8 C- d3 |( u3 g. K, K
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
: h5 y2 X: T* {9 l6 c' m2 jExample: 
  1. treenode item = rank(model(),3);
    # a* u+ Q3 Q  P* w$ a
  2. pt(getname(item));
复制代码
 
. p2 n, Q( q& cThis sets the object that is ranked 3 in the model to item and prints its name to the output console.  
& g0 J/ r5 C- p' e: }4 P6 h
! R: B/ M9 M5 i
6 r$ P: I6 b% A# U) Rsetitem(thing)7 O/ }  X  k6 u, L# t* N+ h3 Q# D
Description: Deprecated. Do not use. 9 G0 R5 Q* R  Y4 N
Example: /! x, M3 t! U! x
此命令不再使用。
" o" z0 q' o( y# p! U/ U/ f7 ~' j; l/ }" Y
parnode(num index)
+ O! T" V# C4 H% W. i7 ~" ~Description:  1 m9 W, s+ W7 i9 M5 O' |( G/ z
This command is used inside a function that is called by the nodefunction() command.0 _8 Y: e0 }/ J: U
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
# s3 R9 A( c7 q( N8 }( @& I1 RIt returns the parameter passed to nodefunction specified by index as a node (or treenode). 4 {0 W2 w8 c$ ]. G
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
- w+ S7 m0 G! V0 X: ~节点和树节点有何不同?2 B1 m# z, |+ I  K& b4 K: ?$ Y
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
5 Q9 U1 \9 G+ Y3 O% n3 P6 hparnode,parval,parstr这三个命令真是让人搞不懂啊...: x1 U2 C  K8 F  K# o: c1 R
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
8 O' @3 E& ]+ N; O- m, [2 C( c5 nExample: 3 _' Y7 `8 l$ x( I
If a trigger/field is called with: 8 _! E; u% D/ r1 \3 [; [' ~
nodefunction(thefuncnode, item)2 q, }# ^4 d) R
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);
复制代码
  
7 A, ~$ Q5 b% t- K& k3 v
4 g+ w/ }* M# r& Rport<no parentheses>6 ], v# M) t% N- W% E5 |
Description: ! `% n4 F* Q6 `  @& u: Q
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.
$ r  y  ]6 K( G7 wExample:
) p' V; s" x, q4 V6 ?
  1. int port = parval(3);+ n, ~" L3 }( R7 r: z/ {* f( h
  2. pd(port);
复制代码
 + }8 r4 W" i6 }( @3 W0 D
This sets port to parval(3) and then prints the value to the output console.
# Q! y$ ~' N( x3 n
4 b. q, s% I( `; Y+ M. F不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
5#
一骑绝尘 发表于 2014-8-20 10:01:35 | 只看该作者
C 一扫疑惑,  但parval(),parnode() 还是有点不解
4#
1010265352 发表于 2014-8-11 13:56:35 | 只看该作者
额,很值得一看
3#
fl2014 发表于 2014-8-10 18:29:45 | 只看该作者
大神啊,解决了我多日的困惑
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite 0 o6 b5 S5 `; y& \! Z

; l- ]& {. b4 x0 b! S  [* ^* e6 U& E  }  Y8 b$ A- c9 v; v
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。) b0 `9 I& I  c) }0 @; h. ?' s( W
    首先在GUI中,它是这样的,如下图:8 Y+ G4 Q- e4 u' G: {
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|全球FlexSim系统仿真中文论坛 ( 京ICP备14043114号-2 )

GMT+8, 2025-9-6 03:58 , Processed in 0.066914 second(s), 15 queries .

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

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