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-2020 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 from ost import gfx
23 import ost
24 import os
25 try:
26  from ost import img
27  _img_present=True
28 except ImportError:
29  _img_present=False
30  pass
31 
32 class SelHelper:
33  __shared_state = {}
34 
35  NO_SELECTION = 0
36  HAS_ENTITY = 1
37  HAS_VIEW = 2
38  HAS_IMG = 4
39  HAS_SURFACE = 8
40  IS_ONE_TYPE = 16
41  IS_MULTI_TYPE = 32
42  SINGLE_SELECTION = 64
43  MULTI_SELECTION = 128
44 
45  def __init__(self):
46  self.__dict__ = self.__shared_state
47  if not '_ready' in dir(self):
48  self.scene_sel_ = gui.SceneSelection.Instance()
49  self.current_flags_ = 0
50  self._ready = True
51 
52  def Update(self):
53  self.current_flags_ = 0
54  if self.scene_sel_.GetActiveNodeCount() == 0 and self.scene_sel_.GetActiveViewCount() == 0:
55  return
56 
57  for i in range(0,self.scene_sel_.GetActiveNodeCount()):
58  node = self.scene_sel_.GetActiveNode(i)
59  if isinstance(node, gfx.Entity):
60  self.current_flags_ = self.current_flags_ | SelHelper.HAS_ENTITY
61  if isinstance(node, gfx.Surface):
62  self.current_flags_ = self.current_flags_ | SelHelper.HAS_SURFACE
63  if (_img_present) and isinstance(node, gfx.MapIso):
64  self.current_flags_ = self.current_flags_ | SelHelper.HAS_IMG
65 
66  if self.scene_sel_.GetActiveViewCount() > 0:
67  self.current_flags_ = self.current_flags_ | SelHelper.HAS_VIEW
68 
69  cnt = 0
70  if self.current_flags_ & SelHelper.HAS_ENTITY:
71  cnt += 1
72  if self.current_flags_ & SelHelper.HAS_SURFACE:
73  cnt += 1
74  if self.current_flags_ & SelHelper.HAS_IMG:
75  cnt += 1
76  if self.current_flags_ & SelHelper.HAS_VIEW:
77  cnt += 1
78 
79  if cnt == 1:
80  self.current_flags_ = self.current_flags_ | SelHelper.IS_ONE_TYPE
81  elif cnt > 1:
82  self.current_flags_ = self.current_flags_ | SelHelper.IS_MULTI_TYPE
83 
84  if self.scene_sel_.GetActiveNodeCount()==1:
85  self.current_flags_ = self.current_flags_ | SelHelper.SINGLE_SELECTION
86  elif self.scene_sel_.GetActiveNodeCount()>1:
87  self.current_flags_ = self.current_flags_ | SelHelper.MULTI_SELECTION
88 
89  def CheckAllFlags(self, flags):
90  if(flags == self.current_flags_ & flags) and (flags == self.current_flags_ | flags):
91  return True
92  return False
93 
94  def CheckNotFlags(self, flags):
95  return not self.CheckFlags(flags)
96 
97  def CheckFlags(self, flags):
98  if(flags == self.current_flags_ & flags):
99  return True
100  return False
101 
102  def CheckMinOneFlag(self, flags):
103  if((self.current_flags_ - (self.current_flags_ & flags)) < self.current_flags_):
104  return True
105  return False
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:60
isocontour rendering for 3D image data
Definition: map_iso.hh:52