我刚刚开始使用 itcl,我发现如何将 itcl 对象从一个类传递到另一个类?但这对我没有帮助。
我定义了以下对象:
package require Itcl
namespace eval FEM {
itcl::class Node {
variable nid
variable x
variable y
variable z
constructor {{NID 0} {coordX 0} {coordY 0} {coordZ 0}} {
set nid $NID
set x $coordX
set y $coordY
set z $coordZ
return $this}
method is {nid coordX coordY coordZ}
method printString
}
itcl::body Node::is {NID coordX coordY coordZ} {
set nid $NID
set x $coordX
set y $coordY
set z $coordZ}
itcl::body Node::printString {} {
return "$nid $x $y $z"}
# #######################################################
itcl::class CQUAD {
variable eid
variable pid
variable node1
variable node2
variable node3
variable node4
constructor {{EID 0} {PID 0} {NODE1 0} {NODE2 0} {NODE3 0} {NODE4 0}} {
set eid $EID
set pid $PID
set node1 $NODE1
set node2 $NODE2
set node3 $NODE3
set node4 $NODE4
return $this}
method is {EID PID NODE1 NODE2 NODE3 NODE4}
method printString
}
itcl::body CQUAD::is { EID PID NODE1 NODE2 NODE3 NODE4 } {
set eid $EID
set pid $PID
set node1 $NODE1
set node2 $NODE2
set node3 $NODE3
set node4 $NODE4}
itcl::body CQUAD::printString {} {
return "$eid $pid $node1 $node2 $node3 $node4"}
}
}
# ########################################################
# Test
for {set n 1} {$n <= 4} {incr n} {
set coord1 [expr {$n+1} ]
set coord2 [expr {$n+2} ]
set coord3 [expr {$n+3} ]
set NID N$n
::FEM::Node $NID $n $coord1 $coord2 $coord3
puts "[$NID printString]"
}
set PID 99
set EID 88
以下是错误的,因为$N1
只是N1
不是“节点”N1
::FEM::CQUAD MyQuad $EID $PID $N1 $N2 $N3 $N4
但是如何将 Node 类型的对象传递给 CQUAD 类型的对象?我也试过:
::FEM::CQUAD MyQuad $EID $PID $::FEM:Node::N1 $::FEM:Node::N2 $::FEM:Node::N3 $::FEM:Node::N4
另外,如何删除对象?unset $N1
是错unset $::FEM::Node::N1
的也是假的
最后一个问题:假设我有一个 CQUAD 对象,其中包含 Node 类型的对象:我怎样才能获得 CQUAD 1 的 Node2 的 y 坐标?