diff --git a/modules/gfx/pymod/export_entity.cc b/modules/gfx/pymod/export_entity.cc index f0542b0c4a80795fc7a9da0fcc3e8201e0558afa..4e555d2b8324a831ad6c5b557c4581f6fd614769 100644 --- a/modules/gfx/pymod/export_entity.cc +++ b/modules/gfx/pymod/export_entity.cc @@ -17,6 +17,7 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ #include <boost/python.hpp> +#include <boost/python/suite/indexing/vector_indexing_suite.hpp> using namespace boost::python; #include <ost/gfx/entity.hh> @@ -236,8 +237,12 @@ void export_Entity() .add_property("selection", &Entity::GetSelection, &Entity::SetSelection) .def("GetView", &Entity::GetView) + .def("GetRenderModeName", &Entity::GetRenderModeName) + .def("GetLoadedRenderModes", &Entity::GetLoadedRenderModes) .def("SetRenderMode", set_rm1, arg("keep")=false) .def("SetRenderMode", set_rm2) + .def("SetEnableRenderMode", &Entity::SetEnableRenderMode) + .def("IsRenderModeEnabled", &Entity::IsRenderModeEnabled) .add_property("view", &Entity::GetView) .def("SetVisible", &Entity::SetVisible) .def("ColorBy", color_by_01) @@ -286,4 +291,6 @@ void export_Entity() to_python_converter<std::pair<GfxObjP, mol::AtomHandle>, PairToTupleConverter<GfxObjP, mol::AtomHandle> >(); + class_<RenderModeTypes>("RenderModeTypes", init<>()) + .def(vector_indexing_suite<RenderModeTypes, true >()); } diff --git a/modules/gfx/src/entity.cc b/modules/gfx/src/entity.cc index 5e17ea1d6e760db75cd79a1f339b42a758d0e4fa..5f5695de222568b0996ac63a111fa7d52b64a81e 100644 --- a/modules/gfx/src/entity.cc +++ b/modules/gfx/src/entity.cc @@ -270,7 +270,7 @@ void Entity::CacheBoundingBox() const for (RendererMap::const_iterator i=renderer_.begin(), e=renderer_.end(); i!=e; ++i) { const impl::EntityRenderer* r=i->second; - if (r->HasDataToRender()) { + if (r->IsEnabled() && r->HasDataToRender()) { if (!has_data) { coord_limits=r->GetBoundingBox(); has_data=true; @@ -311,16 +311,18 @@ void Entity::CustomRenderGL(RenderPass pass) for (RendererMap::iterator i=renderer_.begin(), e=renderer_.end(); i!=e; ++i) { impl::EntityRenderer* r=i->second; - switch(pass) { - case STANDARD_RENDER_PASS: - case OPAQUE_RENDER_PASS: - r->Render(pass); - break; - case GLOW_RENDER_PASS: - if (r->HasSelection()) { + if(r->IsEnabled()){ + switch(pass) { + case STANDARD_RENDER_PASS: + case OPAQUE_RENDER_PASS: r->Render(pass); - } - break; + break; + case GLOW_RENDER_PASS: + if (r->HasSelection()) { + r->Render(pass); + } + break; + } } } geom::AlignedCuboid bbox=this->GetBoundingBox(); @@ -374,7 +376,9 @@ void Entity::CustomRenderGL(RenderPass pass) void Entity::CustomRenderPov(PovState& pov) { for (RendererMap::iterator it=renderer_.begin(); it!=renderer_.end(); ++it) { - it->second->RenderPov(pov,GetName()); + if(it->second->IsEnabled()){ + it->second->RenderPov(pov,GetName()); + } } } @@ -557,6 +561,46 @@ void Entity::OnRenderModeChange() this->FlagRebuild(); } +const String Entity::GetRenderModeName(RenderMode::Type mode){ + RendererMap::iterator i=renderer_.find(mode); + String name = ""; + if(i!=renderer_.end()) { + impl::EntityRenderer* renderer=i->second; + name = renderer->GetName(); + } + return name; +} + +void Entity::SetEnableRenderMode(RenderMode::Type mode, bool enable){ + RendererMap::iterator i=renderer_.find(mode); + if(i!=renderer_.end()) { + impl::EntityRenderer* renderer=i->second; + if(renderer->IsEnabled() != enable){ + renderer->SetEnabled(enable); + this->FlagRebuild(); + } + } +} + +bool Entity::IsRenderModeEnabled(RenderMode::Type mode){ + RendererMap::iterator i=renderer_.find(mode); + if(i!=renderer_.end()) { + impl::EntityRenderer* renderer=i->second; + return renderer->IsEnabled(); + } + return false; +} + + +RenderModeTypes Entity::GetLoadedRenderModes(){ + std::vector<RenderMode::Type> render_modes; + for (RendererMap::iterator i=renderer_.begin(), + e=renderer_.end(); i!=e; ++i) { + render_modes.push_back(i->first); + } + return render_modes; +} + void Entity::SetRenderMode(RenderMode::Type mode, const mol::EntityView& view, bool keep) { @@ -578,6 +622,13 @@ void Entity::SetRenderMode(RenderMode::Type mode, } this->ReapplyColorOps(); this->FlagRebuild(); + Scene::Instance().RenderModeChanged(GetName()); +} + +mol::EntityView Entity::GetRenderView(RenderMode::Type mode) +{ + EntityRenderer* rend = this->GetOrCreateRenderer(mode); + return rend->GetFullView(); } void Entity::SetRenderMode(RenderMode::Type mode) @@ -592,6 +643,7 @@ void Entity::SetVisible(const mol::EntityView& view, bool visible){ renderer->SetVisible(view, visible); renderer->UpdateViews(); } + this->ReapplyColorOps(); this->FlagRebuild(); } diff --git a/modules/gfx/src/entity.hh b/modules/gfx/src/entity.hh index 4f3d49ab8ae15e609bb33220f5dcca7c9744862c..5a62719aece00d9721ebf2eb91cf14e4420d03c7 100644 --- a/modules/gfx/src/entity.hh +++ b/modules/gfx/src/entity.hh @@ -22,6 +22,8 @@ /* Author: Ansgar Philippsen, Marco Biasini */ +#include <vector> + #include <boost/ptr_container/ptr_map.hpp> #include <ost/geom/geom.hh> @@ -47,6 +49,8 @@ namespace ost { namespace gfx { +typedef std::vector<RenderMode::Type> RenderModeTypes; + /// \brief graphical rendering of \ref mol::EntityHandle entites /// /// Entity is responsible for rendering of @@ -114,11 +118,21 @@ public: virtual void OnRenderModeChange(); + const String GetRenderModeName(RenderMode::Type mode); + + void SetEnableRenderMode(RenderMode::Type mode, bool enable); + + bool IsRenderModeEnabled(RenderMode::Type mode); + + RenderModeTypes GetLoadedRenderModes(); + void SetRenderMode(RenderMode::Type mode, const mol::EntityView& view, bool keep=false); virtual void SetRenderMode(RenderMode::Type mode); + mol::EntityView GetRenderView(RenderMode::Type mode); + virtual void SetVisible(const mol::EntityView& view, bool visible); virtual void OptionsChanged(RenderMode::Type mode); diff --git a/modules/gfx/src/impl/cartoon_renderer.cc b/modules/gfx/src/impl/cartoon_renderer.cc index 86bc6df8dd50811564218dbce7b51196aad28558..887e4c449d82292ef2a517442bbfaf8c42bd4f85 100644 --- a/modules/gfx/src/impl/cartoon_renderer.cc +++ b/modules/gfx/src/impl/cartoon_renderer.cc @@ -33,7 +33,14 @@ using namespace impl; CartoonRenderer::CartoonRenderer(BackboneTrace& trace, bool force_tube): TraceRendererBase(trace, 3), force_tube_(force_tube), options_(new CartoonRenderOptions()) -{ } +{ +if(force_tube){ + this->SetName("Smooth Tube"); +} +else{ + this->SetName("Helix & Strand Cartoon"); +} +} void CartoonRenderer::SetForceTube(bool force_tube) { diff --git a/modules/gfx/src/impl/cpk_renderer.cc b/modules/gfx/src/impl/cpk_renderer.cc index dd75324b0d632edf5be21e1180c6a3cbcb0158d8..981ff47f38f1fe93db65a8bc64b04b7f5bc1b3cb 100644 --- a/modules/gfx/src/impl/cpk_renderer.cc +++ b/modules/gfx/src/impl/cpk_renderer.cc @@ -32,7 +32,9 @@ namespace ost { namespace gfx { namespace impl { -CPKRenderer::CPKRenderer(): options_(new CPKRenderOptions()) {} +CPKRenderer::CPKRenderer(): options_(new CPKRenderOptions()) { + this->SetName("Spheres"); +} void CPKRenderer::PrepareRendering() { diff --git a/modules/gfx/src/impl/custom_renderer.cc b/modules/gfx/src/impl/custom_renderer.cc index 73bc4ab519c4486a6871a598029aa2db5eab640d..ff559b6047e7cfa9d807a0cee4333a707dcdea98 100644 --- a/modules/gfx/src/impl/custom_renderer.cc +++ b/modules/gfx/src/impl/custom_renderer.cc @@ -29,6 +29,7 @@ using namespace impl; CustomRenderer::CustomRenderer(): options_(new CustomRenderOptions()) { + this->SetName("Ball & Stick"); this->SetFixedPickRadius(0.2); } diff --git a/modules/gfx/src/impl/debug_renderer.cc b/modules/gfx/src/impl/debug_renderer.cc index 0e28e53946c8f1d653e94dc61e26e55c2ceb5867..918117400b0b4a1e2039590e4739cbcfd26aa611 100644 --- a/modules/gfx/src/impl/debug_renderer.cc +++ b/modules/gfx/src/impl/debug_renderer.cc @@ -34,7 +34,9 @@ using namespace impl; using namespace mol; DebugRenderer::DebugRenderer(BackboneTrace& trace): - TraceRendererBase(trace, 2), options_(new SlineRenderOptions()) {} + TraceRendererBase(trace, 2), options_(new SlineRenderOptions()) { + this->SetName("Debug"); +} void DebugRenderer::PrepareRendering() { diff --git a/modules/gfx/src/impl/entity_renderer.cc b/modules/gfx/src/impl/entity_renderer.cc index 0751e2fa2987702e105162a92c27f4a26ed3ec7f..5ba60e93619a10b8bf17fb9a2e8ac3df817a1020 100644 --- a/modules/gfx/src/impl/entity_renderer.cc +++ b/modules/gfx/src/impl/entity_renderer.cc @@ -36,7 +36,7 @@ namespace ost { namespace gfx { namespace impl { -EntityRenderer::EntityRenderer(){} +EntityRenderer::EntityRenderer():name_(""),enabled_(true){} void EntityRenderer::FlagPositionsDirty() { @@ -44,6 +44,24 @@ void EntityRenderer::FlagPositionsDirty() sel_state_|=DIRTY_VA; } +const String& EntityRenderer::GetName() const{ + return name_; +} + +void EntityRenderer::SetName(const String& name) +{ + name_=name; +} + +void EntityRenderer::SetEnabled(bool enabled){ + enabled_=enabled; +} + +bool EntityRenderer::IsEnabled() const +{ + return enabled_; +} + const Color& EntityRenderer::GetSelectionColor() const { static Color selection_color(0.3,0.9,0.1,0.6); diff --git a/modules/gfx/src/impl/entity_renderer.hh b/modules/gfx/src/impl/entity_renderer.hh index 4b58eee6ab9343fd1f7c05500b4d1d484cfc16b0..2355e225f2716f2a137652a4fa58df24fa7c4c1f 100644 --- a/modules/gfx/src/impl/entity_renderer.hh +++ b/modules/gfx/src/impl/entity_renderer.hh @@ -66,6 +66,12 @@ public: virtual bool HasDataToRender() const; + virtual const String& GetName() const; + + void SetEnabled(bool enabled=true); + + bool IsEnabled() const; + /// \brief whether the renderer has a non-empty selection bool HasSelection() const; @@ -143,6 +149,11 @@ public: void FlagPositionsDirty(); protected: + virtual void SetName(const String& name); + + String name_; + bool enabled_; + mol::EntityView full_view_; mol::EntityView effective_view_; mol::EntityView hidden_view_; diff --git a/modules/gfx/src/impl/line_trace_renderer.cc b/modules/gfx/src/impl/line_trace_renderer.cc index 6d343572397be6a3b7aa999a52aa9fff8898049e..b0279b71f0f274f101757c0e2c321fc102e4c3e2 100644 --- a/modules/gfx/src/impl/line_trace_renderer.cc +++ b/modules/gfx/src/impl/line_trace_renderer.cc @@ -24,7 +24,9 @@ namespace ost { namespace gfx { namespace impl { LineTraceRenderer::LineTraceRenderer(BackboneTrace& trace): TraceRendererBase(trace, 1), options_(new LineTraceRenderOptions()) -{} +{ + this->SetName("Fast Trace"); +} void LineTraceRenderer::PrepareRendering() { diff --git a/modules/gfx/src/impl/simple_renderer.cc b/modules/gfx/src/impl/simple_renderer.cc index f799576ed9cbee5ebdb888d8c2f5f431300c8918..cbd012f3540812738ece08c16560bbd792fd1ff7 100644 --- a/modules/gfx/src/impl/simple_renderer.cc +++ b/modules/gfx/src/impl/simple_renderer.cc @@ -52,7 +52,8 @@ struct BlurQuadEntryLess SimpleRenderer::SimpleRenderer(): options_(new SimpleRenderOptions()) { - this->SetFixedPickRadius(0.2); + this->SetName("Fast Bonds"); + this->SetFixedPickRadius(0.2); } bool SimpleRenderer::CanSetOptions(RenderOptionsPtr& render_options) diff --git a/modules/gfx/src/impl/sline_renderer.cc b/modules/gfx/src/impl/sline_renderer.cc index 5fa836872ae406209b07c26339ced7c32f62c771..6d1fe022dd2f56dcad4b6245f89c57df79632b3a 100644 --- a/modules/gfx/src/impl/sline_renderer.cc +++ b/modules/gfx/src/impl/sline_renderer.cc @@ -24,7 +24,9 @@ namespace ost { namespace gfx { namespace impl { SlineRenderer::SlineRenderer(BackboneTrace& trace): TraceRendererBase(trace, 3), options_(new SlineRenderOptions()) -{} +{ + this->SetName("Fast Spline"); +} void SlineRenderer::PrepareRendering() { diff --git a/modules/gfx/src/impl/trace_renderer.cc b/modules/gfx/src/impl/trace_renderer.cc index d29cfe632dd4b2e193f0e3d1b1b6b1a8913c12e3..5c493d7fe5a572223b044df94024229ecaf46079 100644 --- a/modules/gfx/src/impl/trace_renderer.cc +++ b/modules/gfx/src/impl/trace_renderer.cc @@ -26,7 +26,9 @@ namespace ost { namespace gfx { namespace impl { TraceRenderer::TraceRenderer(BackboneTrace& trace): TraceRendererBase(trace, 1), options_(new TraceRenderOptions()) -{} +{ + this->SetName("Trace"); +} void TraceRenderer::PrepareRendering() { diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index 6c7cb07dc82539888e1b94caf5fe0f8ceb00d543..d6d81bcdaffb6d0045b620da116a34825316ac5e 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -55,11 +55,14 @@ shell_history.hh ) set(OST_GUI_SCENE_WIN_HEADERS +current_selection_node.hh entity_node.hh entity_part_node.hh gfx_scene_node.hh label_node.hh root_node.hh +render_mode_node.hh +render_modes_node.hh scene_node.hh scene_win.hh scene_win_model.hh @@ -254,11 +257,14 @@ python_shell/python_syntax_highlighter.cc python_shell/shell_history.cc python_shell/string_literal_positions.cc python_shell/text_logger.cc +scene_win/current_selection_node.cc scene_win/scene_node.cc scene_win/label_node.cc scene_win/entity_node.cc scene_win/entity_part_node.cc scene_win/gfx_scene_node.cc +scene_win/render_mode_node.cc +scene_win/render_modes_node.cc scene_win/root_node.cc scene_win/scene_win.cc scene_win/scene_win_model.cc @@ -315,10 +321,13 @@ panel_bar/panel_bar_widget_holder.hh panel_bar/side_bar.hh panel_bar/splitter_panel_bar.hh panel_bar/tabbed_panel_bar.hh +scene_win/current_selection_node.hh scene_win/gfx_scene_node.hh scene_win/label_node.hh scene_win/entity_node.hh scene_win/entity_part_node.hh +scene_win/render_mode_node.hh +scene_win/render_modes_node.hh scene_win/root_node.hh scene_win/scene_node.hh scene_win/scene_win.hh diff --git a/modules/gui/src/scene_win/current_selection_node.cc b/modules/gui/src/scene_win/current_selection_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..b242c320b567362023fea30e84877e247291925c --- /dev/null +++ b/modules/gui/src/scene_win/current_selection_node.cc @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2009 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 +//------------------------------------------------------------------------------ +#include <QFont> + +#include <ost/gfx/scene.hh> +#include <ost/gfx/gfx_node.hh> + +#include <ost/gui/gosty_app.hh> +#include <ost/gui/scene_win/scene_win.hh> + +#include "current_selection_node.hh" + +namespace ost { namespace gui { + +CurrentSelectionNode::CurrentSelectionNode(gfx::EntityP entity, SceneNode* parent):GfxSceneNode(entity,parent),visible_(true){ + //GostyApp::Instance()->GetSceneWin()->GetModel()->AttachSelectionObserver(this); +} + +QVariant CurrentSelectionNode::GetData(int column, int role){ + if(column<0 || column > 2)return QVariant(); + + if (role==Qt::CheckStateRole && column==0) { + return QVariant(visible_ ? Qt::Checked : Qt::Unchecked); + } else if(column==1) { + if (role==Qt::DisplayRole) { + return QVariant("Current Selection"); + } else if(role==Qt::FontRole) { + QFont f("Helvetica"); + return QVariant(f); + } + } + return QVariant(); +} + +int CurrentSelectionNode::GetColumnCount() const{ + return 2; +} + +bool CurrentSelectionNode::SetData(int column, const QVariant& value, int role){ + if (column==0 && role == Qt::CheckStateRole) { + gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode()); + if (value.toBool()) { + this->GetParent()->SetData(0,value,Qt::CheckStateRole); + entity->SetVisible(entity->GetSelection(), true); + visible_=true; + } else { + entity->SetVisible(entity->GetSelection(), false); + visible_=false; + } + return true; + } + return false; +} + +Qt::ItemFlags CurrentSelectionNode::Flags(int column) const{ + if(column==0){ + return Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled; + } + else if(column==1){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return Qt::NoItemFlags; +} + +void CurrentSelectionNode::SelectionChanged(){ + if(visible_){ + gfx::EntityP entity = boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode()); + entity->SetVisible(entity->GetSelection(),true); + } +} + +}} + diff --git a/modules/gui/src/scene_win/current_selection_node.hh b/modules/gui/src/scene_win/current_selection_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..59d1a7c5d8cdb79b466c14d1118313a7488d8dc5 --- /dev/null +++ b/modules/gui/src/scene_win/current_selection_node.hh @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2009 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 +//------------------------------------------------------------------------------ +#ifndef OST_GUI_SCENE_WIN_CURRENT_SELECTION_NODE_HH +#define OST_GUI_SCENE_WIN_CURRENT_SELECTION_NODE_HH + +#include <QObject> +#include <QVariant> +#include <QModelIndex> + +#include <ost/mol/entity_view.hh> +#include <ost/mol/query_view_wrapper.hh> + +#include <ost/gfx/entity.hh> +#include <ost/gfx/entity_fw.hh> +#include <ost/gfx/scene_observer.hh> +#include <ost/gfx/gfx_object.hh> +#include <ost/gfx/gfx_object_fw.hh> + +#include <ost/gui/module_config.hh> +#include <ost/gui/scene_win/gfx_scene_node.hh> + +/* + Author: Stefan Scheuber + */ + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI CurrentSelectionNode : public GfxSceneNode { + Q_OBJECT +public: + CurrentSelectionNode(gfx::EntityP entity, SceneNode* node_parent ); + + virtual QVariant GetData(int column, int role); + virtual bool SetData(int column, const QVariant& value, int role); + virtual Qt::ItemFlags Flags(int column) const; + virtual int GetColumnCount() const; + + //Scene Observer interface + virtual void SelectionChanged(); + +private: + bool visible_; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/entity_node.cc b/modules/gui/src/scene_win/entity_node.cc index 780487bfe96f24f14f7fd6a451e98e0c34484b15..8a2aa3e87e567895e7ecb8eea7fc85f9286197e3 100644 --- a/modules/gui/src/scene_win/entity_node.cc +++ b/modules/gui/src/scene_win/entity_node.cc @@ -25,8 +25,10 @@ #include <ost/gui/scene_win/scene_win.hh> #include <ost/mol/query_view_wrapper.hh> +#include "current_selection_node.hh" #include "entity_part_node.hh" #include "label_node.hh" +#include "render_modes_node.hh" #include "entity_node.hh" @@ -35,14 +37,16 @@ namespace ost { namespace gui { EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent): - GfxSceneNode(boost::dynamic_pointer_cast<gfx::GfxNode>(entity->shared_from_this()),parent){ + GfxSceneNode(entity,parent){ SceneWinModel* model = GostyApp::Instance()->GetSceneWin()->GetModel(); model->AddNode(parent, this); + new RenderModesNode(entity, this); + SceneNode* quick_selection = new LabelNode("Quick Selection",this); model->AddNode(this, quick_selection); - SceneNode* node = new EntityPartNode("Backbone", entity, mol::QueryViewWrapper(entity->GetView().Select("aname=CA,C,N,CO,O")), quick_selection); + SceneNode* node = new EntityPartNode("Backbone", entity, mol::QueryViewWrapper(entity->GetView().Select("aname=CA,C,N,O and peptide=true")), quick_selection); model->AddNode(quick_selection, node); node = new EntityPartNode("Ligands", entity, mol::QueryViewWrapper(entity->GetView().Select("ishetatm=1 and ele=C")), quick_selection); model->AddNode(quick_selection, node); @@ -50,7 +54,7 @@ EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent): node = new EntityPartNode("Full View", entity, mol::QueryViewWrapper(entity->GetView()), this); model->AddNode(this, node); - node = new EntityPartNode("Current Selection", entity, mol::QueryViewWrapper(entity->GetSelection()), this); + node = new CurrentSelectionNode(entity, this); model->AddNode(this, node); } diff --git a/modules/gui/src/scene_win/render_mode_node.cc b/modules/gui/src/scene_win/render_mode_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..ea08b64bcd0744bbaffcc9c00548374630c98776 --- /dev/null +++ b/modules/gui/src/scene_win/render_mode_node.cc @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2009 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 +//------------------------------------------------------------------------------ +#include <QFont> + +#include <ost/gfx/scene.hh> +#include <ost/gfx/gfx_node.hh> + +#include <ost/gui/gosty_app.hh> +#include <ost/gui/scene_win/scene_win.hh> + +#include "render_mode_node.hh" + +namespace ost { namespace gui { + +RenderModeNode::RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* parent):GfxSceneNode(entity,parent),render_mode_(render_mode){ +} + +QVariant RenderModeNode::GetData(int column, int role){ + if(column<0 || column > 2)return QVariant(); + + if (role==Qt::CheckStateRole && column==0) { + gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode()); + return QVariant(entity->IsRenderModeEnabled(render_mode_) ? Qt::Checked : Qt::Unchecked); + } else if(column==1) { + if (role==Qt::DisplayRole) { + gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode()); + String name = entity->GetRenderModeName(render_mode_); + return QVariant(name.c_str()); + } else if(role==Qt::FontRole) { + QFont f("Helvetica"); + return QVariant(f); + } + } + return QVariant(); +} + +int RenderModeNode::GetColumnCount() const{ + return 2; +} + +bool RenderModeNode::SetData(int column, const QVariant& value, int role){ + if (column==0 && role == Qt::CheckStateRole) { + gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode()); + if (value.toBool()) { + this->GetParent()->SetData(0,value,Qt::CheckStateRole); + entity->SetEnableRenderMode(render_mode_, true); + } else { + entity->SetEnableRenderMode(render_mode_, false); + } + return true; + } + return false; +} + +Qt::ItemFlags RenderModeNode::Flags(int column) const{ + if(column==0){ + return Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled; + } + else if(column==1){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return Qt::NoItemFlags; +} + +gfx::RenderMode::Type RenderModeNode::GetRenderMode() const { + return render_mode_; +} + +}} + diff --git a/modules/gui/src/scene_win/render_mode_node.hh b/modules/gui/src/scene_win/render_mode_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..b2c387797a88efe33d257353d8d6ea045040c6bf --- /dev/null +++ b/modules/gui/src/scene_win/render_mode_node.hh @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2009 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 +//------------------------------------------------------------------------------ +#ifndef OST_GUI_SCENE_WIN_RENDER_MODE_NODE_HH +#define OST_GUI_SCENE_WIN_RENDER_MODE_NODE_HH + +#include <QObject> +#include <QVariant> +#include <QModelIndex> + +#include <ost/mol/entity_view.hh> +#include <ost/mol/query_view_wrapper.hh> + +#include <ost/gfx/entity.hh> +#include <ost/gfx/entity_fw.hh> +#include <ost/gfx/render_mode.hh> +#include <ost/gfx/scene_observer.hh> +#include <ost/gfx/gfx_object.hh> +#include <ost/gfx/gfx_object_fw.hh> + +#include <ost/gui/module_config.hh> +#include <ost/gui/scene_win/gfx_scene_node.hh> + +/* + Author: Stefan Scheuber + */ + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI RenderModeNode : public GfxSceneNode { + Q_OBJECT +public: + RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* node_parent ); + + virtual QVariant GetData(int column, int role); + virtual bool SetData(int column, const QVariant& value, int role); + virtual Qt::ItemFlags Flags(int column) const; + virtual int GetColumnCount() const; + + gfx::RenderMode::Type GetRenderMode() const; + +private: + gfx::RenderMode::Type render_mode_; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/render_modes_node.cc b/modules/gui/src/scene_win/render_modes_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..434d0f3b068ff066776cc6e43c735073bef9e0ea --- /dev/null +++ b/modules/gui/src/scene_win/render_modes_node.cc @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2009 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 +//------------------------------------------------------------------------------ +#include <boost/pointer_cast.hpp> + +#include <QFont> + +#include <ost/gfx/scene.hh> +#include <ost/gfx/gfx_node.hh> + +#include <ost/gui/gosty_app.hh> +#include <ost/gui/scene_win/scene_win.hh> + +#include "render_modes_node.hh" +#include "render_mode_node.hh" + +namespace ost { namespace gui { + +RenderModesNode::RenderModesNode(gfx::EntityP entity, SceneNode* parent):LabelNode("Render Modes",parent),node_(entity){ + SceneWinModel* model = GostyApp::Instance()->GetSceneWin()->GetModel(); + model->AddNode(parent, this); + + this->Update(); + + GostyApp::Instance()->GetSceneWin()->GetModel()->AttachRenderModeObserver(this); +} + +void RenderModesNode::RenderModeChanged(){ + this->Update(); +} + +void RenderModesNode::Update(){ + SceneWinModel* model = GostyApp::Instance()->GetSceneWin()->GetModel(); + gfx::EntityP entity = boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode()); + gfx::RenderModeTypes render_modes = entity->GetLoadedRenderModes(); + for(unsigned int i=0; i<render_modes.size();i++){ + if(!render_types_.contains(render_modes[i])){ + RenderModeNode* node = new RenderModeNode(entity, render_modes[i],this); + model->AddNode(this, node); + render_types_.insert(render_modes[i]); + } + } +} + +gfx::GfxNodeP RenderModesNode::GetGfxNode(){ + return node_; +} + +}} + diff --git a/modules/gui/src/scene_win/render_modes_node.hh b/modules/gui/src/scene_win/render_modes_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..6fc631ea9312a1dda0b4449994884557e29bc1df --- /dev/null +++ b/modules/gui/src/scene_win/render_modes_node.hh @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2009 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 +//------------------------------------------------------------------------------ +#ifndef OST_GUI_SCENE_WIN_RENDER_MODES_NODE_HH +#define OST_GUI_SCENE_WIN_RENDER_MODES_NODE_HH + +#include <QObject> +#include <QVariant> +#include <QSet> + +#include <ost/gfx/entity.hh> +#include <ost/gfx/entity_fw.hh> +#include <ost/gfx/gfx_node.hh> +#include <ost/gfx/gfx_node_fw.hh> +#include <ost/gfx/scene_observer.hh> +#include <ost/gfx/gfx_object.hh> +#include <ost/gfx/gfx_object_fw.hh> + +#include <ost/gui/module_config.hh> +#include <ost/gui/scene_win/label_node.hh> + +/* + Author: Stefan Scheuber + */ + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI RenderModesNode : public LabelNode { + Q_OBJECT +public: + RenderModesNode(gfx::EntityP entity, SceneNode* node_parent ); + + virtual void RenderModeChanged(); + gfx::GfxNodeP GetGfxNode(); + +private: + void Update(); + + gfx::GfxNodeP node_; + QSet<gfx::RenderMode::Type> render_types_; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/scene_win_model.cc b/modules/gui/src/scene_win/scene_win_model.cc index 03dca9ee3a863c83e023f7569aabe42025a245b8..e65b75379cd95d44e55417e26fe59085dd7df15c 100644 --- a/modules/gui/src/scene_win/scene_win_model.cc +++ b/modules/gui/src/scene_win/scene_win_model.cc @@ -17,7 +17,7 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ /* - Authors: Marco Biasini, Ansgar Philippsen + Authors: Marco Biasini, Ansgar Philippsen, Stefan Scheuber */ #include "scene_win_model.hh" @@ -197,6 +197,17 @@ void SceneWinModel::NodeRemoved(const gfx::GfxNodeP& node) } } +void SceneWinModel::SelectionChanged(const gfx::GfxObjP& obj, const mol::EntityView& sel) +{ +} + +void SceneWinModel::RenderModeChanged(const gfx::GfxNodeP& node) +{ + if(render_observers_.contains(node)){ + render_observers_[node]->RenderModeChanged(); + } +} + SceneNode* SceneWinModel::GetItem(const QModelIndex &index) const { if (index.isValid()) { @@ -217,6 +228,16 @@ bool SceneWinModel::AddNode(SceneNode* parent, SceneNode* child){ return false; } +void SceneWinModel::AttachRenderModeObserver(RenderModesNode* node){ + render_observers_.insert(node->GetGfxNode(),node); +} + +void SceneWinModel::DetachRenderModeObserver(RenderModesNode* node){ + if(render_observers_.contains(node->GetGfxNode())){ + render_observers_.remove(node->GetGfxNode()); + } +} + QModelIndex SceneWinModel::GetIndexOf(SceneNode* node){ return GetIndex(node,index(0,0,QModelIndex())); } @@ -235,6 +256,7 @@ QModelIndex SceneWinModel::GetIndex(SceneNode* node, QModelIndex parent){ if (found.isValid()) { return found; } + i--; } } return QModelIndex(); diff --git a/modules/gui/src/scene_win/scene_win_model.hh b/modules/gui/src/scene_win/scene_win_model.hh index 00e4022d53af57adbb62fc710fd706601c25d811..b0a29dfe5a384350de4a338ed836e9792a9dd4e9 100644 --- a/modules/gui/src/scene_win/scene_win_model.hh +++ b/modules/gui/src/scene_win/scene_win_model.hh @@ -23,6 +23,7 @@ Author: Stefan Scheuber, Marco Biasini, Ansgar Philippsen */ +#include <QMap> #include <QAbstractItemModel> #include <ost/gfx/gfx_node_fw.hh> @@ -30,9 +31,13 @@ #include <ost/gui/module_config.hh> #include <ost/gui/scene_win/scene_node.hh> +#include <ost/gui/scene_win/render_modes_node.hh> namespace ost { namespace gui { + + + /// \brief data model for scene win class DLLEXPORT_OST_GUI SceneWinModel : public QAbstractItemModel, public gfx::SceneObserver { @@ -47,6 +52,9 @@ public: bool AddNode(SceneNode* parent, SceneNode* child); + void AttachRenderModeObserver(RenderModesNode* node); + void DetachRenderModeObserver(RenderModesNode* node); + QModelIndex GetIndexOf(SceneNode* node); // abstract item model interface @@ -72,6 +80,8 @@ public: // scene observer interface virtual void NodeAdded(const gfx::GfxNodeP& node); virtual void NodeRemoved(const gfx::GfxNodeP& node); + virtual void SelectionChanged(const gfx::GfxObjP& obj, const mol::EntityView& sel); + virtual void RenderModeChanged(const gfx::GfxNodeP& node); private: SceneNode* GetItem(const QModelIndex &index) const; @@ -80,6 +90,8 @@ private: SceneNode* root_node_; SceneNode* scene_node_; + + QMap<gfx::GfxNodeP, RenderModesNode*> render_observers_; }; }}