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

Go to the SVN repository for this file.

1 /* $Id: parse_text_dlg.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Igor Filippov
27  *
28  * File Description:
29  *
30  */
31 #include <ncbi_pch.hpp>
32 
33 // For compilers that support precompilation, includes "wx/wx.h".
34 #include "wx/wxprec.h"
35 
36 #ifdef __BORLANDC__
37 #pragma hdrstop
38 #endif
39 
40 #ifndef WX_PRECOMP
41 #include "wx/wx.h"
42 #endif
43 #include <wx/display.h>
44 
60 
64 
66 
67 
69 
70 IMPLEMENT_DYNAMIC_CLASS( CParseTextDlg, CBulkCmdDlg )
71 
72 
73 BEGIN_EVENT_TABLE( CParseTextDlg, CBulkCmdDlg )
74 
75 ////@begin CParseTextDlg event table entries
77 ////@end CParseTextDlg event table entries
78 
80 
82 {
83  Init();
84 }
85 
86 CParseTextDlg::CParseTextDlg( wxWindow* parent, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
87 {
88  Init();
89  Create(parent, wb, id, caption, pos, size, style);
90  SetRegistryPath("Dialogs.Edit.ParseText");
91  LoadSettings();
92 }
93 
94 bool CParseTextDlg::Create( wxWindow* parent, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
95 {
96 ////@begin CParseTextDlg creation
97  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
98  CBulkCmdDlg::Create( parent, wb, id, caption, pos, size, style );
99 
100  CreateControls();
101  if (GetSizer())
102  {
103  GetSizer()->SetSizeHints(this);
104  }
105  Centre();
106 ////@end CParseTextDlg creation
107  return true;
108 }
109 
111 {
112 ////@begin CParseTextDlg destruction
113  SaveSettings();
114 ////@end CParseTextDlg destruction
115 }
116 
117 static const char* kFrameWidth = "Frame Width";
118 static const char* kFrameHeight = "Frame Height";
119 static const char* kFramePosX = "Frame Position X";
120 static const char* kFramePosY = "Frame Position Y";
121 
122 void CParseTextDlg::SetRegistryPath(const string& reg_path)
123 {
124  m_RegPath = reg_path;
125 }
126 
128 {
129  if (m_RegPath.empty())
130  return;
131 
133  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
134 
135  view.Set(kFrameWidth,GetScreenRect().GetWidth());
136  view.Set(kFrameHeight,GetScreenRect().GetHeight());
137  view.Set(kFramePosX,GetScreenPosition().x);
138  view.Set(kFramePosY,GetScreenPosition().y);
139 }
140 
141 
143 {
144  if (m_RegPath.empty())
145  return;
146 
148  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
149 
150  int width = view.GetInt(kFrameWidth, -1);
151  int height = view.GetInt(kFrameHeight, -1);
152  if (width >= 0 && height >= 0)
153  SetSize(wxSize(width,height));
154 
155  int pos_x = view.GetInt(kFramePosX, -1);
156  int pos_y = view.GetInt(kFramePosY, -1);
157 
158  if (pos_x >= 0 && pos_y >= 0)
159  {
160  int max_x = 0;
161  for (auto i = 0; i < wxDisplay::GetCount(); i++) // also see gui/widgets/wx/wx_utils.cpp:CorrectWindowRect() for alternative window position validation
162  {
163  wxDisplay display(i);
164  max_x += display.GetGeometry().GetWidth();
165  }
166  if (pos_x + width > max_x) pos_x = wxGetDisplaySize().GetWidth()-width-5;
167  if (pos_y + height > wxGetDisplaySize().GetHeight()) pos_y = wxGetDisplaySize().GetHeight()-height-5;
168 
169  SetPosition(wxPoint(pos_x,pos_y));
170  }
171 }
172 
173 
175 {
176 ////@begin CParseTextDlg member initialisation
177  m_Constraint = NULL;
178  m_Field1 = NULL;
179  m_Field2 = NULL;
180 ////@end CParseTextDlg member initialisation
181 }
182 
184 {
185  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
186  SetSizer(itemBoxSizer1);
187 
188  wxPanel* itemCBulkCmdDlg1 = new wxPanel(this, wxID_ANY);
189  itemBoxSizer1->Add(itemCBulkCmdDlg1, 1, wxGROW, 0);
190 
191  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
192  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
193 
194  m_ParseOptions = new CParseTextOptionsDlg(itemCBulkCmdDlg1);
195  itemBoxSizer2->Add(m_ParseOptions, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
196 
197  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
198  itemBoxSizer2->Add(itemBoxSizer3, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
199 
200  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
201  itemBoxSizer3->Add(itemBoxSizer4, 1, wxALIGN_CENTER_VERTICAL|wxALL, 2);
202 
203  wxStaticText* itemStaticText1 = new wxStaticText( itemCBulkCmdDlg1, wxID_STATIC, _("From"), wxDefaultPosition, wxDefaultSize, 0 );
204  itemBoxSizer4->Add(itemStaticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
205 
206  m_Field1 = new CQualChoicePanel(itemCBulkCmdDlg1);
207  itemBoxSizer4->Add(m_Field1, 0, wxALIGN_CENTER_HORIZONTAL, 0);
208 
209  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
210  itemBoxSizer3->Add(itemBoxSizer5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 2);
211 
212  wxStaticText* itemStaticText2 = new wxStaticText( itemCBulkCmdDlg1, wxID_STATIC, _("To"), wxDefaultPosition, wxDefaultSize, 0 );
213  itemBoxSizer5->Add(itemStaticText2, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
214 
215  m_Field2 = new CQualChoicePanel(itemCBulkCmdDlg1);
216  itemBoxSizer5->Add(m_Field2, 0, wxALIGN_CENTER_HORIZONTAL, 0);
217 
219  m_Constraint = new CConstraintPanel( itemCBulkCmdDlg1, m_TopSeqEntry);
220  itemBoxSizer2->Add(m_Constraint, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
221 
222  COkCancelPanel* panelOkCancel = new COkCancelPanel( itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
223  itemBoxSizer2->Add(panelOkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
224 }
225 
227 {
228  return true;
229 }
230 wxBitmap CParseTextDlg::GetBitmapResource( const wxString& name )
231 {
232  // Bitmap retrieval
233 ////@begin CParseTextDlg bitmap retrieval
234  wxUnusedVar(name);
235  return wxNullBitmap;
236 ////@end CParseTextDlg bitmap retrieval
237 }
238 wxIcon CParseTextDlg::GetIconResource( const wxString& name )
239 {
240  // Icon retrieval
241 ////@begin CParseTextDlg icon retrieval
242  wxUnusedVar(name);
243  return wxNullIcon;
244 ////@end CParseTextDlg icon retrieval
245 }
246 
247 void CParseTextDlg::ProcessUpdateFeatEvent( wxCommandEvent& event )
248 {
250 }
251 
253 {
254  wxWindowList &slist = win->GetChildren();
255  for (wxWindowList::iterator iter = slist.begin(); iter != slist.end(); ++iter)
256  {
257  wxWindow* child = *iter;
258  CFeatureTypePanel* panel = dynamic_cast<CFeatureTypePanel*>(child);
259  if (panel)
260  {
263  }
264  else
265  {
267  }
268  }
269 }
270 
272 {
273  m_Field1->SetSelection(field_type);
274 }
275 
277 {
278  m_Field2->SetSelection(field_type);
279 }
280 
282 {
284 
286 
288  if (!action1)
289  return cmd;
290 
292  if (!action2)
293  return cmd;
294 
295  CFieldNamePanel* field_name_panel = m_Constraint->GetFieldNamePanel();
296  string ncRNA_class1;
297  auto subtype1 = GetSubtype(m_Field1->GetFieldNamePanel(), ncRNA_class1);
298 
299  string ncRNA_class;
300  auto subtype = GetSubtype(field_name_panel, ncRNA_class);
301  CRef<CEditingActionConstraint> constraint =
303  m_Field1->GetField(),
305  subtype1,
306  ncRNA_class1,
307  field_name_panel ? field_name_panel->GetFieldName(true) : m_Constraint->GetFieldType(),
309  subtype,
310  ncRNA_class,
312 
313  action1->SetConstraint(constraint);
314 
315  int num_conflicts = action1->CheckForExistingText(action2, IEditingAction::eActionType_ParseFrom, *m_ParseOptions->GetParseOptions());
316  edit::EExistingText existing_text = x_GetExistingTextHandling (num_conflicts, true);
317  if (existing_text == edit::eExistingText_cancel)
318  return cmd;
319 
320 
321  action2->SetExistingText(existing_text);
322  action1->ParseFrom(*m_ParseOptions->GetParseOptions(), action2);
323 
324  cmd = action1->GetActionCommand();
325 
326  return cmd;
327 }
328 
329 IMPLEMENT_DYNAMIC_CLASS( CQualChoicePanel, wxPanel )
330 
331 BEGIN_EVENT_TABLE( CQualChoicePanel, wxPanel )
333 
335 {
336  Init();
337 }
338 
339 CQualChoicePanel::CQualChoicePanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
340 {
341  Init();
342  Create(parent, id, pos, size, style);
343 }
344 
345 bool CQualChoicePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
346 {
347  wxPanel::Create( parent, id, pos, size, style );
348  CreateControls();
349  if (GetSizer())
350  {
351  GetSizer()->SetSizeHints(this);
352  }
353  Centre();
354  return true;
355 }
356 
358 {
359 }
360 
362 {
363 }
364 
366 {
367  CQualChoicePanel* itemPanel1 = this;
368 
369  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
370  itemPanel1->SetSizer(itemBoxSizer2);
371 
372  m_Notebook = new wxChoicebook(itemPanel1, wxID_ANY, wxDefaultPosition, wxDefaultSize);
373  itemBoxSizer2->Add(m_Notebook, 0, wxGROW|wxALL, 5);
374 
376  m_Notebook->AddPage(panel1,_("Taxname"));
377  panel1->SetFieldName("taxname");
378 
380  m_Notebook->AddPage(panel2,_("Source"));
381 
383  m_Notebook->AddPage(panel3,_("Feature"));
384  panel3->PopulateFeatureListbox();
385 
387  m_Notebook->AddPage(panel4,_("CDS-Gene-Prot-mRNA"));
388  panel4->SetFieldName("protein name");
389 
391  m_Notebook->AddPage(panel5,_("RNA"));
392  panel5->SetFieldName("product");
393 
396  m_Notebook->AddPage(panel6,_("MolInfo"));
397  panel6->SetFieldName("molecule");
398 
401  m_Notebook->AddPage(panel7,_("Pub"));
402  panel7->SetFieldName("title");
403 
405  m_Notebook->AddPage(panel8,_("Structured Comment"));
406 
409  m_Notebook->AddPage(panel9,_("DBLink"));
410  panel9->SetFieldName("title");
411 
414  m_Notebook->AddPage(panel10,_("Misc"));
416 
417  wxPanel *panel11 = new wxPanel(m_Notebook);
418  m_Notebook->AddPage(panel11, wxString(kLocalId));
419 
420  wxPanel *panel12 = new wxPanel(m_Notebook);
421  m_Notebook->AddPage(panel12, wxString(kDefinitionLineLabel));
422 
423  wxPanel *panel13 = new wxPanel(m_Notebook);
424  m_Notebook->AddPage(panel13, wxString(kBankITComment));
425 
426  wxPanel *panel14 = new wxPanel(m_Notebook);
427  m_Notebook->AddPage(panel14, wxString(kTaxnameAfterBinomial));
428 
429  wxPanel *panel15 = new wxPanel(m_Notebook);
430  m_Notebook->AddPage(panel15, wxString("Dbxref"));
431 
432  wxPanel *panel16 = new wxPanel(m_Notebook);
433  m_Notebook->AddPage(panel16, wxString(kFileSeqId));
434 
436  m_Notebook->AddPage(panel17, wxString(kGeneralId));
437 
438  wxPanel *panel18 = new wxPanel(m_Notebook);
439  m_Notebook->AddPage(panel18, wxString(kComment));
440 
441  wxPanel *panel19 = new wxPanel(m_Notebook);
442  m_Notebook->AddPage(panel19, wxString(kFlatFile));
443 }
444 
446 {
447  if (page != wxNOT_FOUND)
448  {
449  m_Notebook->SetSelection(page);
450  }
451 }
452 
453 string CQualChoicePanel::GetField(bool subfield)
454 {
455  string name;
456  if (m_Notebook)
457  {
458  wxWindow* win = m_Notebook->GetCurrentPage();
459  CFieldNamePanel* panel = dynamic_cast<CFieldNamePanel*>(win);
460  if (panel)
461  {
462  name = panel->GetFieldName(subfield);;
463  }
464  else
465  {
466  name = GetFieldType();
467  }
468  }
469  return name;
470 }
471 
473 {
474  string field_type;
475  int sel = m_Notebook->GetSelection();
476  if (sel != wxNOT_FOUND)
477  {
478  field_type = m_Notebook->GetPageText(sel).ToStdString();
479  }
480  return field_type;
481 }
482 
484 {
485  CFieldNamePanel* name_panel(NULL);
486  if (m_Notebook)
487  {
488  wxWindow* win = m_Notebook->GetCurrentPage();
489  name_panel = dynamic_cast<CFieldNamePanel*>(win);
490  }
491  return name_panel;
492 }
493 
494 
496 {
498  string field = GetField();
499 
500  if (NStr::IsBlank(field))
501  return cmd;
502 
504  string ncRNA_class;
505  int subtype = GetSubtype(GetFieldNamePanel(), ncRNA_class);
506  cmd = CreateAction(seh, field, field_type, subtype);
507  return cmd;
508 }
509 
511 {
512  return true;
513 }
514 
515 wxBitmap CQualChoicePanel::GetBitmapResource( const wxString& name )
516 {
517  wxUnusedVar(name);
518  return wxNullBitmap;
519 }
520 
521 wxIcon CQualChoicePanel::GetIconResource( const wxString& name )
522 {
523  wxUnusedVar(name);
524  return wxNullIcon;
525 }
526 
527 
529 
530 // TODO
531 // GenBank Flatfile 1902
532 
533 
objects::CSeq_entry_Handle m_TopSeqEntry
bool Create(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
bool GetTopLevelSeqEntryAndProcessor()
edit::EExistingText x_GetExistingTextHandling(int num_conflicts, bool allow_multiple=false)
virtual bool SetFieldName(const string &field)
string GetFieldType(void) const
CFieldNamePanel * GetFieldNamePanel(void)
CRef< edit::CStringConstraint > GetStringConstraint(void)
static vector< string > GetFieldNames()
void ListPresentFeaturesFirst(const objects::CSeq_entry_Handle &entry, vector< const objects::CFeatListItem * > *featlist=nullptr)
virtual bool SetFieldName(const string &field)
void SetFieldNames(const vector< string > &field_names)
virtual string GetFieldName(const bool subfield=false)=0
Returns the name of the field as selected in the panel.
static EFieldType GetFieldTypeFromName(const string &field_type_name)
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
static vector< string > GetStrings()
static vector< string > GetFieldNames()
void UpdateChildrenFeaturePanels(wxWindow *win)
CQualChoicePanel * m_Field1
CConstraintPanel * m_Constraint
bool Create(wxWindow *parent, IWorkbench *wb, wxWindowID id=wxID_ANY, const wxString &caption=_("Parse Text"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
static bool ShowToolTips()
virtual void LoadSettings()
void SetFromFieldType(EFieldType field_type)
virtual void SetRegistryPath(const string &reg_path)
CQualChoicePanel * m_Field2
wxIcon GetIconResource(const wxString &name)
void SetToFieldType(EFieldType field_type)
wxBitmap GetBitmapResource(const wxString &name)
virtual CRef< CCmdComposite > GetCommand()
virtual void SaveSettings() const
void ProcessUpdateFeatEvent(wxCommandEvent &event)
CParseTextOptionsDlg * m_ParseOptions
CRef< objects::edit::CParseTextOptions > GetParseOptions()
static vector< string > GetFieldNames(bool extended=false)
wxIcon GetIconResource(const wxString &name)
void SetSelection(int page)
CFieldNamePanel * GetFieldNamePanel(void)
static bool ShowToolTips()
wxChoicebook * m_Notebook
CIRef< IEditingAction > CreateEditingAction(CSeq_entry_Handle seh)
string GetField(bool subfield=true)
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
wxBitmap GetBitmapResource(const wxString &name)
string GetFieldType(void)
virtual bool SetFieldName(const string &field)
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
CSeq_entry_Handle –.
virtual bool SetFieldName(const string &field)
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
#define _(proto)
Definition: ct_nlmzip_i.h:78
CRef< CEditingActionConstraint > CreateEditingActionConstraint(const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class, const string &const_field, CFieldNamePanel::EFieldType const_field_type, int const_subtype, string &const_ncRNA_class, CRef< CConstraintMatcher >constraint)
int GetSubtype(CFieldNamePanel *field_name_panel, string &ncRNA_class)
CIRef< IEditingAction > CreateAction(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class=kEmptyStr, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL))
#define EVT_UPDATE_FEATURE_LIST(id, fn)
const char * kDefinitionLineLabel
const char * kFileSeqId
const char * kComment
const char * kLocalId
const char * kTaxnameAfterBinomial
const char * kFlatFile
const char * kGeneralId
const char * kBankITComment
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static const char * kFramePosX
static const char * kFrameHeight
static const char * kFramePosY
static const char * kFrameWidth
static static static wxID_ANY
EExistingText
@ eExistingText_cancel
wxRect GetScreenRect(const wxWindow &win)
Definition: wx_utils.cpp:783
Modified on Wed Sep 04 14:58:32 2024 by modify_doxy.py rev. 669887