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

Go to the SVN repository for this file.

1 /* $Id: validate_frame.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 
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
117 ////@end CValidateFrame event table entries
119 
120 /*
121  * CValidateFrame constructors
122  */
123 
125  : m_Workbench(NULL)
126 {
127  Init();
128 }
129 
130 CValidateFrame::CValidateFrame( wxWindow* parent, IWorkbench* wb, CRef<CUser_object> params, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
131  : m_Workbench(wb), m_params(params)
132 {
133  Init();
134  Create( parent, id, caption, pos, size, style );
135 
137  SetRegistryPath("Dialogs.Edit.Validate");
138  LoadSettings();
139 }
140 
141 
142 /*
143  * CValidateFrame creator
144  */
145 
146 bool CValidateFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
147 {
148 ////@begin CValidateFrame creation
149  wxFrame::Create( parent, id, caption, pos, size, style );
150 
151  CreateControls();
152  Centre(wxBOTH|wxCENTRE_ON_SCREEN);
153 ////@end CValidateFrame creation
154  return true;
155 }
156 
157 
158 /*
159  * CValidateFrame destructor
160  */
161 
163 {
164 ////@begin CValidateFrame destruction
165  SaveSettings();
166 ////@end CValidateFrame destruction
167 
168  m_Instance = NULL;
169 }
170 
171 static const char* kFrameWidth = "Frame Width";
172 static const char* kFrameHeight = "Frame Height";
173 static const char* kFramePosX = "Frame Position X";
174 static const char* kFramePosY = "Frame Position Y";
175 
176 void CValidateFrame::SetRegistryPath(const string& reg_path)
177 {
178  m_RegPath = reg_path;
179 }
180 
182 {
183  if (m_RegPath.empty())
184  return;
185 
187  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
188 
189  view.Set(kFrameWidth,GetScreenRect().GetWidth());
190  view.Set(kFrameHeight,GetScreenRect().GetHeight());
191  view.Set(kFramePosX,GetScreenPosition().x);
192  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  {
216  int max_x = 0;
217  for (auto i = 0; i < wxDisplay::GetCount(); i++) // also see gui/widgets/wx/wx_utils.cpp:CorrectWindowRect() for alternative window position validation
218  {
219  wxDisplay display(i);
220  max_x += display.GetGeometry().GetWidth();
221  }
222  if (pos_x + width > max_x) pos_x = wxGetDisplaySize().GetWidth()-width-5;
223  if (pos_y + height > wxGetDisplaySize().GetHeight()) pos_y = wxGetDisplaySize().GetHeight()-height-5;
224 
225  SetPosition(wxPoint(pos_x,pos_y));
226  }
227 }
228 
229 
230 /*
231  * Member initialisation
232  */
233 
235 {
236 ////@begin CValidateFrame member initialisation
237  m_Panel = NULL;
238  m_DoneButton = NULL;
239 ////@end CValidateFrame member initialisation
240 }
241 
242 
243 /*
244  * Control creation for CValidateFrame
245  */
246 
248 {
249 ////@begin CValidateFrame content construction
250  // Generated by DialogBlocks, 18/10/2016 11:02:51 (unregistered)
251 
252  CValidateFrame* itemFrame1 = this;
253 
254  wxPanel* itemPanel2 = new wxPanel(itemFrame1);
255  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
256  itemPanel2->SetSizer(itemBoxSizer1);
257 
258 
259  m_Panel = new CValidatePanel( itemPanel2, m_Workbench, m_params);
260  itemBoxSizer1->Add(m_Panel, 1, wxGROW|wxALL, 0);
261  m_Panel->LoadData();
262 
263  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
264  itemBoxSizer1->Add(itemBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL,0);
265 
266  if (RunningInsideNCBI())
267  {
268  wxButton* itemButton8 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_REPORT_BTN, _("Report"), wxDefaultPosition, wxDefaultSize, 0 );
269  itemBoxSizer6->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
270 
271 
272  if (x_AllowDoneButton())
273  {
274  m_DoneButton = new wxButton( itemPanel2, ID_VALIDATE_FRAME_DONE_BTN, _("Done"), wxDefaultPosition, wxDefaultSize, 0 );
275  itemBoxSizer6->Add(m_DoneButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
276  }
277 
278  wxButton* itemButton11 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_SEQUESTER_BTN, _("Sequester"), wxDefaultPosition, wxDefaultSize, 0 );
279  itemBoxSizer6->Add(itemButton11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
280 
281  wxButton* itemButton12 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_SEGREGATE_BTN, _("Segregate"), wxDefaultPosition, wxDefaultSize, 0 );
282  itemBoxSizer6->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
283  }
284 
285 
286  wxButton* itemButton7 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_REFRESH, _("Refresh"), wxDefaultPosition, wxDefaultSize, 0 );
287  itemBoxSizer6->Add(itemButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
288 
289  wxButton* itemButton10 = new wxButton( itemPanel2, ID_VALIDATE_FRAME_DISMISS, _("Dismiss"), wxDefaultPosition, wxDefaultSize, 0 );
290  itemBoxSizer6->Add(itemButton10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
291 
292  wxHyperlinkCtrl* itemHyperlinkCtrl = new wxHyperlinkCtrl( itemPanel2, wxID_HELP, _("Help"), wxT("https://www.ncbi.nlm.nih.gov/tools/gbench/manual8/#validator"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
293  itemHyperlinkCtrl->SetForegroundColour(wxColour(192, 192, 192));
294  itemBoxSizer6->Add(itemHyperlinkCtrl, 0, wxALIGN_CENTER_VERTICAL, 5);
295 
296 ////@end CValidateFrame content construction
297 }
298 
299 /*
300  * Should we show tooltips?
301  */
302 
304 {
305  return true;
306 }
307 
308 /*
309  * Get bitmap resources
310  */
311 
312 wxBitmap CValidateFrame::GetBitmapResource( const wxString& name )
313 {
314  // Bitmap retrieval
315 ////@begin CValidateFrame bitmap retrieval
316  wxUnusedVar(name);
317  return wxNullBitmap;
318 ////@end CValidateFrame bitmap retrieval
319 }
320 
321 /*
322  * Get icon resources
323  */
324 
325 wxIcon CValidateFrame::GetIconResource( const wxString& name )
326 {
327  // Icon retrieval
328 ////@begin CValidateFrame icon retrieval
329  wxUnusedVar(name);
330  return wxNullIcon;
331 ////@end CValidateFrame icon retrieval
332 }
333 
334 void CValidateFrame::OnDismiss(wxCommandEvent& event )
335 {
336  Close();
337 }
338 
339 void CValidateFrame::OnSequester( wxCommandEvent& event )
340 {
341  if (!m_Workbench)
342  return;
343  set<CBioseq_Handle> selected;
344 
345  m_Panel->GetSelected(selected);
347  CSeq_entry_Handle top_seq_entry;
348 
349  m_Panel->GetTopSeqAndSeqSubmit(top_seq_entry,seq_submit);
350  if (!top_seq_entry)
351  return;
352 
353  CSequesterSets * dlg = new CSequesterSets(this, top_seq_entry, seq_submit, m_Workbench);
354 
355  dlg->SetSubsets(selected);
356  dlg->Show(true);
357 }
358 
359 
360 void CValidateFrame::OnSegregate( wxCommandEvent& event )
361 {
362  if (!m_Workbench)
363  return;
364  set<CBioseq_Handle> selected;
365  m_Panel->GetSelected(selected);
367  CSeq_entry_Handle top_seq_entry;
368  m_Panel->GetTopSeqAndSeqSubmit(top_seq_entry,seq_submit);
369  if (!top_seq_entry)
370  return;
371  ICommandProccessor* cmdProcessor = NULL;
373  if (srv)
374  {
375  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
376  if (!ws) return;
377 
378  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(top_seq_entry.GetScope()));
379  if (doc)
380  cmdProcessor = &doc->GetUndoManager();
381  }
382  if (!cmdProcessor)
383  return;
384 
385  CSegregateSets* dlg = new CSegregateSets(this, top_seq_entry, cmdProcessor);
386  dlg->SetSubsets(selected);
387  dlg->Show(true);
388 }
389 
390 void CValidateFrame::OnReport( wxCommandEvent& event )
391 {
393  if (!errs)
394  return;
395 
397  CSeq_entry_Handle top_seq_entry;
398  m_Panel->GetTopSeqAndSeqSubmit(top_seq_entry,seq_submit);
399  if (!top_seq_entry)
400  return;
402  CValidatorReportCfgDlg* report = new CValidatorReportCfgDlg(this, errs, objects.front().scope, top_seq_entry, seq_submit, m_Workbench);
403  report->SetWorkDir(m_Panel->GetWorkDir());
404  report->Show(true);
405 }
406 
407 void CValidateFrame::OnUpdateDoneBtn(wxUpdateUIEvent& event)
408 {
409  if (!m_DoneButton)
410  return;
412  CRegistryReadView view = gui_reg.GetReadView("Dialogs.Edit.SequesterSets");
413  bool enable = true;
414  if (view.HasField("EnableDone"))
415  enable = view.GetBool("EnableDone", true);
416 
417  event.Enable(enable);
418 }
419 
420 void CValidateFrame::OnDone( wxCommandEvent& event )
421 {
422  if (!m_DoneButton)
423  return;
425  if (!projectService) return;
426 
427  CRef<CGBWorkspace> ws = projectService->GetGBWorkspace();
428  if (!ws) return;
429 
430  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*m_Panel->GetScope()));
431  if (!doc) return;
432 
433  string errMsg;
434  try {
435  CProjectFolder& data_folder = doc->SetData();
436  if (data_folder.CanGetItems()) {
437  ITERATE(CProjectFolder::TItems, bit, data_folder.GetItems()) {
438  int pitemId = (*bit)->GetId();
439  CProjectItem* item = data_folder.FindProjectItemById(pitemId);
440  if (item) {
441  string pipe;
442  CProjectItemExtra::GetStr(*item, "SmartPipe", pipe);
443  if (!pipe.empty()) {
444  // Smart in named piped communications mode
445  CSmartClient::SendResult(doc->GetScope(), *item, CSmartClient::eUpdate);
446  }
447  else {
448  // Smart in file mode
449  doc->Save(doc->GetFileName());
450  }
451  }
452  }
453  }
454  } catch (const CException& ex) {
455  errMsg = ex.GetMsg();
456  } catch (const exception& ex) {
457  errMsg = ex.what();
458  }
459  if (!errMsg.empty()) {
460  wxMessageBox(errMsg, wxT("Smart client communication error"), wxOK|wxICON_ERROR);
461  return;
462  }
463 
464  projectService->RemoveProject(*doc);
465 
466  LoadData();
467  Refresh();
468 }
469 
470 
472 
473 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 )
474 {
475  if (!m_Instance)
476  {
477  m_Instance = new CValidateFrame(parent, workbench, params, id, caption, pos, size, style);
478  m_Instance->Show(true);
479  m_Instance->Raise();
480  m_Instance->SetFocus();
481  }
482  else
483  {
484  m_Instance->Raise();
485  m_Instance->SetFocus();
486  m_Instance->LoadData();
487  m_Instance->Refresh();
488  }
489 }
490 
492 {
495 
497 
498  if (indexer == e_GenBankIndexer)
499  return true;
500 
501  return false;
502 }
503 
505 {
506  m_Panel->LoadData();
507 }
508 
509 void CValidateFrame::OnRefresh(wxCommandEvent& event )
510 {
511  LoadData();
512  Refresh();
513 }
514 
516 
User-defined methods of the data storage class.
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)
void Init()
Initialises member variables.
void LoadData(void)
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)
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:815
#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:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
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 * 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_DISMISS
bool RunningInsideNCBI()
Definition: wx_utils.cpp:1335
wxRect GetScreenRect(const wxWindow &win)
Definition: wx_utils.cpp:783
Modified on Mon May 27 04:35:20 2024 by modify_doxy.py rev. 669887