00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 from ost import gui
00022 from ost import gfx
00023 from PyQt4 import QtCore, QtGui
00024 from render_mode_widget import RenderModeWidget
00025
00026
00027 class TubeWidget(RenderModeWidget):
00028 def __init__(self, parent=None):
00029 RenderModeWidget.__init__(self, parent)
00030
00031
00032 self.text_ = "Smooth Tube"
00033
00034
00035 self.mode_ = gfx.RenderMode.TUBE
00036
00037
00038 min_spline_detail = 1
00039 max_spline_detail = 20
00040
00041 min_arc_detail = 1
00042 max_arc_detail = 20
00043
00044 min_radius = 0.1
00045 max_radius = 2
00046
00047 min_ratio = 0.2
00048 max_ratio = 4
00049
00050
00051 tube_label = QtGui.QLabel("Tube Settings")
00052 font = tube_label.font()
00053 font.setBold(True)
00054
00055
00056 poly_mode_label = QtGui.QLabel("Poly Mode")
00057
00058 self.poly_mode_cb_ = QtGui.QComboBox()
00059 self.poly_mode_cb_.addItem("Points")
00060 self.poly_mode_cb_.addItem("Wireframe")
00061 self.poly_mode_cb_.addItem("Surface")
00062
00063
00064 spline_label = QtGui.QLabel("Spline Detail")
00065
00066 self.spline_spinbox_ = QtGui.QSpinBox()
00067 self.spline_spinbox_.setRange(min_spline_detail, max_spline_detail)
00068
00069
00070 arc_label = QtGui.QLabel("Arc Detail")
00071
00072 self.arc_spinbox_ = QtGui.QSpinBox()
00073 self.arc_spinbox_.setRange(min_arc_detail, max_arc_detail)
00074
00075
00076 radius_label = QtGui.QLabel("Tube radius")
00077
00078
00079 self.radius_spinbox_ = QtGui.QDoubleSpinBox()
00080 self.radius_spinbox_.setRange(min_radius, max_radius)
00081 self.radius_spinbox_.setDecimals(1)
00082 self.radius_spinbox_.setSingleStep(0.1)
00083
00084 self.radius_slider_ = QtGui.QSlider(QtCore.Qt.Horizontal, self)
00085 self.radius_slider_.setRange(min_radius*10.0, max_radius*10.0)
00086 self.radius_slider_.setTickPosition(QtGui.QSlider.NoTicks)
00087 self.radius_slider_.setTickInterval(1)
00088
00089
00090 ratio_label = QtGui.QLabel("Tube ratio")
00091
00092 self.ratio_spinbox_ = QtGui.QDoubleSpinBox()
00093 self.ratio_spinbox_.setRange(min_ratio, max_ratio)
00094 self.ratio_spinbox_.setDecimals(1)
00095 self.ratio_spinbox_.setSingleStep(0.1)
00096 self.ratio_slider_ = QtGui.QSlider(QtCore.Qt.Horizontal, self)
00097 self.ratio_slider_.setRange(min_ratio*10.0, max_ratio*10.0)
00098 self.ratio_slider_.setTickPosition(QtGui.QSlider.NoTicks)
00099 self.ratio_slider_.setTickInterval(2)
00100
00101 grid = QtGui.QGridLayout()
00102 grid.addWidget(tube_label,0,0,1,3)
00103 grid.addWidget(poly_mode_label,1,0,1,3)
00104 grid.addWidget(self.poly_mode_cb_,1,3,1,2)
00105 grid.addWidget(spline_label, 2, 0, 1, 3)
00106 grid.addWidget(self.spline_spinbox_, 2, 4, 1, 1)
00107 grid.addWidget(arc_label,3,0,1,3)
00108 grid.addWidget(self.arc_spinbox_,3,4,1,1)
00109 grid.addWidget(radius_label,4,0,1,1)
00110 grid.addWidget(self.radius_slider_,4,1,1,3)
00111 grid.addWidget(self.radius_spinbox_,4,4,1,1)
00112 grid.addWidget(ratio_label,5,0,1,1)
00113 grid.addWidget(self.ratio_slider_,5,1,1,3)
00114 grid.addWidget(self.ratio_spinbox_,5,4,1,1)
00115 grid.setRowStretch(6,1)
00116 self.setLayout(grid)
00117
00118 QtCore.QObject.connect(self.spline_spinbox_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateSplineDetail)
00119 QtCore.QObject.connect(self.arc_spinbox_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateArcDetail)
00120 QtCore.QObject.connect(self.poly_mode_cb_, QtCore.SIGNAL("currentIndexChanged(int)"), self.UpdatePolyMode)
00121 QtCore.QObject.connect(self.radius_spinbox_, QtCore.SIGNAL("valueChanged(double)"), self.UpdateRadius)
00122 QtCore.QObject.connect(self.radius_slider_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateSliderRadius)
00123 QtCore.QObject.connect(self.ratio_spinbox_, QtCore.SIGNAL("valueChanged(double)"), self.UpdateRatio)
00124 QtCore.QObject.connect(self.ratio_slider_, QtCore.SIGNAL("valueChanged(int)"), self.UpdateSliderRatio)
00125
00126 self.setMinimumSize(250,200)
00127
00128 def UpdateGui(self,options):
00129 self.poly_mode_cb_.setCurrentIndex(options.GetPolyMode())
00130 self.spline_spinbox_.setValue(options.GetSplineDetail())
00131 self.arc_spinbox_.setValue(options.GetArcDetail())
00132 self.UpdateRadiusGui(options.GetTubeRadius())
00133 self.UpdateRatioGui(options.GetTubeRatio())
00134
00135 def UpdatePolyMode(self, value):
00136 self.GetOptions().SetPolyMode(value)
00137 self.ApplyOptions()
00138
00139 def UpdateSplineDetail(self, value):
00140 self.GetOptions().SetSplineDetail(value)
00141 self.ApplyOptions()
00142
00143 def UpdateArcDetail(self, value):
00144 self.GetOptions().SetArcDetail(value)
00145 self.ApplyOptions()
00146
00147 def UpdateRadius(self, value):
00148 self.GetOptions().SetTubeRadius(value)
00149 self.ApplyOptions()
00150
00151 def UpdateSliderRadius(self, value):
00152 self.GetOptions().SetTubeRadius(value/10.0)
00153
00154 def UpdateRatio(self, value):
00155 self.GetOptions().SetTubeRatio(value)
00156
00157 def UpdateSliderRatio(self, value):
00158 self.GetOptions().SetTubeRatio(value/10.0)
00159
00160 def UpdateRadiusGui(self,value):
00161 value = round(value, 2)
00162 if(abs(value*10.0 - self.radius_slider_.value())>=self.radius_slider_.singleStep()):
00163 self.radius_slider_.setValue(value*10.0)
00164 if(abs(value - self.radius_spinbox_.value())>=self.radius_spinbox_.singleStep()):
00165 self.radius_spinbox_.setValue(value)
00166
00167 def UpdateRatioGui(self,value):
00168 value = round(value, 2)
00169 if(abs(value*10.0 - self.ratio_slider_.value())>=self.ratio_slider_.singleStep()):
00170 self.ratio_slider_.setValue(value*10.0)
00171 if(abs(value - self.ratio_spinbox_.value())>=self.ratio_spinbox_.singleStep()):
00172 self.ratio_spinbox_.setValue(value)
00173
00174 def GetText(self):
00175 return self.text_
00176
00177 def GetRenderMode(self):
00178 return self.mode_