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 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: 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  {
178  int max_x = 0;
179  for (auto i = 0; i < wxDisplay::GetCount(); i++) // also see gui/widgets/wx/wx_utils.cpp:CorrectWindowRect() for alternative window position validation
180  {
181  wxDisplay display(i);
182  max_x += display.GetGeometry().GetWidth();
183  }
184  if (pos_x + width > max_x) pos_x = wxGetDisplaySize().GetWidth()-width-5;
185  if (pos_y + height > wxGetDisplaySize().GetHeight()) pos_y = wxGetDisplaySize().GetHeight()-height-5;
186 
187  SetPosition(wxPoint(pos_x,pos_y));
188  }
189 }
190 
191 
192 /*!
193  * Member initialisation
194  */
195 
197 {
198 ////@begin CEditPubDlg member initialisation
199  m_Notebook = NULL;
203  m_OkCancel = NULL;
204 ////@end CEditPubDlg member initialisation
205 }
206 
207 
208 /*!
209  * Control creation for CEditPubDlg
210  */
211 
213 {
214 ////@begin CEditPubDlg content construction
215  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
216  SetSizer(itemBoxSizer1);
217 
218  wxPanel* itemCBulkCmdDlg1 = new wxPanel(this, wxID_ANY);
219  itemBoxSizer1->Add(itemCBulkCmdDlg1, 1, wxGROW, 0);
220 
221  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
222  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
223 
224  m_Notebook = new wxNotebook(itemCBulkCmdDlg1, wxID_ANY,wxDefaultPosition,wxDefaultSize);
225  itemBoxSizer2->Add(m_Notebook, 1, wxGROW|wxALL, 5);
226 
228  m_Notebook->AddPage(panel1,_("Replace section"));
229 
231  m_Notebook->AddPage(panel2,_("Replace entire pub"));
232 
234  m_Notebook->AddPage(panel3,_("Replace single field"));
235 
236 
237  CRef<CAuth_list> authors;
238  CConstRef<CObject> sel_pub = GetSelectedPub();
239  if (sel_pub)
240  {
241  CConstRef<CAuth_list> auth_list = GetAuthList(sel_pub);
242  if (auth_list)
243  {
244  authors.Reset(new CAuth_list());
245  authors->Assign(*auth_list);
246  }
247  }
248 
249  CAuthorReplacePanel *panel4 = new CAuthorReplacePanel(m_Notebook, this, authors);
250  m_Notebook->AddPage(panel4,_("Global author replace"));
251 
252  wxStaticBox* constraintDetails = new wxStaticBox(itemCBulkCmdDlg1, wxID_ANY, _("Constraint"));
253  wxStaticBoxSizer* itemStaticBoxSizer9 = new wxStaticBoxSizer(constraintDetails, wxVERTICAL);
254  itemBoxSizer2->Add(itemStaticBoxSizer9, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
255 
256  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
257  itemStaticBoxSizer9->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
258 
259  m_Fieldhandler = new CFieldHandlerNamePanel(itemStaticBoxSizer9->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0);
261  itemBoxSizer10->Add(m_Fieldhandler, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
262 
263  m_StrConstraintPanel = new CStringConstraintPanel(itemStaticBoxSizer9->GetStaticBox(), true, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0);
264  itemBoxSizer10->Add(m_StrConstraintPanel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
265 
266  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
267  itemStaticBoxSizer9->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 2);
268 
269  wxStaticText* itemStaticText14 = new wxStaticText( itemStaticBoxSizer9->GetStaticBox(), wxID_STATIC, _("Publication Status"), wxDefaultPosition, wxDefaultSize, 0 );
270  itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
271 
272  wxArrayString m_PubStatusConstraintStrings;
273  m_PubStatusConstraintStrings.Add(_("Any"));
274  m_PubStatusConstraintStrings.Add(_("Published"));
275  m_PubStatusConstraintStrings.Add(_("Unpublished"));
276  m_PubStatusConstraintStrings.Add(_("In Press"));
277  m_PubStatusConstraintStrings.Add(_("Submitter Block"));
278  m_PubStatusConstraint = new wxChoice( itemStaticBoxSizer9->GetStaticBox(), ID_PUB_STATUS_CONSTRAINT, wxDefaultPosition, wxDefaultSize, m_PubStatusConstraintStrings, 0 );
279  m_PubStatusConstraint->SetStringSelection(_("Any"));
280  itemBoxSizer13->Add(m_PubStatusConstraint, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
281 
282  m_OkCancel = new COkCancelPanel(itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0);
283  itemBoxSizer2->Add(m_OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
284 
285 
286 ////@end CEditPubDlg content construction
287 
289  return;
290 
292  if (!srv) return;
293 
294  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
295  if (!ws) return;
296 
297  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(m_TopSeqEntry.GetScope()));
298  if (!doc) return;
299 
300  SetWorkDir(this, doc->GetWorkDir());
301 }
302 
303 
304 /*!
305  * Should we show tooltips?
306  */
307 
309 {
310  return true;
311 }
312 
313 /*!
314  * Get bitmap resources
315  */
316 
317 wxBitmap CEditPubDlg::GetBitmapResource( const wxString& name )
318 {
319  // Bitmap retrieval
320 ////@begin CEditPubDlg bitmap retrieval
321  wxUnusedVar(name);
322  return wxNullBitmap;
323 ////@end CEditPubDlg bitmap retrieval
324 }
325 
326 /*!
327  * Get icon resources
328  */
329 
330 wxIcon CEditPubDlg::GetIconResource( const wxString& name )
331 {
332  // Icon retrieval
333 ////@begin CEditPubDlg icon retrieval
334  wxUnusedVar(name);
335  return wxNullIcon;
336 ////@end CEditPubDlg icon retrieval
337 }
338 
339 
341 {
342  return m_ErrorMessage;
343 }
344 
345 const string kUnknownError = "Unknown error";
346 
348 {
351  if (!m_TopSeqEntry) {
352  return cmd;
353  }
354 
355  string constraint_field = m_Fieldhandler->GetFieldName(true);
356  string ncRNA_class;
359  CRef<CConstraintMatcher>(new CSimpleConstraintMatcher(string_constraint)));
360 
361  string desired_status = GetStatusConstraint();
364  *constraint1 += constraint2;
365 
366  vector<CSeq_entry_Handle> descr_ctxt;
367  vector<CConstRef<CObject>> objs = GetObjects(m_TopSeqEntry, "status", CFieldNamePanel::eFieldType_Pub, -1, kEmptyStr, m_SeqSubmit, constraint1, &descr_ctxt);
368 
369 
370  if (objs.empty())
371  {
372  m_ErrorMessage = "No publications found!";
373  return cmd;
374  }
375 
376  int sel = m_Notebook->GetSelection();
377  bool any_change(false);
378  CEditPubCmdPanel *win = dynamic_cast<CEditPubCmdPanel*>(m_Notebook->GetPage(sel));
379  if (win)
380  {
381  cmd = win->GetCommand(objs, descr_ctxt);
382  }
383 
385  {
386  wxMessageBox(wxT("No effect!"), wxT("Error"), wxOK | wxICON_ERROR, NULL);
387  }
388 
389  return cmd;
390 }
391 
393 {
396  if (!sel_srv) return CConstRef<CObject>(NULL);
397  sel_srv->GetCurrentSelection(objects);
398  if (objects.empty()) return CConstRef<CObject>(NULL);
400  const CObject* ptr = it->object.GetPointer();
401  const CSeqdesc* seqdesc = dynamic_cast<const CSeqdesc*>(ptr);
402  const CSeq_feat* seqfeat = dynamic_cast<const CSeq_feat*>(ptr);
403  const CCit_sub* citsub = dynamic_cast<const CCit_sub*>(ptr);
404  const CPubdesc* pubdesc = dynamic_cast<const CPubdesc*>(ptr);
405  const CSubmit_block* block = dynamic_cast<const CSubmit_block*>(ptr);
406  if (seqdesc && seqdesc->IsPub()) {
407  return CConstRef<CObject>(seqdesc);
408  } else if (seqfeat && seqfeat->IsSetData() && seqfeat->GetData().IsPub()) {
409  return CConstRef<CObject>(seqfeat);
410  } else if (citsub) {
411  return CConstRef<CObject>(citsub);
412  } else if (pubdesc) {
413  return CConstRef<CObject>(pubdesc);
414  } else if (block && block->IsSetCit()) {
415  return CConstRef<CObject>(block);
416  }
417  }
418  return CConstRef<CObject>(NULL);
419 }
420 
421 
422 void CEditPubDlg::AppendToErrorMsg(const string &msg)
423 {
425  m_ErrorMessage = msg + "\n";
426  } else {
427  m_ErrorMessage += msg + "\n";
428  }
429 }
430 
431 
432 IMPLEMENT_DYNAMIC_CLASS( CEditPubSubpanel, wxPanel )
433 BEGIN_EVENT_TABLE( CEditPubSubpanel, wxPanel )
435 
436 IMPLEMENT_DYNAMIC_CLASS( CReplaceSectionPanel, CEditPubSubpanel )
437 
438 BEGIN_EVENT_TABLE( CReplaceSectionPanel, CEditPubSubpanel )
440 
441 void CReplaceSectionPanel::CreateControls()
442 {
443  CReplaceSectionPanel* itemPanel1 = this;
444 
445  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
446  itemPanel1->SetSizer(itemBoxSizer2);
447 
448  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
449  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL, 0);
450 
451  m_AuthorListSection = new wxCheckBox( this, wxID_ANY, wxT("Replace author list with selected author list"), wxDefaultPosition, wxDefaultSize, 0 );
452  itemBoxSizer3->Add(m_AuthorListSection, 0, wxALIGN_LEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
453  m_TitleSection = new wxCheckBox( this, wxID_ANY, wxT("Replace title with selected title"), wxDefaultPosition, wxDefaultSize, 0 );
454  itemBoxSizer3->Add(m_TitleSection, 0, wxALIGN_LEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
455  m_AffiliationSection = new wxCheckBox( this, wxID_ANY, wxT("Replace affiliation with selected affiliation"), wxDefaultPosition, wxDefaultSize, 0 );
456  itemBoxSizer3->Add(m_AffiliationSection, 0, wxALIGN_LEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
457 }
458 
459 CRef<CCmdComposite> CReplaceSectionPanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
460 {
461  CRef<CCmdComposite> cmd(new CCmdComposite("Edit Publications"));
462 
464  if (!sel_pub)
465  {
466  m_dlg->AppendToErrorMsg("No publication is selected to use as a source!");
467  return CRef<CCmdComposite> (NULL);
468  }
469  CConstRef<CAuth_list> auth_list = GetAuthList(sel_pub);
470  string title = GetPubTitle(sel_pub);
471 
472  bool any_change = false;
473  auto obj_it = objs.begin();
474  auto seh_it = descr_ctxt.begin();
475  _ASSERT(objs.size() == descr_ctxt.size());
476  for ( ; obj_it != objs.end() && seh_it != descr_ctxt.end(); ++obj_it, ++seh_it)
477  {
478  const CSeqdesc* d = dynamic_cast<const CSeqdesc* >(obj_it->GetPointer());
479  if (d && d->IsPub()) {
480  bool this_change = false;
481  CRef<CSeqdesc> new_desc(new CSeqdesc());
482  new_desc->Assign(*d);
483 
484  if (m_AuthorListSection->GetValue() && auth_list) {
485  this_change = SetAuthorNames(new_desc->SetPub(), *auth_list);
486  }
487  if (m_AffiliationSection->GetValue() && auth_list && auth_list->IsSetAffil()) {
488  CConstRef<CAuth_list> this_auth = GetAuthList(new_desc->GetPub());
489  CRef<CAuth_list> new_auth(new CAuth_list());
490  new_auth->Assign(*this_auth);
491  new_auth->SetAffil().Assign(auth_list->GetAffil());
492  this_change |= SetAuthList(new_desc->SetPub(), *new_auth);
493  }
494  if (m_TitleSection->GetValue()) {
495  bool skip_cit_sub = true;
496  this_change |= CPubField::SetPubTitle (new_desc->SetPub(), title, edit::eExistingText_replace_old, skip_cit_sub);
497  }
498 
499  if (this_change) {
500  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(*seh_it, *d, *new_desc));
501  cmd->AddCommand (*ecmd);
502  any_change = true;
503  }
504  }
505  }
506 
507  if (!any_change) {
508  cmd.Reset(NULL);
509  m_dlg->AppendToErrorMsg("No action.");
510  }
511 
512  return cmd;
513 }
514 
515 
516 
517 IMPLEMENT_DYNAMIC_CLASS( CReplaceEntirePubPanel, CEditPubSubpanel )
518 
519 BEGIN_EVENT_TABLE( CReplaceEntirePubPanel, CEditPubSubpanel )
521 
522 void CReplaceEntirePubPanel::CreateControls()
523 {
524  CReplaceEntirePubPanel* itemPanel1 = this;
525 
526  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
527  itemPanel1->SetSizer(itemBoxSizer2);
528 
529  wxStaticText* instructions = new wxStaticText( this, wxID_STATIC, wxT("Replace with selected publication or submitter block"), wxDefaultPosition, wxDefaultSize, 0 );
530  itemBoxSizer2->Add(instructions, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
531 }
532 
533 CRef<CCmdComposite> CReplaceEntirePubPanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
534 {
536  if (!sel_pub)
537  {
538  m_dlg->AppendToErrorMsg("No publication is selected to use as a source!");
539  return CRef<CCmdComposite> (NULL);
540  }
541 
542  const CSeqdesc* orig_desc = dynamic_cast<const CSeqdesc* >(sel_pub.GetPointer());
543  const CSeq_feat* orig_feat = dynamic_cast<const CSeq_feat*>(sel_pub.GetPointer());
544  const CCit_sub* citsub = dynamic_cast<const CCit_sub*>(sel_pub.GetPointer());
545  const CPubdesc* pubdesc = dynamic_cast<const CPubdesc*>(sel_pub.GetPointer());
546 
547  bool any_change = false;
548  bool check_status = NStr::EqualNocase(m_dlg->GetStatusConstraint(), "Any");
549 
550  CRef<CCmdComposite> cmd(new CCmdComposite("Edit Publications"));
551  auto obj_it = objs.begin();
552  auto seh_it = descr_ctxt.begin();
553  _ASSERT(objs.size() == descr_ctxt.size());
554  for (; obj_it != objs.end() && seh_it != descr_ctxt.end(); ++obj_it, ++seh_it)
555  {
556  if (obj_it->GetPointer() == sel_pub.GetPointer()) {
557  continue;
558  }
559  // skip pubs with status submitter, only when "Replace entire publication" is selected
560  if (check_status) {
561  string status = CPubField::GetStatus(**obj_it);
562  if (NStr::EqualNocase(status, "Submitter Block"))
563  {
564  continue;
565  }
566  }
567  const CSeqdesc* d = dynamic_cast<const CSeqdesc* >(obj_it->GetPointer());
568  if (d && d->IsPub() && pubdesc != &(d->GetPub())) {
569  CRef<CSeqdesc> new_desc(new CSeqdesc());
570  bool this_change = false;
571  if (orig_desc) {
572  new_desc->Assign(*orig_desc);
573  this_change = true;
574  } else if (orig_feat) {
575  new_desc->Assign(*d);
576  new_desc->SetPub().Assign(orig_feat->GetData().GetPub());
577  this_change = true;
578  } else if (citsub) {
579  new_desc->Assign(*d);
580  new_desc->SetPub().ResetPub();
581  CRef<CPub> new_pub(new CPub());
582  new_pub->SetSub().Assign(*citsub);
583  new_desc->SetPub().SetPub().Set().push_back(new_pub);
584  this_change = true;
585  } else if (pubdesc) {
586  new_desc->Assign(*d);
587  new_desc->SetPub().Assign(*pubdesc);
588  this_change = true;
589  }
590  if (this_change) {
591  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(*seh_it, *d, *new_desc));
592  cmd->AddCommand (*ecmd);
593  any_change = true;
594  }
595  }
596  }
597 
598  if (!any_change)
599  {
600  cmd.Reset(NULL);
601  m_dlg->AppendToErrorMsg("No target publications.");
602  }
603 
604  return cmd;
605 }
606 
607 
608 IMPLEMENT_DYNAMIC_CLASS( CReplaceSingleFieldPanel, CEditPubSubpanel )
609 
610 BEGIN_EVENT_TABLE( CReplaceSingleFieldPanel, CEditPubSubpanel )
612 
613 void CReplaceSingleFieldPanel::CreateControls()
614 {
615  CReplaceSingleFieldPanel* itemPanel1 = this;
616 
617  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
618  itemPanel1->SetSizer(itemBoxSizer2);
619 
620  m_PubField = new CFieldHandlerNamePanel(this);
621  m_PubField->SetFieldNames(CPubFieldType::GetFieldNames());
622  itemBoxSizer2->Add(m_PubField, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
623  m_FieldText = new wxTextCtrl(this, wxID_ANY);
624  itemBoxSizer2->Add(m_FieldText, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
625 }
626 
627 CRef<CCmdComposite> CReplaceSingleFieldPanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
628 {
629  string field_name = m_PubField->GetFieldName(true);
630  if (NStr::IsBlank(field_name))
631  {
632  m_dlg->AppendToErrorMsg("You must select a field to apply.");
633  return CRef<CCmdComposite>(NULL);
634  }
635 
636  string val = ToStdString(m_FieldText->GetValue());
637  string constraint_field = m_dlg->GetFieldName(true);
639 
640  string desired_status = m_dlg->GetStatusConstraint();
641 
643 
644  string ncRNA_class;
647  CRef<CConstraintMatcher>(new CSimpleConstraintMatcher(string_constraint)));
650  *constraint1 += constraint2;
651  action->SetConstraint(constraint1);
652  action->SetExistingText(edit::eExistingText_replace_old);
653  action->Apply(val);
654  CRef<CCmdComposite> cmd = action->GetActionCommand();
655  if (!cmd)
656  {
657  m_dlg->AppendToErrorMsg("No action.");
658  }
659 
660  return cmd;
661 }
662 
663 
664 IMPLEMENT_DYNAMIC_CLASS( CAuthorReplacePanel, CEditPubSubpanel )
665 
666 BEGIN_EVENT_TABLE( CAuthorReplacePanel, CEditPubSubpanel )
668 
669 void CAuthorReplacePanel::CreateControls()
670 {
671  CAuthorReplacePanel* itemPanel1 = this;
672 
673  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
674  itemPanel1->SetSizer(itemBoxSizer2);
675 
676  if (!m_Authors)
677  {
678  m_Authors.Reset(new CAuth_list());
679  }
680  m_AuthorsPanel = new CAuthorNamesPanel(this, *m_Authors, false);
681  itemBoxSizer2->Add(m_AuthorsPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5);
682  m_AuthorsPanel->TransferDataToWindow();
683 }
684 
685 CRef<CCmdComposite> CAuthorReplacePanel::GetCommand(const vector<CConstRef<CObject>>& objs, const vector<CSeq_entry_Handle>& descr_ctxt)
686 {
687  if (!m_Authors)
688  {
689  m_Authors.Reset(new CAuth_list());
690  }
692  if (!m_Authors->IsSetNames() || m_Authors->GetNameCount() == 0)
693  {
694  m_dlg->AppendToErrorMsg("You must supply an author list.");
695  return CRef<CCmdComposite>(NULL);
696  }
697 
698 
699  CAuth_list& edited_auth_list = *m_Authors;
700  if (!edited_auth_list.IsSetNames())
701  {
702  m_dlg->AppendToErrorMsg("No names set.");
703  return CRef<CCmdComposite>(NULL);
704  }
705  CAuth_list::TNames& edited_names = edited_auth_list.SetNames();
706 
707  bool any_modified = false;
708  CRef<CCmdComposite> comp_cmd(new CCmdComposite("Replace All Authors"));
709  auto obj_it = objs.begin();
710  auto seh_it = descr_ctxt.begin();
711  _ASSERT(objs.size() == descr_ctxt.size());
712  for (; obj_it != objs.end() && seh_it != descr_ctxt.end(); ++obj_it, ++seh_it)
713  {
714  if (const CSeqdesc* desc = dynamic_cast<const CSeqdesc* >(obj_it->GetPointer())) {
715  if (desc->IsPub()) {
716  CRef<CSeqdesc> replacement(new CSeqdesc());
717  replacement->Assign(*desc);
718  bool modified = false;
719  NON_CONST_ITERATE(CPub_equiv::Tdata, pub, replacement->SetPub().SetPub().Set())
720  {
721  switch ((*pub)->Which())
722  {
723  case CPub::e_Gen:
724  (*pub)->SetGen().SetAuthors().SetNames(edited_names);
725  break;
726  case CPub::e_Article:
727  (*pub)->SetArticle().SetAuthors().SetNames(edited_names);
728  break;
729  case CPub::e_Book:
730  (*pub)->SetBook().SetAuthors().SetNames(edited_names);
731  break;
732  case CPub::e_Proc:
733  (*pub)->SetProc().SetBook().SetAuthors().SetNames(edited_names);
734  break;
735  case CPub::e_Sub:
736  (*pub)->SetSub().SetAuthors().SetNames(edited_names);
737  break;
738  case CPub::e_Patent:
739  (*pub)->SetPatent().SetAuthors().SetNames(edited_names);
740  break;
741  case CPub::e_Man:
742  (*pub)->SetMan().SetCit().SetAuthors().SetNames(edited_names);
743  break;
744  default:
745  (*pub)->SetGen().SetAuthors().SetNames(edited_names);
746  break;
747  }
748  modified = true;
749  }
750  if (modified)
751  {
752  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(*seh_it, *desc, *replacement));
753  comp_cmd->AddCommand(*ecmd);
754  any_modified = true;
755  }
756  }
757  }
758  else if (const CSubmit_block* block = dynamic_cast<const CSubmit_block*>(obj_it->GetPointer())) {
759  CRef<CSubmit_block> new_submit_block(new CSubmit_block);
760  new_submit_block->Assign(*block);
761 
762  CAuth_list& authors = new_submit_block->SetCit().SetAuthors();
763  authors.SetNames(edited_names);
764 
766  CObject* actual = (CObject*)(block);
767  cmd->Add(actual, CConstRef<CObject>(new_submit_block));
768  comp_cmd->AddCommand(*cmd);
769  any_modified = true;
770  }
771 
772  }
773 
774  if (!any_modified)
775  {
776  comp_cmd.Reset();
777  m_dlg->AppendToErrorMsg("No action.");
778  }
779  return comp_cmd;
780 }
781 
783 
@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:5353
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:5384
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
@ 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 Sat May 25 14:17:26 2024 by modify_doxy.py rev. 669887