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

Go to the SVN repository for this file.

1 /* $Id: validator_report_cfg_dlg.cpp 41057 2018-05-16 16:03:20Z 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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
42 #include <objmgr/scope.hpp>
44 #include <gui/core/document.hpp>
48 
49 #include <wx/sizer.h>
50 
51 ////@begin XPM images
52 ////@end XPM images
53 
56 
57 /*!
58  * CValidatorReportCfgDlg type definition
59  */
60 
61 IMPLEMENT_DYNAMIC_CLASS( CValidatorReportCfgDlg, wxDialog )
62 
63 
64 /*!
65  * CValidatorReportCfgDlg event table definition
66  */
67 
68 BEGIN_EVENT_TABLE( CValidatorReportCfgDlg, wxDialog )
69 
70 ////@begin CValidatorReportCfgDlg event table entries
72 
74 
77 
78 ////@end CValidatorReportCfgDlg event table entries
79 
81 
82 
83 /*!
84  * CValidatorReportCfgDlg constructors
85  */
86 
88  : m_Errs(), m_Scope()
89 {
90  Init();
91 }
92 
94  CObjectFor<objects::CValidError::TErrs>* errs, objects::CScope* scope,
95  objects::CSeq_entry_Handle top_seq_entry, CConstRef<objects::CSeq_submit> seq_submit, IWorkbench* workbench,
96  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
97  : m_Errs(errs), m_Scope(scope), m_TopSeqEntry(top_seq_entry), m_SeqSubmit(seq_submit), m_Workbench(workbench)
98 {
99  Init();
100  Create(parent, id, caption, pos, size, style);
101 }
102 
103 
104 /*!
105  * CValidatorReportCfgDlg creator
106  */
107 
108 bool CValidatorReportCfgDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
109 {
110 ////@begin CValidatorReportCfgDlg creation
111  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
112  wxDialog::Create( parent, id, caption, pos, size, style );
113 
114  CreateControls();
115  if (GetSizer())
116  {
117  GetSizer()->SetSizeHints(this);
118  }
119  Centre();
120 ////@end CValidatorReportCfgDlg creation
121  return true;
122 }
123 
124 
125 /*!
126  * CValidatorReportCfgDlg destructor
127  */
128 
130 {
131 ////@begin CValidatorReportCfgDlg destruction
132 ////@end CValidatorReportCfgDlg destruction
133 }
134 
135 
136 /*!
137  * Member initialisation
138  */
139 
141 {
142 ////@begin CValidatorReportCfgDlg member initialisation
143 ////@end CValidatorReportCfgDlg member initialisation
144  m_Verbose = NULL;
145 }
146 
147 
148 /*!
149  * Control creation for CValidatorReportCfgDlg
150  */
151 
153 {
154 ////@begin CValidatorReportCfgDlg content construction
155  CValidatorReportCfgDlg* itemDialog1 = this;
156 
157  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
158  itemDialog1->SetSizer(itemBoxSizer2);
159 
160  wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
161  itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
162 
163  m_Verbose = new wxCheckBox(itemDialog1, wxID_ANY, _("Verbose"), wxDefaultPosition, wxDefaultSize, 0);
164  itemBoxSizer2->Add(m_Verbose, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
165 
166  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
167  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
168 
169  wxButton* itemButton5 = new wxButton( itemDialog1, ID_REPORT_BTN, _("Report"), wxDefaultPosition, wxDefaultSize, 0 );
170  itemBoxSizer4->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
171 
172  wxButton* itemButton6 = new wxButton( itemDialog1, ID_VALID_REPORT_DISMISS, _("Dismiss"), wxDefaultPosition, wxDefaultSize, 0 );
173  itemBoxSizer4->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
174 
175  if (RunningInsideNCBI())
176  {
177  wxButton* itemButton11 = new wxButton( itemDialog1, ID_VALID_REPORT_SEQUESTER_BTN, _("Sequester"), wxDefaultPosition, wxDefaultSize, 0 );
178  itemBoxSizer4->Add(itemButton11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
179 
180  wxButton* itemButton12 = new wxButton( itemDialog1, ID_VALID_REPORT_SEGREGATE_BTN, _("Segregate"), wxDefaultPosition, wxDefaultSize, 0 );
181  itemBoxSizer4->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
182  }
183 
184 ////@end CValidatorReportCfgDlg content construction
185  m_Opts.clear();
186  if (m_Errs) {
187  vector<string> errcodes;
188 
189  for (size_t row = 0; row < m_Errs->GetData().size(); row++) {
190  CConstRef<CValidErrItem> pValidErrItem(m_Errs->GetData()[row]);
191  errcodes.push_back(pValidErrItem->GetErrCode());
192  }
193  sort(errcodes.begin(), errcodes.end());
194  vector<string>::iterator final = unique(errcodes.begin(), errcodes.end());
195  errcodes.resize( std::distance(errcodes.begin(), final) );
196 
197  ITERATE(vector<string>, it, errcodes) {
198  wxCheckBox* box = new wxCheckBox( itemDialog1, wxID_ANY, ToWxString(*it), wxDefaultPosition, wxDefaultSize, 0 );
199  itemFlexGridSizer3->Add(box, 0, wxALIGN_LEFT|wxALL, 5);
200  m_Opts.push_back(box);
201  }
202  }
203 }
204 
205 
206 /*!
207  * Should we show tooltips?
208  */
209 
211 {
212  return true;
213 }
214 
215 /*!
216  * Get bitmap resources
217  */
218 
219 wxBitmap CValidatorReportCfgDlg::GetBitmapResource( const wxString& name )
220 {
221  // Bitmap retrieval
222 ////@begin CValidatorReportCfgDlg bitmap retrieval
223  wxUnusedVar(name);
224  return wxNullBitmap;
225 ////@end CValidatorReportCfgDlg bitmap retrieval
226 }
227 
228 /*!
229  * Get icon resources
230  */
231 
232 wxIcon CValidatorReportCfgDlg::GetIconResource( const wxString& name )
233 {
234  // Icon retrieval
235 ////@begin CValidatorReportCfgDlg icon retrieval
236  wxUnusedVar(name);
237  return wxNullIcon;
238 ////@end CValidatorReportCfgDlg icon retrieval
239 }
240 
241 
242 /*!
243  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_VALID_REPORT_DISMISS
244  */
245 
247 {
248  Close();
249 }
250 
251 
252 /*!
253  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_REPORT_BTN
254  */
255 
256 void CValidatorReportCfgDlg::OnReportBtnClick( wxCommandEvent& event )
257 {
259  report->SetTitle(wxT("Validator Report"));
260  report->SetWorkDir(m_WorkDir);
261  bool any = false;
262  ITERATE(vector<wxCheckBox *>, it, m_Opts) {
263  if ((*it)->GetValue()) {
264  any = true;
265  break;
266  }
267  }
268  string msg = "";
269  if (m_Errs && m_Scope) {
270  objects::CObjectManager& objmgr = m_Scope->GetObjectManager();
271  objects::validator::CValidErrorFormat formatter(objmgr);
272  ITERATE(vector<wxCheckBox *>, it, m_Opts) {
273  if ((*it)->GetValue() || !any) {
274  vector<CConstRef<CValidErrItem> > err_list;
275  for (size_t row = 0; row < m_Errs->GetData().size(); row++) {
276  CConstRef<CValidErrItem> pValidErrItem(m_Errs->GetData()[row]);
277  if (NStr::EqualNocase(ToStdString((*it)->GetLabel()), pValidErrItem->GetErrCode())) {
278  err_list.push_back(pValidErrItem);
279  }
280  }
281 
282  if (err_list.size() > 0) {
283  msg += err_list[0]->GetErrCode();
284  if (m_Verbose->GetValue()) {
285  msg += "\t" + err_list[0]->GetVerbose();
286  }
287  msg += "\n";
288  }
289  ITERATE(vector<CConstRef<objects::CValidErrItem> >, err, err_list) {
290  msg += "\t";
291  msg += formatter.FormatForSubmitterReport(**err, *m_Scope);
292  msg += "\n";
293  }
294  }
295  }
296  }
297  report->SetText(ToWxString(msg));
298  report->Show(true);
299 }
300 
302 {
303  if (m_Errs && m_Scope) {
304  objects::CObjectManager& objmgr = m_Scope->GetObjectManager();
305  objects::validator::CValidErrorFormat formatter(objmgr);
306  ITERATE(vector<wxCheckBox *>, it, m_Opts) {
307  if ((*it)->GetValue()) {
308  vector<CConstRef<CValidErrItem> > err_list;
309  for (size_t row = 0; row < m_Errs->GetData().size(); row++) {
310  CConstRef<CValidErrItem> pValidErrItem(m_Errs->GetData()[row]);
311  if (NStr::EqualNocase(ToStdString((*it)->GetLabel()), pValidErrItem->GetErrCode())) {
312  string accession = pValidErrItem->GetAccession();
313  CSeq_id acc_id(accession, CSeq_id::fParse_Default);
314  CBioseq_Handle bsh;
315  try
316  {
317  bsh = m_Scope->GetBioseqHandle(acc_id);
318  }
319  catch(exception &)
320  {}
321  if (bsh)
322  selected.insert(bsh);
323  }
324  }
325  }
326  }
327  }
328 }
329 
330 void CValidatorReportCfgDlg::OnSequester( wxCommandEvent& event )
331 {
332  if (!m_TopSeqEntry)
333  return;
334  set<CBioseq_Handle> selected;
335 
336  GetSelected(selected);
337 
339 
340  dlg->SetSubsets(selected);
341  dlg->Show(true);
342 }
343 
344 void CValidatorReportCfgDlg::OnSegregate( wxCommandEvent& event )
345 {
346  if (!m_TopSeqEntry)
347  return;
348  if (!m_Workbench)
349  return;
350  set<CBioseq_Handle> selected;
351  GetSelected(selected);
352 
353  ICommandProccessor* cmdProcessor = NULL;
355  if (srv)
356  {
357  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
358  if (!ws) return;
359 
360  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(m_TopSeqEntry.GetScope()));
361  if (doc)
362  cmdProcessor = &doc->GetUndoManager();
363  }
364  if (!cmdProcessor)
365  return;
366  wxWindow *main_window = GetParent();
367  CSegregateSets* dlg = new CSegregateSets(main_window, m_TopSeqEntry, cmdProcessor);
368  dlg->SetSubsets(selected);
369  dlg->Show(true);
370 }
371 
static CRef< CScope > m_Scope
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CBioseq_Handle –.
CGBDocument.
Definition: document.hpp:113
CUndoManager & GetUndoManager()
Definition: document.hpp:158
void SetText(const wxString &text)
void SetWorkDir(const wxString &workDir)
CProjectService - a service providing API for operations with Workspaces and Projects.
CRef –.
Definition: ncbiobj.hpp:618
void SetSubsets(const set< objects::CBioseq_Handle > &selected)
void SetSubsets(const set< objects::CBioseq_Handle > &selected)
void OnSequester(wxCommandEvent &event)
CConstRef< objects::CSeq_submit > m_SeqSubmit
objects::CSeq_entry_Handle m_TopSeqEntry
void OnValidReportDismissClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_VALID_REPORT_DISMISS
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
bool Create(wxWindow *parent, wxWindowID id=10384, const wxString &caption=_("Validator Report"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
void Init()
Initialises member variables.
void OnSegregate(wxCommandEvent &event)
void GetSelected(set< objects::CBioseq_Handle > &selected)
void OnReportBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_REPORT_BTN
void CreateControls()
Creates the controls and sizers.
CObjectFor< objects::CValidError::TErrs > * m_Errs
static bool ShowToolTips()
Should we show tooltips?
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
Undo/Redo interface for editing operations.
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
#define _(proto)
Definition: ct_nlmzip_i.h:78
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
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
@ fParse_Default
By default in ParseIDs and IsValid, allow raw parsable non-numeric accessions and plausible local acc...
Definition: Seq_id.hpp:102
T & GetData(void)
Get data as a reference.
Definition: ncbiobj.hpp:2346
#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 EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5347
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size
The Object manager core.
static static static wxID_ANY
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define row(bind, expected)
Definition: string_bind.c:73
USING_SCOPE(objects)
#define ID_REPORT_BTN
#define ID_VALID_REPORT_DISMISS
#define ID_VALID_REPORT_SEGREGATE_BTN
#define ID_VALID_REPORT_SEQUESTER_BTN
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
bool RunningInsideNCBI()
Definition: wx_utils.cpp:1335
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:58:31 2024 by modify_doxy.py rev. 669887