Package windSimSuite :: Package interface :: Module rotor
[hide private]

Source Code for Module windSimSuite.interface.rotor

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # This file is part of MBDyn sim suite. 
  5  # Copyright (C) 2007 André ESPAZE, as part of a Master thesis supervised by 
  6  # Martin O.L.Hansen (DTU) and Nicolas Chauvat (Logilab) 
  7   
  8  # MBDyn sim suite is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12  # 
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program; if not, write to the Free Software 
 20  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 21  # 
 22  """The rotor and hub definition in a graphical environment. 
 23  """ 
 24  import gtk 
 25   
 26  from mbdyn.interface.nodes import NODE_CLASS 
 27  from mbdyn.interface.common import BaseMenu 
 28   
 29  from windSimSuite.interface.common import WithNodesAndElemsMenu 
 30  from windSimSuite.interface.common import GobjectBase, GobjectWithNodesAndElems 
 31   
 32  from windSimSuite.rotor import Rotor as RotorBase 
 33  from windSimSuite.rotor import Hub as HubBase 
 34   
 35  from windSimSuite.interface.blade import Blade, PYLAB_ROTOR_DESC 
 36   
37 -class HubMenu(WithNodesAndElemsMenu):
38 """The hub menu""" 39 pass
40
41 -class Hub(HubBase, GobjectWithNodesAndElems):
42 """The GTK hub. 43 """ 44
45 - def __init__(self, name="hub"):
46 HubBase.__init__(self, name) 47 GobjectWithNodesAndElems.__init__(self) 48 self.set_node_class(NODE_CLASS) 49 self.menu_type = "hub"
50 51 DESC = {} 52 53 DESC["vtk"] = [\ 54 ("blades_visibility", gtk.CheckMenuItem("_Show _blades")) 55 ] 56 57 PYLAB_ROTOR = [] 58 59 for key, display in PYLAB_ROTOR_DESC: 60 PYLAB_ROTOR.append((key, gtk.MenuItem(display))) 61 62 PYLAB_EXTRA = [\ 63 ("electrical_power", "_Plot _Elec _Power"), 64 ("rotational_speed_value", "_Plot _Rotational _Speed"), 65 ("electrical_torque", "_Plot _Elec _Torque") 66 ] 67 68 for key, display in PYLAB_EXTRA: 69 PYLAB_ROTOR.append((key, gtk.MenuItem(display))) 70 71 DESC["pylab"] = PYLAB_ROTOR 72 73
74 -class RotorMenu(BaseMenu):
75 """The rotor menu 76 """ 77
78 - def __init__(self):
79 BaseMenu.__init__(self, DESC, True)
80 81
82 -class Rotor(RotorBase, GobjectBase):
83 """The GTK rotor. As in its original defintion, 84 in charge to manipulate the L{Hub} and the 85 L{Blade<windSimSuite.interface.blade.Blade>} instances. 86 """ 87
88 - def __init__(self):
89 RotorBase.__init__(self) 90 GobjectBase.__init__(self) 91 self.menu_type = "rotor" 92 93 self.feature_keys = [] 94 self.boolean = {}
95
96 - def display_on(self, gtk_tree, giter):
97 """Display the rotor on the GTK treeview for 98 the wind turbine""" 99 if self.has_hub: 100 child_giter = gtk_tree.get_from(giter) 101 gtk_tree.add_at(child_giter, self.hub) 102 self.hub.display_on(gtk_tree, child_giter) 103 104 for blade in self.blades: 105 child_giter = gtk_tree.get_from(giter) 106 gtk_tree.add_at(child_giter, blade) 107 blade.display_on(gtk_tree, child_giter)
108
109 - def init_from_loaded_file(self):
110 """Make the rotor aware of its available results""" 111 self.feature_keys = self.results.names 112 for feature_key in self.feature_keys: 113 self.boolean[feature_key] = False 114 115 if self.has_hub: 116 self.hub.init_from_loaded_file() 117 for blade in self.blades: 118 blade.init_from_loaded_file() 119 120 # Check if at least one blade is represented 121 for blade in self.blades: 122 if "nodes_visibility" in blade.feature_keys: 123 if blade.boolean["nodes_visibility"]: 124 self.boolean["blades_visibility"] = True 125 break
126 127
128 - def activate_blades_visibility(self, current_frame_id, vtk_area):
129 """Show the MBDyn items describing the blade""" 130 for blade in self.blades: 131 if not blade.boolean["nodes_visibility"]: 132 blade.activate_nodes_visibility(current_frame_id, vtk_area) 133 self.boolean["blades_visibility"] = True 134 return "Show all blade nodes of %s" % self.name
135
136 - def desactivate_blades_visibility(self, vtk_area):
137 """Hide the MBDyn items describing the blade""" 138 for blade in self.blades: 139 if blade.boolean["nodes_visibility"]: 140 blade.desactivate_nodes_visibility(vtk_area) 141 self.boolean["blades_visibility"] = False 142 return "Hide all blade nodes of %s" % self.name
143
144 - def set_parameters(self, para):
145 """Set C{Hub} and C{Blade} instances suited for 146 a graphical user interface.""" 147 self.set_own_parameters(para) 148 if self.has_hub: 149 self.hub = Hub() 150 self.hub.set_parameters(self.hub_para) 151 for blade_para in self.blade_paras: 152 blade = Blade() 153 blade.set_parameters(blade_para) 154 self.blades.append(blade)
155