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

Go to the SVN repository for this file.

1 /* $Id: table_delimeters_panel.cpp 43700 2019-08-14 20:31:35Z 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: Bob Falk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>////@begin includes
33 #include "wx/imaglist.h"
34 ////@end includes
35 
38 
39 #include <wx/sizer.h>
40 #include <wx/stattext.h>
41 #include <wx/statbox.h>
42 #include <wx/icon.h>
43 #include <wx/bitmap.h>
44 #include <wx/msgdlg.h>
45 #include <wx/radiobut.h>
46 #include <wx/listctrl.h>
47 #include <wx/checkbox.h>
48 #include <wx/textctrl.h>
49 
50 ////@begin XPM images
51 ////@end XPM images
52 
55 
56 IMPLEMENT_DYNAMIC_CLASS( CTableDelimitersPanel, wxPanel )
57 
58 BEGIN_EVENT_TABLE( CTableDelimitersPanel, wxPanel )
59 
60 ////@begin CTableDelimitersPanel event table entries
69 ////@end CTableDelimitersPanel event table entries
70 
71  EVT_LIST_COL_DRAGGING( ID_CTABLEIMPORTLISTCTRL2, CTableDelimitersPanel::OnCtableImportListctrlColDragging )
72 
74 
76 {
77  Init();
78 }
79 
80 CTableDelimitersPanel::CTableDelimitersPanel( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
81 {
82  Init();
83  Create(parent, id, caption, pos, size, style);
84 }
85 
86 bool CTableDelimitersPanel::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
87 {
88 ////@begin CTableDelimitersPanel creation
89  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
90  wxPanel::Create( parent, id, pos, size, style );
91 
93  if (GetSizer())
94  {
95  GetSizer()->SetSizeHints(this);
96  }
97  Centre();
98 ////@end CTableDelimitersPanel creation
99  return true;
100 }
101 
103 {
104 ////@begin CTableDelimitersPanel destruction
105 ////@end CTableDelimitersPanel destruction
106 }
107 
109 {
110 ////@begin CTableDelimitersPanel member initialisation
121 ////@end CTableDelimitersPanel member initialisation
122 
123  m_DelimsInitialized = false;
124 }
125 
127 {
128 ////@begin CTableDelimitersPanel content construction
129  // Generated by DialogBlocks, 14/08/2019 16:30:17 (unregistered)
130 
131  CTableDelimitersPanel* itemPanel1 = this;
132 
133  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
134  itemPanel1->SetSizer(itemBoxSizer2);
135 
136  wxStaticText* itemStaticText3 = new wxStaticText( itemPanel1, wxID_STATIC, _("Set Delimiters to Separate Data into Columns"), wxDefaultPosition, wxDefaultSize, 0 );
137  itemStaticText3->SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Tahoma")));
138  itemBoxSizer2->Add(itemStaticText3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
139 
140  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
141  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_LEFT|wxALL, 5);
142 
143  wxStaticBox* itemStaticBoxSizer5Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Set Column Delimiters"));
144  wxStaticBoxSizer* itemStaticBoxSizer5 = new wxStaticBoxSizer(itemStaticBoxSizer5Static, wxVERTICAL);
145  itemBoxSizer4->Add(itemStaticBoxSizer5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
146 
147  m_TabDelimCheck = new wxCheckBox( itemStaticBoxSizer5->GetStaticBox(), ID_TABDELIMCHECK, _("Tab"), wxDefaultPosition, wxDefaultSize, 0 );
148  m_TabDelimCheck->SetValue(false);
150  m_TabDelimCheck->SetToolTip(_("Check if table columns are separated by tabs"));
151  itemStaticBoxSizer5->Add(m_TabDelimCheck, 0, wxALIGN_LEFT|wxALL, 5);
152 
153  m_SemicolonDelimCheck = new wxCheckBox( itemStaticBoxSizer5->GetStaticBox(), ID_SEMICOLONDELIMCHECK, _("Semicolon"), wxDefaultPosition, wxDefaultSize, 0 );
154  m_SemicolonDelimCheck->SetValue(false);
156  m_SemicolonDelimCheck->SetToolTip(_("Check if table columns are separated by semicolons"));
157  itemStaticBoxSizer5->Add(m_SemicolonDelimCheck, 0, wxALIGN_LEFT|wxALL, 5);
158 
159  m_CommaDelimCheck = new wxCheckBox( itemStaticBoxSizer5->GetStaticBox(), ID_COMMADELIMCHECK, _("Comma"), wxDefaultPosition, wxDefaultSize, 0 );
160  m_CommaDelimCheck->SetValue(false);
161  itemStaticBoxSizer5->Add(m_CommaDelimCheck, 0, wxALIGN_LEFT|wxALL, 5);
162 
163  m_SpaceDelimCheck = new wxCheckBox( itemStaticBoxSizer5->GetStaticBox(), ID_SPACEDELIMCHECK, _("Space"), wxDefaultPosition, wxDefaultSize, 0 );
164  m_SpaceDelimCheck->SetValue(false);
165  itemStaticBoxSizer5->Add(m_SpaceDelimCheck, 0, wxALIGN_LEFT|wxALL, 5);
166 
167  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
168  itemStaticBoxSizer5->Add(itemBoxSizer10, 0, wxALIGN_LEFT|wxRIGHT, 5);
169 
170  m_OtherDelimCheck = new wxCheckBox( itemStaticBoxSizer5->GetStaticBox(), ID_OTHERDELIMCHECK, _("Other"), wxDefaultPosition, wxDefaultSize, 0 );
171  m_OtherDelimCheck->SetValue(false);
173  m_OtherDelimCheck->SetToolTip(_("For a separators not listed above"));
174  itemBoxSizer10->Add(m_OtherDelimCheck, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
175 
176  m_DelimTextCtrl = new wxTextCtrl( itemStaticBoxSizer5->GetStaticBox(), ID_TABLEDELIMITERTEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(20, -1), 0 );
177  m_DelimTextCtrl->SetMaxLength(1);
179  m_DelimTextCtrl->SetToolTip(_("Type single character tabel delimiter"));
180  itemBoxSizer10->Add(m_DelimTextCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxVERTICAL);
183  itemBoxSizer4->Add(itemBoxSizer13, 0, wxALIGN_TOP|wxALL, 5);
184 
185  m_MergeAdjacentDelimiters = new wxCheckBox( itemPanel1, ID_ADJACENTDELIMITERSCHECK, _("Treat adjacent delimiters as a single delimiter"), wxDefaultPosition, wxDefaultSize, 0 );
186  m_MergeAdjacentDelimiters->SetValue(false);
187  itemBoxSizer13->Add(m_MergeAdjacentDelimiters, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
188 
189  wxArrayString m_TextQualifierStrings;
190  m_TextQualifierStrings.Add(_("&Double Quote: \""));
191  m_TextQualifierStrings.Add(_("&Single Quote: '"));
192  m_TextQualifierStrings.Add(_("&No Text Qualifier"));
193  m_TextQualifier = new wxRadioBox( itemPanel1, ID_RADIOBOX, _("Text Qualifier Selection"), wxDefaultPosition, wxDefaultSize, m_TextQualifierStrings, 3, wxRA_SPECIFY_ROWS );
194  m_TextQualifier->SetSelection(2);
195  itemBoxSizer13->Add(m_TextQualifier, 0, wxALIGN_LEFT|wxALL, 5);
196 
197  wxStaticBox* itemStaticBoxSizer16Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Table Data"));
198  wxStaticBoxSizer* itemStaticBoxSizer16 = new wxStaticBoxSizer(itemStaticBoxSizer16Static, wxHORIZONTAL);
199  itemBoxSizer2->Add(itemStaticBoxSizer16, 1, wxGROW|wxALL, 5);
200 
201  m_ListCtrlPanel = new wxPanel( itemStaticBoxSizer16->GetStaticBox(), ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
202  itemStaticBoxSizer16->Add(m_ListCtrlPanel, 1, wxGROW|wxTOP, 5);
203 
204  wxBoxSizer* itemBoxSizer18 = new wxBoxSizer(wxHORIZONTAL);
205  m_ListCtrlPanel->SetSizer(itemBoxSizer18);
206 
207  m_DelimiterListCtrl = new CTableImportListCtrl( m_ListCtrlPanel, ID_CTABLEIMPORTLISTCTRL2, wxDefaultPosition, wxSize(100, 100), 0 );
208  itemBoxSizer18->Add(m_DelimiterListCtrl, 1, wxGROW|wxALL, 5);
209 
210 ////@end CTableDelimitersPanel content construction
211 }
212 
214 {
215  if (show) {
216  m_TabDelimCheck->SetValue(false);
217  m_SemicolonDelimCheck->SetValue(false);
218  m_CommaDelimCheck->SetValue(false);
219  m_SpaceDelimCheck->SetValue(false);
220  m_OtherDelimCheck->SetValue(false);
221  m_DelimTextCtrl->SetValue(wxT(""));
222 
223  if (!m_ImportedTableData.IsNull()) {
226 
227  for (size_t i=0; i<m_ImportedTableData->GetDelimiters().size(); ++i) {
228  if (m_ImportedTableData->GetDelimiters()[i] == '\t') {
229  m_TabDelimCheck->SetValue(true);
230  }
231  else if (m_ImportedTableData->GetDelimiters()[i] == ';') {
232  m_SemicolonDelimCheck->SetValue(true);
233  }
234  else if (m_ImportedTableData->GetDelimiters()[i] == ',') {
235  m_CommaDelimCheck->SetValue(true);
236  }
237  else if (m_ImportedTableData->GetDelimiters()[i] == ' ') {
238  m_SpaceDelimCheck->SetValue(true);
239  }
240  else {
241  m_OtherDelimCheck->SetValue(true);
242  char delim = m_ImportedTableData->GetDelimiters()[i];
243  string delim_str(1, delim);
244  m_DelimTextCtrl->SetValue(ToWxString(delim_str));
245  }
246  }
247 
248  m_MergeAdjacentDelimiters->SetValue(
250 
251  char quote_char = m_ImportedTableData->GetDelimiterRules().GetQuoteChar();
252 
253  if (quote_char == '\"')
254  m_TextQualifier->SetSelection(0);
255  if (quote_char == '\'')
256  m_TextQualifier->SetSelection(1);
257  if (quote_char == ' ')
258  m_TextQualifier->SetSelection(2);
259  }
260 
261  m_DelimsInitialized = true;
262  }
263  else {
264  m_DelimsInitialized = false;
265  }
266 
267 
268  return wxPanel::Show(show);
269 }
270 
271 void CTableDelimitersPanel::SetMainTitle(const wxString& title)
272 {
273 }
274 
276 {
277  return true;
278 }
279 
281 {
282  // Don't do this before panel is displayed (in that case we use
283  // the delimiter(s) already in the m_ImportedTableData)
284  if (!m_DelimsInitialized)
285  return;
286 
287  vector<char> new_delims;
288 
289  if (m_TabDelimCheck->GetValue())
290  new_delims.push_back('\t');
291  if (m_SemicolonDelimCheck->GetValue())
292  new_delims.push_back(';');
293  if (m_CommaDelimCheck->GetValue())
294  new_delims.push_back(',');
295  if (m_SpaceDelimCheck->GetValue())
296  new_delims.push_back(' ');
297  if (m_OtherDelimCheck->GetValue()) {
298  string sval = ToStdString(m_DelimTextCtrl->GetValue());
299  if (sval.length() == 1) {
300  char schar = sval.c_str()[0];
301  if (schar != '\t' &&
302  schar != ';' &&
303  schar != ',' &&
304  schar != ' ')
305  new_delims.push_back(schar);
306  }
307  }
308 
309  bool merge_delimiters = m_MergeAdjacentDelimiters->GetValue();
310 
311  // Get text qualifier based on selection number in corresponding
312  // radio box.
313  int selected_qualifier_idx = m_TextQualifier->GetSelection();
314  char text_qualifier = ' ';
315  if (selected_qualifier_idx == 0)
316  text_qualifier = '\"';
317  else if (selected_qualifier_idx == 1)
318  text_qualifier ='\'';
319 
320  if (!m_ImportedTableData.IsNull()) {
321  bool update = false;
322 
324  merge_delimiters) {
326  update = true;
327  }
328 
330  text_qualifier) {
332  update = true;
333  }
334 
337  update = true;
338  }
339 
340  if (update) {
343  }
344 
345  ERR_POST(Info << "Import Table User Updated Delimiters");
347  }
348 }
349 
350 
351 void CTableDelimitersPanel::SetRegistryPath( const string& path )
352 {
353  m_RegPath = path;
354 }
355 
356 
358 {
359 }
360 
361 
363 {
364 }
365 
367 {
368  return true;
369 }
370 wxBitmap CTableDelimitersPanel::GetBitmapResource( const wxString& name )
371 {
372  // Bitmap retrieval
373 ////@begin CTableDelimitersPanel bitmap retrieval
374  wxUnusedVar(name);
375  return wxNullBitmap;
376 ////@end CTableDelimitersPanel bitmap retrieval
377 }
378 wxIcon CTableDelimitersPanel::GetIconResource( const wxString& name )
379 {
380  // Icon retrieval
381 ////@begin CTableDelimitersPanel icon retrieval
382  wxUnusedVar(name);
383  return wxNullIcon;
384 ////@end CTableDelimitersPanel icon retrieval
385 }
386 
387 void CTableDelimitersPanel::OnTabDelimCheckClick( wxCommandEvent& event )
388 {
390 }
391 
393 {
394  UpdateDelimiters();
395 }
396 
398 {
399  UpdateDelimiters();
400 }
401 
403 {
404  UpdateDelimiters();
405 }
406 
408 {
409  UpdateDelimiters();
410 }
411 
413 {
414  UpdateDelimiters();
415 }
416 
418 {
419  UpdateDelimiters();
420 }
421 
422 void CTableDelimitersPanel::OnRadioBoxSelected( wxCommandEvent& event )
423 {
424  UpdateDelimiters();
425 }
426 
428 {
429  // Update the whole control when dragging. This is needed because there
430  // may be header rows where distrubtion across columns is based on width
431  // of each column (basically they are left-justified into row irrespective
432  // of column boundaries)
433  m_DelimiterListCtrl->Refresh();
434 }
435 
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
#define ID_TABDELIMCHECK
#define ID_SPACEDELIMCHECK
#define ID_TABLEDELIMITERTEXTCTRL
#define ID_SEMICOLONDELIMCHECK
#define ID_OTHERDELIMCHECK
#define ID_ADJACENTDELIMITERSCHECK
#define ID_COMMADELIMCHECK
void SetQuoteChar(char c)
Get set quote character used for quoting strings.
void SetDelimiters(const vector< char > &d)
Get/set delimiter characters.
void SetMergeDelimiters(bool b)
Get/set merge delimiters rule for tokenizing table into fields.
void LogDelims() const
Write delims information to log.
bool MatchingDelimiters(vector< char > other_delims) const
Return true if the delimiters match (even if order is different)
void OnOtherDelimCheckClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_OTHERDELIMCHECK
void OnAdjacentDelimitersCheckClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_ADJACENTDELIMITERSCHECK
bool Create(wxWindow *parent, wxWindowID id=ID_CTABLEDELIMITERSPANEL, const wxString &caption=_("Set Table Delimiters"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
void OnTableDelimiterTextCtrlTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_TABLEDELIMITERTEXTCTRL
void OnCtableImportListctrlColDragging(wxListEvent &event)
void OnSemiColonDelimCheckClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_SEMICOLONDELIMCHECK
void UpdateDelimiters()
Called after any options that may update the partioning of the table into columns are updated.
void OnCommaDelimCheckClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_COMMADELIMCHECK
void SetRegistryPath(const string &path)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnTabDelimCheckClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_TABDELIMCHECK
virtual bool Show(bool show=true)
Override Show() to allow initialization each time window is displayed.
CRef< CTableImportDataSource > m_ImportedTableData
void OnRadioBoxSelected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBOX_SELECTED event handler for ID_RADIOBOX
CTableImportListCtrl * m_DelimiterListCtrl
void SetMainTitle(const wxString &title)
void OnSpaceDelimCheckClick(wxCommandEvent &event)
wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_SPACEDELIMCHECK
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
const vector< char > & GetDelimiters() const
Return copy of current delimiter(s)
const CTableDelimiterRules & GetDelimiterRules() const
Get set all delimiter rules (for delimited tables)
void RecomputeFields(bool recreate_columns, int recompute_count=-1)
Updated the individual rows and columns to match the current delimiter choice.
void SetViewType(eDataViewType t)
Set/get view type.
void SetDataSource(CRef< CTableImportDataSource > ds)
Set/update data source (used to refresh view to match data source column info)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#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
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
USING_SCOPE(objects)
#define ID_RADIOBOX
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Wed Jun 19 17:02:06 2024 by modify_doxy.py rev. 669887