00001 #------------------------------------------------------------------------------ 00002 # This file is part of the OpenStructure project <www.openstructure.org> 00003 # 00004 # Copyright (C) 2008-2011 by the OpenStructure authors 00005 # 00006 # This library is free software; you can redistribute it and/or modify it under 00007 # the terms of the GNU Lesser General Public License as published by the Free 00008 # Software Foundation; either version 3.0 of the License, or (at your option) 00009 # any later version. 00010 # This library is distributed in the hope that it will be useful, but WITHOUT 00011 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 # details. 00014 # 00015 # You should have received a copy of the GNU Lesser General Public License 00016 # along with this library; if not, write to the Free Software Foundation, Inc., 00017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 #------------------------------------------------------------------------------ 00019 00020 import sys 00021 from ost import gui 00022 import sip 00023 from ost import gfx 00024 import ost 00025 import os 00026 try: 00027 from ost import img 00028 _img_present=True 00029 except ImportError: 00030 _img_present=False 00031 pass 00032 00033 class SelHelper: 00034 __shared_state = {} 00035 00036 NO_SELECTION = 0 00037 HAS_ENTITY = 1 00038 HAS_VIEW = 2 00039 HAS_IMG = 4 00040 HAS_SURFACE = 8 00041 IS_ONE_TYPE = 16 00042 IS_MULTI_TYPE = 32 00043 SINGLE_SELECTION = 64 00044 MULTI_SELECTION = 128 00045 00046 def __init__(self): 00047 self.__dict__ = self.__shared_state 00048 if not '_ready' in dir(self): 00049 self.scene_sel_ = gui.SceneSelection.Instance() 00050 self.current_flags_ = 0 00051 self._ready = True 00052 00053 def Update(self): 00054 self.current_flags_ = 0 00055 if self.scene_sel_.GetActiveNodeCount() == 0 and self.scene_sel_.GetActiveViewCount() == 0: 00056 return 00057 00058 for i in range(0,self.scene_sel_.GetActiveNodeCount()): 00059 node = self.scene_sel_.GetActiveNode(i) 00060 if isinstance(node, gfx.Entity): 00061 self.current_flags_ = self.current_flags_ | SelHelper.HAS_ENTITY 00062 if isinstance(node, gfx.Surface): 00063 self.current_flags_ = self.current_flags_ | SelHelper.HAS_SURFACE 00064 if (_img_present) and isinstance(node, gfx.MapIso): 00065 self.current_flags_ = self.current_flags_ | SelHelper.HAS_IMG 00066 00067 if self.scene_sel_.GetActiveViewCount() > 0: 00068 self.current_flags_ = self.current_flags_ | SelHelper.HAS_VIEW 00069 00070 cnt = 0 00071 if self.current_flags_ & SelHelper.HAS_ENTITY: 00072 cnt += 1 00073 if self.current_flags_ & SelHelper.HAS_SURFACE: 00074 cnt += 1 00075 if self.current_flags_ & SelHelper.HAS_IMG: 00076 cnt += 1 00077 if self.current_flags_ & SelHelper.HAS_VIEW: 00078 cnt += 1 00079 00080 if cnt == 1: 00081 self.current_flags_ = self.current_flags_ | SelHelper.IS_ONE_TYPE 00082 elif cnt > 1: 00083 self.current_flags_ = self.current_flags_ | SelHelper.IS_MULTI_TYPE 00084 00085 if self.scene_sel_.GetActiveNodeCount()==1: 00086 self.current_flags_ = self.current_flags_ | SelHelper.SINGLE_SELECTION 00087 elif self.scene_sel_.GetActiveNodeCount()>1: 00088 self.current_flags_ = self.current_flags_ | SelHelper.MULTI_SELECTION 00089 00090 def CheckAllFlags(self, flags): 00091 if(flags == self.current_flags_ & flags) and (flags == self.current_flags_ | flags): 00092 return True 00093 return False 00094 00095 def CheckNotFlags(self, flags): 00096 return not self.CheckFlags(flags) 00097 00098 def CheckFlags(self, flags): 00099 if(flags == self.current_flags_ & flags): 00100 return True 00101 return False 00102 00103 def CheckMinOneFlag(self, flags): 00104 if((self.current_flags_ - (self.current_flags_ & flags)) < self.current_flags_): 00105 return True 00106 return False