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 RenderOp:
00026 RENDERMODE_ATTRIBUTE_NAME = "RenderMode"
00027 KEEP_ATTRIBUTE_NAME = "Keep"
00028 FLAGS_ATTRIBUTE_NAME = "Flags"
00029
00030 def __init__(self, render_mode, selection, flags, keep=False):
00031 self.render_mode_ = render_mode
00032 self.selection_ = selection
00033 self.keep_ = keep
00034 self.flags_ = flags
00035
00036 def GetName(self):
00037 return "Render mode: %s"%str(self.GetRenderMode())
00038
00039 def SetRenderMode(self, render_mode):
00040 self.render_mode_ = render_mode
00041
00042 def GetRenderMode(self):
00043 return self.render_mode_
00044
00045 def SetSelection(self, selection):
00046 self.selection_ = selection
00047
00048 def GetSelection(self):
00049 return self.selection_
00050
00051 def SetSelectionFlags(self, flags):
00052 self.flags_ = flags
00053
00054 def GetSelectionFlags(self):
00055 return self.flags_
00056
00057 def SetKeep(self, keep):
00058 self.keep_ = keep
00059
00060 def IsKept(self):
00061 return self.keep_
00062
00063 def ApplyOn(self, entity):
00064 if (entity is not None) and isinstance(entity, gfx.Entity):
00065 entity.SetRenderMode(self.GetRenderMode(),entity.view.Select(self.GetSelection(),self.GetSelectionFlags()),self.IsKept())
00066
00067 def ToInfo(self,group):
00068 group.SetAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME, str(self.GetRenderMode().name))
00069 group.SetAttribute(RenderOp.KEEP_ATTRIBUTE_NAME, str(int(self.IsKept())))
00070 group.SetAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME, str(self.GetSelectionFlags()))
00071 group.SetTextData(str(self.GetSelection()))
00072
00073 @staticmethod
00074 def FromInfo(group):
00075 render_op = None
00076 if (group.HasAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME)
00077 and group.HasAttribute(RenderOp.KEEP_ATTRIBUTE_NAME)):
00078 render_mode = getattr(gfx.RenderMode, group.GetAttribute(RenderOp.RENDERMODE_ATTRIBUTE_NAME))
00079 keep = bool(int(group.GetAttribute(RenderOp.KEEP_ATTRIBUTE_NAME)))
00080 flags=0
00081 if group.HasAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME):
00082 flags = int(group.GetAttribute(RenderOp.FLAGS_ATTRIBUTE_NAME))
00083 selection = group.GetTextData()
00084 render_op = RenderOp(render_mode,selection,flags,keep)
00085 return render_op