00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 import sys
00022 from ost import gui
00023 from ost import gfx
00024 try:
00025 from ost import img
00026 from wireframe_widget import WireframeWidget
00027 _img_present=True
00028 except ImportError:
00029 _img_present=False
00030 pass
00031 from PyQt4 import QtCore, QtGui
00032 from scene_selection_helper import SelHelper
00033 from combo_options_widget import ComboOptionsWidget
00034 from custom_widget import CustomWidget
00035 from cpk_widget import CPKWidget
00036 from tube_widget import TubeWidget
00037 from simple_widget import SimpleWidget
00038 from sline_widget import SlineWidget
00039 from hsc_widget import HSCWidget
00040 from trace_widget import TraceWidget
00041 from line_trace_widget import LineTraceWidget
00042
00043 class RenderOptionsWidget(ComboOptionsWidget):
00044 def __init__(self, parent=None):
00045 ComboOptionsWidget.__init__(self, parent)
00046
00047
00048 self.text_ = "Render Options"
00049
00050 self.keep_action_ = QtGui.QAction("K",self)
00051 self.keep_action_.setCheckable(True);
00052 self.keep_action_.setChecked(False)
00053 self.keep_action_.setToolTip("Keep rendermodes and add current")
00054 self.keep_button_ = QtGui.QToolButton(self)
00055 self.keep_button_.setDefaultAction(self.keep_action_)
00056
00057 self.grid_layout_.addWidget(self.keep_button_, 0, 1, 1, 1)
00058 self.grid_layout_.addWidget(self.stacked_widget_, 1, 0, 1, 2)
00059
00060
00061 self.entity_widgets_ = list()
00062 self.entity_widgets_.append(["", EmptyMode()])
00063 self.entity_widgets_.append([gfx.RenderMode.SIMPLE, SimpleWidget()])
00064 self.entity_widgets_.append([gfx.RenderMode.CUSTOM, CustomWidget()])
00065 self.entity_widgets_.append([gfx.RenderMode.CPK, CPKWidget()])
00066 self.entity_widgets_.append([gfx.RenderMode.LINE_TRACE, LineTraceWidget()])
00067 self.entity_widgets_.append([gfx.RenderMode.TRACE, TraceWidget()])
00068 self.entity_widgets_.append([gfx.RenderMode.SLINE, SlineWidget()])
00069 self.entity_widgets_.append([gfx.RenderMode.TUBE, TubeWidget()])
00070 self.entity_widgets_.append([gfx.RenderMode.HSC, HSCWidget()])
00071
00072 self.img_widgets_ = list()
00073 if _img_present:
00074 self.img_widgets_.append(["", EmptyMode()])
00075 self.img_widgets_.append([gfx.RenderMode.SIMPLE, WireframeWidget()])
00076 self.img_widgets_.append([gfx.RenderMode.FILL, EmptyMode("Fill",gfx.RenderMode.FILL)])
00077
00078 self._in_view_method = False
00079 self.setMinimumSize(250,200)
00080 def OnActivate(self, item):
00081 self.DoResize()
00082 def OnComboChange(self, item):
00083 scene_selection = gui.SceneSelection.Instance()
00084 for i in range(0,scene_selection.GetActiveNodeCount()):
00085 node = scene_selection.GetActiveNode(i)
00086 if isinstance(node, gfx.Entity) or (_img_present and isinstance(node, gfx.MapIso)):
00087 render_mode = item.GetRenderMode()
00088 if render_mode is not None:
00089 node.SetRenderMode(render_mode)
00090 if(scene_selection.GetActiveViewCount() > 0):
00091 entity = scene_selection.GetViewEntity()
00092 view = scene_selection.GetViewUnion()
00093 render_mode = item.GetRenderMode()
00094 if render_mode is not None:
00095 entity.SetRenderMode(item.GetRenderMode(),view,self.keep_action_.isChecked())
00096
00097 item.Update()
00098 self.DoResize()
00099
00100 def Update(self):
00101 if hasattr(self, "keep_button_"):
00102 self.keep_button_.setEnabled(True)
00103
00104 ComboOptionsWidget.setEnabled(self,True)
00105
00106 cur_widget = self.GetCurrentWidget()
00107 new_render_mode = None
00108 if cur_widget is not None:
00109 new_render_mode = cur_widget.GetRenderMode()
00110
00111 if SelHelper().CheckAllFlags(SelHelper.NO_SELECTION):
00112 ComboOptionsWidget.setEnabled(self,False)
00113 return
00114
00115 if not self._in_view_method:
00116 for w in self.entity_widgets_:
00117 self.RemoveWidget(w[0])
00118 for w in self.img_widgets_:
00119 self.RemoveWidget(w[0])
00120
00121 scene_selection = gui.SceneSelection.Instance()
00122 if scene_selection.GetActiveNodeCount() > 0 :
00123 if hasattr(self, "keep_button_"):
00124 self.keep_button_.setEnabled(False)
00125 render_mode_valid = True
00126 render_mode = None
00127 for i in range(0,scene_selection.GetActiveNodeCount()):
00128 node = scene_selection.GetActiveNode(i)
00129 if isinstance(scene_selection.GetActiveNode(i), gfx.GfxObj):
00130 if render_mode is None:
00131 render_mode = node.GetRenderMode()
00132 elif render_mode != node.GetRenderMode():
00133 render_mode_valid = False
00134
00135 if SelHelper().CheckFlags(SelHelper.HAS_IMG | SelHelper.IS_ONE_TYPE):
00136 for w in self.img_widgets_:
00137 self.AddWidget(w[0], w[1])
00138 elif SelHelper().CheckMinOneFlag(SelHelper.HAS_ENTITY| SelHelper.HAS_VIEW) and SelHelper().CheckNotFlags(SelHelper.HAS_IMG):
00139 if not self._in_view_method:
00140 for w in self.entity_widgets_:
00141 self.AddWidget(w[0], w[1])
00142 else:
00143 ComboOptionsWidget.setEnabled(self,False)
00144 return
00145
00146 if SelHelper().CheckMinOneFlag(SelHelper.HAS_ENTITY| SelHelper.HAS_IMG) and SelHelper().CheckNotFlags(SelHelper.HAS_VIEW):
00147 if(render_mode_valid):
00148 ComboOptionsWidget.ChangeSelectedItem(self,render_mode)
00149 else:
00150 ComboOptionsWidget.ChangeSelectedItem(self,"")
00151 else:
00152 if not self._in_view_method:
00153 self._in_view_method = True
00154 ComboOptionsWidget.ChangeSelectedItem(self,new_render_mode)
00155 self.GetCurrentWidget().Update()
00156
00157 def GetText(self):
00158 return self.text_
00159
00160 class EmptyMode(QtGui.QWidget):
00161 def __init__(self, text="", render_mode=None, parent=None):
00162 QtGui.QLabel.__init__(self, parent)
00163 self.setMinimumSize(250,30)
00164 self.text = text
00165 self.render_mode = render_mode
00166 if(render_mode):
00167 text_label = QtGui.QLabel(text)
00168 font = text_label.font()
00169 font.setBold(True)
00170 grid = QtGui.QGridLayout()
00171 grid.addWidget(text_label,0,0,1,1)
00172 grid.addWidget(QtGui.QLabel("No Settings available"), 1, 0, 1, 3)
00173 grid.setRowStretch(2,1)
00174 self.setLayout(grid)
00175 self.setMinimumSize(250,60)
00176
00177 def Update(self):
00178 True
00179
00180 def GetText(self):
00181 return self.text
00182
00183 def GetRenderMode(self):
00184 return self.render_mode