OpenStructure
Loading...
Searching...
No Matches
hsc_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
21from ost import gui
22from ost import gfx
23from PyQt5 import QtCore, QtWidgets
24from .render_mode_widget import RenderModeWidget
25
26#Tube Render Options
28 def __init__(self, parent=None):
29 RenderModeWidget.__init__(self, parent)
30
31 #Title
32 self.text_ = "Helix & Strand Cartoon"
33
34 #Set Render Mode
35 self.mode_ = gfx.RenderMode.HSC
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_width = 0.1
45 max_width = 5.0
46 max_tube_width= 5.0
47
48 min_tube_ratio = 0.2
49 max_tube_ratio = 4
50 min_ratio = 0.1
51 max_ratio = 2.5
52
53 min_ecc = 0.1
54 max_ecc = 5
55
56 min_profile=0
57 max_profile=4
58
59
60
61 #Poly Mode
62 poly_mode_label = QtWidgets.QLabel("Poly Mode")
63
64 self.poly_mode_cb_ = QtWidgets.QComboBox()
65 self.poly_mode_cb_.addItem("Points")
66 self.poly_mode_cb_.addItem("Wireframe")
67 self.poly_mode_cb_.addItem("Surface")
68
69 #Sphere Label
70 spline_label = QtWidgets.QLabel("Spline Detail")
71
72 self.spline_spinbox_ = QtWidgets.QSpinBox()
73 self.spline_spinbox_.setRange(min_spline_detail, max_spline_detail)
74
75 #Arc Label
76 arc_label = QtWidgets.QLabel("Arc Detail")
77
78 self.arc_spinbox_ = QtWidgets.QSpinBox()
79 self.arc_spinbox_.setRange(min_arc_detail, max_arc_detail)
80
81 #Tube
82 tube_label = QtWidgets.QLabel("Tube")
83 font = tube_label.font()
84 font.setBold(True)
85
86 #Tube Radius
87 radius_tube_label = QtWidgets.QLabel("Radius")
88
89 self.width_tube_spinbox_ = QtWidgets.QDoubleSpinBox()
90 self.width_tube_spinbox_.setRange(min_width, max_tube_width)
91 self.width_tube_spinbox_.setDecimals(1)
92 self.width_tube_spinbox_.setSingleStep(0.1)
93
94 self.width_tube_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
95 self.width_tube_slider_.setRange(int(min_width*10.0), int(max_tube_width*10.0))
96 self.width_tube_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
97 self.width_tube_slider_.setTickInterval(1)
98
99 #Tube Ratio
100 ratio_tube_label = QtWidgets.QLabel("Ratio")
101
102 self.thickness_tube_spinbox_ = QtWidgets.QDoubleSpinBox()
103 self.thickness_tube_spinbox_.setRange(min_tube_ratio, max_tube_ratio)
104 self.thickness_tube_spinbox_.setDecimals(1)
105 self.thickness_tube_spinbox_.setSingleStep(0.1)
106
107 self.thickness_tube_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
108 self.thickness_tube_slider_.setRange(int(min_tube_ratio*10.0), int(max_tube_ratio*10))
109 self.thickness_tube_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
110 self.thickness_tube_slider_.setTickInterval(1)
111
112 # Tube Profile Type
113 tube_profile_label = QtWidgets.QLabel("Tube Profile Type")
114 self.tube_profile_spinbox_ = QtWidgets.QSpinBox()
115 self.tube_profile_spinbox_.setRange(min_profile, max_profile)
116
117 # Helix
118 helix_label = QtWidgets.QLabel("Helix")
119 font = helix_label.font()
120 font.setBold(True)
121
122 #Helix Radius
123 radius_helix_label = QtWidgets.QLabel("Width")
124
125 self.width_helix_spinbox_ = QtWidgets.QDoubleSpinBox()
126 self.width_helix_spinbox_.setRange(min_width, max_width)
127 self.width_helix_spinbox_.setDecimals(1)
128 self.width_helix_spinbox_.setSingleStep(0.1)
129
130 self.width_helix_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
131 self.width_helix_slider_.setRange(int(min_width*10.0), int(max_width*10.0))
132 self.width_helix_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
133 self.width_helix_slider_.setTickInterval(1)
134
135 #Helix Ratio
136 ratio_helix_label = QtWidgets.QLabel("Thickness")
137
138 self.thickness_helix_spinbox_ = QtWidgets.QDoubleSpinBox()
139 self.thickness_helix_spinbox_.setRange(min_ratio,max_ratio)
140 self.thickness_helix_spinbox_.setDecimals(1)
141 self.thickness_helix_spinbox_.setSingleStep(0.1)
142
143 self.thickness_helix_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
144 self.thickness_helix_slider_.setRange(int(min_ratio*10.0), int(max_ratio*10.0))
145 self.thickness_helix_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
146 self.thickness_helix_slider_.setTickInterval(1)
147
148 #Helix ECC
149 ecc_helix_label = QtWidgets.QLabel("ECC")
150
151 self.ecc_helix_spinbox_ = QtWidgets.QDoubleSpinBox()
152 self.ecc_helix_spinbox_.setRange(min_ecc,max_ecc)
153 self.ecc_helix_spinbox_.setDecimals(1)
154 self.ecc_helix_spinbox_.setSingleStep(0.1)
155
156 self.ecc_helix_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
157 self.ecc_helix_slider_.setRange(int(min_ecc*10), int(max_ecc*10))
158 self.ecc_helix_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
159 self.ecc_helix_slider_.setTickInterval(1)
160
161 # Helix Profile Type
162 helix_profile_label = QtWidgets.QLabel("Helix Profile Type")
163 self.helix_profile_spinbox_ = QtWidgets.QSpinBox()
164 self.helix_profile_spinbox_.setRange(min_profile, max_profile)
165
166 # Helix Rendering Mode
167 helix_mode_label = QtWidgets.QLabel("Helix Render Mode")
168 self.helix_mode_spinbox_ = QtWidgets.QSpinBox()
169 self.helix_mode_spinbox_.setRange(0, 1)
170
171 #Strand
172 strand_label = QtWidgets.QLabel("Strand")
173 font = strand_label.font()
174 font.setBold(1)
175
176 #Strand Radius
177 radius_strand_label = QtWidgets.QLabel("Width")
178
179 self.width_strand_spinbox_ = QtWidgets.QDoubleSpinBox()
180 self.width_strand_spinbox_.setRange(min_width, max_width)
181 self.width_strand_spinbox_.setDecimals(1)
182 self.width_strand_spinbox_.setSingleStep(0.1)
183
184 self.width_strand_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
185 self.width_strand_slider_.setRange(int(min_width*10), int(max_width*10))
186 self.width_strand_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
187 self.width_strand_slider_.setTickInterval(1)
188
189 #Strand Ratio
190 ratio_strand_label = QtWidgets.QLabel("Thickness")
191
192 self.thickness_strand_spinbox_ = QtWidgets.QDoubleSpinBox()
193 self.thickness_strand_spinbox_.setRange(min_ratio,max_ratio)
194 self.thickness_strand_spinbox_.setDecimals(1)
195 self.thickness_strand_spinbox_.setSingleStep(0.1)
196
197 self.thickness_strand_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
198 self.thickness_strand_slider_.setRange(int(min_ratio*10),int(max_ratio*10))
199 self.thickness_strand_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
200 self.thickness_strand_slider_.setTickInterval(1)
201
202 #Strand ECC
203 ecc_strand_label = QtWidgets.QLabel("ECC")
204
205 self.ecc_strand_spinbox_ = QtWidgets.QDoubleSpinBox()
206 self.ecc_strand_spinbox_.setRange(min_ecc,max_ecc)
207 self.ecc_strand_spinbox_.setDecimals(1)
208 self.ecc_strand_spinbox_.setSingleStep(0.1)
209
210 self.ecc_strand_slider_ = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
211 self.ecc_strand_slider_.setRange(int(min_ecc*10), int(max_ecc*10))
212 self.ecc_strand_slider_.setTickPosition(QtWidgets.QSlider.NoTicks)
213 self.ecc_strand_slider_.setTickInterval(1)
214
215 # Strand Profile Type
216 strand_profile_label = QtWidgets.QLabel("Strand Profile Type")
217 self.strand_profile_spinbox_ = QtWidgets.QSpinBox()
218 self.strand_profile_spinbox_.setRange(min_profile, max_profile)
219
220 # Strand Rendering Mode
221 strand_mode_label = QtWidgets.QLabel("Strand Render Mode")
222 self.strand_mode_spinbox_ = QtWidgets.QSpinBox()
223 self.strand_mode_spinbox_.setRange(0, 1)
224
225 #
226 row=1
227 grid = QtWidgets.QGridLayout()
228 grid.addWidget(poly_mode_label,row,0,1,1)
229 grid.addWidget(self.poly_mode_cb_,row,3,1,2)
230 row+=1
231 grid.addWidget(spline_label, row, 0, 1, 3)
232 grid.addWidget(self.spline_spinbox_, row, 4, 1, 1)
233 row+=1
234 grid.addWidget(arc_label,row,0,1,3)
235 grid.addWidget(self.arc_spinbox_,row,4,1,1)
236 row+=1
237 grid.addWidget(tube_label, row, 0, 1, 3)
238 row+=1
239 grid.addWidget(radius_tube_label, row, 0, 1, 1)
240 grid.addWidget(self.width_tube_slider_, row, 1, 1, 3)
241 grid.addWidget(self.width_tube_spinbox_, row, 4, 1, 1)
242 row+=1
243 grid.addWidget(ratio_tube_label, row, 0, 1, 1)
244 grid.addWidget(self.thickness_tube_slider_, row, 1, 1, 3)
245 grid.addWidget(self.thickness_tube_spinbox_, row, 4, 1, 1)
246 row+=1
247 grid.addWidget(tube_profile_label, row, 0, 1, 3)
248 grid.addWidget(self.tube_profile_spinbox_, row, 4, 1, 1)
249 row+=1
250 grid.addWidget(helix_label, row, 0, 1, 3)
251 row+=1
252 grid.addWidget(radius_helix_label, row, 0, 1, 1)
253 grid.addWidget(self.width_helix_slider_, row, 1, 1, 3)
254 grid.addWidget(self.width_helix_spinbox_, row, 4, 1, 1)
255 row+=1
256 grid.addWidget(ratio_helix_label, row, 0, 1, 1)
257 grid.addWidget(self.thickness_helix_slider_, row, 1, 1, 3)
258 grid.addWidget(self.thickness_helix_spinbox_, row, 4, 1, 1)
259 row+=1
260 grid.addWidget(ecc_helix_label, row, 0, 1, 1)
261 grid.addWidget(self.ecc_helix_slider_, row, 1, 1, 3)
262 grid.addWidget(self.ecc_helix_spinbox_, row, 4, 1, 1)
263 row+=1
264 grid.addWidget(helix_profile_label, row, 0, 1, 3)
265 grid.addWidget(self.helix_profile_spinbox_, row, 4, 1, 1)
266 row+=1
267 grid.addWidget(helix_mode_label, row, 0, 1, 3)
268 grid.addWidget(self.helix_mode_spinbox_, row, 4, 1, 1)
269 row+=1
270 grid.addWidget(strand_label, row, 0, 1, 3)
271 row+=1
272 grid.addWidget(radius_strand_label, row, 0, 1, 1)
273 grid.addWidget(self.width_strand_slider_, row, 1, 1, 3)
274 grid.addWidget(self.width_strand_spinbox_, row, 4, 1, 1)
275 row+=1
276 grid.addWidget(ratio_strand_label, row, 0, 1, 1)
277 grid.addWidget(self.thickness_strand_slider_, row, 1, 1, 3)
278 grid.addWidget(self.thickness_strand_spinbox_, row, 4, 1, 1)
279 row+=1
280 grid.addWidget(ecc_strand_label, row, 0, 1, 1)
281 grid.addWidget(self.ecc_strand_slider_, row, 1, 1, 3)
282 grid.addWidget(self.ecc_strand_spinbox_, row, 4, 1, 1)
283 row+=1
284 grid.addWidget(strand_profile_label, row, 0, 1, 3)
285 grid.addWidget(self.strand_profile_spinbox_, row, 4, 1, 1)
286 row+=1
287 grid.addWidget(strand_mode_label, row, 0, 1, 3)
288 grid.addWidget(self.strand_mode_spinbox_, row, 4, 1, 1)
289
290 grid.setRowStretch(row+1,1)
291 self.setLayout(grid)
292
294 self.arc_spinbox_.valueChanged.connect(self.UpdateArcDetailUpdateArcDetail)
295 self.poly_mode_cb_.currentIndexChanged.connect(self.UpdatePolyModeUpdatePolyMode)
296
302
307 self.ecc_helix_spinbox_.valueChanged.connect(self.UpdateHelixEccUpdateHelixEcc)
311
320
321 self.setMinimumSize(250,550)
322
323
324 def UpdateGui(self,options):
325 self.poly_mode_cb_.setCurrentIndex(options.GetPolyMode())
326 self.spline_spinbox_.setValue(options.GetSplineDetail())
327 self.arc_spinbox_.setValue(options.GetArcDetail())
328
329 self.UpdateTubeRadiusGui(options.GetTubeRadius())
330 self.UpdateTubeRatioGui(options.GetTubeRatio())
331 self.tube_profile_spinbox_.setValue(options.GetTubeProfileType())
332 self.UpdateHelixWidthGui(options.GetHelixWidth())
333 self.UpdateHelixThicknessGui(options.GetHelixThickness())
334 self.UpdateHelixEccGui(options.GetHelixEcc())
335 self.helix_profile_spinbox_.setValue(options.GetHelixProfileType())
336 self.helix_mode_spinbox_.setValue(options.GetHelixMode())
337 self.UpdateStrandWidthGui(options.GetStrandWidth())
338 self.UpdateStrandThicknessGui(options.GetStrandThickness())
339 self.UpdateStrandEccGui(options.GetStrandEcc())
340 self.strand_profile_spinbox_.setValue(options.GetStrandProfileType())
341 self.strand_mode_spinbox_.setValue(options.GetStrandMode())
342
343 def UpdatePolyMode(self, value):
344 self.GetOptions().SetPolyMode(value)
345 self.ApplyOptions()
346
347 def UpdateSplineDetail(self, value):
348 self.GetOptions().SetSplineDetail(value)
349 self.ApplyOptions()
350
351 def UpdateArcDetail(self, value):
352 self.GetOptions().SetArcDetail(value)
353 self.ApplyOptions()
354
355 def UpdateTubeRadius(self, value):
356 self.GetOptions().SetTubeRadius(value)
357 self.ApplyOptions()
358
359 def UpdateSliderTubeRadius(self, value):
360 self.GetOptions().SetTubeRadius(value/10.0)
361 self.ApplyOptions()
362
363 def UpdateTubeRatio(self, value):
364 self.GetOptions().SetTubeRatio(value)
365 self.ApplyOptions()
366
367 def UpdateSliderTubeRatio(self, value):
368 self.GetOptions().SetTubeRatio(value/10.0)
369 self.ApplyOptions()
370
371 def UpdateTubeProfileType(self, value):
372 self.GetOptions().SetTubeProfileType(value)
373 self.ApplyOptions()
374
375 def UpdateHelixWidth(self, value):
376 self.GetOptions().SetHelixWidth(value)
377 self.ApplyOptions()
378
379 def UpdateSliderHelixWidth(self, value):
380 self.GetOptions().SetHelixWidth(value/10.0)
381 self.ApplyOptions()
382
383 def UpdateHelixThickness(self, value):
384 self.GetOptions().SetHelixThickness(value)
385 self.ApplyOptions()
386
388 self.GetOptions().SetHelixThickness(value/10.0)
389 self.ApplyOptions()
390
391 def UpdateHelixEcc(self, value):
392 self.GetOptions().SetHelixEcc(value)
393 self.ApplyOptions()
394
395 def UpdateHelixProfileType(self, value):
396 self.GetOptions().SetHelixProfileType(value)
397 self.ApplyOptions()
398
399 def UpdateHelixMode(self, value):
400 self.GetOptions().SetHelixMode(value)
401 self.ApplyOptions()
402
403 def UpdateSliderHelixEcc(self, value):
404 self.GetOptions().SetHelixEcc(value/10.0)
405 self.ApplyOptions()
406
407 def UpdateStrandWidth(self, value):
408 self.GetOptions().SetStrandWidth(value)
409 self.ApplyOptions()
410
411 def UpdateSliderStrandWidth(self, value):
412 self.GetOptions().SetStrandWidth(value/10.0)
413 self.ApplyOptions()
414
415 def UpdateStrandThickness(self, value):
416 self.GetOptions().SetStrandThickness(value)
417 self.ApplyOptions()
418
420 self.GetOptions().SetStrandThickness(value/10.0)
421 self.ApplyOptions()
422
423 def UpdateStrandEcc(self, value):
424 self.GetOptions().SetStrandEcc(value)
425 self.ApplyOptions()
426
427 def UpdateSliderStrandEcc(self, value):
428 self.GetOptions().SetStrandEcc(value/10.0)
429 self.ApplyOptions()
430
431 def UpdateStrandProfileType(self, value):
432 self.GetOptions().SetStrandProfileType(value)
433 self.ApplyOptions()
434
435 def UpdateStrandMode(self, value):
436 self.GetOptions().SetStrandMode(value)
437 self.ApplyOptions()
438
439 def UpdateTubeRadiusGui(self,value):
440 value = round(value, 2)
441 if(abs(value*10.0 - self.width_tube_slider_.value())>=self.width_tube_slider_.singleStep()):
442 self.width_tube_slider_.setValue(int(value*10.0))
443 if(abs(value - self.width_tube_spinbox_.value())>=self.width_tube_spinbox_.singleStep()):
444 self.width_tube_spinbox_.setValue(value)
445
446 def UpdateTubeRatioGui(self,value):
447 value = round(value, 2)
448 if(abs(value*10.0 - self.thickness_tube_slider_.value())>=self.thickness_tube_slider_.singleStep()):
449 self.thickness_tube_slider_.setValue(int(value*10.0))
450 if(abs(value - self.thickness_tube_spinbox_.value())>=self.thickness_tube_spinbox_.singleStep()):
451 self.thickness_tube_spinbox_.setValue(value)
452
453 def UpdateHelixWidthGui(self, value):
454 value = round(value, 2)
455 if(abs(value*10.0 - self.width_helix_slider_.value())>=self.width_helix_slider_.singleStep()):
456 self.width_helix_slider_.setValue(int(value*10.0))
457 if(abs(value - self.width_helix_spinbox_.value())>=self.width_helix_spinbox_.singleStep()):
458 self.width_helix_spinbox_.setValue(value)
459
460 def UpdateHelixThicknessGui(self, value):
461 value = round(value, 2)
462 if(abs(value*10.0 - self.thickness_helix_slider_.value())>=self.thickness_helix_slider_.singleStep()):
463 self.thickness_helix_slider_.setValue(int(value*10.0))
464 if(abs(value - self.thickness_helix_spinbox_.value())>=self.thickness_helix_spinbox_.singleStep()):
465 self.thickness_helix_spinbox_.setValue(value)
466
467 def UpdateHelixEccGui(self, value):
468 value = round(value, 2)
469 if(abs(value*10.0 - self.ecc_helix_slider_.value())>=self.ecc_helix_slider_.singleStep()):
470 self.ecc_helix_slider_.setValue(int(value*10.0))
471 if(abs(value - self.ecc_helix_spinbox_.value())>=self.ecc_helix_spinbox_.singleStep()):
472 self.ecc_helix_spinbox_.setValue(value)
473
474 def UpdateStrandWidthGui(self, value):
475 value = round(value, 2)
476 if(abs(value*10.0 - self.width_strand_slider_.value())>=self.width_strand_slider_.singleStep()):
477 self.width_strand_slider_.setValue(int(value*10.0))
478 if(abs(value - self.width_strand_spinbox_.value())>=self.width_strand_spinbox_.singleStep()):
479 self.width_strand_spinbox_.setValue(value)
480
481 def UpdateStrandThicknessGui(self, value):
482 value = round(value, 2)
483 if(abs(value*10.0 - self.thickness_strand_slider_.value())>=self.thickness_strand_slider_.singleStep()):
484 self.thickness_strand_slider_.setValue(int(value*10.0))
485 if(abs(value - self.thickness_strand_spinbox_.value())>=self.thickness_strand_spinbox_.singleStep()):
486 self.thickness_strand_spinbox_.setValue(value)
487
488 def UpdateStrandEccGui(self, value):
489 value = round(value, 2)
490 if(abs(value*10.0 - self.ecc_strand_slider_.value())>=self.ecc_strand_slider_.singleStep()):
491 self.ecc_strand_slider_.setValue(int(value*10.0))
492 if(abs(value - self.ecc_strand_spinbox_.value())>=self.ecc_strand_spinbox_.singleStep()):
493 self.ecc_strand_spinbox_.setValue(value)
494
495 def GetText(self):
496 return self.text_
497
498 def GetRenderMode(self):
499 return self.mode_