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

Go to the repository for this file.

1 /* $Id: validate_frame.cpp 47817 2025-01-29 20:12:49Z asztalos $
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 
29 
30 #include <ncbi_pch.hpp>
35 #include <gui/objutils/objects.hpp>
39 #include <gui/objutils/utils.hpp>
41 #include <objmgr/util/sequence.hpp>
53 #include <objmgr/seqdesc_ci.hpp>
59 #include <objects/seq/Pubdesc.hpp>
61 #include <objects/pub/Pub.hpp>
63 // for validator response commands
68 
70 
71 // For compilers that support precompilation, includes "wx/wx.h".
72 #include "wx/wxprec.h"
73 
74 #ifdef __BORLANDC__
75 #pragma hdrstop
76 #endif
77 
78 #ifndef WX_PRECOMP
79 #include "wx/wx.h"
80 #endif
81 
82 ////@begin includes
83 #include "wx/imaglist.h"
84 #include <wx/display.h>
85 #include <wx/filename.h>
86 #include <wx/hyperlink.h>
87 ////@end includes
88 
89 
90 ////@begin XPM images
91 ////@end XPM images
92 
94 
95 
96 /*
97  * CValidateFrame type definition
98  */
99 
101 
102 
103 /*
104  * CValidateFrame event table definition
105  */
106 
107 BEGIN_EVENT_TABLE( CValidateFrame, wxFrame )
108 
109 ////@begin CValidateFrame event table entries
118 ////@end CValidateFrame event table entries
120 
121 /*
122  * CValidateFrame constructors
123  */
124 
126  : m_Workbench(NULL)
127 {
128  Init();
129 }
130 
131 CValidateFrame::CValidateFrame( wxWindow* parent, IWorkbench* wb, CRef<CUser_object> params, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
132  : m_Workbench(wb), m_params(params)
133 {
134  SetRegistryPath("Dialogs.Edit.Validate");
135  Init();
136  Create( parent, id, caption, pos, size, style );
137 
139  LoadSettings();
140 }
141 
142 
143 /*
144  * CValidateFrame creator
145  */
146 
147 bool CValidateFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
148 {
149 ////@begin CValidateFrame creation
150  wxFrame::Create( parent, id, caption, pos, size, style );
151 
152  CreateControls();
153  Centre(wxBOTH|wxCENTRE_ON_SCREEN);
154 ////@end CValidateFrame creation
155  return true;
156 }
157 
158 
159 /*
160  * CValidateFrame destructor
161  */
162 
164 {
165  SaveSettings();
166  m_Instance = nullptr;
167 }
168 
169 static const char* kFrameWidth = "Frame Width";
170 static const char* kFrameHeight = "Frame Height";
171 static const char* kFramePosX = "Frame Position X";
172 static const char* kFramePosY = "Frame Position Y";
173 static const char* kValidateGenomes = "Validate genomes";
174 
175 void CValidateFrame::SetRegistryPath(const string& reg_path)
176 {
177  m_RegPath = reg_path;
178 }
179 
181 {
182  if (m_RegPath.empty())
183  return;
184 
186  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
187 
188  view.Set(kFrameWidth,GetScreenRect().GetWidth());
189  view.Set(kFrameHeight,GetScreenRect().GetHeight());
190  view.Set(kFramePosX,GetScreenPosition().x);
191  view.Set(kFramePosY,GetScreenPosition().y);
193 }
194 
195 
197 {
198  if (m_RegPath.empty())
199  return;
200 
202  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
203 
204  int width = view.GetInt(kFrameWidth, -1);
205  int height = view.GetInt(kFrameHeight, -1);
206  if (width >= 0 && height >= 0)
207  SetSize(wxSize(width,height));
208  else
210 
211  int pos_x = view.GetInt(kFramePosX, -1);
212  int pos_y = view.GetInt(kFramePosY, -1);
213 
214  if (pos_x >= 0 && pos_y >= 0) {
215  int max_x = 0;
216  for (unsigned i = 0; i < wxDisplay::GetCount(); i++) { // also see gui/widgets/wx/wx_utils.cpp:CorrectWindowRect() for alternative window position validation
217  wxDisplay display(i);
218  max_x += display.GetGeometry().GetWidth();
219  }
220 
221  if (pos_x + width > max_x)
222  pos_x = wxGetDisplaySize().GetWidth()-width-5;
223 
224  if (pos_y + height > wxGetDisplaySize().GetHeight())
225  pos_y = wxGetDisplaySize().GetHeight()-height-5;
226 
227  SetPosition(wxPoint(pos_x,pos_y));
228  }
229 }
230 
231 
232 /*
233  * Member initialisation
234  */
235 
237 {
238  m_Panel = NULL;
239  m_DoneButton = NULL;
240 
241  if (!m_RegPath.empty()) {
243  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
246  }
247 }
248 
249 
250 /*
251  * Control creation for CValidateFrame
252  */
253 
255 {
256 ////@begin CValidateFrame content construction
257  // Generated by DialogBlocks, 18/10/2016 11:02:51 (unregistered)
258 
259  CValidateFrame* itemFrame1 = this;
260 
261  wxPanel* itemPanel2 = new wxPanel(itemFrame1);
262  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
263  itemPanel2->SetSizer(itemBoxSizer1);
264 
265 
266  m_Panel = new CValidatePanel( itemPanel2, m_Workbench, m_params);
267  itemBoxSizer1->Add(m_Panel, 1, wxGROW|wxALL, 0);
268  m_Panel->LoadData();
269 
270  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
271  itemBoxSizer1->Add(itemBoxSizer6, 0, wxGROW|wxALL,0);
272 
273  if (RunningInsideNCBI()) {
274  wxCheckBox* validate_genomes = new wxCheckBox(itemPanel2, ID_VALIDATE_FRAME_GENOMES_CHKBOX, _("Validate Genomes"), wxDefaultPosition, wxDefaultSize, 0);
275  validate_genomes->SetValue(m_ValidateGenomes);
276  itemBoxSizer6->Add(validate_genomes, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL| wxALL, 5);
277 
278  itemBoxSizer6->AddStretchSpacer();
279 
280  wxButton* itemButton8 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_REPORT_BTN, _("Report"), wxDefaultPosition, wxDefaultSize, 0 );
281  itemBoxSizer6->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
282 
283 
284  if (x_AllowDoneButton())
285  {
286  m_DoneButton = new wxButton( itemPanel2, ID_VALIDATE_FRAME_DONE_BTN, _("Done"), wxDefaultPosition, wxDefaultSize, 0 );
287  itemBoxSizer6->Add(m_DoneButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
288  }
289 
290  wxButton* itemButton11 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_SEQUESTER_BTN, _("Sequester"), wxDefaultPosition, wxDefaultSize, 0 );
291  itemBoxSizer6->Add(itemButton11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
292 
293  wxButton* itemButton12 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_SEGREGATE_BTN, _("Segregate"), wxDefaultPosition, wxDefaultSize, 0 );
294  itemBoxSizer6->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
295  }
296 
297 
298  wxButton* itemButton7 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_REFRESH, _("Refresh"), wxDefaultPosition, wxDefaultSize, 0 );
299  itemBoxSizer6->Add(itemButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
300 
301  wxButton* itemButton10 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_DISMISS, _("Dismiss"), wxDefaultPosition, wxDefaultSize, 0 );
302  itemBoxSizer6->Add(itemButton10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
303 
304  wxHyperlinkCtrl* itemHyperlinkCtrl = new wxHyperlinkCtrl( itemPanel2, wxID_HELP, _("Help"), wxT("https://www.ncbi.nlm.nih.gov/tools/gbench/manual8/#validator"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
305  itemHyperlinkCtrl->SetForegroundColour(wxColour(192, 192, 192));
306  itemBoxSizer6->Add(itemHyperlinkCtrl, 0, wxALIGN_CENTER_VERTICAL, 5);
307 
308  itemBoxSizer6->AddStretchSpacer();
309 
310 ////@end CValidateFrame content construction
311 }
312 
313 /*
314  * Should we show tooltips?
315  */
316 
318 {
319  return true;
320 }
321 
322 /*
323  * Get bitmap resources
324  */
325 
326 wxBitmap CValidateFrame::GetBitmapResource( const wxString& name )
327 {
328  // Bitmap retrieval
329 ////@begin CValidateFrame bitmap retrieval
330  wxUnusedVar(name);
331  return wxNullBitmap;
332 ////@end CValidateFrame bitmap retrieval
333 }
334 
335 /*
336  * Get icon resources
337  */
338 
339 wxIcon CValidateFrame::GetIconResource( const wxString& name )
340 {
341  // Icon retrieval
342 ////@begin CValidateFrame icon retrieval
343  wxUnusedVar(name);
344  return wxNullIcon;
345 ////@end CValidateFrame icon retrieval
346 }
347 
348 void CValidateFrame::OnDismiss(wxCommandEvent& event )
349 {
350  Close();
351 }
352 
353 void CValidateFrame::OnSequester( wxCommandEvent& event )
354 {
355  if (!m_Workbench)
356  return;
357  set<CBioseq_Handle> selected;
358 
359  m_Panel->GetSelected(selected);
361  CSeq_entry_Handle top_seq_entry;
362 
363  m_Panel->GetTopSeqAndSeqSubmit(top_seq_entry,seq_submit);
364  if (!top_seq_entry)
365  return;
366 
367  CSequesterSets * dlg = new CSequesterSets(this, top_seq_entry, seq_submit, m_Workbench);
368 
369  dlg->SetSubsets(selected);
370  dlg->Show(true);
371 }
372 
373 
374 void CValidateFrame::OnSegregate( wxCommandEvent& event )
375 {
376  if (!m_Workbench)
377  return;
378  set<CBioseq_Handle> selected;
379  m_Panel->GetSelected(selected);
381  CSeq_entry_Handle top_seq_entry;
382  m_Panel->GetTopSeqAndSeqSubmit(top_seq_entry,seq_submit);
383  if (!top_seq_entry)
384  return;
385  ICommandProccessor* cmdProcessor = NULL;
387  if (srv)
388  {
389  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
390  if (!ws) return;
391 
392  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(top_seq_entry.GetScope()));
393  if (doc)
394  cmdProcessor = &doc->GetUndoManager();
395  }
396  if (!cmdProcessor)
397  return;
398 
399  CSegregateSets* dlg = new CSegregateSets(this, top_seq_entry, cmdProcessor);
400  dlg->SetSubsets(selected);
401  dlg->Show(true);
402 }
403 
404 void CValidateFrame::OnReport( wxCommandEvent& event )
405 {
407  if (!errs)
408  return;
409 
411  CSeq_entry_Handle top_seq_entry;
412  m_Panel->GetTopSeqAndSeqSubmit(top_seq_entry,seq_submit);
413  if (!top_seq_entry)
414  return;
416  CValidatorReportCfgDlg* report = new CValidatorReportCfgDlg(this, errs, objects.front().scope, top_seq_entry, seq_submit, m_Workbench);
417  report->SetWorkDir(m_Panel->GetWorkDir());
418  report->Show(true);
419 }
420 
421 void CValidateFrame::OnUpdateDoneBtn(wxUpdateUIEvent& event)
422 {
423  if (!m_DoneButton)
424  return;
426  CRegistryReadView view = gui_reg.GetReadView("Dialogs.Edit.SequesterSets");
427  bool enable = true;
428  if (view.HasField("EnableDone"))
429  enable = view.GetBool("EnableDone", true);
430 
431  event.Enable(enable);
432 }
433 
434 void CValidateFrame::OnDone( wxCommandEvent& event )
435 {
436  if (!m_DoneButton)
437  return;
439  if (!projectService) return;
440 
441  CRef<CGBWorkspace> ws = projectService->GetGBWorkspace();
442  if (!ws) return;
443 
444  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*m_Panel->GetScope()));
445  if (!doc) return;
446 
447  string errMsg;
448  try {
449  CProjectFolder& data_folder = doc->SetData();
450  if (data_folder.CanGetItems()) {
451  ITERATE(CProjectFolder::TItems, bit, data_folder.GetItems()) {
452  int pitemId = (*bit)->GetId();
453  CProjectItem* item = data_folder.FindProjectItemById(pitemId);
454  if (item) {
455  string pipe;
456  CProjectItemExtra::GetStr(*item, "SmartPipe", pipe);
457  if (!pipe.empty()) {
458  // Smart in named piped communications mode
459  CSmartClient::SendResult(doc->GetScope(), *item, CSmartClient::eUpdate);
460  }
461  else {
462  // Smart in file mode
463  doc->Save(doc->GetFileName());
464  }
465  }
466  }
467  }
468  } catch (const CException& ex) {
469  errMsg = ex.GetMsg();
470  } catch (const exception& ex) {
471  errMsg = ex.what();
472  }
473  if (!errMsg.empty()) {
474  wxMessageBox(errMsg, wxT("Smart client communication error"), wxOK|wxICON_ERROR);
475  return;
476  }
477 
478  projectService->RemoveProject(*doc);
479 
480  LoadData();
481  Refresh();
482 }
483 
484 void CValidateFrame::OnValidateGenomesChkBox(wxCommandEvent& event)
485 {
486  if (m_Panel) {
489  }
490  m_ValidateGenomes = event.IsChecked();
491 }
492 
493 
495 
496 void CValidateFrame::GetInstance( wxWindow* parent, IWorkbench* workbench, CRef<objects::CUser_object> params, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
497 {
498  if (!m_Instance)
499  {
500  m_Instance = new CValidateFrame(parent, workbench, params, id, caption, pos, size, style);
501  m_Instance->Show(true);
502  m_Instance->Raise();
503  m_Instance->SetFocus();
504  }
505  else
506  {
507  m_Instance->Raise();
508  m_Instance->SetFocus();
509  m_Instance->LoadData();
510  m_Instance->Refresh();
511  }
512 }
513 
515 {
518 
520 
521  if (indexer == e_GenBankIndexer)
522  return true;
523 
524  return false;
525 }
526 
528 {
529  m_Panel->LoadData();
530 }
531 
532 void CValidateFrame::OnRefresh(wxCommandEvent& event )
533 {
534  LoadData();
535  Refresh();
536 }
537 
539 
User-defined methods of the data storage class.
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
CGBDocument.
Definition: document.hpp:113
void Save(const wxString &abs_path)
Definition: document.cpp:503
CUndoManager & GetUndoManager()
Definition: document.hpp:158
wxString GetFileName() const
Definition: document.cpp:132
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
CProjectItem * FindProjectItemById(CProjectItem::TId id)
static bool GetStr(const objects::CProjectItem &pi, const string &tag, string &value)
CProjectService - a service providing API for operations with Workspaces and Projects.
void RemoveProject(CGBDocument &doc)
CRef< objects::CGBWorkspace > GetGBWorkspace()
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
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
bool HasField(const string &key) const
Does a field with this section and key exist in this view?
Definition: reg_view.cpp:352
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
void SetSubsets(const set< objects::CBioseq_Handle > &selected)
CSeq_entry_Handle –.
void SetSubsets(const set< objects::CBioseq_Handle > &selected)
static void SendResult(objects::CScope *scope, const objects::CProjectItem &projitem, EResultType result_type)
static void SetIncludeGenomes(objects::CUser_object &params, bool val)
void Init()
Initialises member variables.
void LoadData(void)
void OnValidateGenomesChkBox(wxCommandEvent &event)
void OnSegregate(wxCommandEvent &event)
static bool ShowToolTips()
Should we show tooltips?
CValidatePanel * m_Panel
virtual void SaveSettings() const
CValidateFrame()
Constructors.
CRef< objects::CUser_object > m_params
void OnDone(wxCommandEvent &event)
void OnDismiss(wxCommandEvent &event)
static CValidateFrame * m_Instance
void OnRefresh(wxCommandEvent &event)
virtual ~CValidateFrame()
Destructor.
wxButton * m_DoneButton
void CreateControls()
Creates the controls and sizers.
void OnSequester(wxCommandEvent &event)
void OnReport(wxCommandEvent &event)
static void GetInstance(wxWindow *parent, IWorkbench *workbench, CRef< objects::CUser_object > params, wxWindowID id=17000, const wxString &caption=_("Validation Errors"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(900, 600), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxTAB_TRAVERSAL)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
virtual void LoadSettings()
void OnUpdateDoneBtn(wxUpdateUIEvent &event)
bool Create(wxWindow *parent, wxWindowID id=17000, const wxString &caption=_("Validation Errors"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(900, 600), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxTAB_TRAVERSAL)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
IWorkbench * m_Workbench
virtual void SetRegistryPath(const string &reg_path)
wxString GetWorkDir()
void LoadData(void)
void GetSelected(set< objects::CBioseq_Handle > &selected)
void UpdateParams(CRef< objects::CUser_object > params)
TConstScopedObjects GetObjects()
void GetTopSeqAndSeqSubmit(objects::CSeq_entry_Handle &top_seq_entry, CConstRef< objects::CSeq_submit > &seq_submit)
CRef< CObjectFor< objects::CValidError::TErrs > > GetErrors()
CRef< objects::CScope > GetScope()
void SetWorkDir(const wxString &workDir)
Undo/Redo interface for editing operations.
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
#define _(proto)
Definition: ct_nlmzip_i.h:78
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:914
#define NULL
Definition: ncbistd.hpp:225
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
CScope & GetScope(void) const
Get scope this handle belongs to.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:104
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:101
list< CRef< CProjectItem > > TItems
bool CanGetItems(void) const
Check if it is safe to call GetItems method.
const TItems & GetItems(void) const
Get the Items member data.
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
void ReportUsage(const wxString &dialog_name)
Report opening & accepting events in the editing package.
const struct ncbi::grid::netcache::search::fields::SIZE size
static const char * kInternalIndexerRegistry
static const char * kInternalIndexerRegistryType
@ e_GenBankIndexer
static const char * kFramePosX
static const char * kFrameHeight
static const char * kValidateGenomes
static const char * kFramePosY
static const char * kFrameWidth
#define ID_VALIDATE_FRAME_DONE_BTN
#define ID_VALIDATE_FRAME_REPORT_BTN
#define ID_VALIDATE_FRAME_REFRESH
#define ID_VALIDATE_FRAME_SEGREGATE_BTN
#define ID_VALIDATE_FRAME_SEQUESTER_BTN
#define SYMBOL_VALIDATE_FRAME_SIZE
#define ID_VALIDATE_FRAME_GENOMES_CHKBOX
#define ID_VALIDATE_FRAME_DISMISS
bool RunningInsideNCBI()
Definition: wx_utils.cpp:1335
wxRect GetScreenRect(const wxWindow &win)
Definition: wx_utils.cpp:783
Modified on Sun Nov 08 14:01:27 2026 by modify_doxy.py rev. 717554