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

Go to the SVN repository for this file.

1 /* $Id: flatfile_exporter.cpp 39345 2017-09-13 19:39:22Z 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 
40 #include "flatfile_exporter.hpp"
41 #include "flatfile_export_page.hpp"
42 
44 
46 
49 
51  public CObject,
52  public IUIExportTool,
53  public IRegSettings
54 {
55 public:
57  /// @name IUIToolManager interface implementation
58  /// @{
59  virtual const IUIObject& GetDescriptor() const;
60  virtual void SetServiceLocator(IServiceLocator* srv_locator);
61  virtual void SetParentWindow(wxWindow* parent);
62  virtual void InitUI();
63  virtual void CleanUI();
64  virtual wxPanel* GetCurrentPanel();
65  virtual bool IsFinalState();
66  virtual bool IsCompletedState();
67  virtual bool CanDo(EAction action);
68  virtual bool DoTransition(EAction action);
69  virtual IAppTask* GetTask();
70  /// @}
71 
72  /// @name IUIExportTool interface implementation
73  /// @{
74  virtual void SetLocations(const TRelatedObjectsMap& input_map);
75  virtual void SetObjects(const TConstScopedObjects& input);
76  /// @}
77 
78  /// @name IRegSettings interface implementation
79  /// @{
80  virtual void SetRegistryPath(const string& path);
81  virtual void SaveSettings() const;
82  virtual void LoadSettings();
83  /// @}
84 
85 protected:
86  /// defines states of the Tool Manager
87  enum EState {
88  eInvalid = -1, // initial
89  eParams, // displaying parameters panel
90  eCompleted // done
91  };
92 
94  wxWindow *m_ParentWindow;
96  string m_RegPath;
97 
100 
101  /// tool manager state (int the Run Tool wizard)
103 };
104 
106  : m_Descriptor("GenBank Flat File", ""),
107  m_ParentWindow(),
108  m_Panel(),
109  m_State(eInvalid)
110 {
111  m_Descriptor.SetLogEvent("exporters");
112 }
113 
115 {
116  return m_Descriptor;
117 }
118 
120 {
121 }
122 
124 {
125  m_ParentWindow = parent;
126 }
127 
129 {
130  m_State = eParams;
131 }
132 
134 {
135  m_State = eInvalid;
136  m_Panel = NULL;
137 }
138 
140 {
141  if (m_Panel == NULL) {
145  m_Panel->TransferDataToWindow();
146 
147  if (!m_RegPath.empty()) {
148  m_Panel->SetRegistryPath(m_RegPath + ".ParamsPanel");
150  }
151  }
152 
153  return m_Panel;
154 }
155 
157 {
158  return m_State == eParams;
159 }
160 
162 {
163  return m_State == eCompleted;
164 }
165 
167 {
168  switch (m_State)
169  {
170  case eInvalid:
171  return action == eNext;
172  case eParams:
173  return action == eNext;
174  case eCompleted:
175  return false; // nothing left to do
176  default:
177  _ASSERT(false);
178  return false;
179  }
180 }
181 
183 {
184  if(m_State == eInvalid && action == eNext) {
185  m_State = eParams;
186  return true;
187  }
188  else if (m_State == eParams && action == eNext) {
190  m_Params = m_Panel->GetData();
192  return true;
193  }
194  return false;
195  }
196 
197  return false;
198 }
199 
201 {
203  return new CAppExportTask(*job, m_Params.GetFileName());
204 }
205 
206 void CFlatFileExporter::SetRegistryPath(const string& path)
207 {
208  m_RegPath = path; // store for later use
209  m_Params.SetRegistryPath(m_RegPath + ".Params");
210 }
211 
213 {
214  m_Objects = input_map;
215 }
216 
218 {
219  if( m_Objects.empty() ){
220 
223  CScope& scope = const_cast<CScope&>(*it->scope);
224  CObjectConverter::FindRelations(scope, *it->object,
225  CSeq_loc::GetTypeInfo()->GetName(), relations);
226 
227  ITERATE(CObjectConverter::TRelationVector, itr, relations) {
228  if (relations.size() > 1 && itr == relations.begin())
229  continue;
230 
231  const CRelation& rel = **itr;
232  string relName = rel.GetProperty(CSeq_loc::GetTypeInfo()->GetName());
233 
234  CRelation::TObjects related;
235  rel.GetRelated(scope, *it->object, related, CRelation::fConvert_NoExpensive);
236 
237  if (!related.empty()) {
238  TConstScopedObjects& vec = m_Objects[relName];
239 
240  ITERATE(CRelation::TObjects, it2, related)
241  vec.push_back(SConstScopedObject(it2->GetObjectPtr(), &scope));
242  }
243  }
244  }
245  }
246 }
247 
249 {
251  if (m_Panel) m_Panel->SaveSettings();
252 }
253 
255 {
257 }
258 
260 {
261  static string sid("flatfile_exporter_factory");
262  return sid;
263 }
264 
265 
267 {
268  static string slabel("Flat File Exporter Factory");
269  return slabel;
270 }
271 
273 {
274  return new CFlatFileExporter();
275 }
276 
278 {
280  if (dynamic_cast<const CSerialObject*>(it->object.GetPointer()) != NULL)
281  return true;
282  }
283  return false;
284 }
285 
CFlatFileExportJob.
virtual bool TransferDataFromWindow()
Transfer data from the window.
void SetData(const CFlatFileExportParams &data)
void SetObjects(map< string, TConstScopedObjects > *objects)
virtual void SaveSettings() const
CFlatFileExportParams & GetData()
Data access.
virtual void SetRegistryPath(const string &path)
IRegSettings.
virtual void SaveSettings() const
IRegSettings.
virtual void SetRegistryPath(const string &path)
IRegSettings.
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.
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 void CleanUI()
CleanUI() is called after the host finished using the manager.
virtual void SetObjects(const TConstScopedObjects &input)
virtual wxPanel * GetCurrentPanel()
Return the panel corresponding to the current state of Tool Manager.
virtual void SetServiceLocator(IServiceLocator *srv_locator)
Sets / unsets Service Locator.
virtual void SetParentWindow(wxWindow *parent)
virtual bool CanDo(EAction action)
Indicates whether given transition is possible in the current state.
virtual IAppTask * GetTask()
Once parameters are gathered and validated this function is called to produce the final Task object t...
CFlatFileExportPage * m_Panel
CFlatFileExportParams m_Params
EState m_State
tool manager state (int the Run Tool wizard)
virtual bool IsFinalState()
True if Tool Manager has reached its final state, i.e.
virtual void LoadSettings()
virtual bool DoTransition(EAction action)
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
virtual void SaveSettings() const
TRelatedObjectsMap m_Objects
virtual void InitUI()
Initializes the Manager before using it in UI.
virtual const IUIObject & GetDescriptor() const
Returns the object describing this tool (UI meta data).
virtual void SetLocations(const TRelatedObjectsMap &input_map)
sets objects to be exported.
virtual bool IsCompletedState()
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
virtual void SetRegistryPath(const string &path)
vector< TRelation > TRelationVector
static void FindRelations(objects::CScope &scope, const CObject &obj, const string &to_type_in, TRelationVector &relations)
CObject –.
Definition: ncbiobj.hpp:180
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
USING_SCOPE(ncbi::objects)
#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
Modified on Thu May 02 14:33:07 2024 by modify_doxy.py rev. 669887