NCBI C++ ToolKit
algo_tool_manager_base.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_CORE___ALGO_TOOL_MANAGER_BASE__HPP
2 #define GUI_CORE___ALGO_TOOL_MANAGER_BASE__HPP
3 
4 /* $Id: algo_tool_manager_base.hpp 46706 2021-09-09 19:54:51Z asztalos $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  * CAlgoToolManagerBase - a base class for simple algorithmic tools.
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 
37 #include <gui/gui_export.h>
38 
42 
44 
45 #include <gui/utils/extension.hpp>
46 
47 #include <wx/panel.h>
48 
49 
51 
54 
55 ///////////////////////////////////////////////////////////////////////////////
56 /// CAlgoToolManagerBase
57 /// This is base class for simple algorithmic tool managers. The class provides
58 /// two pages to the Run Tool dialog.
59 /// 1. Parameters page is for entering tool parameters; derived from
60 /// CAlgoToolManagerParamsPanel class.
61 /// 2. Project selection page – the standard page for specifying how
62 /// results shall be added to the workspace - CProjectSelectorPanel.
63 /// When “Finish” button is pressed the manager creates a standard
64 /// CDataLoadingAppTask that executes a job in the background. Derived classed
65 /// must implement a pure virtual function that creates the job.
66 
68  public CObject,
69  public IUIAlgoToolManager,
70  public IExtension,
71  public IRegSettings
72 {
73 public:
74  CAlgoToolManagerBase(const string& label,
75  const string& icon_alias,
76  const string& hint = kEmptyStr,
77  const string& description = kEmptyStr,
78  const string& help_id = kEmptyStr,
79  const string& category = "Unknown");
80 
81  /// @name IUIToolManager interface implementation
82  /// @{
83  virtual void SetServiceLocator(IServiceLocator* srv_locator);
84  virtual void SetParentWindow(wxWindow* parent);
85  virtual const IUIObject& GetDescriptor() const;
86  virtual void InitUI();
87  virtual void CleanUI();
88  virtual wxPanel* GetCurrentPanel();
89  virtual bool CanDo(EAction action);
90  virtual bool IsFinalState();
91  virtual bool IsCompletedState();
92  virtual bool DoTransition(EAction action);
93  virtual IAppTask* GetTask();
94  virtual void RestoreDefaults();
95  /// @}
96 
97  /// @name IUIToolManager interface implementation
98  /// @{
99  virtual string GetCategory();
100  virtual string SetInputObjects( const vector<TConstScopedObjects>& input );
101 
102  virtual bool CanQuickLaunch() const { return false; }
103  virtual IAppTask* QuickLaunch() { return 0; }
104  /// @}
105 
106  /// @name IExtension interface - implement in derived classes
107  /// @{
108  virtual string GetExtensionIdentifier() const = 0;
109  virtual string GetExtensionLabel() const = 0;
110  /// @}
111 
112  /// @name IRegSettings interface implementation
113  /// @{
114  virtual void SetRegistryPath(const string& path);
115  virtual void LoadSettings();
116  virtual void SaveSettings() const;
117  /// @}
118 
119 protected:
120  /// defines states of the Tool Manager
121  enum EState {
122  eInvalid = -1, // initial
123  eParams, // displaying parameters panel
124  eSelectProject, // displaying target project panel
125  eCompleted // done
126  };
127 
128 protected:
129 
130  /// returns a pointer to the parameters panel, override in derived classes
132 
133  /// return a pointer to Parameters object as IRegSettings interface
135 
136  /// returns / creates Parameters panel, override in derived classes
137  /// see cpp file for example
138  virtual bool x_CreateParamsPanelIfNeeded() = 0;
139 
140  /// factory method for creating the job that executes the tool algorithm
141  /// override in derived classes
143 
144  /// init m_ProjectParams, in particular can select target project based
145  /// on the tool input
146  virtual void x_InitProjectParams();
147 
148  /// validates user input in Parameters panel, report errors if any
149  virtual bool x_ValidateParams();
150 
151  /// returns / creates Project panel
152  virtual void x_CreateProjectPanelIfNeeded();
153 
154  virtual void x_SetInputObjects( const vector<TConstScopedObjects>& input );
155  virtual string x_ValidateInputObjects();
156 
157  void x_ConvertInputObjects(const CTypeInfo* typeInfo, map<string, TConstScopedObjects>& results);
158  void x_ConvertInputObjects(const CTypeInfo* typeInfo, TConstScopedObjects& results);
159 
160  ILocker* x_GetDataLocker();
161 
162 protected:
163  /// describes the Manager's UI properties
165 
166  /// defines tool category
167  const string m_Category;
168 
170 
171  /// a window that will serve as a parent for our panels
172  wxWindow* m_ParentWindow;
173 
174  /// registry path to the settings
175  string m_RegPath;
176 
177  /// tool manager state (int the Run Tool wizard)
179 
180  /// original input objects, the tool needs to select a subset of objects
181  /// that can serve as valid input
182  vector<TConstScopedObjects> m_InputObjects;
183 
186 
187  /// In a derived class one will need to add a data member for holding
188  /// tool parameters and member pointing to the panel displaying the
189  /// parameters. Parameters class should implement IRegSettings interface
190  /// so that parameters could be saved to Registry automatically.
191 
192  /// CMyParams m_Params;
193  /// CMyParamsPanel* m_ParamsPanel;
194 };
195 
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// CAlgoToolManagerParamsPanel
200  public wxPanel,
201  public IRegSettings
202 {
203 public:
204  /// @name IRegSettings interface implementation
205  /// @{
206  virtual void SetRegistryPath(const string& reg_path);
207 
208  virtual void LoadSettings() = 0; /// override in derived classes
209  virtual void SaveSettings() const = 0; /// override in derived classes
210  /// @}
211 
212  /// Restores the default options for the panel
213  virtual void RestoreDefaults() = 0;
214 
215 protected:
216  /// registry path to the settings
217  string m_RegPath;
218 };
219 
221 
222 
223 #endif // GUI_CORE___ALGO_TOOL_MANAGER_BASE__HPP
224 
CAlgoToolManagerBase This is base class for simple algorithmic tool managers.
virtual bool x_CreateParamsPanelIfNeeded()=0
returns / creates Parameters panel, override in derived classes see cpp file for example
virtual IRegSettings * x_GetParamsAsRegSetting()=0
return a pointer to Parameters object as IRegSettings interface
CUIObject m_Descriptor
describes the Manager's UI properties
virtual bool CanQuickLaunch() const
virtual string GetExtensionIdentifier() const =0
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
EState m_State
tool manager state (int the Run Tool wizard)
virtual string GetExtensionLabel() const =0
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
CProjectSelectorPanel * m_ProjectSelPanel
string m_RegPath
registry path to the settings
virtual IAppTask * QuickLaunch()
wxWindow * m_ParentWindow
a window that will serve as a parent for our panels
virtual CDataLoadingAppJob * x_CreateLoadingJob()=0
factory method for creating the job that executes the tool algorithm override in derived classes
const string m_Category
defines tool category
vector< TConstScopedObjects > m_InputObjects
original input objects, the tool needs to select a subset of objects that can serve as valid input
virtual CAlgoToolManagerParamsPanel * x_GetParamsPanel()=0
returns a pointer to the parameters panel, override in derived classes
SProjectSelectorParams m_ProjectParams
CAlgoToolManagerParamsPanel.
virtual void LoadSettings()=0
virtual void SaveSettings() const =0
override in derived classes
string m_RegPath
registry path to the settings
virtual void RestoreDefaults()=0
override in derived classes
CDataLoadingAppJob - a base class for Jobs loading data into projects.
CObject –.
Definition: ncbiobj.hpp:180
CProjectSelectorPanel - a panel that allows the user to specify how the project items created by a pl...
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
CUIObject - default mix-in implementation of IUIObject.
Definition: ui_object.hpp:81
IAppTask.
Definition: app_task.hpp:83
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
virtual void SetRegistryPath(const string &path)=0
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IUIAlgoToolManager is a IUIToolManager that represents an algorithmic tool.
virtual string SetInputObjects(const vector< TConstScopedObjects > &input)=0
sets input objects that can be used as arguments for the tool.
virtual string GetCategory()=0
returns the name for the ToolCategory to which the tool belongs.
IUIObject - object that provides basic properties often required in a UI object.
Definition: ui_object.hpp:63
virtual void SetServiceLocator(IServiceLocator *srv_locator)=0
Sets / unsets Service Locator.
virtual bool CanDo(EAction action)=0
Indicates whether given transition is possible in the current state.
virtual bool DoTransition(EAction action)=0
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
virtual bool IsFinalState()=0
True if Tool Manager has reached its final state, i.e.
virtual void RestoreDefaults()
Restores the default options for the current panel.
virtual const IUIObject & GetDescriptor() const =0
Returns the object describing this tool (UI meta data).
virtual wxPanel * GetCurrentPanel()=0
Return the panel corresponding to the current state of Tool Manager.
virtual void CleanUI()=0
CleanUI() is called after the host finished using the manager.
virtual bool IsCompletedState()=0
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
virtual void SetParentWindow(wxWindow *parent)=0
virtual IAppTask * GetTask()=0
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual void InitUI()=0
Initializes the Manager before using it in UI.
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_GUICORE_EXPORT
Definition: gui_export.h:508
static const char label[]
Defines to provide correct exporting from DLLs in Windows.
static int input()
The NCBI C++/STL use hints.
SProjectSelectorParams - holds data for CProjectSelectorPanel.
Modified on Wed May 29 18:35:09 2024 by modify_doxy.py rev. 669887