📄 layout.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: layout.cpp,v $ * PRODUCTION Revision 1000.0 2004/06/01 21:20:51 gouriano * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2 * PRODUCTION * =========================================================================== *//* $Id: layout.cpp,v 1000.0 2004/06/01 21:20:51 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: Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include <gui/objutils/layout.hpp>BEGIN_NCBI_SCOPE////// CLayoutObject////// virtual dtor for our layout objectsCLayoutObject::~CLayoutObject(){}//////// CLayout//////// clear opur internal list of objectsvoid CLayout::Clear(void){ m_Layout.clear();}// access the entire layoutconst CLayout::TLayout& CLayout::GetLayout(void) const{ return m_Layout;}CLayout::TLayout& CLayout::SetLayout(void){ return m_Layout;}// access a row of the layoutconst CLayout::TLayoutRow& CLayout::GetRow(size_t row) const{ _ASSERT(row < m_Layout.size()); return m_Layout[row];}CLayout::TLayoutRow& CLayout::SetRow(size_t row){ _ASSERT(row < m_Layout.size()); return m_Layout[row];}// add a new row to the layoutCLayout::TLayoutRow& CLayout::AddRow(void){ return AddRow(TLayoutRow());}// add a new row to the layoutCLayout::TLayoutRow& CLayout::AddRow(const TLayoutRow& row){ m_Layout.push_back(row); return m_Layout.back();}void CLayout::Append(const CLayout& layout){ ITERATE (TLayout, row_iter, layout.GetLayout()) { m_Layout.push_back(*row_iter); }}//////// C2DLayoutEngine//////// perform 2D layout// this arranges a set of layout objects into a non-overlapping series of rowsvoid C2DLayoutEngine::Layout(const TObjects& objects, CLayout& layout){ // clear our layout to start layout.Clear(); // for each member in the incoming list... ITERATE (TObjects, iter, objects) { const TSeqRange& new_range = (*iter)->GetLocation().GetTotalRange(); TSignedSeqPos start = 0; TSignedSeqPos end = 0; if (new_range.GetFrom() < new_range.GetTo()) { start = new_range.GetFrom() - m_MinDist; end = new_range.GetTo() + m_MinDist; } else { start = new_range.GetTo() - m_MinDist; end = new_range.GetFrom() + m_MinDist; } // scan the current layout bool inserted = false; NON_CONST_ITERATE (CLayout::TLayout, row_iter, layout.SetLayout()) { // ... and try to insert at the end // since we're sorted by position, we only need to check the end const CLayoutObject& last_obj = *row_iter->back(); const TSeqRange& last_range = last_obj.GetLocation().GetTotalRange(); if (last_range.GetFrom() < last_range.GetTo()) { if (TSignedSeqPos(last_range.GetTo()) <= start) { row_iter->push_back(*iter); inserted = true; break; } } else { if (TSignedSeqPos(last_range.GetFrom()) <= start) { row_iter->push_back(*iter); inserted = true; break; } } } // insert our interval info as we need if ( !inserted ) { // begin an entirely new row CLayout::TLayoutRow& row = layout.AddRow(); row.push_back(*iter); } }#if 0 { int i; int j; _TRACE("\n" << features.size() << " items, spacing = " << spacing); for (i = 0; i < features.size(); ++i) { _TRACE(i + 1 << ": " << features[i]->GetTextId() << ": {" << features[i]->GetExtent().GetFrom() << " - " << features[i]->GetExtent().GetTo() << "}"); } for (i = 0; i < pack.size(); ++i) { _TRACE(i + 1 << ":"); for (j = 0; j < pack[i].size(); ++j) { dumpRecursive(*pack[i][j]); } cerr << endl; } cerr << endl; }#endif}END_NCBI_SCOPE/* * =========================================================================== * $Log: layout.cpp,v $ * Revision 1000.0 2004/06/01 21:20:51 gouriano * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2 * * Revision 1.2 2004/05/21 22:27:44 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.1 2004/04/30 11:48:16 dicuccio * Initial commit - split out from src/gui/utils * * Revision 1.3 2004/03/11 17:49:40 dicuccio * Use TSeqRange instead of TRange * * Revision 1.2 2003/07/21 19:35:21 dicuccio * Changed storage mechanism - CLayoutObject::GetObject() is now pure virtual. * Changed CFeature to wrap a CMappedFeat instead of a CSeq_feat / CSeq_loc pair * * Revision 1.1 2003/06/09 19:32:24 dicuccio * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -