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

Go to the SVN repository for this file.

1 /* $Id: biosourcepanel.cpp 47287 2022-12-17 03:20:06Z evgeniev $
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: Vasuki Palanigobu
27  */
28 
29 #include "wx/wxprec.h"
30 
31 #ifdef __BORLANDC__
32 #pragma hdrstop
33 #endif
34 
35 #ifndef WX_PRECOMP
36 #include "wx/wx.h"
37 #endif
38 
39 ////@begin includes
40 ////@end includes
41 
42 #include <ncbi_pch.hpp>
49 
53 #include "biosourcepanel.hpp"
54 #include "src_other_pnl.hpp"
55 #include "loc_gcode_panel.hpp"
56 
57 #include <wx/statbox.h>
58 #include <wx/treebook.h>
59 
60 #ifdef _DEBUG
61 #include <serial/objostr.hpp>
62 #include <serial/serial.hpp>
63 #endif
64 
65 
66 ////@begin XPM images
67 ////@end XPM images
68 
71 
72 /*
73  * CBioSourcePanel type definition
74  */
75 
76 IMPLEMENT_DYNAMIC_CLASS( CBioSourcePanel, wxPanel )
77 
78 
79 /*
80  * CBioSourcePanel event table definition
81  */
82 
83 BEGIN_EVENT_TABLE( CBioSourcePanel, wxPanel )
84 
85 ////@begin CBioSourcePanel event table entries
86  EVT_BUTTON( ID_ORGPANEL_BTN, CBioSourcePanel::OnTaxonomyLookup )
87 ////@end CBioSourcePanel event table entries
88 
90 
91 
92 /*
93  * CBioSourcePanel constructors
94  */
95 
97 
99 {
100  Init();
101 }
102 
103 
104 CBioSourcePanel::CBioSourcePanel(wxWindow* parent, objects::CBioSource& source, IDescEditorPanel* desc_editor, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) :
105  m_Source(source), m_ParentPanel(desc_editor)
106 {
107  Init();
108  Create(parent, id, pos, size, style);
109 }
110 
111 
112 /*
113  * OrganismNamePanel creator
114  */
115 
116 bool CBioSourcePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
117 {
118 ////@begin CBioSourcePanel creation
119  wxPanel::Create( parent, id, pos, size, style );
120 
121  CreateControls();
122  if (GetSizer())
123  {
124  GetSizer()->SetSizeHints(this);
125  }
126  Centre();
128 ////@end CBioSourcePanel creation
129  return true;
130 }
131 
132 
133 /*
134  * CBioSourcePanel destructor
135  */
136 
138 {
139 ////@begin CBioSourcePanel destruction
140 ////@end CBioSourcePanel destruction
141 }
142 
143 
144 /*
145  * Member initialisation
146  */
147 
149 {
150 ////@begin CBioSourcePanel member initialisation
153 ////@end CBioSourcePanel member initialisation
154 }
155 
156 /*
157  * Control creation for OrganismNamePanel
158  */
159 
161 {
162 ////@begin CBioSourcePanel content construction
163  CBioSourcePanel* itemPanel1 = this;
164 
165  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
166  itemPanel1->SetSizer(itemBoxSizer2);
167 
168  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
169  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5);
170 
171  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Scientific Name"), wxDefaultPosition, wxDefaultSize, 0 );
172  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  m_ScientificNameCtrl = new CAutoCompleteTextCtrl(itemPanel1, ID_ORGPANEL_TXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(200, -1), wxTE_MULTILINE);
175  itemBoxSizer3->Add(m_ScientificNameCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
177 
178  wxButton* itemButton6 = new wxButton( itemPanel1, ID_ORGPANEL_BTN, _("Taxonomy Lookup"), wxDefaultPosition, wxDefaultSize, 0 );
179  itemBoxSizer3->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
180 
181  m_DisableStrainForwardingBtn = new wxCheckBox( itemPanel1, ID_ORGPANEL_CHCKBOX, _("Disable Strain Forwarding"), wxDefaultPosition, wxDefaultSize, 0 );
182  m_DisableStrainForwardingBtn->SetValue(false);
183  itemBoxSizer2->Add(m_DisableStrainForwardingBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
184 
185  wxStaticBox* itemStaticBoxSizer8Static = new wxStaticBox(itemPanel1, ID_ORGPANEL_SIZER, _("Additional Modifiers"));
186  wxStaticBoxSizer* itemStaticBoxSizer8 = new wxStaticBoxSizer(itemStaticBoxSizer8Static, wxVERTICAL);
187  itemBoxSizer2->Add(itemStaticBoxSizer8, 1, wxGROW|wxALL, 5);
188 
189  m_SrcModList = new CSrcModListPanel(itemStaticBoxSizer8->GetStaticBox(), m_Source, wxID_ANY, wxDefaultPosition, wxSize(100, 250), 0 );
190  itemStaticBoxSizer8->Add(m_SrcModList, 1, wxGROW | wxALL, 5);
191 
192  m_ScientificNameCtrl->Bind(wxEVT_LEAVE_WINDOW, &CBioSourcePanel::OnUpdatedTaxname, this);
193  m_ScientificNameCtrl->Bind(wxEVT_TEXT, &CBioSourcePanel::OnEvtText, this);
194 ////@end CBioSourcePanel content construction
195 }
196 
198 {
199  if (!wxPanel::TransferDataToWindow())
200  return false;
202  return true;
203 }
204 
206 {
207  if (!wxPanel::TransferDataFromWindow())
208  return false;
210  return true;
211 }
212 
213 
215 {
216  if (m_Source.IsSetOrg()) {
217  if (m_Source.GetOrg().IsSetTaxname()) {
218  m_ScientificNameCtrl->ChangeValue(ToWxString(m_Source.GetOrg().GetTaxname()));
219  }
220  else {
221  m_ScientificNameCtrl->ChangeValue(wxEmptyString);
222  }
223 
224  }
225  bool disable_strain_forwarding = m_Source.GetDisableStrainForwarding();
226  m_DisableStrainForwardingBtn->SetValue(disable_strain_forwarding);
227  m_DisableStrainForwardingBtn->Show(disable_strain_forwarding);
228 }
229 
231 {
232  if (source.IsSetOrgname()) {
233  COrgName& orgname = source.SetOrg().SetOrgname();
234  if (orgname.IsSetName()) {
235  orgname.ResetName();
236  }
237  }
238  source.RemoveOrgMod(COrgMod::eSubtype_gb_acronym);
240  source.RemoveOrgMod(COrgMod::eSubtype_gb_synonym);
241 }
242 
244 {
245  string old_taxname;
246  if (m_Source.IsSetOrg() && m_Source.GetOrg().IsSetTaxname()) {
247  old_taxname = m_Source.GetOrg().GetTaxname();
248  }
249  string new_taxname = ToStdString(m_ScientificNameCtrl->GetValue());
250  NStr::ReplaceInPlace(new_taxname, "\n", " ");
251  NStr::ReplaceInPlace(new_taxname, "\r", " ");
252  NStr::TruncateSpacesInPlace(new_taxname);
253  m_Source.SetOrg().SetTaxname(new_taxname);
256  if (!NStr::IsBlank(old_taxname) && !NStr::Equal(old_taxname, new_taxname)) {
260  }
261 
262  m_Source.SetDisableStrainForwarding(m_DisableStrainForwardingBtn->GetValue());
263 }
264 
265 
267 {
268  if (m_Source.IsSetOrg()) {
269  source.SetOrg().Assign(m_Source.GetOrg());
270  }
272 
273 #ifdef _DEBUG
274  CNcbiOstrstream ostr;
275  {{
276  unique_ptr<CObjectOStream>
278  *out << m_Source;
279  }}
280  _TRACE(string(CNcbiOstrstreamToString(ostr)));
281 #endif
282 
283 }
284 
285 /*
286  * Should we show tooltips?
287  */
288 
290 {
291  return true;
292 }
293 
294 /*
295  * Get bitmap resources
296  */
297 
298 wxBitmap CBioSourcePanel::GetBitmapResource( const wxString& name )
299 {
300  // Bitmap retrieval
301 ////@begin CBioSourcePanel bitmap retrieval
302  wxUnusedVar(name);
303  return wxNullBitmap;
304 ////@end CBioSourcePanel bitmap retrieval
305 }
306 
307 /*
308  * Get icon resources
309  */
310 
311 wxIcon CBioSourcePanel::GetIconResource( const wxString& name )
312 {
313  // Icon retrieval
314 ////@begin CBioSourcePanel icon retrieval
315  wxUnusedVar(name);
316  return wxNullIcon;
317 ////@end CBioSourcePanel icon retrieval
318 }
319 
320 
321 /*
322  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
323  */
324 
325 void CBioSourcePanel::OnTaxonomyLookup( wxCommandEvent& event )
326 {
328  if (!m_Source.IsSetOrg()) {
329  return;
330  }
331 
332  vector<CRef<COrg_ref> > rq_list;
333  CRef<COrg_ref> org(new COrg_ref());
334  org->Assign(m_Source.GetOrg());
335  rq_list.push_back(org);
336 
337  CTaxon3 taxon3;
338  taxon3.Init();
339  CRef<CTaxon3_reply> reply = taxon3.SendOrgRefList(rq_list);
340  if (reply) {
341  CTaxon3_reply::TReply::const_iterator reply_it = reply->GetReply().begin();
342  if ((*reply_it)->IsData()) {
343  m_Source.SetOrg().Assign((*reply_it)->GetData().GetOrg());
344  m_Source.SetOrg().ResetSyn();
346  if (!m_ParentTreebook) {
348  }
349  for (size_t i = 0; i < m_ParentTreebook->GetPageCount(); ++i) {
350  CSourceOtherPanel* other_panel = dynamic_cast<CSourceOtherPanel*>(m_ParentTreebook->GetPage(i));
351  if (other_panel) {
352  other_panel->TransferFromOrgRef(m_Source.GetOrg());
353  }
354  else {
355  m_ParentTreebook->GetPage(i)->TransferDataToWindow();
356  }
357  }
358  }
359  }
360  event.Skip();
361 }
362 
364 {
365  wxWindow* w = this->GetParent();
366  while (w != NULL) {
367  wxTreebook* parent = dynamic_cast<wxTreebook*>(w);
368  if (parent) {
369  return parent;
370  }
371  else {
372  w = w->GetParent();
373  }
374  }
375  return NULL;
376 }
377 
378 void CBioSourcePanel::OnUpdatedTaxname (wxMouseEvent& event)
379 {
380  if (m_ScientificNameCtrl->IsModified()) {
382  m_ScientificNameCtrl->SetModified(false);
383  }
384 }
385 
386 void CBioSourcePanel::OnEvtText(wxCommandEvent& event)
387 {
388  if (m_ParentPanel) {
390  }
391  else if (m_ParentTreebook) {
392  for (size_t i = 0; i < m_ParentTreebook->GetPageCount(); ++i) {
393  if (CSourceOtherPanel* otherPanel = dynamic_cast<CSourceOtherPanel*>(m_ParentTreebook->GetPage(i))) {
394  otherPanel->OnChangedTaxname();
395  }
396  else if (CLocAndGCodePanel* loc_gc_panel = dynamic_cast<CLocAndGCodePanel*>(m_ParentTreebook->GetPage(i))) {
397  loc_gc_panel->OnChangedTaxname();
398  }
399  }
400  }
401 }
402 
403 
#define static
USING_SCOPE(objects)
static void s_MoreCleanupForTaxnameChange(CBioSource &source)
static CBioSource dummy
CAutoCompleteComboBox.
bool AutoComplete(wxTextCompleter *completer)
CSrcModListPanel * m_SrcModList
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
IDescEditorPanel * m_ParentPanel
void OnUpdatedTaxname(wxMouseEvent &event)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void CreateControls()
Creates the controls and sizers.
CAutoCompleteTextCtrl * m_ScientificNameCtrl
static bool ShowToolTips()
Should we show tooltips?
void PopulateBioSource(objects::CBioSource &source)
void OnEvtText(wxCommandEvent &event)
void OnTaxonomyLookup(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ORGPANEL_BTN
void Init()
Initialises member variables.
wxTreebook * x_GetTree()
wxCheckBox * m_DisableStrainForwardingBtn
wxTreebook * m_ParentTreebook
bool Create(wxWindow *parent, wxWindowID id=ID_ORGANISMNAMEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual bool TransferDataFromWindow()
objects::CBioSource & m_Source
virtual bool TransferDataToWindow()
~CBioSourcePanel()
Destructor.
CBioSourcePanel()
Constructors.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
void TransferFromOrgRef(const objects::COrg_ref &org)
virtual bool TransferDataFromWindow()
void PopulateModifiers(objects::CBioSource &biosrc)
void SetSource(const objects::CBioSource &biosrc)
virtual CRef< CTaxon3_reply > SendOrgRefList(const vector< CRef< COrg_ref > > &list, COrg_ref::fOrgref_parts result_parts=COrg_ref::eOrgref_default, fT3reply_parts t3result_parts=eT3reply_default)
Definition: taxon3.cpp:190
virtual void Init()
Definition: taxon3.cpp:74
virtual void UpdateTaxname()
Definition: utilities.hpp:62
#define _(proto)
Definition: ct_nlmzip_i.h:78
std::ofstream out("events_result.xml")
main entry point for tests
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#define _TRACE(message)
Definition: ncbidbg.hpp:122
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.
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
#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 IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string (in-place)
Definition: ncbistr.cpp:3192
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:5378
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:3396
void ResetName(void)
Reset Name data member.
Definition: OrgName_.cpp:245
bool IsSetName(void) const
Check if a value has been assigned to Name data member.
Definition: OrgName_.hpp:759
@ eSubtype_gb_acronym
used by taxonomy database
Definition: OrgMod_.hpp:115
@ eSubtype_gb_synonym
used by taxonomy database
Definition: OrgMod_.hpp:117
@ eSubtype_gb_anamorph
used by taxonomy database
Definition: OrgMod_.hpp:116
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
Definition: pointer.h:1149
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:58:20 2024 by modify_doxy.py rev. 669887