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

Go to the SVN repository for this file.

1 /* $Id: cdd_ref_dialog.cpp 92497 2021-01-26 18:35:59Z grichenk $
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: Paul Thiessen
27 *
28 * File Description:
29 * dialog for editing CDD references
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 
38 #include <objects/pub/Pub.hpp>
40 
42 
43 #include "cdd_ref_dialog.hpp"
44 #include "structure_set.hpp"
45 #include "cn3d_tools.hpp"
46 
47 #include <wx/tokenzr.h>
48 
49 ////////////////////////////////////////////////////////////////////////////////////////////////
50 // The following is taken unmodified from wxDesigner's C++ header from cdd_ref_dialog.wdr
51 ////////////////////////////////////////////////////////////////////////////////////////////////
52 
53 #include <wx/image.h>
54 #include <wx/statline.h>
55 #include <wx/spinbutt.h>
56 #include <wx/spinctrl.h>
57 #include <wx/splitter.h>
58 #include <wx/listctrl.h>
59 #include <wx/treectrl.h>
60 #include <wx/notebook.h>
61 #include <wx/grid.h>
62 
63 // Declare window functions
64 
65 #define ID_L_REFS 10000
66 #define ID_B_LAUNCH 10001
67 #define ID_B_UP 10002
68 #define ID_B_EDIT 10003
69 #define ID_B_DOWN 10004
70 #define ID_B_ADD 10005
71 #define ID_B_DELETE 10006
72 #define ID_B_DONE 10007
73 wxSizer *SetupReferencesDialog( wxWindow *parent, bool call_fit = TRUE, bool set_sizer = TRUE );
74 
75 ////////////////////////////////////////////////////////////////////////////////////////////////
76 
79 
80 
81 BEGIN_SCOPE(Cn3D)
82 
83 #define DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(var, id, type) \
84  type *var; \
85  var = wxDynamicCast(FindWindow(id), type); \
86  if (!var) { \
87  ERRORMSG("Can't find window with id " << id); \
88  return; \
89  }
90 
91 BEGIN_EVENT_TABLE(CDDRefDialog, wxDialog)
92  EVT_CLOSE ( CDDRefDialog::OnCloseWindow)
93  EVT_BUTTON (-1, CDDRefDialog::OnButton)
95 
97  wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos) :
98  wxDialog(parent, id, title, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE),
99  sSet(structureSet), dialogHandle(handle), selectItem(0)
100 {
101  if (!structureSet || !(descrSet = structureSet->GetCDDDescrSet())) {
102  ERRORMSG("CDDRefDialog::CDDRefDialog() - error getting descr set data");
103  Destroy();
104  return;
105  }
106 
107  // construct the dialog
108  wxSizer *topSizer = SetupReferencesDialog(this, false);
109 
110  // fill in list box with available references
111  ResetListBox();
112 
113  bool readOnly;
120  bAdd->Enable(!readOnly);
121  bEdit->Enable(!readOnly);
122  bDelete->Enable(!readOnly);
123  bUp->Enable(!readOnly);
124  bDown->Enable(!readOnly);
125 
126  // call sizer stuff
127  topSizer->Fit(this);
128  topSizer->SetSizeHints(this);
129 }
130 
132 {
133  // so owner knows that this dialog has been destroyed
135  TRACEMSG("CDD references dialog destroyed");
136 }
137 
138 // same as hitting done
139 void CDDRefDialog::OnCloseWindow(wxCloseEvent& event)
140 {
141  Destroy();
142 }
143 
144 void CDDRefDialog::OnButton(wxCommandEvent& event)
145 {
146  // get listbox and descr from selected item
148  CCdd_descr *descr = NULL;
149  wxArrayInt selections;
150  int nSelected = listbox->GetSelections(selections);
151  selectItem = (nSelected > 0) ? selections.Item(selections.GetCount() - 1) : -1;
152  if (selectItem >= 0 && selectItem < (int) listbox->GetCount()) // pointer to last descr selected
153  descr = dynamic_cast<CCdd_descr*>(reinterpret_cast<CObject*>(listbox->GetClientData(selectItem)));
154 
155  // launch URL(s) given PMID
156  if (event.GetId() == ID_B_LAUNCH && nSelected > 0) {
157  string url("https://www.ncbi.nlm.nih.gov/pubmed/");
158  for (int i=0; i<nSelected; ++i) {
159  descr = dynamic_cast<CCdd_descr*>(reinterpret_cast<CObject*>(listbox->GetClientData(selections.Item(i))));
160  if (i > 0)
161  url += ",";
162  url += NStr::NumericToString(descr->GetReference().GetPmid().Get());
163  }
164  LaunchWebPage(url.c_str());
165  }
166 
167  // add reference(s)
168  else if (event.GetId() == ID_B_ADD) {
169  wxString ids = wxGetTextFromUser("Enter a list of PubMed IDs:", "Input PMIDs", "", this);
170  wxStringTokenizer tkz(ids, " ,;\t\r\n", wxTOKEN_STRTOK);
171  long pmidVal;
172  while (tkz.HasMoreTokens()) {
173  wxString id = tkz.GetNextToken();
174  if (id.size() > 0 && id.ToLong(&pmidVal) && pmidVal > 0) {
175  CRef < CCdd_descr > ref(new CCdd_descr());
176  ref->SetReference().SetPmid().Set((int) pmidVal);
177  CCdd_descr_set::Tdata::iterator d, de = descrSet->Set().end();
178  for (d=descrSet->Set().begin(); d!=de; ++d) {
179  if (d->GetPointer() == descr) {
180  ++d;
181  break;
182  }
183  }
184  descrSet->Set().insert(d, ref);
186  ++selectItem;
187  ResetListBox();
188  } else
189  ERRORMSG("Invalid PMID: '" << id.c_str() << "'");
190  }
191  }
192 
193  // edit reference
194  else if (event.GetId() == ID_B_EDIT && nSelected == 1) {
195  wxString init;
196  init.Printf("%i", descr->GetReference().GetPmid().Get());
197  wxString pmidStr = wxGetTextFromUser("Enter/edit the PubMed ID:", "Edit PMID", init, this);
198  unsigned long pmidVal;
199  if (pmidStr.size() > 0 && pmidStr.ToULong(&pmidVal)) {
200  descr->SetReference().SetPmid().Set((int) pmidVal);
202  ResetListBox();
203  }
204  }
205 
206  // delete reference(s)
207  else if (event.GetId() == ID_B_DELETE && nSelected > 0) {
208  CCdd_descr_set keepDescrs;
209  CCdd_descr_set::Tdata::iterator d, de = descrSet->Set().end();
210  for (d=descrSet->Set().begin(); d!=de; ++d) {
211  int i;
212  for (i=0; i<nSelected; ++i)
213  if (d->GetPointer() ==
214  dynamic_cast<CCdd_descr*>(reinterpret_cast<CObject*>(listbox->GetClientData(selections.Item(i)))))
215  break;
216  if (i == nSelected) // this descr is not one of those selected in the listbox
217  keepDescrs.Set().push_back(*d);
218  }
219  if (keepDescrs.Get().size() != descrSet->Get().size()) {
220  descrSet->Set() = keepDescrs.Set(); // copy list
222  ResetListBox();
223  }
224  }
225 
226  else if ((event.GetId() == ID_B_UP || event.GetId() == ID_B_DOWN) && nSelected == 1) {
227  CCdd_descr_set::Tdata::iterator d, de = descrSet->Set().end(), p = descrSet->Set().end(), n;
228  for (d=descrSet->Set().begin(); d!=de; ++d) {
229  if (d->GetPointer() == descr) {
231  n = d;
232  do { // find next pmid ref
233  ++n;
234  } while (n != descrSet->Set().end() && !((*n)->IsReference() && (*n)->GetReference().IsPmid()));
235  if (event.GetId() == ID_B_DOWN && n != descrSet->Set().end()) {
236  *d = *n;
237  *n = tmp;
238  ++selectItem;
239  } else if (event.GetId() == ID_B_UP && p != descrSet->Set().end()) {
240  *d = *p;
241  *p = tmp;
242  --selectItem;
243  } else
244  break;
246  ResetListBox();
247  break;
248  }
249  if ((*d)->IsReference() && (*d)->GetReference().IsPmid())
250  p = d; // keep prev pmid ref
251  }
252  }
253 
254  else if (event.GetId() == ID_B_DONE) {
255  Destroy();
256  }
257 }
258 
260 {
262 
263  listbox->Clear();
264  CCdd_descr_set::Tdata::iterator d, de = descrSet->Set().end();
265  for (d=descrSet->Set().begin(); d!=de; ++d) {
266  if ((*d)->IsReference() && (*d)->GetReference().IsPmid()) {
267  wxString title;
268  title.Printf("%i", (*d)->GetReference().GetPmid().Get());
269  // make client data of menu item a pointer to the CCdd_descr object
270  listbox->Append(title, d->GetPointer());
271  }
272  }
273  if (selectItem >= 0 && selectItem < (int) listbox->GetCount())
274  listbox->SetSelection(selectItem, true);
275 }
276 
277 END_SCOPE(Cn3D)
278 
279 //////////////////////////////////////////////////////////////////////////////////////////////////
280 // The following are taken *without* modification from wxDesigner C++ code generated from
281 // cdd_ref_dialog.wdr.
282 //////////////////////////////////////////////////////////////////////////////////////////////////
283 
284 wxSizer *SetupReferencesDialog( wxWindow *parent, bool call_fit, bool set_sizer )
285 {
286  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
287 
288  wxStaticBox *item2 = new wxStaticBox( parent, -1, wxT("PubMed IDs") );
289  wxStaticBoxSizer *item1 = new wxStaticBoxSizer( item2, wxVERTICAL );
290 
291  wxFlexGridSizer *item3 = new wxFlexGridSizer( 1, 0, 0 );
292 
293  wxString *strs4 = (wxString*) NULL;
294  wxListBox *item4 = new wxListBox( parent, ID_L_REFS, wxDefaultPosition, wxSize(80,100), 0, strs4, wxLB_EXTENDED|wxLB_NEEDED_SB );
295  item3->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
296 
297  wxGridSizer *item5 = new wxGridSizer( 2, 0, 0 );
298 
299  wxButton *item6 = new wxButton( parent, ID_B_LAUNCH, wxT("Launch"), wxDefaultPosition, wxDefaultSize, 0 );
300  item5->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
301 
302  wxButton *item7 = new wxButton( parent, ID_B_UP, wxT("Move Up"), wxDefaultPosition, wxDefaultSize, 0 );
303  item5->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
304 
305  wxButton *item8 = new wxButton( parent, ID_B_EDIT, wxT("Edit"), wxDefaultPosition, wxDefaultSize, 0 );
306  item5->Add( item8, 0, wxALIGN_CENTRE|wxALL, 5 );
307 
308  wxButton *item9 = new wxButton( parent, ID_B_DOWN, wxT("Move Down"), wxDefaultPosition, wxDefaultSize, 0 );
309  item5->Add( item9, 0, wxALIGN_CENTRE|wxALL, 5 );
310 
311  wxButton *item10 = new wxButton( parent, ID_B_ADD, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
312  item5->Add( item10, 0, wxALIGN_CENTRE|wxALL, 5 );
313 
314  wxButton *item11 = new wxButton( parent, ID_B_DELETE, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
315  item5->Add( item11, 0, wxALIGN_CENTRE|wxALL, 5 );
316 
317  item3->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
318 
319  item1->Add( item3, 0, wxALIGN_CENTRE, 5 );
320 
321  item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
322 
323  wxBoxSizer *item12 = new wxBoxSizer( wxHORIZONTAL );
324 
325  wxButton *item13 = new wxButton( parent, ID_B_DONE, wxT("Done"), wxDefaultPosition, wxDefaultSize, 0 );
326  item12->Add( item13, 0, wxALIGN_CENTRE|wxALL, 5 );
327 
328  item0->Add( item12, 0, wxALIGN_CENTRE|wxALL, 5 );
329 
330  if (set_sizer)
331  {
332  parent->SetAutoLayout( TRUE );
333  parent->SetSizer( item0 );
334  if (call_fit)
335  {
336  item0->Fit( parent );
337  item0->SetSizeHints( parent );
338  }
339  }
340 
341  return item0;
342 }
User-defined methods of the data storage class.
User-defined methods of the data storage class.
USING_SCOPE(objects)
#define ID_B_DELETE
#define ID_B_EDIT
#define DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(var, id, type)
#define ID_B_ADD
wxSizer * SetupReferencesDialog(wxWindow *parent, bool call_fit=TRUE, bool set_sizer=TRUE)
#define ID_L_REFS
#define ID_B_DONE
#define ID_B_DOWN
USING_NCBI_SCOPE
#define ID_B_UP
#define ID_B_LAUNCH
CCdd_descr_set –.
CCdd_descr –.
Definition: Cdd_descr.hpp:66
void ResetListBox(void)
StructureSet * sSet
void OnCloseWindow(wxCloseEvent &event)
CDDRefDialog ** dialogHandle
ncbi::objects::CCdd_descr_set * descrSet
void OnButton(wxCommandEvent &event)
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
static const unsigned int eCDDData
void SetDataChanged(unsigned int what) const
bool RegistryGetBoolean(const string &section, const string &name, bool *value)
Definition: cn3d_tools.cpp:250
void LaunchWebPage(const char *url)
Definition: cn3d_tools.cpp:432
#define TRACEMSG(stream)
Definition: cn3d_tools.hpp:83
static const std::string REG_ADVANCED_SECTION
Definition: cn3d_tools.hpp:191
static const std::string REG_CDD_ANNOT_READONLY
Definition: cn3d_tools.hpp:192
#define ERRORMSG(stream)
Definition: cn3d_tools.hpp:86
Include a standard set of the NCBI C++ Toolkit most basic headers.
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:40
static char tmp[3200]
Definition: utf8.c:42
#define NULL
Definition: ncbistd.hpp:225
TPrim & Set(void)
Definition: serialbase.hpp:351
const TPrim & Get(void) const
Definition: serialbase.hpp:347
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
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
const Tdata & Get(void) const
Get the member data.
TReference & SetReference(void)
Select the variant.
Definition: Cdd_descr_.cpp:248
Tdata & Set(void)
Assign a value to data member.
const TReference & GetReference(void) const
Get the variant data.
Definition: Cdd_descr_.cpp:242
TPmid & SetPmid(void)
Select the variant.
Definition: Pub_.hpp:690
const TPmid & GetPmid(void) const
Get the variant data.
Definition: Pub_.hpp:683
END_EVENT_TABLE()
int i
yy_size_t n
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define TRUE
bool replacment for C indicating true.
Definition: ncbi_std.h:97
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:32 2024 by modify_doxy.py rev. 669887