全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 $ i! ~, j2 V/ w, {1 G

2 _& k' R5 h3 q2 U在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    2 J, c0 B! E2 \7 r+ I
  2. treenode item = parnode(1);
    ) [) j1 a) F3 w  m  Q$ r
  3. int port = parval(2);
复制代码
 
. O% I2 G8 g3 S! M" X: E意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。( D! d1 a5 e2 W& C& m5 D- k9 x
在接下来的代码中可以直接引用这三个已经声明好了的变量。
6 O& x/ \; v2 m5 S8 w/ w3 [- ^对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。. J2 d( r; d, a
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
) A  ~9 A3 ]3 y
* D% Z/ y6 B0 g! y: `# Dtreenode
$ X, c( Y+ j, W! `Variable Types' I3 X. ], [6 g8 j' T
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.
# D: C' S! {6 w' n  VType Description . \" X' j' {& c; c1 L& a
int  integer type  
$ ^8 n# p7 Q9 b( O7 E8 ]9 vdouble  double precision floating point type  
" r$ Z& u; X: I3 P6 T- P8 }string  text string  
2 N1 |8 }8 E3 ^5 ]/ b+ q+ d# \1 itreenode  reference to a Flexsim node or object  
3 ?9 H7 ~) |" n. K0 U! q" d9 G, |( @flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。$ \2 A* f4 i6 p& W+ V, s

2 p5 E- e' m: k. f1 l# Mcurrent<no parentheses>
: X- l- n, X8 L9 R6 c0 ]1 GDescription:  & |' ^$ O, O7 I; R+ e' f, o
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. ; p; b& G; N3 N0 C7 z) q4 W, @7 f4 {, R
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。+ x' Q  p3 a& k+ \
不解:
+ F0 \, Y" R4 Q. T1.used...with....是什么意思?
% B9 f$ ~& d8 T以前current是必须和setcurrent一起使用的吗?0 z7 |" G; M8 Y( J" q

$ Q  k8 N" N6 O' o; M' \1 o2.as any other variable type是什么意思?
  B) X, g3 f* K8 O* r前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
$ {: G4 j3 [0 h
Example:
8 o9 w. }! S* G2 p& r: v' U4 R: R
  1. treenode current = rank(model(),3);, B0 U  J4 e9 s7 i$ t: f9 [
  2. pt(getname(current));
复制代码
 
/ H7 _+ ^1 e, i. y4 z& w4 \: [3 }( cThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  $ r; H6 x$ ]! T0 ]9 Q8 P
) K$ _' b( D7 R& t2 E9 y
9 c" y8 O' @! u/ \! {# c
ownerobject(node thenode)
2 N# |+ ]  W2 X2 K- l4 P  u
Description:
* d* t# v) f% A6 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.1 h3 J# n. C) F+ _, e) }/ O$ ?
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.
/ z6 F1 h) G3 V) N该函数返回参数节点所在的实体。
/ k1 S' M# e( |; P' h" A2 i* N; A5 I' K! W# W) D; U
Example:
  R+ L. M4 a- {& U6 p
  1. string objname = getname(ownerobject(c));
复制代码
 / c6 c- B, |  m3 P# G( v
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);
复制代码
 
  S0 M. I4 @5 k6 ?This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
# m  K0 a+ {& d3 K这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。  `% Q9 J7 }- M* H) C, o7 h
$ G2 [% n' v1 g7 |, p* c! u  {
c<no parentheses>! p% C5 E% J; Q8 `2 D
Description:  
; H% r7 A, F. p! s1 Y* UThis command is used to reference the active node during a function's execution.
" d% e+ {5 B! {  u! w+ T2 MIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.
: P% G  c# h- }7 }' ^8 A& d! ^, LIf the function is an event function, c returns a reference to the object that contains the event. - ]- X! B6 H  X) Y  ?8 F5 |
c在函数执行的过程中指向活动实体。
. {5 r. s( u# k$ p1 i: x) l如果是节点型函数,c指向函数所在实体,
6 ~4 G, @: k2 N如果是事件型函数,c指向事件所在实体。
& L% {2 q: O$ ^. o4 M$ e( RExample: 
  1. treenode current = ownerobject(c);
复制代码
 7 {, j& k- b- T1 `0 ?- t5 x% N

1 `* D! Z& `7 jsetcurrent(thing)5 I. l  i2 {5 j' O
Description: Deprecated. Do not use.
" e5 |& h. Z8 U2 ~, w) M) ?9 `: w' DExample: /
$ G; Y  K! q& z# Z; e7 {  R+ s此命令不再使用。  N7 K% b9 s5 ]; G' H
. y/ A( X8 w7 E: i4 E/ e+ b$ i& M
item<no parentheses>
1 b0 V; p' G6 H8 k! L5 l7 I6 M
Description:  
: ]% c7 w9 O% M* [( |- ~( ^" ], E7 SDeprecated. 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. % t7 ]0 t+ n+ A
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
& d$ y  C! e. V  bExample: 
  1. treenode item = rank(model(),3);
      Y% B3 ~; n. j. k7 W# T
  2. pt(getname(item));
复制代码
 
- [- ]7 z# }2 ^+ M: k4 c" t0 G* ]This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
; P8 M) Q1 \" B/ x
+ N- X$ x. p) [* r& Q
* j4 O4 T% c) I0 W2 {7 K: Wsetitem(thing)
4 _2 S! H7 |3 A) R5 E; T5 r6 |
Description: Deprecated. Do not use.
; ]5 D" e' i4 g. K" ?1 T" yExample: /. Q6 G" f- X2 ?$ V, p" ?( v$ F8 ?. c
此命令不再使用。
+ w5 v, e5 H$ k' Y& G4 |: s! K
7 p4 |  R& j! k" S0 @% Q1 G  h  w4 T  tparnode(num index)
% ?- l+ M& K3 A: O) a% K% DDescription:  ; q& J/ E) j7 N/ E/ N
This command is used inside a function that is called by the nodefunction() command.: K6 t" ~# E1 j6 G" {$ R
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?  M8 u) V) G  u: c% D
It returns the parameter passed to nodefunction specified by index as a node (or treenode). 2 C! [; T" g) I9 G9 }
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.- S+ v1 r+ S% }& T* R: b* w. S& W" T
节点和树节点有何不同?
/ M. d1 v+ Z3 K8 @5 J5 [2 h2 ~The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
1 ~$ K) `5 W6 zparnode,parval,parstr这三个命令真是让人搞不懂啊...: B6 }& G" ]' e2 `5 y+ F
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. ( r% d4 Q6 r$ b$ T+ q# N
Example:
. A( ]$ m  H/ f% L9 n$ j: sIf a trigger/field is called with:
5 F9 a: x  _6 M' |nodefunction(thefuncnode, item), M3 t, s- b7 a3 M. m: F
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);
复制代码
  & z7 A7 c' k2 e" V3 D1 G
8 l9 H0 M+ P9 U1 ~! w, m  d. ]8 t  z
port<no parentheses>! f- m8 {$ k6 f, \  Y; Z- r
Description:
8 ^$ d$ \7 Z' i( y: h( [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.
, n% [7 {. }& e, Q) uExample:' q% r+ w, u7 i. r' {
  1. int port = parval(3);: ?" e1 O; _6 l+ P0 V0 F1 n
  2. pd(port);
复制代码
 6 i5 E5 J* ]& r1 T
This sets port to parval(3) and then prints the value to the output console.
, M3 \" {' e  e$ x! t6 |: b2 \: `1 x% x& S6 }7 Y
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite
" F, [, f/ X  L5 g5 l
. q; m7 r. q4 k: x7 R
3 M+ Y4 L) z8 g2 o/ _. P首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。2 J+ ]. f8 Z$ H! Q6 q
    首先在GUI中,它是这样的,如下图:+ n2 p5 t5 s. L' 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:13 , Processed in 0.062269 second(s), 15 queries .

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

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