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

Go to the SVN repository for this file.

1 /* $Id: feature_create_dlg.cpp 43197 2019-05-26 01:34:33Z 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: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <wx/bitmap.h>
33 #include <wx/icon.h>
34 #include <wx/sizer.h>
35 #include <wx/stattext.h>
36 #include <wx/statbox.h>
37 #include <wx/button.h>
38 #include <wx/dialog.h>
39 #include <wx/srchctrl.h>
40 #include <wx/choice.h>
41 #include <wx/grid.h>
42 
49 
50 
51 ////@begin includes
52 ////@end includes
53 
56 
57 ////@begin XPM images
58 ////@end XPM images
59 
62 
63 
64 /*!
65  * CFeatureCreateDialog type definition
66  */
67 
68 IMPLEMENT_DYNAMIC_CLASS( CFeatureCreateDialog, wxDialog )
69 
70 
71 /*!
72  * CFeatureCreateDialog event table definition
73  */
74 
75 BEGIN_EVENT_TABLE( CFeatureCreateDialog, wxDialog )
76  EVT_CHOICE(ID_CHOICE6, CFeatureCreateDialog::OnFeatureTypeChanged)
78 
79 
80 /*!
81  * CFeatureCreateDialog constructors
82  */
83 
85 {
86  Init();
87 }
88 
89 CFeatureCreateDialog::CFeatureCreateDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90 {
91  Init();
92  Create(parent, id, caption, pos, size, style);
93 }
94 
95 
96 /*!
97  * CFeatureCreateDialog creator
98  */
99 
100 bool CFeatureCreateDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
101 {
102 ////@begin CFeatureCreateDialog creation
103  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
104  wxDialog::Create( parent, id, caption, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CFeatureCreateDialog creation
113  return true;
114 }
115 
116 
117 /*!
118  * CFeatureCreateDialog destructor
119  */
120 
122 {
123 ////@begin CFeatureCreateDialog destruction
124 ////@end CFeatureCreateDialog destruction
125 }
126 
127 
128 /*!
129  * Member initialisation
130  */
131 
133 {
134 ////@begin CFeatureCreateDialog member initialisation
135 ////@end CFeatureCreateDialog member initialisation
136  m_pIn = NULL;
137  m_pOut = NULL;
138  m_pFeatType = NULL;
139  m_pQualifiers = NULL;
140 }
141 
142 
143 /*!
144  * Control creation for CFeatureCreateDialog
145  */
146 
148 {
149 ////@begin CFeatureCreateDialog content construction
150  CFeatureCreateDialog* itemDialog1 = this;
151 
152  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
153  itemDialog1->SetSizer(itemBoxSizer2);
154 
155  wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
156  itemBoxSizer2->Add(itemFlexGridSizer3, 1, wxGROW|wxALL, 5);
157 
158  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Feature Type"), wxDefaultPosition, wxDefaultSize, 0 );
159  itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
160 
161  wxArrayString itemChoice5Strings;
162  wxChoice* itemChoice5 = new wxChoice( itemDialog1, ID_CHOICE6, wxDefaultPosition, wxDefaultSize, itemChoice5Strings, 0 );
163  itemFlexGridSizer3->Add(itemChoice5, 1, wxGROW|wxALIGN_TOP|wxALL, 5);
164 
165  wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("Label"), wxDefaultPosition, wxDefaultSize, 0 );
166  itemFlexGridSizer3->Add(itemStaticText6, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
167 
168  wxTextCtrl* itemTextCtrl7 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
169  itemFlexGridSizer3->Add(itemTextCtrl7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
170 
171  wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Comment"), wxDefaultPosition, wxDefaultSize, 0 );
172  itemFlexGridSizer3->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  wxTextCtrl* itemTextCtrl9 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxSize(-1, 50), wxTE_MULTILINE );
175  itemFlexGridSizer3->Add(itemTextCtrl9, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
176 
177  itemFlexGridSizer3->AddGrowableCol(1);
178 
179  wxStaticBox* itemStaticBoxSizer10Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Qualifiers"));
180  wxStaticBoxSizer* itemStaticBoxSizer10 = new wxStaticBoxSizer(itemStaticBoxSizer10Static, wxHORIZONTAL);
181  itemBoxSizer2->Add(itemStaticBoxSizer10, 0, wxGROW|wxALL, 5);
182 
183  wxGrid* itemGrid11 = new wxGrid( itemDialog1, ID_GRID1, wxDefaultPosition, wxSize(250, 200), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
184  itemGrid11->SetDefaultColSize(25);
185  itemGrid11->SetDefaultRowSize(25);
186  itemGrid11->SetColLabelSize(25);
187  itemGrid11->SetRowLabelSize(50);
188  itemGrid11->CreateGrid(1, 2, wxGrid::wxGridSelectCells);
189  itemStaticBoxSizer10->Add(itemGrid11, 1, wxGROW|wxALL, 5);
190 
191  wxStaticLine* itemStaticLine12 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
192  itemBoxSizer2->Add(itemStaticLine12, 0, wxGROW|wxALL, 5);
193 
194  wxStdDialogButtonSizer* itemStdDialogButtonSizer13 = new wxStdDialogButtonSizer;
195 
196  itemBoxSizer2->Add(itemStdDialogButtonSizer13, 0, wxALIGN_RIGHT|wxALL, 5);
197  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
198  itemStdDialogButtonSizer13->AddButton(itemButton14);
199 
200  wxButton* itemButton15 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
201  itemStdDialogButtonSizer13->AddButton(itemButton15);
202 
203  itemStdDialogButtonSizer13->Realize();
204 
205  // Set validators
206  itemTextCtrl7->SetValidator( wxTextValidator(wxFILTER_NONE, & m_Label) );
207  itemTextCtrl9->SetValidator( wxTextValidator(wxFILTER_NONE, & m_Comments) );
208 ////@end CFeatureCreateDialog content construction
209 
210  itemGrid11->SetDefaultColSize(110);
211  itemGrid11->SetDefaultRowSize(20);
212  itemGrid11->SetColLabelSize(20);
213  itemGrid11->SetRowLabelSize(0);
214 
215  m_pFeatType = itemChoice5;
216  m_pQualifiers = itemGrid11;
217 
218  m_pQualifiers->SetColLabelValue(0, wxT("Name"));
219  m_pQualifiers->SetColLabelValue(1, wxT("Value"));
220 
221 }
222 
223 
224 /*!
225  * Should we show tooltips?
226  */
227 
229 {
230  return true;
231 }
232 
233 /*!
234  * Get bitmap resources
235  */
236 
237 wxBitmap CFeatureCreateDialog::GetBitmapResource( const wxString& name )
238 {
239  // Bitmap retrieval
240 ////@begin CFeatureCreateDialog bitmap retrieval
241  wxUnusedVar(name);
242  return wxNullBitmap;
243 ////@end CFeatureCreateDialog bitmap retrieval
244 }
245 
246 /*!
247  * Get icon resources
248  */
249 
250 wxIcon CFeatureCreateDialog::GetIconResource( const wxString& name )
251 {
252  // Icon retrieval
253 ////@begin CFeatureCreateDialog icon retrieval
254  wxUnusedVar(name);
255  return wxNullIcon;
256 ////@end CFeatureCreateDialog icon retrieval
257 }
258 
260 {
262 }
263 
264 
265 
267 {
268  const CFeatList* feat_list = CSeqFeatData::GetFeatList();
269  vector <int> allowed;
270  ITERATE(vector<CSeqFeatData::ESubtype>, subt, m_Options){
271  allowed.push_back(*subt);
272  }
273 
274  int selected = 0;
275  ITERATE(CFeatList, ft_it, *feat_list) {
276  const CFeatListItem& item = *ft_it;
277  string desc = item.GetDescription();
278  int subt = item.GetSubtype();
279  if (find(allowed.begin(), allowed.end(), subt) != allowed.end()){
280  int idx = m_pFeatType->Append(ToWxString(desc),
281  new int(item.GetSubtype()));
282  if (item.GetSubtype() == m_Selected) {
283  selected = idx;
284  }
285  }
286  }
287  m_pFeatType->SetSelection(selected);
288 }
289 
291 {
292  int feat_sel;
293  if (m_pFeatType && ((feat_sel=m_pFeatType->GetSelection())!=wxNOT_FOUND)){
294 
295  if (m_pQualifiers->GetNumberRows()) {
296  m_pQualifiers->DeleteRows(0, m_pQualifiers->GetNumberRows());
297  }
298 
299  int subtype = *((int*)m_pFeatType->GetClientData(feat_sel));
300  const auto& quals = CSeqFeatData::GetLegalQualifiers
301  ((CSeqFeatData::ESubtype)subtype);
302 
303  for (auto q : quals) {
304  string qual_name = CSeqFeatData::GetQualifierAsString(q);
305  m_pQualifiers->AppendRows();
306  m_pQualifiers->SetCellValue(m_pQualifiers->GetNumberRows() - 1, 0,
307  ToWxString(qual_name));
308  m_pQualifiers->SetReadOnly(m_pQualifiers->GetNumberRows() - 1, 0);
309  }
310  }
311 
312 }
313 
315 {
316  m_pIn = &in;
317  m_pOut = &out;
318 }
319 
320 void CFeatureCreateDialog::SetConstraints(vector <CSeqFeatData::ESubtype> & options,
321  CSeqFeatData::ESubtype selected)
322 {
323  m_Options = options;
324  m_Selected = selected;
325 }
326 
328 {
329  x_InitFeatTypes();
331  return wxDialog::TransferDataToWindow();
332 }
333 
335 {
336  if (m_pIn && m_pOut && m_pFeatType) {
338  // obtaining location
339  const CSeq_loc * seq_loc =
340  dynamic_cast<const CSeq_loc*>(cso->object.GetPointer());
341 
342  int feat_sel;
343  if ((feat_sel=m_pFeatType->GetSelection())==wxNOT_FOUND) continue;
344 
345 
346 
347  if (seq_loc) {
348  // preparing feature
349  CRef<CSeq_feat> feat(new CSeq_feat);
350  feat->SetLocation(*const_cast<CSeq_loc*>(seq_loc));
351 
352  int subtype = *((int*)m_pFeatType->GetClientData(feat_sel));
353  switch(subtype) {
354  case CSeqFeatData::eSubtype_gene: feat->SetData().SetGene(); break;
357  case CSeqFeatData::eSubtype_rRNA: feat->SetData().SetRna(); break;
358  case CSeqFeatData::eSubtype_exon: feat->SetData().SetRegion(); break;
359  case CSeqFeatData::eSubtype_region: feat->SetData().SetRegion(); break;
360  case CSeqFeatData::eSubtype_site: feat->SetData().SetRsite(); break;
361  case CSeqFeatData::eSubtype_imp: feat->SetData().SetImp(); break;
364  feat->SetData().SetCdregion().SetOrf(true);
365  feat->SetData().SetCdregion().SetFrame(CCdregion::eFrame_one);
366  }
367  }
368 
369  // add non-empty qualifiers
370  int nmb_rows = m_pQualifiers->GetNumberRows();
371  for (int i=0; i<nmb_rows; i++) {
372  string qual_name = ToStdString(m_pQualifiers->GetCellValue(i, 0));
373  string qual_value = ToStdString(m_pQualifiers->GetCellValue(i, 1));
374 
375  if (!qual_value.empty()){
376  feat->AddQualifier(qual_name, qual_value);
377  }
378  }
379 
380  m_pOut->push_back(SConstScopedObject(feat,
381  const_cast<CScope*>(cso->scope.GetPointer())));
382  }
383  }
384  }
385  return wxDialog::TransferDataFromWindow();
386 }
387 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CFeatListItem - basic configuration data for one "feature" type.
int GetSubtype() const
string GetDescription() const
CConfigurableItems - a static list of items that can be configured.
bool Create(wxWindow *parent, wxWindowID id=ID_CFEATURECREATEDIALOG, const wxString &caption=_("Feature Create Dialog"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(300, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
vector< objects::CSeqFeatData::ESubtype > m_Options
void SetIO(TConstScopedObjects &in, TConstScopedObjects &out)
objects::CSeqFeatData::ESubtype m_Selected
~CFeatureCreateDialog()
Destructor.
void OnFeatureTypeChanged(wxCommandEvent &event)
CFeatureCreateDialog()
Constructors.
static bool ShowToolTips()
Should we show tooltips?
virtual bool TransferDataToWindow()
TConstScopedObjects * m_pOut
void SetConstraints(vector< objects::CSeqFeatData::ESubtype > &options, objects::CSeqFeatData::ESubtype selected)
virtual bool TransferDataFromWindow()
TConstScopedObjects * m_pIn
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
CScope –.
Definition: scope.hpp:92
const TLegalQualifiers & GetLegalQualifiers(void) const
Get a list of all the legal qualifiers for the feature.
static const CFeatList * GetFeatList()
static CTempString GetQualifierAsString(EQualifier qual)
Convert a qualifier from an enumerated value to a string representation or empty if not found.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
void AddQualifier(const string &qual_name, const string &qual_val)
Add a qualifier to this feature.
Definition: Seq_feat.cpp:291
#define _(proto)
Definition: ct_nlmzip_i.h:78
std::ofstream out("events_result.xml")
main entry point for tests
USING_SCOPE(objects)
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
void SetExp_ev(TExp_ev value)
Assign a value to Exp_ev data member.
Definition: Seq_feat_.hpp:1277
@ eExp_ev_not_experimental
similarity, pattern, etc
Definition: Seq_feat_.hpp:103
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
std::istream & in(std::istream &in_, double &x_)
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:57:35 2024 by modify_doxy.py rev. 669887