全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 4 U  m" o5 T4 t4 @

1 [* Z. Q9 K5 v! c在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    7 p4 z! |4 T) S& E: k1 b1 j- q
  2. treenode item = parnode(1);9 h! i" x* U1 B4 M) k; j7 G2 ~
  3. int port = parval(2);
复制代码
 , \- v4 Y1 z) T
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
$ B2 H1 L) S6 T! H* z7 ?! U2 f在接下来的代码中可以直接引用这三个已经声明好了的变量。. ^2 q( F6 V7 L! `: L0 _% n
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
5 A2 c9 Q5 R# R" j, ]* I% B7 x下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
! ~! ]( Y' j* F" [, V7 q9 l4 r  V2 J$ G
treenode8 c9 ?& W$ k) H7 V9 p
Variable Types
4 @6 q& [; f  DFlexsim 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.# B9 M) k% ~# K9 Z. V0 p
Type Description
2 l4 i( P* K5 e# h1 R  Z4 iint  integer type  
% p/ u  K7 j. A8 H+ U7 ?1 wdouble  double precision floating point type  8 t- b- S. X% K1 t$ ]
string  text string  : J9 |# o, w. j
treenode  reference to a Flexsim node or object  
+ S3 v6 `* l. yflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
7 |3 s* l* @1 D9 _
, ], v9 c2 s/ y5 y% Jcurrent<no parentheses> ) L7 V8 N/ h% h4 N: m( g' q( L
Description:  
, D: D  {! t$ d; [  v" I& g- V- {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.
% e0 p* t2 H% O- H0 @/ q! M5 f不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。, A1 X5 ]  b- s7 z' W( ?
不解:% n! w' x: I; P0 h* W, T5 [
1.used...with....是什么意思?% U) K, n, g+ {0 k- H
以前current是必须和setcurrent一起使用的吗?+ N: x9 j& [, n7 g# O5 @, I- V4 j3 U
# `% E3 B9 y/ G# Q0 h7 }
2.as any other variable type是什么意思?2 M+ ]6 q$ m" C' M% w" o
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
, o% c$ R' Y9 M9 m- x7 v2 p' P
Example:
: c7 `2 g: j* c) i9 u
  1. treenode current = rank(model(),3);
    ' R! H( K  Q- O! [. v/ a" O1 ^6 J
  2. pt(getname(current));
复制代码
 
" u+ M" ^( z  u9 Y9 K9 {. H+ D- jThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  
3 B4 G3 ~1 k0 Q& I! C8 `7 i/ C8 m* e  t* e! W4 `
( T4 ^* u1 g6 ~$ c, f4 |5 k
ownerobject(node thenode)
4 y0 I# t% o0 q8 Q7 k" Q0 O
Description:
" ^. a/ V0 F5 q/ D, P+ OThis 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.
8 W- @/ b* R$ z! CThis 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.! Q% z" v. H  j) T# g
该函数返回参数节点所在的实体。6 j( t; [: }, e
' v6 L% B9 ?- A. b/ t4 R
Example:
/ Y) z; z/ ^8 m! f9 g3 m
  1. string objname = getname(ownerobject(c));
复制代码
   Q- u, z9 ?5 D! e
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);
复制代码
 ; e7 d. H; S! f& x0 V7 T
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.! f' I+ V$ }0 ^# O& u& b9 b0 d
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
% p/ Y. h) J$ f, n
! ~) _/ b# s- |8 [6 `5 Mc<no parentheses>$ x: n$ T5 D: Z! x6 n( q
Description:  
9 M, i/ h( F1 Y9 wThis command is used to reference the active node during a function's execution.
" o7 M* o- D0 s: M" x- v4 B5 {If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
) A6 l1 b+ L/ g% i2 x& YIf the function is an event function, c returns a reference to the object that contains the event. : Y% Y0 c- x9 x
c在函数执行的过程中指向活动实体。1 y) f4 Q% D. X+ x9 f0 @$ S
如果是节点型函数,c指向函数所在实体,
: l' k/ D/ c! g* s6 P. d6 g  V9 {: I* Z如果是事件型函数,c指向事件所在实体。# f2 _: J2 X4 W5 A) Z- J
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
! L9 r5 B( U# \1 D5 Q1 |. ?9 Z6 n, `8 y: H
setcurrent(thing)
* Z9 J& M  g& n7 g0 j2 k
Description: Deprecated. Do not use.
: V7 X2 i/ s* |4 ?$ \) c! mExample: /
2 b& t0 U* i5 A: B' O9 a" _% X2 y此命令不再使用。- H% @5 w; M# O* `) P' U  L0 X: Z
7 j/ k( t- f+ z
item<no parentheses> ! {& _4 F" m" X# H3 D
Description:  0 Q% S: N% Y- f; I9 H4 r6 R; J4 s0 M5 q) O
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. 2 Z/ [% O3 O9 t
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。9 b: [+ Z# `. n/ y5 t6 s+ t& p
Example: 
  1. treenode item = rank(model(),3);
    ; U/ o' B8 f( t6 t4 a/ ^
  2. pt(getname(item));
复制代码
 # T+ ^; Z7 G! f
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  2 V) u% X, L+ A2 a3 ?

+ {9 J3 w4 |' B9 Q$ z7 a2 v$ Z3 C& K4 A$ G& N) ~9 i
setitem(thing)' I0 J4 j9 _7 n$ f
Description: Deprecated. Do not use.
' I& V: I9 T3 F% z. ^) O4 HExample: /$ q8 ]# E6 L3 ?8 y, w* T# T' W
此命令不再使用。, w, i! \# z/ g, B" `# o. m2 d5 P

$ }4 t! e0 I/ wparnode(num index) * m5 O% k' A5 r0 A  \" e% m
Description:  ) ?1 a2 l# |5 d; |0 p4 q: S5 L
This command is used inside a function that is called by the nodefunction() command.
: k! M( I' ?1 {" V3 C1 Y) {/ Q此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
8 E  b8 m8 }$ j' {- k1 OIt returns the parameter passed to nodefunction specified by index as a node (or treenode). # M3 s' }. ?4 V" o1 i) z) N! t7 W
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
3 w8 L' x; p4 X5 P5 y节点和树节点有何不同?" ^4 J# w0 Q: j* t
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
: U! d" ^& f9 {parnode,parval,parstr这三个命令真是让人搞不懂啊...1 ?. a1 L6 T4 g, C. r# E
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 3 a8 D9 M2 W* q- n: ~& U; [
Example: $ q5 }) W. d- J# g6 t9 a+ ~
If a trigger/field is called with:
4 |" h; |5 P$ Q# M4 Z9 I, b! Rnodefunction(thefuncnode, item)5 v9 Q6 S% a5 \. F( Y- G& M$ e( S0 B
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);
复制代码
  - T2 C( s9 N: E

, i9 H. |) ?* I) U  @  C0 h! S0 Oport<no parentheses>
" Y1 ^  Z9 B0 t. e8 |Description: . v6 x. g7 g% {6 m" J% Y. z7 G
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.
* I% c$ g0 U( O* u$ @) E3 k$ E' yExample:/ t$ r8 R& F; P# r! \
  1. int port = parval(3);
    $ }: {) i  _+ ^/ C# q7 H! }" V3 B! _( m
  2. pd(port);
复制代码
 8 Y( Z% n3 l6 y' {/ g9 Q; s4 L
This sets port to parval(3) and then prints the value to the output console.  P: C  n/ j# }$ w) S# }, u
3 ^# J3 g6 y. q; N, @; m
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite 1 f  p- c$ f( N1 u* P# Z; r
- A/ Y0 \$ S) d! A' Y
% ], H3 \  f4 e' _2 I& l, Q
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
+ q  y6 R3 E+ `% |. N+ C. {    首先在GUI中,它是这样的,如下图:
4 ^/ T. N- L# t! w( l2 O( v而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-12 06:38 , Processed in 0.065832 second(s), 14 queries .

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

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