seqgraphic_widget.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:20k
- /*
- * ===========================================================================
- * PRODUCTION $Log: seqgraphic_widget.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 21:12:59 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: seqgraphic_widget.cpp,v 1000.2 2004/06/01 21:12:59 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Vlad Lebedev
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/utils/fltk_utils.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_widget.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_ds.hpp>
- #include <gui/widgets/fl/menu.hpp>
- #include <gui/config/feat_config_list.hpp>
- #include "seqgraphic_pane.hpp"
- #include <FL/Fl_Box.H>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- void s_CSeqGraphicWidget_ScrollCB(Fl_Widget* w, void*)
- {
- dynamic_cast<CSeqGraphicWidget&> (*w->parent()).x_ScrollCB();
- }
- void s_CSeqGraphicWidget_SliderXCB(Fl_Widget* w, void*)
- {
- dynamic_cast<CSeqGraphicWidget&> (*w->parent()).x_SliderCB();
- }
- void s_CSeqGraphicWidget_SearchXCB(Fl_Widget* w, void*)
- {
- dynamic_cast<CSeqGraphicWidget&> (*w->parent()->parent()).x_SearchCB();
- }
- void s_CSeqGraphicWidget_PrevXCB(Fl_Widget* w, void*)
- {
- dynamic_cast<CSeqGraphicWidget&> (*w->parent()->parent()).x_PrevCB();
- }
- void s_CSeqGraphicWidget_NextXCB(Fl_Widget* w, void*)
- {
- dynamic_cast<CSeqGraphicWidget&> (*w->parent()->parent()).x_NextCB();
- }
- static
- DEFINE_MENU(PopupMenu)
- MENU_ITEM(eCmdZoomIn, "Zoom In")
- MENU_ITEM(eCmdZoomOut, "Zoom Out")
- MENU_ITEM(eCmdZoomAll, "Zoom All")
- MENU_ITEM(eCmdZoomObject, "Zoom on Object")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdPrevExon, "Feature: Prev. Exon")
- MENU_ITEM(eCmdNextExon, "Feature: Next Exon")
- END_MENU()
- BEGIN_CMD_MAP(CSeqGraphicWidget, CCommandTarget)
- ON_COMMAND(eCmdZoomIn, &CSeqGraphicWidget::OnZoomIn)
- ON_COMMAND(eCmdZoomOut, &CSeqGraphicWidget::OnZoomOut)
- ON_COMMAND(eCmdZoomAll, &CSeqGraphicWidget::OnZoomAll)
- ON_COMMAND(eCmdZoomObject, &CSeqGraphicWidget::OnZoomObject)
- ON_COMMAND(eCmdPrevExon, &CSeqGraphicWidget::OnPrevExon)
- ON_COMMAND(eCmdNextExon, &CSeqGraphicWidget::OnNextExon)
- END_CMD_MAP()
- void CSeqGraphicWidget::OnZoomIn(void)
- {
- m_SeqGraphicPane->ZoomIn();
- }
- void CSeqGraphicWidget::OnZoomOut(void)
- {
- m_SeqGraphicPane->ZoomOut();
- }
- void CSeqGraphicWidget::OnZoomAll(void)
- {
- m_SeqGraphicPane->ZoomAll();
- }
- void CSeqGraphicWidget::OnZoomObject(void)
- {
- m_SeqGraphicPane->ZoomObject();
- }
- void CSeqGraphicWidget::OnPrevExon(void)
- {
- m_SeqGraphicPane->NextPrevExon(CSeqGraphicPane::ePrev);
- }
- void CSeqGraphicWidget::OnNextExon(void)
- {
- m_SeqGraphicPane->NextPrevExon(CSeqGraphicPane::eNext);
- }
- void CSeqGraphicWidget::OnShowPopup()
- {
- CPopupMenu menu(x(), y(), w(), h());
- menu.SetCmdTarget(static_cast<CCommandTarget*>(this));
- add(&menu);
- menu.SetItems(PopupMenu);
-
- menu.popup();
- remove(&menu);
- }
- CSeqGraphicWidget::CSeqGraphicWidget(int x, int y,
- int w, int h, const char* label)
- : Fl_Group(x, y, w, h, label)
- {
- const int kScrollBarSize = 15;
- const int kSliderBarSize = 40;
- const int kSearchBarSize = 24;
-
- const int kNextW = 14;
- const int kPrevW = 14;
- const int kChoiceW = 150;
- const int kRangeW = 100;
- const int kAllW = kChoiceW + kRangeW + kPrevW + kNextW;
- const int kSearchW = x + (w - kAllW) - 86;
-
- begin();
- m_ScrollX = new Fl_Scrollbar
- (x, y+(h - kScrollBarSize - kSliderBarSize - kSearchBarSize),
- w - kScrollBarSize, kScrollBarSize);
- m_ScrollX->type(FL_HORIZONTAL);
- m_ScrollX->callback( s_CSeqGraphicWidget_ScrollCB );
- m_ScrollX->when(m_ScrollX->when() | FL_WHEN_RELEASE);
- m_ScrollX->labeltype(FL_NO_LABEL);
- m_ScrollY = new Fl_Scrollbar
- (x + (w - kScrollBarSize), y, kScrollBarSize,
- h - kSliderBarSize - kSearchBarSize - kScrollBarSize);
- m_ScrollY->callback( s_CSeqGraphicWidget_ScrollCB );
- m_ScrollY->labeltype(FL_NO_LABEL);
- m_SlideZoomX = new Fl_Value_Slider
- (x + 2, y+(h - kSearchBarSize - (kSliderBarSize - 20)),
- w - 4, kSliderBarSize - 20, "Sequence Zoom Level");
- m_SlideZoomX->type(FL_HOR_NICE_SLIDER);
- m_SlideZoomX->callback( s_CSeqGraphicWidget_SliderXCB );
- m_SlideZoomX->when(m_SlideZoomX->when() | FL_WHEN_RELEASE);
- m_SlideZoomX->align(FL_ALIGN_TOP);
- //
- // search bar
- //
- Fl_Group* search = new Fl_Group(x, y+(h - kSearchBarSize),
- w, kSearchBarSize);
- search->box(FL_DOWN_FRAME);
- search->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
- {{
- Fl_Box* box =
- new Fl_Box(search->x() + Fl::box_dx(FL_DOWN_FRAME),
- search->y() + Fl::box_dy(FL_DOWN_FRAME),
- 60 - Fl::box_dx(FL_DOWN_FRAME),
- kSearchBarSize - Fl::box_dh(FL_DOWN_FRAME));
- box->label("Search:");
- }}
- m_SearchInput =
- new Fl_Input(search->x() + 60,
- search->y() + Fl::box_dy(FL_DOWN_FRAME),
- kSearchW,
- kSearchBarSize - Fl::box_dh(FL_DOWN_FRAME));
- m_SearchInput->callback( s_CSeqGraphicWidget_SearchXCB );
- m_SearchInput->when(FL_WHEN_ENTER_KEY);
-
- m_PrevButton =
- new Fl_Button(m_SearchInput->x() + m_SearchInput->w() + 4,
- search->y() + Fl::box_dy(FL_DOWN_FRAME),
- kPrevW,
- kSearchBarSize - Fl::box_dh(FL_DOWN_FRAME),
- "<");
- m_PrevButton->callback( s_CSeqGraphicWidget_PrevXCB );
- m_NextButton =
- new Fl_Button(m_PrevButton->x() + m_PrevButton->w() + 2,
- search->y() + Fl::box_dy(FL_DOWN_FRAME),
- kNextW, kSearchBarSize - Fl::box_dh(FL_DOWN_FRAME),
- ">");
- m_NextButton->callback( s_CSeqGraphicWidget_NextXCB );
-
- m_SearchChoice =
- new Fl_Choice(m_NextButton->x() + m_NextButton->w() + 4,
- search->y() + Fl::box_dy(FL_DOWN_FRAME),
- kChoiceW, kSearchBarSize - Fl::box_dh(FL_DOWN_FRAME));
- m_RangeChoice =
- new Fl_Choice(m_SearchChoice->x() + m_SearchChoice->w() + 4,
- search->y() + Fl::box_dy(FL_DOWN_FRAME),
- kRangeW, kSearchBarSize - Fl::box_dh(FL_DOWN_FRAME));
- search->resizable(m_SearchInput);
- search->end();
- // we wrap the panel in a group because FLTK will not respect the
- // widget's border type
- Fl_Group* group = new Fl_Group(x, y,
- w - kScrollBarSize, h - kScrollBarSize -
- kSliderBarSize - kSearchBarSize);
- const Fl_Boxtype panel_box = FL_THIN_DOWN_FRAME;
- group->box(panel_box);
- group->labeltype(FL_NO_LABEL);
- m_SeqGraphicPane = new CSeqGraphicPane
- (x + Fl::box_dx(panel_box), y + Fl::box_dy(panel_box),
- w - kScrollBarSize - Fl::box_dw(panel_box),
- h - kScrollBarSize - kSliderBarSize -
- kSearchBarSize - Fl::box_dh(panel_box));
- group->end();
- group->resizable(m_SeqGraphicPane);
- m_SeqGraphicPane->SetWidget(this); // For popups to work
-
- end();
- resizable(group);
-
- // Fill In Data
- m_RangeChoice->add("Molecule");
- m_RangeChoice->add("Range");
- m_RangeChoice->value(0);
- vector<string> names;
- GetFeatConfigList()->GetDescriptions(names, true);
- // m_SeqGraphicPane->GetFeatureNames(names);
- ITERATE(vector<string>, iter, names) {
- m_SearchChoice->add( (*iter).c_str() );
- }
- m_SearchChoice->value(1);
-
- m_PrevButton->deactivate();
- m_NextButton->deactivate();
- }
- CSeqGraphicWidget::~CSeqGraphicWidget()
- {
- }
- // ISelection interface
- void CSeqGraphicWidget::GetSelections(TConstScopedObjects& objs) const
- {
- CRef<CScope> scope
- (&m_SeqGraphicPane->GetDataSource()->GetBioseqHandle().GetScope());
- objs.clear();
- {{
- TConstObjects sel_objs =
- m_SeqGraphicPane->GetSelectedObjects();
- ITERATE (TConstObjects, iter, sel_objs) {
- objs.push_back(SConstScopedObject(**iter, *scope));
- }
- }}
- {{
- vector< CRef<CSeq_loc> > sel_objs = GetSelectedSeqLocs();
- ITERATE (vector< CRef<CSeq_loc> >, iter, sel_objs) {
- objs.push_back(SConstScopedObject(**iter, *scope));
- }
- }}
- }
- void CSeqGraphicWidget::SetSelections(const TConstScopedObjects& objs)
- {
- ClearSelection();
- ITERATE (TConstScopedObjects, iter, objs) {
- const CObject* obj = iter->object;
- const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>(obj);
- if (loc) {
- SelectSeqLoc(loc);
- } else if (obj) {
- SelectObject(obj);
- }
- }
- }
- void CSeqGraphicWidget::x_ScrollCB()
- {
- m_SeqGraphicPane->Scroll(TSeqPos(m_ScrollX->value()),
- TSeqPos(m_ScrollY->value()) );
- if (Fl::event() == FL_RELEASE) {
- // perform the callback to handle visible range change
- do_callback(this, (void*)0);
- }
- }
- void CSeqGraphicWidget::x_SliderCB()
- {
- m_SeqGraphicPane->SetZoomX(m_SlideZoomX->value());
- if (Fl::event() == FL_RELEASE) {
- // perform the callback to handle visible range change
- do_callback(this, (void*)0);
- }
- }
- void CSeqGraphicWidget::x_SearchCB()
- {
- CFltkCursorGuard WAIT_GUARD;
- m_SearchStr = m_SearchInput->value();
- //
- // try numeric first
- //
- try {
- list<string> toks;
- NStr::Split(m_SearchStr, ", -:", toks);
- if (toks.size() <= 2) {
- TSeqPos pos = NStr::StringToInt(toks.front());
- TSeqPos pos_end = pos + 100;
- if (toks.size() == 2) {
- pos_end = NStr::StringToInt(toks.back());
- } else if (pos >= 100) {
- pos -= 100;
- }
- m_SeqGraphicPane->ZoomOnRange(TSeqRange(pos, pos_end));
- redraw();
- }
- return;
- }
- catch (...) {
- }
- //
- // fall back to feature label search
- //
- m_SearchCount =
- m_SeqGraphicPane->SearchFeature(m_SearchStr,
- m_SearchChoice->text(),
- m_RangeChoice->value() == eVisible);
- m_PrevButton->deactivate();
- if (m_SearchCount > 1)
- m_NextButton->activate();
- else
- m_NextButton->deactivate();
-
- x_UpdateSearchMsg( 0 );
- }
- void CSeqGraphicWidget::x_PrevCB()
- {
- int pos = m_SeqGraphicPane->SearchFeaturePrev();
- m_NextButton->activate();
- if (pos > 0)
- m_PrevButton->activate();
- else
- m_PrevButton->deactivate();
-
- x_UpdateSearchMsg(pos);
- }
- void CSeqGraphicWidget::x_NextCB()
- {
- int pos = m_SeqGraphicPane->SearchFeatureNext();
- m_PrevButton->activate();
- if (pos < m_SearchCount - 1) {
- m_NextButton->activate();
- } else {
- m_NextButton->deactivate();
- }
- x_UpdateSearchMsg(pos);
- }
-
- void CSeqGraphicWidget::x_UpdateSearchMsg(int pos)
- {
- string msg = m_SearchStr + ": " + (m_SearchCount == 0 ? "Nothing found" :
- "Found: " + NStr::UIntToString(pos+1) + "/" +
- NStr::UIntToString(m_SearchCount) +
- " feature(s)");
-
- m_SearchInput->value( msg.c_str() );
- }
- void CSeqGraphicWidget::SetZoomX(float value)
- {
- m_SeqGraphicPane->SetZoomX(value);
- }
- void CSeqGraphicWidget::ZoomOnRange(const TSeqRange& range)
- {
- m_SeqGraphicPane->ZoomOnRange(range);
- }
- TSeqRange CSeqGraphicWidget::GetVisibleRange() const
- {
- return m_SeqGraphicPane->GetVisibleRange();
- }
- bool CSeqGraphicWidget::VisibleRangeChanged() const
- {
- return m_SeqGraphicPane->VisibleRangeChanged();
- }
- void CSeqGraphicWidget::ResetVisibleRangeChanged()
- {
- m_SeqGraphicPane->ResetVisibleRangeChanged();
- }
- void CSeqGraphicWidget::SetDataSource(CSeqGraphicDataSource* ds)
- {
- m_SeqGraphicPane->SetDataSource(ds);
- }
- void CSeqGraphicWidget::Print(const CPrintOptions& opts)
- {
- _TRACE("CSeqGraphicWidget::Print()");
- m_SeqGraphicPane->Print(opts);
- }
- // Set/Clear selection
- void CSeqGraphicWidget::SelectObject(const CObject* obj)
- {
- m_SeqGraphicPane->SelectObject(obj);
- }
- void CSeqGraphicWidget::SelectSeqLoc(const CSeq_loc* loc)
- {
- m_SeqGraphicPane->SelectSeqLoc(loc);
- }
- void CSeqGraphicWidget::ClearSelection()
- {
- m_SeqGraphicPane->ClearSelection();
- }
-
- // retrieve selected objects from this widget
- const TConstObjects& CSeqGraphicWidget::GetSelectedObjects(void) const
- {
- return m_SeqGraphicPane->GetSelectedObjects();
- }
- // retrieve selected seq-locs from this object
- // this is only for selections of raw sequence, not for seq-locs
- // arising from features, for example.
- vector< CRef<CSeq_loc> >
- CSeqGraphicWidget::GetSelectedSeqLocs(void) const
- {
- vector< CRef<CSeq_loc> > locs;
- const CSeqGraphicPane::TRangeColl& ranges =
- m_SeqGraphicPane->GetSelectedSeqRanges();
- ITERATE (CSeqGraphicPane::TRangeColl, iter, ranges) {
- CRef<CSeq_loc> loc(new CSeq_loc());
- loc->SetInt().SetFrom(iter->GetFrom());
- loc->SetInt().SetTo (iter->GetTo());
- loc->SetInt().SetId().Assign
- (*m_SeqGraphicPane->GetDataSource()->GetBioseqHandle().GetSeqId());
- locs.push_back(loc);
- }
- return locs;
- }
- void CSeqGraphicWidget::SetConfig(CRef<CSeqGraphicConfig> config)
- {
- m_SeqGraphicPane->SetConfig(config);
- }
- void CSeqGraphicWidget::UpdateConfig()
- {
- m_SeqGraphicPane->UpdateConfig();
- redraw();
- }
- void CSeqGraphicWidget::redraw()
- {
- m_SeqGraphicPane->redraw();
- Fl_Group::redraw();
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: seqgraphic_widget.cpp,v $
- * Revision 1000.2 2004/06/01 21:12:59 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13
- *
- * Revision 1.13 2004/05/21 22:27:55 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.12 2004/04/16 14:53:04 dicuccio
- * Pass objects using TConstObjects, not TObjSelections. Added ISelection
- * interfaces.
- *
- * Revision 1.11 2004/03/12 15:57:32 lebedev
- * Implemented CCommandTarget interface, so the widget
- * can use command maps
- *
- * Revision 1.10 2004/03/11 17:53:06 dicuccio
- * Deprecated typedefs TPosition, TDimension, TIndex, TColor. Use TSeqRange instead of TRange
- *
- * Revision 1.9 2004/02/13 18:11:32 lebedev
- * Use SeqGraphic config for enabling/disabling viewing options
- *
- * Revision 1.8 2004/02/10 13:15:34 lebedev
- * ISelHandlerHost interface implemented for selections on sequence pane
- *
- * Revision 1.7 2004/01/27 16:14:43 lebedev
- * Methods for working with selections added
- *
- * Revision 1.6 2004/01/20 20:35:31 rsmith
- * Add UpdateConfig method to notify classes when the configuration object has changed.
- *
- * Revision 1.5 2004/01/20 14:07:38 rsmith
- * use feat_config_list.hpp not feat_config.
- *
- * Revision 1.4 2004/01/14 20:31:35 rsmith
- * make feature type menu hierarchical.
- *
- * Revision 1.3 2004/01/06 20:53:05 dicuccio
- * Added CFltkCursorGuard to the search function
- *
- * Revision 1.2 2004/01/05 19:14:18 dicuccio
- * Added ability to jump to sequence location in search bar
- *
- * Revision 1.1 2003/12/22 12:59:01 lebedev
- * Files renamed
- *
- * Revision 1.27 2003/11/20 19:58:57 friedman
- * Changed the zoom slider and the horizontal scrollbar and their callbacks
- * to invoke the view callback on release only
- *
- * Revision 1.26 2003/11/19 20:37:46 friedman
- * API to detect and reset visible range change
- *
- * Revision 1.25 2003/11/18 20:35:32 rsmith
- * Perculate redraw down to lower levels. Allow config object to live at the plugin level.
- *
- * Revision 1.24 2003/11/13 17:32:51 friedman
- * Fixed compiltion error. GetVisibleRange needs a return statement
- *
- * Revision 1.23 2003/11/13 15:31:53 lebedev
- * Methods to get visible sequence range added
- *
- * Revision 1.22 2003/11/06 20:15:15 dicuccio
- * Added USING_SCOPE(objects) to implementation file
- *
- * Revision 1.21 2003/10/30 13:21:59 lebedev
- * Display of master sequence under selected CDSs and Proteins added
- *
- * Revision 1.20 2003/10/28 15:29:07 lebedev
- * Use new configuration library
- *
- * Revision 1.19 2003/10/24 13:21:53 lebedev
- * ZoomOnRange method added
- *
- * Revision 1.18 2003/10/10 17:21:22 dicuccio
- * Changed box type to thin down frame
- *
- * Revision 1.17 2003/10/09 16:27:09 lebedev
- * Widget redesign: Use independent IRenderable panels for display
- *
- * Revision 1.16 2003/08/18 16:18:33 lebedev
- * New methods to show/hide features added
- *
- * Revision 1.15 2003/08/18 13:44:42 lebedev
- * Changed SearchBar to be the same width as widget
- *
- * Revision 1.14 2003/08/15 19:37:45 dicuccio
- * Reformatting changes for the search bar
- *
- * Revision 1.13 2003/08/14 18:39:47 lebedev
- * Search of features in the widget added.
- * Display panels are fully configurable now. Use feature type and subtype
- * combination to identify and configure features in the display. Some code
- * cleanup.
- *
- * Revision 1.12 2003/07/31 17:06:47 dicuccio
- * Fixed resizable issues
- *
- * Revision 1.11 2003/07/23 19:13:41 dicuccio
- * Added API to retrieve the value of a configured parameter
- *
- * Revision 1.10 2003/07/22 13:40:22 lebedev
- * Highlign master sequence in the alignment display
- * Anchor master sequence. In Lens 10x mode show viewing range on the
- * sequence bar. Improved (faster) drawing of STSs and Repeat regions.
- *
- * Revision 1.9 2003/07/21 19:38:23 dicuccio
- * Removed commented-out code: the explicit deletes in the dtor aren't necessary
- * (Fl_Group takes care of these).
- *
- * Revision 1.8 2003/07/21 19:36:42 dicuccio
- * Externalized selections. Make sure to call the correct base class when
- * passing to the base class. Moved some initialization into intializer lists.
- *
- * Revision 1.7 2003/06/20 14:55:21 dicuccio
- * Minor clean-ups. Changed derivation of the graphical widget from Fl_Gl_Window
- * to CGlCanvas2d
- *
- * Revision 1.6 2003/06/10 12:01:58 lebedev
- * Rendering engine separated from FLTK into it's own class
- *
- * Revision 1.5 2003/06/05 11:22:32 lebedev
- * Prepare to separate display renderer from the widget itself
- *
- * Revision 1.4 2003/06/03 16:20:11 lebedev
- * FLTK calls removed from feature rendering engine. Minor clean-up.
- *
- * Revision 1.3 2003/05/23 10:56:21 lebedev
- * New rendering engine, hit test engine, many other changes
- *
- * Revision 1.2 2003/05/19 16:53:55 dicuccio
- * Better memory management. Minor rearrangement of #includes
- *
- * Revision 1.1 2003/05/16 16:46:20 lebedev
- * Initial revision
- *
- * ===========================================================================
- */