diff --git a/modules/gui/pymod/CMakeLists.txt b/modules/gui/pymod/CMakeLists.txt index c3fc64a17961c93349763793d7b1376b5791089e..03d7150c87557ff9a43ed0af4f98fe4aa98b0a01 100644 --- a/modules/gui/pymod/CMakeLists.txt +++ b/modules/gui/pymod/CMakeLists.txt @@ -8,7 +8,6 @@ set(OST_GUI_PYMOD_SOURCES export_gosty.cc export_remote_site_loader.cc export_scene_win.cc - export_sequence_viewer.cc export_sequence_viewerV2.cc export_perspective.cc export_sip_handler.cc diff --git a/modules/gui/pymod/export_gosty.cc b/modules/gui/pymod/export_gosty.cc index 9cd97b7fdabdc80c208a521c47e50b136d5babb1..1a2216e2a09651cec0d3ed0947e925b5f675f0e6 100644 --- a/modules/gui/pymod/export_gosty.cc +++ b/modules/gui/pymod/export_gosty.cc @@ -92,10 +92,6 @@ void export_Gosty() return_value_policy<reference_existing_object>()) .add_property("scene_win", make_function(&GostyApp::GetSceneWin, return_value_policy<reference_existing_object>())) - .def("GetSequenceViewer", &GostyApp::GetSequenceViewer, - return_value_policy<reference_existing_object>()) - .add_property("seq_viewer", make_function(&GostyApp::GetSequenceViewer, - return_value_policy<reference_existing_object>())) .def("GetSequenceViewerV2", &GostyApp::GetSequenceViewerV2, return_value_policy<reference_existing_object>()) .add_property("seq_viewer_v2", make_function(&GostyApp::GetSequenceViewerV2, diff --git a/modules/gui/pymod/export_sequence_viewer.cc b/modules/gui/pymod/export_sequence_viewer.cc deleted file mode 100644 index e6127166c5cb2c23903b9d407ad7437959c0addb..0000000000000000000000000000000000000000 --- a/modules/gui/pymod/export_sequence_viewer.cc +++ /dev/null @@ -1,39 +0,0 @@ -//------------------------------------------------------------------------------ -// 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 -//------------------------------------------------------------------------------ -#include <boost/python.hpp> - -#include <ost/gui/sequence_viewer/sequence_viewer.hh> - -#include "sip_handler.hh" - -using namespace boost::python; -using namespace ost; -using namespace ost::gui; - - -void export_SequenceViewer() -{ - class_<SequenceViewer, boost::noncopyable >("SequenceViewer", no_init) - .def("Show", &SequenceViewer::show) - .def("Hide", &SequenceViewer::hide) - .def("GetQObject",&get_py_qobject<SequenceViewer>) - .add_property("qobject", &get_py_qobject<SequenceViewer>) - ; -} - diff --git a/modules/gui/pymod/wrap_gui.cc b/modules/gui/pymod/wrap_gui.cc index 149c7885f69b5b5fb4df54bb63f18104696aae57..542356c51e61d82d4d2cb28a1fc8dec414e7ee0b 100644 --- a/modules/gui/pymod/wrap_gui.cc +++ b/modules/gui/pymod/wrap_gui.cc @@ -32,7 +32,6 @@ void export_GLWin(); void export_Gosty(); void export_PyShell(); void export_SceneWin(); -void export_SequenceViewer(); void export_SequenceViewerV2(); void export_PanelBar(); void export_Perspective(); @@ -116,7 +115,6 @@ BOOST_PYTHON_MODULE(_gui) export_Perspective(); export_SceneWin(); export_SceneSelection(); - export_SequenceViewer(); export_SequenceViewerV2(); export_RemoteSiteLoader(); export_FileLoader(); diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index 744b59c57f4c95b260f2373cc4f15bde95f2d043..d972cbd0a7b1c2299f738d53af996da8a529b26b 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -12,13 +12,6 @@ side_bar.hh splitter_panel_bar.hh tabbed_panel_bar.hh ) -set(OST_GUI_SEQUENCE_VIEWER_HEADERS -sequence_item.hh -sequence_viewer_base.hh -sequence_viewer.hh -sequence_scene.hh -sequence_search_bar.hh -) set(OST_GUI_SEQUENCE_VIEW_HEADERS align_properties_painter.hh @@ -211,11 +204,6 @@ scene_menu.cc widget.cc widget_pool.cc remote_site_loader.cc -sequence_viewer/sequence_item.cc -sequence_viewer/sequence_viewer_base.cc -sequence_viewer/sequence_viewer.cc -sequence_viewer/sequence_scene.cc -sequence_viewer/sequence_search_bar.cc sequence/align_properties_painter.cc sequence/base_row.cc sequence/background_painter.cc @@ -346,11 +334,6 @@ scene_selection.hh widget.hh widget_geom_handler.hh widget_pool.hh -sequence_viewer/sequence_item.hh -sequence_viewer/sequence_viewer_base.hh -sequence_viewer/sequence_viewer.hh -sequence_viewer/sequence_scene.hh -sequence_viewer/sequence_search_bar.hh sequence/align_properties_painter.hh sequence/background_painter.hh sequence/base_row.hh diff --git a/modules/gui/src/gosty_app.cc b/modules/gui/src/gosty_app.cc index 15f30c171f571daaddf5a0ce401c913bccd4beca..324aee547c90d6c59c7e4c35b5a2c8f499d1f97a 100644 --- a/modules/gui/src/gosty_app.cc +++ b/modules/gui/src/gosty_app.cc @@ -46,7 +46,7 @@ GostyApp* GostyApp::app_=NULL; GostyApp::GostyApp(): py_shell_(NULL), w_py_shell_(NULL), gl_win_(NULL), w_gl_win_(NULL), - scene_win_(NULL), w_scene_win_(NULL), seq_viewer_(NULL), seq_viewer_v2_(NULL), tool_options_win_(NULL), + scene_win_(NULL), w_scene_win_(NULL), seq_viewer_v2_(NULL), tool_options_win_(NULL), w_tool_options_(NULL), main_(new GostyMainWindow), perspective_(NULL), external_widgets_(QMap<QString,WidgetGeomHandler *>()) { @@ -95,15 +95,6 @@ SceneWin* GostyApp::GetSceneWin() return scene_win_; } -SequenceViewer* GostyApp::GetSequenceViewer() -{ - if (seq_viewer_==NULL) { - seq_viewer_=new SequenceViewer; - seq_viewer_->SetDestroyOnClose(false); - } - return seq_viewer_; -} - SequenceViewerV2* GostyApp::GetSequenceViewerV2() { if (seq_viewer_v2_==NULL) { diff --git a/modules/gui/src/gosty_app.hh b/modules/gui/src/gosty_app.hh index 46381ff1662237a5b60525407d7936eb05bd3eb4..e3f3a1f08bbf873f9364553a3bafd7188afb5173 100644 --- a/modules/gui/src/gosty_app.hh +++ b/modules/gui/src/gosty_app.hh @@ -30,7 +30,6 @@ #include <ost/config.hh> #include <ost/gui/module_config.hh> #include <ost/gui/scene_win/scene_win.hh> -#include <ost/gui/sequence_viewer/sequence_viewer.hh> #include <ost/gui/sequence/sequence_viewer.hh> #include <ost/gui/main.hh> #include <ost/gui/widget_geom_handler.hh> @@ -92,7 +91,6 @@ public: /// /// The sequence viewer is initialized when this method is first called. All /// subsequent calls will return the same SequenceViewer instance. - SequenceViewer* GetSequenceViewer(); SequenceViewerV2* GetSequenceViewerV2(); /// \brief get tool options window @@ -156,7 +154,6 @@ private: SceneWin* scene_win_; QWidget* w_scene_win_; - SequenceViewer* seq_viewer_; SequenceViewerV2* seq_viewer_v2_; ToolOptionsWin* tool_options_win_; diff --git a/modules/gui/src/main.cc b/modules/gui/src/main.cc index 9836c6e9057805a340c8559ee51183e08232581d..9abeac746c3a53ed5d99ea631814997db97e2ced 100644 --- a/modules/gui/src/main.cc +++ b/modules/gui/src/main.cc @@ -43,7 +43,6 @@ #include "gl_win.hh" //#include "entity_explorer/entity_explorer.hh" #include "mdi_sub_window.hh" -#include "sequence_viewer/sequence_viewer.hh" #include "tools/tool_options_win.hh" #include "plot_viewer/plot_viewer_proxy.hh" #include "plot_viewer/plot_viewer.hh" diff --git a/modules/gui/src/sequence/sequence_table_view.cc b/modules/gui/src/sequence/sequence_table_view.cc index 52f9083c5dd986d0fb15b432dfaf31ccdadd3a82..807c130da835bf75bcb219073a9ea704d7faf5e3 100644 --- a/modules/gui/src/sequence/sequence_table_view.cc +++ b/modules/gui/src/sequence/sequence_table_view.cc @@ -67,7 +67,6 @@ SequenceTableView::SequenceTableView(QAbstractItemModel * model) delegate_ = new SequenceDelegate(qobject_cast<SequenceModel*>(this->model()),this); #if !(defined(__APPLE__) && (QT_VERSION>=0x040600)) - std::cout << "INIT STATIC" << QT_VERSION << std::endl; this->InitStaticRow(); this->InitStaticColumn(); this->InitStaticField(); diff --git a/modules/gui/src/sequence_viewer/sequence_item.cc b/modules/gui/src/sequence_viewer/sequence_item.cc deleted file mode 100644 index 6200f6c15f6ea86c4ee5f970255cb10be60b1f96..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_item.cc +++ /dev/null @@ -1,494 +0,0 @@ -//------------------------------------------------------------------------------ -// 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 -//------------------------------------------------------------------------------ -/* - Author: Marco Biasini - */ - -#include <ost/mol/mol.hh> -#include <boost/bind.hpp> - -#include "sequence_item.hh" -#include "sequence_scene.hh" - -#include <QPainter> -#include <QGraphicsSceneMouseEvent> -#include <QGraphicsSceneContextMenuEvent> -#include <QGraphicsItem> -#include <QDebug> - -namespace ost { namespace gui { - -using boost::bind; - -Knob::Knob(const QString& text, const QColor& color, - SequenceItem* parent): - QGraphicsItem(parent) -{ - -} - -void Knob::paint(QPainter* painter, const QStyleOptionGraphicsItem*, - QWidget* widget) -{ - painter->setBrush(QBrush(color_)); - painter->setPen(QPen(color_.darker())); - painter->drawEllipse(this->boundingRect()); - if (this->isUnderMouse()) { - painter->setPen(QPen(color_.darker())); - } else { - painter->setPen(QPen(Qt::white)); - } - painter->drawText(this->boundingRect(), Qt::AlignCenter, text_); -} - -QRectF Knob::boundingRect() const -{ - return QRectF(0.0, 0.0, 15.0, 15.0); -} - - -SequenceHeader::SequenceHeader(SequenceItem* parent): - QGraphicsItem(parent) -{ - font_=QFont("Courier", 12); - font_.setKerning(false); - font_.setFixedPitch(true); -} - - -void SequenceHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem*, - QWidget* widget) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - painter->setFont(font_); - QFontMetrics m(font_); - QString name(si->GetSequence().GetName().c_str()); - QRectF br=this->boundingRect(); - name=m.elidedText(name, Qt::ElideMiddle, br.width()); - painter->drawText(br, Qt::AlignTop, name); -} - -QRectF SequenceHeader::boundingRect() const -{ - QFontMetrics metrics(font_); - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - QString name(si->GetSequence().GetName().c_str()); - QRectF rect(0, -2,name.size()*si->GetCharWidth()*1.1, - si->GetCharHeight()+2); - SequenceScene* s=dynamic_cast<SequenceScene*>(this->scene()); - rect.setWidth(std::min(qreal(s->GetHeaderWidth()), rect.width())); - return rect; -} - -SequenceBody::SequenceBody(SequenceItem* parent): - QGraphicsItem(parent) -{ - -} - - -void SequenceBody::paint(QPainter* painter, const QStyleOptionGraphicsItem*, - QWidget* widget) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - seq::SequenceHandle seq=si->GetSequence(); - if (!seq.IsValid()) { - return; - } - QString qstr(seq.GetString().c_str()); - QColor sel_color(Qt::yellow); - if (si->IsSecStructureVisible()) { - sel_color.setAlpha(50); - painter->setBrush(QBrush(sel_color)); - painter->setPen(QPen(QColor(Qt::yellow).darker())); - painter->drawPath(si->GetSecStructPaths()); - } - painter->setFont(si->GetFont()); - painter->setPen(QPen(Qt::black)); - QString tt("X"); - QRectF br=this->boundingRect(); - for (int i=0; i<qstr.size(); ++i) { - tt[0]=qstr[i]; - QRectF rect(br.left()+i*si->GetCharWidth(), br.top(), - br.width(), br.height()); - painter->drawText(rect, Qt::AlignLeft|Qt::AlignVCenter, tt); - } - - sel_color=QColor(Qt::green).lighter(); - painter->setPen(QPen(Qt::green)); - sel_color.setAlpha(100); - painter->setBrush(QBrush(sel_color)); - QRectF text_bounds=painter->boundingRect(boundingRect(), - Qt::AlignLeft|Qt::AlignVCenter, - qstr); - const SequenceItem::Selection& sel=si->GetSelection(); - for (size_t i=0; i<sel.size(); ++i) { - painter->drawRect(QRectF(sel[i].Loc*si->GetCharWidth(), 0, - sel[i].Length*si->GetCharWidth(), - si->GetCharHeight())); - } -} - -QRectF SequenceBody::boundingRect() const -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - seq::SequenceHandle seq=si->GetSequence(); - if (!seq.IsValid()) { - return QRectF(); - } - return QRectF(0, -2, seq.GetLength()*si->GetCharWidth(), - si->GetCharHeight()+2); -} - - -SequenceItem::SequenceItem(const seq::SequenceHandle& seq, - QGraphicsItem* parent): - QGraphicsItem(parent), seq_(seq), show_sec_struct_(true) -{ - header_=new SequenceHeader(this); - body_=new SequenceBody(this); - body_->translate(120.0, 0.0); - font_=QFont("Courier", 12); - font_.setKerning(false); - font_.setFixedPitch(true); - QFontMetrics metrics(font_); - advance_=metrics.boundingRect('W').width(); - height_=metrics.boundingRect('|').height(); - ascent_=metrics.ascent(); - this->setAcceptedMouseButtons(Qt::LeftButton); - this->ExtractSecStructSegments(); - selection_change_=false; -} - -SequenceHeader* SequenceItem::GetHeader() -{ - return header_; -} - -SequenceBody* SequenceItem::GetBody() -{ - return body_; -} - -const seq::SequenceHandle& SequenceItem::GetSequence() const -{ - return seq_; -} - -QRectF SequenceItem::GetCharBounds(int pos) const -{ - QPointF a(pos*advance_, 0); - return QRectF(this->mapToScene(a), QSizeF(advance_, height_)); -} - -float SequenceItem::GetCharWidth() const -{ - return advance_; -} - -float SequenceItem::GetCharHeight() const -{ - return height_; -} - -void SequenceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, - QWidget* widget) -{ -} - -QRectF SequenceItem::boundingRect() const -{ - QRectF child_r(this->childrenBoundingRect()); - if (show_sec_struct_) { - return QRectF(child_r.topLeft(), - QSize(child_r.width(), child_r.height()*2.5)); - } else { - return QRectF(child_r.topLeft(), - QSize(child_r.width(), child_r.height())); - } -} - -void SequenceItem::ExtractSecStructSegments() -{ - if (!seq_.HasAttachedView()) { - return; - } - mol::ChainView chain=seq_.GetAttachedView().GetChainList()[0]; - sec_=mol::alg::ExtractSecStructureSegments(chain); - this->SecStructSegmentsToPaths(); -} - -void SequenceHeader::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) -{ - //... -} -void SequenceBody::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - event->accept(); - last_index_=-1; - good_ole_click_=true; - merge_select_=event->modifiers() & Qt::ShiftModifier; - si->BeginSelectionChange(); -} - -void SequenceBody::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - int index=std::max(0, int(event->pos().x()/si->GetCharWidth())); - // find the secondary structure element -- if any that we are in - mol::alg::SecStructureSegments::iterator i=si->GetSecStructSegments().begin(), - e=si->GetSecStructSegments().end(); - for (;i!=e; ++i) { - if (i->first<=index && i->last>=index) { - si->Select(i->first, i->last+1, !merge_select_); - break; - } - } - good_ole_click_=false; -} -void SequenceHeader::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - event->accept(); -} - -void SequenceHeader::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - if (si->IsEverythingSelected()) { - si->ClearSelection(); - } else { - si->SelectAll(); - } - -} - -void SequenceBody::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - if (good_ole_click_) { - int index=std::max(0, int(event->pos().x()/si->GetCharWidth())); - si->Select(index, index+1, !merge_select_); - } - si->EndSelectionChange(); -} - -void SequenceBody::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - SequenceItem* si=dynamic_cast<SequenceItem*>(this->parentItem()); - good_ole_click_=false; - if (!si->GetSequence().IsValid()) { - return; - } - float x=event->pos().x(); - int index=std::max(0, int(x/si->GetCharWidth())); - if (last_index_!=-1 && last_index_!=index) { - si->Select(last_index_, index, !merge_select_); - } else { - last_index_=index; - } -} - -void SequenceItem::StackToPath(std::vector<QPointF>& stack) -{ - if (!stack.empty()) { - sec_paths_.moveTo(QPointF(stack.front().x(), stack.front().y()+.5*ascent_)); - for (std::vector<QPointF>::iterator j=stack.begin()+1, - e2=stack.end(); j!=e2; ++j) { - sec_paths_.lineTo(QPointF(j->x(), j->y()+0.5*ascent_)); - } - for (std::vector<QPointF>::reverse_iterator j=stack.rbegin(), - e2=stack.rend(); j!=e2; ++j) { - sec_paths_.lineTo(QPointF(j->x(), -j->y()+.5*ascent_)); - } - sec_paths_.closeSubpath(); - stack.clear(); - } -} - -void SequenceItem::SecStructSegmentsToPaths() -{ - sec_paths_=QPainterPath(); - - sec_paths_.setFillRule(Qt::WindingFill); - std::vector<QPointF> stack; - int last_end=-2; - for (mol::alg::SecStructureSegments::iterator i=sec_.begin(), - e=sec_.end(); i!=e; ++i) { - mol::alg::SecStructureSegment s=*i; - if (last_end!=s.first-1) { - this->StackToPath(stack); - } - if (s.ss_type.IsCoil()) { - stack.push_back(QPointF(s.first*advance_, -.6*height_)); - stack.push_back(QPointF((s.last+1)*advance_, -.6*height_)); - } else if (s.ss_type.IsHelical()) { - stack.push_back(QPointF(s.first*advance_, -.6*height_)); - stack.push_back(QPointF(s.first*advance_, -.9*height_)); - stack.push_back(QPointF((s.last+1)*advance_, -.9*height_)); - stack.push_back(QPointF((s.last+1)*advance_, -.6*height_)); - } else if (s.ss_type.IsExtended()) { - stack.push_back(QPointF(s.first*advance_, -.6*height_)); - stack.push_back(QPointF(s.first*advance_, -.9*height_)); - stack.push_back(QPointF((s.last-0.5)*advance_, -.9*height_)); - stack.push_back(QPointF((s.last-0.5)*advance_, -1.3*height_)); - stack.push_back(QPointF((s.last+1)*advance_, -.6*height_)); - - } - last_end=s.last; - } - this->StackToPath(stack); -} - -void SequenceItem::Select(int i1, int i2, bool clear) -{ - if (selection_change_>0) { - selection_=ref_sel_; - } - int a1=std::min(i1, i2); - int len=std::abs(i1-i2); - Range sel_start(a1, len); - Range* sel=&sel_start; - bool modified=false; - if (clear) { - selection_.clear(); - selection_.push_back(*sel); - } else { - for (size_t i=0; i<selection_.size(); ++i) { - if (sel->Loc>=selection_[i].Loc && sel->Loc<selection_[i].End()) { - int old_end=selection_[i].End(); - if (sel->End()<=selection_[i].End()) { - selection_[i].Length=int(sel->Loc-selection_[i].Loc); - if (old_end-sel->End()>0) { - selection_.push_back(Range(sel->End(), old_end-sel->End())); - } - } else { - selection_[i].Length=int(sel->Loc-selection_[i].Loc); - if (sel->End()-old_end>0) { - selection_.push_back(Range(old_end, sel->End()-old_end)); - } - } - modified=true; - break; - } else if (sel->End()>selection_[i].Loc && - sel->End()<=selection_[i].End()) { - int nn=selection_[i].Loc; - selection_[i].Length-=sel->End()-selection_[i].Loc; - selection_[i].Loc=sel->End(); - modified=true; - selection_.push_back(Range(sel->Loc, nn-sel->Loc)); - break; - } else if (sel->Loc<selection_[i].Loc && - sel->End()>selection_[i].End()) { - selection_[i].Length=0; - } else if (sel->Loc==selection_[i].End()) { - selection_[i].Length+=sel->Length; - sel->Length=0; - sel=&selection_[i]; - modified=true; - } else if (sel->End()==selection_[i].Loc) { - selection_[i].Loc-=sel->Length; - selection_[i].Length+=sel->Length; - sel->Length=0; - sel=&selection_[i]; - modified=true; - } - } - if (!modified) { - selection_.push_back(Range(a1, len)); - } - } - Selection::iterator i=std::remove_if(selection_.begin(), selection_.end(), - bind(&Range::Length, _1)==size_t(0)); - selection_.erase(i, selection_.end()); - if (!selection_change_) { - emit this->SelectionChanged(this); - } else { - selection_change_=2; - } - update(); -} - -void SequenceItem::ClearSelection() -{ - selection_.clear(); - if (selection_change_>0) { - selection_change_=2; - } else { - emit this->SelectionChanged(this); - update(); - } -} - -void SequenceItem::SelectAll() -{ - if (!seq_.IsValid()) { - return; - } - selection_.clear(); - selection_.push_back(Range(0, seq_.GetLength())); - if (selection_change_>0) { - selection_change_=1; - } else { - emit this->SelectionChanged(this); - update(); - } -} - -void SequenceItem::BeginSelectionChange() -{ - selection_change_=1; - ref_sel_=selection_; -} - -void SequenceItem::EndSelectionChange() -{ - if (selection_change_==2) { - emit this->SelectionChanged(this); - } - selection_change_=0; -} - -bool SequenceItem::IsEverythingSelected() const -{ - return selection_.size()==1 && selection_.front().Loc==0 && - selection_.front().End()>=static_cast<size_t>(seq_.GetLength()); -} - -const SequenceItem::Selection& SequenceItem::GetSelection() const -{ - return selection_; -} - -mol::alg::SecStructureSegments& SequenceItem::GetSecStructSegments() -{ - return sec_; -} - -void SequenceItem::SetShowSecStructure(bool show) -{ - show_sec_struct_=show; -} - -bool SequenceItem::IsSecStructureVisible() const -{ - return show_sec_struct_; -} - -}} diff --git a/modules/gui/src/sequence_viewer/sequence_item.hh b/modules/gui/src/sequence_viewer/sequence_item.hh deleted file mode 100644 index aeaa63d1a9af36e29a925aa5af3b5fc214b2c8be..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_item.hh +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// 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_SEQUENCE_ITEM_HH -#define OST_GUI_SEQUENCE_ITEM_HH - -#include <ost/gui/module_config.hh> -#include <ost/mol/sec_structure.hh> -#include <ost/mol/alg/sec_structure_segments.hh> - -#include <ost/seq/sequence_handle.hh> - -#include <QGraphicsItem> -#include <QFont> - -namespace ost { namespace gui { - -class SequenceItem; -class SequenceHeader; - -class DLLEXPORT_OST_GUI Knob : public QGraphicsItem { -public: - Knob(const QString& text, const QColor& color, - SequenceItem* parent=NULL); - - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* opts, - QWidget* widget=NULL); - virtual QRectF boundingRect() const; -private: - QString text_; - QColor color_; -}; - -class DLLEXPORT_OST_GUI SequenceHeader : public QGraphicsItem { -public: - SequenceHeader(SequenceItem* parent=NULL); - - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* opts, - QWidget* widget=NULL); - virtual QRectF boundingRect() const; -protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent* event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); - virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* event); -private: - QFont font_; -}; - -class DLLEXPORT_OST_GUI SequenceBody : public QGraphicsItem { -public: - SequenceBody(SequenceItem* parent=NULL); - - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* opts, - QWidget* widget=NULL); - virtual QRectF boundingRect() const; -protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent* event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - - virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event); -private: - QFont font_; - bool merge_select_; - bool good_ole_click_; - int last_index_; -}; - - -class DLLEXPORT_OST_GUI SequenceItem : public QObject, // required for signals - public QGraphicsItem { - Q_OBJECT -public: - typedef std::vector<Range> Selection; - - SequenceItem(const seq::SequenceHandle& seq, QGraphicsItem* parent=NULL); - - /// \brief get sequence - const seq::SequenceHandle& GetSequence() const; - - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* opts, - QWidget* widget=NULL); - virtual QRectF boundingRect() const; - - QRectF GetCharBounds(int pos) const; - - float GetCharWidth() const; - float GetCharHeight() const; - - SequenceBody* GetBody(); - SequenceHeader* GetHeader(); - QPainterPath& GetSecStructPaths() { return sec_paths_; } - QFont GetFont() { return font_; } - - const Selection& GetSelection() const; - void Select(int i1, int i2, bool clear=true); - - void BeginSelectionChange(); - void EndSelectionChange(); - - bool IsEverythingSelected() const; - void ClearSelection(); - void SelectAll(); - void SetShowSecStructure(bool show=true); - bool IsSecStructureVisible() const; - - mol::alg::SecStructureSegments& GetSecStructSegments(); -signals: - - /// \brief emitted whenever the selection changes - /// - /// When using BeginSelectionChange(), no signal is emitted until - /// EndSelectionChange() is called. - void SelectionChanged(SequenceItem* item); -private: - void ExtractSecStructSegments(); - void SecStructSegmentsToPaths(); - void StackToPath(std::vector<QPointF>& stack); - - QPainterPath sec_paths_; - mol::alg::SecStructureSegments sec_; - SequenceHeader* header_; - SequenceBody* body_; - seq::SequenceHandle seq_; - QFont font_; - Selection selection_; - Selection ref_sel_; - float advance_; - float height_; - float ascent_; - int selection_change_; - bool show_sec_struct_; -}; - -typedef std::vector<SequenceItem*> SequenceItemList; -}} - -#endif diff --git a/modules/gui/src/sequence_viewer/sequence_scene.cc b/modules/gui/src/sequence_viewer/sequence_scene.cc deleted file mode 100644 index 4b77a71e3e61d610ecfa973a87ae242be634d3d2..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_scene.cc +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -// 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 -//------------------------------------------------------------------------------ -#include "sequence_scene.hh" -#include <boost/bind.hpp> -#include <QPainter> - -namespace ost { namespace gui { - -using boost::bind; - -void SequenceScene::drawBackground(QPainter* painter, const QRectF& rect) -{ - if (sequences_.empty()) { - return; - } - QBrush stripe_brushes[]={ - QBrush(QColor(Qt::white)), - QBrush(QColor(245, 245, 245)) - }; - float width=sequences_[0]->GetCharWidth()*5; - QRectF stripe(QPointF(((int(rect.left()/width)-1)-1)*width+header_width_, - rect.top()), - QSizeF(width, rect.height())); - int n=round(rect.width()/width)+2; - int start=std::max(0, int(floor(rect.left()/width)))-1; - for (int i=0; i<n; ++i, stripe.translate(width, 0.0)) { - painter->fillRect(stripe, stripe_brushes[(i+start+2) % 2]); - } - painter->setPen(QPen(Qt::gray)); - const static int STEP_SIZE=10; - float s=sequences_[0]->GetCharWidth()*STEP_SIZE; - int n_rulers=round(rect.width()/s); - int first=std::max(0, int(floor(rect.left()/s))); - painter->fillRect(QRectF(QPointF(0.0, rect.top()), - QSizeF(header_width_, rect.height())), - QBrush(Qt::white)); - for (int i=first;i<first+n_rulers+2; ++i) { - painter->drawText(QRectF(QPointF(i*s-50+header_width_, - rect.top()), QSizeF(100, 30)), - Qt::AlignCenter, QString::number(i*STEP_SIZE)); - painter->drawLine(QPointF(i*s+header_width_, rect.top()+30), - QPointF(i*s+header_width_, rect.top()+30+rect.height())); - } - -} - -void SequenceScene::SetContextMenu(QMenu* menu) -{ - context_menu_=menu; -} - -QMenu* SequenceScene::GetContextMenu() -{ - return context_menu_; -} - -SequenceScene::SequenceScene(QObject* parent): - QGraphicsScene(parent), header_width_(120.0) -{ - connect(this, SIGNAL(sceneRectChanged(const QRectF&)), this, - SLOT(OnSceneRectChange(const QRectF&))); - context_menu_=NULL; -} - -void SequenceScene::RepackSequences() -{ - if (sequences_.empty()) { - return; - } - sequences_.front()->setPos(0.0, 50.0); - for (std::vector<SequenceItem*>::iterator i=sequences_.begin()+1, - e=sequences_.end(); i!=e; ++i) { - (*i)->setPos(0.0, (*(i-1))->pos().y()+ - (*(i-1))->boundingRect().height()); - } -} - -void SequenceScene::AddSequence(SequenceItem* seq) -{ - this->addItem(seq); - if (!sequences_.empty()) { - seq->setPos(0.0, sequences_.back()->pos().y()+ - sequences_.back()->boundingRect().height()); - } else { - seq->setPos(0.0, 50.0); - } - sequences_.push_back(seq); - update(); -} - -void SequenceScene::RemoveSequence(SequenceItem* seq) -{ - this->removeItem(seq); - std::vector<SequenceItem*>::iterator f=std::find(sequences_.begin(), - sequences_.end(), seq); - if(f != sequences_.end()) - { - sequences_.erase(f); - } - RepackSequences(); -} - -void SequenceScene::SetHeaderWidth(float width) -{ - header_width_=width; - update(); -} - -float SequenceScene:: GetHeaderWidth() const -{ - return header_width_; -} - -void SequenceScene::OnSceneRectChange(const QRectF& rect) -{ -} - -}} diff --git a/modules/gui/src/sequence_viewer/sequence_scene.hh b/modules/gui/src/sequence_viewer/sequence_scene.hh deleted file mode 100644 index 2547d9fbdf27527b2870617058affc08c9e76b2e..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_scene.hh +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// 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_SEQUENCE_SCENE_HH -#define OST_GUI_SEQUENCE_SCENE_HH - -#include <ost/gui/module_config.hh> -#include <ost/gui/sequence_viewer/sequence_item.hh> - -#include <QGraphicsScene> - -namespace ost { namespace gui { - - -class SequenceScene : public QGraphicsScene { - Q_OBJECT -public: - typedef std::vector<Range> Selection; - - SequenceScene(QObject* parent=NULL); - - void SetContextMenu(QMenu* menu); - - QMenu* GetContextMenu(); - std::vector<SequenceItem*>& GetSequences() { return sequences_; } - const Selection& GetSelection() const; - - /// \brief get length of longest sequence (including gaps) in the alignment - void GetMaxSequenceLength(); - - - void SetHeaderWidth(float width); - float GetHeaderWidth() const; - void AddSequence(SequenceItem* seq); - void RemoveSequence(SequenceItem* seq); - void RepackSequences(); -public slots: - void OnSceneRectChange(const QRectF& rect); -protected: - virtual void drawBackground(QPainter* painter, const QRectF& rect); -private: - void UpdateAlignment(); - Selection selection_; - Selection ref_sel_; - std::vector<SequenceItem*> sequences_; - QMenu* context_menu_; - float header_width_; -}; - -}} - -#endif diff --git a/modules/gui/src/sequence_viewer/sequence_search_bar.cc b/modules/gui/src/sequence_viewer/sequence_search_bar.cc deleted file mode 100644 index 808d45904e21293e5360e7bd5e3e8e25de82c132..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_search_bar.cc +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// 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 -//------------------------------------------------------------------------------ -/* - Author: Marco Biasini - */ - -#include "sequence_search_bar.hh" -#include "sequence_item.hh" - -#include <QHBoxLayout> -#include <QLineEdit> -#include <QPainter> -#include <QPaintEvent> -#include <QLabel> -#include <QKeyEvent> - -namespace ost { namespace gui { - -SequenceSearchBar::SequenceSearchBar(QWidget* parent): - QWidget(parent) -{ - subject_=new QLineEdit(this); - search_all_=new QCheckBox("search in all sequences", this); - search_in_=new QComboBox(this); - QHBoxLayout* l= new QHBoxLayout(this); - l->addSpacing(2); - l->addWidget(subject_, 0); - l->addWidget(search_all_, 0); - QLabel* label=new QLabel("search in:", this); - l->addSpacing(10); - l->addWidget(label, 0); - l->addWidget(search_in_, 0); - l->addStretch(1); - subject_->setMaximumWidth(200); - setLayout(l); - l->setSizeConstraint(QLayout::SetMaximumSize); - l->setMargin(1); - search_all_->setCheckState(Qt::Checked); - search_in_->setEnabled(false); -#if defined(__APPLE__) - subject_->setAttribute(Qt::WA_MacSmallSize, true); - search_all_->setAttribute(Qt::WA_MacSmallSize, true); - search_in_->setAttribute(Qt::WA_MacSmallSize, true); - label->setAttribute(Qt::WA_MacSmallSize, true); -#endif - connect(subject_, SIGNAL(textChanged(const QString&)), this, - SLOT(OnSubjectChanged(const QString&))); - connect(search_all_, SIGNAL(stateChanged(int)), this, - SLOT(OnSearchAllChanged(int))); - connect(search_in_, SIGNAL(currentIndexChanged(int)), this, - SLOT(OnSearchInChanged(int))); -} - -void SequenceSearchBar::Show(const std::vector<SequenceItem*>& sequences) -{ - search_in_->clear(); - - for (size_t i=0;i<sequences.size(); ++i) { - QString name(sequences[i]->GetSequence().GetName().c_str()); - search_in_->addItem(name); - } - if (sequences.empty()) { - search_all_->setCheckState(Qt::Checked); - search_in_->setEnabled(false); - } - this->show(); - subject_->setFocus(Qt::ActiveWindowFocusReason); - subject_->selectAll(); -} -void SequenceSearchBar::OnSearchAllChanged(int state) -{ - if (state==Qt::Unchecked) { - search_in_->setEnabled(true); - } else { - search_in_->setEnabled(false); - } - emit Changed(subject_->text(), search_all_->checkState()==Qt::Checked, - search_in_->currentIndex()); -} - -void SequenceSearchBar::OnSearchInChanged(int index) -{ - emit Changed(subject_->text(), search_all_->checkState()==Qt::Checked, - search_in_->currentIndex()); -} - -void SequenceSearchBar::OnSubjectChanged(const QString& str) -{ - emit Changed(str, search_all_->checkState()==Qt::Checked, - search_in_->currentIndex()); -} - -void SequenceSearchBar::paintEvent(QPaintEvent* paint_event) -{ - QPainter p(this); - p.setBrush(QBrush(QColor(Qt::blue).lighter(300))); - p.setPen(QPen(QColor(Qt::blue).lighter(200))); - p.drawRect(rect()); - paint_event->accept(); -} - -void SequenceSearchBar::keyPressEvent(QKeyEvent* key_event) -{ - if (key_event->key()==Qt::Key_Escape) { - this->hide(); - key_event->accept(); - } - QWidget::keyPressEvent(key_event); -} - -}} diff --git a/modules/gui/src/sequence_viewer/sequence_search_bar.hh b/modules/gui/src/sequence_viewer/sequence_search_bar.hh deleted file mode 100644 index fae7280dc6d119f47063e29645a5baaa882c95fe..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_search_bar.hh +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// 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_SEQUENCE_SEARCH_BAR_HH -#define OST_SEQUENCE_SEARCH_BAR_HH - -/* - Author: Marco Biasini - */ -#include <ost/gui/module_config.hh> -#include <ost/seq/alignment_handle.hh> -#include <QWidget> -#include <QComboBox> -#include <QCheckBox> - -namespace ost { namespace gui { - -class SequenceItem; - -/// \brief search bar to search in multiple sequence alignment -class DLLEXPORT_OST_GUI SequenceSearchBar : public QWidget { - Q_OBJECT -public: - SequenceSearchBar(QWidget* parent=NULL); - - void Show(const std::vector<SequenceItem*>& sequences); -signals: - void Changed(const QString&, bool, int); -public slots: - void OnSubjectChanged(const QString&); - void OnSearchInChanged(int); - void OnSearchAllChanged(int); -protected: - virtual void paintEvent(QPaintEvent* paint_event); - virtual void keyPressEvent(QKeyEvent* key_event); -private: - seq::AlignmentHandle ali_; - QLineEdit* subject_; - QCheckBox* search_all_; - QComboBox* search_in_; -}; - -}} - -#endif diff --git a/modules/gui/src/sequence_viewer/sequence_viewer.cc b/modules/gui/src/sequence_viewer/sequence_viewer.cc deleted file mode 100644 index 05d5d03cf1c64f68a374105eee97fe1bafb3b979..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_viewer.cc +++ /dev/null @@ -1,242 +0,0 @@ -//------------------------------------------------------------------------------ -// 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 -//------------------------------------------------------------------------------ -#include <QMenu> - -#include <ost/dyn_cast.hh> -#include <ost/mol/view_op.hh> - -#include <ost/gfx/entity.hh> -#include <ost/gfx/scene.hh> -#include <ost/gfx/gfx_node_visitor.hh> -#include <ost/gfx/gfx_node.hh> -#include <ost/gfx/gfx_object.hh> - -#include <ost/gui/widget_registry.hh> -#include <ost/gui/gosty_app.hh> - -#include "sequence_viewer.hh" - - -namespace ost { namespace gui { - -struct GetNodesVisitor: public gfx::GfxNodeVisitor { - GetNodesVisitor(): nodes_() {} - virtual void VisitObject(gfx::GfxObj* o, const Stack& st) { - nodes_.push_back(o->shared_from_this()); - } - gfx::NodePtrList nodes_; - gfx::NodePtrList GetNodes(){return nodes_;} -}; - -class SequenceViewerFactory: public WidgetFactory { -public: - SequenceViewerFactory() : - WidgetFactory("ost::gui::SequenceViewer", "Sequence Viewer") { - } - - virtual Widget* Create(QWidget* parent) { - return GostyApp::Instance()->GetSequenceViewer(); - } -}; - -OST_REGISTER_WIDGET(SequenceViewer, SequenceViewerFactory); - -SequenceViewer::SequenceViewer(QWidget* parent): - SequenceViewerBase(parent), we_are_changing_the_selection_(false) -{ - gfx::Scene::Instance().AttachObserver(this); - this->SetDisplayStyle(SequenceViewer::LOOSE); - - gfx::GfxNodeP root_node = gfx::Scene::Instance().GetRootNode(); - GetNodesVisitor gnv; - gfx::Scene::Instance().Apply(gnv); - gfx::NodePtrList list = gnv.GetNodes(); - for(unsigned int i=0; i<list.size();i++){ - this->NodeAdded(list[i]); - } -} - -SequenceViewer::~SequenceViewer() -{ - gfx::Scene::Instance().DetachObserver(this); -} - -void SequenceViewer::NodeAdded(const gfx::GfxNodeP& n) -{ - if (gfx::EntityP o=dyn_cast<gfx::Entity>(n)) { - // extract all chains - mol::EntityView v=o->GetView(); - for (mol::ChainViewList::const_iterator c=v.GetChainList().begin(), - e1=v.GetChainList().end(); c!=e1; ++c) { - mol::ChainView chain=*c; - String seq_str; - seq_str.reserve(chain.GetResidueCount()); - for (mol::ResidueViewList::const_iterator r=chain.GetResidueList().begin(), - e2=chain.GetResidueList().end(); r!=e2; ++r) { - mol::ResidueView res=*r; - seq_str.append(1, res.GetOneLetterCode()); - } - if (seq_str.empty()) { - continue; - } - String name=o->GetName(); - if (chain.GetName()!="" && chain.GetName()!=" ") { - name+=" ("+chain.GetName()+")"; - } - seq::SequenceHandle seq=seq::CreateSequence(name, seq_str); - mol::EntityView v_one_chain=v.GetHandle().CreateEmptyView(); - v_one_chain.AddChain(chain, mol::ViewAddFlag::INCLUDE_ALL); - seq.AttachView(v_one_chain); - SequenceItem* item=new SequenceItem(seq); - connect(item, SIGNAL(SelectionChanged(SequenceItem*)), - this, SLOT(ItemSelectionChanged(SequenceItem*))); - this->AddSequence(item); - obj_map_.insert(std::make_pair(item, o)); - } - } -} - -void SequenceViewer::ItemSelectionChanged(SequenceItem* item) -{ - if (we_are_changing_the_selection_==true) { - return; - } - we_are_changing_the_selection_=true; - // map sequence item back to graphical object - if (gfx::GfxObjP p=this->GfxObjForSeqItem(item)) { - gfx::EntityP ec=dyn_cast<gfx::Entity>(p); - seq::SequenceHandle seq=item->GetSequence(); - mol::EntityView att_v=seq.GetAttachedView(); - if (!att_v) { - we_are_changing_the_selection_=false; - return; - } - const SequenceItem::Selection& sel=item->GetSelection(); - // reset selection of "our" chain - mol::EntityView sel_v=ec->GetSelection(); - if (mol::ChainView c=sel_v.FindChain(att_v.GetChainList().front().GetHandle())) { - sel_v.RemoveChain(c); - } - if (sel.empty()) { - try { - ec->SetSelection(sel_v); - } catch(...) { - } - we_are_changing_the_selection_=false; - return; - } - for (SequenceItem::Selection::const_iterator j=sel.begin(), - e=sel.end(); j!=e; ++j) { - for (size_t k=j->Loc; k<j->End(); ++k) { - if (int(k)>seq.GetLength() || seq.GetOneLetterCode(k)=='-') { - continue; - } - if (mol::ResidueView rv=seq.GetResidue(k)) { - sel_v.AddResidue(rv, mol::ViewAddFlag::INCLUDE_ATOMS); - } - } - } - sel_v.AddAllInclusiveBonds(); - try { - ec->SetSelection(sel_v); - } catch(...) { - } - - } - we_are_changing_the_selection_=false; -} - -void SequenceViewer::NodeRemoved(const gfx::GfxNodeP& node) -{ - if (gfx::EntityP o=dyn_cast<gfx::Entity>(node)) { - SequenceItemList seq_items=this->SeqItemsForGfxObj(o); - for (SequenceItemList::iterator i=seq_items.begin(), - e=seq_items.end(); i!=e; ++i) { - SequenceItem* seq_item=*i; - this->RemoveSequence(seq_item); - delete seq_item; - } - } -} - -void SequenceViewer::SelectionChanged(const gfx::GfxObjP& o, - const mol::EntityView& view) -{ - if (we_are_changing_the_selection_) { - return; - } - we_are_changing_the_selection_=true; - gfx::EntityP ec=dyn_cast<gfx::Entity>(o); - - - std::vector<bool> selected_cols; - selected_cols.resize(this->GetLongestSequenceLength(), false); - - // get affected sequence items - SequenceItemList seq_items=this->SeqItemsForGfxObj(o); - - for (SequenceItemList::iterator i=seq_items.begin(), - e=seq_items.end(); i!=e; ++i) { - SequenceItem* seq_item=*i; - - if(view.GetChainCount()==0){ - this->SelectColumns(seq_item, selected_cols); - } - else - { - seq::SequenceHandle seq=seq_item->GetSequence(); - mol::ChainView dst_chain=(seq.GetAttachedView().GetChainList())[0]; - if (mol::ChainView src_chain=view.FindChain(dst_chain.GetName())) { - // for each residue in the selection deduce index in sequence - for (mol::ResidueViewList::const_iterator j=src_chain.GetResidueList().begin(), - e2=src_chain.GetResidueList().end(); j!=e2; ++j) { - mol::ResidueView dst_res=dst_chain.FindResidue(j->GetHandle()); - assert(dst_res.IsValid()); - int p=seq.GetPos(dst_res.GetIndex()); - assert(p>=0 && p<=seq.GetLength()); - selected_cols[p]=true; - } - this->SelectColumns(seq_item, selected_cols); - std::fill(selected_cols.begin(), selected_cols.end(), false); - } - } - } - we_are_changing_the_selection_=false; -} - -SequenceItemList SequenceViewer::SeqItemsForGfxObj(const gfx::GfxObjP& obj) -{ - SequenceItemList seq_items; - gfx::EntityP ec=dyn_cast<gfx::Entity>(obj); - std::map<SequenceItem*, gfx::EntityP>::iterator i,e; - for (i=obj_map_.begin(), e=obj_map_.end(); i!=e; ++i) { - if (i->second==ec) { - seq_items.push_back(i->first); - } - } - return seq_items; -} - -gfx::GfxObjP SequenceViewer::GfxObjForSeqItem(SequenceItem* item) -{ - std::map<SequenceItem*, gfx::EntityP>::iterator i=obj_map_.find(item); - return (i!=obj_map_.end()) ? i->second : gfx::EntityP(); -} - -}} diff --git a/modules/gui/src/sequence_viewer/sequence_viewer.hh b/modules/gui/src/sequence_viewer/sequence_viewer.hh deleted file mode 100644 index 0b5811dc1fb17fd7905501845b01a77d592d75c8..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_viewer.hh +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// 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_SEQUENCE_VIEWER_HH -#define OST_SEQUENCE_VIEWER_HH - -/* - Author: Marco Biasini - */ - -#include <map> - -#include <ost/gfx/scene_observer.hh> -#include <ost/gui/sequence_viewer/sequence_viewer_base.hh> -#include <ost/gfx/entity.hh> - -namespace ost { namespace gui { - -class SequenceItem; - -/// \brief sequence view -class DLLEXPORT_OST_GUI SequenceViewer : public SequenceViewerBase, - public gfx::SceneObserver { - Q_OBJECT -public: - SequenceViewer(QWidget* parent=NULL); - ~SequenceViewer(); - - 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); -public slots: - void ItemSelectionChanged(SequenceItem* item); -private: - SequenceItemList SeqItemsForGfxObj(const gfx::GfxObjP& obj); - gfx::GfxObjP GfxObjForSeqItem(SequenceItem* seq_item); - std::map<SequenceItem*, gfx::EntityP> obj_map_; - bool we_are_changing_the_selection_; -}; - -}} - -#endif diff --git a/modules/gui/src/sequence_viewer/sequence_viewer_base.cc b/modules/gui/src/sequence_viewer/sequence_viewer_base.cc deleted file mode 100644 index 61cae9aac9015f3c3db6a27741a12c7f84da109a..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_viewer_base.cc +++ /dev/null @@ -1,237 +0,0 @@ -//------------------------------------------------------------------------------ -// 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 -//------------------------------------------------------------------------------ -#include "sequence_viewer_base.hh" -#include "sequence_search_bar.hh" -#include <QShortcut> -#include <QVBoxLayout> -#include <QPainter> - -namespace ost { namespace gui { - -SequenceViewerBase::SequenceViewerBase(QWidget* parent): - Widget(NULL, parent), style_(DENSE), sel_mode_(ROW), - scene_(new SequenceScene(this)), search_bar_(new SequenceSearchBar(this)), - view_(new QGraphicsView(NULL, this)) -{ - QVBoxLayout* l=new QVBoxLayout; - this->setLayout(l); - l->setMargin(0); - l->setSpacing(0); - view_->setScene(scene_); - l->addWidget(search_bar_, 0); - l->addWidget(view_, 1); - view_->setScene(scene_); - view_->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); - view_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); - QShortcut* shortcut=new QShortcut(QKeySequence(tr("Ctrl+F")), this); - connect(shortcut, SIGNAL(activated()), this, SLOT(FindInSequence())); - connect(search_bar_, SIGNAL(Changed(const QString&, bool, int)), this, - SLOT(OnSearchBarUpdate(const QString&, bool, int))); - search_bar_->hide(); - view_->setAlignment(Qt::AlignLeft|Qt::AlignTop); -} - -namespace { - -size_t update_select_state(seq::SequenceHandle seq, const String& subject, - std::vector<bool>& sel_state) -{ - size_t pos=0; - size_t first=String::npos; - String seq_str=seq.GetString(); - while ((pos=seq_str.find(subject, pos))!=String::npos) { - if (first==String::npos) { - first=pos; - } - std::fill_n(sel_state.begin()+pos, subject.length(), true); - pos+=subject.length(); - } - return first; -} - - -void set_sel(std::vector<bool>& selected, SequenceItem* item) -{ - std::vector<bool>::iterator c=selected.begin(); - item->ClearSelection(); - while (c!=selected.end()) { - std::vector<bool>::iterator e=c; - while ((*(++e))==*c && e!=selected.end()) {} - if (*c) { - // this is really ugly! - item->BeginSelectionChange(); - item->Select(c-selected.begin(), e-selected.begin(), false); - } - c=e; - } - item->EndSelectionChange(); -} - -} - -void SequenceViewerBase::FindInSequence() -{ - if (scene_->GetSequences().empty()) { - return; - } - search_bar_->Show(scene_->GetSequences()); -} - -int SequenceViewerBase::GetLongestSequenceLength() const -{ - std::vector<SequenceItem*>::iterator i=scene_->GetSequences().begin(), - e=scene_->GetSequences().end(); - int longest=0; - for (; i!=e; ++i) { - longest=std::max(longest, (*i)->GetSequence().GetLength()); - } - return longest; -} - -void SequenceViewerBase::SelectColumns(std::vector<bool>& selected_cols) -{ - std::vector<SequenceItem*>::iterator i=scene_->GetSequences().begin(), - e=scene_->GetSequences().end(); - for (; i!=e; ++i) { - set_sel(selected_cols, *i); - } -} - -void SequenceViewerBase::SelectColumns(SequenceItem* seq_item, - std::vector<bool>& selected_cols) -{ - set_sel(selected_cols, seq_item); -} - -void SequenceViewerBase::ClearSelection() -{ - std::vector<SequenceItem*>::iterator i=scene_->GetSequences().begin(), - e=scene_->GetSequences().end(); - for (; i!=e; ++i) { - (*i)->ClearSelection(); - } -} - -void SequenceViewerBase::OnSearchBarUpdate(const QString& subject, - bool search_in_all, int seq_id) -{ - String std_subj=subject.toStdString(); - this->ClearSelection(); - if (scene_->GetSequences().empty() || (seq_id==-1 && !search_in_all)) { - return; - } - if (subject.size()==0) { - return; - } - - std::vector<bool> selected; - selected.resize(GetLongestSequenceLength(), false); - /// \todo implement selection for SelMode==COLUMN - std::pair<int, size_t> first(0, String::npos); - if (search_in_all) { - for (size_t i=0; i<scene_->GetSequences().size(); ++i) { - (scene_->GetSequences())[i]->ClearSelection(); - seq::SequenceHandle s=(scene_->GetSequences())[i]->GetSequence(); - size_t pos=update_select_state(s, std_subj, selected); - if (pos!=String::npos && first.second==String::npos) { - first.second=pos; - first.first=i; - } - if (sel_mode_==ROW) { - set_sel(selected, (scene_->GetSequences())[i]); - std::fill_n(selected.begin(), selected.size(), false); - } - } - } else { - first.first=seq_id; - SequenceItem* s=(scene_->GetSequences())[seq_id]; - size_t pos=update_select_state(s->GetSequence(), std_subj, selected); - if (pos!=String::npos) { - first.second=pos; - } - if (sel_mode_==ROW) { - set_sel(selected, s); - } - } - if (sel_mode_==COLUMN) { - this->SelectColumns(selected); - } - if (first.second!=String::npos) { - QRectF r=(scene_->GetSequences()[first.first]->GetCharBounds(first.second)); - - view_->ensureVisible(r); - } - scene_->update(); -} - -void SequenceViewerBase::SetDisplayStyle(Style style) -{ - style_=style; - for (std::vector<SequenceItem*>::iterator i=scene_->GetSequences().begin(), - e=scene_->GetSequences().end(); i!=e; ++i) { - (*i)->SetShowSecStructure(style_==LOOSE); - } - scene_->RepackSequences(); -} - -void SequenceViewerBase::SetSelMode(SelMode mode) -{ - sel_mode_=mode; -} - -SequenceViewerBase::SelMode SequenceViewerBase::GetSelMode() const -{ - return sel_mode_; -} - -SequenceViewerBase::Style SequenceViewerBase::GetDisplayStyle() const -{ - return style_; -} - -void SequenceViewerBase::AddSequence(SequenceItem* seq) -{ - seq->SetShowSecStructure(style_==LOOSE); - scene_->AddSequence(seq); - QRectF rect=scene_->itemsBoundingRect(); - view_->setSceneRect(QRectF(0, 0, +rect.left()+rect.width(), - rect.height()+rect.top())); -} - -void SequenceViewerBase::RemoveSequence(SequenceItem* seq) -{ - scene_->RemoveSequence(seq); -} - -void SequenceViewerBase::Clear() -{ - -} - -bool SequenceViewerBase::Restore(const QString& prefix) -{ - return true; -} - -bool SequenceViewerBase::Save(const QString& prefix) -{ - return true; -} - -}} diff --git a/modules/gui/src/sequence_viewer/sequence_viewer_base.hh b/modules/gui/src/sequence_viewer/sequence_viewer_base.hh deleted file mode 100644 index 6bc183765c54a9f3b3b4f20f33eb0a0cd20a6e73..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence_viewer/sequence_viewer_base.hh +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -// 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_SEQUENCE_VIEWER_BASE_HH -#define OST_GUI_SEQUENCE_VIEWER_BASE_HH -/* - Author: Marco Biasini - */ - -#include <ost/gui/sequence_viewer/sequence_item.hh> -#include <ost/gui/sequence_viewer/sequence_scene.hh> - -#include <ost/gui/widget.hh> - -#include <QGraphicsView> - -namespace ost { namespace gui { - -class SequenceSearchBar; - -/// \brief base class for sequence viewers -/// -/// subclassed by AlignmentViewer and SequenceViewer -class DLLEXPORT_OST_GUI SequenceViewerBase : public Widget { - Q_OBJECT -public: - typedef enum { - DENSE, - LOOSE, - } Style; - - typedef enum { - COLUMN, - ROW - } SelMode; -public: - SequenceViewerBase(QWidget* parent=NULL); - void SetDisplayStyle(Style style); - - void SetSelMode(SelMode mode); - - SelMode GetSelMode() const; - Style GetDisplayStyle() const; - - /// \brief add sequence - /// - /// issue: should we copy the sequence object to avoid weird side-effects? - void AddSequence(SequenceItem* seq); - - /// \brief remove sequence - void RemoveSequence(SequenceItem* seq); - - /// \brief select columns in all sequences - void SelectColumns(std::vector<bool>& selected_cols); - - /// \brief select columns in sequence - void SelectColumns(SequenceItem* seq, std::vector<bool>& selected_cols); - /// \brief get length of longest sequence including gaps - int GetLongestSequenceLength() const; - /// \brief remove all sequences - void Clear(); - - virtual bool Restore(const QString& prefix); - virtual bool Save(const QString& prefix); -public slots: - /// \brief clear selection - void ClearSelection(); - - /// \internal - void OnSearchBarUpdate(const QString&, bool, int); - - /// \brief show sequence search bar - void FindInSequence(); - -private: - Style style_; - SelMode sel_mode_; - SequenceScene* scene_; - SequenceSearchBar* search_bar_; - QGraphicsView* view_; -}; - -}} -#endif diff --git a/scripts/init.py b/scripts/init.py index 020a660797852353077ff6c36a8f10834c1dd05a..424ae43981cb059c86a629547b66c4111cf927e2 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -35,7 +35,6 @@ def _InitPanels(app): panels.AddWidgetToPool('ost.gui.PythonShell', 1) panels.AddWidgetToPool('ost.gui.RemoteLoader', -1) panels.AddWidgetToPool('ost.gui.SceneWin', 1) - panels.AddWidgetToPool('ost.gui.SequenceViewer', 1) panels.AddWidgetToPool('ost.gui.SequenceViewerV2', 1) if not panels.Restore("ui/perspective/panels"): panels.AddWidget(gui.PanelPosition.LEFT_PANEL, app.scene_win) @@ -43,7 +42,7 @@ def _InitPanels(app): 'ost.gui.FileBrowser', False) panels.AddWidgetByName(gui.PanelPosition.LEFT_PANEL, 'ost.gui.RemoteLoader', False) - panels.AddWidget(gui.PanelPosition.BOTTOM_PANEL, app.seq_viewer) + panels.AddWidget(gui.PanelPosition.BOTTOM_PANEL, app.seq_viewer_v2) panels.AddWidget(gui.PanelPosition.BOTTOM_PANEL, app.py_shell) def _InitFrontEnd():