全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 5 ~; v5 F# _6 J/ W3 [- u

* H0 g, |' }' d- @在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    9 D" A) G" s' T! P4 t; n! v0 O
  2. treenode item = parnode(1);& P2 Y7 x8 f. T" q* }8 w
  3. int port = parval(2);
复制代码
 
& f! a# T1 X, F: V; m意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。+ x8 C3 c2 S; {2 @
在接下来的代码中可以直接引用这三个已经声明好了的变量。4 D; X' t! T- A' |
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
, ]1 n9 i7 l( [2 |5 R下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。0 I3 f6 a. O! n' V

1 N0 x! S+ B; a+ @treenode7 d7 ^& ^6 |/ S1 T
Variable Types
$ |) W' [: a2 ?1 w. uFlexsim 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.- R$ ^! r) r- Y  t+ s
Type Description   i" M2 Y( c1 |7 X$ w4 e) l8 e' k
int  integer type  5 u. g1 t" \- B1 f  w
double  double precision floating point type  
- \2 A9 u! q+ Z* P. t8 z  Astring  text string  
1 K( @' H3 T& s+ a1 M4 m5 Wtreenode  reference to a Flexsim node or object  
( ~: q- t; c3 N7 i' m) ]8 Jflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。: {5 i8 i# u" n2 g
( \3 ?: }( @- C! q" y
current<no parentheses> 2 M5 G! e# b0 r
Description:  
; y7 `5 x: c/ U* lDeprecated. 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. , `. q+ V# e+ d0 |# p. r1 ^4 ^
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
4 j: I) [+ o/ h4 @+ `; t不解:
6 v+ M+ q( C$ D1 o$ R+ P; O1.used...with....是什么意思?8 }5 C( O5 k+ O  A! m: Z; B' t
以前current是必须和setcurrent一起使用的吗?
% w% B7 O: T8 w) B9 J7 o0 d: }& e% b
2.as any other variable type是什么意思?1 X8 r% s/ b4 j; a% T  p
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
: Z! E' ~9 E, }1 G5 Q
Example:
- E! \( o; y! }, Y* N- E. x
  1. treenode current = rank(model(),3);- F5 O. j; V: j$ x& J
  2. pt(getname(current));
复制代码
 + j7 E: t1 a' h' L& r
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  + ~8 u  ]3 |2 d% u

' M1 |( @$ G* W% f6 z; H: q
7 i# f" s) @, h. v: V6 q; [* H/ Uownerobject(node thenode)
4 X* w/ I& C) W% x$ k) K- I; _
Description:
, a2 O6 \2 z$ _* T, s7 _) _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.
& h% {6 X7 u4 W& s+ h5 x% PThis 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.
/ Y% h( L& ?. K& d- y该函数返回参数节点所在的实体。- h% C9 f. W$ T, c- H

/ u! U1 y! F% l) V- i" BExample:
7 z; I: z! Y2 d5 b
  1. string objname = getname(ownerobject(c));
复制代码
 6 c3 D6 q( t  t3 F; {9 g6 x& i
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);
复制代码
 7 C" n0 a5 z8 P! Y  N) _
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
9 p* M; E, X# k$ Z% t+ k这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
8 h: F/ S) k: x2 U6 Q) K  E2 z8 l+ k" M% t
c<no parentheses>
% ]3 {! S# L) h; zDescription:  * N! A" [: V9 c# J0 b9 r
This command is used to reference the active node during a function's execution.
3 L% G" I% \, yIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.9 `' u7 u8 |5 `7 J' ^4 P+ K1 D$ B+ ~
If the function is an event function, c returns a reference to the object that contains the event. % T& X9 a0 o1 W$ Q: ^
c在函数执行的过程中指向活动实体。4 |: t& P/ z% B, g
如果是节点型函数,c指向函数所在实体,1 a+ v' e% F% L, a: Y9 o2 V
如果是事件型函数,c指向事件所在实体。
; Z4 z) J& _" W, QExample: 
  1. treenode current = ownerobject(c);
复制代码
 
/ c7 D3 Y) V, [4 `) t* `5 I- r. m; Z1 e$ S' T; {* w0 V
setcurrent(thing)
4 {( C# [4 h$ S* t9 I
Description: Deprecated. Do not use. 6 F2 s! ~' h- s* k0 Z/ d4 s
Example: /
9 C" ?& v; N/ Z9 m4 l4 M% E, d此命令不再使用。' P4 E% \; W' i6 P2 F& U, q

/ A2 t" B8 v; [' X* r/ Aitem<no parentheses> 7 w- e" K) O- n8 H) j6 x
Description:  
3 R: O) N7 h* M2 fDeprecated. 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. # a# c+ F1 T. q, G, \
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
$ c6 p, Q1 H; x5 U7 SExample: 
  1. treenode item = rank(model(),3);
    ) G9 M# Q2 _( i+ ~+ M# t: F
  2. pt(getname(item));
复制代码
 8 P$ H$ e" E( \# x% m0 R( T
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
& k+ N9 {$ H# K. f  I0 |1 K# x$ u1 ~

, Z/ x, A$ y$ ]setitem(thing)
- j1 v) t1 _! S4 z
Description: Deprecated. Do not use. 3 R' q' K6 Y; D) |  L
Example: /; |9 p5 }9 b; ~
此命令不再使用。+ x6 D* f0 {8 r* O: q
9 \/ S3 B7 x3 {# Y4 G1 p9 C. U
parnode(num index) : v% u# m9 Q/ D8 u* h6 x' \9 I
Description:  + U% {& U" Z. @, g. S4 q" P( a( A! k
This command is used inside a function that is called by the nodefunction() command.& ^5 C* O1 q/ B5 x9 u
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
8 {& D6 ?$ Q" C  V% vIt returns the parameter passed to nodefunction specified by index as a node (or treenode).
( Y8 r1 i7 @0 N- Y此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
! \  p. a" H3 T节点和树节点有何不同?
* Z" A$ _  i3 p* \3 JThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
9 f8 x) m' F% z* Zparnode,parval,parstr这三个命令真是让人搞不懂啊..., L7 B' y. }3 r2 u* X9 q5 ?, Z' A
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
. W5 o; Q" N& ZExample:
* F7 Q3 R- T# _If a trigger/field is called with: / c  d$ F8 u9 ?+ s
nodefunction(thefuncnode, item): ~' t7 _4 Q6 C0 S# o  n  e1 M
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);
复制代码
  & M5 \8 H4 W( v/ A
. x0 h8 W- x  E; W3 ^, L. f1 Z% W2 S
port<no parentheses>
; Q4 k( m' i$ R: {" ^3 I# M: @Description:   s' k8 {. G" e. u
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.
' b  I* p' X& o0 o; y8 _Example:* k: l8 t1 L. Q/ e2 L, a
  1. int port = parval(3);
    1 U" H5 m3 T4 I' _
  2. pd(port);
复制代码
 
( p6 ?. K' Y1 Z. ]0 C, wThis sets port to parval(3) and then prints the value to the output console.
3 ?$ |9 L0 t- b8 I3 @% z/ F
0 m- F) n% v1 C% H不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite + u" N/ |  q" m/ f# U' {
; J! u+ B/ _: \& \
1 v; e$ `- Z3 c
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。# N' }6 C2 H1 e* x1 Q
    首先在GUI中,它是这样的,如下图:& c& p" i- d  L/ a1 R! ^
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-5-11 12:49 , Processed in 0.077860 second(s), 14 queries .

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

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