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

Go to the SVN repository for this file.

1 /* $Id: convert_set_type_dlg.cpp 37014 2016-11-25 15:32:09Z filippov $
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 #include "wx/imaglist.h"
35 ////@end includes
36 
37 #include <objmgr/seqdesc_ci.hpp>
43 
44 #include <wx/sizer.h>
45 #include <wx/button.h>
46 
47 ////@begin XPM images
48 ////@end XPM images
49 
51 
53 
54 /*!
55  * CConvertSetTypeDlg type definition
56  */
57 
58 IMPLEMENT_DYNAMIC_CLASS( CConvertSetTypeDlg, wxDialog )
59 
60 
61 /*!
62  * CConvertSetTypeDlg event table definition
63  */
64 
65 BEGIN_EVENT_TABLE( CConvertSetTypeDlg, wxDialog )
66 
67 ////@begin CConvertSetTypeDlg event table entries
69 
70  EVT_BUTTON( wxID_OK, CConvertSetTypeDlg::OnOkClick )
71 
72 ////@end CConvertSetTypeDlg event table entries
73 
75 
76 
77 /*!
78  * CConvertSetTypeDlg constructors
79  */
80 
82 {
83  Init();
84 }
85 
86 CConvertSetTypeDlg::CConvertSetTypeDlg( wxWindow* parent, const CBioseq_set& set, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
87 {
88  m_Set.Reset(new CBioseq_set());
89  m_Set->Assign(set);
90  Init();
91  Create(parent, id, caption, pos, size, style);
92 }
93 
94 
95 /*!
96  * CConvertSetTypeDlg creator
97  */
98 
99 bool CConvertSetTypeDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
100 {
101 ////@begin CConvertSetTypeDlg creation
102  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
103  wxDialog::Create( parent, id, caption, pos, size, style );
104 
105  CreateControls();
106  if (GetSizer())
107  {
108  GetSizer()->SetSizeHints(this);
109  }
110  Centre();
111 ////@end CConvertSetTypeDlg creation
112  return true;
113 }
114 
115 
116 /*!
117  * CConvertSetTypeDlg destructor
118  */
119 
121 {
122 ////@begin CConvertSetTypeDlg destruction
123 ////@end CConvertSetTypeDlg destruction
124 }
125 
126 
127 /*!
128  * Member initialisation
129  */
130 
132 {
133 ////@begin CConvertSetTypeDlg member initialisation
134  m_Tree = NULL;
136 ////@end CConvertSetTypeDlg member initialisation
137 }
138 
139 
140 /*!
141  * Control creation for CConvertSetTypeDlg
142  */
143 
145 {
146 ////@begin CConvertSetTypeDlg content construction
147  CConvertSetTypeDlg* itemDialog1 = this;
148 
149  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
150  itemDialog1->SetSizer(itemBoxSizer2);
151 
152  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
153  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
154 
155  m_Tree = new wxTreeCtrl( itemDialog1, ID_TREEBOOK, wxDefaultPosition, wxSize(300, 300), wxTR_SINGLE );
156  itemBoxSizer3->Add(m_Tree, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
157 
158  m_ClassChoice = new CSetClassPanel( itemDialog1, ID_WINDOW8, wxDefaultPosition, wxSize(100, 100), 0 );
159  itemBoxSizer2->Add(m_ClassChoice, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
160 
161  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
162  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
163 
164  wxButton* itemButton7 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
165  itemBoxSizer6->Add(itemButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
166 
167  wxButton* itemButton8 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
168  itemBoxSizer6->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
169 
170 ////@end CConvertSetTypeDlg content construction
171 
172  objects::CBioseq_set::EClass class_type = m_Set->IsSetClass() ? m_Set->GetClass() : CBioseq_set::eClass_not_set;
173  wxTreeItemId root = m_Tree->AddRoot(ToWxString(CSetClassPanel::GetClassName(class_type)));
174  m_ItemSets.push_back(TItemSet(root, m_Set.GetPointer()));
175  m_ClassChoice->SetClass(class_type);
176  if (m_Set->IsSetSeq_set()) {
177  NON_CONST_ITERATE(CBioseq_set::TSeq_set, it, m_Set->SetSeq_set()) {
178  if ((*it)->IsSet()) {
179  x_AddSet((*it)->SetSet(), root);
180  }
181  }
182  }
183  m_Tree->ExpandAll();
184 }
185 
186 
187 void CConvertSetTypeDlg::x_AddSet(objects::CBioseq_set& set, wxTreeItemId parent)
188 {
189  objects::CBioseq_set::EClass class_type = set.IsSetClass() ? set.GetClass() : CBioseq_set::eClass_not_set;
190 // CSetClassPanel* pnl = new CSetClassPanel(this);
191 // pnl->SetClass(class_type);
192  wxTreeItemId this_node = m_Tree->AppendItem(parent, ToWxString(CSetClassPanel::GetClassName(class_type)));
193  m_ItemSets.push_back(TItemSet(this_node, &set));
194  m_ClassChoice->SetClass(class_type);
195  if (set.IsSetSeq_set()) {
196  NON_CONST_ITERATE(CBioseq_set::TSeq_set, it, set.SetSeq_set()) {
197  if ((*it)->IsSet()) {
198  x_AddSet((*it)->SetSet(), this_node);
199  }
200  }
201  }
202 }
203 
204 
205 /*!
206  * Should we show tooltips?
207  */
208 
210 {
211  return true;
212 }
213 
214 /*!
215  * Get bitmap resources
216  */
217 
218 wxBitmap CConvertSetTypeDlg::GetBitmapResource( const wxString& name )
219 {
220  // Bitmap retrieval
221 ////@begin CConvertSetTypeDlg bitmap retrieval
222  wxUnusedVar(name);
223  return wxNullBitmap;
224 ////@end CConvertSetTypeDlg bitmap retrieval
225 }
226 
227 /*!
228  * Get icon resources
229  */
230 
231 wxIcon CConvertSetTypeDlg::GetIconResource( const wxString& name )
232 {
233  // Icon retrieval
234 ////@begin CConvertSetTypeDlg icon retrieval
235  wxUnusedVar(name);
236  return wxNullIcon;
237 ////@end CConvertSetTypeDlg icon retrieval
238 }
239 
240 
241 /*!
242  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
243  */
244 
245 void CConvertSetTypeDlg::OnOkClick( wxCommandEvent& event )
246 {
247 ////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK in CConvertSetTypeDlg.
248  // Before editing this code, remove the block markers.
249  event.Skip();
250 ////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK in CConvertSetTypeDlg.
251 }
252 
253 
254 
255 /*!
256  * wxEVT_COMMAND_TREE_SEL_CHANGED event handler for ID_TREEBOOK
257  */
258 
260 {
261  wxTreeItemId id = event.GetItem();
262  CBioseq_set &bset = x_GetSetFromId(id);
264  m_ClassChoice->SetClass(class_type);
265 }
266 
267 
269 {
270  wxTreeItemId id = m_Tree->GetSelection();
271  CBioseq_set &bset = x_GetSetFromId(id);
272 
273  CBioseq_set::EClass old_class = bset.GetClass();
274  CBioseq_set::EClass class_type = m_ClassChoice->GetClass();
275 
276  if (old_class == CBioseq_set::eClass_genbank && bset.IsSetSeq_set() && !bset.GetSeq_set().empty() &&
277  bset.GetSeq_set().front()->IsSet() && bset.GetSeq_set().front()->GetSet().GetClass() != CBioseq_set::eClass_nuc_prot )
278  {
280  {
281  (*it)->SetSet().SetClass(class_type);
282  wxTreeItemId sub_id = x_GetIdFromSet(&(*it)->SetSet());
283  m_Tree->SetItemText(sub_id, ToWxString(CSetClassPanel::GetClassName(class_type)));
284  }
285  }
286  else
287  {
288  bset.SetClass(class_type);
289  m_Tree->SetItemText(id, ToWxString(CSetClassPanel::GetClassName(class_type)));
290  }
291 }
292 
293 
295 {
296  for (size_t i = 0; i < m_ItemSets.size(); i++) {
297  if (m_ItemSets[i].first == id) {
298  return *m_ItemSets[i].second;
299  }
300  }
301  return *m_Set;
302 }
303 
305 {
306  wxTreeItemId id;
307  for (size_t i = 0; i < m_ItemSets.size(); i++) {
308  if (m_ItemSets[i].second == bset) {
309  id = m_ItemSets[i].first;
310  }
311  }
312  return id;
313 }
314 
315 
317  const objects::CBioseq_set& orig,
318  const objects::CBioseq_set& new_set,
319  bool& error)
320 {
321  CRef<CCmdComposite> cmd(new CCmdComposite("Change Set Class"));
322  bool any = false;
323 
324  if (new_set.IsSetClass() &&
325  (!orig.IsSetClass() || orig.GetClass() != new_set.GetClass())) {
327  CRef<CCmdChangeSetClass> sub(new CCmdChangeSetClass(bh, new_set.GetClass()));
328  cmd->AddCommand(*sub);
329  if (!CBioseq_set::NeedsDocsumTitle(new_set.GetClass()))
330  {
332  for (CSeqdesc_CI desc(seh, CSeqdesc::e_Title, 1); desc; ++desc)
333  {
334  CIRef<IEditCommand> cmdDelDesc(new CCmdDelDesc(seh, *desc));
335  cmd->AddCommand(*cmdDelDesc);
336  }
337  }
338  any = true;
339  }
340 
341  if (m_Set->IsSetSeq_set()) {
342  if (orig.IsSetSeq_set()) {
343  CBioseq_set::TSeq_set::const_iterator orig_i = orig.GetSeq_set().begin();
344  CBioseq_set::TSeq_set::const_iterator new_i = new_set.GetSeq_set().begin();
345  while (orig_i != orig.GetSeq_set().end() &&
346  new_i != new_set.GetSeq_set().end()) {
347  if ((*orig_i)->IsSet()) {
348  if ((*new_i)->IsSet()) {
349  CRef<CCmdComposite> sub = GetCommand(scope,
350  (*orig_i)->GetSet(),
351  (*new_i)->GetSet(),
352  error);
353  if (error) {
354  break;
355  } else if (sub) {
356  cmd->AddCommand(*sub);
357  any = true;
358  }
359  } else {
360  // sets don't match up
361  error = true;
362  break;
363  }
364  } else if ((*new_i)->IsSet()) {
365  // sets don't match up
366  error = true;
367  break;
368  }
369  orig_i++;
370  new_i++;
371  }
372  if (orig_i != orig.GetSeq_set().end() || new_i != new_set.GetSeq_set().end()) {
373  // sets don't match up
374  error = true;
375  }
376  } else {
377  // sets don't match up
378  error = true;
379  }
380  } else if (orig.IsSetSeq_set()) {
381  // sets don't match up
382  error = true;
383  }
384 
385  if (!any || error) {
386  cmd.Reset(NULL);
387  }
388  return cmd;
389 }
390 
391 
392 CRef<CCmdComposite> CConvertSetTypeDlg::GetCommand(CScope& scope, const objects::CBioseq_set& orig, bool& error)
393 {
394  error = false;
395  return GetCommand(scope, orig, *m_Set, error);
396 }
397 
398 
CBioseq_set_Handle –.
bool NeedsDocsumTitle() const
Definition: Bioseq_set.cpp:343
wxTreeItemId x_GetIdFromSet(objects::CBioseq_set *set)
static bool ShowToolTips()
Should we show tooltips?
void OnOkClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
CRef< objects::CBioseq_set > m_Set
void x_AddSet(objects::CBioseq_set &set, wxTreeItemId parent)
pair< wxTreeItemId, objects::CBioseq_set * > TItemSet
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=10420, const wxString &caption=_("Convert Set Type"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
objects::CBioseq_set & x_GetSetFromId(wxTreeItemId id)
void OnTreebookSelChanged(wxTreeEvent &event)
wxEVT_COMMAND_TREE_SEL_CHANGED event handler for ID_TREEBOOK
CSetClassPanel * m_ClassChoice
CRef< CCmdComposite > GetCommand(objects::CScope &scope, const objects::CBioseq_set &orig, bool &error)
void Init()
Initialises member variables.
vector< TItemSet > m_ItemSets
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
CConvertSetTypeDlg()
Constructors.
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
objects::CBioseq_set::EClass GetClass()
static string GetClassName(objects::CBioseq_set::TClass class_type)
void SetClass(objects::CBioseq_set::EClass class_type)
Definition: set.hpp:45
USING_SCOPE(ncbi::objects)
#define ID_WINDOW8
#define ID_TREEBOOK
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
CBioseq_set_Handle GetBioseq_setHandle(const CBioseq_set &seqset, EMissing action=eMissing_Default)
Definition: scope.cpp:176
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
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
bool IsSetClass(void) const
Check if a value has been assigned to Class data member.
TClass GetClass(void) const
Get the Class member data.
bool IsSetSeq_set(void) const
Check if a value has been assigned to Seq_set data member.
const TSeq_set & GetSeq_set(void) const
Get the Seq_set member data.
void SetClass(TClass value)
Assign a value to Class data member.
list< CRef< CSeq_entry > > TSeq_set
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
@ eClass_genbank
converted genbank
@ e_Title
a title for this sequence
Definition: Seqdesc_.hpp:115
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sat Feb 24 07:47:09 2024 by modify_doxy.py rev. 669887