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

Go to the SVN repository for this file.

1 /* $Id: gff_exporter.cpp 40050 2017-12-13 18:32:01Z 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 "gff_exporter.hpp"
41 #include "gff_export_page.hpp"
42 
45 
47 
50 
51 class CGffExporter :
52  public CObject,
53  public IUIExportTool,
54  public IRegSettings
55 {
56 public:
57  CGffExporter();
58  /// @name IUIToolManager interface implementation
59  /// @{
60  virtual const IUIObject& GetDescriptor() const;
61  virtual void SetServiceLocator(IServiceLocator* srv_locator);
62  virtual void SetParentWindow(wxWindow* parent);
63  virtual void InitUI();
64  virtual void CleanUI();
65  virtual wxPanel* GetCurrentPanel();
66  virtual bool IsFinalState();
67  virtual bool IsCompletedState();
68  virtual bool CanDo(EAction action);
69  virtual bool DoTransition(EAction action);
70  virtual IAppTask* GetTask();
71  /// @}
72 
73  /// @name IUIExportTool interface implementation
74  /// @{
75  virtual void SetLocations(const TRelatedObjectsMap& /*input_map*/) {}
76  virtual void SetObjects(const TConstScopedObjects& input);
77  /// @}
78 
79  /// @name IRegSettings interface implementation
80  /// @{
81  virtual void SetRegistryPath(const string& path);
82  virtual void SaveSettings() const;
83  virtual void LoadSettings();
84  /// @}
85 
86 protected:
87  /// defines states of the Tool Manager
88  enum EState {
89  eInvalid = -1, // initial
90  eParams, // displaying parameters panel
91  eCompleted // done
92  };
93 
95  wxWindow* m_ParentWindow;
97  string m_RegPath;
98 
101 
102  /// tool manager state (int the Run Tool wizard)
104 };
105 
106 
108  : m_Descriptor("GFF3 File", ""),
109  m_ParentWindow(),
110  m_Panel(),
111  m_State(eInvalid)
112 {
113  m_Descriptor.SetLogEvent("exporters");
114 }
115 
117 {
118  return m_Descriptor;
119 }
120 
122 {
123 }
124 
125 void CGffExporter::SetParentWindow(wxWindow* parent)
126 {
127  m_ParentWindow = parent;
128 }
129 
131 {
132  m_State = eParams;
133 }
134 
136 {
137  m_State = eInvalid;
138  m_Panel = NULL;
139 }
140 
142 {
143  if (m_Panel == NULL) {
147  m_Panel->TransferDataToWindow();
148 
149  if (!m_RegPath.empty()) {
150  m_Panel->SetRegistryPath(m_RegPath + ".ParamsPanel");
152  }
153  }
154 
155  return m_Panel;
156 }
157 
159 {
160  return m_State == eParams;
161 }
162 
164 {
165  return m_State == eCompleted;
166 }
167 
169 {
170  switch (m_State)
171  {
172  case eInvalid:
173  return action == eNext;
174  case eParams:
175  return action == eNext;
176  case eCompleted:
177  return false; // nothing left to do
178  default:
179  _ASSERT(false);
180  return false;
181  }
182 }
183 
185 {
186  if(m_State == eInvalid && action == eNext) {
187  m_State = eParams;
188  return true;
189  }
190  else if (m_State == eParams && action == eNext) {
192  m_Params = m_Panel->GetData();
194  return true;
195  }
196  return false;
197  }
198 
199  return false;
200 }
201 
203 {
205  return new CAppExportTask(*job, m_Params.GetFileName());
206 }
207 
208 void CGffExporter::SetRegistryPath(const string& path)
209 {
210  m_RegPath = path; // store for later use
211  m_Params.SetRegistryPath(m_RegPath + ".GffParams");
212 }
213 
215 {
216  m_Objects.clear();
217 
218  TConstScopedObjects convert, original;
219  set<CBioseq_Handle> seqSet;
220 
222  const CSeq_align* align = dynamic_cast<const CSeq_align*>(it->object.GetPointerOrNull());
223  const CSeq_annot* annot = dynamic_cast<const CSeq_annot*>(it->object.GetPointerOrNull());
224  const CSeq_entry* seqEntry = dynamic_cast<const CSeq_entry*>(it->object.GetPointerOrNull());
225  const CBioseq* bioseq = dynamic_cast<const CBioseq*>(it->object.GetPointerOrNull());
226  const CSeq_loc* seqLoc = dynamic_cast<const CSeq_loc*>(it->object.GetPointerOrNull());
227  const CSeq_id* seqId = dynamic_cast<const CSeq_id*>(it->object.GetPointerOrNull());
228 
229  if (align || annot || seqEntry || bioseq || seqLoc || seqId) {
230  original.push_back(*it);
231  }
232  else {
233  //convert.push_back(*it);
234  }
235  convert.push_back(*it);
236  }
237 
238  if (!convert.empty()) {
239  AsyncConvertObjects(CSeq_loc::GetTypeInfo(), convert, m_Objects);
240  }
241 
242  if (!original.empty())
243  m_Objects["Selection"] = original;
244 }
245 
247 {
249  if (m_Panel) m_Panel->SaveSettings();
250 }
251 
253 {
255 }
256 
258 {
259  static string sid("gff_exporter_factory");
260  return sid;
261 }
262 
263 
265 {
266  static string slabel("GFF Exporter Factory");
267  return slabel;
268 }
269 
271 {
272  return new CGffExporter();
273 }
274 
276 {
278  if (dynamic_cast<const CSerialObject*>(it->object.GetPointer()) != NULL)
279  return true;
280  }
281  return false;
282 }
283 
void AsyncConvertObjects(const CTypeInfo *typeInfo, const TConstScopedObjects &inputObjects, map< string, TConstScopedObjects > &results)
static TDSRET convert(TDSSOCKET *tds, TDSICONV *conv, TDS_ICONV_DIRECTION direction, const char *from, size_t from_len, char *dest, size_t *dest_len)
Definition: charconv.c:57
CGffExportJob.
virtual void LoadSettings()
virtual void SaveSettings() const
void SetObjects(map< string, TConstScopedObjects > *objects)
virtual bool TransferDataFromWindow()
Transfer data from the window.
void SetData(const CGffExportParams &data)
CGffExportParams & GetData()
Data access.
virtual void SetRegistryPath(const string &path)
IRegSettings.
virtual void SetRegistryPath(const string &path)
IRegSettings.
virtual void LoadSettings()
wxString GetFileName() const
virtual void SaveSettings() const
IRegSettings.
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 IUIExportTool * CreateInstance() const
create and instance of the IUIExporter
virtual bool TestInputObjects(TConstScopedObjects &objects) const
Check if exporter can handle the objects.
virtual void SetServiceLocator(IServiceLocator *srv_locator)
Sets / unsets Service Locator.
virtual void SetLocations(const TRelatedObjectsMap &)
sets objects to be exported.
string m_RegPath
virtual void InitUI()
Initializes the Manager before using it in UI.
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 SetParentWindow(wxWindow *parent)
virtual void SetRegistryPath(const string &path)
CGffExportParams m_Params
CUIObject m_Descriptor
EState m_State
tool manager state (int the Run Tool wizard)
TRelatedObjectsMap m_Objects
virtual void SaveSettings() const
virtual void CleanUI()
CleanUI() is called after the host finished using the manager.
virtual const IUIObject & GetDescriptor() const
Returns the object describing this tool (UI meta data).
virtual bool DoTransition(EAction action)
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
virtual IAppTask * GetTask()
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual bool CanDo(EAction action)
Indicates whether given transition is possible in the current state.
wxWindow * m_ParentWindow
virtual void SetObjects(const TConstScopedObjects &input)
virtual wxPanel * GetCurrentPanel()
Return the panel corresponding to the current state of Tool Manager.
CGffExportPage * m_Panel
virtual void LoadSettings()
CObject –.
Definition: ncbiobj.hpp:180
Definition: Seq_entry.hpp:56
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
void clear()
Definition: map.hpp:169
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 Fri Dec 01 04:46:54 2023 by modify_doxy.py rev. 669887