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

Go to the SVN repository for this file.

1 /* $Id: relaxed_lookup_dlg.cpp 47624 2023-12-14 19:30:14Z 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
27  */
28 
29 #include <ncbi_pch.hpp>
30 
31 #include <objects/pub/Pub.hpp>
38 #include <objects/biblio/Title.hpp>
42 
47 
51 #include <gui/utils/app_popup.hpp>
52 #include <wx/radiobut.h>
53 #include <wx/stattext.h>
54 #include <wx/statbox.h>
55 
56 
59 
60 /*
61  * CRelaxedLookupDlg type definition
62  */
63 
64 IMPLEMENT_DYNAMIC_CLASS( CRelaxedLookupDlg, wxDialog )
65 
66 
67 /*
68  * CRelaxedLookupDlg event table definition
69  */
70 
71 BEGIN_EVENT_TABLE( CRelaxedLookupDlg, wxDialog )
72 
73 ////@begin CRelaxedLookupDlg event table entries
75 
76 ////@end CRelaxedLookupDlg event table entries
77 
79 
80 
81 /*
82  * CRelaxedLookupDlg constructors
83  */
84 
86 {
87  Init();
88 }
89 
90 CRelaxedLookupDlg::CRelaxedLookupDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
91 {
92  Init();
93  Create(parent, id, caption, pos, size, style);
94 }
95 
96 
97 /*
98  * CRelaxedLookupDlg creator
99  */
100 
101 bool CRelaxedLookupDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
102 {
103 ////@begin CRelaxedLookupDlg creation
104  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
105  wxDialog::Create( parent, id, caption, pos, size, style );
106 
107  CreateControls();
108  if (GetSizer())
109  {
110  GetSizer()->SetSizeHints(this);
111  }
112  Centre();
113 ////@end CRelaxedLookupDlg creation
114  return true;
115 }
116 
117 
118 /*
119  * CRelaxedLookupDlg destructor
120  */
121 
123 {
124 ////@begin CRelaxedLookupDlg destruction
125 ////@end CRelaxedLookupDlg destruction
126 }
127 
128 
129 /*
130  * Member initialisation
131  */
132 
134 {
135 ////@begin CRelaxedLookupDlg member initialisation
142  m_JournalTxt = NULL;
143  m_UseYearBtn = NULL;
144  m_YearTxt = NULL;
148  m_UsePageBtn = NULL;
149  m_UsePageTxt = NULL;
155  m_Sizer = NULL;
156 ////@end CRelaxedLookupDlg member initialisation
157 }
158 
159 
160 /*
161  * Control creation for CRelaxedLookupDlg
162  */
163 
165 {
166 ////@begin CRelaxedLookupDlg content construction
167  CRelaxedLookupDlg* itemDialog1 = this;
168 
169  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
170  itemDialog1->SetSizer(itemBoxSizer2);
171 
172  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
173  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
174 
175  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Number of potential matches (Max 20):"), wxDefaultPosition, wxDefaultSize, 0 );
176  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
177 
178  m_MaxMatchTxt = new wxTextCtrl( itemDialog1, ID_MAX_MATCH_TXT, _("20"), wxDefaultPosition, wxDefaultSize, 0 );
179  itemBoxSizer3->Add(m_MaxMatchTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
180 
181  wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Available information on this in-press citation:"));
182  wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer(itemStaticBoxSizer6Static, wxVERTICAL);
183  itemBoxSizer2->Add(itemStaticBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
184 
185  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
186  itemStaticBoxSizer6->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
187 
188  m_UseFirstAuthorBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_USE_FIRST_AUTHOR_BTN, _("First Author"), wxDefaultPosition, wxDefaultSize, 0 );
189  m_UseFirstAuthorBtn->SetValue(false);
190  itemBoxSizer7->Add(m_UseFirstAuthorBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
191 
192  m_FirstAuthorTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_FIRST_AUTHOR_TXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
193  itemBoxSizer7->Add(m_FirstAuthorTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
194 
195  m_UseLastAuthorBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_USE_LAST_AUTHOR_BTN, _("Last Author"), wxDefaultPosition, wxDefaultSize, 0 );
196  m_UseLastAuthorBtn->SetValue(false);
197  itemBoxSizer7->Add(m_UseLastAuthorBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
198 
199  m_LastAuthorTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_LAST_AUTHOR_TXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
200  itemBoxSizer7->Add(m_LastAuthorTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
201 
202  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
203  itemStaticBoxSizer6->Add(itemBoxSizer12, 0, wxGROW|wxALL, 5);
204 
205  m_UseJournalBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_USE_JOURNAL_BTN, _("Journal"), wxDefaultPosition, wxDefaultSize, 0 );
206  m_UseJournalBtn->SetValue(false);
207  itemBoxSizer12->Add(m_UseJournalBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
208 
209  m_JournalTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_JOURNAL_TXT, wxEmptyString, wxDefaultPosition, wxSize(500, -1), 0 );
210  itemBoxSizer12->Add(m_JournalTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
211 
212  wxBoxSizer* itemBoxSizer15 = new wxBoxSizer(wxHORIZONTAL);
213  itemStaticBoxSizer6->Add(itemBoxSizer15, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
214 
215  m_UseYearBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_USE_YEAR_BTN, _("Year"), wxDefaultPosition, wxDefaultSize, 0 );
216  m_UseYearBtn->SetValue(false);
217  itemBoxSizer15->Add(m_UseYearBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
218 
219  m_YearTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_YEAR_TXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
220  itemBoxSizer15->Add(m_YearTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
221 
222  m_YearFuzzBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_YEAR_FUZZ_BTN, _("+/- 1 Year"), wxDefaultPosition, wxDefaultSize, 0 );
223  m_YearFuzzBtn->SetValue(true);
224  itemBoxSizer15->Add(m_YearFuzzBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
225 
226  m_UseVolumeBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_USE_VOLUME_BTN, _("Volume"), wxDefaultPosition, wxDefaultSize, 0 );
227  m_UseVolumeBtn->SetValue(false);
228  itemBoxSizer15->Add(m_UseVolumeBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
229 
230  m_UseVolumeTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_USE_VOLUME_TXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
231  itemBoxSizer15->Add(m_UseVolumeTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
232 
233  m_UsePageBtn = new wxCheckBox( itemStaticBoxSizer6->GetStaticBox(), ID_USE_PAGE_BTN, _("Page"), wxDefaultPosition, wxDefaultSize, 0 );
234  m_UsePageBtn->SetValue(false);
235  itemBoxSizer15->Add(m_UsePageBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
236 
237  m_UsePageTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_PAGE_TXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
238  itemBoxSizer15->Add(m_UsePageTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
239 
240  wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxHORIZONTAL);
241  itemStaticBoxSizer6->Add(itemBoxSizer23, 0, wxGROW|wxALL, 5);
242 
243  wxStaticText* itemStaticText24 = new wxStaticText( itemStaticBoxSizer6->GetStaticBox(), wxID_STATIC, _("Article Title:"), wxDefaultPosition, wxDefaultSize, 0 );
244  itemBoxSizer23->Add(itemStaticText24, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
245 
246  m_ArticleTitleTxt = new wxTextCtrl( itemStaticBoxSizer6->GetStaticBox(), ID_ARTICLE_TITLE_TXT, wxEmptyString, wxDefaultPosition, wxSize(500, -1), wxTE_MULTILINE );
247  itemBoxSizer23->Add(m_ArticleTitleTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
248 
249  wxBoxSizer* itemBoxSizer26 = new wxBoxSizer(wxHORIZONTAL);
250  itemBoxSizer2->Add(itemBoxSizer26, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
251 
252  m_UseExtraTermsBtn = new wxCheckBox( itemDialog1, ID_USE_EXTRA_TERMS_BTN, _("Add these terms to new query"), wxDefaultPosition, wxDefaultSize, 0 );
253  m_UseExtraTermsBtn->SetValue(false);
254  itemBoxSizer26->Add(m_UseExtraTermsBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
255 
256  m_ExtraTermsTxt = new wxTextCtrl( itemDialog1, ID_EXTRA_TERMS_TXT, wxEmptyString, wxDefaultPosition, wxSize(400, -1), 0 );
257  itemBoxSizer26->Add(m_ExtraTermsTxt, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
258 
259  wxBoxSizer* itemBoxSizer29 = new wxBoxSizer(wxHORIZONTAL);
260  itemBoxSizer2->Add(itemBoxSizer29, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
261 
262  wxStaticText* itemStaticText30 = new wxStaticText( itemDialog1, wxID_STATIC, _("New query option:"), wxDefaultPosition, wxDefaultSize, 0 );
263  itemBoxSizer29->Add(itemStaticText30, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
264 
265  wxArrayString m_NewQueryChoiceStrings;
266  m_NewQueryChoiceStrings.Add(_("default: use all fields"));
267  m_NewQueryChoiceStrings.Add(_("customize: use checked fields"));
268  m_NewQueryChoice = new wxChoice( itemDialog1, ID_NEW_QUERY_CHOICE, wxDefaultPosition, wxDefaultSize, m_NewQueryChoiceStrings, 0 );
269  m_NewQueryChoice->SetStringSelection(_("default: use all fields"));
270  itemBoxSizer29->Add(m_NewQueryChoice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
271 
272  wxButton* itemButton32 = new wxButton( itemDialog1, ID_SEND_QUERY, _("Send Modified Query"), wxDefaultPosition, wxDefaultSize, 0 );
273  itemBoxSizer29->Add(itemButton32, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
274 
275  wxStaticText* itemStaticText33 = new wxStaticText( itemDialog1, wxID_STATIC, _("Summary of potential matches, highlight one to use in update"), wxDefaultPosition, wxDefaultSize, 0 );
276  itemBoxSizer2->Add(itemStaticText33, 0, wxALIGN_LEFT|wxALL, 5);
277 
278  m_ScrolledWindow = new wxScrolledWindow( itemDialog1, ID_SCROLLEDWINDOW, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
279  itemBoxSizer2->Add(m_ScrolledWindow, 0, wxGROW|wxALL, 5);
280  m_ScrolledWindow->SetScrollbars(1, 1, 0, 0);
281  m_Sizer = new wxBoxSizer(wxVERTICAL);
282  m_ScrolledWindow->SetSizer(m_Sizer);
283 
284  m_ScrolledWindow->SetMinSize(wxSize(100, 200));
285 
286  wxBoxSizer* itemBoxSizer36 = new wxBoxSizer(wxHORIZONTAL);
287  itemBoxSizer2->Add(itemBoxSizer36, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
288 
289  wxButton* itemButton37 = new wxButton( itemDialog1, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
290  itemBoxSizer36->Add(itemButton37, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
291 
292  wxButton* itemButton38 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
293  itemBoxSizer36->Add(itemButton38, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
294 
295 ////@end CRelaxedLookupDlg content construction
296 }
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 CRelaxedLookupDlg::GetBitmapResource( const wxString& name )
313 {
314  // Bitmap retrieval
315 ////@begin CRelaxedLookupDlg bitmap retrieval
316  wxUnusedVar(name);
317  return wxNullBitmap;
318 ////@end CRelaxedLookupDlg bitmap retrieval
319 }
320 
321 /*
322  * Get icon resources
323  */
324 
325 wxIcon CRelaxedLookupDlg::GetIconResource( const wxString& name )
326 {
327  // Icon retrieval
328 ////@begin CRelaxedLookupDlg icon retrieval
329  wxUnusedVar(name);
330  return wxNullIcon;
331 ////@end CRelaxedLookupDlg icon retrieval
332 }
333 
334 
335 /*
336  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SEND_QUERY
337  */
338 
339 void CRelaxedLookupDlg::OnSendQueryClick( wxCommandEvent& event )
340 {
341  SendQuery();
342 }
343 
344 
345 void CRelaxedLookupDlg::OnPubTextClick( wxMouseEvent& event )
346 {
347  // Find radio button next to text, select
348  wxStaticText* item = (wxStaticText*)event.GetEventObject();
349  wxWindow* prev = item->GetPrevSibling();
350  if (prev) {
351  wxRadioButton* btn = dynamic_cast<wxRadioButton*>(prev);
352  if (btn) {
353  btn->SetValue(true);
354  }
355  }
356 }
357 
358 
359 void CRelaxedLookupDlg::OnPubTextDClick( wxMouseEvent& event )
360 {
361  if (!m_Sizer) {
362  return;
363  }
364  // Find pub for clicked text, launch URL for pub
365  wxStaticText* pubitem = (wxStaticText*)event.GetEventObject();
366  if (!pubitem) {
367  return;
368  }
369 
370  wxSizerItemList::iterator node = m_Sizer->GetChildren().begin();
371  vector<CRef<CPubdesc> >::iterator pub_it = m_Pubs.begin();
372  while (pub_it != m_Pubs.end() && !(*pub_it)) {
373  ++pub_it;
374  }
375 
377 
378  for (; node != m_Sizer->GetChildren().end() && pub_it != m_Pubs.end() && pmid == ZERO_ENTREZ_ID; ++node) {
379  if ((*node)->IsSizer()) {
380  wxStaticText *w = dynamic_cast<wxStaticText *>((*node)->GetSizer()->GetItem((size_t)1)->GetWindow());
381  if (w && w == pubitem) {
382  ITERATE(CPubdesc::TPub::Tdata, pit, (*pub_it)->GetPub().Get()) {
383  if ((*pit)->IsPmid()) {
384  pmid.Set((*pit)->GetPmid().Get());
385  break;
386  }
387  }
388  }
389  ++pub_it;
390  while (pub_it != m_Pubs.end() && !(*pub_it)) {
391  ++pub_it;
392  }
393  }
394  }
395  if (pmid > ZERO_ENTREZ_ID) {
396  string url = "https://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids=" +
397  NStr::NumericToString(pmid.Get()) + "&dopt=Abstract";
398  CAppPopup::PopupURL(url);
399  }
400 }
401 
402 
404 {
405  m_MaxMatchTxt->SetValue(wxT("20"));
406  m_UseFirstAuthorBtn->SetValue(false);
407  m_FirstAuthorTxt->SetValue(wxEmptyString);
408  m_UseLastAuthorBtn->SetValue(false);
409  m_LastAuthorTxt->SetValue(wxEmptyString);
410  m_UseJournalBtn->SetValue(false);
411  m_JournalTxt->SetValue(wxEmptyString);
412  m_UseYearBtn->SetValue(false);
413  m_YearTxt->SetValue(wxEmptyString);
414  m_UseVolumeBtn->SetValue(false);
415  m_UseVolumeTxt->SetValue(wxEmptyString);
416  m_UsePageBtn->SetValue(false);
417  m_UsePageTxt->SetValue(wxEmptyString);
418  m_UseExtraTermsBtn->SetValue(false);
419  m_ExtraTermsTxt->SetValue(wxEmptyString);
420 }
421 
422 
423 string s_GetStringFromAuthor(const CAuthor& auth)
424 {
425  string val = "";
426 
427  if (auth.IsSetName() && auth.GetName().IsName()
428  && auth.GetName().GetName().IsSetLast()) {
429  val = auth.GetName().GetName().GetLast();
430  }
431  return val;
432 }
433 
434 
436 {
437  Clear();
438  m_Authors.clear();
440  if (pubdesc.IsSetPub()) {
441  ITERATE(CPubdesc::TPub::Tdata, pub_it, pubdesc.GetPub().Get()) {
442  if ((*pub_it)->IsArticle()) {
443  m_CitMatch.Reset(new CPub);
444  m_CitMatch->Assign(**pub_it);
445  const CCit_art& article = (*pub_it)->GetArticle();
446  if (article.IsSetTitle()) {
447  try {
448  string title = article.GetTitle().GetTitle();
449  m_ArticleTitleTxt->SetValue(ToWxString(title));
450  } catch(CException&) {} catch (exception&) {}
451  }
452  if ((*pub_it)->IsSetAuthors()
453  && (*pub_it)->GetAuthors().IsSetNames()
454  && (*pub_it)->GetAuthors().GetNames().IsStd()
455  && (*pub_it)->GetAuthors().GetNames().GetStd().size() > 0) {
456  const CAuthor& first_auth = *((*pub_it)->GetAuthors().GetNames().GetStd().front());
457  string first = s_GetStringFromAuthor(first_auth);
458  if (!NStr::IsBlank(first)) {
459  m_UseFirstAuthorBtn->SetValue(true);
460  m_FirstAuthorTxt->SetValue(ToWxString(first));
461  }
462  const CAuthor& last_auth = *((*pub_it)->GetAuthors().GetNames().GetStd().back());
463  string last = s_GetStringFromAuthor(last_auth);
464  if (!NStr::IsBlank(last)) {
465  m_UseLastAuthorBtn->SetValue(true);
466  m_LastAuthorTxt->SetValue(ToWxString(last));
467  }
468  for (const auto &author : (*pub_it)->GetAuthors().GetNames().GetStd())
469  {
470  string name = s_GetStringFromAuthor(*author);
471  if (!NStr::IsBlank(name) && m_AuthorsExist.find(name) == m_AuthorsExist.end())
472  {
473  m_AuthorsExist.insert(name);
474  m_Authors.push_back(name);
475  }
476  }
477  }
478  if (article.IsSetFrom() && article.GetFrom().IsJournal()) {
479  const CCit_jour& journal = article.GetFrom().GetJournal();
480  if (journal.IsSetTitle()) {
481  try {
482  string title = journal.GetTitle().GetTitle();
483  if (!NStr::IsBlank(title)) {
484  m_UseJournalBtn->SetValue(true);
485  m_JournalTxt->SetValue(ToWxString(title));
486  }
487  } catch(CException&) {} catch (exception&) {}
488  }
489  if (journal.IsSetImp()) {
490  const CImprint& imp = journal.GetImp();
491  if (imp.IsSetDate() && imp.GetDate().IsStd() && imp.GetDate().GetStd().IsSetYear()) {
492  m_UseYearBtn->SetValue(true);
494  }
495  if (imp.IsSetVolume() && !NStr::IsBlank(imp.GetVolume())) {
496  m_UseVolumeBtn->SetValue(true);
497  m_UseVolumeTxt->SetValue(ToWxString(imp.GetVolume()));
498  }
499  if (imp.IsSetPages() && !NStr::IsBlank(imp.GetPages())) {
500  m_UsePageBtn->SetValue(true);
501  m_UsePageTxt->SetValue(ToWxString(imp.GetPages()));
502  }
503  // TODO issue!
504  }
505  }
506  }
507  }
508  }
509 }
510 
511 
512 void s_AddToTerms(string& terms, const string& key, const string& val)
513 {
514  if (NStr::IsBlank(val)) {
515  return;
516  }
517  if (!NStr::IsBlank(terms)) {
518  terms += " AND ";
519  }
520  terms += val;
521 
522  if (!NStr::IsBlank(key)) {
523  terms += "[" + key + "]";
524  }
525 }
526 
527 
529 {
530  string terms;
531  //s_AddToTerms(terms, "TITLE", ToStdString(m_ArticleTitleTxt->GetValue()));
532 
533  bool use_all = false;
534  if (m_NewQueryChoice->GetSelection() == 0) {
535  use_all = true;
536  }
537 
538  if (use_all || m_UseExtraTermsBtn->GetValue()) {
539  string val = ToStdString(m_ExtraTermsTxt->GetValue());
540  s_AddToTerms(terms, "", val);
541  }
542 
543  string other_author = "";
544 
545  if (use_all || m_UseFirstAuthorBtn->GetValue()) {
546  string val = ToStdString(m_FirstAuthorTxt->GetValue());
547  s_AddToTerms(terms, "AUTH", val);
548  other_author = val;
549  }
550  if (use_all || m_UseLastAuthorBtn->GetValue()) {
551  string val = ToStdString(m_LastAuthorTxt->GetValue());
552  if (!NStr::Equal(other_author, val)) {
553  s_AddToTerms(terms, "AUTH", val);
554  }
555  }
556 
557  if (use_all || m_UseJournalBtn->GetValue()) {
558  string val = ToStdString(m_JournalTxt->GetValue());
559  s_AddToTerms(terms, "JOUR", val);
560  }
561 
562  if (use_all || m_UseVolumeBtn->GetValue()) {
563  string val = ToStdString(m_UseVolumeTxt->GetValue());
564  s_AddToTerms(terms, "VOLUME", val);
565  }
566 
567  if (use_all || m_UsePageBtn->GetValue()) {
568  string val = ToStdString(m_UsePageTxt->GetValue());
569  s_AddToTerms(terms, "PAGE", val);
570  }
571 
572  if (use_all || m_UseYearBtn->GetValue()) {
573  string val = ToStdString(m_YearTxt->GetValue());
574  if (!NStr::IsBlank(val)) {
575  int year = 0;
576  try {
577  year = NStr::StringToInt(val);
578  string year_text = "";
579  if (m_YearFuzzBtn->GetValue()) {
580  year_text = "(" + NStr::NumericToString(year - 1) + "[EDAT] OR "
581  + NStr::NumericToString(year) + "[EDAT] OR "
582  + NStr::NumericToString(year + 1) + "[EDAT])";
583  } else {
584  year_text = NStr::NumericToString(year) + "[EDAT]";
585  }
586  if (NStr::IsBlank(terms)) {
587  terms = year_text;
588  } else {
589  terms += " AND " + year_text;
590  }
591  } catch(CException&) {} catch (exception&) {}
592  }
593  }
594 
595  return terms;
596 }
597 
599 {
600  vector<string> terms;
601 
602  // title
603  if (!m_ArticleTitleTxt->GetValue().IsEmpty()) {
604  string title = ToStdString(m_ArticleTitleTxt->GetValue());
605  title = NStr::Sanitize(title);
606  NStr::ReplaceInPlace(title, ",", " ");
607  NStr::ReplaceInPlace(title, ":", " ");
608  NStr::ReplaceInPlace(title, "(", " ");
609  NStr::ReplaceInPlace(title, ")", " ");
610  NStr::ReplaceInPlace(title, "-", " ");
611  NStr::ReplaceInPlace(title, ".", " ");
612 
613  list<string> tokens;
614  NStr::Split(title, " ", tokens, NStr::fSplit_Tokenize);
615  terms.assign(tokens.begin(), tokens.end());
616  }
617 
618  // authors
619  for (const auto& name : m_Authors) {
620  terms.push_back(name);
621  }
622 
623  return terms;
624 }
625 
627 {
628  vector<TEntrezId> pmids;
629  vector<string> search_terms = x_GetCitMatchSearchTerms();
630 
631  m_Ids.clear();
632  try {
633  edit::CEUtilsUpdater::DoPubSearch(search_terms, pmids);
634  }
635  catch (const CException& e) {
636  LOG_POST(Error << "Citation matcher failed: " << e.GetMsg());
637  }
638  catch (const exception& e) {
639  LOG_POST(Error << "Citation matcher failed: " << e.what());
640  }
641 
642  if (pmids.size() == 1) {
643  m_Ids.push_back(pmids.front());
644  }
645 }
646 
648 {
649  if (!m_CitMatch)
650  return;
651 
652  CRef<CSeqdesc> desc(new CSeqdesc);
653  desc->SetPub().SetPub().Set().push_back(m_CitMatch);
654 
655  try {
656  IObjtoolsListener* pMessageListener = nullptr;
657  edit::CRemoteUpdater updater(pMessageListener, edit::EPubmedSource::eEUtils);
658 
659  updater.UpdatePubReferences(*desc);
660 
661  for (const auto& pub_it : desc->GetPub().GetPub().Get()) {
662  if (pub_it->IsPmid()) {
663  m_Ids.push_back(pub_it->GetPmid().Get());
664  break;
665  }
666  }
667  }
668  catch (const CException& e) {
669  LOG_POST(Error << "CRelaxedLookupDlg::x_GetPubIdsEutils(): error executing MedLine Lookup " + e.GetMsg());
670  }
671 }
672 
673 void CRelaxedLookupDlg::x_GetPubIds(const string& terms)
674 {
675  // get Pub IDs
676  m_Ids.clear();
677 
678  int max = 20;
679  try {
681  if (max < 1 || max > 20) {
682  max = 20;
683  }
684  }
685  catch(CException&) {} catch (exception&) {}
686 
687 
688  string db = "PubMed";
689 
690  CGuiEutilsClient ecli;
691  ecli.SetMaxReturn(max);
692 
693  try {
694  ecli.Search(db, terms, m_Ids);
695  }
696  catch (CException& e) {
697  LOG_POST(Error << "CRelaxedLookupDlg::x_GetPubIds(): error executing search Entrez query: " << terms << ": " << e.GetMsg());
698  }
699 }
700 
701 
702 
703 void CRelaxedLookupDlg::SendQuery(bool use_pubmed_citmatch)
704 {
705  Freeze();
706  while (m_Sizer->GetItemCount() > 0) {
707  int pos = 0;
708  m_Sizer->GetItem(pos)->DeleteWindows();
709  m_Sizer->Remove(pos);
710  }
711 
712  int one_row_height = 0;
713  int total_height = 0;
714  int total_width = 0;
715  int num_rows = 0;
716  int max_rows_displayed = 6;
717 
718  if (use_pubmed_citmatch) { // replaced hydra search
720  }
721  else {
722  string terms = x_GetSearchTerms();
723  x_GetPubIds(terms);
724  }
725 
726  m_Labels.clear();
727  m_Pubs.clear();
728  ITERATE(vector<TEntrezId>, it, m_Ids) {
730  if (pubdesc) {
731 #if 1
732  m_Labels.push_back(GetDocSumLabel(*pubdesc));
733 #else
734  m_Labels.push_back(GetPubdescLabel(*pubdesc));
735 #endif
736  } else {
737  m_Labels.push_back("");
738  }
739  m_Pubs.push_back(pubdesc);
740  }
741 
742  bool first = true;
743  if (m_Labels.size() == 0) {
744  wxStaticText* label = new wxStaticText( m_ScrolledWindow, wxID_STATIC,
745  wxT("No match was found, hints for a modified query:\n Leave out one author\n Leave out year field (or increase it by 1) \n Leave out Volume field \n Modify the fields as you deem sensible"),
746  wxDefaultPosition, wxDefaultSize, 0 );
747  label->Wrap(550);
748  m_Sizer->Add(label, 0, wxALIGN_LEFT|wxALL, 0);
749  } else {
750  ITERATE(list<string>, it, m_Labels) {
751  if (!NStr::IsBlank(*it)) {
752 
753  wxSizer* row = new wxBoxSizer(wxHORIZONTAL);
754  m_Sizer->Add(row, 0, wxALIGN_LEFT|wxALL, 0);
755 
756  wxRadioButton* btn = new wxRadioButton( m_ScrolledWindow, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
757  row->Add(btn, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 0);
758  if (first)
759  {
760  btn->SetValue(true);
761  first = false;
762  }
763  wxStaticText* label = new wxStaticText( m_ScrolledWindow, wxID_STATIC, ToWxString(*it), wxDefaultPosition, wxDefaultSize, 0 );
764  label->Wrap(550);
765  row->Add(label, 0, wxALIGN_LEFT|wxALL, 0);
766  label->Connect(wxEVT_LEFT_UP, (wxObjectEventFunction)(wxEventFunction)&CRelaxedLookupDlg::OnPubTextClick, NULL, this);
767  label->Connect(wxEVT_LEFT_DCLICK, (wxObjectEventFunction)(wxEventFunction)&CRelaxedLookupDlg::OnPubTextDClick, NULL, this);
768 
769  int row_height, row_width;
770  int btn_height, btn_width;
771  int label_height, label_width;
772  btn->GetClientSize(&btn_width, &btn_height);
773  label->GetClientSize(&label_width, &label_height);
774  row_height = btn_height;
775  if (label_height > row_height) {
776  row_height = label_height;
777  }
778  row_width = btn_width + label_width;
779 
780  if (row_width > total_width) {
781  total_width = row_width;
782  }
783  if (num_rows < max_rows_displayed) {
784  total_height += row_height;
785  }
786  num_rows++;
787  if (one_row_height == 0 || one_row_height > row_height) {
788  one_row_height = row_height;
789  }
790  }
791  }
792  }
793 
794 
795  m_ScrolledWindow->SetVirtualSize(total_width + 10, total_height);
796  m_ScrolledWindow->SetScrollRate(0, one_row_height);
797 
798  m_ScrolledWindow->FitInside();
799  Layout();
800  Thaw();
801 }
802 
803 
805 {
806  wxSizerItemList::iterator node = m_Sizer->GetChildren().begin();
807  vector<CRef<CPubdesc> >::iterator pub_it = m_Pubs.begin();
808  while (pub_it != m_Pubs.end() && !(*pub_it)) {
809  ++pub_it;
810  }
811 
812  for (; node != m_Sizer->GetChildren().end() && pub_it != m_Pubs.end(); ++node) {
813  if ((*node)->IsSizer()) {
814  wxRadioButton *w = dynamic_cast<wxRadioButton *>((*node)->GetSizer()->GetItem((size_t)0)->GetWindow());
815  if (w) {
816  if (w->GetValue()) {
817  return *pub_it;
818  }
819  ++pub_it;
820  while (pub_it != m_Pubs.end() && !(*pub_it)) {
821  ++pub_it;
822  }
823  }
824  }
825  }
826  return CRef<CPubdesc>(NULL);
827 }
828 
830 {
831  m_MaxMatchTxt->SetValue(_("1"));
832  m_YearFuzzBtn->SetValue(false);
833 }
834 
836 
User-defined methods of the data storage class.
CAuthor –.
Definition: Author.hpp:59
void SetMaxReturn(int ret_max)
Uint8 Search(const string &db, const string &term, vector< objects::CSeq_id_Handle > &uids, const string &xml_path=kEmptyStr)
CImprint –.
Definition: Imprint.hpp:66
Definition: Pub.hpp:56
@Pubdesc.hpp User-defined methods of the data storage class.
Definition: Pubdesc.hpp:54
static bool ShowToolTips()
Should we show tooltips?
void OnPubTextClick(wxMouseEvent &event)
void OnPubTextDClick(wxMouseEvent &event)
void CreateControls()
Creates the controls and sizers.
wxTextCtrl * m_FirstAuthorTxt
wxTextCtrl * m_LastAuthorTxt
CRef< objects::CPubdesc > GetPubdesc()
CRelaxedLookupDlg()
Constructors.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxCheckBox * m_UseJournalBtn
wxScrolledWindow * m_ScrolledWindow
bool Create(wxWindow *parent, wxWindowID id=10092, const wxString &caption=_("In-press citation update"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
vector< string > x_GetCitMatchSearchTerms() const
void SetPubdesc(const objects::CPubdesc &pubdesc)
void SendQuery(bool use_pubmed_citmatch=false)
void OnSendQueryClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SEND_QUERY
vector< CRef< objects::CPubdesc > > m_Pubs
wxTextCtrl * m_ExtraTermsTxt
set< string > m_AuthorsExist
vector< TEntrezId > m_Ids
wxCheckBox * m_UseLastAuthorBtn
void x_GetPubIds(const string &terms)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
wxTextCtrl * m_ArticleTitleTxt
wxCheckBox * m_UseFirstAuthorBtn
CRef< objects::CPub > m_CitMatch
wxCheckBox * m_UseExtraTermsBtn
vector< string > m_Authors
~CRelaxedLookupDlg()
Destructor.
const string & GetTitle(C_E::E_Choice type=C_E::e_not_set) const
If the internal list contains a title (of the specified type, if given), returns the corresponding st...
Definition: Title.cpp:56
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
void clear()
Definition: set.hpp:153
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ZERO_ENTREZ_ID
Definition: ncbimisc.hpp:1102
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
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
static bool PopupURL(const string &url)
launch an application to handle a URL
Definition: app_popup.cpp:181
TPrim & Set(void)
Definition: serialbase.hpp:351
const TPrim & Get(void) const
Definition: serialbase.hpp:347
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
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static string Sanitize(CTempString str, TSS_Flags flags=fSS_print)
Sanitize a string, allowing only specified classes of characters.
Definition: ncbistr.hpp:2876
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
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
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3401
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
static const char label[]
bool IsSetVolume(void) const
Check if a value has been assigned to Volume data member.
Definition: Imprint_.hpp:746
const TJournal & GetJournal(void) const
Get the variant data.
Definition: Cit_art_.cpp:111
const TVolume & GetVolume(void) const
Get the Volume member data.
Definition: Imprint_.hpp:758
const TPages & GetPages(void) const
Get the Pages member data.
Definition: Imprint_.hpp:852
const TFrom & GetFrom(void) const
Get the From member data.
Definition: Cit_art_.hpp:567
bool IsSetTitle(void) const
title of paper (ANSI requires) Check if a value has been assigned to Title data member.
Definition: Cit_art_.hpp:513
const TTitle & GetTitle(void) const
Get the Title member data.
Definition: Cit_art_.hpp:525
bool IsSetFrom(void) const
Check if a value has been assigned to From data member.
Definition: Cit_art_.hpp:555
const TName & GetName(void) const
Get the Name member data.
Definition: Author_.hpp:352
bool IsSetDate(void) const
date of publication Check if a value has been assigned to Date data member.
Definition: Imprint_.hpp:716
bool IsSetName(void) const
Author, Primary or Secondary Check if a value has been assigned to Name data member.
Definition: Author_.hpp:340
bool IsJournal(void) const
Check if variant Journal is selected.
Definition: Cit_art_.hpp:495
const TDate & GetDate(void) const
Get the Date member data.
Definition: Imprint_.hpp:728
bool IsSetPages(void) const
Check if a value has been assigned to Pages data member.
Definition: Imprint_.hpp:840
bool IsSetYear(void) const
full year (including 1900) Check if a value has been assigned to Year data member.
Definition: Date_std_.hpp:407
bool IsStd(void) const
Check if variant Std is selected.
Definition: Date_.hpp:320
bool IsName(void) const
Check if variant Name is selected.
Definition: Person_id_.hpp:359
bool IsSetLast(void) const
Check if a value has been assigned to Last data member.
Definition: Name_std_.hpp:410
TYear GetYear(void) const
Get the Year member data.
Definition: Date_std_.hpp:426
const TLast & GetLast(void) const
Get the Last member data.
Definition: Name_std_.hpp:422
const TName & GetName(void) const
Get the variant data.
Definition: Person_id_.cpp:137
const TStd & GetStd(void) const
Get the variant data.
Definition: Date_.cpp:109
list< CRef< CPub > > Tdata
Definition: Pub_equiv_.hpp:90
const Tdata & Get(void) const
Get the member data.
Definition: Pub_equiv_.hpp:165
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
bool IsSetPub(void) const
the citation(s) Check if a value has been assigned to Pub data member.
Definition: Pubdesc_.hpp:593
const TPub & GetPub(void) const
Get the Pub member data.
Definition: Pubdesc_.hpp:605
CRef< objects::CPubdesc > GetPubdescFromEntrezById(TEntrezId id)
Definition: utilities.cpp:78
string GetDocSumLabel(const objects::CPubdesc &pd)
string GetPubdescLabel(const objects::CPubdesc &pd)
END_EVENT_TABLE()
This file contains the definition of the xml::document class.
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
T max(T x_, T y_)
#define ID_SCROLLEDWINDOW
CRef< CPub > journal(ParserPtr pp, char *bptr, char *eptr, CRef< CAuth_list > &auth_list, CRef< CTitle::C_E > &title, bool has_muid, CRef< CCit_art > &cit_art, Int4 er)
Definition: ref.cpp:1468
USING_SCOPE(objects)
void s_AddToTerms(string &terms, const string &key, const string &val)
string s_GetStringFromAuthor(const CAuthor &auth)
#define ID_USE_FIRST_AUTHOR_BTN
#define ID_USE_EXTRA_TERMS_BTN
#define ID_ARTICLE_TITLE_TXT
#define ID_YEAR_FUZZ_BTN
#define ID_YEAR_TXT
#define ID_JOURNAL_TXT
#define ID_USE_JOURNAL_BTN
#define ID_SEND_QUERY
#define ID_USE_LAST_AUTHOR_BTN
#define ID_USE_VOLUME_TXT
#define ID_LAST_AUTHOR_TXT
#define ID_USE_YEAR_BTN
#define ID_NEW_QUERY_CHOICE
#define ID_FIRST_AUTHOR_TXT
#define ID_USE_PAGE_BTN
#define ID_PAGE_TXT
#define ID_MAX_MATCH_TXT
#define ID_EXTRA_TERMS_TXT
#define ID_USE_VOLUME_BTN
static static static wxID_ANY
static static static() wxObjectEventFunction(wxEventFunction) wxStaticCastEvent(CSeqMarkerEventFunction
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Tue Feb 27 05:56:24 2024 by modify_doxy.py rev. 669887