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

Go to the SVN repository for this file.

1 /* $Id: dbxref_panel.cpp 37100 2016-12-05 17:10:36Z 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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
32 
33 ////@begin includes
34 ////@end includes
35 
36 #include "dbxref_panel.hpp"
38 
39 ////@begin XPM images
40 ////@end XPM images
41 
44 
45 /*!
46  * CDbxrefPanel type definition
47  */
48 
49 IMPLEMENT_DYNAMIC_CLASS( CDbxrefPanel, wxPanel )
50 
51 
52 /*!
53  * CDbxrefPanel event table definition
54  */
55 
56 BEGIN_EVENT_TABLE( CDbxrefPanel, wxPanel )
57 
58 ////@begin CDbxrefPanel event table entries
59 ////@end CDbxrefPanel event table entries
60 
62 
63 
64 /*!
65  * CDbxrefPanel constructors
66  */
67 
68 CDbxrefPanel::CDbxrefPanel()
69 {
70  Init();
71 }
72 
73 CDbxrefPanel::CDbxrefPanel( wxWindow* parent, CSerialObject& object, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
74  : m_Object(&object)
75 {
76  Init();
77  x_UpdateXrefs();
78  Create(parent, id, caption, pos, size, style);
79 }
80 
82 {
83  //m_Object = dynamic_cast<CSeq_feat*>(&object);
84  m_Xrefs.clear();
85  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>(m_Object);
86  if (feat) {
87  if (feat->IsSetDbxref()) {
88  CSeq_feat::TDbxref::const_iterator it = feat->GetDbxref().begin();
89  while (it != feat->GetDbxref().end()) {
90  CRef< CDbtag > tag(new CDbtag());
91  tag->Assign(**it);
92  m_Xrefs.push_back(tag);
93  ++it;
94  }
95  }
96  } else {
97  const COrg_ref* org = dynamic_cast<const COrg_ref*>(m_Object);
98  if (org) {
99  if (org->IsSetDb()) {
100  COrg_ref::TDb::const_iterator it = org->GetDb().begin();
101  while (it != org->GetDb().end()) {
102  CRef< CDbtag > tag(new CDbtag());
103  tag->Assign(**it);
104  m_Xrefs.push_back(tag);
105  ++it;
106  }
107  }
108  }
109  }
110 }
111 
112 /*!
113  * CDbxrefPanel creator
114  */
115 
116 bool CDbxrefPanel::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
117 {
118 ////@begin CDbxrefPanel creation
119  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
120  wxPanel::Create( parent, id, pos, size, style );
121 
122  CreateControls();
123  if (GetSizer())
124  {
125  GetSizer()->SetSizeHints(this);
126  }
127  Centre();
128 ////@end CDbxrefPanel creation
129  return true;
130 }
131 
132 
133 /*!
134  * CDbxrefPanel destructor
135  */
136 
138 {
139 ////@begin CDbxrefPanel destruction
140 ////@end CDbxrefPanel destruction
141 }
142 
143 
144 /*!
145  * Member initialisation
146  */
147 
149 {
150 ////@begin CDbxrefPanel member initialisation
152  m_Sizer = NULL;
153 ////@end CDbxrefPanel member initialisation
154 }
155 
156 
157 /*!
158  * Control creation for CDbxrefPanel
159  */
160 
162 {
163 ////@begin CDbxrefPanel content construction
164  // Generated by DialogBlocks, 30/12/2011 08:04:17 (unregistered)
165 
166  CDbxrefPanel* itemPanel1 = this;
167 
168  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
169  itemPanel1->SetSizer(itemBoxSizer2);
170 
171  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
172  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
173 
174  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Database"), wxDefaultPosition, wxSize(100, -1), 0 );
175  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
176 
177  wxStaticText* itemStaticText5 = new wxStaticText( itemPanel1, wxID_STATIC, _("Object ID"), wxDefaultPosition, wxSize(100, -1), 0 );
178  itemBoxSizer3->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
179 
180  m_ScrolledWindow = new wxScrolledWindow( itemPanel1, ID_SCROLLEDWINDOW2, wxDefaultPosition, wxSize(200, 100), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
181  itemBoxSizer2->Add(m_ScrolledWindow, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
182  m_ScrolledWindow->SetScrollbars(1, 1, 0, 0);
183  m_Sizer = new wxBoxSizer(wxVERTICAL);
184  m_ScrolledWindow->SetSizer(m_Sizer);
185 
186  m_ScrolledWindow->FitInside();
187 
188 ////@end CDbxrefPanel content construction
189 }
190 
191 
193 {
194  wxWindow* row = new CSingleDbxref_SubPanel(m_ScrolledWindow, *tag);
195  m_Sizer->Add(row, 0, wxALIGN_LEFT|wxALL, 0);
196  int row_width;
197  int row_height;
198  row->GetSize(&row_width, &row_height);
199  if (row_width > m_TotalWidth) {
200  m_TotalWidth = row_width;
201  }
202  m_TotalHeight += row_height;
203  m_ScrollRate = row_height;
204  m_NumRows++;
205  return row;
206 }
207 
208 
210 {
211  Freeze();
212  while (m_Sizer->GetItemCount() > 0) {
213  size_t pos = 0;
214  m_Sizer->GetItem(pos)->DeleteWindows();
215  m_Sizer->Remove(pos);
216  }
217  m_TotalHeight = 0;
218  m_TotalWidth = 0;
219  m_NumRows = 0;
220  m_ScrollRate = 0;
221 
222  x_UpdateXrefs();
223  vector< CRef< objects::CDbtag > >::iterator it = m_Xrefs.begin();
224  vector<wxWindow*> rows_to_update;
225  while (it != m_Xrefs.end()) {
226  rows_to_update.push_back(x_AddRow (*it));
227  ++it;
228  }
229  ITERATE(vector<wxWindow*>, it, rows_to_update) {
230  (*it)->TransferDataToWindow();
231  }
232  CRef<CDbtag> last_tag (new CDbtag());
233  x_AddRow (last_tag);
234  m_ScrolledWindow->SetVirtualSize(m_TotalWidth + 10, m_TotalHeight);
235  m_ScrolledWindow->SetScrollRate(0, m_ScrollRate);
236  m_ScrolledWindow->FitInside();
237  Layout();
238  Thaw();
239 
240  if (!wxPanel::TransferDataToWindow())
241  return false;
242  return true;
243 }
244 
245 
247 {
248  if (!wxPanel::TransferDataFromWindow())
249  return false;
250 
251  m_Xrefs.clear();
252 
253  wxSizerItemList::iterator node = m_Sizer->GetChildren().begin();
254  for (; node != m_Sizer->GetChildren().end(); ++node) {
255  wxWindow *w = (*node)->GetWindow();
256  if (!w) {
257  continue;
258  }
259  CRef<CDbtag> edited_tag;
260  CSingleDbxref_SubPanel* singlexref_panel = dynamic_cast<CSingleDbxref_SubPanel*> (w);
261  if (singlexref_panel) {
262  edited_tag = singlexref_panel->GetDbtag();
263  m_Xrefs.push_back(edited_tag);
264  }
265  }
266  return true;
267 }
268 
269 
270 static bool s_HasTag (CDbtag& tag)
271 {
272  bool rval = false;
273 
274  if (tag.IsSetTag()) {
275  if (tag.GetTag().IsStr() && !NStr::IsBlank(tag.GetTag().GetStr())) {
276  rval = true;
277  } else if (tag.GetTag().IsId()) {
278  rval = true;
279  }
280  }
281  return rval;
282 }
283 
284 
286 {
288 
289  seq_feat.ResetDbxref();
290 
291  for (CSeq_feat::TDbxref::iterator x = m_Xrefs.begin();
292  x != m_Xrefs.end();
293  x++) {
294  if ((*x)->IsSetDb() || s_HasTag(**x)) {
295  CRef<CDbtag> new_tag(new CDbtag());
296  new_tag->Assign(**x);
297  seq_feat.SetDbxref().push_back(new_tag);
298  }
299  }
300 }
301 
302 
304 {
306 
307  org.ResetDb();
308 
309  for (COrg_ref::TDb::iterator x = m_Xrefs.begin();
310  x != m_Xrefs.end();
311  x++) {
312  if ((*x)->IsSetDb() || s_HasTag(**x)) {
313  CRef<CDbtag> new_tag(new CDbtag());
314  new_tag->Assign(**x);
315  org.SetDb().push_back(new_tag);
316  }
317  }
318 }
319 
321 {
323  if ((*db)->IsSetDb() && NStr::Equal((*db)->GetDb(), "taxon", NStr::eNocase)) {
324  VECTOR_ERASE(db, m_Xrefs);
325  }
326  }
327 
328  wxSizerItemList::iterator node = m_Sizer->GetChildren().begin();
329  size_t pos = 0;
330  int row_width, row_height;
331  vector<size_t> removed_pos;
332  for (node; node != m_Sizer->GetChildren().end(); ++node, ++pos) {
333  wxWindow *w = (*node)->GetWindow();
334  if (w) {
335  CSingleDbxref_SubPanel* singlexref_panel = dynamic_cast<CSingleDbxref_SubPanel*> (w);
336  if (singlexref_panel) {
337  CRef<CDbtag> tag = singlexref_panel->GetDbtag();
338  if (tag && tag->IsSetDb() && NStr::Equal(tag->GetDb(), "taxon", NStr::eNocase)) {
339  singlexref_panel->GetSize(&row_width, &row_height);
340  removed_pos.push_back(pos);
341  }
342  }
343  }
344  }
345 
346  if ( ! removed_pos.empty()) {
347  for (pos = 0; pos < removed_pos.size(); ++pos) {
348  m_Sizer->GetItem(removed_pos[pos])->DeleteWindows();
349  m_Sizer->Remove(removed_pos[pos]);
350  m_TotalHeight -= row_height;
351  m_NumRows--;
352  m_ScrolledWindow->SetVirtualSize(m_TotalWidth +10, m_TotalHeight);
353  m_ScrolledWindow->FitInside();
354  m_Sizer->Layout();
355  m_ScrolledWindow->Refresh();
356  }
357  Layout();
358  }
359 }
360 
361 /*!
362  * Should we show tooltips?
363  */
364 
366 {
367  return true;
368 }
369 
370 /*!
371  * Get bitmap resources
372  */
373 
374 wxBitmap CDbxrefPanel::GetBitmapResource( const wxString& name )
375 {
376  // Bitmap retrieval
377 ////@begin CDbxrefPanel bitmap retrieval
378  wxUnusedVar(name);
379  return wxNullBitmap;
380 ////@end CDbxrefPanel bitmap retrieval
381 }
382 
383 /*!
384  * Get icon resources
385  */
386 
387 wxIcon CDbxrefPanel::GetIconResource( const wxString& name )
388 {
389  // Icon retrieval
390 ////@begin CDbxrefPanel icon retrieval
391  wxUnusedVar(name);
392  return wxNullIcon;
393 ////@end CDbxrefPanel icon retrieval
394 }
395 
396 
397 static bool s_IsLastRow(wxWindow* wnd, wxSizerItemList& itemList)
398 {
399  bool is_last = false;
400  if (NULL == wnd)
401  return false;
402 
403  for(wxSizerItemList::iterator it = itemList.begin(); it != itemList.end(); ++it) {
404  wxWindow* child = (**it).GetWindow();
405  if (child && child == wnd) {
406  is_last = true;
407  } else {
408  if (is_last) {
409  is_last = false;
410  return is_last;
411  }
412  }
413  }
414 
415  return is_last;
416 }
417 
418 
419 void CDbxrefPanel::AddLastDbxref (wxWindow* link)
420 {
421  // find the row that holds the author to be deleted
422  wxSizerItemList& itemList = m_Sizer->GetChildren();
423 
424  if (s_IsLastRow(link, itemList)) {
426  CRef<CDbtag> last_tag (new CDbtag());
427  m_Xrefs.push_back(last_tag);
428  x_AddRow (last_tag);
429  m_ScrolledWindow->SetVirtualSize(m_TotalWidth + 10, m_TotalHeight);
430  m_ScrolledWindow->SetScrollRate(0, m_ScrollRate);
431  m_ScrolledWindow->FitInside();
432  }
433 }
434 
435 
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxScrolledWindow * m_ScrolledWindow
void ResetDb(void)
Reset Db data member.
Definition: Org_ref_.cpp:70
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:102
END_EVENT_TABLE()
Case insensitive compare.
Definition: ncbistr.hpp:1192
void ResetDbxref(void)
Reset Dbxref data member.
Definition: Seq_feat_.cpp:188
CSerialObject * m_Object
bool Create(wxWindow *parent, wxWindowID id=ID_CDBXREFPANEL, const wxString &caption=_("DbxrefPanel"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:219
#define NULL
Definition: ncbistd.hpp:225
bool IsSetDbxref(void) const
support for xref to other databases Check if a value has been assigned to Dbxref data member...
Definition: Seq_feat_.hpp:1304
USING_SCOPE(objects)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:795
void x_UpdateXrefs()
void DeleteTaxonRef()
#define VECTOR_ERASE(Var, Cont)
Use this macro inside body of ERASE_ITERATE cycle to erase from vector-like container.
Definition: ncbimisc.hpp:832
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
vector< CRef< objects::CDbtag > > m_Xrefs
const char * tag
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
virtual bool TransferDataFromWindow()
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void CreateControls()
Creates the controls and sizers.
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
static bool s_HasTag(CDbtag &tag)
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
static void Init(void)
Definition: cursor6.c:76
int size
void AddLastDbxref(wxWindow *link)
const TDb & GetDb(void) const
Get the Db member data.
Definition: Org_ref_.hpp:475
void PopulateDbxrefs(objects::CSeq_feat &seq_feat)
TDbxref & SetDbxref(void)
Assign a value to Dbxref data member.
Definition: Seq_feat_.hpp:1322
~CDbxrefPanel()
Destructor.
Base class for all serializable objects.
Definition: serialbase.hpp:149
#define _(proto)
Definition: ct_nlmzip_i.h:78
CDbxrefPanel()
Constructors.
#define ERASE_ITERATE(Type, Var, Cont)
Non-constant version with ability to erase current element, if container permits. ...
Definition: ncbimisc.hpp:823
bool IsSetDb(void) const
name of database or system Check if a value has been assigned to Db data member.
Definition: Dbtag_.hpp:207
vector< CRef< CDbtag > > TDb
Definition: Org_ref_.hpp:101
const TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:259
namespace ncbi::objects::
Definition: Seq_feat.hpp:56
const TDbxref & GetDbxref(void) const
Get the Dbxref member data.
Definition: Seq_feat_.hpp:1316
bool IsSetDb(void) const
ids in taxonomic or culture dbases Check if a value has been assigned to Db data member.
Definition: Org_ref_.hpp:463
virtual bool TransferDataToWindow()
wxWindow * x_AddRow(CRef< objects::CDbtag > tag)
static bool s_IsLastRow(wxWindow *wnd, wxSizerItemList &itemList)
bool IsSetTag(void) const
appropriate tag Check if a value has been assigned to Tag data member.
Definition: Dbtag_.hpp:247
static bool Equal(const CTempString str, SIZE_TYPE pos, SIZE_TYPE n, const char *pattern, ECase use_case=eCase)
Test for equality of a substring with a pattern.
Definition: ncbistr.hpp:5113
void Init()
Initialises member variables.
Definition: Dbtag.hpp:52
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
static bool ShowToolTips()
Should we show tooltips?
TDb & SetDb(void)
Assign a value to Db data member.
Definition: Org_ref_.hpp:481
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
CRef< objects::CDbtag > GetDbtag()
wxBoxSizer * m_Sizer
Modified on Thu May 24 13:02:52 2018 by modify_doxy.py rev. 546573