全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 : A+ b, v: _4 V% f  O6 s
+ F3 S5 V7 ~' O1 y4 V
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);8 g* B  T5 f$ W0 i% P! S/ K
  2. treenode item = parnode(1);& g3 [- c: [# ~+ S) f* E
  3. int port = parval(2);
复制代码
 
$ q9 w3 i1 E& T5 F意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。0 v+ f9 j* {9 f/ s9 w
在接下来的代码中可以直接引用这三个已经声明好了的变量。" }. u; |% t/ `/ {4 k' ]
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。8 |1 {7 S! A3 _/ H, ]/ o  b3 F
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
  A/ a! [: `4 [! C2 R
* J/ G8 q) G( k1 C7 v, wtreenode
$ M2 p6 w* D1 ZVariable Types* W1 U) v2 r  [* I
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.! s! d3 z/ J5 ^$ r- Z" l7 K2 o
Type Description
; o( D# J/ ^1 j0 u& Cint  integer type  
. v$ W8 ~1 m8 l0 q! }- odouble  double precision floating point type  
2 q- I2 D7 U$ m5 Vstring  text string  % f( Z4 `9 i! \. I' Q
treenode  reference to a Flexsim node or object  # t4 J, L8 ?( w6 w$ |" k$ S$ `
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。4 t* N2 M! q3 M6 N$ U

( d4 a" F9 v$ p4 icurrent<no parentheses> - o5 z! H3 G# ~) o! T, k
Description:  : R+ Y, X6 L) N, i& U
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.
! x  {- H) H- Z8 c3 m( m/ V) v不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
& Y. r9 U& H& O9 _" H' s不解:
; ~$ t& x6 t0 X& f4 H1.used...with....是什么意思?
1 t+ Q0 [  H9 i4 T5 {以前current是必须和setcurrent一起使用的吗?  E9 }* D* H) B# U- C' }% G

1 i6 d+ V+ E2 v& ?2.as any other variable type是什么意思?
% Y4 h, U) w3 N$ y前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
& x* W' A) B8 ~; y  D9 l
Example:
% z, ~! ?- _* A2 b
  1. treenode current = rank(model(),3);  a# E) L) I7 t: M4 |. Y/ o
  2. pt(getname(current));
复制代码
 % n: j& W7 }0 e+ \; U+ C
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  . k1 A2 J9 \; D- q7 D" z5 v

5 I9 Y9 D7 i2 h' M# W, a" h8 ]4 r- g9 E
ownerobject(node thenode)
" y& g' n7 \0 L8 B1 d7 Z8 z( y
Description:7 V6 c2 Q6 I9 G- j2 h
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.4 a! l& C3 ]5 \' z: j
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.
1 B/ k$ n1 t* f$ T) p该函数返回参数节点所在的实体。
% g. {/ B: y6 y3 x, z/ q9 _+ M% Z- z9 T  A/ Y% v+ ?
Example:
: S7 I% `- C8 e* t
  1. string objname = getname(ownerobject(c));
复制代码
 7 S& L4 ?. B4 E; x9 l
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);
复制代码
 ' \' O+ n2 z" a! [
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.4 h2 `, c0 i4 E- Z
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
4 [( M, z5 U" L+ [! S  Y- T& f
6 i7 K& ]! X" n! ]* ~+ l9 yc<no parentheses>
: `1 P2 r3 P6 U4 H# o6 }+ d7 kDescription:  
* m# }* G1 |! d# ?7 m5 x$ OThis command is used to reference the active node during a function's execution. * d9 U9 U- a( a3 K; R. K- t( l
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.. O6 m7 D6 h+ p6 |8 o
If the function is an event function, c returns a reference to the object that contains the event.
( ~& e7 P2 h$ j; _+ |c在函数执行的过程中指向活动实体。
6 S& Q/ X) a* B) C3 L1 q( u如果是节点型函数,c指向函数所在实体,) J, G$ L* I/ H& A6 ~8 y0 H3 h% [
如果是事件型函数,c指向事件所在实体。
9 `5 i! D% U% o$ a1 {& Z5 KExample: 
  1. treenode current = ownerobject(c);
复制代码
 7 Q! |# L. w1 }# t% z4 z( H1 Q* Z- H
: J. E1 c0 O- n: N2 f$ j' |  ?
setcurrent(thing)
9 s2 u$ v# h- ^! h6 C7 `
Description: Deprecated. Do not use. $ {2 f, h, J9 E$ W; S$ w/ R  D
Example: /
" ^+ r3 s8 q5 ?  L此命令不再使用。
7 w( E) Q7 @( p2 O+ z
/ X; U2 }7 d, o1 x  K8 Yitem<no parentheses> 5 R( F$ B$ z! d% K8 B) z3 M& u
Description:  
& @* p$ l) M$ _2 RDeprecated. 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. & J8 q( s; A. W9 g& I
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。2 b) `3 U0 @  K3 {3 c% I. g
Example: 
  1. treenode item = rank(model(),3);8 g9 k; H* g  \& I. V  F* |! S
  2. pt(getname(item));
复制代码
 
) J- X% D/ u4 _This sets the object that is ranked 3 in the model to item and prints its name to the output console.  # M7 Q" F. n  h* U, D) S- {8 b$ I

) S3 [9 l3 T0 T3 W8 Q8 G! L5 O( D+ }1 C
setitem(thing)+ i: A& r4 S% F: h4 r
Description: Deprecated. Do not use. 6 w! ?" Y; R+ i2 y# S
Example: /* U9 c/ T# l0 l  t5 K& w, F
此命令不再使用。
+ ^7 t" z7 r: c% G
, X7 P4 S) y$ x: z$ U# D( ?. oparnode(num index)
+ j9 A( \" Y. C+ ~8 ?; e$ PDescription:  
5 Y% d/ ?4 |9 n0 qThis command is used inside a function that is called by the nodefunction() command.
: E" R  i$ T7 O. X4 c) o. K9 l此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
& t, T2 _$ l9 o; u+ C6 nIt returns the parameter passed to nodefunction specified by index as a node (or treenode). , l# @# ?) R8 S$ E8 W
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.0 K- W0 l7 V, `$ c% F% I
节点和树节点有何不同?' \: y" Q: r2 _$ J9 {, W; |6 L* z
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.2 c. ?! C) v. ]; d9 |6 c
parnode,parval,parstr这三个命令真是让人搞不懂啊...0 `5 T( o. L( O! ~
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
% b. D: y; ^5 o! G2 \# yExample: ' Z3 J; d$ o  `6 I
If a trigger/field is called with:
1 G# y' B0 B0 T" d4 t: U; fnodefunction(thefuncnode, item)0 T0 b4 `* j; \9 ?2 x4 |
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);
复制代码
  ! x! P$ |* B" U! O4 b& M5 y
* u2 e( Z) U! V  a- ~6 H) G
port<no parentheses>
% P3 Y! u1 e; w- t' `/ {; Y2 d0 T+ WDescription:
: L2 b5 g* E0 @1 g5 V4 v* j3 |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. ) G  O& F  \+ `# s* ~
Example:
+ k( N' H1 _. g2 x7 |7 K5 F
  1. int port = parval(3);
    9 T& x; b+ [  Y" u% Q
  2. pd(port);
复制代码
 & k; ?* O9 U- x; N6 P3 P
This sets port to parval(3) and then prints the value to the output console.
, [! N8 ~/ ~* o
$ I& x) J9 b& o7 y, m$ ^不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite / j9 u+ N3 t5 p. _5 V( q1 k8 A
# O# s% `* S$ l$ u9 i# A' z" D" X

3 w' b' d) S7 n- P2 \! y首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。* I$ p. s7 D9 x, b% k" Z
    首先在GUI中,它是这样的,如下图:
) S  j2 Z: @* c5 H1 W) O/ _: f; u而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-2 22:36 , Processed in 0.067161 second(s), 15 queries .

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

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