OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
render_options_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 import sys
22 from ost import gui
23 from ost import gfx
24 try:
25  from ost import img
26  from .wireframe_widget import WireframeWidget
27  _img_present=True
28 except ImportError:
29  _img_present=False
30  pass
31 from PyQt5 import QtCore, QtWidgets
32 from .scene_selection_helper import SelHelper
33 from .combo_options_widget import ComboOptionsWidget
34 from .custom_widget import CustomWidget
35 from .cpk_widget import CPKWidget
36 from .tube_widget import TubeWidget
37 from .simple_widget import SimpleWidget
38 from .sline_widget import SlineWidget
39 from .hsc_widget import HSCWidget
40 from .trace_widget import TraceWidget
41 from .line_trace_widget import LineTraceWidget
42 
43 class RenderOptionsWidget(ComboOptionsWidget):
44  def __init__(self, parent=None):
45  ComboOptionsWidget.__init__(self, parent)
46 
47  #Title
48  self.text_ = "Render Options"
49 
50  self.keep_action_ = QtWidgets.QAction("K",self)
51  self.keep_action_.setCheckable(True);
52  self.keep_action_.setChecked(False)
53  self.keep_action_.setToolTip("Keep rendermodes and add current")
54  self.keep_button_ = QtWidgets.QToolButton(self)
55  self.keep_button_.setDefaultAction(self.keep_action_)
56 
57  self.grid_layout_.addWidget(self.keep_button_, 0, 1, 1, 1)
58  self.grid_layout_.addWidget(self.stacked_widget_, 1, 0, 1, 2)
59 
60  #Add options to menu
61  self.entity_widgets_ = list()
62  self.entity_widgets_.append(["", EmptyMode()])
63  self.entity_widgets_.append([gfx.RenderMode.SIMPLE, SimpleWidget()])
64  self.entity_widgets_.append([gfx.RenderMode.CUSTOM, CustomWidget()])
65  self.entity_widgets_.append([gfx.RenderMode.CPK, CPKWidget()])
66  self.entity_widgets_.append([gfx.RenderMode.LINE_TRACE, LineTraceWidget()])
67  self.entity_widgets_.append([gfx.RenderMode.TRACE, TraceWidget()])
68  self.entity_widgets_.append([gfx.RenderMode.SLINE, SlineWidget()])
69  self.entity_widgets_.append([gfx.RenderMode.TUBE, TubeWidget()])
70  self.entity_widgets_.append([gfx.RenderMode.HSC, HSCWidget()])
71 
72  self.img_widgets_ = list()
73  if _img_present:
74  self.img_widgets_.append(["", EmptyMode()])
75  self.img_widgets_.append([gfx.RenderMode.SIMPLE, WireframeWidget()])
76  self.img_widgets_.append([gfx.RenderMode.FILL, EmptyMode("Fill",gfx.RenderMode.FILL)])
77 
78  self._in_view_method = False
79  self.setMinimumSize(250,200)
80  def OnActivate(self, item):
81  self.DoResize()
82  def OnComboChange(self, item):
83  scene_selection = gui.SceneSelection.Instance()
84  for i in range(0,scene_selection.GetActiveNodeCount()):
85  node = scene_selection.GetActiveNode(i)
86  if isinstance(node, gfx.Entity) or (_img_present and isinstance(node, gfx.MapIso)):
87  render_mode = item.GetRenderMode()
88  if render_mode is not None:
89  node.SetRenderMode(render_mode)
90  if(scene_selection.GetActiveViewCount() > 0):
91  entity = scene_selection.GetViewEntity()
92  view = scene_selection.GetViewUnion()
93  render_mode = item.GetRenderMode()
94  if render_mode is not None:
95  entity.SetRenderMode(item.GetRenderMode(),view,self.keep_action_.isChecked())
96 
97  item.Update()
98  self.DoResize()
99 
100  def Update(self):
101  if hasattr(self, "keep_button_"):
102  self.keep_button_.setEnabled(True)
103 
104  ComboOptionsWidget.setEnabled(self,True)
105 
106  cur_widget = self.GetCurrentWidget()
107  new_render_mode = None
108  if cur_widget is not None:
109  new_render_mode = cur_widget.GetRenderMode()
110 
111  if SelHelper().CheckAllFlags(SelHelper.NO_SELECTION):
112  ComboOptionsWidget.setEnabled(self,False)
113  return
114 
115  if not self._in_view_method:
116  for w in self.entity_widgets_:
117  self.RemoveWidget(w[0])
118  for w in self.img_widgets_:
119  self.RemoveWidget(w[0])
120 
121  scene_selection = gui.SceneSelection.Instance()
122  if scene_selection.GetActiveNodeCount() > 0 :
123  if hasattr(self, "keep_button_"):
124  self.keep_button_.setEnabled(False)
125  render_mode_valid = True
126  render_mode = None
127  for i in range(0,scene_selection.GetActiveNodeCount()):
128  node = scene_selection.GetActiveNode(i)
129  if isinstance(scene_selection.GetActiveNode(i), gfx.GfxObj):
130  if render_mode is None:
131  render_mode = node.GetRenderMode()
132  elif render_mode != node.GetRenderMode():
133  render_mode_valid = False
134 
135  if SelHelper().CheckFlags(SelHelper.HAS_IMG | SelHelper.IS_ONE_TYPE):
136  for w in self.img_widgets_:
137  self.AddWidget(w[0], w[1])
138  elif SelHelper().CheckMinOneFlag(SelHelper.HAS_ENTITY| SelHelper.HAS_VIEW) and SelHelper().CheckNotFlags(SelHelper.HAS_IMG):
139  if not self._in_view_method:
140  for w in self.entity_widgets_:
141  self.AddWidget(w[0], w[1])
142  else:
143  ComboOptionsWidget.setEnabled(self,False)
144  return
145 
146  if SelHelper().CheckMinOneFlag(SelHelper.HAS_ENTITY| SelHelper.HAS_IMG) and SelHelper().CheckNotFlags(SelHelper.HAS_VIEW):
147  if(render_mode_valid):
148  ComboOptionsWidget.ChangeSelectedItem(self,render_mode)
149  else:
150  ComboOptionsWidget.ChangeSelectedItem(self,"")
151  else:
152  if not self._in_view_method:
153  self._in_view_method = True
154  ComboOptionsWidget.ChangeSelectedItem(self,new_render_mode)
155  self.GetCurrentWidget().Update()
156 
157  def GetText(self):
158  return self.text_
159 
160 class EmptyMode(QtWidgets.QWidget):
161  def __init__(self, text="", render_mode=None, parent=None):
162  QtWidgets.QLabel.__init__(self, parent)
163  self.setMinimumSize(250,30)
164  self.text = text
165  self.render_mode = render_mode
166  if(render_mode):
167  text_label = QtWidgets.QLabel(text)
168  font = text_label.font()
169  font.setBold(True)
170  grid = QtWidgets.QGridLayout()
171  grid.addWidget(text_label,0,0,1,1)
172  grid.addWidget(QtWidgets.QLabel("No Settings available"), 1, 0, 1, 3)
173  grid.setRowStretch(2,1)
174  self.setLayout(grid)
175  self.setMinimumSize(250,60)
176 
177  def Update(self):
178  True #Do Nothing
179 
180  def GetText(self):
181  return self.text
182 
183  def GetRenderMode(self):
184  return self.render_mode
main class for all graphic objects
Definition: gfx_object.hh:51
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:60
isocontour rendering for 3D image data
Definition: map_iso.hh:52