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

Go to the SVN repository for this file.

1 /* $Id: fasta_align_exporter.cpp 38593 2017-06-01 17:31:50Z evgeniev $
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: Vladislav Evgeniev
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
31 
33 
34 #include <serial/typeinfo.hpp>
35 
37 
38 #include "fasta_align_exporter.hpp"
40 
42 
44 
47 
49  public CObject,
50  public IUIExportTool,
51  public IRegSettings
52 {
53 public:
55  /// @name IUIToolManager interface implementation
56  /// @{
57  virtual const IUIObject& GetDescriptor() const;
58  virtual void SetServiceLocator(IServiceLocator* srv_locator);
59  virtual void SetParentWindow(wxWindow* parent);
60  virtual void InitUI();
61  virtual void CleanUI();
62  virtual wxPanel* GetCurrentPanel();
63  virtual bool IsFinalState();
64  virtual bool IsCompletedState();
65  virtual bool CanDo(EAction action);
66  virtual bool DoTransition(EAction action);
67  virtual IAppTask* GetTask();
68  /// @}
69 
70  /// @name IUIExportTool interface implementation
71  /// @{
72  virtual void SetLocations(const TRelatedObjectsMap&) {}
73  virtual void SetObjects(const TConstScopedObjects& input);
74  /// @}
75 
76  /// @name IRegSettings interface implementation
77  /// @{
78  virtual void SetRegistryPath(const string& path);
79  virtual void SaveSettings() const;
80  virtual void LoadSettings();
81  /// @}
82 
83 protected:
84  /// defines states of the Tool Manager
85  enum EState {
86  eInvalid = -1, // initial
87  eParams, // displaying parameters panel
88  eCompleted // done
89  };
90 
92  wxWindow *m_ParentWindow;
94  string m_RegPath;
95 
98 
99  /// tool manager state (int the Run Tool wizard)
101 };
102 
104  : m_Descriptor("FASTA Alignment File", ""),
105  m_ParentWindow(),
106  m_Panel(),
107  m_State(eInvalid)
108 {
109  m_Descriptor.SetLogEvent("exporters");
110 }
111 
113 {
114  return m_Descriptor;
115 }
116 
118 {
119 }
120 
122 {
123  m_ParentWindow = parent;
124 }
125 
127 {
128  m_State = eParams;
129 }
130 
132 {
133  m_State = eInvalid;
134  m_Panel = NULL;
135 }
136 
138 {
139  if (m_Panel == NULL) {
143  m_Panel->TransferDataToWindow();
144 
145  if (!m_RegPath.empty()) {
146  m_Panel->SetRegistryPath(m_RegPath + ".FastaAlignParamsPanel");
148  }
149  }
150 
151  return m_Panel;
152 }
153 
155 {
156  return m_State == eParams;
157 }
158 
160 {
161  return m_State == eCompleted;
162 }
163 
165 {
166  switch (m_State)
167  {
168  case eInvalid:
169  return action == eNext;
170  case eParams:
171  return action == eNext;
172  case eCompleted:
173  return false; // nothing left to do
174  default:
175  _ASSERT(false);
176  return false;
177  }
178 }
179 
181 {
182 
183  if(m_State == eInvalid && action == eNext) {
184  m_State = eParams;
185  return true;
186  }
187  else if (m_State == eParams && action == eNext) {
189  m_Params = m_Panel->GetData();
191  return true;
192  }
193  return false;
194  }
195  return false;
196 }
197 
199 {
201  return new CAppJobTask(*job, true);
202 }
203 
204 void CFastaAlignExporter::SetRegistryPath(const string& path)
205 {
206  m_RegPath = path; // store for later use
207  m_Params.SetRegistryPath(m_RegPath + ".FastaAlignParams");
208 }
209 
211 {
213  const objects::CSeq_annot* annot = dynamic_cast<const objects::CSeq_annot*>(it->object.GetPointer());
214  if (nullptr == annot)
215  continue;
216 
217  if (!annot->IsAlign())
218  continue;
219 
220  for (auto &align : annot->GetData().GetAlign()) {
221  m_Objects.push_back(SConstScopedObject(align.GetPointer(), const_cast<CScope*>(it->scope.GetPointer())));
222  }
223  }
224 }
225 
227 {
229  if (m_Panel) m_Panel->SaveSettings();
230 }
231 
233 {
235 }
236 
238 {
239  static string sid("fasta_align_exporter_factory");
240  return sid;
241 }
242 
243 
245 {
246  static string slabel("FASTA Alignment Exporter Factory");
247  return slabel;
248 }
249 
251 {
252  return new CFastaAlignExporter();
253 }
254 
256 {
258  const objects::CSeq_annot* annot = dynamic_cast<const objects::CSeq_annot*>(it->object.GetPointer());
259  if (nullptr == annot)
260  continue;
261 
262  if (!annot->IsAlign())
263  continue;
264 
265  return true;
266  }
267  return false;
268 }
269 
CAppJobTask CAppJobTask is an adapter that allows for running IAppJobs as Tasks in App Task Service.
CFastaAlignExportJob.
CFastaAlignExportParams & GetData()
virtual void SetRegistryPath(const string &path)
IRegSettings.
void SetObjects(TConstScopedObjects &objects)
void SetData(const CFastaAlignExportParams &data)
virtual void SaveSettings() const
virtual void SetRegistryPath(const string &path)
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 bool TestInputObjects(TConstScopedObjects &objects) const
Check if exporter can handle the objects.
virtual IUIExportTool * CreateInstance() const
create and instance of the IUIExporter
CFastaAlignExportParams m_Params
virtual wxPanel * GetCurrentPanel()
Return the panel corresponding to the current state of Tool Manager.
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 bool IsFinalState()
True if Tool Manager has reached its final state, i.e.
virtual void SaveSettings() const
virtual void CleanUI()
CleanUI() is called after the host finished using the manager.
virtual void SetRegistryPath(const string &path)
virtual void SetObjects(const TConstScopedObjects &input)
EState m_State
tool manager state (int the Run Tool wizard)
virtual void SetParentWindow(wxWindow *parent)
virtual void InitUI()
Initializes the Manager before using it in UI.
virtual void SetLocations(const TRelatedObjectsMap &)
sets objects to be exported.
CFastaAlignExportPage * m_Panel
virtual bool IsCompletedState()
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
TConstScopedObjects m_Objects
virtual IAppTask * GetTask()
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual void SetServiceLocator(IServiceLocator *srv_locator)
Sets / unsets Service Locator.
virtual bool DoTransition(EAction action)
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
CObject –.
Definition: ncbiobj.hpp:180
CScope –.
Definition: scope.hpp:92
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
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()
#define _ASSERT
Modified on Fri Sep 20 14:57:57 2024 by modify_doxy.py rev. 669887