alnmulti_widget.cpp
来自「ncbi源码」· C++ 代码 · 共 894 行 · 第 1/2 页
CPP
894 行
/* * =========================================================================== * PRODUCTION $Log: alnmulti_widget.cpp,v $ * PRODUCTION Revision 1000.5 2004/06/01 21:07:16 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.49 * PRODUCTION * =========================================================================== *//* $Id: alnmulti_widget.cpp,v 1000.5 2004/06/01 21:07:16 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/widgets/aln_multiple/alnmulti_ds.hpp>#include <gui/widgets/aln_multiple/alnmulti_settings.hpp>#include <gui/widgets/aln_multiple/alnmulti_widget.hpp>#include <gui/types.hpp>#include <gui/objutils/utils.hpp>#include <FL/Fl.H>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);/////////////////////////////////////////////////////////////////////////////////// class CAlnMultiWidgetCAlnMultiWidget::CAlnMultiWidget(int PosX, int PosY, int Width, int Height, const char* label) : Fl_Group(PosX, PosY, Width, Height, label), m_pDataSource(NULL), m_pListener(NULL), m_pModel(NULL), m_pAlignPane(NULL), m_pScrollX(NULL), m_pScrollY(NULL), m_pPopupMenu(NULL){ end(); }void CAlnMultiWidget::Create(){ x_CreateModel(); begin(); x_CreateControls(); end(); TVPRect rcVP; rcVP.SetSize(m_pAlignPane->GetAlignVPWidth(), m_pAlignPane->GetAlignVPHeight()); x_GetAlignPort().SetViewport(rcVP); m_pModel->SetPortLimits();}CAlnMultiWidget::~CAlnMultiWidget(){}BEGIN_CMD_MAP(CAlnMultiWidget, CCommandTarget) ON_COMMAND(eCmdZoomIn, &CAlnMultiWidget::OnZoomIn) ON_COMMAND(eCmdZoomOut, &CAlnMultiWidget::OnZoomOut) ON_COMMAND(eCmdZoomAll, &CAlnMultiWidget::OnZoomAll) ON_COMMAND(eCmdZoomSel, &CAlnMultiWidget::OnZoomSelection) ON_COMMAND(eCmdZoomSeq, &CAlnMultiWidget::OnZoomSequence) ON_COMMAND(eCmdSetSelMaster, &CAlnMultiWidget::MakeSelectedRowMaster) ON_COMMAND(eCmdSetConsMaster, &CAlnMultiWidget::MakeConsensusRowMaster) ON_COMMAND(eCmdUnsetMaster, &CAlnMultiWidget::UnsetMaster) ON_COMMAND(eCmdResetSelection, &CAlnMultiWidget::OnResetSelection) ON_COMMAND(eCmdMarkSelected, &CAlnMultiWidget::OnMarkSelected) ON_COMMAND(eCmdUnMarkSelected, &CAlnMultiWidget::OnUnMarkSelected) ON_COMMAND(eCmdUnMarkAll, &CAlnMultiWidget::OnUnMarkAll) ON_COMMAND(eCmdHideSelected, &CAlnMultiWidget::OnHideSelected) ON_COMMAND(eCmdShowAll, &CAlnMultiWidget::OnShowAll) ON_COMMAND(eCmdMoveSelectedUp, &CAlnMultiWidget::OnMoveSelectedUp)END_CMD_MAP()////////////////////////////////////////////////////////////////////////////////// IAlnMultiPaneParent implementationIAlnMultiDataSource* CAlnMultiWidget::GetDataSource(){ return m_pDataSource;}const IAlnMultiDataSource* CAlnMultiWidget::GetDataSource() const{ return m_pDataSource;}void CAlnMultiWidget::SetListener(CAlnMultiWidgetListener* listener){ m_pListener = listener;}/// changes visibility state for given vector of rows to "b_visible"void CAlnMultiWidget::SetVisible(const vector<TNumrow>& rows, bool b_visible, bool b_invert_others){ m_pModel->SetVisible(rows, b_visible, b_invert_others); x_AdjustVisible(false); x_SetScrollbars(); x_RedrawControls();} void CAlnMultiWidget::Select(const vector<TNumrow>& rows, bool b_select, bool b_invert_others){ if(m_pModel) { CAlnMultiModel::TIndexVector vsel; vsel.reserve(rows.size()); for( size_t i = 0; i < rows.size(); i++ ) { CAlnMultiModel::TIndex index = m_pModel->GetLineByRowNum(rows[i]); vsel.push_back(index); } m_pModel->SLM_SelectItems(vsel, true); }}void CAlnMultiWidget::SetStyleCatalog(const CRowStyleCatalog* catalog){ m_pModel->SetStyleCatalog(catalog);}const CWidgetDisplayStyle* CAlnMultiWidget::GetDisplayStyle() const{ return m_pModel->GetDisplayStyle();} void CAlnMultiWidget::SetDataSource(IAlnMultiDataSource* p_ds){ _ASSERT(m_pModel); m_pDataSource = p_ds; m_pModel->SetDataSource(m_pDataSource); x_UpdateOnDataChanged();}CAlnMultiModel* CAlnMultiWidget::GetModel(){ return m_pModel;}const CAlnMultiModel* CAlnMultiWidget::GetModel() const{ return m_pModel;}CAlnMultiWidget::TNumrow CAlnMultiWidget::GetRowNumByLine(TLine line) const{ IAlignRow* p_row = m_pModel->GetRowByLine(line); return p_row->GetRowNum();}/// return -1 if "row" does not exist or is not visibleint CAlnMultiWidget::GetLineByRowNum(TNumrow row) const{ return m_pModel->GetLineByRowNum(row);}void CAlnMultiWidget::OnChildResize(){ x_OnResize();}void CAlnMultiWidget::OnSetScaleX(TModelUnit scale_x, const TModelPoint& point){ x_GetAlignPort().SetScaleRefPoint(scale_x, x_GetAlignPort().GetScaleY(), point); x_UpdateOnZoom();}void CAlnMultiWidget::OnZoomRect(const TModelRect& rc){ TSeqPos left = (TSeqPos) floor(rc.Left()); TSeqPos right = (TSeqPos) ceil(rc.Right()); x_ZoomToRange(left, right);}void CAlnMultiWidget::OnScroll(TModelUnit d_x, TModelUnit d_y){ x_GetAlignPort().Scroll(d_x, d_y); x_UpdateOnZoom();}void CAlnMultiWidget::OnRowChanged(IAlignRow* p_row){ x_UpdateOnRowHChanged();}void CAlnMultiWidget::OnShowPopup(){ m_pPopupMenu = new CPopupMenu(x(), y(), w(), h()); m_pPopupMenu->SetCmdTarget(static_cast<CCommandTarget*>(this)); add(m_pPopupMenu); // create menu CMenuItem* root = new CMenuItem("Root"); root->AddSubItem(new CMenuItem("Zoom In", eCmdZoomIn)); root->AddSubItem(new CMenuItem("Zoom Out", eCmdZoomOut)); root->AddSubItem(new CMenuItem("Zoom All", eCmdZoomAll)); root->AddSubItem(new CMenuItem("Zoom to Sequence", eCmdZoomSeq)); root->AddSubItem(new CMenuItem("Zoom Selection", eCmdZoomSel)); root->AddSubItem(new CMenuItem()); CMenuItem* master = new CMenuItem("Master"); root->AddSubItem(master); master->AddSubItem(new CMenuItem("Set Selected", eCmdSetSelMaster)); master->AddSubItem(new CMenuItem("Set Consensus", eCmdSetConsMaster)); master->AddSubItem(new CMenuItem("Unset", eCmdUnsetMaster)); root->AddSubItem(new CMenuItem()); root->AddSubItem(new CMenuItem("Hide Selected", eCmdHideSelected)); root->AddSubItem(new CMenuItem("Show All", eCmdShowAll)); // show menu m_pPopupMenu->SetItems(root); m_pPopupMenu->popup(); remove(m_pPopupMenu);}void CAlnMultiWidget::OnNotify(ENotification notification){ if(m_pListener) { m_pListener->OnNotify(notification); }}/// overriding base class implementationbool CAlnMultiWidget::IsRendererFocused(){ return Fl::focus() == m_pAlignPane;}// end IAlnMultiPaneParent implementation////////////////////////////////////////////////////////////////////////////////void CAlnMultiWidget::resize(int x, int y, int w, int h){ Fl_Group::resize(x, y, w, h); x_OnResize();}void CAlnMultiWidget::OnZoomIn(){ if(x_GetAlignPort().IsZoomInAvaiable()) { x_GetAlignPort().ZoomInCenter(); x_UpdateOnZoom(); }}void CAlnMultiWidget::OnZoomOut(){ if(x_GetAlignPort().IsZoomOutAvaiable()) { x_GetAlignPort().ZoomOutCenter(); x_UpdateOnZoom(); }}void CAlnMultiWidget::OnZoomSequence(){ double w = 1.5 * GetDisplayStyle()->m_SeqFont.GetMetric(CGlBitmapFont::eMetric_MaxCharWidth); x_GetAlignPort().SetScale(1 / w, x_GetAlignPort().GetScaleY()); x_UpdateOnZoom();}void CAlnMultiWidget::OnZoomAll(){ x_GetAlignPort().ZoomAll(); x_UpdateOnZoom();}void CAlnMultiWidget::OnZoomSelection(){ CRange<TSeqPos> sel_r = m_pAlignPane->GetSelectionLimits(); if(sel_r.NotEmpty()) { x_ZoomToRange(sel_r.GetFrom(), sel_r.GetTo()); } x_UpdateOnZoom();}void CAlnMultiWidget::MakeSelectedRowMaster(){ if(m_pModel->SLM_GetSelectedCount() == 1) { CAlnMultiModel::TIndexVector vIndices; m_pModel->SLM_GetSelectedIndices(vIndices); int SelIndex = vIndices[0]; // take the first selected item TNumrow iRow = GetRowNumByLine(SelIndex); x_UpdateOnSwitchMaster(iRow); }}void CAlnMultiWidget::x_ZoomToRange(TSeqPos from, TSeqPos to){ TModelRect rcV = x_GetAlignPort().GetVisibleRect(); rcV.SetLeft(from); rcV.SetRight(to + 1); x_GetAlignPort().ZoomRect(rcV); x_UpdateOnZoom();}void CAlnMultiWidget::x_MakeVisibleHorz(TSeqPos pos){ x_MakeVisibleHorz(pos, pos);}void CAlnMultiWidget::x_MakeVisibleHorz(TSeqPos from, TSeqPos to){ TModelRect rcV = x_GetAlignPort().GetVisibleRect(); TModelUnit sh_left = from - rcV.Left(); TModelUnit sh_right = to + 1 - rcV.Right(); TModelUnit sh = 0; if(sh_left < 0) { // shift left sh = sh_left; } else if(sh_right > 0) { sh = min(sh_right, sh_left); } if(sh != 0) { x_GetAlignPort().Scroll(sh, 0); x_UpdateOnZoom(); }}CGlPane& CAlnMultiWidget::x_GetAlignPort(){ _ASSERT(m_pModel); return m_pModel->GetAlignPort();}void CAlnMultiWidget::UnsetMaster(void){ x_UpdateOnSwitchMaster(-1);}void CAlnMultiWidget::MakeConsensusRowMaster(void){ int iRow = GetDataSource()->GetConsensusRow(); if(iRow > -1) { x_UpdateOnSwitchMaster(iRow); }}void CAlnMultiWidget::OnResetSelection(void){ m_pAlignPane->ResetSelection(true);}void CAlnMultiWidget::GetSelectedIds(TRSeqIdVector& ids) const{ if(GetModel() && GetDataSource()) { CAlnMultiModel::TIndexVector vindices; GetModel()->SLM_GetSelectedIndices(vindices); ITERATE(CAlnMultiModel::TIndexVector, itInd, vindices) { TNumrow row = GetRowNumByLine(*itInd); if(GetDataSource()->CanGetId(row)) { const CSeq_id& id = GetDataSource()->GetSeqId(row); ids.push_back(CConstRef<CSeq_id>(&id)); } } } else _ASSERT(false);}void CAlnMultiWidget::SetSelectedIds(const TRSeqIdVector& ids, CScope& scope){ if(GetModel() && GetDataSource()) { vector<CAlnVec::TNumrow> sel_rows; ITERATE(TRSeqIdVector, it, ids) { const CSeq_id& id = **it; //find row corresponding to id int n_rows = GetDataSource()->GetNumRows(); for( CAlnVec::TNumrow row = 0; row < n_rows; row++ ) { if((GetModel()->GetRowState(row) & IAlignRow::fItemHidden) == 0) { const CSeq_id& row_id = GetDataSource()->GetSeqId(row); if(CSeqUtils::Match(row_id, id, &scope)) { sel_rows.push_back(row); break; } } } } Select(sel_rows, true); }}const CAlnMultiWidget::TRangeColl& CAlnMultiWidget::GetSelection(void) const{ return m_pAlignPane->GetSelection();}void CAlnMultiWidget::OnMarkSelected(void){ const TRangeColl& C = m_pAlignPane->GetSelection(); m_pAlignPane->MarkSelectedRows(C, true); m_pAlignPane->redraw();}void CAlnMultiWidget::OnUnMarkSelected(){ const TRangeColl& C = m_pAlignPane->GetSelection(); m_pAlignPane->MarkSelectedRows(C, false); m_pAlignPane->redraw();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?