1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The nodes described for VTK. The only node really developed
23 is for the L{StructuralNode} class."""
24 import vtk
25 import numpy as N
26
27 from mbdyn.nodes import StructuralNode as StructuralNodeBase
28
29 from mbdyn.interface.common import BaseMenu
30 from mbdyn.interface.vectors import ReferenceFrame
31
32
33 DESC = {}
34
35 DESC["vtk"] = [\
36
37
38 ("rotation_matrix","_Rotation _matrix"),
39 ("position", "_Show")
40 ]
41
42
44 """The GTK menu for a node"""
45
50
51
53 """A structural node receiving instructions
54 from GTK and showing its results in the VTK area.
55 """
56
58 StructuralNodeBase.__init__(self)
59
60 self.actor = vtk.vtkActor()
61 self.prop = None
62 self.vtk_ref = ReferenceFrame()
63
64 self.position_array = N.zeros((3, 1))
65
66 self.feature_keys = []
67 self.boolean = {}
68 self.descriptions = []
69
70 self.menu_type = "node"
71
73 """Once the parameters from the result files have
74 been loaded on the node, the initialization is done.
75 """
76 menu_offer = [desc[0] for desc in DESC["vtk"]]
77 for name in self.results.names:
78 if name in menu_offer:
79 self.feature_keys.append(name)
80
81 for feature_key in self.feature_keys:
82 self.boolean[feature_key] = False
83
84
85 if "position" in self.results.names:
86 self.boolean["position"] = True
87 self.descriptions.append(self.set_vtk_position)
88
90 """Set the node mapper"""
91 self.actor.SetMapper(obj_mapper.mapper)
92 self.prop = self.actor.GetProperty()
93
95 """Set the color to blue"""
96 self.prop.SetColor(0.5, 0.5, 1.)
97
99 """Set a strong opacity"""
100 self.prop.SetOpacity(1.)
101
103 """Set a light opacity"""
104 self.prop.SetOpacity(0.5)
105
111
113 """Get back the position at C{idx} frame number"""
114 self.position_array = self.results.position[idx]
115
117 """Set the node position in VTK"""
118 self._fill_position(idx)
119 self.actor.SetPosition(self.position_array[0][0],
120 self.position_array[1][0],
121 self.position_array[2][0])
122
124 """Show the node reference frame in the VTK area
125 at the current C{idx} frame"""
126 rot_matrix = self.results.rotation_matrix[idx]
127 self._fill_position(idx)
128 self.vtk_ref.set_orientation_matrix(rot_matrix)
129 self.vtk_ref.set_position(self.position_array)
130
132 """Set the arrow mapper representing the unit vector
133 for the node reference frame"""
134 for axe in self.vtk_ref.axes:
135 axe.set_arrow(unit_arrow)
136
138 """The node will show its position"""
139 self.descriptions.append(self.set_vtk_position)
140 self.set_vtk_position(current_frame_id)
141 vtk_area.add_actor(self.actor)
142 vtk_area.can_be_selected(self.actor, self)
143 self.boolean["position"] = True
144 return "Show " + self.name
145
147 """The node position will not be seen"""
148 self.descriptions.remove(self.set_vtk_position)
149 vtk_area.remove_actor(self.actor)
150 vtk_area.remove_from_selection(self.actor)
151 self.boolean["position"] = False
152 return "Hide " + self.name
153
155 """The reference frame of the node will be seen"""
156 self.descriptions.append(self.set_vtk_rotation_matrix)
157 self.set_vtk_rotation_matrix(current_frame_id)
158 for axe in self.vtk_ref.axes:
159 vtk_area.add_actor(axe.actor)
160 self.boolean["rotation_matrix"] = True
161 return "Show rotation matrix of " + self.name
162
164 """The reference frame of the node will not be seen"""
165 self.descriptions.remove(self.set_vtk_rotation_matrix)
166 for axe in self.vtk_ref.axes:
167 vtk_area.remove_actor(axe.actor)
168 self.boolean["rotation_matrix"] = False
169 return "Hide rotation matrix of " + self.name
170
171 - def activate(self, key_feature, current_frame_id, vtk_area):
172 """Activate a feature for the node"""
173 return getattr(self, "activate_" + key_feature)(current_frame_id,
174 vtk_area)
175
177 """Deactivate a feature for the node"""
178 return getattr(self, "desactivate_" + key_feature)(vtk_area)
179
180
181 NODE_CLASS = {}
182 NODE_CLASS["STRUCTURAL"] = {}
183 NODE_CLASS["STRUCTURAL"]["structural"] = StructuralNode
184