OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scene_selection_helper.py
Go to the documentation of this file.
1 #------------------------------------------------------------------------------
2 # This file is part of the OpenStructure project <www.openstructure.org>
3 #
4 # Copyright (C) 2008-2011 by the OpenStructure authors
5 #
6 # This library is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation; either version 3.0 of the License, or (at your option)
9 # any later version.
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #------------------------------------------------------------------------------
19 
20 import sys
21 from ost import gui
22 import sip
23 from ost import gfx
24 import ost
25 import os
26 try:
27  from ost import img
28  _img_present=True
29 except ImportError:
30  _img_present=False
31  pass
32 
33 class SelHelper:
34  __shared_state = {}
35 
36  NO_SELECTION = 0
37  HAS_ENTITY = 1
38  HAS_VIEW = 2
39  HAS_IMG = 4
40  HAS_SURFACE = 8
41  IS_ONE_TYPE = 16
42  IS_MULTI_TYPE = 32
43  SINGLE_SELECTION = 64
44  MULTI_SELECTION = 128
45 
46  def __init__(self):
47  self.__dict__ = self.__shared_state
48  if not '_ready' in dir(self):
49  self.scene_sel_ = gui.SceneSelection.Instance()
50  self.current_flags_ = 0
51  self._ready = True
52 
53  def Update(self):
54  self.current_flags_ = 0
55  if self.scene_sel_.GetActiveNodeCount() == 0 and self.scene_sel_.GetActiveViewCount() == 0:
56  return
57 
58  for i in range(0,self.scene_sel_.GetActiveNodeCount()):
59  node = self.scene_sel_.GetActiveNode(i)
60  if isinstance(node, gfx.Entity):
61  self.current_flags_ = self.current_flags_ | SelHelper.HAS_ENTITY
62  if isinstance(node, gfx.Surface):
63  self.current_flags_ = self.current_flags_ | SelHelper.HAS_SURFACE
64  if (_img_present) and isinstance(node, gfx.MapIso):
65  self.current_flags_ = self.current_flags_ | SelHelper.HAS_IMG
66 
67  if self.scene_sel_.GetActiveViewCount() > 0:
68  self.current_flags_ = self.current_flags_ | SelHelper.HAS_VIEW
69 
70  cnt = 0
71  if self.current_flags_ & SelHelper.HAS_ENTITY:
72  cnt += 1
73  if self.current_flags_ & SelHelper.HAS_SURFACE:
74  cnt += 1
75  if self.current_flags_ & SelHelper.HAS_IMG:
76  cnt += 1
77  if self.current_flags_ & SelHelper.HAS_VIEW:
78  cnt += 1
79 
80  if cnt == 1:
81  self.current_flags_ = self.current_flags_ | SelHelper.IS_ONE_TYPE
82  elif cnt > 1:
83  self.current_flags_ = self.current_flags_ | SelHelper.IS_MULTI_TYPE
84 
85  if self.scene_sel_.GetActiveNodeCount()==1:
86  self.current_flags_ = self.current_flags_ | SelHelper.SINGLE_SELECTION
87  elif self.scene_sel_.GetActiveNodeCount()>1:
88  self.current_flags_ = self.current_flags_ | SelHelper.MULTI_SELECTION
89 
90  def CheckAllFlags(self, flags):
91  if(flags == self.current_flags_ & flags) and (flags == self.current_flags_ | flags):
92  return True
93  return False
94 
95  def CheckNotFlags(self, flags):
96  return not self.CheckFlags(flags)
97 
98  def CheckFlags(self, flags):
99  if(flags == self.current_flags_ & flags):
100  return True
101  return False
102 
103  def CheckMinOneFlag(self, flags):
104  if((self.current_flags_ - (self.current_flags_ & flags)) < self.current_flags_):
105  return True
106  return False
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:63
isocontour rendering for 3D image data
Definition: map_iso.hh:52