seqgraphic_widget.cpp
来自「ncbi源码」· C++ 代码 · 共 687 行 · 第 1/2 页
CPP
687 行
/* * =========================================================================== * 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_SCOPEUSING_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();}staticDEFINE_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 interfacevoid 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()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?