NCBI C++ ToolKit
framework_app.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: framework_app.cpp 46068 2021-01-21 18:47:45Z grichenk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 
33 #include <ncbi_pch.hpp>
34 
36 
40 
44 
45 #include <wx/menu.h>
46 
47 
49 
50 ///////////////////////////////////////////////////////////////////////////////
51 /// Derive our application class from CwxNCBIApp and use it together with
52 /// standard CNCBIwxApplication.
53 
55 {
56 protected:
57  // we are overriding this function to create our main frame window
58  virtual bool x_CreateGUI();
59  virtual void x_DestroyGUI();
60 
61 protected:
62  virtual void x_InitAppJobDispatcher();
63 
64  virtual wxString x_GetGuiRegistryPath();
65 
66  virtual bool x_OnIdle();
67 
68 protected:
70  unique_ptr<CWorkbench> m_Workbench;
71 };
72 
73 
74 // Declare wxWidgets application class
75 // this will allow CNCBIwxApplication to instantiate our class
76 DECLARE_APP(ncbi::CFrameworkDemoApp)
77 IMPLEMENT_APP_NO_MAIN(ncbi::CFrameworkDemoApp)
78 IMPLEMENT_WX_THEME_SUPPORT
79 
80 
82 {
84 
86 
87  // register additional Thread Pool engine for executing tools
88  static int kMaxToolThreads = 3;
89  static int kMaxToolJobs = 100;
90  CThreadPoolEngine* engine = new CThreadPoolEngine(kMaxToolThreads, kMaxToolJobs);
91  disp.RegisterEngine("ThreadPool", *engine);
92 }
93 
94 
96 {
97  //LOG_POST("");
98  LOG_POST(Info << "CFrameworkDemoApp::x_CreateGUI() BEGIN");
99 
100  // create Workbench instance with m_GUI as Advisor
101  m_Workbench.reset(new CWorkbench(&m_GUI));
102 
103  /// set path in Registry, we need to this before calling Init()
104  m_Workbench->SetRegistryPath("Workbench");
105 
107  m_GUI.SetRegistryPath("ApplicationGUI");
108 
109  m_Workbench->Init();
110 
112 
113  LOG_POST(Info << "CFrameworkDemoApp::x_CreateGUI() END");
114  return true;
115 }
116 
117 
119 {
120  //LOG_POST("");
121  LOG_POST(Info << "CFrameworkDemoApp::x_DestroyGUI() BEGIN");
122 
123  // m_Workbench already has been shut down
125 
126  m_Workbench.reset();
127 
128  LOG_POST(Info << "CFrameworkDemoApp::x_DestroyGUI() END");
129 }
130 
131 
133 {
134  return CSysPath::ResolvePath(wxT("<home>/demo_gui_framework.asn"));
135 }
136 
137 
138 // we override this function to add idle processing for CAppTaskService
140 {
141  bool handled = CwxNCBIApp::x_OnIdle();
142  if( ! handled && m_Workbench.get() != NULL) {
143  CAppTaskService* task_mgr = m_Workbench->GetAppTaskService();
144  if(task_mgr) {
145  handled = task_mgr->IdleCallback();
146  }
147  }
148  return handled;
149 }
150 
151 
153 
154 /////////////////////////////////////////////////////////////////////////////
155 // main entry point
156 
157 int NcbiSys_main(int argc, ncbi::TXChar* argv[])
158 {
159  // create standard NCBI wxWidgets application
160  ncbi::CNCBIwxApplication ncbi_app("wxWidgets demo App");
161 
162  // Execute main application function
163  return ncbi_app.AppMain(argc, argv);
164 }
CAppJobDispatcher.
CAppTaskService - Application Task Service.
Derive our application class from CwxNCBIApp and use it together with standard CNCBIwxApplication.
virtual bool x_CreateGUI()
create main application window and initialize associated objects return true if successful
unique_ptr< CWorkbench > m_Workbench
virtual void x_InitAppJobDispatcher()
override this function to configure / register engines
virtual bool x_OnIdle()
called from OnIdle() and can be overridden in derived classes returns true if something was done
CFrameworkDemoGUI m_GUI
virtual void x_DestroyGUI()
destroy application GUI objects
virtual wxString x_GetGuiRegistryPath()
CFrameworkDemoFrame.
Definition: gui.hpp:79
virtual void SetWorkbench(IWorkbench *workbench)
Definition: gui.cpp:153
virtual void RestoreWindowLayout()
Definition: gui.cpp:216
virtual void SetRegistryPath(const string &path)
Definition: gui.cpp:147
static wxString ResolvePath(const wxString &path, const wxString &rel_name)
Utility function to hide the platform specifics of locating our standard directories and files.
Definition: sys_path.cpp:106
CThreadPoolEngine.
CWorkbench - default implementation of IWorkbench.
CwxNCBIApp - this class should be used in NCBI applications instead of wxApp it provides polling supp...
Definition: wx_app.hpp:80
virtual void x_InitAppJobDispatcher()
override this function to configure / register engines
Definition: wx_app.cpp:226
virtual bool x_OnIdle()
called from OnIdle() and can be overridden in derived classes returns true if something was done
Definition: wx_app.cpp:341
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
bool IdleCallback()
This function shall be called in the the application idle function, it polls the Task Queue and execu...
static CAppJobDispatcher & GetInstance()
bool RegisterEngine(const string &name, IAppJobEngine &engine)
Registers a new Engine, returns true if successful.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
char TXChar
Definition: ncbistr.hpp:172
#define wxT(x)
Definition: muParser.cpp:41
Modified on Fri Sep 20 14:57:48 2024 by modify_doxy.py rev. 669887