gbench.cpp
来自「ncbi源码」· C++ 代码 · 共 756 行 · 第 1/2 页
CPP
756 行
/* * =========================================================================== * PRODUCTION $Log: gbench.cpp,v $ * PRODUCTION Revision 1000.6 2004/06/01 20:48:09 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.86 * PRODUCTION * =========================================================================== *//* $Id: gbench.cpp,v 1000.6 2004/06/01 20:48:09 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: * CGBenchApp -- main application class for GBENCH */#include <ncbi_pch.hpp>#include "gbench.hpp"#include "gbench_exception.hpp"#include "named_pipe.hpp"#include "load_file.hpp"#include <gui/utils/system_path.hpp>#include <corelib/ncbiargs.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbifile.hpp>#include <corelib/ncbireg.hpp>// GUI classes#include <FL/Fl.H>#include <gui/core/algo.hpp>#include <gui/core/doc_exception.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_registry.hpp>#include <gui/config/settings.hpp>#include <gui/core/version.hpp>#include <gui/core/iview.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/utils/fltk_utils.hpp>#include <gui/utils/message_box.hpp>#include <gui/widgets/fl/menu_window.hpp>// dialogs#include "about_dlg.hpp"#include "main_window.hpp"#include <gui/core/message_queue.hpp>#include <gui/plugin/PluginMessage.hpp>#include <corelib/ncbi_system.hpp>#include <connect/ncbi_core_cxx.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);const double sc_FLTK_WAIT_TIMEOUT = 0.05;const unsigned int sc_MQ_TIMEOUT_SEC = 0; const unsigned int sc_MQ_TIMEOUT_NSEC = 0;//// FLTK idle processing function//void fltkGBenchIdleFunc(void*){ CPluginMessageQueue::ProcessMessage(sc_MQ_TIMEOUT_SEC, sc_MQ_TIMEOUT_NSEC); Fl::repeat_timeout(sc_FLTK_WAIT_TIMEOUT, fltkGBenchIdleFunc);}CGBenchApp::CGBenchApp(void) : m_AboutDlg(NULL){}void CGBenchApp::Init(void){ // Create command - line argument descriptions class auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); // Specify USAGE context arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "NCBI Genome Workbench"); // Flag: just dump the version and exit arg_desc->AddFlag("v", "Version"); // Set the scheme for the application as a whole arg_desc->AddDefaultKey("scheme", "FltkScheme", "FLTK rendering scheme", CArgDescriptions::eString, "none"); arg_desc->SetConstraint("scheme", &(*new CArgAllow_Strings, "none", "plastic")); // Set the background color arg_desc->AddOptionalKey("bg", "BackgroundColor", "Global widget background color", CArgDescriptions::eString); // Set the foreground color arg_desc->AddOptionalKey("fg", "ForegroundColor", "Global widget foreground color", CArgDescriptions::eString); // Flag: don't try to launch Data_File in another app instance // via named pipe arg_desc->AddFlag("noremote", "Don't Try to open Data_File using " "already-running gbench; launch a new gbench instance"); arg_desc->AddFlag("nr", "Synonym for -noremote"); // Flag: try to launch Data_File in another app instance // via named pipe arg_desc->AddFlag("remote", "Try to open Data_File using already-running gbench" " (default unless registry specifies otherwise)"); arg_desc->AddFlag("r", "Synonym for -remote"); // Optional file to load arg_desc->AddOptionalPositional ("Data_File", "data file to read", CArgDescriptions::eInputFile); // Optional file type arg_desc->AddDefaultKey("t", "File_Type", "Type of optional data file", CArgDescriptions::eString, "auto"); arg_desc->SetConstraint("t", &(*new CArgAllow_Strings, "auto", "asntext", "asnbin", "xml", "fasta", "textalign", "newick")); // Setup arg.descriptions for this application SetupArgDescriptions(arg_desc.release());}void CGBenchApp::ProcessMessage(){}int CGBenchApp::Run(void){ CArgs args = GetArgs(); // // version checking // if (args["v"]) { cerr << "NCBI Genome Workbench, version " << CPluginVersion::eMajor << "." << CPluginVersion::eMinor << endl; cerr << " build date: " << __DATE__ << " " << __TIME__ << endl; return 0; } try { CONNECT_Init(&GetConfig()); // // FLTK requres a list of command line arguments // The only strict requirement is for an application name // We also provide a few FLTK options, which we parse out here // // The arguments we use are: // NB: this must be expanded in size if we add arguments! // argv[0] = name // argv[1] = '-scheme' // argv[2] = scheme name // argv[3] = '-bg' // argv[4] = color // argv[5] = '-fg' // argv[6] = color // char* argv[7]; int argc = 0; argv[argc++] = "gbench"; // fltk scheme string fltk_scheme = args["scheme"].AsString(); argv[argc++] = "-scheme"; argv[argc++] = const_cast<char*> (fltk_scheme.c_str()); // initialize our default FLTK states CFltkUtils::Init(argc, argv); // // first, our general app set-up stuff // this involves connecting our various plug-ins // CNcbiRegistry& registry = GetConfig(); string dir; // if handed a file on command line, try sending it to // another application instance via the named pipe // if the command line switches and registry // say to do so if (args["Data_File"] && (args["remote"] || args["r"] || (registry.GetBool("APP", "RemoteByDefault", true) && !args["noremote"] && !args["nr"]))) { try { string fname = args["Data_File"].AsString(); // if pathname is relative, convert to absolute if (!CDirEntry::IsAbsolutePath(fname)) { fname = CDirEntry::ConcatPath(CDir::GetCwd(), fname); } // try to open via named pipe CGBenchPipe::OpenRemote(fname, args["t"].AsString()); // if this was successful, we're all done return 0; } catch (exception& e) { LOG_POST(Info << "Remote open failed: " << e.what()); } } if ( (dir = registry.Get("app", "plugin_path")).empty() ) { registry.Set("app", "plugin_path", "<std>, <home>", CNcbiRegistry::ePersistent, " default plugin_path"); } if ( !(dir = registry.Get("app", "plugin_path")).empty() ) { x_LoadPlugins(dir); } // Get our various saved preferences for plugins. if ( !(dir = registry.Get("app", "plugin_config_path")).empty() ) { CDocManager::GetSettings().LoadPluginConfigs(dir); } else { CDocManager::GetSettings().LoadPluginConfig(); } // // create our GUI components // m_MainWin = new CMainWindow(); CDocManager::AttachView(m_MainWin); CMenu::SetResourceManager(CRef<CResourceManager>(&x_GetResourceMgr())); // // first, set up a custom diagnostics handler // this has a hook to FLTK which allows us to display log messages // LOG_POST(Warning << "NCBI Genome Workbench, version " << (int)CPluginVersion::eMajor << "." << (int)CPluginVersion::eMinor); LOG_POST(Warning << " build date: " << __DATE__ << " " << __TIME__); LOG_POST(Warning << " Genome Workbench installation path: " << CSystemPath::ResolvePath("<std>", "")); LOG_POST(Warning << " Genome Workbench user path: " << CSystemPath::ResolvePath("<home>", "")); // call show() and start our business m_MainWin->Show(argc, argv); // post messages for plugin initialization CPluginUtils::CallPlugin("CPluginNews", eAlgoCommand_run); // register an idle processing callback for FLTK // this will process one message off of the queue Fl::add_timeout(sc_FLTK_WAIT_TIMEOUT, fltkGBenchIdleFunc); // if handed a file on command line, make a plugin call to load it if (args["Data_File"]) { GBenchLoadFile(args["Data_File"].AsString(), args["t"].AsString(), true); } // set up the named pipe if possible try { CGBenchPipe::Start(); } catch (exception& e) { LOG_POST(Warning << "Couldn't set up named pipe: " << e.what()); } while (m_MainWin->Shown()) { // poll between the message queue and fltk event loop Fl::wait(sc_FLTK_WAIT_TIMEOUT); } // shut down cleanly CDocManager::ShutDown(); // on exit, write our config file as appropriate if (GetConfig().Modified()) { string home_path = CSystemPath::ResolvePath("<home>", ""); CDir home(home_path); if ( !home.Exists() ) { home.Create(); } home_path += CDirEntry::GetPathSeparator(); home_path += "gbench.ini"; CNcbiOfstream o_file(home_path.c_str(), ios::out|ios::binary); GetConfig().Write(o_file); } } catch (CException& e) { NcbiMessageBox(string("Error:\n") + e.GetMsg()); return 1; } catch (std::exception& e) { NcbiMessageBox(string("Error:\n") + e.what()); return 1; }#ifndef _DEBUG catch (...) { NcbiMessageBox("An unknown error has occurred."); return 1; }#endif return 0;}// raise the main application window to the foregroundvoid CGBenchApp::Raise(){ CNcbiApplication* app = CNcbiApplication::Instance(); _ASSERT(app); CGBenchApp* gbapp = dynamic_cast<CGBenchApp*>(app); if (gbapp) { if (gbapp->m_MainWin) { gbapp->m_MainWin->Show(); } }}void CGBenchApp::Exit(void){ SetDiagStream(0);}bool CGBenchApp::LoadConfig(CNcbiRegistry& reg, const string* conf){ string config_path; if (conf == NULL || conf->empty()) { config_path = CSystemPath::ResolvePathExisting("<home>/gbench.ini, "
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?