OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tube_widget.py
Go to the documentation of this file.
1 #------------------------------------------------------------------------------
2 # This file is part of the OpenStructure project <www.openstructure.org>
3 #
4 # Copyright (C) 2008-2020 by the OpenStructure authors
5 #
6 # This library is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation; either version 3.0 of the License, or (at your option)
9 # any later version.
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #------------------------------------------------------------------------------
19 # -*- coding: utf-8 -*-
20 
21 from ost import gui
22 from ost import gfx
23 from PyQt5 import QtCore, QtWidgets
24 from .render_mode_widget import RenderModeWidget
25 
26 #Tube Render Options
27 class TubeWidget(RenderModeWidget):
28  def __init__(self, parent=None):
29  RenderModeWidget.__init__(self, parent)
30 
31  #Title
32  self.text_ = "Smooth Tube"
33 
34  #Set Render Mode
35  self.mode_ = gfx.RenderMode.TUBE
36 
37  #Defaults
38  min_spline_detail = 1
39  max_spline_detail = 20
40 
41  min_arc_detail = 1
42  max_arc_detail = 20
43 
44  min_radius = 0.1
45  max_radius = 2
46 
47  min_ratio = 0.2
48  max_ratio = 4
49 
50  #UI
51  tube_label = QtWidgets.QLabel("Tube Settings")
52  font = tube_label.font()
53  font.setBold(True)
54 
55  #Poly Mode
56  poly_mode_label = QtWidgets.QLabel("Poly Mode")
57 
58  self.poly_mode_cb_ = QtWidgets.QComboBox()
59  self.poly_mode_cb_.addItem("Points")
60  self.poly_mode_cb_.addItem("Wireframe")
61  self.poly_mode_cb_.addItem("Surface")
62 
63  #Sphere Label
64  spline_label = QtWidgets.QLabel("Spline Detail")
65 
66  self.spline_spinbox_ = QtWidgets.QSpinBox()
67  self.spline_spinbox_.setRange(min_spline_detail, max_spline_detail)
68 
69  #Arc Label
70  arc_label = QtWidgets.QLabel("Arc Detail")
71 
72  self.arc_spinbox_ = QtWidgets.QSpinBox()
73  self.arc_spinbox_.setRange(min_arc_detail, max_arc_detail)
74 
75  #Radius
76  radius_label = QtWidgets.QLabel("Tube radius")
77 
78 
79  self.radius_spinbox_ = QtWidgets.QDoubleSpinBox()
80  self.radius_spinbox_.setRange(min_radius, max_radius)
81  self.radius_spinbox_.setDecimals(1)
82  self.radius_spinbox_.setSingleStep(0.1)
83 
84  self.radius_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
85  self.radius_slider_.setRange(int(min_radius*10.0), int(max_radius*10.0))
86  self.radius_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
87  self.radius_slider_.setTickInterval(1)
88 
89  #Ratio
90  ratio_label = QtWidgets.QLabel("Tube ratio")
91 
92  self.ratio_spinbox_ = QtWidgets.QDoubleSpinBox()
93  self.ratio_spinbox_.setRange(min_ratio, max_ratio)
94  self.ratio_spinbox_.setDecimals(1)
95  self.ratio_spinbox_.setSingleStep(0.1)
96  self.ratio_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
97  self.ratio_slider_.setRange(int(min_ratio*10.0), int(max_ratio*10.0))
98  self.ratio_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
99  self.ratio_slider_.setTickInterval(2)
100 
101  grid = QtWidgets.QGridLayout()
102  grid.addWidget(tube_label,0,0,1,3)
103  grid.addWidget(poly_mode_label,1,0,1,3)
104  grid.addWidget(self.poly_mode_cb_,1,3,1,2)
105  grid.addWidget(spline_label, 2, 0, 1, 3)
106  grid.addWidget(self.spline_spinbox_, 2, 4, 1, 1)
107  grid.addWidget(arc_label,3,0,1,3)
108  grid.addWidget(self.arc_spinbox_,3,4,1,1)
109  grid.addWidget(radius_label,4,0,1,1)
110  grid.addWidget(self.radius_slider_,4,1,1,3)
111  grid.addWidget(self.radius_spinbox_,4,4,1,1)
112  grid.addWidget(ratio_label,5,0,1,1)
113  grid.addWidget(self.ratio_slider_,5,1,1,3)
114  grid.addWidget(self.ratio_spinbox_,5,4,1,1)
115  grid.setRowStretch(6,1)
116  self.setLayout(grid)
117 
118  self.spline_spinbox_.valueChanged.connect(self.UpdateSplineDetail)
119  self.arc_spinbox_.valueChanged.connect(self.UpdateArcDetail)
120  self.poly_mode_cb_.currentIndexChanged.connect(self.UpdatePolyMode)
121  self.radius_spinbox_.valueChanged.connect(self.UpdateRadius)
122  self.radius_slider_.valueChanged.connect(self.UpdateSliderRadius)
123  self.ratio_spinbox_.valueChanged.connect(self.UpdateRatio)
124  self.ratio_slider_.valueChanged.connect(self.UpdateSliderRatio)
125 
126  self.setMinimumSize(250,200)
127 
128  def UpdateGui(self,options):
129  self.poly_mode_cb_.setCurrentIndex(options.GetPolyMode())
130  self.spline_spinbox_.setValue(options.GetSplineDetail())
131  self.arc_spinbox_.setValue(options.GetArcDetail())
132  self.UpdateRadiusGui(options.GetTubeRadius())
133  self.UpdateRatioGui(options.GetTubeRatio())
134 
135  def UpdatePolyMode(self, value):
136  self.GetOptions().SetPolyMode(value)
137  self.ApplyOptions()
138 
139  def UpdateSplineDetail(self, value):
140  self.GetOptions().SetSplineDetail(value)
141  self.ApplyOptions()
142 
143  def UpdateArcDetail(self, value):
144  self.GetOptions().SetArcDetail(value)
145  self.ApplyOptions()
146 
147  def UpdateRadius(self, value):
148  self.GetOptions().SetTubeRadius(value)
149  self.ApplyOptions()
150 
151  def UpdateSliderRadius(self, value):
152  self.GetOptions().SetTubeRadius(value/10.0)
153 
154  def UpdateRatio(self, value):
155  self.GetOptions().SetTubeRatio(value)
156 
157  def UpdateSliderRatio(self, value):
158  self.GetOptions().SetTubeRatio(value/10.0)
159 
160  def UpdateRadiusGui(self,value):
161  value = round(value, 2)
162  if(abs(value*10.0 - self.radius_slider_.value())>=self.radius_slider_.singleStep()):
163  self.radius_slider_.setValue(int(value*10.0))
164  if(abs(value - self.radius_spinbox_.value())>=self.radius_spinbox_.singleStep()):
165  self.radius_spinbox_.setValue(value)
166 
167  def UpdateRatioGui(self,value):
168  value = round(value, 2)
169  if(abs(value*10.0 - self.ratio_slider_.value())>=self.ratio_slider_.singleStep()):
170  self.ratio_slider_.setValue(int(value*10.0))
171  if(abs(value - self.ratio_spinbox_.value())>=self.ratio_spinbox_.singleStep()):
172  self.ratio_spinbox_.setValue(value)
173 
174  def GetText(self):
175  return self.text_
176 
177  def GetRenderMode(self):
178  return self.mode_