feat_config.cpp
来自「ncbi源码」· C++ 代码 · 共 345 行
CPP
345 行
/* * =========================================================================== * PRODUCTION $Log: feat_config.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 20:43:11 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * PRODUCTION * =========================================================================== *//* $Id: feat_config.cpp,v 1000.3 2004/06/01 20:43:11 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 Smith * *//// @file feat_config.cpp/// /// Utilities to configure preferences for viewing SeqFeats.#include <ncbi_pch.hpp>#include <gui/config/feat_config.hpp>BEGIN_NCBI_SCOPE/// This returns a string in response to any key if there is nothing/// for that key in the PluginConfigCache. Hence it works closely/// with LoadCurrentSettings below.// const string CFeatConfigFactoryDefaults::kNotDefined("#NOT Defined#");const string CFeatConfigFactoryDefaults::kTrueStr("true");const string CFeatConfigFactoryDefaults::kFalseStr("false");string CFeatConfigFactoryDefaults::Get(const string& key) const{ string key1, key2; NStr::SplitInTwo(key, "|", key1, key2); if (key1 == "color") { if (key2 == "Master") { return CRgbaColor::ColorStrFromName("black"); } else if (key2 == "Gene") { return CRgbaColor::ColorStrFromName("green"); } else if (key2 == "RNA Master") { return CRgbaColor::ColorStrFromName("blue"); } else if (key2 == "CDS") { return CRgbaColor::ColorStrFromName("red"); } else if (key2 == "repeat_region") { return CRgbaColor::ColorStrFromName("blue"); } } else if (key == "show|Master") { return kTrueStr; } NCBI_THROW(CConfigException, eNoDefaultValue, "key: " + key); }// definitions for CFeatConfig/// use this cstr when declaring a CFeatConfig object.CFeatConfig::CFeatConfig(objects::CPluginConfigCache* config_cache) : CSettingsSet(config_cache, "features", new CFeatConfigFactoryDefaults()), m_FeatList(*GetFeatConfigList()){ LoadCurrentSettings(eLoad_Current);}/// use this cstr when initializing a CFeatConfig object as a parent object/// in an inherited class, since it will probably need a different type/// and factory defaults. But the FactoryDefaultSettings object pass in to here/// should probably inherit from CFeatConfigFactoryDefaults.CFeatConfig::CFeatConfig(objects::CPluginConfigCache* config_cache, const string& type, const AutoPtr<IFactoryDefaultSettings>& fds) : CSettingsSet(config_cache, type, fds), m_FeatList(*GetFeatConfigList()){ LoadCurrentSettings(eLoad_Current);}bool CFeatConfig::LoadCurrentSettings(ELoadValueSource src){ /// iterate through all feature types. /// if we Get a "Not Defined" string, do not set anything for /// that value, for the feature type. /// Else set a real value and set Inherited to false. string featvaluestr; ClearColors(); ClearShows(); ITERATE ( CFeatConfig, fc_it, *this ) { int myType = fc_it->GetType(); int mySubtype = fc_it->GetSubtype(); try { featvaluestr = Get("color" + GetKeyDelimiter() + fc_it->GetStoragekey(), src); SetColor( myType, mySubtype, CGlColor(featvaluestr)); SetColorInherited( myType, mySubtype, false); } catch (const CConfigException&) { } try { featvaluestr = Get("show" + GetKeyDelimiter() + fc_it->GetStoragekey(), src); SetShow( myType, mySubtype, NStr::StringToBool(featvaluestr)); SetShowInherited( myType, mySubtype, false); } catch (const CConfigException&) { } } return true;}bool CFeatConfig::SaveCurrentSettings(void){ // iterate through all feature types. // if features color/show/etc. value is not inherited // save it as a string. // If it is inherited, or no value is defined for that feature type, // we do not save it and make sure there is not an entry with that key. ITERATE(CFeatConfigList, fc_it, m_FeatList) { int myType = fc_it->GetType(); int mySubtype = fc_it->GetSubtype(); if ( ! m_FeatColors.GetInherited(myType, mySubtype)) { Set("color" + GetKeyDelimiter() + fc_it->GetStoragekey(), GetColor(myType, mySubtype).ToString(false) ); } else { Delete("color" + GetKeyDelimiter() + fc_it->GetStoragekey()); } if ( ! m_FeatShows.GetInherited(myType, mySubtype)) { Set("show" + GetKeyDelimiter() + fc_it->GetStoragekey(), NStr::BoolToString(GetShow(myType, mySubtype)) ); } else { Delete("show" + GetKeyDelimiter() + fc_it->GetStoragekey()); } } return true;}void CFeatConfig::GetFeatureDescs(vector<string>& names) const{ names.clear(); ITERATE (CFeatConfigList, iter, m_FeatList) { names.push_back(iter->GetDescription()); }}bool CFeatConfig::GetTypeSubType(const string& desc, int& type, int& subtype) const{ CFeatConfigItem config_item; if ( m_FeatList.GetItemByDescription(desc, config_item) ) { type = config_item.GetType(); subtype = config_item.GetSubtype(); return true; } return false;}size_t CFeatConfig::size() const{ return m_FeatList.size();}CFeatConfig::const_iterator CFeatConfig::begin() const{ return m_FeatList.begin();}CFeatConfig::const_iterator CFeatConfig::end() const{ return m_FeatList.end();}bool CFeatConfig::GetShow(int type, int subtype) const{ return m_FeatShows.GetValue(type, subtype);}void CFeatConfig::SetShow(int type, int subtype, bool show){ m_FeatShows.SetValue(type, subtype, show);}void CFeatConfig::SetShowInherited(int type, int subtype, bool inherited){ m_FeatShows.SetInherited(type, subtype, inherited);}void CFeatConfig::SetShows(const CFeatConfigValues<bool>& o){ m_FeatShows = o;}const CFeatConfigValues<bool>& CFeatConfig::GetShows() const{ return m_FeatShows;}void CFeatConfig::ClearShows(){ m_FeatShows.ClearValues();}CGlColor CFeatConfig::GetColor(int type, int subtype) const{ return m_FeatColors.GetValue(type, subtype);}void CFeatConfig::SetColor(int type, int subtype, CGlColor color){ m_FeatColors.SetValue(type, subtype, color);}void CFeatConfig::SetColors(const CFeatConfigValues<CGlColor>& o){ m_FeatColors = o;}const CFeatConfigValues<CGlColor>& CFeatConfig::GetColors() const{ return m_FeatColors;}void CFeatConfig::SetColorInherited(int type, int subtype, bool inherited){ m_FeatColors.SetInherited(type, subtype, inherited);}void CFeatConfig::ClearColors(){ m_FeatColors.ClearValues();}END_NCBI_SCOPE/* * =========================================================================== * $Log: feat_config.cpp,v $ * Revision 1000.3 2004/06/01 20:43:11 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.12 * * Revision 1.12 2004/05/21 22:27:39 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.11 2004/05/20 12:27:41 dicuccio * Removed unnecessary doxygen module directives - they're in the headers * * Revision 1.10 2003/12/30 15:00:30 dicuccio * Fixed compiler warnings on MSVC * * Revision 1.9 2003/12/29 14:43:29 rsmith * Get returns string not string&. Take out stuff now in separate files. * * Revision 1.8 2003/11/21 12:49:12 rsmith * Add ability to delete values by key. * * Revision 1.7 2003/11/18 20:22:57 rsmith * Any -> Master, get/set all Show and Color values at once. * * Revision 1.6 2003/10/30 14:23:39 rsmith * Add cstr for use as a base class, and static value strings. * * Revision 1.5 2003/10/28 19:02:17 dicuccio * Changed ctor parameter for config cache from CRef<> to raw pointer * * Revision 1.4 2003/10/28 13:43:41 rsmith * Expose feature list's size(). * * Revision 1.3 2003/10/27 19:29:14 rsmith * Expose iterators on CFeatConfigItem in CFeatConfig * * Revision 1.2 2003/10/24 14:49:50 rsmith * CFeatConfig -> CFeatConfigList, CFeatConfig now contains a CFeatConfigList, * several methods added. * * Revision 1.1 2003/10/17 19:45:01 rsmith * configuration information for SeqFeats. Replaces config_items.cpp * * * Log below was from config_items.cpp which this file replaced. * * Revision 1.3 2003/10/16 16:29:58 rsmith * change implementation to use a set not a map, so that the iterators would * return CFeatConfigItem not a pair. * * Revision 1.2 2003/10/10 19:37:03 dicuccio * Reqorked static initializer to use struct constructors * * Revision 1.1 2003/10/10 17:43:42 rsmith * moved from gui/core to gui/config * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?