1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """Define a L{WindTurbine} and L{Simulation} in a graphical environment
23 """
24 from windSimSuite.main import WindTurbine as WindTurbineBase
25 from windSimSuite.main import Simulation as SimulationBase
26 from windSimSuite.main import PyMBDynFile as PyMBDynFileBase
27
28 from windSimSuite.interface.rotor import Rotor
29 from windSimSuite.interface.nacelle import Nacelle
30 from windSimSuite.interface.tower import Tower
31
32 from mbdyn.interface.groups import ReferenceList, Nodes
33 from mbdyn.interface.mapper import MAPPER_CLASS
34 from mbdyn.interface.vectors import Arrow as ArrowMapper
35
36 CLASS = {"rotor" : Rotor,
37 "nacelle" : Nacelle,
38 "tower": Tower}
39
41 """A GTK wind turbine.
42 """
43
45 """Display the wind turbine on the GTk treeview"""
46 gtk_tree.clean()
47 for compo_name in ["tower", "nacelle", "rotor"]:
48 if getattr(self, "has_" + compo_name):
49 compo = getattr(self, compo_name)
50 giter = gtk_tree.get_top()
51 gtk_tree.add_at(giter, compo)
52 compo.display_on(gtk_tree, giter)
53
55 """Make the wind turbine objects aware of their
56 available results"""
57 for compo_name in ["tower", "nacelle", "rotor"]:
58 if getattr(self, "has_" + compo_name):
59 compo = getattr(self, compo_name)
60 compo.init_from_loaded_file()
61
63 """Will set graphical wind turbine objects as attribute"""
64 self.set_own_parameters(para)
65 for children_name in self.children_names:
66 children = CLASS[children_name]()
67 children.set_parameters(para[children_name])
68 setattr(self, children_name, children)
69
70
72 """A graphical simulation. Able to deal
73 with the C{Manager}.
74 """
75
77 SimulationBase.__init__(self)
78 self.refs = ReferenceList()
79 self.nodes = Nodes()
80
81 self.unit_arrow = None
82 self.scale_table = None
83 self.items = []
84 self.actors = []
85
86 self.frame_step = 1
87 self.current_frame_id = 0
88 self.nb_frames = 0.
89 self.has_time = False
90
92 """Set the scale table for resizing the VTK
93 mappers"""
94 self.scale_table = scale_table
95
97 """Set the user frame step to play the simulation"""
98 self.frame_step = frame_step
99
101 """Display the simulation on the GTK treeview
102 for MBDyn components (reference frames and nodes)"""
103 gtk_tree.clean()
104
105 giter = gtk_tree.get_top()
106 gtk_tree.add_at(giter, self.refs)
107 for ref in self.refs:
108 giter1 = gtk_tree.get_from(giter)
109 gtk_tree.add_at(giter1, ref)
110
111 giter = gtk_tree.get_top()
112 gtk_tree.add_at(giter, self.nodes)
113 for group in self.nodes.groups.values():
114 giter1 = gtk_tree.get_from(giter)
115 gtk_tree.add_at(giter1, group)
116 for node in group:
117 giter2 = gtk_tree.get_from(giter1)
118 gtk_tree.add_at(giter2, node)
119
121 """Create the VTK mappers and actors of the simulation.
122 Currently, only the reference frames and nodes exist."""
123 unit_arrow = ArrowMapper()
124 self.scale_table.reset()
125 self.scale_table.add_vector(unit_arrow)
126
127 self.items = self.nodes.all
128 for node in self.nodes.all:
129 node.init_once_file_loaded()
130 MapperClass = MAPPER_CLASS["NODE"][node.group_key]\
131 [node.class_key]
132 mapper = MapperClass()
133 node.set_mapper(mapper)
134 self.scale_table.add(mapper)
135 node.set_unit_arrow(unit_arrow)
136 node.set_color()
137 node.set_description(0)
138
139 self.refs.set_unit_arrow(unit_arrow)
140
141 self.scale_table.redraw()
142
143 self.unit_arrow = unit_arrow
144
146 """Show the simulation at the C{idx} index.
147 The simulation is completely described by the
148 frame index in the results."""
149 for node in self.items:
150 node.set_description(idx)
151
153 """Add the actors that can be selected on the VTK area"""
154 self.actors = []
155 for node in self.nodes.all:
156 vtk_area.add_actor(node.actor)
157 vtk_area.can_be_selected(node.actor, node)
158 self.actors.append(node.actor)
159
161 """Create a wind turbine able to deal with graphical libraries"""
162 self.set_own_parameters(para)
163 self.refs.set_parameters(para["refs"])
164 if self.has_turbine:
165 self.turbine = WindTurbine()
166 self.turbine.set_parameters(self.turbine_para)
167 self.turbine.add_on_simulation(self)
168
170 """Made the simulation aware of its available results
171 to the interface."""
172 self.turbine.init_from_loaded_file()
173
174 if hasattr(self, "results"):
175 if hasattr(self.results, "time"):
176 if len(self.results.time) > 0:
177 self.nb_frames = len(self.results.time)
178 self.has_time = True
179
180
182 """The container file that will set a L{Simulation} instance
183 suited for graphical interaction.
184 """
185
186 - def __init__(self, name, mode="r", path=".", autoload=True):
187 PyMBDynFileBase.__init__(self, name, mode, path, autoload=False)
188 self.CLASS = Simulation
189 if (mode=="r") and autoload:
190 self.load()
191