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

Go to the SVN repository for this file.

1 /* $Id: table_import_wizard.cpp 43757 2019-08-28 16:52:27Z 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 
33 
35 
36 #include "table_format_panel.hpp"
40 #include "table_xform_panel.hpp"
41 
44 
47 
49  m_TableFormatPanel()
50  , m_TableDelimitersPanel()
51  , m_TableFixedWidthPanel()
52  , m_TableColumnIdPanel()
53  , m_TableColumnXFormPanel()
54  , m_SelectFormatPage(*this)
55  , m_DelimitersPage(*this)
56  , m_FixedWidthPage(*this)
57  , m_ColumnIdPage(*this)
58  , m_ColumnXForm(*this)
59  , m_ImportedTableData(new CTableImportDataSource())
60  , m_AnnotTableData(new CTableAnnotDataSource())
61  , m_ParentWindow(NULL)
62  , m_CurrentPage(&m_SelectFormatPage)
63 {
64 }
65 
67 {
69 }
70 
72 {
79 }
80 
82 {
83  return (m_CurrentPage == &m_SelectFormatPage);
84 }
85 
87 {
88  return (m_CurrentPage->GetNextPage() == 0);
89 }
90 
92 {
93  return (m_CurrentPage == 0);
94 }
95 
97 {
98  return m_CurrentPage ? m_CurrentPage->GetPanel() : (wxPanel*)0;
99 }
100 
102 {
103  if (filenames.empty())
104  return false;
105 
106  CTableFormatPanel* formatPanel = x_GetSelectFormatPanel();
107  formatPanel->m_PreviewFname = filenames[0];
108 
109  return formatPanel->PreviewData();
110 }
111 
113 {
115 }
116 
118 {
119  if (m_CurrentPage == 0)
120  return false;
121 
122  if (!m_CurrentPage->CanLeavePage(true))
123  return false;
124 
126  return true;
127 }
128 
130 {
131  if (m_CurrentPage == 0) {
133  } else {
135  }
136  return true;
137 }
138 
139 static const string kSelectFormatTag = ".SelectFormatPanel";
140 static const string kDelimitersTag = ".DelimitersPanel";
141 static const string kFixedWidthTag = ".FixedWidthPanel";
142 static const string kColumnIdTag = ".ColumnIdPanel";
143 static const string kColumnXformTag = ".ColumnXformPanel";
144 
146 {
147  if (m_TableFormatPanel == NULL) {
149 
150  if ( !m_RegPath.empty() ) {
153  }
154  }
156 
157  return m_TableFormatPanel;
158 }
159 
161 {
162  if (m_TableDelimitersPanel == NULL) {
164 
165  if ( !m_RegPath.empty() ) {
168  }
169  }
171 
172  return m_TableDelimitersPanel;
173 }
174 
176 {
177  if (m_TableFixedWidthPanel == NULL) {
179 
180  if ( !m_RegPath.empty() ) {
183  }
184  }
186 
187  return m_TableFixedWidthPanel;
188 }
189 
191 {
192  if (m_TableColumnIdPanel == NULL) {
194 
195  if ( !m_RegPath.empty() ) {
198  }
199  }
200 
202 
203  return m_TableColumnIdPanel;
204 }
205 
207 {
208  if (m_TableColumnXFormPanel == NULL) {
210 
211  if ( !m_RegPath.empty() ) {
214  }
215  }
218 
220 }
221 
223 {
224  // Now convert the table to a seq-annot - could be slow if there is a lot
225  // of data so use async converter to give user a message as to what's
226  // going on.
228 
229  ERR_POST(Info << "Import Table - Converting SeqTable to SeqAnnot");
230 
231  GUI_AsyncExec([this](ICanceled&)
232  {
234  }, wxT("Preparing Table Data..."));
235 }
236 
238 {
239  GUI_AsyncExec([this](ICanceled&)
240  {
242  guesser.GuessColumns();
243  }, wxT("Analyzing column data..."));
244 
245  ERR_POST(Info << "Table Import - Guessed Columns: ");
247 }
248 
249 //
250 // CSelectFormatPage navigation
251 //
252 
254 {
256 }
257 
259 {
260  CTableFormatPanel* panel = m_Manager.x_GetSelectFormatPanel();
261  if (forward && !panel->IsInputValid())
262  return false;
263 
264  panel->SaveSettings();
265  return true;
266 }
267 
269 {
270  CTableFormatPanel* panel = m_Manager.x_GetSelectFormatPanel();
271  if (panel->IsDelimitedFile())
272  return &m_Manager.m_DelimitersPage;
273  else
274  return &m_Manager.m_FixedWidthPage;
275 }
276 
277 //
278 // CDelimitersPage navigation
279 //
280 
282 {
283  return m_Manager.x_GetDelimitersPanel();
284 }
285 
287 {
288  CTableDelimitersPanel* panel = m_Manager.x_GetDelimitersPanel();
289  if (forward) {
290  if (!panel->IsInputValid())
291  return false;
292 
293  panel->SaveSettings();
294  m_Manager.x_GuessColumns();
295  return true;
296  }
297 
298  panel->SaveSettings();
299  return true;
300 }
301 
303 {
304  return &m_Manager.m_SelectFormatPage;
305 }
306 
308 {
309  m_Manager.m_ColumnIdPage.SetPrevPage(this);
310  return &m_Manager.m_ColumnIdPage;
311 }
312 
313 //
314 // CFixedWidthPage navigation
315 //
316 
318 {
319  return m_Manager.x_GetFixedWidthPanel();
320 }
321 
323 {
324  CTableFixedWidthPanel* panel = m_Manager.x_GetFixedWidthPanel();
325  if (forward) {
326  if (!panel->IsInputValid())
327  return false;
328 
329  panel->SaveSettings();
330  m_Manager.x_GuessColumns();
331  return true;
332  }
333 
334  panel->SaveSettings();
335  return true;
336 }
337 
339 {
340  return &m_Manager.m_SelectFormatPage;
341 }
342 
344 {
345  m_Manager.m_ColumnIdPage.SetPrevPage(this);
346  return &m_Manager.m_ColumnIdPage;
347 }
348 
349 //
350 // CColumnIdPage navigation
351 //
352 
354 {
355  return m_Manager.x_GetColumnIdPanel();
356 }
357 
359 {
360  CTableColumnIdPanel* panel = m_Manager.x_GetColumnIdPanel();
361  if (forward) {
362  if (!panel->IsInputValid())
363  return false;
364 
365  panel->SaveSettings();
366  m_Manager.x_ConvertToSeqAnnot();
367  return true;
368  }
369 
370  panel->SaveSettings();
371  return true;
372 }
373 
375 {
376  return CWizardPage::GetPrevPage();
377 }
378 
380 {
381  return &m_Manager.m_ColumnXForm;
382 }
383 
384 //
385 // CColumnXFormPage navigation
386 //
387 
389 {
390  return m_Manager.x_GetColumnXForm();
391 }
392 
394 {
395  CTableXformPanel* panel = m_Manager.x_GetColumnXForm();
396  if (forward && !panel->IsInputValid())
397  return false;
398 
399  panel->SaveSettings();
400  return true;
401 }
402 
404 {
405  return &m_Manager.m_ColumnIdPage;
406 }
407 
409 {
410  return 0;
411 }
412 
std::invoke_result< _Fty, ICanceled & >::type GUI_AsyncExec(_Fty &&_Fnarg, const wxString &msg=wxT("Accessing network..."))
Definition: async_call.hpp:130
CRef< CSeq_annot > GetContainer()
void SetImportDataSource(CRef< CTableImportDataSource > ds)
void SetRegistryPath(const string &path)
CTableColumnTypeGuesser -.
void GuessColumns()
Update columns in data source with type info based on best-guesses.
void SetRegistryPath(const string &path)
void SetImportDataSource(CRef< CTableImportDataSource > ds)
void SetRegistryPath(const string &path)
void SetImportDataSource(CRef< CTableImportDataSource > ds)
void SetImportDataSource(CRef< CTableImportDataSource > ds)
bool PreviewData()
Load the selected file and displays its contents in the list.
bool IsDelimitedFile() const
Return true if delimited button selected, false if fixed btn selected.
void SetRegistryPath(const string &path)
CTableImportDataSource -.
void LogColumnInfo() const
Log column information.
void ConvertToSeqAnnot(CRef< CSeq_annot > annot_container)
Save data in table into annot_container.
virtual bool CanLeavePage(bool forward)
virtual bool CanLeavePage(bool forward)
virtual bool CanLeavePage(bool forward)
CTableFormatPanel * m_TableFormatPanel
CTableColumnIdPanel * x_GetColumnIdPanel()
CTableImportWizard::CSelectFormatPage m_SelectFormatPage
CTableDelimitersPanel * x_GetDelimitersPanel()
CTableFixedWidthPanel * x_GetFixedWidthPanel()
bool ValidateFilenames(const vector< wxString > &filenames)
CTableXformPanel * m_TableColumnXFormPanel
CRef< CTableImportDataSource > m_ImportedTableData
Data is loaded initially into this table for delimiter processing.
CTableColumnIdPanel * m_TableColumnIdPanel
CTableFormatPanel * x_GetSelectFormatPanel()
CTableFixedWidthPanel * m_TableFixedWidthPanel
CTableDelimitersPanel * m_TableDelimitersPanel
CTableXformPanel * x_GetColumnXForm()
CRef< CTableAnnotDataSource > m_AnnotTableData
After delimiters and column types are identified, table is copied to this table for saving as asn and...
CTableImportWizard::CColumnXFormPage m_ColumnXForm
IExecuteUnit * GetExecuteUnit(const vector< wxString > &filenames)
CTableObjectLoader.
void SetRegistryPath(const string &path)
void SetAnnotDataSource(CRef< CTableAnnotDataSource > ad)
void SetImportDataSource(CRef< CTableImportDataSource > ds)
void SaveSettings() const
virtual IWizardPage * GetPrevPage()
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
virtual void SetPrevPage(IWizardPage *)=0
virtual IWizardPage * GetPrevPage()=0
virtual IWizardPage * GetNextPage()=0
virtual wxPanel * GetPanel()=0
virtual bool CanLeavePage(bool forward)=0
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 wxT(x)
Definition: muParser.cpp:41
static int filenames
Definition: pcregrep.c:172
USING_SCOPE(objects)
static const string kColumnXformTag
static const string kSelectFormatTag
static const string kFixedWidthTag
static const string kColumnIdTag
static const string kDelimitersTag
Modified on Tue Dec 05 02:15:22 2023 by modify_doxy.py rev. 669887