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

Source Code for Module windSimSuite.interface.common

  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 common graphical objects. Used for every wind turbine object 
 23  that need to deal with the graphical user interface.""" 
 24  from mbdyn.interface.common import BaseMenu 
 25   
 26  DESC = {} 
 27   
 28  DESC["vtk"] = [\ 
 29  ("nodes_visibility", "_Show _nodes") 
 30  ] 
 31   
32 -class WithNodesAndElemsMenu(BaseMenu):
33 """A menu for an object with nodes 34 and elements 35 """ 36
37 - def __init__(self, build=True):
38 BaseMenu.__init__(self) 39 self.add_items("vtk", DESC["vtk"]) 40 if build: 41 self.build()
42 43
44 -class GobjectBase:
45 """The base of a graphical object. It is able 46 to activate or desactivate a feature from the 47 VTK area. 48 """ 49
50 - def __init__(self):
51 # will be provided by the derived class 52 #self.name = None 53 #self.results = None 54 pass
55
56 - def activate(self, feature_key, current_frame_id, vtk_area):
57 """Activate a feature on the object. The corresponding 58 method will be called""" 59 return getattr(self, "activate_" + feature_key)(current_frame_id, 60 vtk_area)
61
62 - def desactivate(self, feature_key, vtk_area):
63 """Deactivate a feature on the object. The corresponding 64 method will be called""" 65 return getattr(self, "desactivate_" + feature_key)(vtk_area)
66 67
68 -class GobjectWithNodesAndElems(GobjectBase):
69 """For an abstrat turbine object manipulating nodes and elements. 70 The common methods are resumed in this class. 71 """ 72
73 - def __init__(self):
74 GobjectBase.__init__(self) 75 # Will be the attributes coming from the first inheritance 76 # An error in Pylint when the module is tested separately 77 # self.nodes = None 78 79 self.feature_keys = [] 80 self.boolean = {}
81
83 """Make the component aware of its own results""" 84 for feature in self.results.names: 85 self.feature_keys.append(feature) 86 for feature_key in self.feature_keys: 87 self.boolean[feature_key] = False 88 89 # Check if at least one node position is represented 90 for node in self.nodes: 91 if "position" in node.feature_keys: 92 if node.boolean["position"]: 93 self.boolean["nodes_visibility"] = True 94 break
95
96 - def init_from_loaded_file(self):
97 """Initialize the object results once the result file 98 has been loaded""" 99 self.common_init_from_loaded_file()
100
101 - def display_on(self, gtk_tree, giter):
102 """Display the nodes object on the GTK treeview""" 103 self.display_nodes_on(gtk_tree, giter)
104
105 - def display_nodes_on(self, gtk_tree, giter):
106 """Display the nodes on the GTK treeview""" 107 for node in self.nodes: 108 child_giter = gtk_tree.get_from(giter) 109 gtk_tree.add_at(child_giter, node)
110
111 - def activate_nodes_visibility(self, current_frame_id, vtk_area):
112 """Show the nodes position""" 113 for node in self.nodes: 114 if not node.boolean["visibility"]: 115 node.activate_visibility(current_frame_id, vtk_area) 116 self.boolean["nodes_visibility"] = True 117 return "Show all nodes of %s" % self.name
118
119 - def desactivate_nodes_visibility(self, vtk_area):
120 """Hide the nodes position""" 121 for node in self.nodes: 122 if node.boolean["visibility"]: 123 node.desactivate_visibility(vtk_area) 124 self.boolean["nodes_visibility"] = False 125 return "Hide all nodes of %s" % self.name
126