00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 from ost import info
00022 from ost import gfx
00023 from PyQt4 import QtGui
00024
00025 class VisibilityOp:
00026 VISIBLE_ATTRIBUTE_NAME = "Visible"
00027 FLAGS_ATTRIBUTE_NAME = "Flags"
00028
00029 def __init__(self, selection, flags, visible=False):
00030 self.selection_ = selection
00031 self.visible_ = visible
00032 self.flags_ = flags
00033
00034 def GetName(self):
00035 return "Visible: %s"%str(self.IsVisible())
00036
00037 def SetSelection(self, selection):
00038 self.selection_ = selection
00039
00040 def GetSelection(self):
00041 return self.selection_
00042
00043 def SetVisible(self, visible):
00044 self.visible_ = visible
00045
00046 def SetSelectionFlags(self, flags):
00047 self.flags_ = flags
00048
00049 def GetSelectionFlags(self):
00050 return self.flags_
00051
00052 def IsVisible(self):
00053 return self.visible_
00054
00055 def ApplyOn(self, entity):
00056 if (entity is not None) and isinstance(entity, gfx.Entity):
00057 entity.SetVisible(entity.view.Select(self.GetSelection(),self.GetSelectionFlags()),self.IsVisible())
00058
00059 def ToInfo(self,group):
00060 group.SetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME, str(int(self.IsVisible())))
00061 group.SetAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME, str(self.GetSelectionFlags()))
00062 group.SetTextData(str(self.GetSelection()))
00063
00064 @staticmethod
00065 def FromInfo(group):
00066 visible_op = None
00067 if group.HasAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME):
00068 visible = bool(int(group.GetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME)))
00069 flags = 0
00070 if group.HasAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME):
00071 flags = int(group.GetAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME))
00072 selection = group.GetTextData()
00073 visible_op = VisibilityOp(selection,flags,visible)
00074 return visible_op