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

Go to the SVN repository for this file.

1 /* $Id: edit_pub_dlg_std.cpp 47498 2023-05-19 19:50:11Z 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: Colleen Bollin, Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 #include <objects/biblio/Affil.hpp>
45 
46 
47 
58 
59 #include <wx/button.h>
60 #include <wx/stattext.h>
61 #include <wx/msgdlg.h>
62 #include <wx/display.h>
63 
66 
67 
68 IMPLEMENT_DYNAMIC_CLASS( CEditPubDlg, CBulkCmdDlg )
69 
70 
71 /*!
72  * CEditPubDlg event table definition
73  */
74 
75 BEGIN_EVENT_TABLE( CEditPubDlg, CBulkCmdDlg )
76 
77 ////@begin CEditPubDlg event table entries
78 ////@end CEditPubDlg event table entries
79 
81 
82 
83 /*!
84  * CEditPubDlg constructors
85  */
86 
88 {
89  Init();
90 }
91 
92 CEditPubDlg::CEditPubDlg( wxWindow* parent, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
93  : CBulkCmdDlg(wb)
94 {
95  Init();
96  Create(parent, id, caption, pos, size, style);
97  SetRegistryPath("Dialogs.Edit.EditPublications");
98  LoadSettings();
99 }
100 
101 
102 /*!
103  * CEditPubDlg creator
104  */
105 
106 bool CEditPubDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
107 {
108 ////@begin CEditPubDlg creation
109  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
110  CBulkCmdDlg::Create( parent, id, caption, pos, size, style );
111 
112  CreateControls();
113  if (GetSizer())
114  {
115  GetSizer()->SetSizeHints(this);
116  }
117  Centre();
118 ////@end CEditPubDlg creation
119  return true;
120 }
121 
122 
123 /*!
124  * CEditPubDlg destructor
125  */
126 
128 {
129 ////@begin CEditPubDlg destruction
130  SaveSettings();
131 ////@end CEditPubDlg destruction
132 }
133 
134 
135 static const char* kFrameWidth = "Frame Width";
136 static const char* kFrameHeight = "Frame Height";
137 static const char* kFramePosX = "Frame Position X";
138 static const char* kFramePosY = "Frame Position Y";
139 
140 void CEditPubDlg::SetRegistryPath(const string& reg_path)
141 {
142  m_RegPath = reg_path;
143 }
144 
146 {
147  if (m_RegPath.empty())
148  return;
149 
151  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
152 
153  view.Set(kFrameWidth,GetScreenRect().GetWidth());
154  view.Set(kFrameHeight,GetScreenRect().GetHeight());
155  view.Set(kFramePosX,GetScreenPosition().x);
156  view.Set(kFramePosY,GetScreenPosition().y);
157 }
158 
159 
161 {
162  if (m_RegPath.empty())
163  return;
164 
166  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
167 
168  int width = view.GetInt(kFrameWidth, -1);
169  int height = view.GetInt(kFrameHeight, -1);
170  if (width >= 0 && height >= 0)
171  SetSize(wxSize(width,height));
172 
173  int pos_x = view.GetInt(kFramePosX, -1);
174  int pos_y = view.GetInt(kFramePosY, -1);
175 
176  if (pos_x >= 0 && pos_y >= 0) {
177  int max_x = 0;
178  for (unsigned i = 0; i < wxDisplay::GetCount(); i++) // also see gui/widgets/wx/wx_utils.cpp:CorrectWindowRect() for alternative window position validation
179  {
180  wxDisplay display(i);
181  max_x += display.GetGeometry().GetWidth();
182  }
183 
184  if (pos_x + width > max_x)
185  pos_x = wxGetDisplaySize().GetWidth()-width-5;
186  if (pos_y + height > wxGetDisplaySize().GetHeight())
187  pos_y = wxGetDisplaySize().GetHeight()-height-5;
188 
189  SetPosition(wxPoint(pos_x,pos_y));
190  }
191 }
192 
193 
194 /*!
195  * Member initialisation
196  */
197 
199 {
200 ////@begin CEditPubDlg member initialisation
201  m_Notebook = NULL;
205  m_OkCancel = NULL;
206 ////@end CEditPubDlg member initialisation
207 }
208 
209 
210 /*!
211  * Control creation for CEditPubDlg
212  */
213 
215 {
216 ////@begin CEditPubDlg content construction
217  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
218  SetSizer(itemBoxSizer1);
219 
220  wxPanel* itemCBulkCmdDlg1 = new wxPanel(this, wxID_ANY);
221  itemBoxSizer1->Add(itemCBulkCmdDlg1, 1, wxGROW, 0);
222 
223  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
224  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
225 
226  m_Notebook = new wxNotebook(itemCBulkCmdDlg1, wxID_ANY,wxDefaultPosition,wxDefaultSize);
227  itemBoxSizer2->Add(m_Notebook, 1, wxGROW|wxALL, 5);
228 
230  m_Notebook->AddPage(panel1,_("Replace section"));
231 
233  m_Notebook->AddPage(panel2,_("Replace entire pub"));
234 
236  m_Notebook->AddPage(panel3,_("Replace single field"));
237 
238 
239  CRef<CAuth_list> authors;
240  CConstRef<CObject> sel_pub = GetSelectedPub();
241  if (sel_pub)
242  {
243  CConstRef<CAuth_list> auth_list = GetAuthList(sel_pub);
244  if (auth_list)
245  {
246  authors.Reset(new CAuth_list());
247  authors->Assign(*auth_list);
248  }
249  }
250 
251  CAuthorReplacePanel *panel4 = new CAuthorReplacePanel(m_Notebook, this, authors);
252  m_Notebook->AddPage(panel4,_("Global author replace"));
253 
254  wxStaticBox* constraintDetails = new wxStaticBox(itemCBulkCmdDlg1, wxID_ANY, _("Constraint"));
255  wxStaticBoxSizer* itemStaticBoxSizer9 = new wxStaticBoxSizer(constraintDetails, wxVERTICAL);
256  itemBoxSizer2->Add(itemStaticBoxSizer9, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
257 
258  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
259  itemStaticBoxSizer9->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
260 
261  m_Fieldhandler = new CFieldHandlerNamePanel(itemStaticBoxSizer9->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0);
263  itemBoxSizer10->Add(m_Fieldhandler, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
264 
265  m_StrConstraintPanel = new CStringConstraintPanel(itemStaticBoxSizer9->GetStaticBox(), true, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0);
266  itemBoxSizer10->Add(m_StrConstraintPanel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
267 
268  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
269  itemStaticBoxSizer9->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
270 
271  wxStaticText* itemStaticText14 = new wxStaticText( itemStaticBoxSizer9->GetStaticBox(), wxID_STATIC, _("Publication Status"), wxDefaultPosition, wxDefaultSize, 0 );
272  itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
273 
274  wxArrayString m_PubStatusConstraintStrings;
275  m_PubStatusConstraintStrings.Add(_("Any"));
276  m_PubStatusConstraintStrings.Add(_("Published"));
277  m_PubStatusConstraintStrings.Add(_("Unpublished"));
278  m_PubStatusConstraintStrings.Add(_("In Press"));
279  m_PubStatusConstraintStrings.Add(_("Submitter Block"));
280  m_PubStatusConstraint = new wxChoice( itemStaticBoxSizer9->GetStaticBox(), ID_PUB_STATUS_CONSTRAINT, wxDefaultPosition, wxDefaultSize, m_PubStatusConstraintStrings, 0 );
281  m_PubStatusConstraint->SetStringSelection(_("Any"));
282  itemBoxSizer13->Add(m_PubStatusConstraint, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
283 
284  m_OkCancel = new COkCancelPanel(itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0);
285  itemBoxSizer2->Add(m_OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
286 
287 
288 ////@end CEditPubDlg content construction
289 
291  return;
292 
294  if (!srv) return;
295 
296  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
297  if (!ws) return;
298 
299  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(m_TopSeqEntry.GetScope()));
300  if (!doc) return;
301 
302  SetWorkDir(this, doc->GetWorkDir());
303 }
304 
305 
306 /*!
307  * Should we show tooltips?
308  */
309 
311 {
312  return true;
313 }
314 
315 /*!
316  * Get bitmap resources
317  */
318 
319 wxBitmap CEditPubDlg::GetBitmapResource( const wxString& name )
320 {
321  // Bitmap retrieval
322 ////@begin CEditPubDlg bitmap retrieval
323  wxUnusedVar(name);
324  return wxNullBitmap;
325 ////@end CEditPubDlg bitmap retrieval
326 }
327 
328 /*!
329  * Get icon resources
330  */
331 
332 wxIcon CEditPubDlg::GetIconResource( const wxString& name )
333 {
334  // Icon retrieval
335 ////@begin CEditPubDlg icon retrieval
336  wxUnusedVar(name);
337  return wxNullIcon;
338 ////@end CEditPubDlg icon retrieval
339 }
340 
341 
343 {
344  return m_ErrorMessage;
345 }
346 
347 const string kUnknownError = "Unknown error";
348 
350 {
353  if (!m_TopSeqEntry) {
354  return cmd;
355  }
356 
357  string constraint_field = m_Fieldhandler->GetFieldName(true);
358  string ncRNA_class;
361  CRef<CConstraintMatcher>(new CSimpleConstraintMatcher(string_constraint)));
362 
363  string desired_status = GetStatusConstraint();
366  *constraint1 += constraint2;
367 
368  vector<CSeq_entry_Handle> descr_ctxt;
369  vector<CConstRef<CObject>> objs = GetObjects(m_TopSeqEntry, "status", CFieldNamePanel::eFieldType_Pub, -1, kEmptyStr, m_SeqSubmit, constraint1, &descr_ctxt);
370 
371 
372  if (objs.empty())
373  {
374  m_ErrorMessage = "No publications found!";
375  return cmd;
376  }
377 
378  int sel = m_Notebook->GetSelection();
379  bool any_change(false);
380  CEditPubCmdPanel *win = dynamic_cast<CEditPubCmdPanel*>(m_Notebook->GetPage(sel));
381  if (win)
382  {
383  cmd = win->GetCommand(objs, descr_ctxt);
384  }
385 
387  {
388  wxMessageBox(wxT("No effect!"), wxT("Error"), wxOK | wxICON_ERROR, NULL);
389  }
390 
391  return cmd;
392 }
393 
395 {
398  if (!sel_srv) return CConstRef<CObject>(NULL);
399  sel_srv->GetCurrentSelection(objects);
400  if (objects.empty()) return CConstRef<CObject>(NULL);
402  const CObject* ptr = it->object.GetPointer();
403  const CSeqdesc* seqdesc = dynamic_cast<const CSeqdesc*>(ptr);
404  const CSeq_feat* seqfeat = dynamic_cast<const CSeq_feat*>(ptr);
405  const CCit_sub* citsub = dynamic_cast<const CCit_sub*>(ptr);
406  const CPubdesc* pubdesc = dynamic_cast<const CPubdesc*>(ptr);
407  const CSubmit_block* block = dynamic_cast<const CSubmit_block*>(ptr);
408  if (seqdesc && seqdesc->IsPub()) {
409  return CConstRef<CObject>(seqdesc);
410  } else if (seqfeat && seqfeat->IsSetData() && seqfeat->GetData().IsPub()) {
411  return CConstRef<CObject>(seqfeat);
412  } else if (citsub) {
413  return CConstRef<CObject>(citsub);
414  } else if (pubdesc) {
415  return CConstRef<CObject>(pubdesc);
416  } else if (block && block->IsSetCit()) {
417  return CConstRef<CObject>(block);
418  }
419  }
420  return CConstRef<CObject>(NULL);
421 }
422 
423 
425 {
427  m_ErrorMessage = msg + "\n";
428  } else {
429  m_ErrorMessage += msg + "\n";
430  }
431 }
432 
433 
434 IMPLEMENT_DYNAMIC_CLASS( CEditPubSubpanel, wxPanel )
435 BEGIN_EVENT_TABLE( CEditPubSubpanel, wxPanel )
437 
438 IMPLEMENT_DYNAMIC_CLASS( CReplaceSectionPanel, CEditPubSubpanel )
439 
440 BEGIN_EVENT_TABLE( CReplaceSectionPanel, CEditPubSubpanel )
442 
443 void CReplaceSectionPanel::CreateControls()
444 {
445  CReplaceSectionPanel* itemPanel1 = this;
446 
447  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
448  itemPanel1->SetSizer(itemBoxSizer2);
449 
450  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
451  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL, 0);
452 
453  m_AuthorListSection = new wxCheckBox( this, wxID_ANY, wxT("Replace author list with selected author list"), wxDefaultPosition, wxDefaultSize, 0 );
454  itemBoxSizer3->Add(m_AuthorListSection, 0, wxALIGN_LEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
455  m_TitleSection = new wxCheckBox( this, wxID_ANY, wxT("Replace title with selected title"), wxDefaultPosition, wxDefaultSize, 0 );
456  itemBoxSizer3->Add(m_TitleSection, 0, wxALIGN_LEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
457  m_AffiliationSection = new wxCheckBox( this, wxID_ANY, wxT("Replace affiliation with selected affiliation"), wxDefaultPosition, wxDefaultSize, 0 );
458  itemBoxSizer3->Add(m_AffiliationSection, 0, wxALIGN_LEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
459 }
460 
461 CRef<CCmdComposite> CReplaceSectionPanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
462 {
463  CRef<CCmdComposite> cmd(new CCmdComposite("Edit Publications"));
464 
466  if (!sel_pub)
467  {
468  m_dlg->AppendToErrorMsg("No publication is selected to use as a source!");
469  return CRef<CCmdComposite> (NULL);
470  }
471  CConstRef<CAuth_list> auth_list = GetAuthList(sel_pub);
472  string title = GetPubTitle(sel_pub);
473 
474  bool any_change = false;
475  auto obj_it = objs.begin();
476  auto seh_it = descr_ctxt.begin();
477  _ASSERT(objs.size() == descr_ctxt.size());
478  for ( ; obj_it != objs.end() && seh_it != descr_ctxt.end(); ++obj_it, ++seh_it)
479  {
480  const CSeqdesc* d = dynamic_cast<const CSeqdesc* >(obj_it->GetPointer());
481  if (d && d->IsPub()) {
482  bool this_change = false;
483  CRef<CSeqdesc> new_desc(new CSeqdesc());
484  new_desc->Assign(*d);
485 
486  if (m_AuthorListSection->GetValue() && auth_list) {
487  this_change = SetAuthorNames(new_desc->SetPub(), *auth_list);
488  }
489  if (m_AffiliationSection->GetValue() && auth_list && auth_list->IsSetAffil()) {
490  CConstRef<CAuth_list> this_auth = GetAuthList(new_desc->GetPub());
491  CRef<CAuth_list> new_auth(new CAuth_list());
492  new_auth->Assign(*this_auth);
493  new_auth->SetAffil().Assign(auth_list->GetAffil());
494  this_change |= SetAuthList(new_desc->SetPub(), *new_auth);
495  }
496  if (m_TitleSection->GetValue()) {
497  bool skip_cit_sub = true;
498  this_change |= CPubField::SetPubTitle (new_desc->SetPub(), title, edit::eExistingText_replace_old, skip_cit_sub);
499  }
500 
501  if (this_change) {
502  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(*seh_it, *d, *new_desc));
503  cmd->AddCommand (*ecmd);
504  any_change = true;
505  }
506  }
507  }
508 
509  if (!any_change) {
510  cmd.Reset(NULL);
511  m_dlg->AppendToErrorMsg("No action.");
512  }
513 
514  return cmd;
515 }
516 
517 
518 
519 IMPLEMENT_DYNAMIC_CLASS( CReplaceEntirePubPanel, CEditPubSubpanel )
520 
521 BEGIN_EVENT_TABLE( CReplaceEntirePubPanel, CEditPubSubpanel )
523 
524 void CReplaceEntirePubPanel::CreateControls()
525 {
526  CReplaceEntirePubPanel* itemPanel1 = this;
527 
528  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
529  itemPanel1->SetSizer(itemBoxSizer2);
530 
531  wxStaticText* instructions = new wxStaticText( this, wxID_STATIC, wxT("Replace with selected publication or submitter block"), wxDefaultPosition, wxDefaultSize, 0 );
532  itemBoxSizer2->Add(instructions, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
533 }
534 
535 CRef<CCmdComposite> CReplaceEntirePubPanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
536 {
538  if (!sel_pub)
539  {
540  m_dlg->AppendToErrorMsg("No publication is selected to use as a source!");
541  return CRef<CCmdComposite> (NULL);
542  }
543 
544  const CSeqdesc* orig_desc = dynamic_cast<const CSeqdesc* >(sel_pub.GetPointer());
545  const CSeq_feat* orig_feat = dynamic_cast<const CSeq_feat*>(sel_pub.GetPointer());
546  const CCit_sub* citsub = dynamic_cast<const CCit_sub*>(sel_pub.GetPointer());
547  const CPubdesc* pubdesc = dynamic_cast<const CPubdesc*>(sel_pub.GetPointer());
548 
549  bool any_change = false;
550  bool check_status = NStr::EqualNocase(m_dlg->GetStatusConstraint(), "Any");
551 
552  CRef<CCmdComposite> cmd(new CCmdComposite("Edit Publications"));
553  auto obj_it = objs.begin();
554  auto seh_it = descr_ctxt.begin();
555  _ASSERT(objs.size() == descr_ctxt.size());
556  for (; obj_it != objs.end() && seh_it != descr_ctxt.end(); ++obj_it, ++seh_it)
557  {
558  if (obj_it->GetPointer() == sel_pub.GetPointer()) {
559  continue;
560  }
561  // skip pubs with status submitter, only when "Replace entire publication" is selected
562  if (check_status) {
563  string status = CPubField::GetStatus(**obj_it);
564  if (NStr::EqualNocase(status, "Submitter Block"))
565  {
566  continue;
567  }
568  }
569  const CSeqdesc* d = dynamic_cast<const CSeqdesc* >(obj_it->GetPointer());
570  if (d && d->IsPub() && pubdesc != &(d->GetPub())) {
571  CRef<CSeqdesc> new_desc(new CSeqdesc());
572  bool this_change = false;
573  if (orig_desc) {
574  new_desc->Assign(*orig_desc);
575  this_change = true;
576  } else if (orig_feat) {
577  new_desc->Assign(*d);
578  new_desc->SetPub().Assign(orig_feat->GetData().GetPub());
579  this_change = true;
580  } else if (citsub) {
581  new_desc->Assign(*d);
582  new_desc->SetPub().ResetPub();
583  CRef<CPub> new_pub(new CPub());
584  new_pub->SetSub().Assign(*citsub);
585  new_desc->SetPub().SetPub().Set().push_back(new_pub);
586  this_change = true;
587  } else if (pubdesc) {
588  new_desc->Assign(*d);
589  new_desc->SetPub().Assign(*pubdesc);
590  this_change = true;
591  }
592  if (this_change) {
593  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(*seh_it, *d, *new_desc));
594  cmd->AddCommand (*ecmd);
595  any_change = true;
596  }
597  }
598  }
599 
600  if (!any_change)
601  {
602  cmd.Reset(NULL);
603  m_dlg->AppendToErrorMsg("No target publications.");
604  }
605 
606  return cmd;
607 }
608 
609 
610 IMPLEMENT_DYNAMIC_CLASS( CReplaceSingleFieldPanel, CEditPubSubpanel )
611 
612 BEGIN_EVENT_TABLE( CReplaceSingleFieldPanel, CEditPubSubpanel )
614 
615 void CReplaceSingleFieldPanel::CreateControls()
616 {
617  CReplaceSingleFieldPanel* itemPanel1 = this;
618 
619  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
620  itemPanel1->SetSizer(itemBoxSizer2);
621 
622  m_PubField = new CFieldHandlerNamePanel(this);
623  m_PubField->SetFieldNames(CPubFieldType::GetFieldNames());
624  itemBoxSizer2->Add(m_PubField, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
625  m_FieldText = new wxTextCtrl(this, wxID_ANY);
626  itemBoxSizer2->Add(m_FieldText, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
627 }
628 
629 CRef<CCmdComposite> CReplaceSingleFieldPanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
630 {
631  string field_name = m_PubField->GetFieldName(true);
632  if (NStr::IsBlank(field_name))
633  {
634  m_dlg->AppendToErrorMsg("You must select a field to apply.");
635  return CRef<CCmdComposite>(NULL);
636  }
637 
638  string val = ToStdString(m_FieldText->GetValue());
639  string constraint_field = m_dlg->GetFieldName(true);
641 
642  string desired_status = m_dlg->GetStatusConstraint();
643 
645 
646  string ncRNA_class;
649  CRef<CConstraintMatcher>(new CSimpleConstraintMatcher(string_constraint)));
652  *constraint1 += constraint2;
653  action->SetConstraint(constraint1);
654  action->SetExistingText(edit::eExistingText_replace_old);
655  action->Apply(val);
656  CRef<CCmdComposite> cmd = action->GetActionCommand();
657  if (!cmd)
658  {
659  m_dlg->AppendToErrorMsg("No action.");
660  }
661 
662  return cmd;
663 }
664 
665 
666 IMPLEMENT_DYNAMIC_CLASS( CAuthorReplacePanel, CEditPubSubpanel )
667 
668 BEGIN_EVENT_TABLE( CAuthorReplacePanel, CEditPubSubpanel )
670 
671 void CAuthorReplacePanel::CreateControls()
672 {
673  CAuthorReplacePanel* itemPanel1 = this;
674 
675  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
676  itemPanel1->SetSizer(itemBoxSizer2);
677 
678  if (!m_Authors)
679  {
680  m_Authors.Reset(new CAuth_list());
681  }
682  m_AuthorsPanel = new CAuthorNamesPanel(this, *m_Authors, false);
683  itemBoxSizer2->Add(m_AuthorsPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
684  m_AuthorsPanel->TransferDataToWindow();
685 }
686 
687 CRef<CCmdComposite> CAuthorReplacePanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
688 {
689  if (!m_Authors)
690  {
691  m_Authors.Reset(new CAuth_list());
692  }
694  if (!m_Authors->IsSetNames() || m_Authors->GetNameCount() == 0)
695  {
696  m_dlg->AppendToErrorMsg("You must supply an author list.");
697  return CRef<CCmdComposite>(NULL);
698  }
699 
700 
701  CAuth_list& edited_auth_list = *m_Authors;
702  if (!edited_auth_list.IsSetNames())
703  {
704  m_dlg->AppendToErrorMsg("No names set.");
705  return CRef<CCmdComposite>(NULL);
706  }
707  CAuth_list::TNames& edited_names = edited_auth_list.SetNames();
708 
709  bool any_modified = false;
710  CRef<CCmdComposite> comp_cmd(new CCmdComposite("Replace All Authors"));
711  auto obj_it = objs.begin();
712  auto seh_it = descr_ctxt.begin();
713  _ASSERT(objs.size() == descr_ctxt.size());
714  for (; obj_it != objs.end() && seh_it != descr_ctxt.end(); ++obj_it, ++seh_it)
715  {
716  if (const CSeqdesc* desc = dynamic_cast<const CSeqdesc* >(obj_it->GetPointer())) {
717  if (desc->IsPub()) {
718  CRef<CSeqdesc> replacement(new CSeqdesc());
719  replacement->Assign(*desc);
720  bool modified = false;
721  NON_CONST_ITERATE(CPub_equiv::Tdata, pub, replacement->SetPub().SetPub().Set())
722  {
723  switch ((*pub)->Which())
724  {
725  case CPub::e_Gen:
726  (*pub)->SetGen().SetAuthors().SetNames(edited_names);
727  break;
728  case CPub::e_Article:
729  (*pub)->SetArticle().SetAuthors().SetNames(edited_names);
730  break;
731  case CPub::e_Book:
732  (*pub)->SetBook().SetAuthors().SetNames(edited_names);
733  break;
734  case CPub::e_Proc:
735  (*pub)->SetProc().SetBook().SetAuthors().SetNames(edited_names);
736  break;
737  case CPub::e_Sub:
738  (*pub)->SetSub().SetAuthors().SetNames(edited_names);
739  break;
740  case CPub::e_Patent:
741  (*pub)->SetPatent().SetAuthors().SetNames(edited_names);
742  break;
743  case CPub::e_Man:
744  (*pub)->SetMan().SetCit().SetAuthors().SetNames(edited_names);
745  break;
746  default:
747  (*pub)->SetGen().SetAuthors().SetNames(edited_names);
748  break;
749  }
750  modified = true;
751  }
752  if (modified)
753  {
754  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(*seh_it, *desc, *replacement));
755  comp_cmd->AddCommand(*ecmd);
756  any_modified = true;
757  }
758  }
759  }
760  else if (const CSubmit_block* block = dynamic_cast<const CSubmit_block*>(obj_it->GetPointer())) {
761  CRef<CSubmit_block> new_submit_block(new CSubmit_block);
762  new_submit_block->Assign(*block);
763 
764  CAuth_list& authors = new_submit_block->SetCit().SetAuthors();
765  authors.SetNames(edited_names);
766 
768  CObject* actual = (CObject*)(block);
769  cmd->Add(actual, CConstRef<CObject>(new_submit_block));
770  comp_cmd->AddCommand(*cmd);
771  any_modified = true;
772  }
773 
774  }
775 
776  if (!any_modified)
777  {
778  comp_cmd.Reset();
779  m_dlg->AppendToErrorMsg("No action.");
780  }
781  return comp_cmd;
782 }
783 
785 
@Auth_list.hpp User-defined methods of the data storage class.
Definition: Auth_list.hpp:57
size_t GetNameCount() const
Definition: Auth_list.cpp:58
void PopulateAuthors(objects::CAuth_list &auth_list)
virtual CRef< CCmdComposite > GetCommand(const vector< CConstRef< CObject >> &objs, const vector< CSeq_entry_Handle > &descr_ctxt)
CRef< CAuth_list > m_Authors
CAuthorNamesPanel * m_AuthorsPanel
CConstRef< objects::CSeq_submit > m_SeqSubmit
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)
IWorkbench * m_Workbench
bool GetTopLevelSeqEntryAndProcessor()
void AddCommand(IEditCommand &command)
virtual CRef< CCmdComposite > GetCommand(const vector< CConstRef< CObject >> &objs, const vector< CSeq_entry_Handle > &descr_ctxt)=0
~CEditPubDlg()
Destructor.
virtual CRef< CCmdComposite > GetCommand()
static bool ShowToolTips()
Should we show tooltips?
wxChoice * m_PubStatusConstraint
virtual void LoadSettings()
virtual string GetErrorMessage()
CFieldHandlerNamePanel * m_Fieldhandler
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
string GetFieldName(const bool subfield)
void Init()
Initialises member variables.
CSeq_entry_Handle GetTopSeqEntry()
string GetStatusConstraint()
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Edit Publications"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(800, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CConstRef< CObject > GetSelectedPub()
void AppendToErrorMsg(const string &msg)
CEditPubDlg()
Constructors.
CRef< edit::CStringConstraint > GetStringConstraint()
void CreateControls()
Creates the controls and sizers.
wxNotebook * m_Notebook
CStringConstraintPanel * m_StrConstraintPanel
virtual void SetRegistryPath(const string &reg_path)
CConstRef< objects::CSeq_submit > GetSeqSubmit()
virtual void SaveSettings() const
COkCancelPanel * m_OkCancel
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
void SetFieldNames(const vector< string > &field_names)
CGBDocument.
Definition: document.hpp:113
wxString GetWorkDir() const
Definition: document.cpp:1364
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
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
static vector< string > GetFieldNames(bool extended=false)
static string GetStatus(const CObject &obj)
Definition: pub_field.cpp:1759
static bool SetPubTitle(CPubdesc &pdesc, const string &title, objects::edit::EExistingText existing_text, bool skip_sub=false)
Definition: pub_field.cpp:366
Definition: Pub.hpp:56
@Pubdesc.hpp User-defined methods of the data storage class.
Definition: Pubdesc.hpp:54
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
virtual CRef< CCmdComposite > GetCommand(const vector< CConstRef< CObject >> &objs, const vector< CSeq_entry_Handle > &descr_ctxt)
wxCheckBox * m_AuthorListSection
virtual CRef< CCmdComposite > GetCommand(const vector< CConstRef< CObject >> &objs, const vector< CSeq_entry_Handle > &descr_ctxt)
wxCheckBox * m_AffiliationSection
virtual CRef< CCmdComposite > GetCommand(const vector< CConstRef< CObject >> &objs, const vector< CSeq_entry_Handle > &descr_ctxt)
CFieldHandlerNamePanel * m_PubField
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CRef< edit::CStringConstraint > GetStringConstraint()
CSubmit_block –.
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
#define _(proto)
Definition: ct_nlmzip_i.h:78
CChangeUnindexedObjectCommand< objects::CSubmit_block > CChangeSubmitBlockCommand
USING_SCOPE(objects)
static const char * kFramePosX
const string kUnknownError
static const char * kFrameHeight
static const char * kFramePosY
static const char * kFrameWidth
#define ID_PUB_STATUS_CONSTRAINT
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)
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))
vector< CConstRef< CObject > > GetObjects(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class, CConstRef< objects::CSeq_submit > submit, CRef< CEditingActionConstraint > constraint, vector< CSeq_entry_Handle > *descr_context=nullptr)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#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
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
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
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5378
bool IsSetAffil(void) const
author affiliation Check if a value has been assigned to Affil data member.
Definition: Auth_list_.hpp:498
const TAffil & GetAffil(void) const
Get the Affil member data.
Definition: Auth_list_.hpp:510
void SetAffil(TAffil &value)
Assign a value to Affil data member.
Definition: Auth_list_.cpp:160
bool IsSetNames(void) const
Check if a value has been assigned to Names data member.
Definition: Auth_list_.hpp:464
void SetNames(TNames &value)
Assign a value to Names data member.
Definition: Auth_list_.cpp:149
list< CRef< CPub > > Tdata
Definition: Pub_equiv_.hpp:90
TSub & SetSub(void)
Select the variant.
Definition: Pub_.cpp:195
@ e_Article
Definition: Pub_.hpp:106
@ e_Book
Definition: Pub_.hpp:108
@ e_Gen
general or generic unparsed
Definition: Pub_.hpp:102
@ e_Patent
Definition: Pub_.hpp:110
@ e_Proc
proceedings of a meeting
Definition: Pub_.hpp:109
@ e_Man
manuscript, thesis, or letter
Definition: Pub_.hpp:112
@ e_Sub
submission
Definition: Pub_.hpp:103
const TPub & GetPub(void) const
Get the variant data.
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
bool IsPub(void) const
Check if variant Pub is selected.
void SetPub(TPub &value)
Assign a value to Pub data member.
Definition: Pubdesc_.cpp:72
TPub & SetPub(void)
Select the variant.
Definition: Seqdesc_.cpp:362
const TPub & GetPub(void) const
Get the variant data.
Definition: Seqdesc_.cpp:356
void ResetPub(void)
Reset Pub data member.
Definition: Pubdesc_.cpp:63
bool IsPub(void) const
Check if variant Pub is selected.
Definition: Seqdesc_.hpp:1096
void SetCit(TCit &value)
Assign a value to Cit data member.
bool IsSetCit(void) const
citation for this submission Check if a value has been assigned to Cit data member.
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
bool SetAuthorNames(CPubdesc &pdesc, const CAuth_list &auth_list)
Definition: pub_field.cpp:170
bool SetAuthList(CPubdesc &pdesc, const CAuth_list &auth_list)
Definition: pub_field.cpp:120
CConstRef< CAuth_list > GetAuthList(const CPubdesc &pubdesc)
Definition: pub_field.cpp:82
string GetPubTitle(CConstRef< CObject > sel_pub)
Definition: pub_field.cpp:312
static static static wxID_ANY
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
@ eExistingText_replace_old
#define _ASSERT
void SetWorkDir(wxWindow *wnd, const wxString &workDir)
Definition: work_dir.cpp:38
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
wxRect GetScreenRect(const wxWindow &win)
Definition: wx_utils.cpp:783
Modified on Fri Sep 20 14:58:05 2024 by modify_doxy.py rev. 669887