diff --git a/modules/gui/pymod/scene/inspector_widget.py b/modules/gui/pymod/scene/inspector_widget.py index f72444f423fd6dd1bf192268461e1fceb0a0fe19..8366c3870f4ab05405d6ac8448ccc10b5617a45a 100644 --- a/modules/gui/pymod/scene/inspector_widget.py +++ b/modules/gui/pymod/scene/inspector_widget.py @@ -48,7 +48,7 @@ class InspectorWidget(ToolBarOptionsWidget): app=gui.GostyApp.Instance() self.scene_selection_ = gui.SceneSelection.Instance() scenewin = sip.wrapinstance(app.GetSceneWin().GetSipHandle(),QtGui.QWidget) - QtCore.QObject.connect(scenewin,QtCore.SIGNAL("ActiveNodesChanged(gfx::NodePtrList)"), + QtCore.QObject.connect(scenewin,QtCore.SIGNAL("ActiveNodesChanged(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)"), self.EntitySelectionChanged) self.setMinimumSize(250,215) diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index d6d81bcdaffb6d0045b620da116a34825316ac5e..4b5a993336cdafe330964548a83702282621e5d7 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -55,7 +55,9 @@ shell_history.hh ) set(OST_GUI_SCENE_WIN_HEADERS +context_menu.hh current_selection_node.hh +custom_part_node.hh entity_node.hh entity_part_node.hh gfx_scene_node.hh @@ -257,7 +259,9 @@ python_shell/python_syntax_highlighter.cc python_shell/shell_history.cc python_shell/string_literal_positions.cc python_shell/text_logger.cc +scene_win/context_menu.cc scene_win/current_selection_node.cc +scene_win/custom_part_node.cc scene_win/scene_node.cc scene_win/label_node.cc scene_win/entity_node.cc @@ -321,7 +325,9 @@ 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/context_menu.hh scene_win/current_selection_node.hh +scene_win/custom_part_node.hh scene_win/gfx_scene_node.hh scene_win/label_node.hh scene_win/entity_node.hh diff --git a/modules/gui/src/scene_selection.cc b/modules/gui/src/scene_selection.cc index 1c803e14acf24a082ec46464df3ec47d0b9623f3..d0ba0039ad7a4710ff7a0e0397e70734927c7e0d 100644 --- a/modules/gui/src/scene_selection.cc +++ b/modules/gui/src/scene_selection.cc @@ -21,6 +21,8 @@ #include <ost/geom/vec3.hh> #include <ost/geom/vecmat3_op.hh> +#include <ost/mol/view_op.hh> + #include <ost/gfx/scene.hh> #include <ost/gfx/gfx_object.hh> #include <ost/gfx/entity.hh> @@ -35,15 +37,17 @@ namespace ost { namespace gui { SceneSelection* SceneSelection::scene_selection_ = NULL; -SceneSelection::SceneSelection():nodes_() +SceneSelection::SceneSelection():nodes_(),views_() { SceneWin* scene_win = GostyApp::Instance()->GetSceneWin(); - QObject::connect(scene_win, SIGNAL(ActiveNodesChanged(gfx::NodePtrList)), - this, SLOT(SetActiveNodes(gfx::NodePtrList))); + QObject::connect(scene_win, SIGNAL(ActiveNodesChanged(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)), + this, SLOT(SetActiveNodes(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList))); } -void SceneSelection::SetActiveNodes(gfx::NodePtrList nodes){ +void SceneSelection::SetActiveNodes(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views){ nodes_ = nodes; + view_entity_ = entity; + views_ = views; } gfx::GfxNodeP SceneSelection::GetActiveNode(unsigned int pos){ @@ -59,6 +63,10 @@ int SceneSelection::GetActiveNodeCount(){ return nodes_.size(); } +int SceneSelection::GetActiveViewCount(){ + return views_.size(); +} + SceneSelection* SceneSelection::Instance() { if (!SceneSelection::scene_selection_) { SceneSelection::scene_selection_=new SceneSelection; @@ -176,46 +184,42 @@ void SceneSelection::Hide() { } } -void SceneSelection::ShowMenu(const QPoint & p){ - QMenu* menu = new QMenu(); - bool all_visible = true; - bool all_not_scene = true; - bool all_hidden = true; - bool all_entities = true; - bool all_gfx_objects = true; - for(unsigned int i = 0; i < nodes_.size(); i++){ - if(nodes_[i]){ - if(nodes_[i]->IsVisible()){all_hidden=false;} - else{all_visible=false;} - if(nodes_[i]->GetType()==0){all_not_scene = false;} - if(!dynamic_cast<gfx::GfxObj*> (nodes_[i].get())){all_gfx_objects = false;} - if(!dynamic_cast<gfx::Entity*> (nodes_[i].get())){all_entities = false;} +mol::EntityView SceneSelection::GetViewUnion() { + mol::EntityView view; + if(views_.size()>0){ + view = views_[0].GetEntityView().Copy(); + for(unsigned int i = 1; i < views_.size(); i++){ + view = mol::Union(view,views_[i].GetEntityView()); } } - QAction* action; - if(all_gfx_objects){ - action = menu->addAction("Center on Object"); - connect(action, SIGNAL(triggered()), this, SLOT(CenterOnObjects())); - } - if(all_entities){ - action = menu->addAction("Copy"); - connect(action, SIGNAL(triggered()), this, SLOT(CopyViews())); - action = menu->addAction("Select"); - connect(action, SIGNAL(triggered()), this, SLOT(Select())); - } - if(all_not_scene){ - action = menu->addAction("Delete"); - connect(action, SIGNAL(triggered()), this, SLOT(Delete())); - } - if(!all_visible){ - action = menu->addAction("Show"); - connect(action, SIGNAL(triggered()), this, SLOT(Show())); + return view; +} + +void SceneSelection::ShowExclusive(){ + view_entity_->SetVisible(view_entity_->GetView(),false); + this->MakeVisible(); +} + +void SceneSelection::HideExclusive(){ + view_entity_->SetVisible(view_entity_->GetView(),true); + this->MakeHidden(); +} + +void SceneSelection::MakeVisible(){ + for(unsigned int i= 0; i < views_.size(); i++){ + view_entity_->SetVisible(views_[i].GetEntityView(),true); } - if(!all_hidden){ - action = menu->addAction("Hide"); - connect(action, SIGNAL(triggered()), this, SLOT(Hide())); +} + +void SceneSelection::MakeHidden(){ + for(unsigned int i= 0; i < views_.size(); i++){ + view_entity_->SetVisible(views_[i].GetEntityView(),false); } - menu->popup(p); } + +gfx::EntityP SceneSelection::GetViewEntity(){ + return view_entity_; +} + }} diff --git a/modules/gui/src/scene_selection.hh b/modules/gui/src/scene_selection.hh index 0c3e979c1c7bac05cd27e65acff21c1f502b65a2..dd89f19f7027026c703cfb9094e4bae32a14b376 100644 --- a/modules/gui/src/scene_selection.hh +++ b/modules/gui/src/scene_selection.hh @@ -23,6 +23,9 @@ #include <QMenu> #include <QPoint> +#include <ost/mol/query_view_wrapper.hh> + +#include <ost/gfx/entity.hh> #include <ost/gfx/gfx_node_fw.hh> #include <ost/gui/module_config.hh> @@ -34,7 +37,8 @@ public: static SceneSelection* Instance(); gfx::GfxNodeP GetActiveNode(unsigned int pos); int GetActiveNodeCount(); - void ShowMenu(const QPoint & p); + int GetActiveViewCount(); + gfx::EntityP GetViewEntity(); public slots: void CenterOnObjects(); @@ -43,13 +47,20 @@ public slots: void Select(); void Show(); void Hide(); + void MakeVisible(); + void MakeHidden(); + void ShowExclusive(); + void HideExclusive(); + mol::EntityView GetViewUnion(); private slots: - void SetActiveNodes(gfx::NodePtrList nodes); + void SetActiveNodes(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views); private: SceneSelection(); gfx::NodePtrList nodes_; + gfx::EntityP view_entity_; + mol::QueryViewWrapperList views_; static SceneSelection* scene_selection_; QMenu* menu_; }; diff --git a/modules/gui/src/scene_win/context_menu.cc b/modules/gui/src/scene_win/context_menu.cc new file mode 100644 index 0000000000000000000000000000000000000000..5947a1cbdab81e079901d605ce7e6d6d981f5ab7 --- /dev/null +++ b/modules/gui/src/scene_win/context_menu.cc @@ -0,0 +1,171 @@ +//------------------------------------------------------------------------------ +// 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 +//------------------------------------------------------------------------------ +/* + Authors: Stefan Scheuber +*/ +#include <QAction> +#include <QMenu> +#include <QItemSelection> +#include <QItemSelectionModel> + +#include <ost/gui/scene_selection.hh> + +#include "custom_part_node.hh" +#include "entity_node.hh" +#include "entity_part_node.hh" +#include "gfx_scene_node.hh" + +#include "context_menu.hh" + +namespace ost { namespace gui { + +ContextMenu::ContextMenu(QTreeView* view, SceneWinModel* model): + QObject(model),view_(view),model_(model) +{ + +} + +void ContextMenu::ShowMenu(const QPoint& pos) +{ + QModelIndexList indexes = view_->selectionModel()->selection().indexes(); + + bool all_visible = true; + bool all_not_scene = true; + bool all_hidden = true; + bool all_entities = true; + bool all_gfx_objects = true; + bool all_entity_views = true; + bool all_custom_views = true; + + if(indexes.size()>0){ + for(int i = 0; i < indexes.size(); i++){ + if(indexes[i].column()==0){ + GfxSceneNode* gfx_scene_node = qobject_cast<GfxSceneNode*>(model_->GetItem(indexes[i])); + if(gfx_scene_node){ + gfx::GfxNodeP gfx_node = gfx_scene_node->GetGfxNode(); + if(gfx_node->IsVisible()){all_hidden=false;} + else{all_visible=false;} + if(gfx_node->GetType()==0){all_not_scene = false;} + if(!dynamic_cast<gfx::GfxObj*> (gfx_node.get())){all_gfx_objects = false;} + if(!dynamic_cast<gfx::Entity*> (gfx_node.get())){all_entities = false;} + } + else{ + all_gfx_objects = false; + all_entities = false; + all_visible = true; + all_hidden = true; + } + EntityPartNode* entity_part_node = qobject_cast<EntityPartNode*>(model_->GetItem(indexes[i])); + if(!entity_part_node){ + all_entity_views = false; + all_custom_views = false; + } + else{ + CustomPartNode* custom_part_node = qobject_cast<CustomPartNode*>(entity_part_node); + if(!custom_part_node){ + all_custom_views = false; + } + } + } + } + + QMenu* menu = new QMenu(); + + QAction* action; + if(all_gfx_objects){ + action = menu->addAction("Center on Object"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CenterOnObjects())); + } + if(all_entities){ + action = menu->addAction("Copy"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CopyViews())); + action = menu->addAction("Select"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Select())); + + if(all_not_scene){ + action = menu->addAction("Delete"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Delete())); + } + } + + if(!all_visible){ + action = menu->addAction("Show"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Show())); + } + if(!all_hidden){ + action = menu->addAction("Hide"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Hide())); + } + + if((all_gfx_objects || all_custom_views) && indexes.size()==2){ + action = menu->addAction("Rename"); + connect(action, SIGNAL(triggered()), this, SLOT(Rename())); + } + + if(all_entity_views){ + action = menu->addAction("Show"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeVisible())); + + action = menu->addAction("Hide"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeHidden())); + + action = menu->addAction("Show Exclusive"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(ShowExclusive())); + + action = menu->addAction("Hide Exclusive"); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(HideExclusive())); + + action = menu->addAction("Create Custom View"); + connect(action, SIGNAL(triggered()), this, SLOT(AddView())); + } + + menu->popup(pos); + } +} + +void ContextMenu::AddView(){ + gfx::EntityP entity = SceneSelection::Instance()->GetViewEntity(); + + EntityNode* ent_node = qobject_cast<EntityNode*>(model_->FindGfxNode(entity)); + if(ent_node) + { + mol::EntityView view = SceneSelection::Instance()->GetViewUnion(); + SceneNode* child_node = new CustomPartNode("New View", entity, mol::QueryViewWrapper(view),ent_node->GetCustomViewNode()); + model_->AddNode(ent_node->GetCustomViewNode(),child_node); + this->Rename(model_->GetIndexOf(child_node,1)); + } +} + +void ContextMenu::Rename(QModelIndex index){ + if(index.isValid()){ + view_->expand(index.parent()); + view_->edit(index); + } +} + +void ContextMenu::Rename(){ + QModelIndexList indexes = view_->selectionModel()->selection().indexes(); + if(indexes.size() == 2) + { + this->Rename(indexes[1]); + } +} + +}} // ns + diff --git a/modules/gui/src/scene_win/context_menu.hh b/modules/gui/src/scene_win/context_menu.hh new file mode 100644 index 0000000000000000000000000000000000000000..67d6e027d188f79a5855937166379e809f7e266e --- /dev/null +++ b/modules/gui/src/scene_win/context_menu.hh @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// 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 +//------------------------------------------------------------------------------ +#ifndef OST_GUI_SCENE_WIN_CONTEXT_MENU_HH +#define OST_GUI_SCENE_WIN_CONTEXT_MENU_HH + +/* + Author: Stefan Scheuber + */ + +#include <QMap> +#include <QAbstractItemModel> +#include <QTreeView> + +#include <ost/gui/module_config.hh> +#include <ost/gui/scene_win/scene_win_model.hh> + +namespace ost { namespace gui { + +enum ContextMenuType { + GFX_OBJECTS = 1, + ENTITIES, + ENTITY_VIEWS, + MIX +}; + + +class DLLEXPORT_OST_GUI ContextMenu : public QObject { + Q_OBJECT +public: + ContextMenu(QTreeView* view, SceneWinModel* model); + ~ContextMenu(){}; + + void ShowMenu(const QPoint& pos); + void Rename(QModelIndex index); + +private slots: + void AddView(); + void Rename(); + +private: + gui::ContextMenuType GetType(); + + QTreeView* view_; + SceneWinModel* model_; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/current_selection_node.cc b/modules/gui/src/scene_win/current_selection_node.cc index b242c320b567362023fea30e84877e247291925c..2906e5073a848bb824bdd5a3db3dc90d2a15987e 100644 --- a/modules/gui/src/scene_win/current_selection_node.cc +++ b/modules/gui/src/scene_win/current_selection_node.cc @@ -18,6 +18,8 @@ //------------------------------------------------------------------------------ #include <QFont> +#include <ost/mol/query_view_wrapper.hh> + #include <ost/gfx/scene.hh> #include <ost/gfx/gfx_node.hh> @@ -28,61 +30,21 @@ 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(); +CurrentSelectionNode::CurrentSelectionNode(gfx::EntityP entity, SceneNode* parent):EntityPartNode("Current Selection",entity,mol::QueryViewWrapper(entity->GetSelection()),parent),wrapper_(mol::QueryViewWrapper(entity->GetSelection())){ } -int CurrentSelectionNode::GetColumnCount() const{ - return 2; +void CurrentSelectionNode::SetQueryView(mol::QueryViewWrapper part) +{ + //Do Nothing } -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; +mol::QueryViewWrapper CurrentSelectionNode::GetQueryView() const +{ + if(this->GetEntity()->GetSelection()!=wrapper_.GetEntityView()){ + wrapper_ = mol::QueryViewWrapper(this->GetEntity()->GetSelection()); } - 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); - } + return wrapper_; } }} diff --git a/modules/gui/src/scene_win/current_selection_node.hh b/modules/gui/src/scene_win/current_selection_node.hh index 59d1a7c5d8cdb79b466c14d1118313a7488d8dc5..baedc36040b1f34f54cd87a31b339e8a7db10bca 100644 --- a/modules/gui/src/scene_win/current_selection_node.hh +++ b/modules/gui/src/scene_win/current_selection_node.hh @@ -28,12 +28,9 @@ #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> +#include <ost/gui/scene_win/entity_part_node.hh> /* Author: Stefan Scheuber @@ -41,21 +38,16 @@ namespace ost { namespace gui { -class DLLEXPORT_OST_GUI CurrentSelectionNode : public GfxSceneNode { +class DLLEXPORT_OST_GUI CurrentSelectionNode : public EntityPartNode { 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(); + virtual void SetQueryView(mol::QueryViewWrapper part); + virtual mol::QueryViewWrapper GetQueryView() const; private: - bool visible_; + mutable mol::QueryViewWrapper wrapper_; }; }} diff --git a/modules/gui/src/scene_win/custom_part_node.cc b/modules/gui/src/scene_win/custom_part_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..f8e5f79db5d70d3ff6d963e0368037301e46dd02 --- /dev/null +++ b/modules/gui/src/scene_win/custom_part_node.cc @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// 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 "custom_part_node.hh" + +#include "entity_part_node.hh" + +#include <ost/gfx/entity.hh> +#include <ost/gfx/gfx_node.hh> + +namespace ost { namespace gui { + +CustomPartNode::CustomPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, SceneNode* parent):EntityPartNode(name,entity,part,parent){ +} + +bool CustomPartNode::SetData(int column, const QVariant& value, int role){ + if (column==1 && role == Qt::EditRole) { + this->SetName(value.toString()); + return true; + } + return false; +} + +Qt::ItemFlags CustomPartNode::Flags(int column) const{ + if(column==0){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + else if(column==1){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable; + } + return Qt::NoItemFlags; +} + +}} + diff --git a/modules/gui/src/scene_win/custom_part_node.hh b/modules/gui/src/scene_win/custom_part_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..b585af4e0ee03dc06445763d6687007dd4fab761 --- /dev/null +++ b/modules/gui/src/scene_win/custom_part_node.hh @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// 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_CUSTOM_PART_NODE_HH +#define OST_GUI_SCENE_WIN_CUSTOM_PART_NODE_HH + +#include <QObject> +#include <QVariant> +#include <QModelIndex> + +#include <ost/mol/query_view_wrapper.hh> + +#include <ost/gfx/entity_fw.hh> + +#include <ost/gui/module_config.hh> +#include <ost/gui/scene_win/scene_node.hh> + +#include "entity_part_node.hh" +/* + Author: Stefan Scheuber + */ + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI CustomPartNode : public EntityPartNode { + Q_OBJECT +public: + CustomPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, SceneNode* node_parent ); + + virtual bool SetData(int column, const QVariant& value, int role); + virtual Qt::ItemFlags Flags(int column) const; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/entity_node.cc b/modules/gui/src/scene_win/entity_node.cc index 8a2aa3e87e567895e7ecb8eea7fc85f9286197e3..3b10dbbba297927ccceeb51c90268f74b5be25c5 100644 --- a/modules/gui/src/scene_win/entity_node.cc +++ b/modules/gui/src/scene_win/entity_node.cc @@ -37,7 +37,7 @@ namespace ost { namespace gui { EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent): - GfxSceneNode(entity,parent){ + GfxSceneNode(entity,parent),custom_view_(NULL){ SceneWinModel* model = GostyApp::Instance()->GetSceneWin()->GetModel(); model->AddNode(parent, this); @@ -51,6 +51,9 @@ EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent): node = new EntityPartNode("Ligands", entity, mol::QueryViewWrapper(entity->GetView().Select("ishetatm=1 and ele=C")), quick_selection); model->AddNode(quick_selection, node); + custom_view_ = new LabelNode("Custom Views", this); + model->AddNode(this, custom_view_); + node = new EntityPartNode("Full View", entity, mol::QueryViewWrapper(entity->GetView()), this); model->AddNode(this, node); @@ -58,5 +61,9 @@ EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent): model->AddNode(this, node); } +SceneNode* EntityNode::GetCustomViewNode(){ + return custom_view_; +} + }} diff --git a/modules/gui/src/scene_win/entity_node.hh b/modules/gui/src/scene_win/entity_node.hh index e63a4b646721c9779e78209cb68fd4fe145ee661..fa776f37726282ead07b0fc60877e39dba163357 100644 --- a/modules/gui/src/scene_win/entity_node.hh +++ b/modules/gui/src/scene_win/entity_node.hh @@ -38,6 +38,11 @@ class DLLEXPORT_OST_GUI EntityNode : public GfxSceneNode { Q_OBJECT public: EntityNode(gfx::EntityP& entity, SceneNode* node_parent); + + SceneNode* GetCustomViewNode(); + +private: + SceneNode* custom_view_; }; }} diff --git a/modules/gui/src/scene_win/entity_part_node.cc b/modules/gui/src/scene_win/entity_part_node.cc index 9316e16d7029c4e9a9e65d3c4d9c45fe94bbaf09..cfa59678093e354f499e3fbd8ef7b2c37af7e230 100644 --- a/modules/gui/src/scene_win/entity_part_node.cc +++ b/modules/gui/src/scene_win/entity_part_node.cc @@ -30,10 +30,7 @@ EntityPartNode::EntityPartNode(QString name, gfx::EntityP entity, mol::QueryView QVariant EntityPartNode::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(column==1) { if (role==Qt::DisplayRole) { return QVariant(name_); } else if(role==Qt::FontRole) { @@ -48,24 +45,9 @@ int EntityPartNode::GetColumnCount() const{ return 2; } -bool EntityPartNode::SetData(int column, const QVariant& value, int role){ - if (column==0 && role == Qt::CheckStateRole) { - if (value.toBool()) { - this->GetParent()->SetData(0,value,Qt::CheckStateRole); - entity_->SetVisible(query_view_.GetEntityView(), true); - visible_=true; - } else { - entity_->SetVisible(query_view_.GetEntityView(), false); - visible_=false; - } - return true; - } - return false; -} - Qt::ItemFlags EntityPartNode::Flags(int column) const{ if(column==0){ - return Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled; + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; } else if(column==1){ return Qt::ItemIsSelectable|Qt::ItemIsEnabled; @@ -81,5 +63,25 @@ mol::QueryViewWrapper EntityPartNode::GetQueryView() const{ return query_view_; } +void EntityPartNode::SetVisible(bool visible){ + visible_ = visible; +} + +bool EntityPartNode::GetVisible(){ + return visible_; +} + +gfx::EntityP EntityPartNode::GetEntity() const{ + return entity_; +} + +void EntityPartNode::SetName(QString name){ + name_ = name; +} + +const QString& EntityPartNode::GetName() const{ + return name_; +} + }} diff --git a/modules/gui/src/scene_win/entity_part_node.hh b/modules/gui/src/scene_win/entity_part_node.hh index b544a5e56ceb4b69ded2b368b4825d34626d509a..191350d3465f37a616a62e526728030e205f882a 100644 --- a/modules/gui/src/scene_win/entity_part_node.hh +++ b/modules/gui/src/scene_win/entity_part_node.hh @@ -23,9 +23,10 @@ #include <QVariant> #include <QModelIndex> +#include <ost/mol/query_view_wrapper.hh> + #include <ost/gfx/entity_fw.hh> -#include <ost/mol/query_view_wrapper.hh> #include <ost/gui/module_config.hh> #include <ost/gui/scene_win/scene_node.hh> @@ -41,13 +42,21 @@ public: EntityPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, 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; virtual void SetQueryView(mol::QueryViewWrapper part); virtual mol::QueryViewWrapper GetQueryView() const; + virtual gfx::EntityP GetEntity() const; + + virtual void SetName(QString name); + virtual const QString& GetName() const; + +protected: + virtual void SetVisible(bool visible); + virtual bool GetVisible(); + private: QString name_; gfx::EntityP entity_; diff --git a/modules/gui/src/scene_win/gfx_scene_node.cc b/modules/gui/src/scene_win/gfx_scene_node.cc index 89f8a98d5cf5767b31b40e5e016a24cb3f6911a4..9b8828779f3a85f3e20c726276fe608e64bffdf1 100644 --- a/modules/gui/src/scene_win/gfx_scene_node.cc +++ b/modules/gui/src/scene_win/gfx_scene_node.cc @@ -59,9 +59,6 @@ bool GfxSceneNode::SetData(int column, const QVariant& value, int role){ gfx_node_->Show(); } else { gfx_node_->Hide(); - for(int i = 0; i<this->GetChildCount(); i++){ - this->GetChild(i)->SetData(0,value,Qt::CheckStateRole); - } } return true; } diff --git a/modules/gui/src/scene_win/render_mode_node.cc b/modules/gui/src/scene_win/render_mode_node.cc index ea08b64bcd0744bbaffcc9c00548374630c98776..63789cd3748647cf9b595cc57c2a2826e48defe1 100644 --- a/modules/gui/src/scene_win/render_mode_node.cc +++ b/modules/gui/src/scene_win/render_mode_node.cc @@ -18,29 +18,25 @@ //------------------------------------------------------------------------------ #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 <ost/mol/query_view_wrapper.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){ +RenderModeNode::RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* parent):EntityPartNode(entity->GetRenderModeName(render_mode).c_str(),entity,mol::QueryViewWrapper(entity->GetRenderView(render_mode)),parent), + entity_(entity), + 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); + 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_); + String name = entity_->GetRenderModeName(render_mode_); return QVariant(name.c_str()); } else if(role==Qt::FontRole) { QFont f("Helvetica"); @@ -56,12 +52,11 @@ int RenderModeNode::GetColumnCount() const{ 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); + entity_->SetEnableRenderMode(render_mode_, true); } else { - entity->SetEnableRenderMode(render_mode_, false); + entity_->SetEnableRenderMode(render_mode_, false); } return true; } @@ -82,5 +77,10 @@ gfx::RenderMode::Type RenderModeNode::GetRenderMode() const { return render_mode_; } +void RenderModeNode::SetQueryView(mol::QueryViewWrapper part) +{ + //Do Nothing +} + }} diff --git a/modules/gui/src/scene_win/render_mode_node.hh b/modules/gui/src/scene_win/render_mode_node.hh index b2c387797a88efe33d257353d8d6ea045040c6bf..68bf5300ee720a5becd74a2e0b07e890d4801d68 100644 --- a/modules/gui/src/scene_win/render_mode_node.hh +++ b/modules/gui/src/scene_win/render_mode_node.hh @@ -34,7 +34,7 @@ #include <ost/gfx/gfx_object_fw.hh> #include <ost/gui/module_config.hh> -#include <ost/gui/scene_win/gfx_scene_node.hh> +#include <ost/gui/scene_win/entity_part_node.hh> /* Author: Stefan Scheuber @@ -42,7 +42,7 @@ namespace ost { namespace gui { -class DLLEXPORT_OST_GUI RenderModeNode : public GfxSceneNode { +class DLLEXPORT_OST_GUI RenderModeNode : public EntityPartNode { Q_OBJECT public: RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* node_parent ); @@ -54,7 +54,10 @@ public: gfx::RenderMode::Type GetRenderMode() const; + virtual void SetQueryView(mol::QueryViewWrapper part); + private: + gfx::EntityP entity_; gfx::RenderMode::Type render_mode_; }; diff --git a/modules/gui/src/scene_win/scene_node.hh b/modules/gui/src/scene_win/scene_node.hh index 3705785c03f2966ca815a855ebc1d67a778cb2cd..926c16f75440e241c1610207cb2033913c0cc64b 100644 --- a/modules/gui/src/scene_win/scene_node.hh +++ b/modules/gui/src/scene_win/scene_node.hh @@ -52,7 +52,6 @@ public: virtual bool SetData(int column, const QVariant& value, int role); virtual Qt::ItemFlags Flags(int column) const; virtual int GetColumnCount() const; - private: SceneNode* parent_; SceneNodeList nodes_; diff --git a/modules/gui/src/scene_win/scene_win.cc b/modules/gui/src/scene_win/scene_win.cc index b457a871dff2d4ba88a30556ad4b414220130463..7d69772f75c28a32a022501a585ef7ce3b826889 100644 --- a/modules/gui/src/scene_win/scene_win.cc +++ b/modules/gui/src/scene_win/scene_win.cc @@ -50,6 +50,7 @@ SceneWin::SceneWin(QWidget* parent) : layout->setSpacing(0); model_ = new SceneWinModel(this); view_ = new QTreeView(this); + context_menu_ = new ContextMenu(view_,model_); view_->setAttribute(Qt::WA_MacShowFocusRect, false); view_->header()->hide(); view_->setContextMenuPolicy(Qt::CustomContextMenu); @@ -57,6 +58,7 @@ SceneWin::SceneWin(QWidget* parent) : view_->setSelectionBehavior(QAbstractItemView::SelectRows); view_->setSelectionMode(QAbstractItemView::ExtendedSelection); view_->expandAll(); + layout->addWidget(view_); connect(view_->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, @@ -70,7 +72,7 @@ SceneWin::SceneWin(QWidget* parent) : void SceneWin::ContextMenuRequested(const QPoint& pos) { if (view_->indexAt(pos).isValid()) { - SceneSelection::Instance()->ShowMenu(view_->viewport()->mapToGlobal(pos)); + context_menu_->ShowMenu(view_->viewport()->mapToGlobal(pos)); } } @@ -79,7 +81,12 @@ void SceneWin::OnSelectionChange(const QItemSelection& sel, QItemSelectionModel* model = view_->selectionModel(); QModelIndexList indexes = model->selection().indexes(); gfx::NodePtrList selected_nodes = model_->GetGfxNodes(indexes); - emit this->ActiveNodesChanged(selected_nodes); + mol::QueryViewWrapperList selected_views = model_->GetQueryViewsList(indexes); + gfx::EntityP entity = model_->GetEntityOfViews(indexes); + if(entity) + emit this->ActiveNodesChanged(selected_nodes,entity,selected_views); + else + emit this->ActiveNodesChanged(selected_nodes,entity,mol::QueryViewWrapperList()); } SceneWinModel* SceneWin::GetModel(){ @@ -100,6 +107,11 @@ void SceneWin::RowsInserted(const QModelIndex & parent, int start, int end){ } +void SceneWin::AddView(gfx::EntityP entity, mol::EntityView view){ + +} + + SceneWin::~SceneWin() { } diff --git a/modules/gui/src/scene_win/scene_win.hh b/modules/gui/src/scene_win/scene_win.hh index bc69700c5ed3dd1089b2c257625ba555c6214d8f..5a9d5adeb89c9df6d40cfcfc74a276d010dd3dce 100644 --- a/modules/gui/src/scene_win/scene_win.hh +++ b/modules/gui/src/scene_win/scene_win.hh @@ -22,11 +22,14 @@ #include <QTreeView> #include <QItemSelection> +#include <ost/mol/query_view_wrapper.hh> + #include <ost/gfx/gfx_node_fw.hh> #include <ost/gui/module_config.hh> #include <ost/gui/widget.hh> #include <ost/gui/scene_win/scene_win_model.hh> +#include <ost/gui/scene_win/context_menu.hh> /* Authors: Marco Biasini, Ansgar Philippsen, Stefan Scheuber @@ -43,12 +46,14 @@ public: ~SceneWin(); signals: - void ActiveNodesChanged(gfx::NodePtrList nodes); + void ActiveNodesChanged(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views); public: virtual bool Save(const QString& prefix) { return true; } virtual bool Restore(const QString& prefix) { return true; } + void AddView(gfx::EntityP entity, mol::EntityView view); + public slots: void OnSelectionChange(const QItemSelection& sel, const QItemSelection& desel); @@ -64,6 +69,7 @@ private slots: private: SceneWinModel* model_; QTreeView* view_; + ContextMenu* context_menu_; }; }} // ns diff --git a/modules/gui/src/scene_win/scene_win_model.cc b/modules/gui/src/scene_win/scene_win_model.cc index c08830f6db6a2a3bbc13b40fdea607f3f8268a38..12df1534d79e3ac9ed4d2dc609773a1cb88ad8e8 100644 --- a/modules/gui/src/scene_win/scene_win_model.cc +++ b/modules/gui/src/scene_win/scene_win_model.cc @@ -68,6 +68,43 @@ gfx::NodePtrList SceneWinModel::GetGfxNodes(QModelIndexList indexes){ return selected_nodes; } +mol::QueryViewWrapperList SceneWinModel::GetQueryViewsList(QModelIndexList indexes){ + mol::QueryViewWrapperList selected_views; + for(int i = 0; i < indexes.size(); i++){ + if(indexes[i].column()==0){ + EntityPartNode* part_node = qobject_cast<EntityPartNode*>(GetItem(indexes[i])); + if(part_node){ + mol::QueryViewWrapper node = part_node->GetQueryView(); + selected_views.push_back(node); + } + } + } + return selected_views; +} + +gfx::EntityP SceneWinModel::GetEntityOfViews(QModelIndexList indexes){ + mol::QueryViewWrapperList selected_views; + gfx::EntityP entity; + bool entity_set = false; + for(int i = 0; i < indexes.size(); i++){ + if(indexes[i].column()==0){ + EntityPartNode* part_node = qobject_cast<EntityPartNode*>(GetItem(indexes[i])); + if(part_node){ + if(entity_set){ + if (entity != part_node->GetEntity()){ + return gfx::EntityP(); + } + } + else{ + entity = part_node->GetEntity(); + entity_set = true; + } + } + } + } + return entity; +} + void SceneWinModel::Update(){ emit this->dataChanged(QModelIndex(),QModelIndex()); } @@ -163,37 +200,21 @@ bool SceneWinModel::setData(const QModelIndex& index, void SceneWinModel::NodeAdded(const gfx::GfxNodeP& node) { - QModelIndex scene_node_model_index = this->index(0,0,QModelIndex()); - - SceneNode* scene_node = NULL; gfx::EntityP e=boost::dynamic_pointer_cast<gfx::Entity>(node); if(e){ - scene_node = new EntityNode(e,scene_node_); + new EntityNode(e,scene_node_); } else{ - scene_node = new GfxSceneNode(node, scene_node_); + SceneNode* scene_node = new GfxSceneNode(node, scene_node_); this->AddNode(scene_node_,scene_node); } } void SceneWinModel::NodeRemoved(const gfx::GfxNodeP& node) { - int i=0; - SceneNode* found = NULL; - while(!found && i<scene_node_->GetChildCount()){ - GfxSceneNode* gfx_scene_node = qobject_cast<GfxSceneNode*>(scene_node_->GetChild(i)); - if(gfx_scene_node && node==gfx_scene_node->GetGfxNode()){ - found = gfx_scene_node; - } - else{ - i++; - } - } - if(found){ - QModelIndex scene_node_model_index = this->index(0,0,QModelIndex()); - this->beginRemoveRows(scene_node_model_index,i,i); - scene_node_->RemoveChild(found); - this->endRemoveRows(); + SceneNode* scene_node = this->FindGfxNode(node); + if(scene_node->GetParent()){ + this->RemoveNode(scene_node); } } @@ -254,11 +275,11 @@ void SceneWinModel::DetachRenderModeObserver(RenderModesNode* node){ } } -QModelIndex SceneWinModel::GetIndexOf(SceneNode* node){ - return GetIndex(node,index(0,0,QModelIndex())); +QModelIndex SceneWinModel::GetIndexOf(SceneNode* node, int column){ + return GetIndex(node,index(0,0,QModelIndex()),column); } -QModelIndex SceneWinModel::GetIndex(SceneNode* node, QModelIndex parent){ +QModelIndex SceneWinModel::GetIndex(SceneNode* node, QModelIndex parent, int column){ if(parent.isValid()){ SceneNode* parent_node =reinterpret_cast<SceneNode*>(parent.internalPointer()); if(parent_node == node)return parent; @@ -266,9 +287,12 @@ QModelIndex SceneWinModel::GetIndex(SceneNode* node, QModelIndex parent){ while(i>=0){ SceneNode* child = parent_node->GetChild(i); if(child == node){ - return index(i,0,parent); + if(column<child->GetColumnCount()) + return index(i,column,parent); + else + return QModelIndex(); } - QModelIndex found = GetIndex(node, index(i,0,parent)); + QModelIndex found = GetIndex(node, index(i,0,parent),column); if (found.isValid()) { return found; } @@ -278,5 +302,19 @@ QModelIndex SceneWinModel::GetIndex(SceneNode* node, QModelIndex parent){ return QModelIndex(); } +SceneNode* SceneWinModel::FindGfxNode(gfx::GfxNodeP node) const{ + int i=0; + while(i<scene_node_->GetChildCount()){ + GfxSceneNode* gfx_scene_node = qobject_cast<GfxSceneNode*>(scene_node_->GetChild(i)); + if(gfx_scene_node && node==gfx_scene_node->GetGfxNode()){ + return gfx_scene_node; + } + else{ + i++; + } + } + return root_node_; +} + }} // ns diff --git a/modules/gui/src/scene_win/scene_win_model.hh b/modules/gui/src/scene_win/scene_win_model.hh index 258e798bdbb443df850a2e998ae2082b1953bb71..996f7b640de20d1e9fea7303a7f162649757524c 100644 --- a/modules/gui/src/scene_win/scene_win_model.hh +++ b/modules/gui/src/scene_win/scene_win_model.hh @@ -26,6 +26,9 @@ #include <QMap> #include <QAbstractItemModel> +#include <ost/mol/view_type_fw.hh> +#include <ost/mol/query_view_wrapper.hh> + #include <ost/gfx/gfx_node_fw.hh> #include <ost/gfx/scene_observer.hh> @@ -47,16 +50,23 @@ public: ~SceneWinModel(); gfx::NodePtrList GetGfxNodes(QModelIndexList indexes); + mol::QueryViewWrapperList GetQueryViewsList(QModelIndexList indexes); + gfx::EntityP GetEntityOfViews(QModelIndexList indexes); virtual void Update(); + SceneNode* GetItem(const QModelIndex &index) const; + + SceneNode* FindGfxNode(gfx::GfxNodeP node) const; + + bool AddNode(SceneNode* parent, SceneNode* child); bool RemoveNode(SceneNode* node); void AttachRenderModeObserver(RenderModesNode* node); void DetachRenderModeObserver(RenderModesNode* node); - QModelIndex GetIndexOf(SceneNode* node); + QModelIndex GetIndexOf(SceneNode* node, int column=0); // abstract item model interface QModelIndex index(int row, int col, const QModelIndex& parent = QModelIndex()) const; @@ -85,9 +95,7 @@ public: virtual void RenderModeChanged(const gfx::GfxNodeP& node); private: - SceneNode* GetItem(const QModelIndex &index) const; - - QModelIndex GetIndex(SceneNode* node, QModelIndex index); + QModelIndex GetIndex(SceneNode* node, QModelIndex index,int column); SceneNode* root_node_; SceneNode* scene_node_;