hit_matrix_widget.cpp
来自「ncbi源码」· C++ 代码 · 共 453 行
CPP
453 行
/* * =========================================================================== * PRODUCTION $Log: hit_matrix_widget.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 21:11:02 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * PRODUCTION * =========================================================================== *//* $Id: hit_matrix_widget.cpp,v 1000.3 2004/06/01 21:11:02 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: Andrey Yazhuk * * File Description: * */#include <ncbi_pch.hpp>#include <gui/opengl/glfont.hpp>#include <gui/graph/igraph_utils.hpp>#include <gui/widgets/fl/menu.hpp>#include <gui/types.hpp>#include <objmgr/util/sequence.hpp>#include <gui/widgets/hit_matrix/hit_matrix_widget.hpp>#include <gui/widgets/hit_matrix/choose_seq_dlg.hpp>#include <gui/widgets/hit_matrix/score_dlg.hpp>#include <list>#include <FL/Fl.H>BEGIN_NCBI_SCOPEUSING_SCOPE(ncbi::objects);/////////////////////////////////////////////////////////////////////////////////// class CHitMatrixWidgetCHitMatrixWidget::CHitMatrixWidget(int PosX, int PosY, int Width, int Height, const char* label): CGlPaneWidget(PosX, PosY, Width, Height, label), m_pDataSource(NULL), m_pMatrixPane(NULL), m_ScoreIndex(-1){ // setup Port m_Port.SetAdjustmentPolicy(CGlPane::fAdjustAll, CGlPane::fAdjustAll); m_Port.SetMinScaleX(1 / 30.0); m_Port.SetOriginType(CGlPane::eOriginLeft, CGlPane::eOriginBottom); m_Port.EnableZoom(true, true);}CHitMatrixWidget::~CHitMatrixWidget(){}BEGIN_CMD_MAP(CHitMatrixWidget, CGlPaneWidget) ON_COMMAND(eCmdZoomSel, &CHitMatrixWidget::OnZoomSelection) ON_COMMAND(eCmdZoomSelObjects, &CHitMatrixWidget::OnZoomToSelectedHitElems) ON_COMMAND(eCmdSetEqualScale, &CHitMatrixWidget::OnSetEqualScale) ON_COMMAND(eCmdZoomObjects, &CHitMatrixWidget::OnZoomToHits) ON_COMMAND(eCmdChooseSeq, &CHitMatrixWidget::OnChooseSeq) ON_COMMAND(eCmdColorByScore, &CHitMatrixWidget::OnColorByScore)END_CMD_MAP()void CHitMatrixWidget::x_CreatePane(){ m_pMatrixPane = new CHitMatrixPane(0, 0, 0, 0); m_pMatrixPane->SetWidget(this);}CGlPaneWidgetChild* CHitMatrixWidget::x_GetPane(){ return static_cast<CGlPaneWidgetChild*>(m_pMatrixPane);}void CHitMatrixWidget::x_SetPortLimits(){ CHitMatrixDataSource* pDS = GetDS(); if(pDS) { TSeqPos q_len = pDS->GetQueryHandle().GetBioseqLength(); TSeqPos s_len = pDS->GetSubjectHandle().GetBioseqLength(); m_Port.SetModelLimitsRect(TModelRect(0,0, s_len, q_len)); } else { m_Port.SetModelLimitsRect(TModelRect(0,0, 1000, 1000)); }}void CHitMatrixWidget::SetDataSource(CHitMatrixDataSource* p_ds){ m_pDataSource = p_ds; x_Update(); }CHitMatrixDataSource* CHitMatrixWidget::GetDS(void){ return m_pDataSource;}const CGlPane& CHitMatrixWidget::GetPort(void) const{ return x_GetPort();}void CHitMatrixWidget::OnZoomToHits(void){ if(m_pDataSource) { x_ZoomToHits(); x_UpdateOnZoom(); }}void CHitMatrixWidget::OnZoomSelection(void){ if(m_pDataSource) { const CHitMatrixPane::TRangeColl& horz_sel = m_pMatrixPane->GetSubjectSelection(); const CHitMatrixPane::TRangeColl& vert_sel = m_pMatrixPane->GetQuerySelection(); TModelRect rc_m = m_Port.GetVisibleRect(); if(horz_sel.size()) { rc_m.SetHorz(horz_sel.GetFrom(), horz_sel.GetToOpen()); } if(vert_sel.size()) { rc_m.SetVert(vert_sel.GetFrom(), vert_sel.GetToOpen()); } m_Port.ZoomRect(rc_m); x_UpdateOnZoom(); }}void CHitMatrixWidget::OnZoomToSelectedHitElems(void){ TModelRect rc_m = m_pMatrixPane->GetSelectedHitElemsRect(); if(! rc_m.IsEmpty()) { m_Port.ZoomRect(rc_m); x_UpdateOnZoom(); }}void CHitMatrixWidget::x_ZoomToHits(void){ if(m_pDataSource) { TModelRect rc_m; TSeqRange s_r = m_pDataSource->GetSubjectHitsRange(); rc_m.SetHorz(s_r.GetFrom(), s_r.GetToOpen()); TSeqRange q_r = m_pDataSource->GetQueryHitsRange(); rc_m.SetVert(q_r.GetFrom(), q_r.GetToOpen()); m_Port.ZoomRect(rc_m); }}void CHitMatrixWidget::OnSetEqualScale(void){ TModelUnit scale = min(m_Port.GetScaleX(), m_Port.GetScaleY()); m_Port.SetScale(scale, scale); x_UpdateOnZoom();}void CHitMatrixWidget::OnChooseSeq(){ if(m_pDataSource && m_pMatrixPane) { // get current settings CScope& scope = m_pDataSource->GetScope(); CConstRef<CSeq_id> query_id = m_pDataSource->GetQueryId(); CConstRef<CSeq_id> subject_id = m_pDataSource->GetSubjectId(); // create a list of string representing sequences available in Data Source vector<string> v_descrs; const vector<CConstRef<CSeq_id> > v_ids = m_pDataSource->GetSeqIDs(); int i_q = -1, i_s = -1; for( size_t i = 0; i < v_ids.size(); i++ ) { CConstRef<CSeq_id> id = v_ids[i]; if(id->Match(*query_id)) { i_q = i; } if(id->Match(*subject_id)) { i_s = i; } CBioseq_Handle handle = scope.GetBioseqHandle(*id); const CSeq_id& best_id = sequence::GetId(handle, sequence::eGetId_Best); string s; best_id.GetLabel(&s); v_descrs.push_back(s); } // create and show Dialog CChooseSeqDlg dlg; dlg.SetTitle("Choose Sequences to Display..."); dlg.SetSeqs(v_descrs, i_q, i_s); dlg.CenterOnActive(); if(dlg.ShowModal() == eOK) { int new_i_q = dlg.GetQueryIndex(); int new_i_s = dlg.GetSubjectIndex(); if(new_i_q != i_q || new_i_s != i_s) { // if things did change query_id = v_ids[new_i_q]; subject_id = v_ids[new_i_s]; m_pDataSource->SelectIds(query_id, subject_id); x_Update(); //### needs to be incremental } } }}void CHitMatrixWidget::OnColorByScore(){ if(m_pDataSource && m_pMatrixPane) { CConstRef<CObject_id> curr_sc_id = m_pMatrixPane->GetScoreId(); int i_curr_sc = -1; // index of the currently used score // fill the list with all available scores int scores_n = m_pDataSource->GetScoresCount(); vector<string> items; for( int i = 0; i < scores_n; i++ ) { const CObject_id& id = m_pDataSource->GetScoreId(i); if(curr_sc_id.NotEmpty() && curr_sc_id->Match(id)) { i_curr_sc = i; // this one is current } items.push_back(id.GetStr()); } // create and show the Dialog CScoreDlg dlg; dlg.SetTitle("Color by Score..."); dlg.SetItems(items, i_curr_sc); dlg.CenterOnActive(); if(dlg.ShowModal() == eOK) { int score_index = dlg.GetSelectedIndex(); if(score_index != i_curr_sc) { // things did change - update pane _ASSERT(m_pMatrixPane); CConstRef<CObject_id> id(&m_pDataSource->GetScoreId(score_index)); m_pMatrixPane->ColorByScore(id); x_RedrawControls(); //### } } }}staticDEFINE_MENU(PopupMenu) MENU_ITEM(eCmdZoomIn, "Zoom In") MENU_ITEM(eCmdZoomOut, "Zoom Out") MENU_ITEM(eCmdZoomAll, "Zoom All") MENU_ITEM(eCmdZoomObjects, "Zoom to Hits") MENU_SEPARATOR() MENU_ITEM(eCmdZoomSel, "Zoom to Selection") MENU_ITEM(eCmdZoomSelObjects, "Zoom to Selected Hits") MENU_ITEM(eCmdSetEqualScale, "Make Proportional")END_MENU()void CHitMatrixWidget::OnShowPopup(){ CPopupMenu menu(x(), y(), w(), h()); menu.SetCmdTarget(static_cast<CCommandTarget*>(this)); add(&menu); menu.SetItems(PopupMenu); menu.popup(); remove(&menu);}CConstRef<CSeq_align_set> CHitMatrixWidget::GetSelectedHits() const{ _ASSERT(m_pMatrixPane); return m_pMatrixPane->GetSelectedHits();}CRef<CSeq_loc> CHitMatrixWidget::GetSubjectSelection() const{ const CHitMatrixPane::TRangeColl& cl_sel = m_pMatrixPane->GetSubjectSelection(); CRef<CSeq_loc> seq_loc(new CSeq_loc()); CSeq_loc::TPacked_int& p_int = seq_loc->SetPacked_int(); CConstRef<CSeq_id> seq_id = m_pDataSource->GetSubjectId(); ITERATE(CHitMatrixPane::TRangeColl, it_r, cl_sel) { // for each range in mark p_int.AddInterval(*seq_id, it_r->GetFrom(), it_r->GetTo()); } return seq_loc;}CRef<CSeq_loc> CHitMatrixWidget::GetQuerySelection() const{ const CHitMatrixPane::TRangeColl& cl_sel = m_pMatrixPane->GetQuerySelection(); CRef<CSeq_loc> seq_loc(new CSeq_loc()); CSeq_loc::TPacked_int& p_int = seq_loc->SetPacked_int(); CConstRef<CSeq_id> seq_id = m_pDataSource->GetQueryId(); ITERATE(CHitMatrixPane::TRangeColl, it_r, cl_sel) { // for each range in mark p_int.AddInterval(*seq_id, it_r->GetFrom(), it_r->GetTo()); } return seq_loc;}void CHitMatrixWidget::x_Update(){ x_SetPortLimits(); if(m_pDataSource) { x_ZoomToHits(); } else { m_Port.ZoomAll(); } x_UpdatePane(); x_UpdateScrollbars(); x_RedrawControls();}void CHitMatrixWidget::x_UpdatePane(){ m_pMatrixPane->Update();}void CHitMatrixWidget::OnSetScaleX(TModelUnit scale_x, const TModelPoint& point){ m_Port.SetScaleRefPoint(scale_x, m_Port.GetScaleY(), point); x_UpdateOnZoom();}void CHitMatrixWidget::x_UpdateScrollbars(){ TModelRect rcAll = m_Port.GetModelLimitsRect(); TModelRect rcVisible = m_Port.GetVisibleRect(); if (m_Port.NeedsScrollX()) { m_pScrollX->value((int) rcVisible.Left(), (int) rcVisible.Width(), (int) rcAll.Left(), (int) rcAll.Width()); } else { m_pScrollX->value(0, 0, 0, 0); } if (m_Port.NeedsScrollY()) { m_pScrollY->value((int) (rcAll.Top() - rcVisible.Top()), (int) rcVisible.Height(), (int) rcAll.Bottom(), (int) rcAll.Height()); } else { m_pScrollY->value(0, 0, 0, 0); }}void CHitMatrixWidget::x_OnScrollX(){ int V = m_pScrollX->value(); double dX = V - m_Port.GetVisibleRect().Left(); m_Port.Scroll(dX, 0); x_RedrawControls(); //###}void CHitMatrixWidget::x_OnScrollY(){ int V = m_pScrollY->value(); TModelRect rcAll = m_Port.GetModelLimitsRect(); double dY = rcAll.Top() - V - m_Port.GetVisibleRect().Top(); m_Port.Scroll(0, dY); x_RedrawControls();}END_NCBI_SCOPE/* * =========================================================================== * $Log: hit_matrix_widget.cpp,v $ * Revision 1000.3 2004/06/01 21:11:02 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * * Revision 1.11 2004/05/21 22:27:54 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.10 2004/05/03 15:10:05 gorelenk * Changed GetObject to dereferencing operator . * * Revision 1.9 2004/03/05 17:40:06 dicuccio * Use sequence::GetId() instead of CSeq-id::GetStringDescr() * * Revision 1.8 2004/02/12 21:07:01 yazhuk * Implemented OnShowPopup(), new Zoom functions; * * Revision 1.7 2004/01/08 19:48:05 yazhuk * Minor clean-up * * Revision 1.6 2003/12/10 16:58:06 yazhuk * Updated implementation of IMouseZoomHandlerHost interface. * Fixed scrollbars setup. Added dialogs centering. * * Revision 1.5 2003/12/05 17:46:40 yazhuk * Implemented support for "Choose sequences.." and "Color by.." commands, * added functions for retrieving selections. * * Revision 1.4 2003/12/01 17:04:25 yazhuk * Eliminated IHitMatrixParent inheritance, updated code dealing with data * source. * * Revision 1.3 2003/11/20 20:00:45 yazhuk * Changed ON_COMMAND() invocation to make GCC happy * * Revision 1.2 2003/11/18 00:05:59 yazhuk * GCC compilation fixes * * Revision 1.1 2003/11/17 20:41:18 yazhuk * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?