diff --git a/modules/gfx/pymod/export_entity.cc b/modules/gfx/pymod/export_entity.cc index e8d78cd325e651d3c42968ba631d4bfa5e98c0f9..990894fd86b1d17684b82aecf5d727d8e30b7d95 100644 --- a/modules/gfx/pymod/export_entity.cc +++ b/modules/gfx/pymod/export_entity.cc @@ -38,6 +38,16 @@ void color_by_chain_02(Entity* e, const String& selection) e->ColorByChain(selection); } +void color_by_element_01(Entity* e) +{ + e->ColorByElement(); +} + +void color_by_element_02(Entity* e, const String& selection) +{ + e->ColorByElement(selection); +} + void color_by_01(Entity* e, const String& prop, const Gradient& gradient, @@ -102,6 +112,14 @@ void color_by_08(Entity* e, e->ColorBy(prop,c1,c2); } +void color_by_09(Entity* e, + const String& prop, + const Gradient& gradient, + const String& selection) +{ + e->ColorBy(prop,gradient,selection); +} + // temporary, see comment in gfx/entity.hh void detail_color_by_02(Entity* e, const String& prop, @@ -308,6 +326,7 @@ void export_Entity() .def("ColorBy", color_by_06) .def("ColorBy", color_by_07) .def("ColorBy", color_by_08) + .def("ColorBy", color_by_09) .def("DetailColorBy", detail_color_by_02) COLOR_BY_DEF() .def("RadiusBy", radius_by_01) @@ -317,7 +336,8 @@ void export_Entity() .def("ResetRadiusBy", &Entity::ResetRadiusBy) .def("PickAtom", &Entity::PickAtom) .def("PickBond", &Entity::PickBond) - .def("ColorByElement",&Entity::ColorByElement) + .def("ColorByElement", color_by_element_01) + .def("ColorByElement", color_by_element_02) .def("ColorByChain", color_by_chain_01) .def("ColorByChain", color_by_chain_02) .def("CleanColorOps", &Entity::CleanColorOps) diff --git a/modules/gfx/src/entity.cc b/modules/gfx/src/entity.cc index 9111b9140339093991131ab7a828630f126fa71f..d91dd041ea6eea867eb5957c7826ffc51ac3eeb3 100644 --- a/modules/gfx/src/entity.cc +++ b/modules/gfx/src/entity.cc @@ -786,6 +786,12 @@ void Entity::ColorByElement() this->Apply(cop); } +void Entity::ColorByElement(const String& selection) +{ + ByElementColorOp cop = ByElementColorOp(selection); + this->Apply(cop); +} + void Entity::ColorByChain() { ByChainColorOp cop = ByChainColorOp(); @@ -854,6 +860,14 @@ void Entity::ColorBy(const String& prop, this->Apply(glop); } +void Entity::ColorBy(const String& prop, + const Gradient& gradient, + const String& selection) +{ + GradientLevelColorOp glop = GradientLevelColorOp(selection,prop,gradient); + this->Apply(glop); +} + mol::EntityView Entity::GetView() const { do_update_view(); diff --git a/modules/gfx/src/entity.hh b/modules/gfx/src/entity.hh index 328b4852eb36b593ef1ec32ba397a1cca7b786ef..e7ea96d92d7ab00110e155699ca934509e293758 100644 --- a/modules/gfx/src/entity.hh +++ b/modules/gfx/src/entity.hh @@ -174,6 +174,9 @@ public: /// \brief color by element void ColorByElement(); + /// \brief color by element for a specific selection + void ColorByElement(const String& selection); + /// \brief color by chain void ColorByChain(); @@ -229,6 +232,11 @@ public: const Gradient& gradient, mol::Prop::Level hint=mol::Prop::UNSPECIFIED); + // convenience + void ColorBy(const String& prop, + const Gradient& gradient, + const String& selection); + // convenience void ColorBy(const String& prop, const Color& c1, const Color& c2, diff --git a/modules/gui/pymod/scene/color_options_widget.py b/modules/gui/pymod/scene/color_options_widget.py index fb176038843e7649ad556088c5a85a84762b26bc..13e33f7c68c52e17e858d5e8d0aa356a8433c08c 100644 --- a/modules/gui/pymod/scene/color_options_widget.py +++ b/modules/gui/pymod/scene/color_options_widget.py @@ -41,18 +41,26 @@ class ColorOptionsWidget(ComboOptionsWidget): #Title self.text_ = "Color Options" + conly_label_ = QtGui.QLabel('carbons only') + self.conly_box_ = QtGui.QCheckBox() #Add options to menu self.entity_widgets_ = list() - self.entity_widgets_.append(["Color by Element", ByElementWidget("Color by Element")]) - self.entity_widgets_.append(["Color by Chain", ByChainWidget("Color by Chain")]) - self.entity_widgets_.append(["Color by Entity", ByEntityWidget("Color by Entity")]) - self.entity_widgets_.append(["Color by Property", GradientEditor()]) - self.entity_widgets_.append(["Uniform",UniformColorWidget()]) + self.entity_widgets_.append(["Color by Element", ByElementWidget("Color by Element", self)]) + self.entity_widgets_.append(["Color by Chain", ByChainWidget("Color by Chain", self)]) + self.entity_widgets_.append(["Color by Entity", ByEntityWidget("Color by Entity", self)]) + self.entity_widgets_.append(["Color by Property", GradientEditor(self)]) + self.entity_widgets_.append(["Uniform",UniformColorWidget(self)]) self.img_widgets_ = list() self.img_widgets_.append(["Uniform",UniformColorWidget()]) + qw = QtGui.QWidget(self) + gl = QtGui.QGridLayout(qw) + gl.addWidget(self.conly_box_, 0, 0, 1, 1) + gl.addWidget(conly_label_, 0, 1, 1, 4) + self.grid_layout_.addWidget(qw, 2, 0, 1, 1) + self.setMinimumSize(250,200) def OnComboChange(self, item): @@ -99,11 +107,16 @@ class ColorOptionsWidget(ComboOptionsWidget): def GetText(self): return self.text_ + + def GetCarbonsOnly(self): + return self.conly_box_.isChecked() class ByElementWidget(QtGui.QWidget): def __init__(self, text, parent=None): QtGui.QWidget.__init__(self, parent) + self.parent_ = parent + #Title self.text_ = text @@ -126,7 +139,10 @@ class ByElementWidget(QtGui.QWidget): def ChangeColor(self, node): if isinstance(node, gfx.Entity): node.CleanColorOps() - node.ColorByElement() + if self.parent_.GetCarbonsOnly(): + node.ColorByElement("ele=C") + else: + node.ColorByElement() def ChangeViewColor(self, entity, view): if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView): @@ -140,6 +156,7 @@ class ByElementWidget(QtGui.QWidget): class ByChainWidget(QtGui.QWidget): def __init__(self, text, parent=None): QtGui.QWidget.__init__(self, parent) + self.parent_ = parent #Title self.text_ = text @@ -149,13 +166,8 @@ class ByChainWidget(QtGui.QWidget): font = text_label.font() font.setBold(True) - conly_label = QtGui.QLabel('carbons only') - self.conly_box = QtGui.QCheckBox() - grid = QtGui.QGridLayout() grid.addWidget(text_label,0,0,1,1) - grid.addWidget(self.conly_box, 1,0,1,1) - grid.addWidget(conly_label, 1,1,1,3) grid.setRowStretch(2,1) self.setLayout(grid) self.setMinimumSize(250,60) @@ -166,12 +178,11 @@ class ByChainWidget(QtGui.QWidget): def ChangeColor(self, node): if isinstance(node, gfx.Entity): node.CleanColorOps() - if self.conly_box.isChecked(): + if self.parent_.GetCarbonsOnly(): node.ColorByChain('ele=C') else: node.ColorByChain() - def ChangeViewColor(self, entity, view): if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView): bco=gfx.ByChainColorOp(mol.QueryViewWrapper(view)) @@ -183,6 +194,7 @@ class ByChainWidget(QtGui.QWidget): class ByEntityWidget(QtGui.QWidget): def __init__(self, text, parent=None): QtGui.QWidget.__init__(self, parent) + self.parent_ = parent #Title self.text_ = text @@ -192,13 +204,8 @@ class ByEntityWidget(QtGui.QWidget): font = text_label.font() font.setBold(True) - conly_label = QtGui.QLabel('carbons only') - self.conly_box = QtGui.QCheckBox() - grid = QtGui.QGridLayout() grid.addWidget(text_label,0,0,1,1) - grid.addWidget(self.conly_box, 1,0,1,1) - grid.addWidget(conly_label, 1,1,1,3) grid.setRowStretch(2,1) self.setLayout(grid) self.setMinimumSize(250,60) @@ -217,7 +224,7 @@ class ByEntityWidget(QtGui.QWidget): else: color=self.gradient_.GetColorAt(float(i) / entity_count) node = scene_selection.GetActiveNode(i) - if self.conly_box.isChecked(): + if self.parent_.GetCarbonsOnly(): node.SetColor(color, 'ele=C') else: node.SetColor(color) diff --git a/modules/gui/pymod/scene/gradient_editor_widget.py b/modules/gui/pymod/scene/gradient_editor_widget.py index d4d1882481c677f37666ecf62ab9764619bcbe43..3c5b8629433707548bab7453d7592df57a1e6aab 100644 --- a/modules/gui/pymod/scene/gradient_editor_widget.py +++ b/modules/gui/pymod/scene/gradient_editor_widget.py @@ -29,6 +29,7 @@ from gradient_preset_widget import GradientPresetWidget class GradientEditor(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) + self.parent_ = parent #Create Ui elements gradient_label = QtGui.QLabel("Gradient Editor") @@ -80,9 +81,13 @@ class GradientEditor(QtGui.QWidget): def ChangeColor(self,node): if isinstance(node, gfx.Entity) or isinstance(node, gfx.Surface): node.CleanColorOps() - node.ColorBy(self.props[self.prop_combo_box_.currentIndex()], + if self.parent_.GetCarbonsOnly(): + node.ColorBy(self.props[self.prop_combo_box_.currentIndex()], + self.gradient_edit_.GetGfxGradient(), "ele=C") + else: + node.ColorBy(self.props[self.prop_combo_box_.currentIndex()], self.gradient_edit_.GetGfxGradient()) - + def ChangeViewColor(self, entity, view): if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView): glco=gfx.GradientLevelColorOp(mol.QueryViewWrapper(view),self.props[self.prop_combo_box_.currentIndex()],self.gradient_edit_.GetGfxGradient(),mol.Prop.Level.UNSPECIFIED) diff --git a/modules/gui/pymod/scene/uniform_color_widget.py b/modules/gui/pymod/scene/uniform_color_widget.py index 29bc7cf9f6e1fcccf72c6bcbdda6e1ae508902d3..db8e5346f3276fac962da07868670c88149e2f88 100644 --- a/modules/gui/pymod/scene/uniform_color_widget.py +++ b/modules/gui/pymod/scene/uniform_color_widget.py @@ -34,6 +34,7 @@ from color_select_widget import ColorSelectWidget class UniformColorWidget(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) + self.parent_ = parent self.text_ = "Uniform Color" @@ -42,9 +43,6 @@ class UniformColorWidget(QtGui.QWidget): font = uniform_label.font() font.setBold(True) - conly_label = QtGui.QLabel('carbons only') - self.conly_box = QtGui.QCheckBox() - self.color_select_widget_ = ColorSelectWidget(1,1,QtGui.QColor("White")) top_layout = QtGui.QVBoxLayout() @@ -56,9 +54,6 @@ class UniformColorWidget(QtGui.QWidget): grid.setColumnStretch(0,1) grid.setColumnStretch(2,1) - grid.addWidget(self.conly_box, 4,0) - grid.addWidget(conly_label, 4,1) - top_layout.addWidget(uniform_label) top_layout.addLayout(grid) self.setLayout(top_layout) @@ -92,7 +87,7 @@ class UniformColorWidget(QtGui.QWidget): gfx_color = self.color_select_widget_.GetGfxColor() if isinstance(node, gfx.Entity) or isinstance(node, gfx.Surface): node.CleanColorOps() - if self.conly_box.isChecked(): + if self.parent_.GetCarbonsOnly(): node.SetColor(gfx_color,"ele=C") else: node.SetColor(gfx_color,"")