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

Go to the SVN repository for this file.

1 /* $Id: fix_specifichost.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: Andrea Asztalos
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
34 
35 
38 
39 
40 CSpecificHostNode::CSpecificHostNode( CSpecificHostNode* parent, const wxString& current_spechost,
41  const wxString& correction, const wxString& category, const wxString& str_seqid)
42  : m_CurSpechost(current_spechost), m_Corrected(correction),
43  m_Category(category), m_Seqid(str_seqid), m_Container(false)
44 {
45 }
46 
48  : m_CurSpechost(branch), m_Corrected(wxEmptyString), m_Category(wxEmptyString),
49  m_Seqid(wxEmptyString), m_Container(true), m_Parent(parent)
50 {
51 }
52 
54 {
55  // free all the children nodes
56  size_t count = m_Children.GetCount(); // can be replaced by a member function
57  for (size_t n = 0; n < count; ++n) {
58  CSpecificHostNode* child = m_Children[n];
59  delete child;
60  child = NULL;
61  }
62 }
63 
64  /// Implementing CSpecificHostModel
66  {
67  // fill up the model with actual data from the seq_entry
68  m_Root = new CSpecificHostNode( NULL, "Specific Hosts to be Corrected" );
69  // This is not the root itself!
70  // It is the sole child of the actual, invisible root.
71  // special case: when the tool is applied and the model might be empty
72  m_esc = new CSpecificHostNode( m_Root, "Eschericia coli (2)");
73  m_esc->Append(new CSpecificHostNode(m_esc, "Eschericia coli", "Escherichia coli", "Spelling", "lcl|seq1"));
74  m_esc->Append(new CSpecificHostNode(m_esc, "Eschericia coli", "Escherichia coli", "Spelling", "lcl|seq3"));
76 
77  m_hsap = new CSpecificHostNode(NULL, "Homo sapins", "Homo", "Truncation", "lcl|seq5");
79 
80  m_hsup = new CSpecificHostNode(NULL, "Homo supiens", "Homo", "Truncation", "lcl|seq2");
82 
83  m_giraf = new CSpecificHostNode(m_Root, "giraffa giraffa (2)");
84  m_giraf->Append(new CSpecificHostNode(m_giraf, "giraffa giraffa", "Giraffa Giraffa", "Capitalization", "lcl|seq4"));
85  m_giraf->Append(new CSpecificHostNode(m_giraf, "giraffa giraffa", "Giraffa", "Truncation", "lcl|seq9"));
87 
88  m_ver = new CSpecificHostNode(m_Root, "vertebrate", "Unable to suggest correction for", "Unrecognized", "lcl|seq11");
89  m_Root->Append(m_ver);
90 
91  }
92 
93 wxString CSpecificHostModel::GetCurSpechost( const wxDataViewItem& item) const
94 {
95  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
96  if (!node)
97  return wxEmptyString;
98 
99  return node->m_CurSpechost;
100 }
101 
102 wxString CSpecificHostModel::GetCorrection( const wxDataViewItem& item) const
103 {
104  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
105  if (!node)
106  return wxEmptyString;
107 
108  return node->m_Corrected;
109 }
110 wxString CSpecificHostModel::GetCategory( const wxDataViewItem& item) const
111 {
112  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
113  if (!node)
114  return wxEmptyString;
115 
116  return node->m_Category;
117 }
118 wxString CSpecificHostModel::GetSeqId (const wxDataViewItem& item) const
119 {
120  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
121  if (!node) // happens if item.IsOk()==false
122  return wxEmptyString;
123 
124  return node->m_Seqid;
125 }
126 
127 void CSpecificHostModel::AddSpecHostNode (const wxString& current_spechost, const wxString& correction,
128  const wxString& category, const wxString& str_seqid)
129 {
130  _ASSERT(m_Root);
131  CSpecificHostNode* child_node = new CSpecificHostNode(m_Root, current_spechost, correction, category, str_seqid);
132  m_Root->Append(child_node);
133 
134  if (true)
135  {
136  // notify control
137  wxDataViewItem child( (void*) child_node );
138  wxDataViewItem parent( (void*) m_Root );
139  ItemAdded( parent, child );
140  }
141 }
142 
143 void CSpecificHostModel::Delete ( const wxDataViewItem& item)
144 {
145  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
146  if (!node) // happens if item.IsOk()==false
147  return;
148 
149  wxDataViewItem parent( node->GetParent() );
150  if (!parent.IsOk())
151  {
152  //wxASSERT(node == m_Root);
153  //wxLogError( "Cannot remove the root item!" );
154  return;
155  }
156 
157  if (node == m_esc)
158  m_esc = NULL;
159  else if (node == m_hsap)
160  m_hsap = NULL;
161  else if (node == m_hsup)
162  m_hsup = NULL;
163  else if (node == m_ver)
164  m_ver = NULL;
165  else if (node == m_giraf)
166  m_giraf = NULL;
167 
168  node->GetParent()->GetChildren().Remove( node );
169  delete node;
170  node = NULL;
171 
172  // notify control
173  ItemDeleted( parent, item );
174 }
175 
176 int CSpecificHostModel::Compare ( const wxDataViewItem& item1, const wxDataViewItem& item2,
177  unsigned int column, bool ascending) const
178 {
179  _ASSERT(item1.IsOk() && item2.IsOk());
180 
181  if (IsContainer(item1) && IsContainer(item2))
182  {
183  wxVariant value1, value2;
184  GetValue( value1, item1, 0 );
185  GetValue( value2, item2, 0 );
186 
187  wxString str1 = value1.GetString();
188  wxString str2 = value2.GetString();
189  int res = str1.Cmp( str2 );
190  if (res) return res;
191 
192  // items must be different
193  wxUIntPtr litem1 = (wxUIntPtr) item1.GetID();
194  wxUIntPtr litem2 = (wxUIntPtr) item2.GetID();
195 
196  return static_cast<int>(litem1-litem2);
197  }
198 
199  return wxDataViewModel::Compare( item1, item2, column, ascending );
200 }
201 
202 void CSpecificHostModel::GetValue( wxVariant &variant,
203  const wxDataViewItem &item, unsigned int col ) const
204 {
205  _ASSERT(item.IsOk());
206 
207  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
208  switch (col)
209  {
210  case 0:
211  variant = node->m_CurSpechost;
212  break;
213  case 1:
214  variant = node->m_Corrected;
215  break;
216  case 2:
217  variant = node->m_Category;
218  break;
219  case 3:
220  variant = node->m_Seqid;
221  break;
222  default:
223  //wxLogError( "CSpecificHostModel::GetValue: wrong column %d", col );
224  break;
225  }
226 }
227 
228 bool CSpecificHostModel::SetValue( const wxVariant &variant,
229  const wxDataViewItem &item, unsigned int col )
230 { _ASSERT(item.IsOk());
231 
232  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
233  switch (col)
234  {
235  case 0:
236  node->m_CurSpechost = variant.GetString();
237  return true;
238  case 1:
239  node->m_Corrected = variant.GetString();
240  return true;
241  case 2:
242  node->m_Category = variant.GetString();
243  return true;
244  case 3:
245  node->m_Seqid = variant.GetString();
246  return true;
247 
248  default:
249  //wxLogError( "CSpecificHostModel::SetValue: wrong column" );
250  break;
251  }
252  return false;
253 }
254 
255 bool CSpecificHostModel::IsEnabled( const wxDataViewItem &item,
256  unsigned int col ) const
257 {
258  _ASSERT(item.IsOk());
259 
260  //CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
261 
262  return true;
263 }
264 
265 wxDataViewItem CSpecificHostModel::GetParent( const wxDataViewItem &item ) const
266 {
267  if (!item.IsOk())
268  return wxDataViewItem(0);
269 
270  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
271 
272  if (node == m_Root)
273  return wxDataViewItem(0);
274 
275  return wxDataViewItem( (void*) node->GetParent() );
276 }
277 
278 bool CSpecificHostModel::IsContainer( const wxDataViewItem &item ) const
279 {
280  if (!item.IsOk())
281  return true;
282 
283  CSpecificHostNode *node = (CSpecificHostNode*) item.GetID();
284  return node->IsContainer();
285 }
286 
287 unsigned int CSpecificHostModel::GetChildren( const wxDataViewItem &parent, wxDataViewItemArray &array ) const
288 {
289  CSpecificHostNode *node = (CSpecificHostNode*) parent.GetID();
290  if (!node)
291  {
292  array.Add( wxDataViewItem( (void*) m_Root ) );
293  return 1;
294  }
295 
296  if (node == m_esc)
297  {
298  //CSpecificHostModel *model = (CSpecificHostModel*)(const CSpecificHostModel*) this;
299  }
300 
301  if (node->GetChildCount() == 0)
302  {
303  return 0;
304  }
305 
306  unsigned int count = static_cast<unsigned int>(node->GetChildren().GetCount());
307  for (unsigned int pos = 0; pos < count; pos++)
308  {
309  CSpecificHostNode *child = node->GetChildren().Item( pos );
310  array.Add( wxDataViewItem( (void*) child ) );
311  }
312 
313  return count;
314 }
315 
317 
CSpecificHostNode * m_hsup
virtual void GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const
virtual bool IsContainer(const wxDataViewItem &item) const
virtual bool IsEnabled(const wxDataViewItem &item, unsigned int col) const
virtual wxDataViewItem GetParent(const wxDataViewItem &item) const
CSpecificHostNode * m_hsap
CSpecificHostModel()
Implementing CSpecificHostModel.
void AddSpecHostNode(const wxString &current_spechost, const wxString &correction, const wxString &category, const wxString &str_seqid)
CSpecificHostNode * m_giraf
int Compare(const wxDataViewItem &item1, const wxDataViewItem &item2, unsigned int column, bool ascending) const
wxString GetCorrection(const wxDataViewItem &item) const
CSpecificHostNode * m_Root
CSpecificHostNode * m_ver
wxString GetCurSpechost(const wxDataViewItem &item) const
virtual bool SetValue(const wxVariant &variant, const wxDataViewItem &item, unsigned int col)
wxString GetCategory(const wxDataViewItem &item) const
void Delete(const wxDataViewItem &item)
wxString GetSeqId(const wxDataViewItem &item) const
CSpecificHostNode * m_esc
virtual unsigned int GetChildren(const wxDataViewItem &parent, wxDataViewItemArray &array) const
unsigned int GetChildCount() const
CSpecificHostNode * GetParent()
bool IsContainer(void) const
CSpecificHostNodePtrArray & GetChildren()
void Append(CSpecificHostNode *child)
CSpecificHostNode(CSpecificHostNode *parent, const wxString &current_spechost, const wxString &correction, const wxString &category, const wxString &str_seqid)
CSpecificHostNodePtrArray m_Children
USING_SCOPE(objects)
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static const char * column
Definition: stats.c:23
#define NULL
Definition: ncbistd.hpp:225
sequence::ECompare Compare(const CSeq_loc &loc1, const CSeq_loc &loc2, CScope *scope)
Returns the sequence::ECompare containment relationship between CSeq_locs.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
yy_size_t n
#define _ASSERT
Modified on Mon Apr 22 04:01:56 2024 by modify_doxy.py rev. 669887