OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wireframe_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-2011 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 PyQt4 import QtCore, QtGui
24 try:
25  from ost import img
26  _img_present=True
27 except ImportError:
28  _img_present=False
29  pass
30 from scene_selection_helper import SelHelper
31 
32 #Wireframe Options
33 class WireframeWidget(QtGui.QWidget):
34  def __init__(self, parent=None):
35  QtGui.QWidget.__init__(self, parent)
36 
37  #Title
38  self.text_ = "Wireframe"
39 
40  #Defaults
41  min_line_width = 0.01
42  max_line_width = 20
43 
44  #Set Render Mode
45  self.mode_ = gfx.RenderMode.SIMPLE
46 
47  #Create Ui elements
48  self.aa_rendering_cb_ = QtGui.QCheckBox()
49 
50  self.radius_spinbox_ = QtGui.QDoubleSpinBox()
51  self.radius_spinbox_.setRange(min_line_width, max_line_width)
52  self.radius_spinbox_.setDecimals(2)
53  self.radius_spinbox_.setSingleStep(0.1)
54 
55  simple_label = QtGui.QLabel("Wireframe Settings")
56  font = simple_label.font()
57  font.setBold(True)
58 
59  radius_label = QtGui.QLabel("Line Width")
60  aa_label = QtGui.QLabel("AA-Lines")
61 
62  grid = QtGui.QGridLayout()
63  grid.addWidget(simple_label,0,0,1,3)
64  grid.addWidget(aa_label, 1, 0, 1, 3)
65  grid.addWidget(self.aa_rendering_cb_, 1, 2, 1, 1)
66  grid.addWidget(radius_label,2,0,1,3)
67  grid.addWidget(self.radius_spinbox_,2,2,1,1)
68  grid.setRowStretch(5,1)
69  self.setLayout(grid)
70 
71  QtCore.QObject.connect(self.radius_spinbox_, QtCore.SIGNAL("valueChanged(double)"), self.UpdateLineWidth)
72  QtCore.QObject.connect(self.aa_rendering_cb_, QtCore.SIGNAL("stateChanged(int)"), self.UpdateAA)
73 
74  self.setMinimumSize(250,100)
75 
76  def UpdateAA(self, value):
77  scene_selection = gui.SceneSelection.Instance()
78  for i in range(0,scene_selection.GetActiveNodeCount()):
79  node = scene_selection.GetActiveNode(i)
80  node.SetAALines(value)
81 
82  def UpdateLineWidth(self, value):
83  scene_selection = gui.SceneSelection.Instance()
84  for i in range(0,scene_selection.GetActiveNodeCount()):
85  node = scene_selection.GetActiveNode(i)
86  node.SetLineWidth(value)
87 
88  def UpdateGui(self):
89  scene_selection = gui.SceneSelection.Instance()
90  node = scene_selection.GetActiveNode(0)
91  self.radius_spinbox_.setValue(node.GetLineWidth())
92 
93  def Update(self):
94  self.setEnabled(True)
95  self.UpdateGui()
96  if SelHelper().CheckNotFlags(SelHelper.HAS_IMG | SelHelper.IS_ONE_TYPE):
97  self.setEnabled(False)
98 
99  def GetText(self):
100  return self.text_
101 
102  def GetRenderMode(self):
103  return self.mode_