全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
' Z  f2 V9 Q+ d" W, m
: w/ p0 h2 a) J- o5 i2 n在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    & R1 A. _7 ^8 i/ K7 ^
  2. treenode item = parnode(1);
    7 u- R5 j  ~  ~2 E/ \
  3. int port = parval(2);
复制代码
 
8 A2 @. B& E& m. s  o: Y意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
& o- H/ V$ J9 d1 ?在接下来的代码中可以直接引用这三个已经声明好了的变量。
7 d9 m6 j7 z+ d. d, z& v. g对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
& f* |2 f/ k& I: T, W% ^下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
2 n* n- a, r6 \
  V' I4 h5 N( |+ L/ [5 b4 gtreenode
/ x8 `9 W( |/ s+ x; r4 y6 CVariable Types
- U1 Z/ W% F" R" L. J/ b) hFlexsim 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.
4 j! a# l+ o/ S8 w/ wType Description
: O1 ?7 O/ ~7 h, fint  integer type  
" f/ Q# c5 g* u! v& S, _double  double precision floating point type  
. t. |6 l$ z% k# m+ T7 g( d4 Ystring  text string  
" P% C9 Y, Q( T4 y; X/ W2 Etreenode  reference to a Flexsim node or object  7 ?! |" Y0 q8 z8 p
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。: @$ g6 |2 R# e. h

; C8 C* a5 H# l8 C" d' @: rcurrent<no parentheses>
" v  ]* ~+ M  i! c! ZDescription:  
( T: `: Z/ W3 H: O6 RDeprecated. 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. " G. I5 q" \9 s# @% |8 T) }
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。: p- c$ Z$ d& T/ n
不解:
9 e% F' a" v2 a8 @8 C1.used...with....是什么意思?
" V- J+ S  S& c; E" H7 m( h6 O& ~以前current是必须和setcurrent一起使用的吗?  I5 `' M* `5 ?; R3 t8 D; l5 b
# @7 k2 a) N; U% ~1 _
2.as any other variable type是什么意思?# K9 S* p$ g0 n: `8 I) D
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
% L) m5 S' d! D0 Y; D4 a: X
Example:
  ~& Y! r. d5 j" Y
  1. treenode current = rank(model(),3);5 b+ w/ i# }4 }* x$ p+ E0 \* k
  2. pt(getname(current));
复制代码
 
1 ^8 C* x3 ^. }  v6 i9 LThis sets the object that is ranked 3 in the model to current and prints its name to the output console.  0 G3 L# g$ A3 F" y  E
3 z$ x0 \* r4 s* C0 X

9 B3 C& Q4 N6 N( x$ o' N& hownerobject(node thenode)
5 b3 h- i  u$ L, [5 p6 ]
Description:' P+ j. C: f, n6 v( G' Z; J9 ?
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.8 o. Z1 s) F/ e  P* v4 e3 K0 C5 H
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 H8 c. N7 j* W: }; O8 G. a
该函数返回参数节点所在的实体。
5 I) h3 K; r, K3 Y; s+ G5 o, Y* R% E- d
Example: . O) l: E. u) \& C" T  k
  1. string objname = getname(ownerobject(c));
复制代码
 7 E; f6 {  `/ g" f* 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);
复制代码
 
8 o' q6 g8 ?* Y7 h3 t6 I8 UThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.
* T1 s. V0 h$ G" W7 m7 z# V这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。2 T( Y. {, M7 h% G: N6 r

/ ~, b; _# w3 t2 X5 T, sc<no parentheses>
4 ^) l, ~6 h$ YDescription:  
/ ^* V# ?, ], E1 \& T# wThis command is used to reference the active node during a function's execution. 0 p; G1 U. I% Z/ \9 z2 t. W2 O
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.) {( U2 P' g4 x' o0 I
If the function is an event function, c returns a reference to the object that contains the event.
& M+ A$ w4 r. ac在函数执行的过程中指向活动实体。
8 F. f8 b  X6 p如果是节点型函数,c指向函数所在实体,
# \% p4 L0 U3 \6 M# U) ]如果是事件型函数,c指向事件所在实体。
. F0 P, O* V, @1 z# [/ z9 S$ G/ EExample: 
  1. treenode current = ownerobject(c);
复制代码
 
) t  X* [+ @8 N
4 a/ [. C& M" _! e* Y3 z0 G( rsetcurrent(thing)
" S" F# N4 s- a! O6 ^! X
Description: Deprecated. Do not use.
8 }+ _. Z$ C! G: h, G, K6 WExample: /
6 y7 {2 ~# [) J, G* `此命令不再使用。9 `& b. c+ k+ e( U6 f
9 O5 u/ l4 s2 o9 g. P* b
item<no parentheses> ! C1 I6 w8 s6 [9 w0 O: j
Description:  & w' d. X9 q4 v$ M4 r6 j# Z
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.
6 w1 W9 \. }& z8 U  r不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。, R' x) _1 b$ K, k1 Y; `4 Z
Example: 
  1. treenode item = rank(model(),3);
    8 J) P; }" {  H& \9 B  f4 s1 {
  2. pt(getname(item));
复制代码
 
1 Z9 y0 ~8 `& x" A( d5 j3 A4 G$ [This sets the object that is ranked 3 in the model to item and prints its name to the output console.  
) ]$ ]8 ~3 e! C" j& B9 g- D6 }, T4 n7 O" l6 d5 t

2 {, P" b# v( }( g6 i/ Lsetitem(thing)& F, u3 [4 b4 J, y7 o3 t7 A- R9 H
Description: Deprecated. Do not use.
" v# o% U3 S2 E4 \9 uExample: /
; B% i% M0 _% \) h此命令不再使用。. U$ X( |0 l2 H

8 R6 M/ ^2 Z; w3 [parnode(num index) % y2 J9 n/ ]" b' ?/ \' S
Description:  
/ x9 N1 n5 Y  F$ f- fThis command is used inside a function that is called by the nodefunction() command.
  p0 [* Q  x: d; X; _此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?7 P3 C+ F. F# h& d
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
" j" w7 a, y: O. U, g) p, t此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.( n2 l6 i6 p- I9 W7 F
节点和树节点有何不同?, V# ~" P0 s+ i: O
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
# M! [9 X5 X: X; @5 S+ N2 A& xparnode,parval,parstr这三个命令真是让人搞不懂啊...* C+ R4 U) ]' n7 v. u0 I
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 3 Y3 p/ i3 a7 X, e5 W* w
Example:
( M  G/ [% d3 x. s% o( A% lIf a trigger/field is called with: 2 Q7 D: A: s) Q  Y4 m
nodefunction(thefuncnode, item)) c* |" ~# _: P! d1 [% {
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);
复制代码
  
: [% w2 Z) N/ p+ U! K
1 Q" ]$ u- V1 C2 Pport<no parentheses>0 `1 K' M7 ?, M0 g0 K! r" Z
Description: % E2 G" S( k+ d5 ?2 B
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.   N1 r$ b6 N: O% m& S4 k
Example:1 ]7 E' H: J+ ]( D
  1. int port = parval(3);
    0 x2 `7 X( `+ P1 V! X4 v- W
  2. pd(port);
复制代码
 / _' \8 `0 C! ^5 r
This sets port to parval(3) and then prints the value to the output console.  M+ J7 m' ]5 w4 O+ H5 B
0 x7 j6 q- {" N3 I, C: y% n+ i
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
5#
一骑绝尘 发表于 2014-8-20 10:01:35 | 只看该作者
C 一扫疑惑,  但parval(),parnode() 还是有点不解
4#
1010265352 发表于 2014-8-11 13:56:35 | 只看该作者
额,很值得一看
3#
fl2014 发表于 2014-8-10 18:29:45 | 只看该作者
大神啊,解决了我多日的困惑
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite % p, i. ^5 M7 L9 g! n; |
& c5 m2 N/ \1 U

) H7 e2 U# r% A4 A4 Z首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
$ Z# N7 H3 e$ N- I, D    首先在GUI中,它是这样的,如下图:/ Q1 y/ g! t( d
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|全球FlexSim系统仿真中文论坛 ( 京ICP备14043114号-2 )

GMT+8, 2025-6-30 14:27 , Processed in 0.087430 second(s), 15 queries .

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

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