diff --git a/modules/gui/pymod/CMakeLists.txt b/modules/gui/pymod/CMakeLists.txt index caf7a25735ff138062486d5029e322196061f96a..911f91d3c576f6aaa8ed72cb74f01bd3ce0b509d 100644 --- a/modules/gui/pymod/CMakeLists.txt +++ b/modules/gui/pymod/CMakeLists.txt @@ -50,6 +50,7 @@ toolbar_options_widget.py trace_widget.py tube_widget.py uniform_color_widget.py +visibility_op.py file_loader.py loader_info_handler.py loader_list_model.py diff --git a/modules/gui/pymod/scene/preset.py b/modules/gui/pymod/scene/preset.py index 335cd884b01a0e30a86fd165487c749028b033c5..f46c3cd07dbd007b14bd0cff495568fa919bb26c 100644 --- a/modules/gui/pymod/scene/preset.py +++ b/modules/gui/pymod/scene/preset.py @@ -22,7 +22,7 @@ from ost import info from ost import gfx from PyQt4 import QtGui -from render_op import RenderOp +from ost.gfx import ColorOp #Rendering Preset class Preset(): @@ -31,8 +31,7 @@ class Preset(): CLASS_NAME_ATTRIBUTE_NAME = "ClassName" INDEX_ATTRIBUTE_NAME = "Index" - MODULE_NAME = "ost.gfx" - RENDERMODE_MODULE_NAME = "ost.gui.scene.render_op" + MODULE_NAMES = ["ost.gfx","ost.gui.scene.visibility_op","ost.gui.scene.render_op"] def __init__(self, name, parent=None): self.name_ = name @@ -71,10 +70,10 @@ class Preset(): def ApplyOn(self, entity): if (entity is not None) and isinstance(entity, gfx.Entity): for op in self.ops_: - if(isinstance(op, RenderOp)): - op.ApplyOn(entity) - else: + if isinstance(op,ColorOp): entity.Apply(op) + else: + op.ApplyOn(entity) def ToInfo(self,group): group.SetAttribute(Preset.NAME_ATTRIBUTE_NAME, self.name_) @@ -98,13 +97,12 @@ class Preset(): class_name = op_group.GetAttribute(Preset.CLASS_NAME_ATTRIBUTE_NAME) index = int(op_group.GetAttribute(Preset.INDEX_ATTRIBUTE_NAME)) op_class = None - try: - op_class = Preset.__get_op_class("%s.%s"%(Preset.MODULE_NAME,class_name)) - except AttributeError: + for module in Preset.MODULE_NAMES: try: - op_class = Preset.__get_op_class("%s.%s"%(Preset.RENDERMODE_MODULE_NAME,class_name)) - except: - print "op can not be loaded" + op_class = Preset.__get_op_class("%s.%s"%(module,class_name)) + break + except AttributeError: + pass if op_class is not None: op = op_class.FromInfo(op_group) class_order_dict[index]=op diff --git a/modules/gui/pymod/scene/preset_editor_widget.py b/modules/gui/pymod/scene/preset_editor_widget.py index 9bf512946f993f3225d5d1d7a2fa04615216b6bc..4ecd8293cc48c591372d8480a7925b8909fbce03 100644 --- a/modules/gui/pymod/scene/preset_editor_widget.py +++ b/modules/gui/pymod/scene/preset_editor_widget.py @@ -36,6 +36,7 @@ from ost.gfx import GradientLevelColorOp from ost.gfx import UniformColorOp from preset import Preset from render_op import RenderOp +from visibility_op import VisibilityOp #Preset Editor class PresetEditor(QtGui.QDialog): @@ -54,11 +55,13 @@ class PresetEditor(QtGui.QDialog): self.beow_=ByElementColorOpWidget(self) self.bcow_=ByChainColorOpWidget(self) self.row_=RenderOpWidget(self) + self.vow_=VisibilityOpWidget(self) self.combo_box_.addItem("Uniform Color Operation", QtCore.QVariant(self.ufcow_)) self.combo_box_.addItem("Gradient Operation", QtCore.QVariant(self.glcow_)) self.combo_box_.addItem("By Element Operation", QtCore.QVariant(self.beow_)) self.combo_box_.addItem("By Chain Operation", QtCore.QVariant(self.bcow_)) self.combo_box_.addItem("RenderMode Operation", QtCore.QVariant(self.row_)) + self.combo_box_.addItem("Visibility Operation", QtCore.QVariant(self.vow_)) self.add_button_ = QtGui.QPushButton("Add") @@ -146,6 +149,10 @@ class PresetEditor(QtGui.QDialog): self.row_.SetOp(op) if self.row_.exec_(): self.list_model_.SetItem(current_index, self.row_.GetOp()) + elif isinstance(op, VisibilityOp): + self.vow_.SetOp(op) + if self.vow_.exec_(): + self.list_model_.SetItem(current_index, self.vow_.GetOp()) def Remove(self): current_index = self.list_view_.currentIndex() @@ -570,7 +577,7 @@ class RenderOpWidget(QtGui.QDialog): def GetOp(self): selection = str(self.selection_edit_.text()) render_mode = self.render_modes_.itemData(self.render_modes_.currentIndex()).toPyObject() - ro = RenderOp(gfx.RenderMode(render_mode), selection, self.keep_.isChecked(), self) + ro = RenderOp(gfx.RenderMode(render_mode), selection, self.keep_.isChecked()) return ro def SetOp(self, ro): @@ -584,6 +591,50 @@ class RenderOpWidget(QtGui.QDialog): break if not found: self.render_modes_.setCurrentIndex(0) + self.keep_.setChecked(ro.IsKept()) + + def Ok(self): + self.accept() + + def Cancel(self): + self.reject() + +class VisibilityOpWidget(QtGui.QDialog): + def __init__(self, parent=None): + QtGui.QDialog.__init__(self, parent) + selection_label = QtGui.QLabel("Selection") + self.selection_edit_ = QtGui.QLineEdit() + + self.visible_ = QtGui.QCheckBox("Visible") + self.visible_.setChecked(True) + + self.hbox_ = QtGui.QHBoxLayout() + self.ok_button_ = QtGui.QPushButton("OK") + self.cancel_button_ = QtGui.QPushButton("Cancel") + self.hbox_.addWidget(self.ok_button_) + self.hbox_.addStretch() + self.hbox_.addWidget(self.cancel_button_) + + grid = QtGui.QGridLayout() + grid.setContentsMargins(0,5,0,0) + grid.addWidget(selection_label, 0, 0, 1, 1) + grid.addWidget(self.selection_edit_, 0, 1, 1, 1) + grid.addWidget(self.visible_, 1, 1, 1, 1) + grid.addLayout(self.hbox_,2,0,1,2) + grid.setRowStretch(1, 1) + self.setLayout(grid) + + QtCore.QObject.connect(self.ok_button_, QtCore.SIGNAL("clicked()"), self.Ok) + QtCore.QObject.connect(self.cancel_button_, QtCore.SIGNAL("clicked()"), self.Cancel) + + def GetOp(self): + selection = str(self.selection_edit_.text()) + vo = VisibilityOp(selection, self.visible_.isChecked()) + return vo + + def SetOp(self, ro): + self.selection_edit_.setText(ro.GetSelection()) + self.visible_.setChecked(ro.IsVisible()) def Ok(self): self.accept() diff --git a/modules/gui/pymod/scene/render_op.py b/modules/gui/pymod/scene/render_op.py index 672a7636f2c7b82e9ec9ecbfa439917edfe3a039..d36a4530800581eac1fc15fb0169507557f08dd9 100644 --- a/modules/gui/pymod/scene/render_op.py +++ b/modules/gui/pymod/scene/render_op.py @@ -26,7 +26,7 @@ class RenderOp(): RENDERMODE_ATTRIBUTE_NAME = "RenderMode" KEEP_ATTRIBUTE_NAME = "Keep" - def __init__(self, render_mode, selection, keep=False, parent=None): + def __init__(self, render_mode, selection, keep=False): self.render_mode_ = render_mode self.selection_ = selection self.keep_ = keep diff --git a/modules/gui/pymod/scene/visibility_op.py b/modules/gui/pymod/scene/visibility_op.py new file mode 100644 index 0000000000000000000000000000000000000000..cb6ec07d68c2ff6a00ad47c29841ca2b66941e80 --- /dev/null +++ b/modules/gui/pymod/scene/visibility_op.py @@ -0,0 +1,59 @@ +#------------------------------------------------------------------------------ +# This file is part of the OpenStructure project <www.openstructure.org> +# +# Copyright (C) 2008-2010 by the OpenStructure authors +# +# This library is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 3.0 of the License, or (at your option) +# any later version. +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +#------------------------------------------------------------------------------ +# -*- coding: utf-8 -*- + +from ost import info +from ost import gfx +from PyQt4 import QtGui + +class VisibilityOp(): + VISIBLE_ATTRIBUTE_NAME = "Visible" + + def __init__(self, selection, visible=False): + self.selection_ = selection + self.visible_ = visible + + def SetSelection(self, selection): + self.selection_ = selection + + def GetSelection(self): + return self.selection_ + + def SetVisible(self, visible): + self.visible_ = visible + + def IsVisible(self): + return self.visible_ + + def ApplyOn(self, entity): + if (entity is not None) and isinstance(entity, gfx.Entity): + entity.SetVisible(entity.view.Select(self.GetSelection()),self.IsVisible()) + + def ToInfo(self,group): + group.SetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME, str(int(self.IsVisible()))) + group.SetTextData(str(self.GetSelection())) + + @staticmethod + def FromInfo(group): + visible_op = None + if group.HasAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME): + visible = bool(int(group.GetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME))) + selection = group.GetTextData() + visible_op = VisibilityOp(selection,visible) + return visible_op