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

Go to the SVN repository for this file.

1 /* $Id: 5col_exporter.cpp 39666 2017-10-25 16:01:13Z katargir $
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: Roman Katargin
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <corelib/ncbifile.hpp>
33 
35 
36 #include <serial/typeinfo.hpp>
37 
39 
42 
43 #include "5col_exporter.hpp"
44 #include "5col_export_page.hpp"
45 
47 
49 
52 
54  public CObject,
55  public IUIExportTool,
56  public IRegSettings
57 {
58 public:
59  C5ColExporter();
60  /// @name IUIToolManager interface implementation
61  /// @{
62  virtual const IUIObject& GetDescriptor() const;
63  virtual void SetServiceLocator(IServiceLocator* srv_locator);
64  virtual void SetParentWindow(wxWindow* parent);
65  virtual void InitUI();
66  virtual void CleanUI();
67  virtual wxPanel* GetCurrentPanel();
68  virtual bool IsFinalState();
69  virtual bool IsCompletedState();
70  virtual bool CanDo(EAction action);
71  virtual bool DoTransition(EAction action);
72  virtual IAppTask* GetTask();
73  /// @}
74 
75  /// @name IUIExportTool interface implementation
76  /// @{
77  virtual void SetLocations(const TRelatedObjectsMap& input_map);
78  virtual void SetObjects(const TConstScopedObjects& input);
79  /// @}
80 
81  /// @name IRegSettings interface implementation
82  /// @{
83  virtual void SetRegistryPath(const string& path);
84  virtual void SaveSettings() const;
85  virtual void LoadSettings();
86  /// @}
87 
88 protected:
89  /// defines states of the Tool Manager
90  enum EState {
91  eInvalid = -1, // initial
92  eParams, // displaying parameters panel
93  eCompleted // done
94  };
95 
97  wxWindow* m_ParentWindow;
99  string m_RegPath;
100 
102  wxString m_FileName;
105 
106  /// tool manager state (int the Run Tool wizard)
108 };
109 
110 
112  : m_Descriptor("5 Column Feature File", ""),
113  m_ParentWindow(),
114  m_Panel(),
115  m_State(eInvalid)
116 {
117  m_Descriptor.SetLogEvent("exporters");
118 }
119 
121 {
122  return m_Descriptor;
123 }
124 
126 {
127 }
128 
129 void C5ColExporter::SetParentWindow(wxWindow* parent)
130 {
131  m_ParentWindow = parent;
132 }
133 
135 {
136  m_State = eParams;
137 }
138 
140 {
141  m_State = eInvalid;
142  m_Panel = NULL;
143 }
144 
146 {
147  if (m_Panel == NULL) {
152  m_Panel->TransferDataToWindow();
153 
154  if (!m_RegPath.empty()) {
155  m_Panel->SetRegistryPath(m_RegPath + ".ParamsPanel");
157  }
158  }
159 
160  return m_Panel;
161 }
162 
164 {
165  return m_State == eParams;
166 }
167 
169 {
170  return m_State == eCompleted;
171 }
172 
174 {
175  switch (m_State)
176  {
177  case eInvalid:
178  return action == eNext;
179  case eParams:
180  return action == eNext;
181  case eCompleted:
182  return false; // nothing left to do
183  default:
184  _ASSERT(false);
185  return false;
186  }
187 }
188 
190 {
191  if(m_State == eInvalid && action == eNext) {
192  m_State = eParams;
193  return true;
194  }
195  else if (m_State == eParams && action == eNext) {
199  m_Params = m_Panel->GetData();
201  return true;
202  }
203  return false;
204  }
205 
206  return false;
207 }
208 
210 {
212  return new CAppExportTask(*job, m_FileName);
213 }
214 
215 void C5ColExporter::SetRegistryPath(const string& path)
216 {
217  m_RegPath = path; // store for later use
218  m_Params.SetRegistryPath(m_RegPath + ".5ColParams");
219 }
220 
222 {
223  m_Objects = input_map;
224 }
225 
227 {
228  if( m_Objects.empty() ){
229 
232  CScope& scope = const_cast<CScope&>(*it->scope);
233  CObjectConverter::FindRelations(scope, *it->object,
234  CSeq_loc::GetTypeInfo()->GetName(), relations);
235 
236  ITERATE(CObjectConverter::TRelationVector, itr, relations) {
237  if (relations.size() > 1 && itr == relations.begin())
238  continue;
239 
240  const CRelation& rel = **itr;
241  string relName = rel.GetProperty(CSeq_loc::GetTypeInfo()->GetName());
242 
243  CRelation::TObjects related;
244  rel.GetRelated(scope, *it->object, related, CRelation::fConvert_NoExpensive);
245 
246  if (!related.empty()) {
247  TConstScopedObjects& vec = m_Objects[relName];
248 
249  ITERATE(CRelation::TObjects, it2, related)
250  vec.push_back(SConstScopedObject(it2->GetObjectPtr(), &scope));
251  }
252  }
253  }
254  }
255 }
256 
257 static const char* kFileName = "FileName";
258 
260 {
262 
263  if (!m_RegPath.empty()) {
265  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
267  }
268 
269  if (m_Panel) m_Panel->SaveSettings();
270 }
271 
273 {
275 
276  if (!m_RegPath.empty()) {
278  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
279 
280  m_FileName =
282  }
283 }
284 
286 {
287  static string sid("z5col_exporter_factory");
288  return sid;
289 }
290 
291 
293 {
294  static string slabel("5 Column Exporter Factory");
295  return slabel;
296 }
297 
299 {
300  return new C5ColExporter();
301 }
302 
304 {
306  if (dynamic_cast<const CSerialObject*>(it->object.GetPointer()) != NULL)
307  return true;
308  }
309  return false;
310 }
311 
USING_SCOPE(ncbi::objects)
static const char * kFileName
C5ColExportJob.
C5ColExportParams & GetData()
Data access.
void SetObjects(map< string, TConstScopedObjects > *objects)
virtual bool TransferDataFromWindow()
Transfer data from the window.
void SetFileName(wxString value)
SConstScopedObject GetSeqLoc() const
wxString GetFileName() const
virtual void LoadSettings()
virtual void SetRegistryPath(const string &path)
IRegSettings.
void SetData(const C5ColExportParams &data)
virtual void SaveSettings() const
virtual void SaveSettings() const
IRegSettings.
virtual void SetRegistryPath(const string &path)
IRegSettings.
virtual void LoadSettings()
virtual IUIExportTool * CreateInstance() const
create and instance of the IUIExporter
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool TestInputObjects(TConstScopedObjects &objects) const
Check if exporter can handle the objects.
wxWindow * m_ParentWindow
virtual void CleanUI()
CleanUI() is called after the host finished using the manager.
wxString m_FileName
virtual IAppTask * GetTask()
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual const IUIObject & GetDescriptor() const
Returns the object describing this tool (UI meta data).
virtual bool CanDo(EAction action)
Indicates whether given transition is possible in the current state.
virtual wxPanel * GetCurrentPanel()
Return the panel corresponding to the current state of Tool Manager.
C5ColExportParams m_Params
virtual void SetLocations(const TRelatedObjectsMap &input_map)
sets objects to be exported.
virtual bool IsFinalState()
True if Tool Manager has reached its final state, i.e.
virtual bool IsCompletedState()
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
virtual void SetObjects(const TConstScopedObjects &input)
CUIObject m_Descriptor
C5ColExportPage * m_Panel
virtual void SetParentWindow(wxWindow *parent)
EState m_State
tool manager state (int the Run Tool wizard)
virtual void SaveSettings() const
SConstScopedObject m_SeqLoc
virtual bool DoTransition(EAction action)
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
TRelatedObjectsMap m_Objects
virtual void SetRegistryPath(const string &path)
virtual void LoadSettings()
virtual void SetServiceLocator(IServiceLocator *srv_locator)
Sets / unsets Service Locator.
virtual void InitUI()
Initializes the Manager before using it in UI.
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
vector< TRelation > TRelationVector
static void FindRelations(objects::CScope &scope, const CObject &obj, const string &to_type_in, TRelationVector &relations)
CObject –.
Definition: ncbiobj.hpp:180
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: reg_view.cpp:246
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
vector< SObject > TObjects
Definition: relation.hpp:130
virtual string GetProperty(const string &) const
Definition: relation.hpp:145
virtual void GetRelated(objects::CScope &scope, const CObject &obj, TObjects &related, TFlags flags=eDefault, ICanceled *cancel=NULL) const =0
@ fConvert_NoExpensive
do not perform any expensive tests (such as fetching from the network)
Definition: relation.hpp:60
CScope –.
Definition: scope.hpp:92
Base class for all serializable objects.
Definition: serialbase.hpp:150
CUIObject - default mix-in implementation of IUIObject.
Definition: ui_object.hpp:81
IAppTask.
Definition: app_task.hpp:83
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IUIExporter is a IUIToolManager that represents an export tool.
IUIObject - object that provides basic properties often required in a UI object.
Definition: ui_object.hpp:63
bool empty() const
Definition: map.hpp:149
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
virtual void SetLogEvent(const string &log_event)
Definition: ui_object.cpp:118
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
static int input()
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
#define _ASSERT
wxString FnToWxString(const string &s)
Definition: wx_utils.cpp:253
string FnToStdString(const wxString &s)
Definition: wx_utils.cpp:268
Modified on Wed Jun 12 11:17:05 2024 by modify_doxy.py rev. 669887