全球FlexSim系统仿真中文论坛

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

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

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2013-9-12 13:51:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
$ O3 C. W: \  G! A! Q- ]4 ?
- O4 o, N# F; G在触发器中常会看到顶端已经自动写好的一些代码,通常如下: 
  1. treenode current = ownerobject(c);
    9 h( `# u; C- K0 O
  2. treenode item = parnode(1);' S8 T7 `, E6 B( Z  Q4 l7 D4 R6 G' ?
  3. int port = parval(2);
复制代码
 6 k  [* X  t6 a$ a$ [0 k: z1 j
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
, R) c, x, \( G, M$ H% {在接下来的代码中可以直接引用这三个已经声明好了的变量。
, m9 z& W$ C& J9 a/ w对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
3 Z& `7 r& [! g9 y4 Y2 r下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。+ d- V: |' h" Y' e

! y9 G7 @3 v: z4 f4 C7 ctreenode$ p- U, x6 ~; J. p
Variable Types* w5 P6 x0 }; ^: M; ~4 ~4 C
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.% U% q+ [- K8 \, |: ]  R" |0 O7 e; w$ R
Type Description # }6 m8 I' Q9 Z: w0 h& n( s# n9 ?$ ^
int  integer type  
3 X! A* D' f8 w9 [double  double precision floating point type  
; m" d% C7 L5 t# o: F& Rstring  text string  5 n* Z/ _; b# |2 }' t% W% I
treenode  reference to a Flexsim node or object  4 C4 d' e  h# @+ D
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。0 }7 R$ z2 L! W
3 A) \/ g: U/ _, M
current<no parentheses>
/ A7 }) \( a9 @/ G  i) ~Description:  $ U7 k) J! R8 `8 m5 h/ y' F6 x
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.
8 V: U3 @- k: E) w; k不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。) ~# Z7 Y4 k( P" r, g" b8 k8 Z
不解:
* u9 V$ `- [) K& \4 \9 ^9 y; i1.used...with....是什么意思?- b2 r! N+ L& D. ~. ]) o
以前current是必须和setcurrent一起使用的吗?3 T, T4 m+ O4 @
. X7 N' o/ I1 S, ^8 ~
2.as any other variable type是什么意思?* P! `6 r( @1 Z+ [1 g! o4 M
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
6 M; Z' j4 G, F/ v% w: I+ z
Example: ( L3 a$ Q/ ~3 Q2 }% L
  1. treenode current = rank(model(),3);$ m/ _. f  H; ?& O; R. y( o1 M- B; |
  2. pt(getname(current));
复制代码
 1 B  z) Z; A% v; f
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  ' d; |' G+ Q) O* {3 N; O* Q

+ B' |8 w3 d' ^+ L+ v: ^* ~3 ]6 ^* Z: y4 B+ k
ownerobject(node thenode)4 O* }1 P  x( v
Description:2 |. X% u1 ^" M0 d: 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.! e8 j4 g3 k: b7 d% q1 F
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.
: |9 Q* O+ x# }/ }( c该函数返回参数节点所在的实体。
& E' `! ~. ^; A! s2 H  b, ~( o  B4 J& o8 W% m, W. q. ^( x6 p
Example: & [: B( O1 p- y- f! {
  1. string objname = getname(ownerobject(c));
复制代码
 " E9 J: @% s4 v# C' L) q) q2 l1 I
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);
复制代码
 
6 S- l5 z. I  O7 q% R* I4 }This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
# \5 ]4 d* w6 g" g这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
( W& r' J4 q/ j1 W" s
7 r* `: i/ Q( C8 d+ ~+ cc<no parentheses>' U) R5 W' b3 {
Description:  / s3 C8 ?  r: e- i
This command is used to reference the active node during a function's execution.
; F' O4 t- F; y) v  \If the function was called using nodefunction(), c returns a reference to the node on which the function is written.; Z: v- ]+ _2 a7 `
If the function is an event function, c returns a reference to the object that contains the event.
' f: f# m4 }9 O, vc在函数执行的过程中指向活动实体。2 w& z, F8 F  @0 x6 s) }
如果是节点型函数,c指向函数所在实体,4 Y! e8 q! @* h/ H
如果是事件型函数,c指向事件所在实体。0 L9 `' t. f* M* q6 g7 J5 \+ B  \
Example: 
  1. treenode current = ownerobject(c);
复制代码
 
5 k( S* W8 Y7 T7 r: K
. h1 \9 q/ A2 K1 K/ C) H+ ?4 Esetcurrent(thing)
3 p1 j% E/ G8 F( j
Description: Deprecated. Do not use.
0 ]+ G7 h# y' ~2 x9 n7 b# _' L0 tExample: /  v( e7 ~5 b, T/ K+ [( r
此命令不再使用。
/ S9 ]6 O# r" ^$ U! R& Q
9 s; B3 k# O, ?. D* jitem<no parentheses>
: i& z. Q' F, u- f" ]
Description:  
: P& t  ~3 \% Y6 s. ~, X& [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. ; |+ j; _+ N( ~$ [
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。- ~" o6 B/ h* [$ U2 r1 ?) o
Example: 
  1. treenode item = rank(model(),3);
    6 D* u! @! ~/ \" p! g
  2. pt(getname(item));
复制代码
 
, R- C3 n; R( \3 uThis sets the object that is ranked 3 in the model to item and prints its name to the output console.  
+ a' s1 d1 [, p; j
  i2 t( m; t# u0 [# v& b' r. N' W
! b9 V' y1 \- }- G; N) z0 Ssetitem(thing)
( x# ~+ Q4 b' m& y
Description: Deprecated. Do not use. # ?8 M  O1 i4 q& Z1 K5 S) J
Example: /
: E2 x5 H4 V& d$ ~: }* ~5 D, ~此命令不再使用。
& C. ?7 J+ L* R8 B* G8 g3 E+ ]+ Q' I
parnode(num index)
7 q0 E: y5 \6 zDescription:  ; j- k; ~" V. L! [; n
This command is used inside a function that is called by the nodefunction() command.
4 a+ V$ K) Y& ]# f9 ?此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
1 e1 r7 z# i- m3 X* r0 r, KIt returns the parameter passed to nodefunction specified by index as a node (or treenode). ; Q1 q0 c, z$ l5 v, Q) y1 g
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
" A5 t# W; g1 G! c, `1 S" ~节点和树节点有何不同?
8 Y7 T5 `9 c8 W' u: T8 QThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.0 k0 H* J: r* l6 b' i+ d; }* T# @; v) [
parnode,parval,parstr这三个命令真是让人搞不懂啊...
# N& m8 i9 w, Z8 Q- S" V& _- NParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
6 e3 W$ Q; Q! FExample:   {7 N! T0 u, U4 Y* n
If a trigger/field is called with:
+ D% P9 N  q- E6 S8 Z: f  ~2 U! Dnodefunction(thefuncnode, item)
) Z/ k) z5 }( d1 t. p7 B+ j9 Z. l. Ithen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:
  1. treenode item = parnode(1);
复制代码
    l2 b, Z  U; B/ U' z, K  U+ J

% b& y5 f) p: O1 I/ uport<no parentheses>
0 Y9 ^8 ?/ O# \( YDescription:
2 S7 j5 I3 K6 A8 \5 T" TDeprecated. 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.
8 P* c9 r- Q' m$ yExample:
0 A+ F! |6 ]! C  _
  1. int port = parval(3);
    : P5 P  O! |4 r( K# g
  2. pd(port);
复制代码
 3 P& M/ ~" p) u" @8 E' i) T% p2 ~! P
This sets port to parval(3) and then prints the value to the output console.
9 Q, k0 ^( A1 q# A* a
, F! _1 i! a. a9 T8 y# G不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。
2#
天性518 发表于 2013-9-17 13:56:40 | 只看该作者
1# zorsite ; p3 v! t2 J# g/ @, B

" L/ ?$ k, d* c6 \  t& d# G8 K+ h# p
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
1 j9 c; P* ]% L, ?, [% L    首先在GUI中,它是这样的,如下图:! W8 \4 E9 u4 H, R& _9 d7 j
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

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

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-9-6 06:00 , Processed in 0.070655 second(s), 14 queries .

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

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