全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑   V. ]+ r; P  i, O
! Q6 Y! y: A4 m5 A7 j
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    9 b: x1 k- x: C) q
  2. treenode item = parnode(1);1 ^- V: }2 K6 x. {
  3. int port = parval(2);
复制代码
 
( E6 z$ ~, H' J* O9 e. t5 o! i5 k" v意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
# B5 w7 |3 @! l0 k在接下来的代码中可以直接引用这三个已经声明好了的变量。
7 ^* V, `+ h" U$ i6 x! N$ S对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。. ?$ m% N1 J" B  {" H6 U
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
5 B* n/ U; }5 |! z5 D! N; k- M; T
: N1 J8 J: w- u, t& w, n0 itreenode
* B0 r2 R4 i3 T0 u+ l# bVariable Types2 Z; A6 M2 a4 Q, X- k* @. j% k
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.
9 _4 c7 A! m; `  n; ?& W5 tType Description
. Q5 k  l+ V! E8 Xint  integer type  * P7 u/ r+ J3 z
double  double precision floating point type  
: z' M& E( f7 h( ]! B8 Xstring  text string  6 Q" p0 D0 I1 {& A1 p
treenode  reference to a Flexsim node or object  
% H6 X" G8 c' @. f9 X) Z( }flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。2 _. }% ?8 \6 @, O  l
3 Z+ C' k8 C0 v- d8 n
current<no parentheses>
5 h) c, z4 y( l. `. s- @Description:  
! u$ y2 f: I. Y" |& pDeprecated. 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. . S  h; t2 F( M' V, F- U; s6 f5 I
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。. t9 x, ~) I  u3 M% J
不解:
/ p, f/ [! k, N2 }/ f1.used...with....是什么意思?
9 G" S2 f8 R! V以前current是必须和setcurrent一起使用的吗?. G/ s0 q/ k+ ~3 G; f! u
# x$ Y0 V8 o/ q1 a' t' X
2.as any other variable type是什么意思?
" {+ r+ y. J4 r# M前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?

% Z- V+ K$ L6 i4 BExample:
4 O; W/ a# E1 ^: S7 f
  1. treenode current = rank(model(),3);
    ( x; L7 O7 _/ P! z( P% H
  2. pt(getname(current));
复制代码
 
( z& U/ X# q: J1 H+ e2 PThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  ) P9 v! ~4 S6 \. }0 a3 j

! q! L& W* s* L  a0 \
/ s8 d/ ~  a- j& w- j0 Rownerobject(node thenode)1 K2 t* I3 ^% W8 v8 l
Description:
' N  x# q& c1 {& \4 m: c$ vThis 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.0 q% f- }' _+ r8 _
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.
* C0 \; a& k3 q1 I* w, M7 G! J该函数返回参数节点所在的实体。
7 a+ q  m7 S8 O' c7 a9 n! s' L4 v0 {' j* n1 p, h# u
Example:
8 R$ j% V! F5 r; C% K
  1. string objname = getname(ownerobject(c));
复制代码
 
( B! |) l* T, N! jThis 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);
复制代码
 5 i# P0 U' W! _+ F8 e+ A& C3 R
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.4 O. B; R8 |$ n+ b
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。: F. L& {2 S% i0 y1 k6 w" L* D
4 _2 @6 |! l. G; L" G) t% T% d, `
c<no parentheses># u2 H1 a& L, `, [  H9 g
Description:  
0 d. j' Q9 ^! P, C7 \. d* _This command is used to reference the active node during a function's execution. , b( D/ N4 t, ]2 O- P
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
$ ~* c" c* q; ?' Z" KIf the function is an event function, c returns a reference to the object that contains the event.
, w0 f: {9 w+ N/ G0 pc在函数执行的过程中指向活动实体。4 @( r3 ]5 v; p3 ]
如果是节点型函数,c指向函数所在实体,; F# L7 a5 Y) ^! `4 O
如果是事件型函数,c指向事件所在实体。  L- ~! _9 u; T5 V
Example: 
  1. treenode current = ownerobject(c);
复制代码
 % O3 F* F0 Y& X4 }  J: b8 c# `
* l; r8 P/ z; Q( ?+ s# u
setcurrent(thing): h( u8 f. t; k, V" i; ^
Description: Deprecated. Do not use. $ O" t8 U$ ~6 O) ~
Example: /
, _- o) U' V* s7 H! m  i& d此命令不再使用。0 e8 f; ?2 U( i* N% g4 I+ t. z
3 g: N! k6 l0 }  Z5 E
item<no parentheses>
. \7 t' F2 d' b6 s3 e# u
Description:  2 q6 Z: }7 ~5 g0 w) j
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. 0 i) Y" [0 P1 ?
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
6 M* ~( X' Y' r! ZExample: 
  1. treenode item = rank(model(),3);
    $ i7 X- I* X! {# k9 S* ?- F6 {
  2. pt(getname(item));
复制代码
 7 L6 g1 Y8 m8 [; i2 E. Y# W8 U0 u
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
1 O$ ?' v# E6 v/ V: a
: ~$ B! h1 q# [- c9 V4 Y: X
4 o% c$ A! g3 R6 ~setitem(thing)0 ]: c3 z: I$ H3 P& {
Description: Deprecated. Do not use.
) N! z  G% F0 ~7 P, U  H0 Q5 n8 oExample: /% H% D# x9 T8 M6 x
此命令不再使用。6 w) ]8 L) o" o8 w# f" a% P/ Y% {6 a

" B$ ]. \$ a5 Y( p2 l4 cparnode(num index) . z% ^0 H3 q( P. r. p8 C
Description:  
9 G3 j! ]- I1 a+ ?  r1 _4 b, WThis command is used inside a function that is called by the nodefunction() command.7 [* o- D, Z1 O$ X  ]+ ~* q: Y
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?2 A- F! g/ d' B7 S; ?/ t1 x  C$ A
It returns the parameter passed to nodefunction specified by index as a node (or treenode). 4 M$ t! K) P' w0 |5 I: u+ a8 J
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
% k; f+ \) Z& k! v  s/ c节点和树节点有何不同?9 o" F' h' _# F, n) B
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
) _" M3 ]# c6 K3 Yparnode,parval,parstr这三个命令真是让人搞不懂啊...4 v4 N9 o! r* l7 D& o
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
, R# L7 G! O9 o; o: }+ MExample:
0 w- \0 T- w# o+ A+ U  l6 N, SIf a trigger/field is called with: . U7 Q( u/ t3 r5 y: a$ c, I# b! O
nodefunction(thefuncnode, item): I, J0 X! Y+ b) i
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);
复制代码
  6 v) z8 ?- D, m5 e& M6 a
; b5 N3 K5 ?' `) Y# v' C
port<no parentheses>' q0 x0 R- M  {/ q$ W2 V
Description:
2 f4 |; f* D) _& R3 zDeprecated. 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. : L7 u. G  W8 g; j. i) i
Example:% V; O$ b- F1 y& L$ q
  1. int port = parval(3);
    / T/ @+ j: u. J6 V
  2. pd(port);
复制代码
 8 V$ N2 w# f# V9 E. |2 }% }
This sets port to parval(3) and then prints the value to the output console.* X; b+ {4 S7 u4 Y. T& J: ?

$ W( ]6 v8 s, G% ?# ]7 ^不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite 2 f  a5 `* Z6 n) d2 @

; R3 r1 {: v, N5 ?# f. w
4 m4 O. A/ h" K- [( A1 U首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。# C- `0 J  i! a$ N! v. T) R7 E5 R
    首先在GUI中,它是这样的,如下图:
9 h$ i$ Z2 U0 `9 e: ]) y而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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 14:45 , Processed in 0.088033 second(s), 15 queries .

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

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