全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 & c; l5 q) A2 N8 r8 ~7 _
* V  s2 I& ]) q, N' K
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);& M" q* u$ w; g* e& U+ h2 I! @# }
  2. treenode item = parnode(1);
      C* g5 M" D9 i# }3 J% _: k
  3. int port = parval(2);
复制代码
 
9 \( u9 X2 M  V5 d意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
* o' i: l9 }7 ^" T$ U在接下来的代码中可以直接引用这三个已经声明好了的变量。8 I: C( ?- z6 B: ]& i7 ?9 e
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
, [! R3 U+ E# E3 y1 k下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
7 M0 i' P0 u7 Y- ]* N, ~4 j5 j6 I. E- L
treenode2 [9 _/ h. T) v. j
Variable Types% d! Q* ^' N& H0 n( J; 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.5 q  \3 d7 w7 |( ~
Type Description 9 r6 o9 A3 D/ r/ n. ?" |
int  integer type  
7 Q8 j5 _. d: A% P% n9 Q) Ldouble  double precision floating point type  
' \9 n" C: C3 \. _& H5 pstring  text string  
( ~2 h. T7 O3 Ytreenode  reference to a Flexsim node or object  ; Q8 h% l$ T( K. L: `
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。3 M$ Z1 L9 ^8 P3 d4 A5 G; R

8 T3 [+ M2 {; h! u) Ncurrent<no parentheses>
3 P+ |6 I# {5 X' K6 U! B  f' X7 X% nDescription:  8 x9 t9 y: y$ o" r  K) k
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. ( Z/ |5 ]. V3 y" e9 O
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。0 b* Z! i& f8 w5 S# f$ }: s
不解:
8 M& l# _' D0 O8 i$ R; V/ N1.used...with....是什么意思?
1 E. c; y5 `, G; t以前current是必须和setcurrent一起使用的吗?
8 S8 s& a: V; N& S' J6 \/ h* [( h" S. s, V
2.as any other variable type是什么意思?
: q7 y4 d( ^* l前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
8 c# d7 T) z# w, N/ A! u. t
Example:
/ b* q5 T* X3 Y
  1. treenode current = rank(model(),3);! b! q/ Y, B7 Y* T3 [" i, Y
  2. pt(getname(current));
复制代码
 " T4 k" f  `( Q% O  c
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  
6 H: g, C, G+ x  ^5 W
, T) ~* H1 i9 C" }3 H3 t2 @8 H: A( d
ownerobject(node thenode): f/ C8 H+ X) N  f
Description:# `, l9 S" g9 Y
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; J& F. @3 Z) @5 `& k& k
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.7 ?: h6 v" z: i
该函数返回参数节点所在的实体。
% }1 W' U( U+ ?* M( I  H9 }+ U! \2 D, @$ _
Example: - L& g; v( ?& k
  1. string objname = getname(ownerobject(c));
复制代码
 
* j, ~  P! }/ u  S& V% aThis 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);
复制代码
 , _9 v* G6 c1 W3 n$ C
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.' M: ~5 j" M  O; B$ D
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
  g5 A9 L% l* r- d2 w+ @
) |- U$ U1 T& m- Q. m6 Oc<no parentheses>: j' c$ T' p* ^! s! p
Description:  ! x: A  h" |: K1 }8 z+ p; L
This command is used to reference the active node during a function's execution.
4 U+ m( {5 Z1 J% A3 c) ~, mIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.
9 Z" _9 n* V% d2 p3 h/ P& BIf the function is an event function, c returns a reference to the object that contains the event.
, d# h% i! V" H. Hc在函数执行的过程中指向活动实体。
" e/ j; ~) Z9 u. r如果是节点型函数,c指向函数所在实体,
8 A  y/ j% ^; O7 m- o如果是事件型函数,c指向事件所在实体。5 ]& k' A, A& [- V% H
Example: 
  1. treenode current = ownerobject(c);
复制代码
 # d4 \3 R, X" Z! ^
$ S0 Y6 Y, n1 w' c+ y# P2 h
setcurrent(thing), i# ~; s7 l7 ~, f  w* p
Description: Deprecated. Do not use.
$ G5 O2 n6 o" B: y' F! C, b8 L* O; lExample: /* j$ u' j2 Y: k4 a0 O, C$ i4 K
此命令不再使用。+ Y" ~2 T1 K* u# k* m' k

+ v7 Z- t- b+ i9 w1 y: ^item<no parentheses>
" A! F- F2 x( B8 l- {( N  V
Description:  6 C% X5 |7 k+ F7 v- e
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. - I. l+ v. V- w. O: h- m6 R
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
( H' d# C# H" n5 xExample: 
  1. treenode item = rank(model(),3);
    9 N( x' Y% x8 F4 f0 V
  2. pt(getname(item));
复制代码
 + ^. K" u7 ?: d. x4 s
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  9 J% D. e; l0 u. G

( E2 ^- c. W+ i, z' I. t: j- _  l3 g& M7 D0 D: r+ O% C) N
setitem(thing)2 t  |' N% ]6 c8 T3 r% ]& q
Description: Deprecated. Do not use. & M; F2 P, w( S
Example: /
6 Z$ a4 @! e) F1 r. \' r此命令不再使用。
, I8 J8 z  a6 u+ S' n* d
" L' a' G. F  [- S; C' Oparnode(num index) 7 W# q2 }" n/ z) x& G) M
Description:  
9 f; z! t) T5 X6 e% W. D3 B! s" AThis command is used inside a function that is called by the nodefunction() command.# p" B- u: Z8 ]
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
' l# U8 y+ b" d1 hIt returns the parameter passed to nodefunction specified by index as a node (or treenode).
4 f3 [* E  n, @) z2 k2 v# `: B此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.* T) \3 k& s3 H6 s8 G/ g& ^
节点和树节点有何不同?
& E7 h: Q; H2 |. |8 M8 E* c7 yThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
4 B( R" z3 i7 f0 H2 Qparnode,parval,parstr这三个命令真是让人搞不懂啊...
* Q, `, h. _# M8 v. @- gParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. # n2 {: [+ x) r* D
Example: . G3 R( i* y( `" a, A) D
If a trigger/field is called with: : S! m6 A0 ?3 D% ~  H
nodefunction(thefuncnode, item); r4 T* t6 n) b; N: K& c' z
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);
复制代码
  + r2 W# n0 `+ r1 w5 }' j

/ p& W8 O. [1 ?/ C' r5 f9 i. F- qport<no parentheses>
$ ?  _1 G  ~1 KDescription:
: E2 @- V- I8 P4 r3 q: oDeprecated. 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.
* V% V1 D$ L# a, a. x" gExample:
. e; R" I' U$ ^1 n' N& R
  1. int port = parval(3);% o' \( r% o; H1 W& V
  2. pd(port);
复制代码
 % t2 n4 g! |  T: ?. ^
This sets port to parval(3) and then prints the value to the output console.* {  R9 o% |! e- Z! V2 G, |* H

+ I  i  L, s/ ?8 B% y4 I不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite
2 s5 v( M" v( z% q
- N  T) }' w7 D  f2 n: ~- z+ G# V; N. F% o; k! A. p; K  ~
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
6 k; Q( m' {% U    首先在GUI中,它是这样的,如下图:, h6 J& g; b4 T2 i
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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:11 , Processed in 0.067194 second(s), 15 queries .

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

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