diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index 6857779b6f8c4a53fc12ca30923916864082620b..6c7cb07dc82539888e1b94caf5fe0f8ceb00d543 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -55,7 +55,10 @@ shell_history.hh ) set(OST_GUI_SCENE_WIN_HEADERS +entity_node.hh +entity_part_node.hh gfx_scene_node.hh +label_node.hh root_node.hh scene_node.hh scene_win.hh @@ -252,6 +255,9 @@ python_shell/shell_history.cc python_shell/string_literal_positions.cc python_shell/text_logger.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/root_node.cc scene_win/scene_win.cc @@ -310,6 +316,9 @@ panel_bar/side_bar.hh panel_bar/splitter_panel_bar.hh panel_bar/tabbed_panel_bar.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/root_node.hh scene_win/scene_node.hh scene_win/scene_win.hh diff --git a/modules/gui/src/scene_win/entity_node.cc b/modules/gui/src/scene_win/entity_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..b45b7c87da20c64c87804143c05007280a506379 --- /dev/null +++ b/modules/gui/src/scene_win/entity_node.cc @@ -0,0 +1,58 @@ +//------------------------------------------------------------------------------ +// 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 <QString> + +#include <ost/gui/gosty_app.hh> +#include <ost/gui/scene_win/scene_win.hh> +#include <ost/mol/query_view_wrapper.hh> + +#include "entity_part_node.hh" +#include "label_node.hh" + +#include "entity_node.hh" + + + +namespace ost { namespace gui { + +EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent): + GfxSceneNode(boost::dynamic_pointer_cast<gfx::GfxNode>(entity->shared_from_this()),parent){ + SceneWinModel* model = GostyApp::Instance()->GetSceneWin()->GetModel(); + model->AddNode(parent, 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")), 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); + + 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); + model->AddNode(this, node); +} + +}} + diff --git a/modules/gui/src/scene_win/entity_node.hh b/modules/gui/src/scene_win/entity_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..e63a4b646721c9779e78209cb68fd4fe145ee661 --- /dev/null +++ b/modules/gui/src/scene_win/entity_node.hh @@ -0,0 +1,45 @@ +//------------------------------------------------------------------------------ +// 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_ENTITY_NODE_HH +#define OST_GUI_SCENE_WIN_ENTITY_NODE_HH + +#include <ost/gfx/gfx_node_fw.hh> +#include <ost/gfx/gfx_node.hh> + +#include <ost/gfx/entity_fw.hh> +#include <ost/gfx/entity.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 EntityNode : public GfxSceneNode { + Q_OBJECT +public: + EntityNode(gfx::EntityP& entity, SceneNode* node_parent); +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/entity_part_node.cc b/modules/gui/src/scene_win/entity_part_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..9316e16d7029c4e9a9e65d3c4d9c45fe94bbaf09 --- /dev/null +++ b/modules/gui/src/scene_win/entity_part_node.cc @@ -0,0 +1,85 @@ +//------------------------------------------------------------------------------ +// 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 "entity_part_node.hh" + +#include <ost/gfx/entity.hh> +#include <ost/gfx/gfx_node.hh> + +namespace ost { namespace gui { + +EntityPartNode::EntityPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, SceneNode* parent):SceneNode(parent),name_(name),entity_(entity),query_view_(part),visible_(true){ +} + +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 (role==Qt::DisplayRole) { + return QVariant(name_); + } else if(role==Qt::FontRole) { + QFont f("Helvetica"); + return QVariant(f); + } + } + return QVariant(); +} + +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; + } + else if(column==1){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return Qt::NoItemFlags; +} + +void EntityPartNode::SetQueryView(mol::QueryViewWrapper part){ + query_view_ = part; +} + +mol::QueryViewWrapper EntityPartNode::GetQueryView() const{ + return query_view_; +} + +}} + diff --git a/modules/gui/src/scene_win/entity_part_node.hh b/modules/gui/src/scene_win/entity_part_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..b544a5e56ceb4b69ded2b368b4825d34626d509a --- /dev/null +++ b/modules/gui/src/scene_win/entity_part_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_ENTITY_PART_NODE_HH +#define OST_GUI_SCENE_WIN_ENTITY_PART_NODE_HH + +#include <QObject> +#include <QVariant> +#include <QModelIndex> + +#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> + +/* + Author: Stefan Scheuber + */ + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI EntityPartNode : public SceneNode { + Q_OBJECT +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; + +private: + QString name_; + gfx::EntityP entity_; + mol::QueryViewWrapper query_view_; + bool visible_; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/label_node.cc b/modules/gui/src/scene_win/label_node.cc new file mode 100644 index 0000000000000000000000000000000000000000..7a9c29ce7373cdd6c191cb82e48ca4ec85c8a84b --- /dev/null +++ b/modules/gui/src/scene_win/label_node.cc @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// 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 "label_node.hh" + +#include <ost/gfx/entity.hh> +#include <ost/gfx/gfx_node.hh> + +namespace ost { namespace gui { + +LabelNode::LabelNode(QString name, SceneNode* parent):SceneNode(parent),name_(name){ +} + +QVariant LabelNode::GetData(int column, int role){ + if(column<0 || column > 2)return QVariant(); + + if(column==1) { + if (role==Qt::DisplayRole) { + return QVariant(name_); + } else if(role==Qt::FontRole) { + QFont f("Helvetica"); + return QVariant(f); + } + } + return QVariant(); +} + +int LabelNode::GetColumnCount() const{ + return 2; +} + +bool LabelNode::SetData(int column, const QVariant& value, int role){ + if (column==0 && role == Qt::CheckStateRole) { + if (value.toBool()) { + this->GetParent()->SetData(0,value,Qt::CheckStateRole); + } else { + for(int i = 0; i<this->GetChildCount(); i++){ + this->GetChild(i)->SetData(0,value,Qt::CheckStateRole); + } + } + return true; + } + return false; +} + +Qt::ItemFlags LabelNode::Flags(int column) const{ + if(column==0 || column==1){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return Qt::NoItemFlags; +} + +void LabelNode::SetName(QString name){ + name_ = name; +} + +QString LabelNode::GetName() const{ + return name_; +} + +}} + diff --git a/modules/gui/src/scene_win/label_node.hh b/modules/gui/src/scene_win/label_node.hh new file mode 100644 index 0000000000000000000000000000000000000000..50d471be0991240d5f99a5becac4be368cc71871 --- /dev/null +++ b/modules/gui/src/scene_win/label_node.hh @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// 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_LABEL_NODE_HH +#define OST_GUI_SCENE_WIN_LABEL_NODE_HH + +#include <QObject> +#include <QVariant> +#include <QModelIndex> + +#include <ost/gui/module_config.hh> +#include <ost/gui/scene_win/scene_node.hh> + +/* + Author: Stefan Scheuber + */ + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI LabelNode : public SceneNode { + Q_OBJECT +public: + LabelNode(QString name, 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 SetName(QString name); + virtual QString GetName() const; + +private: + QString name_; +}; + +}} + +#endif diff --git a/modules/gui/src/scene_win/scene_node.cc b/modules/gui/src/scene_win/scene_node.cc index 57c7b44320da1bf34a0bf54bedfb7e559f8c3c89..024513538e0f8e9a2e734ccbd6fdfb50b3e46b9a 100644 --- a/modules/gui/src/scene_win/scene_node.cc +++ b/modules/gui/src/scene_win/scene_node.cc @@ -43,7 +43,7 @@ void SceneNode::RemoveChild(SceneNode* node){ int SceneNode::GetChildRow(const SceneNode* node) const{ for(int i = 0; i < nodes_.size(); i++){ - if(this == node)return i; + if(nodes_[i] == node)return i; } return -1; } diff --git a/modules/gui/src/scene_win/scene_win.cc b/modules/gui/src/scene_win/scene_win.cc index c3b78c1c86407b3389e115d7036882ebeab01cdd..b457a871dff2d4ba88a30556ad4b414220130463 100644 --- a/modules/gui/src/scene_win/scene_win.cc +++ b/modules/gui/src/scene_win/scene_win.cc @@ -82,6 +82,10 @@ void SceneWin::OnSelectionChange(const QItemSelection& sel, emit this->ActiveNodesChanged(selected_nodes); } +SceneWinModel* SceneWin::GetModel(){ + return model_; +} + void SceneWin::Update() { model_->Update(); view_->viewport()->update(); diff --git a/modules/gui/src/scene_win/scene_win.hh b/modules/gui/src/scene_win/scene_win.hh index fe25b6d29f7ec62d00e50af210fe3254ec107459..bc69700c5ed3dd1089b2c257625ba555c6214d8f 100644 --- a/modules/gui/src/scene_win/scene_win.hh +++ b/modules/gui/src/scene_win/scene_win.hh @@ -54,6 +54,8 @@ public slots: void ContextMenuRequested(const QPoint& pos); + SceneWinModel* GetModel(); + void Update(); private slots: diff --git a/modules/gui/src/scene_win/scene_win_model.cc b/modules/gui/src/scene_win/scene_win_model.cc index 28c54cf5ae5985519ae857020d528d9d8773c281..03dca9ee3a863c83e023f7569aabe42025a245b8 100644 --- a/modules/gui/src/scene_win/scene_win_model.cc +++ b/modules/gui/src/scene_win/scene_win_model.cc @@ -22,11 +22,16 @@ #include "scene_win_model.hh" +#include <boost/pointer_cast.hpp> + #include <ost/gfx/scene.hh> #include <ost/gfx/gfx_object.hh> +#include <ost/gfx/entity_fw.hh> +#include <ost/gfx/entity.hh> #include <ost/gui/scene_win/root_node.hh> #include <ost/gui/scene_win/gfx_scene_node.hh> +#include <ost/gui/scene_win/entity_node.hh> #include <QSize> #include <QFont> @@ -80,12 +85,15 @@ QModelIndex SceneWinModel::index(int row, int col, const QModelIndex& parent) co QModelIndex SceneWinModel::parent(const QModelIndex& index) const { + if(!index.isValid())return QModelIndex(); + SceneNode* node = GetItem(index); + assert(node); SceneNode* parent_node = node->GetParent(); - if(parent_node==root_node_) return QModelIndex(); + if(parent_node==root_node_ || parent_node==NULL) return QModelIndex(); - return createIndex(parent_node->GetChildCount(), 0, parent_node); + return createIndex(parent_node->GetRow(), 0, parent_node); } int SceneWinModel::rowCount(const QModelIndex& parent) const @@ -106,17 +114,17 @@ QVariant SceneWinModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); - SceneNode* node = reinterpret_cast<SceneNode*>(index.internalPointer()); + SceneNode* node = GetItem(index); if(!node) return QVariant(); - - return node->GetData(index.column(),role); + QVariant data = node->GetData(index.column(),role); + return data; } QVariant SceneWinModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - if(section==0) return QVariant("Vis"); + if(section==0) return QVariant("Visible"); else if(section==1) return QVariant("Node"); } return QVariant(); @@ -157,10 +165,15 @@ void SceneWinModel::NodeAdded(const gfx::GfxNodeP& node) { QModelIndex scene_node_model_index = this->index(0,0,QModelIndex()); - this->beginInsertRows(scene_node_model_index,0,0); - GfxSceneNode* gfx_scene_node = new GfxSceneNode(node, scene_node_); - scene_node_->AddChild(gfx_scene_node); - this->endInsertRows(); + SceneNode* scene_node = NULL; + gfx::EntityP e=boost::dynamic_pointer_cast<gfx::Entity>(node); + if(e){ + scene_node = new EntityNode(e,scene_node_); + } + else{ + scene_node = new GfxSceneNode(node, scene_node_); + this->AddNode(scene_node_,scene_node); + } } void SceneWinModel::NodeRemoved(const gfx::GfxNodeP& node) @@ -186,13 +199,46 @@ void SceneWinModel::NodeRemoved(const gfx::GfxNodeP& node) SceneNode* SceneWinModel::GetItem(const QModelIndex &index) const { - if (index.isValid()) { - SceneNode *node = reinterpret_cast<SceneNode*>(index.internalPointer()); - if (node) return node; - } - return root_node_; + if (index.isValid()) { + SceneNode *node = reinterpret_cast<SceneNode*>(index.internalPointer()); + if (node) return node; + } + return root_node_; +} + +bool SceneWinModel::AddNode(SceneNode* parent, SceneNode* child){ + QModelIndex parent_index = GetIndexOf(parent); + if(parent_index.isValid()){ + this->beginInsertRows(parent_index,0,0); + parent->AddChild(child); + this->endInsertRows(); + return true; + } + return false; +} + +QModelIndex SceneWinModel::GetIndexOf(SceneNode* node){ + return GetIndex(node,index(0,0,QModelIndex())); } +QModelIndex SceneWinModel::GetIndex(SceneNode* node, QModelIndex parent){ + if(parent.isValid()){ + SceneNode* parent_node =reinterpret_cast<SceneNode*>(parent.internalPointer()); + if(parent_node == node)return parent; + int i=parent_node->GetChildCount()-1; + while(i>=0){ + SceneNode* child = parent_node->GetChild(i); + if(child == node){ + return index(i,0,parent); + } + QModelIndex found = GetIndex(node, index(i,0,parent)); + if (found.isValid()) { + return found; + } + } + } + return QModelIndex(); +} }} // ns diff --git a/modules/gui/src/scene_win/scene_win_model.hh b/modules/gui/src/scene_win/scene_win_model.hh index 623b4c910813689f017ed074932b798aa028860d..00e4022d53af57adbb62fc710fd706601c25d811 100644 --- a/modules/gui/src/scene_win/scene_win_model.hh +++ b/modules/gui/src/scene_win/scene_win_model.hh @@ -45,6 +45,10 @@ public: virtual void Update(); + bool AddNode(SceneNode* parent, SceneNode* child); + + QModelIndex GetIndexOf(SceneNode* node); + // abstract item model interface QModelIndex index(int row, int col, const QModelIndex& parent = QModelIndex()) const; @@ -72,6 +76,8 @@ public: private: SceneNode* GetItem(const QModelIndex &index) const; + QModelIndex GetIndex(SceneNode* node, QModelIndex index); + SceneNode* root_node_; SceneNode* scene_node_; };