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

Go to the SVN repository for this file.

1 /* $Id: submitter_affil_panel.cpp 43206 2019-05-28 21:41:23Z 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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
34 #include <objects/biblio/Affil.hpp>
39 
40 #include <wx/sizer.h>
41 #include <wx/stattext.h>
42 #include <wx/textctrl.h>
43 #include <wx/combobox.h>
44 #include <wx/icon.h>
45 
48 
49 /*
50  * CSubmitterAffilPanel type definition
51  */
52 
53 IMPLEMENT_DYNAMIC_CLASS( CSubmitterAffilPanel, wxPanel )
54 
55 
56 /*
57  * CSubmitterAffilPanel event table definition
58  */
59 
60 BEGIN_EVENT_TABLE( CSubmitterAffilPanel, wxPanel )
61 
62 ////@begin CSubmitterAffilPanel event table entries
63  EVT_COMBOBOX( ID_SUB_AFFIL_COUNTRY, CSubmitterAffilPanel::OnAffilCountrySelected )
64 ////@end CSubmitterAffilPanel event table entries
65 
67 
68 
69 /*
70  * CSubmitterAffilPanel constructors
71  */
72 
74 {
75  Init();
76 }
77 
78 CSubmitterAffilPanel::CSubmitterAffilPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
79 {
80  Init();
81  Create(parent, id, pos, size, style);
82 }
83 
84 
85 /*
86  * SubmitterAffilPanel creator
87  */
88 
89 bool CSubmitterAffilPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
90 {
91 ////@begin CSubmitterAffilPanel creation
92  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
93  wxPanel::Create( parent, id, pos, size, style );
94 
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101 ////@end CSubmitterAffilPanel creation
102  return true;
103 }
104 
105 
106 /*
107  * CSubmitterAffilPanel destructor
108  */
109 
111 {
112 ////@begin CSubmitterAffilPanel destruction
113 ////@end CSubmitterAffilPanel destruction
114 }
115 
116 
117 /*
118  * Member initialisation
119  */
120 
122 {
123 ////@begin CSubmitterAffilPanel member initialisation
124  m_AffilCtrl = NULL;
126  m_StreetCtrl = NULL;
127  m_CityCtrl = NULL;
128  m_SubCtrl = NULL;
129  m_ZipCtrl = NULL;
131  m_PhoneCtrl = NULL;
132 ////@end CSubmitterAffilPanel member initialisation
133 }
134 
135 
136 /*
137  * Control creation for SubmitterAffilPanel
138  */
139 
141 {
142 ////@begin CSubmitterAffilPanel content construction
143  CSubmitterAffilPanel* itemPanel1 = this;
144 
145  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
146  itemPanel1->SetSizer(itemBoxSizer2);
147 
148  wxFlexGridSizer* itemFlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 0);
149  itemBoxSizer2->Add(itemFlexGridSizer1, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
150 
151  wxStaticText* itemStaticText2 = new wxStaticText( itemPanel1, wxID_STATIC, _("Institution*"), wxDefaultPosition, wxDefaultSize, 0 );
152  itemFlexGridSizer1->Add(itemStaticText2, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
153 
154  m_AffilCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_INST, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0 );
155  itemFlexGridSizer1->Add(m_AffilCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
156 
157  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Department*"), wxDefaultPosition, wxDefaultSize, 0 );
158  itemFlexGridSizer1->Add(itemStaticText4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
159 
160  m_DepartmentCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_DEPT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
161  itemFlexGridSizer1->Add(m_DepartmentCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
162 
163  wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Street*"), wxDefaultPosition, wxDefaultSize, 0 );
164  itemFlexGridSizer1->Add(itemStaticText6, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
165 
166  m_StreetCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_ADDRESS, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
167  itemFlexGridSizer1->Add(m_StreetCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("City*"), wxDefaultPosition, wxDefaultSize, 0 );
170  itemFlexGridSizer1->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
171 
172  m_CityCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_CITY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
173  itemFlexGridSizer1->Add(m_CityCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
174 
175  wxStaticText* itemStaticText10 = new wxStaticText( itemPanel1, wxID_STATIC, _("State/Province"), wxDefaultPosition, wxDefaultSize, 0 );
176  itemFlexGridSizer1->Add(itemStaticText10, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
177 
178  m_SubCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_STATE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
179  itemFlexGridSizer1->Add(m_SubCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
180 
181  wxStaticText* itemStaticText12 = new wxStaticText( itemPanel1, wxID_STATIC, _("Postal code*"), wxDefaultPosition, wxDefaultSize, 0 );
182  itemFlexGridSizer1->Add(itemStaticText12, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
183 
184  m_ZipCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_CODE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
185  itemFlexGridSizer1->Add(m_ZipCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
186 
187  wxStaticText* itemStaticText14 = new wxStaticText( itemPanel1, wxID_STATIC, _("Country*"), wxDefaultPosition, wxDefaultSize, 0 );
188  itemFlexGridSizer1->Add(itemStaticText14, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
189 
190  wxArrayString m_CountryCtrlStrings;
191  vector<CTempString> countries;
192  for (unsigned int p = 0; !GetValidCountryCode(p).empty(); ++p) {
193  countries.push_back(GetValidCountryCode(p));
194  }
195  for (auto&& it : countries) {
196  m_CountryCtrlStrings.Add(ToWxString(it));
197  }
198  m_CountryCtrlStrings.Add(wxT("Other")); // SP: Unknown or unspecified country
199  m_CountryCtrl = new wxComboBox( itemPanel1, ID_SUB_AFFIL_COUNTRY, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_CountryCtrlStrings, wxCB_DROPDOWN );
200  itemFlexGridSizer1->Add(m_CountryCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
201 
202  wxStaticText* itemStaticText16 = new wxStaticText( itemPanel1, wxID_STATIC, _("Phone"), wxDefaultPosition, wxDefaultSize, 0 );
203  itemFlexGridSizer1->Add(itemStaticText16, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
204 
205  m_PhoneCtrl = new wxTextCtrl( itemPanel1, ID_SUB_AFFIL_PHONE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
206  itemFlexGridSizer1->Add(m_PhoneCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
207 
208 ////@end CSubmitterAffilPanel content construction
209 }
210 
211 
212 /*
213  * Should we show tooltips?
214  */
215 
217 {
218  return true;
219 }
220 
221 /*
222  * Get bitmap resources
223  */
224 
225 wxBitmap CSubmitterAffilPanel::GetBitmapResource( const wxString& name )
226 {
227  // Bitmap retrieval
228 ////@begin CSubmitterAffilPanel bitmap retrieval
229  wxUnusedVar(name);
230  return wxNullBitmap;
231 ////@end CSubmitterAffilPanel bitmap retrieval
232 }
233 
234 /*
235  * Get icon resources
236  */
237 
238 wxIcon CSubmitterAffilPanel::GetIconResource( const wxString& name )
239 {
240  // Icon retrieval
241 ////@begin CSubmitterAffilPanel icon retrieval
242  wxUnusedVar(name);
243  return wxNullIcon;
244 ////@end CSubmitterAffilPanel icon retrieval
245 }
246 
247 /*
248  * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SUB_AFFIL_COUNTRY
249  */
250 
251 void CSubmitterAffilPanel::OnAffilCountrySelected( wxCommandEvent& event )
252 {
253  if (m_CountryCtrl->GetCurrentSelection() + 1 == (int)m_CountryCtrl->GetCount()) {
254  m_CountryCtrl->ChangeValue(wxEmptyString);
255  }
256 }
257 
258 
259 void CSubmitterAffilPanel::ApplySubmitBlock(objects::CSubmit_block& block)
260 {
261  m_SubmitBlock.Reset(&block);
263 }
264 
265 
267 {
268  m_AffilCtrl->SetValue(wxT(""));
269  m_DepartmentCtrl->SetValue(wxT(""));
270  m_StreetCtrl->SetValue(wxT(""));
271  m_CityCtrl->SetValue(wxT(""));
272  m_SubCtrl->SetValue(wxT(""));
273  m_ZipCtrl->SetValue(wxT(""));
274  m_CountryCtrl->SetValue(wxT(""));
275  m_PhoneCtrl->SetValue(wxT(""));
276 }
277 
278 
280 {
281  if (!wxPanel::TransferDataToWindow()) {
282  return false;
283  }
284 
285  x_Reset();
286  if (!m_SubmitBlock)
287  return false;
288 
289  const CAffil* affil = nullptr;
290  if (m_SubmitBlock->IsSetCit() &&
291  m_SubmitBlock->GetCit().IsSetAuthors() &&
292  m_SubmitBlock->GetCit().GetAuthors().IsSetAffil()) {
293  affil = &(m_SubmitBlock->GetCit().GetAuthors().GetAffil());
294  }
295 
296  if (!affil && m_SubmitBlock->IsSetContact() &&
297  m_SubmitBlock->GetContact().IsSetContact() &&
298  m_SubmitBlock->GetContact().GetContact().IsSetAffil()) {
299  affil = &(m_SubmitBlock->GetContact().GetContact().GetAffil());
300  }
301 
302  if (affil) {
303  if (affil->IsStr()) {
304  m_AffilCtrl->SetValue(affil->GetStr());
305  } else if (affil->IsStd()) {
306  const auto& stad = affil->GetStd();
307  if (stad.IsSetAffil()) {
308  m_AffilCtrl->SetValue(ToWxString(stad.GetAffil()));
309  }
310  if (stad.IsSetDiv()) {
311  m_DepartmentCtrl->SetValue(ToWxString(stad.GetDiv()));
312  }
313  if (stad.IsSetStreet()) {
314  m_StreetCtrl->SetValue(ToWxString(stad.GetStreet()));
315  }
316  if (stad.IsSetCity()) {
317  m_CityCtrl->SetValue(ToWxString(stad.GetCity()));
318  }
319  if (stad.IsSetSub()) {
320  m_SubCtrl->SetValue(ToWxString(stad.GetSub()));
321  }
322  if (stad.IsSetPostal_code()) {
323  m_ZipCtrl->SetValue(ToWxString(stad.GetPostal_code()));
324  }
325  if (stad.IsSetCountry()) {
326  m_CountryCtrl->SetValue(ToWxString(stad.GetCountry()));
327  }
328  if (stad.IsSetPhone()) {
329  m_PhoneCtrl->SetValue(ToWxString(stad.GetPhone()));
330  }
331  }
332  }
333  return true;
334 }
335 
336 
338 {
339  if (!wxPanel::TransferDataFromWindow()) {
340  return false;
341  }
342  if (!m_SubmitBlock)
343  return false;
344 
345  auto& contact = m_SubmitBlock->SetContact().SetContact();
346  auto& affil = contact.SetAffil().SetStd();
347 
348  if (m_AffilCtrl->GetValue().IsEmpty())
349  affil.ResetAffil();
350  else
351  affil.SetAffil(ToStdString(m_AffilCtrl->GetValue()));
352 
353  if (m_DepartmentCtrl->GetValue().IsEmpty())
354  affil.ResetDiv();
355  else
356  affil.SetDiv(ToStdString(m_DepartmentCtrl->GetValue()));
357 
358  if (m_StreetCtrl->GetValue().IsEmpty())
359  affil.ResetStreet();
360  else
361  affil.SetStreet(ToStdString(m_StreetCtrl->GetValue()));
362 
363  if (m_CityCtrl->GetValue().IsEmpty())
364  affil.ResetCity();
365  else
366  affil.SetCity(ToStdString(m_CityCtrl->GetValue()));
367 
368  if (m_SubCtrl->GetValue().IsEmpty())
369  affil.ResetSub();
370  else
371  affil.SetSub(ToStdString(m_SubCtrl->GetValue()));
372 
373  if (m_ZipCtrl->GetValue().IsEmpty())
374  affil.ResetPostal_code();
375  else
376  affil.SetPostal_code(ToStdString(m_ZipCtrl->GetValue()));
377 
378  if (m_CountryCtrl->GetValue().IsEmpty())
379  affil.ResetCountry();
380  else
381  affil.SetCountry(ToStdString(m_CountryCtrl->GetValue()));
382 
383  if (m_PhoneCtrl->GetValue().IsEmpty())
384  affil.ResetPhone();
385  else
386  affil.SetPhone(ToStdString(m_PhoneCtrl->GetValue()));
387 
388  if (!affil.IsSetAffil() &&
389  !affil.IsSetDiv() &&
390  !affil.IsSetStreet() &&
391  !affil.IsSetCity() &&
392  !affil.IsSetSub() &&
393  !affil.IsSetPostal_code() &&
394  !affil.IsSetCountry() &&
395  !affil.IsSetPhone())
396  contact.ResetAffil();
397 
398  // store the same information in the Cit-sub affiliation field
399  x_CopyAffil(m_SubmitBlock->SetCit().SetAuthors());
400 
401  return true;
402 }
403 
404 void CSubmitterAffilPanel::x_CopyAffil(objects::CAuth_list &auth_list)
405 {
406  const auto& contact = m_SubmitBlock->GetContact().GetContact();
407  if (contact.IsSetAffil()) {
408  auth_list.SetAffil().Assign(contact.GetAffil());
409  }
410  else {
411  auth_list.ResetAffil();
412  }
413 }
414 
416 {
418  CRef<objects::CAffil> empty(new objects::CAffil);
419  empty->SetStd();
420 
421  if (m_SubmitBlock->IsSetCit() &&
422  m_SubmitBlock->GetCit().IsSetAuthors() &&
423  m_SubmitBlock->GetCit().GetAuthors().IsSetAffil() &&
424  m_SubmitBlock->GetCit().GetAuthors().GetAffil().Equals(*empty)) {
425  return;
426  }
428 }
429 
431 {
432  if (m_AffilCtrl->GetValue().IsEmpty())
433  text += "Submitter Institution\n";
434 
435  if (m_DepartmentCtrl->GetValue().IsEmpty())
436  text += "Submitter Department\n";
437 
438  if (m_StreetCtrl->GetValue().IsEmpty())
439  text += "Submitter Street\n";
440 
441  if (m_CityCtrl->GetValue().IsEmpty())
442  text += "Submitter City\n";
443 
444  if (m_ZipCtrl->GetValue().IsEmpty())
445  text += "Submitter Postal Code\n";
446 
447  if (m_CountryCtrl->GetValue().IsEmpty())
448  text += "Submitter Country\n";;
449 }
450 
User-defined methods of the data storage class.
@Affil.hpp User-defined methods of the data storage class.
Definition: Affil.hpp:56
virtual void ApplySubmitCommand()=0
bool Create(wxWindow *parent, wxWindowID id=ID_SUBMITTERAFFILPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
void OnAffilCountrySelected(wxCommandEvent &event)
wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_SUB_AFFIL_COUNTRY
void x_CopyAffil(objects::CAuth_list &auth_list)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CSubmitterAffilPanel()
Constructors.
CRef< objects::CSubmit_block > m_SubmitBlock
virtual bool TransferDataFromWindow()
void CreateControls()
Creates the controls and sizers.
void ApplySubmitBlock(objects::CSubmit_block &block)
virtual void ReportMissingFields(string &text)
CSubmissionPageChangeListener * GetParentWizard(wxWindow *wnd) const
const string & GetValidCountryCode(unsigned int i)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
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
const TStr & GetStr(void) const
Get the variant data.
Definition: Affil_.hpp:1193
bool IsStr(void) const
Check if variant Str is selected.
Definition: Affil_.hpp:1187
const TStd & GetStd(void) const
Get the variant data.
Definition: Affil_.cpp:214
bool IsStd(void) const
Check if variant Std is selected.
Definition: Affil_.hpp:1207
END_EVENT_TABLE()
static void text(MDB_val *v)
Definition: mdb_dump.c:62
#define wxT(x)
Definition: muParser.cpp:41
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
USING_SCOPE(objects)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sun Mar 03 03:12:58 2024 by modify_doxy.py rev. 669887