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

Go to the SVN repository for this file.

1 /* $Id: autodef_org_panel.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
27  */
28 
29 
30 // Generated by DialogBlocks (unregistered), 21/06/2013 14:02:01
31 
32 #include <ncbi_pch.hpp>
33 
34 ////@begin includes
35 ////@end includes
36 
40 
41 ////@begin XPM images
42 ////@end XPM images
43 
45 
46 /*!
47  * CAutodefOrgPanel type definition
48  */
49 
50 IMPLEMENT_DYNAMIC_CLASS( CAutodefOrgPanel, wxPanel )
51 
52 
53 /*!
54  * CAutodefOrgPanel event table definition
55  */
56 
57 BEGIN_EVENT_TABLE( CAutodefOrgPanel, wxPanel )
58 
59 ////@begin CAutodefOrgPanel event table entries
60 ////@end CAutodefOrgPanel event table entries
61 
63 
64 
65 /*!
66  * CAutodefOrgPanel constructors
67  */
68 
70 {
71  Init();
72 }
73 
74 CAutodefOrgPanel::CAutodefOrgPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
75 {
76  Init();
77  Create(parent, id, pos, size, style);
78 }
79 
80 
81 /*!
82  * CAutodefOrgPanel creator
83  */
84 
85 bool CAutodefOrgPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86 {
87 ////@begin CAutodefOrgPanel creation
88  wxPanel::Create( parent, id, pos, size, style );
89 
91  if (GetSizer())
92  {
93  GetSizer()->SetSizeHints(this);
94  }
95  Centre();
96 ////@end CAutodefOrgPanel creation
97  return true;
98 }
99 
100 
101 /*!
102  * CAutodefOrgPanel destructor
103  */
104 
106 {
107 ////@begin CAutodefOrgPanel destruction
108 ////@end CAutodefOrgPanel destruction
109 }
110 
111 
112 /*!
113  * Member initialisation
114  */
115 
117 {
118 ////@begin CAutodefOrgPanel member initialisation
120  m_MaxMods = NULL;
122  m_UseLabels = NULL;
126  m_LeaveParen = NULL;
129  m_NoSp = NULL;
130  m_NoCf = NULL;
131  m_NoAff = NULL;
132  m_NoNr = NULL;
135 ////@end CAutodefOrgPanel member initialisation
136  m_HIVRule = NULL;
138 }
139 
140 
141 /*!
142  * Control creation for CAutodefOrgPanel
143  */
144 
146 {
147 ////@begin CAutodefOrgPanel content construction
148  CAutodefOrgPanel* itemPanel1 = this;
149 
150  wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemPanel1, wxID_ANY, _("SOURCE"));
151  wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
152  itemPanel1->SetSizer(itemStaticBoxSizer2);
153 
154  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
155  itemStaticBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
156 
157  wxStaticText* itemStaticText4 = new wxStaticText( itemStaticBoxSizer2->GetStaticBox(), wxID_STATIC, _("Modifier List"), wxDefaultPosition, wxDefaultSize, 0 );
158  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
159 
160  wxArrayString m_ModListTypeStrings;
161  m_ModListTypeStrings.Add(_("Custom"));
162  m_ModListTypeStrings.Add(_("All"));
163  m_ModListType = new wxChoice( itemStaticBoxSizer2->GetStaticBox(), ID_MOD_LIST_TYPE, wxDefaultPosition, wxDefaultSize, m_ModListTypeStrings, 0 );
164  m_ModListType->SetStringSelection(_("Custom"));
165  itemBoxSizer3->Add(m_ModListType, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
166 
167  m_MaxMods = new wxStaticText( itemStaticBoxSizer2->GetStaticBox(), wxID_STATIC, _("Maximum modifiers per line"), wxDefaultPosition, wxDefaultSize, 0 );
168  itemBoxSizer3->Add(m_MaxMods, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
169 
170  wxArrayString m_MaxModifiersStrings;
171  m_MaxModifiersStrings.Add(_("No limit"));
172  m_MaxModifiers = new wxChoice( itemStaticBoxSizer2->GetStaticBox(), ID_AD_MODLIMIT, wxDefaultPosition, wxDefaultSize, m_MaxModifiersStrings, 0 );
173  m_MaxModifiers->SetStringSelection(_("No limit"));
174  itemBoxSizer3->Add(m_MaxModifiers, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
175 
176  m_UseLabels = new wxCheckBox( itemStaticBoxSizer2->GetStaticBox(), ID_AD_USE_LABELS, _("Use labels"), wxDefaultPosition, wxDefaultSize, 0 );
177  m_UseLabels->SetValue(false);
178  itemBoxSizer3->Add(m_UseLabels, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
179 
180  m_AvailableModifiersSizer = new wxStaticBox(itemStaticBoxSizer2->GetStaticBox(), wxID_ANY, _("Available Modifiers"));
181  wxStaticBoxSizer* itemStaticBoxSizer9 = new wxStaticBoxSizer(m_AvailableModifiersSizer, wxVERTICAL);
182  itemStaticBoxSizer2->Add(itemStaticBoxSizer9, 0, wxGROW|wxALL, 0);
183 
184  m_ModifierSizer = new wxFlexGridSizer(0, m_ModifierSizerColumns, 0, 0);
185  itemStaticBoxSizer9->Add(m_ModifierSizer, 0, wxGROW|wxALL, 5);
186 
187  wxStaticBox* itemStaticBoxSizer11Static = new wxStaticBox(itemStaticBoxSizer2->GetStaticBox(), wxID_ANY, _("Other Options"));
188  wxStaticBoxSizer* itemStaticBoxSizer11 = new wxStaticBoxSizer(itemStaticBoxSizer11Static, wxVERTICAL);
189  itemStaticBoxSizer2->Add(itemStaticBoxSizer11, 0, wxGROW|wxALL, 0);
190 
191  m_OtherOptionsGrid = new wxFlexGridSizer(0, 3, 0, 0);
192  itemStaticBoxSizer11->Add(m_OtherOptionsGrid, 0, wxGROW|wxALL, 5);
193 
194  m_LeaveParen = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_LEAVE_PARENTHETICAL, _("Leave in parenthetical organism info"), wxDefaultPosition, wxDefaultSize, 0 );
195  m_LeaveParen->SetValue(false);
196  m_OtherOptionsGrid->Add(m_LeaveParen, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
197 
198  m_IncludeCountry = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_INCLUDE_COUNTRY_TEXT, _("Include text after colon in country"), wxDefaultPosition, wxDefaultSize, 0 );
199  m_IncludeCountry->SetValue(false);
200  m_OtherOptionsGrid->Add(m_IncludeCountry, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
201 
202  m_KeepAfterSemicolon = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_KEEP_AFTER_SEMICOLON, _("Include text after semicolon in modifiers"), wxDefaultPosition, wxDefaultSize, 0 );
203  m_KeepAfterSemicolon->SetValue(false);
204  m_OtherOptionsGrid->Add(m_KeepAfterSemicolon, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
205 
206  m_NoSp = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_DO_NOT_APPLY_TO_SP, _("Do not apply modifiers to 'sp.' organisms"), wxDefaultPosition, wxDefaultSize, 0 );
207  m_NoSp->SetValue(false);
208  m_OtherOptionsGrid->Add(m_NoSp, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
209 
210  m_NoCf = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_DO_NOT_APPLY_TO_CF, _("Do not apply modifiers to 'cf.' organisms"), wxDefaultPosition, wxDefaultSize, 0 );
211  m_NoCf->SetValue(false);
212  m_OtherOptionsGrid->Add(m_NoCf, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
213 
214  m_NoAff = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_DO_NOT_APPLY_TO_AFF, _("Do not apply modifiers to 'aff.' organisms"), wxDefaultPosition, wxDefaultSize, 0 );
215  m_NoAff->SetValue(false);
216  m_OtherOptionsGrid->Add(m_NoAff, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
217 
218  m_NoNr = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_DO_NOT_APPLY_TO_NR, _("Do not apply modifiers to 'nr.' organisms"), wxDefaultPosition, wxDefaultSize, 0 );
219  m_NoNr->SetValue(false);
220  m_OtherOptionsGrid->Add(m_NoNr, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
221 
222  m_NoMatchTaxname = new wxCheckBox( itemStaticBoxSizer11->GetStaticBox(), ID_AD_NO_MATCH_TAXNAME, _("Do not apply modifier to organisms with matching taxname"), wxDefaultPosition, wxDefaultSize, 0 );
223  m_NoMatchTaxname->SetValue(true);
224  m_OtherOptionsGrid->Add(m_NoMatchTaxname, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
225 
226  m_HIVRuleSizer = new wxBoxSizer(wxVERTICAL);
227  itemStaticBoxSizer2->Add(m_HIVRuleSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
228 
229 ////@end CAutodefOrgPanel content construction
230 
231 }
232 
233 
234 /*!
235  * Should we show tooltips?
236  */
237 
239 {
240  return true;
241 }
242 
243 /*!
244  * Get bitmap resources
245  */
246 
247 wxBitmap CAutodefOrgPanel::GetBitmapResource( const wxString& name )
248 {
249  // Bitmap retrieval
250 ////@begin CAutodefOrgPanel bitmap retrieval
251  wxUnusedVar(name);
252  return wxNullBitmap;
253 ////@end CAutodefOrgPanel bitmap retrieval
254 }
255 
256 /*!
257  * Get icon resources
258  */
259 
260 wxIcon CAutodefOrgPanel::GetIconResource( const wxString& name )
261 {
262  // Icon retrieval
263 ////@begin CAutodefOrgPanel icon retrieval
264  wxUnusedVar(name);
265  return wxNullIcon;
266 ////@end CAutodefOrgPanel icon retrieval
267 }
268 
269 
271 {
272 
273 }
274 
275 
276 static string s_GetModifierStatus (bool all_present, bool all_unique, bool is_unique)
277 {
278  string status = "";
279 
280  if (all_present && all_unique)
281  {
282  status = "All present, all unique";
283  }
284  else if (all_present && is_unique)
285  {
286  status = "All present, one unique";
287  }
288  else if (all_present && ! is_unique)
289  {
290  status = "All present, mixed";
291  }
292  else if (! all_present && all_unique)
293  {
294  status = "Some missing, all unique";
295  }
296  else if (! all_present && is_unique)
297  {
298  status = "Some missing, one unique";
299  }
300  else if (! all_present && ! is_unique)
301  {
302  status = "Some missing, mixed";
303  }
304  return status;
305 }
306 
307 
309 {
310  wxArrayString HIVStrings;
311  HIVStrings.Add(_("Prefer Clone"));
312  HIVStrings.Add(_("Prefer Isolate"));
313  HIVStrings.Add(_("Want Both Isolate and Clone"));
314 
315  m_HIVRule = new wxRadioBox (this, wxID_ANY, _("HIV Rule"), wxDefaultPosition, wxDefaultSize,
316  HIVStrings, 1, wxRA_SPECIFY_ROWS);
317  m_HIVRuleSizer->Add (m_HIVRule, 0, wxALIGN_LEFT|wxALL, 5);
318 }
319 
320 bool sortByLabel(const objects::CAutoDefAvailableModifier& name1, const objects::CAutoDefAvailableModifier& name2)
321 {
322  return name1.Label() < name2.Label();
323 }
324 
326 {
327  // list modifiers in alphabetical order in m_ModifierSizerColumns number of columns
328  // fill the sizer in a column-major order
329  m_ModifierButtons.clear();
330 
331  sort(params.m_ModifierList.begin(), params.m_ModifierList.end(), sortByLabel);
332  int num_available = 0;
333  for (auto& it : params.m_ModifierList) {
334  if (it.AnyPresent()) {
335  num_available++;
336  }
337  }
338 
339  size_t row = 3;
340  if (num_available > 9) {
341  row = num_available / 3;
342  if (num_available % 3 != 0) {
343  row++;
344  }
345  }
346 
347  vector<wxFlexGridSizer*> flex_sizers;
348  for (auto i = 0; i < m_ModifierSizerColumns; ++i) {
349  wxFlexGridSizer* flexsizerA = new wxFlexGridSizer(0, 1, 0, 0);
350  m_ModifierSizer->Add(flexsizerA, 0, wxGROW | wxALL, 5);
351  flex_sizers.push_back(flexsizerA);
352  }
353 
354  num_available = 0;
355  for (size_t n = 0; n < params.m_ModifierList.size(); ++n) {
356  if (params.m_ModifierList[n].AnyPresent()) {
357  string mod_status = s_GetModifierStatus(params.m_ModifierList[n].AllPresent(),
358  params.m_ModifierList[n].AllUnique(),
359  params.m_ModifierList[n].IsUnique());
360  string first_value;
361  params.m_ModifierList[n].FirstValue(first_value);
362  if (first_value.length() > 25) {
363  first_value = first_value.substr(0, 22) + "...";
364  }
365  mod_status += " '" + first_value + "'";
366 
367  string mod_name = params.m_ModifierList[n].Label();
368  mod_name[0] = toupper(mod_name[0]);
369 
370  wxCheckBox* btn = new wxCheckBox(m_AvailableModifiersSizer, wxID_ANY,
371  ToWxString(mod_name + ": " + mod_status), wxDefaultPosition, wxDefaultSize, 0);
372  btn->SetValue(params.m_ModifierList[n].IsRequested());
373 
374  size_t ratio = num_available / row;
375  if (ratio < flex_sizers.size()) {
376  flex_sizers[ratio]->Add(btn, 0, wxALIGN_LEFT | wxALL, 5);
377  }
378 
379  m_ModifierButtons.push_back(btn);
380  num_available++;
381  }
382  else {
383  m_ModifierButtons.push_back(NULL);
384  }
385  }
386  return num_available;
387 }
388 
390 {
391  if (!params) {
392  Clear();
393  return;
394  }
395 
396  m_UseLabels->SetValue (params->m_UseLabels);
397 
398  while (m_ModifierSizer->GetItemCount() > 0) {
399  int pos = 0;
400  m_ModifierSizer->GetItem(pos)->DeleteWindows();
401  m_ModifierSizer->Remove(pos);
402  }
403 
404  int num_available = x_ListModifiers(*params);
405 
406  m_MaxModifiers->Clear();
407  m_MaxModifiers->AppendString(wxT("No limit"));
408  for (int i = 1; i < num_available; i++) {
410  }
411  m_MaxModifiers->SetSelection (params->m_MaxMods);
412  if (num_available < 1) {
413  m_MaxModifiers->Enable(false);
414  } else {
415  m_MaxModifiers->Enable(true);
416  }
417 
418  // Other Options
419  m_NoSp->SetValue (params->m_DoNotApplyToSp);
420  m_NoNr->SetValue (params->m_DoNotApplyToNr);
421  m_NoCf->SetValue (params->m_DoNotApplyToCf);
422  m_NoAff->SetValue (params->m_DoNotApplyToAff);
423  m_LeaveParen->SetValue (params->m_LeaveParenthetical);
424  m_IncludeCountry->SetValue (params->m_IncludeCountryText);
425  m_KeepAfterSemicolon->SetValue (params->m_KeepAfterSemicolon);
426 
427  if (params->m_NeedHIVRule) {
428  if (m_HIVRule == NULL) {
429  x_AddHIVRule();
430  }
431  m_HIVRule->SetSelection (params->m_HIVRule);
432  } else {
433  while (m_HIVRuleSizer->GetItemCount() > 0) {
434  int pos = 0;
435  m_HIVRuleSizer->GetItem(pos)->DeleteWindows();
436  m_HIVRuleSizer->Remove(pos);
437  }
438  }
439 
440  if (GetSizer())
441  {
442  GetSizer()->SetSizeHints(this);
443  }
444  Centre();
445 }
446 
447 
449 {
450  params.m_UseLabels = m_UseLabels->GetValue();
451 
452  sort(params.m_ModifierList.begin(), params.m_ModifierList.end(), sortByLabel);
453 
454  for (size_t n = 0; n < params.m_ModifierList.size(); n++) {
455  if (m_ModifierButtons[n] == NULL) {
456  params.m_ModifierList[n].SetRequested(false);
457  } else {
458  params.m_ModifierList[n].SetRequested (m_ModifierButtons[n]->GetValue ());
459  }
460  }
461 
462  params.m_DoNotApplyToSp = m_NoSp->GetValue ();
463  params.m_DoNotApplyToNr = m_NoNr->GetValue ();
464  params.m_DoNotApplyToCf = m_NoCf->GetValue ();
465  params.m_DoNotApplyToAff = m_NoAff->GetValue ();
466 
467  for (size_t n = 0; n < params.m_ModifierList.size(); n++) {
468  if (m_ModifierButtons[n] == NULL) {
469  params.m_ModifierList[n].SetRequested(false);
470  } else {
471  params.m_ModifierList[n].SetRequested (m_ModifierButtons[n]->GetValue ());
472  }
473  }
474 
475  if (m_HIVRule) {
476  params.m_HIVRule = m_HIVRule->GetSelection ();
477  }
478 
479  params.m_MaxMods = m_MaxModifiers->GetSelection ();
480 
481  params.m_LeaveParenthetical = m_LeaveParen->GetValue();
482  params.m_IncludeCountryText = m_IncludeCountry->GetValue();
483  params.m_KeepAfterSemicolon = m_KeepAfterSemicolon->GetValue();
484 
485 }
486 
488 
static string s_GetModifierStatus(bool all_present, bool all_unique, bool is_unique)
bool sortByLabel(const objects::CAutoDefAvailableModifier &name1, const objects::CAutoDefAvailableModifier &name2)
#define ID_AD_INCLUDE_COUNTRY_TEXT
#define ID_AD_MODLIMIT
#define ID_AD_DO_NOT_APPLY_TO_CF
#define ID_AD_DO_NOT_APPLY_TO_SP
#define ID_AD_NO_MATCH_TAXNAME
#define ID_MOD_LIST_TYPE
#define ID_AD_USE_LABELS
#define ID_AD_LEAVE_PARENTHETICAL
#define ID_AD_DO_NOT_APPLY_TO_AFF
#define ID_AD_DO_NOT_APPLY_TO_NR
#define ID_AD_KEEP_AFTER_SEMICOLON
vector< wxCheckBox * > m_ModifierButtons
wxBoxSizer * m_HIVRuleSizer
wxCheckBox * m_IncludeCountry
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
~CAutodefOrgPanel()
Destructor.
CAutodefOrgPanel()
Constructors.
void SetParams(SAutodefParams *params)
wxStaticText * m_MaxMods
int x_ListModifiers(SAutodefParams &params)
wxFlexGridSizer * m_OtherOptionsGrid
wxCheckBox * m_UseLabels
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=10204, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
wxCheckBox * m_LeaveParen
wxStaticBox * m_AvailableModifiersSizer
wxCheckBox * m_NoMatchTaxname
static bool ShowToolTips()
Should we show tooltips?
wxFlexGridSizer * m_ModifierSizer
void PopulateParams(SAutodefParams &params)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxCheckBox * m_KeepAfterSemicolon
void Init()
Initialises member variables.
objects::CAutoDefSourceDescription::TAvailableModifierVector m_ModifierList
unsigned int m_HIVRule
unsigned int m_MaxMods
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#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 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
END_EVENT_TABLE()
int i
yy_size_t n
#define wxT(x)
Definition: muParser.cpp:41
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size
int toupper(Uchar c)
Definition: ncbictype.hpp:73
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Tue Jun 18 13:34:00 2024 by modify_doxy.py rev. 669887