featgroup_config_dlg.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: featgroup_config_dlg.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:15:13 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id $
- * ===========================================================================
- *
- * 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 Description:
- * Test application for plugins
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbiapp.hpp>
- #include <corelib/ncbiargs.hpp>
- #include <corelib/ncbienv.hpp>
- #include <corelib/ncbireg.hpp>
- #include <serial/serial.hpp>
- #include <serial/objostr.hpp>
- #include <serial/objistr.hpp>
- #include <corelib/ncbifile.hpp>
- #include <gui/config/PluginConfigCache.hpp>
- #include <gui/dialogs/config/config_dlg.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_conf.hpp>
- #include "featgroup_config_mediat.hpp"
- #include "featgroup_config_panel.hpp"
- USING_NCBI_SCOPE;
- USING_SCOPE(objects);
- //
- // a test exception class
- //
- class CPluginTestException : EXCEPTION_VIRTUAL_BASE public CException
- {
- public:
- // Enumerated list of document management errors
- enum EErrCode {
- eTestFailed
- };
- // Translate the specific error code into a string representations of
- // that error code.
- virtual const char* GetErrCodeString(void) const
- {
- switch (GetErrCode()) {
- case eTestFailed: return "eTestFailed";
- default: return CException::GetErrCodeString();
- }
- }
- NCBI_EXCEPTION_DEFAULT(CPluginTestException, CException);
- };
- class CPluginTestApp : public CNcbiApplication
- {
- public:
- CPluginTestApp();
- private:
- CRef<objects::CPluginConfigCache> m_PCC;
- virtual void Init(void);
- virtual int Run(void);
- virtual void Exit(void);
- void WritePluginConfig(const string& pcfile, const CPluginConfigCache& pcc);
- void ReadPluginConfig(const string& pc_file);
- void SetPluginConfig(CPluginConfigCache& pcc);
- };
- CPluginTestApp::CPluginTestApp()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // Init test for all different types of arguments
- void CPluginTestApp::Init(void)
- {
- // Create command-line argument descriptions class
- auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
- // Specify USAGE context
- arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
- "Test for the Configuration dialog.");
- // Setup arg.descriptions for this application
- SetupArgDescriptions(arg_desc.release());
- }
- int CPluginTestApp::Run(void)
- {
- string pcc_file("/Users/rsmith/test_config.asn");
- ReadPluginConfig(pcc_file);
- CRef<CSeqGraphicConfig> configSettings(new CSeqGraphicConfig(m_PCC));
- // create panel
- CFeatGroupConfigPanel preference_panel;
-
- // create configuration mediator from data set and panel
- CTestConfigMediator preference_mediator(*configSettings, preference_panel);
-
- // create and display dialog given the mediator.
- CConfigDlg preference_dialog(preference_mediator);
- EDialogReturnValue dlg_ret = preference_dialog.ShowModal();
- if (eCancel != dlg_ret) {
- cerr << "ok chosen" << endl;
- WritePluginConfig( pcc_file, configSettings->SetConfigCache());
- } else {
- cerr << "cancel chosen, no processing done." << endl;
- }
- return 0;
- }
- void CPluginTestApp::WritePluginConfig(const string& pcfile, const CPluginConfigCache& pcc)
- {
- try {
- auto_ptr<CObjectOStream> os(CObjectOStream::Open(eSerial_AsnText, pcfile));
- *os << pcc;
- cerr << "plugin config cache written to: " << pcfile;
- } catch (...) {
- cerr << "Write of plugin config cache to " << pcfile << " failed";
- }
-
- return;
- }
- void CPluginTestApp::ReadPluginConfig(const string& pcfile)
- {
- {{
- // first check if the file exists.
- CFile file(pcfile);
- if ( ! file.Exists() ) {
- LOG_POST( Info << "CSettings::LoadPluginConfig(): "
- "no plugin config cache found at " << pcfile);
- return;
- }
- }}
-
- // try reading in ASN.1 test format
- try {
- auto_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_AsnText, pcfile));
- CRef<CPluginConfigCache> config_cache(new CPluginConfigCache);
-
- *is >> *config_cache;
- LOG_POST( Info << "CSettings::LoadPluginConfig(): "
- "text plugin config cache read from: " << pcfile);
- SetPluginConfig(*config_cache);
- return;
- } catch (...) {
- _TRACE("read of ASN.1 text plugin config cache in " << pcfile << " failed");
- }
-
- // try reading in ASN.1 binary format
- try {
- auto_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_AsnBinary, pcfile));
- CRef<CPluginConfigCache> config_cache(new CPluginConfigCache);
-
- *is >> *config_cache;
- LOG_POST( Info << "CSettings::LoadPluginConfig(): "
- "binary plugin config cache read from: " << pcfile);
- SetPluginConfig(*config_cache);
- return;
- } catch (...) {
- _TRACE("read of ASN.1 binary plugin config cache in " << pcfile << " failed");
- }
- // if not, try reading in XML
- try {
- auto_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_Xml, pcfile));
- CRef<CPluginConfigCache> config_cache(new CPluginConfigCache);
-
- *is >> *config_cache;
- LOG_POST( Info << "CSettings::LoadPluginConfig(): "
- "XML plugin config cache read from: " << pcfile);
- SetPluginConfig(*config_cache);
- return;
- } catch (...) {
- _TRACE("read of XML plugin config cache in " << pcfile << " failed");
- }
-
- // Log an error and continue.
- LOG_POST( Error << "CSettings::LoadPluginConfig(): "
- "File does not contain a plugin config cache: " << pcfile);
-
- return;
- }
- void CPluginTestApp::SetPluginConfig(CPluginConfigCache& pcc)
- {
- m_PCC.Reset(&pcc);
- }
- /////////////////////////////////////////////////////////////////////////////
- // Cleanup
- void CPluginTestApp::Exit(void)
- {
- SetDiagStream(0);
- }
- /////////////////////////////////////////////////////////////////////////////
- // MAIN
- int main(int argc, const char* argv[])
- {
- // Execute main application function
- return CPluginTestApp().AppMain(argc, argv, 0, eDS_Default, 0);
- }
- /*
- * ===========================================================================
- * $Log: featgroup_config_dlg.cpp,v $
- * Revision 1000.0 2004/06/01 21:15:13 gouriano
- * PRODUCTION: IMPORTED [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/02/24 16:59:03 rsmith
- * update include paths.
- *
- * Revision 1.1 2004/02/20 16:14:18 rsmith
- * Initial checkin of prototype, currenty unused code.
- *
- * ===========================================================================
- */