layout_chooser.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: layout_chooser.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:43:20 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: layout_chooser.cpp,v 1000.1 2004/06/01 20:43:20 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: Robert G. Smith
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/config/layout_chooser.hpp>
- #include <gui/objutils/layout.hpp>
- #include <gui/objutils/feature.hpp>
- #include <gui/objutils/alignment.hpp>
- #include <gui/objutils/graph.hpp>
- #include <gui/config/feat_config.hpp>
- BEGIN_NCBI_SCOPE
- //
- // CLayoutObjectChooser
- //
- CLayoutObjectChooser::~CLayoutObjectChooser()
- {
- }
- bool CLayoutObjectChooser::CanMatchFeats() const
- {
- return false;
- }
- bool CLayoutObjectChooser::CanMatchAlignments() const
- {
- return false;
- }
- bool CLayoutObjectChooser::CanMatchGraphs() const
- {
- return false;
- }
- CLayoutObjectChooser* CLayoutObjectChooser::FromString(const string& s)
- {
- string classkey, data;
- NStr::SplitInTwo(s, ":", classkey, data);
- if (classkey == CLayoutFeatChooser::GetClassKey()) {
- return new CLayoutFeatChooser;
- } else if (classkey == CLayoutAlignChooser::GetClassKey()) {
- return new CLayoutAlignChooser;
- } else if (classkey == CLayoutGraphChooser::GetClassKey()) {
- return new CLayoutGraphChooser;
- } else if (classkey == CLayoutFeatTypeChooser::GetClassKey()) {
- return new CLayoutFeatTypeChooser(data);
- } else if (classkey == CLayoutFeatTypeListChooser::GetClassKey()) {
- return new CLayoutFeatTypeListChooser(data);
- }
- NCBI_THROW2(CStringException, eConvert, "String is not a CLayoutObjectChooser class: [" + s + "]", 0);
- return NULL;
- }
- //
- // CLayoutFeatChooser
- //
- bool CLayoutFeatChooser::Matches(const CLayoutObject* obj) const
- {
- const CLayoutFeat* feat = dynamic_cast<const CLayoutFeat*> (obj);
- if (feat == NULL) {
- return false;
- }
-
- return MatchFeat(*feat);
- }
- bool CLayoutFeatChooser::CanMatchFeats() const
- {
- return true;
- }
- bool CLayoutFeatChooser::MatchFeat(const CLayoutFeat& feat) const
- {
- return true;
- }
- string CLayoutFeatChooser::ToString() const
- {
- return GetClassKey();
- }
- string CLayoutFeatChooser::GetClassKey()
- {
- return "All Features";
- }
- //
- // CLayoutAlignChooser
- //
- bool CLayoutAlignChooser::Matches(const CLayoutObject* obj) const
- {
- const CLayoutAlign* align = dynamic_cast<const CLayoutAlign*> (obj);
- return align != NULL;
- }
- bool CLayoutAlignChooser::CanMatchAlignments() const
- {
- return true;
- }
- string CLayoutAlignChooser::ToString() const
- {
- return GetClassKey();
- }
- string CLayoutAlignChooser::GetClassKey()
- {
- return "Alignments";
- }
- //
- // CLayoutGraphChooser
- //
- bool CLayoutGraphChooser::Matches(const CLayoutObject* obj) const
- {
- const CLayoutGraph* graph = dynamic_cast<const CLayoutGraph*> (obj);
- return graph != NULL;
- }
- bool CLayoutGraphChooser::CanMatchGraphs() const
- {
- return true;
- }
- string CLayoutGraphChooser::ToString() const
- {
- return GetClassKey();
- }
- string CLayoutGraphChooser::GetClassKey()
- {
- return "Graphs";
- }
- //
- // CLayoutFeatTypeChooser
- //
- CLayoutFeatTypeChooser::CLayoutFeatTypeChooser() :
- m_MatchingType(objects::CSeqFeatData::e_not_set),
- m_MatchingSubtype(objects::CSeqFeatData::eSubtype_any)
- {
- }
- CLayoutFeatTypeChooser::CLayoutFeatTypeChooser(int type, int subtype) :
- m_MatchingType(type),
- m_MatchingSubtype(subtype)
- {}
- CLayoutFeatTypeChooser::CLayoutFeatTypeChooser(const string& data)
- {
- const CFeatConfigList& feat_types = *GetFeatConfigList();
- CFeatConfigItem feat_info;
- if (feat_types.GetItemByKey(data, feat_info)) {
- SetMatchingType(feat_info.GetType());
- SetMatchingSubtype(feat_info.GetSubtype());
- } else {
- NCBI_THROW2(CStringException, eConvert, "String is not a feature type: [" + data + "]", 0);
- }
- }
- bool CLayoutFeatTypeChooser::MatchFeat(const CLayoutFeat& feat) const
- {
- if (m_MatchingType == objects::CSeqFeatData::e_not_set) {
- return true;
- }
-
- const objects::CSeqFeatData& data = feat.GetFeature().GetData();
-
- if (m_MatchingType == data.Which()) {
- if (m_MatchingSubtype == objects::CSeqFeatData::eSubtype_any ||
- m_MatchingSubtype == data.GetSubtype()) {
- return true;
- }
- }
- return false;
- }
- int CLayoutFeatTypeChooser::GetMatchingType() const
- {
- return m_MatchingType;
- }
- int CLayoutFeatTypeChooser::GetMatchingSubtype() const
- {
- return m_MatchingSubtype;
- }
- void CLayoutFeatTypeChooser::SetMatchingType(int type)
- {
- m_MatchingType = type;
- }
- void CLayoutFeatTypeChooser::SetMatchingSubtype(int subtype)
- {
- m_MatchingSubtype = subtype;
- }
- string CLayoutFeatTypeChooser::ToString() const
- {
- return GetClassKey() + ":" +
- GetFeatConfigList()->GetStoragekey(m_MatchingType, m_MatchingSubtype);
- }
- string CLayoutFeatTypeChooser::GetClassKey()
- {
- return "Feature";
- }
- //
- // CLayoutFeatTypeListChooser
- //
- CLayoutFeatTypeListChooser::CLayoutFeatTypeListChooser()
- {
- }
- CLayoutFeatTypeListChooser::CLayoutFeatTypeListChooser(const string& data)
- {
- list<string> dataKeys;
- NStr::Split(data, ":", dataKeys);
- ITERATE(list<string>, key_it, dataKeys) {
- m_MatchTypes.push_back(CLayoutFeatTypeChooser(*key_it));
- }
- }
- CLayoutFeatTypeListChooser::CLayoutFeatTypeListChooser(const vector<CLayoutFeatTypeChooser>& types) :
- m_MatchTypes(types)
- {
- }
- bool CLayoutFeatTypeListChooser::MatchFeat(const CLayoutFeat& feat) const
- {
- ITERATE(vector<CLayoutFeatTypeChooser>, chooser_it, m_MatchTypes) {
- if (chooser_it->MatchFeat(feat)) {
- return true;
- }
- }
- return false;
- }
- void CLayoutFeatTypeListChooser::AddTypeSubtype(int type, int subtype)
- {
- m_MatchTypes.push_back(CLayoutFeatTypeChooser(type, subtype));
- }
- string CLayoutFeatTypeListChooser::ToString() const
- {
- const CFeatConfigList& feat_types = *GetFeatConfigList();
- string myStr = GetClassKey() + ":";
- ITERATE(vector<CLayoutFeatTypeChooser>, typeChooser_it, m_MatchTypes) {
- string feat_key = feat_types.GetStoragekey(typeChooser_it->GetMatchingType(),
- typeChooser_it->GetMatchingSubtype());
- myStr += feat_key + ";";
- }
- return myStr;
- }
- string CLayoutFeatTypeListChooser::GetClassKey()
- {
- return "FeatureList";
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: layout_chooser.cpp,v $
- * Revision 1000.1 2004/06/01 20:43:20 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:40 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2004/05/03 12:47:44 dicuccio
- * gui/utils ->gui/objutils where needed
- *
- * Revision 1.1 2003/12/30 15:01:57 dicuccio
- * Moved all FLTK code into gui/dialogs/config. Moved layout_chooser from
- * gui/utils to avoid circular dependency
- *
- * Revision 1.2 2003/12/29 19:26:29 rsmith
- * Add serialization (ToString, from string) to Layout Chooser classes.
- *
- * Revision 1.1 2003/11/26 21:14:51 rsmith
- * Initial checkin
- *
- *
- * ===========================================================================
- */