alnmulti_model.cpp
来自「ncbi源码」· C++ 代码 · 共 647 行 · 第 1/2 页
CPP
647 行
/* * =========================================================================== * PRODUCTION $Log: alnmulti_model.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:07:07 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * PRODUCTION * =========================================================================== *//* $Id: alnmulti_model.cpp,v 1000.1 2004/06/01 21:07:07 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_model.hpp>#include <gui/widgets/aln_multiple/alnmulti_ds.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);/////////////////////////////////////////////////////////////////////////////////// class CAlnMultiModelCAlnMultiModel::CAlnMultiModel(): m_pStyleCatalog(NULL), m_pDataSource(NULL), m_pMasterRow(NULL), m_bAutoSort(false){ double max_sym_w = 2 * m_Style.m_SeqFont.GetMetric(CGlBitmapFont::eMetric_MaxCharWidth); // setup Port m_Port.SetAdjustmentPolicy(CGlPane::fAdjustAll, CGlPane::fShiftToLimits); m_Port.SetMinScaleX(1 / max_sym_w); m_Port.SetOriginType(CGlPane::eOriginLeft, CGlPane::eOriginTop); SetPortLimits();}CAlnMultiModel::~CAlnMultiModel(){ ClearRows();}////////////////////////////////////////////////////////////////////////////////// IAlnMultiPaneParent implementationvoid CAlnMultiModel::SetStyleCatalog(const CRowStyleCatalog* catalog){ m_pStyleCatalog = catalog;}const CWidgetDisplayStyle* CAlnMultiModel::GetDisplayStyle() const{ return &m_Style;}int CAlnMultiModel::GetRowState(TNumrow row) const{ return x_GetRecordByRow(row).m_State;}bool CAlnMultiModel::SRowRecord::PRecLineLess(const SRowRecord* rec1, const SRowRecord* rec2){ return rec1->m_Line < rec2->m_Line;}/// changes visibility state for given vector of rows to "b_visible"void CAlnMultiModel::SetVisible(const vector<TNumrow>& rows, bool b_visible, bool b_invert_others){ size_t n_rows = rows.size(); if(n_rows || b_invert_others) { vector<TNumrow> v_items; TNumrow master_row = m_pDataSource->GetAnchor(); if(b_invert_others) { // all rows in alignment are affected // by default set state for all rows to "! b_visible" vector<bool> new_visible(m_RowToRec.size(), ! b_visible); ITERATE(vector<TNumrow>, it, rows) { new_visible[*it] = b_visible; } vector<SRowRecord*> vis_recs; vis_recs.reserve(b_visible ? rows.size() : new_visible.size() - rows.size()); for( TNumrow row = 0; row < (TNumrow) new_visible.size(); row++ ) { // for all rows if(row != master_row && new_visible[row]) { SRowRecord& rec = x_GetRecordByRow(row); vis_recs.push_back(&rec); } } // sort records by line number sort(vis_recs.begin(), vis_recs.end(), SRowRecord::PRecLineLess); // copy row numbers to v_items v_items.reserve(vis_recs.size()); ITERATE(vector<SRowRecord*>, it, vis_recs) { IAlignRow* p_row = (*it)->m_pRow; v_items.push_back(p_row->GetRowNum()); } TNumrowModelImpl::SetItems(v_items, false, true); } else { // only "rows" will be affected v_items.reserve(n_rows); vector<TLine> v_indices; v_indices.reserve(n_rows); ITERATE(vector<TNumrow>, it, rows) { TNumrow row = *it; SRowRecord& rec = x_GetRecordByRow(row); bool b_old_vis = rec.IsVisible(); if(b_old_vis != b_visible && row != master_row) { // state needs to be changed TLine line = rec.m_Line; // clip line, it can be invalid line = min(line, (TLine) m_vVisibleRows.size()); v_indices.push_back(line); if(b_visible) { v_items.push_back(row); } } } if(b_visible) { TNumrowModelImpl::InsertItems(v_items, v_indices, false); } else { TNumrowModelImpl::DeleteItems(v_indices, false); } } if(m_bAutoSort) { x_DoUpdateRowsOrder(); // applying sorting x_DoUpdateRowPositions(); } SetPortLimits(); }}CGlPane& CAlnMultiModel::GetAlignPort(){ return m_Port;}const CGlPane& CAlnMultiModel::GetAlignPort() const{ return m_Port;}CAlnMultiModel::TNumrow CAlnMultiModel::GetLinesCount(){ return m_vVisibleRows.size();}int CAlnMultiModel::GetFocusedItemIndex() const{ return SLM_GetFocusedItemIndex();}bool CAlnMultiModel::IsItemSelected(int index) const{ return SLM_IsItemSelected(index);}IAlignRow* CAlnMultiModel::GetRowByLine(int i_line){ return x_GetRowByLine(i_line);}int CAlnMultiModel::GetLineByRowNum(TNumrow row) const{ const CAlnMultiModel::SRowRecord& rec = x_GetRecordByRow(row); return rec.IsVisible() ? rec.m_Line : -1;}IAlignRow* CAlnMultiModel::GetMasterRow(){ return m_pMasterRow;}int CAlnMultiModel::GetLineByModelY(int Y) const{ const TModelRect& rcL = m_Port.GetModelLimitsRect(); if(Y < rcL.Top() || Y > rcL.Bottom()) return -1; else { vector<int>::const_iterator it = lower_bound(m_vVisibleRowPos.begin(), m_vVisibleRowPos.end(), Y); return it - m_vVisibleRowPos.begin() - 1; }}int CAlnMultiModel::GetLinePosY(int index) const{ return m_vVisibleRowPos[index];}int CAlnMultiModel::GetLineHeight(TLine line) const{ return x_GetRowByLine(line)->GetHeightPixels();} bool CAlnMultiModel::IsRendererFocused(){ return true;}void CAlnMultiModel::ShowAll(){ vector<TNumrow> nothing; SetVisible(nothing, false, true); // hide nothing and make other visible}void CAlnMultiModel::EnableAutoSorting(bool b_en){ m_bAutoSort = b_en;}void CAlnMultiModel::UpdateSortOrder(void){ m_bAutoSort = true; x_DoUpdateRowsOrder(); x_DoUpdateRowPositions(); }/// order can be changed only for visible rows, hidden will be ignoredvoid CAlnMultiModel::SetRowOrder(const vector<TNumrow>& rows, int pos){ m_bAutoSort = false; // cancel auto sorting int n_vis = m_vVisibleRows.size(); if(pos >= 0 && pos < n_vis) { vector<SRowRecord*> new_vis(n_vis, (SRowRecord*)NULL); // new container to replace m_vVisibleRows // move specified rows to new_order and replace them with NULL in m_vVisibleRows int i = 0, line = pos; for( ; i < (int) rows.size() && line < n_vis; i++ ) { TNumrow row = rows[i]; SRowRecord* p_rec = &x_GetRecordByRow(row); if(p_rec->IsVisible()) { new_vis[line] = p_rec; m_vVisibleRows[p_rec->m_Line] = NULL; // remove from m_vVisibleRows line++; } } // move the rest of the rows (those that are not NULL) preserving existing order // move first "pos" elements and insert them before "pos" position i = 0; // current postion in m_vVisibleRow int ins_i = 0; // insertion position in new_vis while(ins_i < pos) { for( ; m_vVisibleRows[i] == NULL && i < n_vis; i++ ) { // skip } _ASSERT(i < n_vis); new_vis[ins_i++] = m_vVisibleRows[i++]; } // copy the rest of rows to new_vis after "line" ins_i = line; while(ins_i < n_vis) { for( ; m_vVisibleRows[i] == NULL && i < n_vis; i++ ) { // skip } _ASSERT(i < n_vis); new_vis[ins_i++] = m_vVisibleRows[i++]; } // assign new_vis to m_vVisibleRows m_vVisibleRows = new_vis; x_DoUpdateRowLines(); x_DoUpdateRowPositions(); }}void CAlnMultiModel::SetDataSource(IAlnMultiDataSource* p_ds){ m_pDataSource = p_ds; x_UpdateOnDataChanged(); // before it called Widget's version of function}/////////////////////////////////////////////////////////////////////////////////// Update handlersvoid CAlnMultiModel::ClearRows(){ TNumrowModelImpl::DeleteAllItems(); NON_CONST_ITERATE(TRowToRecMap, it, m_RowToRec) { delete (*it)->m_pRow;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?