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

Go to the SVN repository for this file.

1 /* $Id: orggeneral_panel.cpp 47139 2022-09-12 19:11:59Z 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 <objmgr/bioseq_ci.hpp>
35 #include <objmgr/seqdesc_ci.hpp>
38 
45 
46 #include <wx/sizer.h>
47 #include <wx/stattext.h>
48 #include <wx/textctrl.h>
49 #include <wx/choice.h>
50 #include <wx/icon.h>
51 
52 
55 
56 /*
57  * COrgGeneralPanel type definition
58  */
59 
60 IMPLEMENT_DYNAMIC_CLASS( COrgGeneralPanel, wxPanel )
61 
62 
63 /*
64  * COrgGeneralPanel event table definition
65  */
66 
67 BEGIN_EVENT_TABLE( COrgGeneralPanel, wxPanel )
68 
69 ////@begin COrgGeneralPanel event table entries
70 ////@end COrgGeneralPanel event table entries
71 
73 
74 
75 /*
76  * COrgGeneralPanel constructors
77  */
78 
80 {
81  Init();
82 }
83 
84 COrgGeneralPanel::COrgGeneralPanel( wxWindow* parent,
85  ICommandProccessor* cmdproc,
87  wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
88  : m_CmdProcessor(cmdproc), m_Seh(seh)
89 {
90  Init();
91  Create(parent, id, pos, size, style);
92 }
93 
94 
95 /*
96  * COrgGeneralPanel creator
97  */
98 
99 bool COrgGeneralPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
100 {
101 ////@begin COrgGeneralPanel creation
102  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
103  wxPanel::Create( parent, id, pos, size, style );
104 
105  CreateControls();
106  if (GetSizer())
107  {
108  GetSizer()->SetSizeHints(this);
109  }
110  Centre();
111 ////@end COrgGeneralPanel creation
112  return true;
113 }
114 
115 
116 /*
117  * COrgGeneralPanel destructor
118  */
119 
121 {
122 ////@begin COrgGeneralPanel destruction
123 ////@end COrgGeneralPanel destruction
124 }
125 
126 
127 /*
128  * Member initialisation
129  */
130 
132 {
133 ////@begin COrgGeneralPanel member initialisation
134  m_Taxname = NULL;
135  m_Strain = NULL;
136  m_Isolate = NULL;
137  m_Cultivar = NULL;
138  m_Breed = NULL;
139 ////@end COrgGeneralPanel member initialisation
140 }
141 
142 
143 /*
144  * Control creation for COrgGeneralPanel
145  */
146 
148 {
149 ////@begin COrgGeneralPanel content construction
150  COrgGeneralPanel* itemPanel1 = this;
151 
152  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
153  itemPanel1->SetSizer(itemBoxSizer2);
154 
155  wxFlexGridSizer* itemFlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 0);
156  itemBoxSizer2->Add(itemFlexGridSizer1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
157 
158  wxStaticText* itemStaticText2 = new wxStaticText( itemPanel1, wxID_STATIC, _("Organism*"), wxDefaultPosition, wxDefaultSize, 0 );
159  itemFlexGridSizer1->Add(itemStaticText2, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
160 
161 #ifdef __WXMSW__
162  m_Taxname = new wxTextCtrl(itemPanel1, ID_ORGTAXNAME, wxEmptyString, wxDefaultPosition, wxSize(240, -1), 0);
163 #else
164  m_Taxname = new wxTextCtrl(itemPanel1, ID_ORGTAXNAME, wxEmptyString, wxDefaultPosition, wxSize(270, -1), 0);
165 #endif
166  itemFlexGridSizer1->Add(m_Taxname, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
167 
168  wxStaticText* itemStaticText3 = new wxStaticText( itemPanel1, wxID_STATIC, _("strain**"), wxDefaultPosition, wxDefaultSize, 0 );
169  itemFlexGridSizer1->Add(itemStaticText3, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
170 
171  m_Strain = new wxTextCtrl( itemPanel1, ID_ORGSTRAIN, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
172  itemFlexGridSizer1->Add(m_Strain, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("isolate**"), wxDefaultPosition, wxDefaultSize, 0 );
175  itemFlexGridSizer1->Add(itemStaticText4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
176 
177  m_Isolate = new wxTextCtrl( itemPanel1, ID_ORGISOLATE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
178  itemFlexGridSizer1->Add(m_Isolate, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
179 
180  wxStaticText* itemStaticText5 = new wxStaticText( itemPanel1, wxID_STATIC, _("cultivar**"), wxDefaultPosition, wxDefaultSize, 0 );
181  itemFlexGridSizer1->Add(itemStaticText5, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
182 
183  m_Cultivar = new wxTextCtrl( itemPanel1, ID_ORGCULTIVAR, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
184  itemFlexGridSizer1->Add(m_Cultivar, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
185 
186  wxStaticText* itemStaticText6 = new wxStaticText(itemPanel1, wxID_STATIC, _("breed**"), wxDefaultPosition, wxDefaultSize, 0);
187  itemFlexGridSizer1->Add(itemStaticText6, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
188 
189  m_Breed = new wxTextCtrl(itemPanel1, ID_ORGBREED, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
190  itemFlexGridSizer1->Add(m_Breed, 0, wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);
191 
192 
193  itemBoxSizer2->AddStretchSpacer();
194 
195  wxStaticText* itemStaticText7 = new wxStaticText(itemPanel1, wxID_STATIC, _("**At least one field is required"), wxDefaultPosition, wxDefaultSize, 0);
196  itemBoxSizer2->Add(itemStaticText7, 0, wxALIGN_RIGHT | wxALL, 5);
197 
198 
199 ////@end COrgGeneralPanel content construction
200 }
201 
202 
203 /*
204  * Should we show tooltips?
205  */
206 
208 {
209  return true;
210 }
211 
212 /*
213  * Get bitmap resources
214  */
215 
216 wxBitmap COrgGeneralPanel::GetBitmapResource( const wxString& name )
217 {
218  // Bitmap retrieval
219 ////@begin COrgGeneralPanel bitmap retrieval
220  wxUnusedVar(name);
221  return wxNullBitmap;
222 ////@end COrgGeneralPanel bitmap retrieval
223 }
224 
225 /*
226  * Get icon resources
227  */
228 
229 wxIcon COrgGeneralPanel::GetIconResource( const wxString& name )
230 {
231  // Icon retrieval
232 ////@begin COrgGeneralPanel icon retrieval
233  wxUnusedVar(name);
234  return wxNullIcon;
235 ////@end COrgGeneralPanel icon retrieval
236 }
237 
239 {
240  m_Source.Reset(&src);
242 }
243 
244 
246 {
247  m_Taxname->SetValue(wxT(""));
248  m_Strain->SetValue(wxT(""));
249  m_Isolate->SetValue(wxT(""));
250  m_Cultivar->SetValue(wxT(""));
251  m_Breed->SetValue(wxT(""));
252 }
253 
254 
256 {
257  x_Reset();
258  if (m_Source) {
259  if (m_Source->IsSetTaxname()) {
260  m_Taxname->SetValue(ToWxString(m_Source->GetTaxname()));
261  }
262  if (m_Source->IsSetOrgMod()) {
263  for (auto& it : m_Source->GetOrg().GetOrgname().GetMod()) {
264  if (it->IsSetSubtype() && it->IsSetSubname()) {
265  auto subtype = it->GetSubtype();
266  switch (subtype) {
268  m_Strain->SetValue(ToWxString(it->GetSubname()));
269  break;
271  m_Isolate->SetValue(ToWxString(it->GetSubname()));
272  break;
274  m_Cultivar->SetValue(ToWxString(it->GetSubname()));
275  break;
277  m_Breed->SetValue(ToWxString(it->GetSubname()));
278  break;
279  default:
280  break;
281  }
282  }
283  }
284  }
285  }
286  return true;
287 }
288 
289 COrgName::TMod::iterator s_UpdateSubtype
290 (COrgName::TMod& orgmod_list, COrgName::TMod::iterator it, wxTextCtrl* ctrl, bool& changed)
291 {
292  if (ctrl->IsEmpty()) {
293  it = orgmod_list.erase(it);
294  changed = true;
295  } else {
296  if (!(*it)->IsSetSubname() || !NStr::Equal((*it)->GetSubname(), ToStdString(ctrl->GetValue()))) {
297  (*it)->SetSubname(ToStdString(ctrl->GetValue()));
298  changed = true;
299  }
300  ++it;
301  }
302  return it;
303 }
304 
306 {
307  bool any_change = false;
308 
309  COrg_ref& org = src.SetOrg();
310 
311  // get taxname
312  const string taxname = ToStdString(m_Taxname->GetValue());
313  if (org.IsSetTaxname()) {
314  if (taxname.empty()) { // delete old taxname
315  org.ResetTaxname();
316  any_change = true;
317  }
318  else if (!NStr::Equal(taxname, org.GetTaxname())) { // update
319  org.SetTaxname(taxname);
320  any_change = true;
321  }
322  }
323  else if (!taxname.empty()) {
324  org.SetTaxname(taxname);
325  any_change = true;
326  }
327 
328  bool found_strain = false;
329  bool found_isolate = false;
330  bool found_cultivar = false;
331  bool found_breed = false;
332 
333  auto& orgmodlist = org.SetOrgname().SetMod();
334  auto mod = orgmodlist.begin();
335  while (mod != orgmodlist.end()) {
336  if ((*mod)->IsSetSubtype() && (*mod)->IsSetSubname()) {
337  auto subtype = (*mod)->GetSubtype();
338  switch (subtype) {
340  found_strain = true;
341  mod = s_UpdateSubtype(orgmodlist, mod, m_Strain, any_change);
342  break;
344  found_isolate = true;
345  mod = s_UpdateSubtype(orgmodlist, mod, m_Isolate, any_change);
346  break;
348  found_cultivar = true;
349  mod = s_UpdateSubtype(orgmodlist, mod, m_Cultivar, any_change);
350  break;
352  found_breed = true;
353  mod = s_UpdateSubtype(orgmodlist, mod, m_Breed, any_change);
354  break;
355  default:
356  ++mod;
357  }
358  }
359  else {
360  ++mod;
361  }
362  }
363 
364  // Create new orgmods for items that have values but weren't already present
365  if (!found_strain && !m_Strain->IsEmpty()) {
366  orgmodlist.push_back(CRef<COrgMod>(new COrgMod(COrgMod::eSubtype_strain, ToStdString(m_Strain->GetValue()))));
367  any_change = true;
368  }
369  if (!found_isolate && !m_Isolate->IsEmpty()) {
370  orgmodlist.push_back(CRef<COrgMod>(new COrgMod(COrgMod::eSubtype_isolate, ToStdString(m_Isolate->GetValue()))));
371  any_change = true;
372  }
373  if (!found_cultivar && !m_Cultivar->IsEmpty()) {
374  orgmodlist.push_back(CRef<COrgMod>(new COrgMod(COrgMod::eSubtype_cultivar, ToStdString(m_Cultivar->GetValue()))));
375  any_change = true;
376  }
377  if (!found_breed && !m_Breed->IsEmpty()) {
378  orgmodlist.push_back(CRef<COrgMod>(new COrgMod(COrgMod::eSubtype_breed, ToStdString(m_Breed->GetValue()))));
379  any_change = true;
380  }
381 
382  // reset orgmods if none found
383  if (any_change && orgmodlist.empty()) {
384  org.SetOrgname().ResetMod();
385  }
386  return any_change;
387 }
388 
389 bool COrgGeneralPanel::x_HasTaxnameChanged(const CBioSource& orig_src, const CBioSource& edited_src)
390 {
391  if (orig_src.IsSetTaxname() && edited_src.IsSetTaxname() && !NStr::EqualCase(orig_src.GetTaxname(), edited_src.GetTaxname()))
392  return true;
393 
394  if (!orig_src.IsSetTaxname() && edited_src.IsSetTaxname())
395  return true;
396 
397  if (orig_src.IsSetTaxname() && !edited_src.IsSetTaxname())
398  return true;
399 
400  return false;
401 }
402 
404 {
406 
407  return true;
408 }
409 
410 
412 {
414  empty->SetSource();
415 
416  CRef<CSeqdesc> new_desc(new CSeqdesc());
417  new_desc->SetSource();
418  x_ApplyChangesToSource(new_desc->SetSource());
419 
420  if (new_desc->Equals(*empty))
421  return;
422 
423  CRef<CCmdComposite> cmd(new CCmdComposite("update source"));
424  bool any_changes = false;
425 
426  bool taxname_changed = false;
427  for (CBioseq_CI bi(m_Seh, CSeq_inst::eMol_na); bi; ++bi) {
429  if (di) {
430  // edit existing descriptor
431  CRef<CSeqdesc> cpy(new CSeqdesc());
432  cpy->Assign(*di);
433 
435  taxname_changed = x_HasTaxnameChanged(di->GetSource(), cpy->GetSource());
436  if (taxname_changed) {
438  if (cpy->GetSource().IsSetLineage())
439  cpy->SetSource().SetOrg().SetOrgname().ResetLineage();
440  }
441  if (!di->Equals(*cpy)) {
443  cmd->AddCommand(*chg);
444  any_changes = true;
445  }
446  } else {
447  // create new source descriptor on this sequence or on the nuc-prot that contains it
448  CRef<CSeqdesc> cpy(new CSeqdesc());
449  cpy->Assign(*new_desc);
451  auto entry = bi->GetParentEntry();
452  if (parent && parent.IsSetClass() && parent.GetClass() == CBioseq_set::eClass_nuc_prot)
453  entry = parent.GetParentEntry();
454  CIRef<IEditCommand> cmdAddDesc(new CCmdCreateDesc(entry, *cpy));
455  cmd->AddCommand(*cmdAddDesc);
456  any_changes = true;
457  taxname_changed = true;
458  }
459  }
460 
461  if (any_changes) {
463  }
464 
465  if (taxname_changed) {
466  try {
468  if (taxlookup_cmd)
469  m_CmdProcessor->Execute(taxlookup_cmd);
470  }
471  catch (const CException& e) {
472  LOG_POST(Error << e.GetMsg());
473  }
474  }
475 }
476 
478 {
479  if (m_Taxname->GetValue().IsEmpty())
480  text += "Organism\n";
481 
482  if (m_Strain->GetValue().IsEmpty() && m_Isolate->GetValue().IsEmpty() && m_Cultivar->GetValue().IsEmpty() && m_Breed->GetValue().IsEmpty())
483  text += "At least one field is required: strain, isolate, cultivar, breed\n";
484 }
485 
const string & GetTaxname(void) const
Definition: BioSource.cpp:340
bool IsSetLineage(void) const
Definition: BioSource.cpp:355
bool IsSetTaxname(void) const
Definition: BioSource.cpp:335
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_set_Handle –.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool x_ApplyChangesToSource(objects::CBioSource &src)
bool Create(wxWindow *parent, wxWindowID id=ID_CORGGENERALPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void CreateControls()
Creates the controls and sizers.
virtual void ApplyCommand()
wxTextCtrl * m_Cultivar
static bool ShowToolTips()
Should we show tooltips?
virtual bool TransferDataToWindow()
void Init()
Initialises member variables.
objects::CSeq_entry_Handle m_Seh
virtual bool TransferDataFromWindow()
virtual void ReportMissingFields(string &text)
ICommandProccessor * m_CmdProcessor
void ApplyBioSource(objects::CBioSource &src)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
~COrgGeneralPanel()
Destructor.
wxTextCtrl * m_Isolate
bool x_HasTaxnameChanged(const objects::CBioSource &orig_src, const objects::CBioSource &edited_src)
COrgGeneralPanel()
Constructors.
CRef< objects::CBioSource > m_Source
wxTextCtrl * m_Taxname
@OrgMod.hpp User-defined methods of the data storage class.
Definition: OrgMod.hpp:54
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
#define _(proto)
Definition: ct_nlmzip_i.h:78
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#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
void CleanupForTaxnameChange(CObjectInfo oi)
Definition: macro_util.cpp:526
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
virtual bool Equals(const CSerialObject &object, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
TClass GetClass(void) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
bool IsSetClass(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Definition: seqdesc_ci.cpp:326
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 bool EqualCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive equality of a substring with another string.
Definition: ncbistr.hpp:5325
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
void SetOrg(TOrg &value)
Assign a value to Org data member.
Definition: BioSource_.cpp:108
const TTaxname & GetTaxname(void) const
Get the Taxname member data.
Definition: Org_ref_.hpp:372
void ResetTaxname(void)
Reset Taxname data member.
Definition: Org_ref_.cpp:52
void SetTaxname(const TTaxname &value)
Assign a value to Taxname data member.
Definition: Org_ref_.hpp:381
list< CRef< COrgMod > > TMod
Definition: OrgName_.hpp:332
bool IsSetTaxname(void) const
preferred formal name Check if a value has been assigned to Taxname data member.
Definition: Org_ref_.hpp:360
void SetOrgname(TOrgname &value)
Assign a value to Orgname data member.
Definition: Org_ref_.cpp:87
@ eSubtype_cultivar
Definition: OrgMod_.hpp:93
@ eSubtype_strain
Definition: OrgMod_.hpp:85
@ eSubtype_isolate
Definition: OrgMod_.hpp:100
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
const TSource & GetSource(void) const
Get the variant data.
Definition: Seqdesc_.cpp:566
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
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
Int mod(Int i, Int j)
Definition: njn_integer.hpp:67
USING_SCOPE(objects)
COrgName::TMod::iterator s_UpdateSubtype(COrgName::TMod &orgmod_list, COrgName::TMod::iterator it, wxTextCtrl *ctrl, bool &changed)
CRef< CCmdComposite > TaxonomyLookupCommand(objects::CSeq_entry_Handle seh)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Mon May 13 04:34:11 2024 by modify_doxy.py rev. 669887