NCBI C++ Toolkit Cross Reference

  C++/src/gui/widgets/edit/biosourcepanel.cpp


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
/* $Id: biosourcepanel.cpp 31212 2014-09-12 12:45:01Z bollin $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Vasuki Palanigobu */ #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif ////@begin includes ////@end includes #include <ncbi_pch.hpp> #include <objects/seqfeat/Org_ref.hpp> #include <objects/seqfeat/OrgName.hpp> #include <objects/taxon3/taxon3.hpp> #include <gui/widgets/wx/wx_utils.hpp> #include <gui/widgets/wx/message_box.hpp> //#include <gui/widgets/wx/sys_path.hpp> //#include <gui/widgets/wx/auto_complete_combo.hpp> #include <gui/widgets/wx/auto_complete_text_ctrl.hpp> #include <gui/widgets/wx/taxon_text_completer.hpp> #include "biosourcepanel.hpp" #include "src_other_pnl.hpp" #include <wx/statbox.h> #include <wx/treebook.h> #ifdef _DEBUG #include <serial/objostr.hpp> #include <serial/serial.hpp> #endif ////@begin XPM images ////@end XPM images BEGIN_NCBI_SCOPE USING_SCOPE(objects); /* * CBioSourcePanel type definition */ IMPLEMENT_DYNAMIC_CLASS( CBioSourcePanel, wxPanel ) /* * CBioSourcePanel event table definition */ BEGIN_EVENT_TABLE( CBioSourcePanel, wxPanel ) ////@begin CBioSourcePanel event table entries EVT_BUTTON( ID_BUTTON, CBioSourcePanel::OnTaxonomyLookup ) ////@end CBioSourcePanel event table entries END_EVENT_TABLE() /* * CBioSourcePanel constructors */ static CBioSource dummy; CBioSourcePanel::CBioSourcePanel(): m_Source(dummy) { Init(); } CBioSourcePanel::CBioSourcePanel( wxWindow* parent, objects::CBioSource& source, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ): m_Source(source) { Init(); Create(parent, id, pos, size, style); } /* * OrganismNamePanel creator */ bool CBioSourcePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) { ////@begin CBioSourcePanel creation wxPanel::Create( parent, id, pos, size, style ); CreateControls(); if (GetSizer()) { GetSizer()->SetSizeHints(this); } Centre(); ////@end CBioSourcePanel creation return true; } /* * CBioSourcePanel destructor */ CBioSourcePanel::~CBioSourcePanel() { ////@begin CBioSourcePanel destruction ////@end CBioSourcePanel destruction } /* * Member initialisation */ void CBioSourcePanel::Init() { ////@begin CBioSourcePanel member initialisation m_ScientificNameCtrl = NULL; m_DisableStrainForwardingBtn = NULL; ////@end CBioSourcePanel member initialisation } /* * Control creation for OrganismNamePanel */ void CBioSourcePanel::CreateControls() { ////@begin CBioSourcePanel content construction CBioSourcePanel* itemPanel1 = this; wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); itemPanel1->SetSizer(itemBoxSizer2); wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 3, 0, 0); itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxALIGN_LEFT|wxALL, 5); wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Scientific Name"), wxDefaultPosition, wxDefaultSize, 0 ); itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5); m_ScientificNameCtrl = new CAutoCompleteTextCtrl( itemPanel1, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0 ); itemFlexGridSizer3->Add(m_ScientificNameCtrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5); wxButton* itemButton6 = new wxButton( itemPanel1, ID_BUTTON, _("Taxonomy Lookup"), wxDefaultPosition, wxDefaultSize, 0 ); itemFlexGridSizer3->Add(itemButton6, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); m_DisableStrainForwardingBtn = new wxCheckBox( itemPanel1, ID_DISABLE_STRAIN_FORWARDING_BTN, _("Disable Strain Forwarding"), wxDefaultPosition, wxDefaultSize, 0 ); m_DisableStrainForwardingBtn->SetValue(false); itemBoxSizer2->Add(m_DisableStrainForwardingBtn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); wxStaticBox* itemStaticBoxSizer8Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Additional Modifiers")); wxStaticBoxSizer* itemStaticBoxSizer8 = new wxStaticBoxSizer(itemStaticBoxSizer8Static, wxVERTICAL); itemBoxSizer2->Add(itemStaticBoxSizer8, 0, wxGROW|wxALL, 5); ////@end CBioSourcePanel content construction //m_ScientificNameCtrl->SetIgnoreCase(true); m_ScientificNameCtrl->AutoComplete(new CTaxonTextCompleter()); m_SrcModList = new CSrcModListPanel( itemPanel1, m_Source, wxID_ANY, wxDefaultPosition, wxSize(100, 200), 0 ); itemStaticBoxSizer8->Add(m_SrcModList, 0, wxGROW|wxALL, 5); m_ScientificNameCtrl->Connect(ID_TEXTCTRL, wxEVT_KILL_FOCUS, wxFocusEventHandler(CBioSourcePanel::OnUpdatedTaxname), NULL, this); } bool CBioSourcePanel::TransferDataToWindow() { m_SrcModList->TransferDataToWindow(); if (!wxPanel::TransferDataToWindow()) return false; x_GetOrganismInfo(); return true; } bool CBioSourcePanel::TransferDataFromWindow() { m_SrcModList->TransferDataFromWindow(); if (!wxPanel::TransferDataFromWindow()) return false; x_SetOrganismInfo(); return true; } void CBioSourcePanel::x_GetOrganismInfo() { if (m_Source.IsSetOrg()) { if (m_Source.GetOrg().IsSetTaxname()) { m_ScientificNameCtrl->SetValue(ToWxString(m_Source.GetOrg().GetTaxname())); } else { m_ScientificNameCtrl->Clear(); } } bool disable_strain_forwarding = m_Source.GetDisableStrainForwarding(); m_DisableStrainForwardingBtn->SetValue(disable_strain_forwarding); m_DisableStrainForwardingBtn->Show(disable_strain_forwarding); } void CBioSourcePanel::x_SetOrganismInfo() { string old_taxname = ""; if (m_Source.IsSetOrg() && m_Source.GetOrg().IsSetTaxname()) { old_taxname = m_Source.GetOrg().GetTaxname(); } string new_taxname = ToStdString(m_ScientificNameCtrl->GetValue()); m_Source.SetOrg().SetTaxname(new_taxname); m_SrcModList->TransferDataFromWindow(); m_SrcModList->PopulateModifiers(m_Source); if (!NStr::IsBlank(old_taxname) && !NStr::Equal(old_taxname, new_taxname) && m_Source.IsSetOrg() && m_Source.GetOrg().IsSetOrgname() && m_Source.GetOrg().GetOrgname().IsSetMod()) { COrgName::TMod::iterator it = m_Source.SetOrg().SetOrgname().SetMod().begin(); while (it != m_Source.SetOrg().SetOrgname().SetMod().end()) { if ((*it)->GetSubtype() && (*it)->GetSubtype() == COrgMod::eSubtype_old_name) { it = m_Source.SetOrg().SetOrgname().SetMod().erase(it); } else { it++; } } if (m_Source.GetOrg().GetOrgname().GetMod().empty()) { m_Source.SetOrg().SetOrgname().ResetMod(); } m_SrcModList->SetSource(m_Source); } m_Source.SetDisableStrainForwarding(m_DisableStrainForwardingBtn->GetValue()); } void CBioSourcePanel::PopulateBioSource(CBioSource& source) { if (m_Source.IsSetOrg()) { if (m_Source.GetOrg().IsSetTaxname()) { source.SetOrg().SetTaxname(m_Source.GetOrg().GetTaxname()); } if (m_Source.GetOrg().IsSetCommon()) { source.SetOrg().SetCommon(m_Source.GetOrg().GetCommon()); } if (m_Source.GetOrg().IsSetOrgname()) { if (m_Source.GetOrg().GetOrgname().IsSetLineage()) { source.SetOrg().SetOrgname().SetLineage(m_Source.GetOrg().GetOrgname().GetLineage()); } if (m_Source.GetOrg().GetOrgname().IsSetDiv()) { source.SetOrg().SetOrgname().SetDiv(m_Source.GetOrg().GetOrgname().GetDiv()); } } } m_SrcModList->PopulateModifiers(source); #ifdef _DEBUG CNcbiOstrstream ostr; {{ auto_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, ostr)); *out << m_Source; }} _TRACE(string(CNcbiOstrstreamToString(ostr))); #endif } /* * Should we show tooltips? */ bool CBioSourcePanel::ShowToolTips() { return true; } /* * Get bitmap resources */ wxBitmap CBioSourcePanel::GetBitmapResource( const wxString& name ) { // Bitmap retrieval ////@begin CBioSourcePanel bitmap retrieval wxUnusedVar(name); return wxNullBitmap; ////@end CBioSourcePanel bitmap retrieval } /* * Get icon resources */ wxIcon CBioSourcePanel::GetIconResource( const wxString& name ) { // Icon retrieval ////@begin CBioSourcePanel icon retrieval wxUnusedVar(name); return wxNullIcon; ////@end CBioSourcePanel icon retrieval } /* * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON */ void CBioSourcePanel::OnTaxonomyLookup( wxCommandEvent& event ) { x_SetOrganismInfo(); if (!m_Source.IsSetOrg()) { return; } vector<CRef<COrg_ref> > rq_list; CRef<COrg_ref> org(new COrg_ref()); org->Assign(m_Source.GetOrg()); rq_list.push_back(org); CTaxon3 taxon3; taxon3.Init(); CRef<CTaxon3_reply> reply = taxon3.SendOrgRefList(rq_list); if (reply) { CTaxon3_reply::TReply::const_iterator reply_it = reply->GetReply().begin(); if ((*reply_it)->IsData()) { m_Source.SetOrg().Assign((*reply_it)->GetData().GetOrg()); TransferDataToWindow(); wxTreebook* parent = x_GetTree(); for (size_t i = 0; i < parent->GetPageCount(); ++i) { CSourceOtherPanel* other_panel = dynamic_cast<CSourceOtherPanel*>(parent->GetPage(i)); if (other_panel) { other_panel->TransferFromOrgRef(m_Source.GetOrg()); } else { parent->GetPage(i)->TransferDataToWindow(); } } } } event.Skip(); } wxTreebook* CBioSourcePanel::x_GetTree() { wxWindow* w = this->GetParent(); while (w != NULL) { wxTreebook* parent = dynamic_cast<wxTreebook*>(w); if (parent) { return parent; } else { w = w->GetParent(); } } return NULL; } void CBioSourcePanel::OnUpdatedTaxname (wxFocusEvent& event) { /* when taxname is updated by the user, the "taxon" db reference and the common name should be cleared, JIRA:GB-3053 */ event.Skip(); if (! m_ScientificNameCtrl->IsModified()) return; wxTreebook* parent = x_GetTree(); if (!parent) return; CSourceOtherPanel* other_panel = 0; for (size_t i = 0; i < parent->GetPageCount(); ++i) { other_panel = dynamic_cast<CSourceOtherPanel*>(parent->GetPage(i)); if (other_panel) break; } if (other_panel) { other_panel->OnChangedTaxname(); } m_ScientificNameCtrl->SetModified(false); } END_NCBI_SCOPE

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.