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

Go to the SVN repository for this file.

1 /* $Id: singlegbqual_subpanel.cpp 37632 2017-01-30 19:34:30Z 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: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
33 
34 ////@begin includes
35 ////@end includes
36 
38 #include "gbqualtext_panel.hpp"
39 #include "twopartqual_panel.hpp"
41 #include "rptunitrange_panel.hpp"
43 #include "rpttype_panel.hpp"
45 
46 #include <wx/bitmap.h>
47 #include <wx/icon.h>
48 #include <wx/choice.h>
49 #include <wx/textctrl.h>
50 #include <wx/stattext.h>
51 
54 
55 ////@begin XPM images
56 ////@end XPM images
57 
58 
59 /*!
60  * CSingleGbQualSubPanel type definition
61  */
62 
63 IMPLEMENT_DYNAMIC_CLASS( CSingleGbQualSubPanel, wxPanel )
64 
65 
66 /*!
67  * CSingleGbQualSubPanel event table definition
68  */
69 
70 BEGIN_EVENT_TABLE( CSingleGbQualSubPanel, wxPanel )
71 
72 ////@begin CSingleGbQualSubPanel event table entries
73 ////@end CSingleGbQualSubPanel event table entries
74 
76 
77 
78 /*!
79  * CSingleGbQualSubPanel constructors
80  */
81 
83 {
84  Init();
85 }
86 
87 CSingleGbQualSubPanel::CSingleGbQualSubPanel( wxWindow* parent, CGb_qual& qual, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
88 : m_Qual(0)
89 {
90  Init();
91  m_Qual = new CGb_qual();
92  m_Qual->Assign(qual);
93  Create(parent, id, caption, pos, size, style);
94 }
95 
96 
97 /*!
98  * SimpleGbQualSubPanel creator
99  */
100 
101 bool CSingleGbQualSubPanel::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
102 {
103 ////@begin CSingleGbQualSubPanel creation
104  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
105  wxPanel::Create( parent, id, pos, size, style );
106 
107  CreateControls();
108  if (GetSizer())
109  {
110  GetSizer()->SetSizeHints(this);
111  }
112  Centre();
113 ////@end CSingleGbQualSubPanel creation
114  return true;
115 }
116 
117 
118 /*!
119  * CSingleGbQualSubPanel destructor
120  */
121 
123 {
124 ////@begin CSingleGbQualSubPanel destruction
125 ////@end CSingleGbQualSubPanel destruction
126 }
127 
128 
129 /*!
130  * Member initialisation
131  */
132 
134 {
135 ////@begin CSingleGbQualSubPanel member initialisation
136  m_TheSizer = NULL;
137  m_KeyCtrl = NULL;
138 ////@end CSingleGbQualSubPanel member initialisation
139 }
140 
141 
142 /*!
143  * Control creation for SimpleGbQualSubPanel
144  */
145 
147 {
148 ////@begin CSingleGbQualSubPanel content construction
149  CSingleGbQualSubPanel* itemPanel1 = this;
150 
151  m_TheSizer = new wxBoxSizer(wxHORIZONTAL);
152  itemPanel1->SetSizer(m_TheSizer);
153 
154  m_KeyCtrl = new wxStaticText( itemPanel1, wxID_STATIC, _("Static text"), wxDefaultPosition, wxSize(160, -1), 0 );
155  m_TheSizer->Add(m_KeyCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
156 
157 ////@end CSingleGbQualSubPanel content construction
158 
159  // for now, only text
160  // later, implement specialized editors
161 
162  string key = m_Qual->GetQual();
163  if ( NStr::EqualNocase(key, "mobile_element") )
164  {
165  key = "mobile_element_type";
166  m_Qual->SetQual(key);
167  }
168 
169  key = NStr::ReplaceInPlace(key, "_", "-");
170  m_KeyCtrl->SetLabel(ToWxString(key));
171  string val;
172  if (m_Qual->IsSetVal()) {
173  val = m_Qual->GetVal();
174  }
175 
176  if (NStr::EqualNocase(key, "mobile-element-type") || NStr::EqualNocase(key, "satellite")) {
177  CTwoPartQualPanel* ctrl = new CTwoPartQualPanel(this);
178  m_ValueCtrl = ctrl;
179  if (NStr::EqualNocase(key, "mobile-element-type")) {
180  vector<string> choices;
181  choices.push_back("insertion sequence");
182  choices.push_back("retrotransposon");
183  choices.push_back("non-LTR retrotransposon");
184  choices.push_back("transposon");
185  choices.push_back("integron");
186  choices.push_back("other");
187  choices.push_back("SINE");
188  choices.push_back("MITE");
189  choices.push_back("LINE");
190  ctrl->SetControlledList(choices);
191  } else if (NStr::EqualNocase(key, "satellite")) {
192  vector<string> choices;
193  choices.push_back("satellite");
194  choices.push_back("microsatellite");
195  choices.push_back("minisatellite");
196  ctrl->SetControlledList(choices);
197  }
198  } else if (NStr::EqualNocase(key, "regulatory-class")) {
200  m_ValueCtrl = ctrl;
201  vector<string> choices = CSeqFeatData::GetRegulatoryClassList();
202  ctrl->SetControlledList(choices);
203  } else if (NStr::EqualNocase(key, "recombination-class")) {
205  m_ValueCtrl = ctrl;
206  vector<string> choices;
208  ITERATE(CGb_qual::TLegalRecombinationClassSet, it, recomb_classes) {
209  choices.push_back(*it);
210  }
211  ctrl->SetControlledList(choices);
212  } else if (NStr::EqualNocase(key, "rpt-unit-range")) {
213  CRptUnitRangePanel* ctrl = new CRptUnitRangePanel(this);
214  m_ValueCtrl = ctrl;
215  } else if (NStr::EqualNocase(key, "direction")) {
217  m_ValueCtrl = ctrl;
218  } else if (NStr::EqualNocase(key, "rpt-type") && CRptTypePanel::IsParseable(val)) {
219  CRptTypePanel* ctrl = new CRptTypePanel(this);
220  m_ValueCtrl = ctrl;
221  } else if (NStr::EqualNocase(key, "inference")) {
222  // temporary
223  m_ValueCtrl = new CInferencePanel(this);
224  } else {
225  m_ValueCtrl = new CGBQualTextPanel(itemPanel1);
226  }
227  m_TheSizer->Add(m_ValueCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 0);
228 
229 }
230 
231 
233 {
234  if (!wxPanel::TransferDataToWindow())
235  return false;
236 
237  if (m_Qual->IsSetVal()) {
238  if (m_Qual->IsSetQual() && NStr::Equal(m_Qual->GetQual(), "replace") && m_Qual->GetVal().empty())
239  m_ValueCtrl->SetValue("\"\"");
240  else
241  m_ValueCtrl->SetValue(m_Qual->GetVal());
242  } else {
244  }
245 
246  return true;
247 }
248 
249 
251 {
252  if (!wxPanel::TransferDataFromWindow())
253  return false;
254 
255  string val = m_ValueCtrl->GetValue();
256  if (NStr::IsBlank(val)) {
257  if (m_Qual->IsSetQual() && NStr::Equal(m_Qual->GetQual(), "regulatory")) {
258  m_Qual->SetVal("other");
259  } else {
260  m_Qual->ResetQual();
261  m_Qual->ResetVal();
262  }
263  } else {
264  if (m_Qual->IsSetQual() && NStr::Equal(m_Qual->GetQual(), "replace") && val == "\"\"")
265  m_Qual->SetVal(kEmptyStr);
266  else
267  m_Qual->SetVal(val);
268  }
269  return true;
270 }
271 
272 
274 {
276  if (m_Qual)
277  return m_Qual;
278 
279  return CRef<CGb_qual>();
280 }
281 
283 {
284  m_Qual = qual;
286 }
287 
288 /*!
289  * Should we show tooltips?
290  */
291 
293 {
294  return true;
295 }
296 
297 /*!
298  * Get bitmap resources
299  */
300 
301 wxBitmap CSingleGbQualSubPanel::GetBitmapResource( const wxString& name )
302 {
303  // Bitmap retrieval
304 ////@begin CSingleGbQualSubPanel bitmap retrieval
305  wxUnusedVar(name);
306  return wxNullBitmap;
307 ////@end CSingleGbQualSubPanel bitmap retrieval
308 }
309 
310 /*!
311  * Get icon resources
312  */
313 
314 wxIcon CSingleGbQualSubPanel::GetIconResource( const wxString& name )
315 {
316  // Icon retrieval
317 ////@begin CSingleGbQualSubPanel icon retrieval
318  wxUnusedVar(name);
319  return wxNullIcon;
320 ////@end CSingleGbQualSubPanel icon retrieval
321 }
322 
virtual void SetValue(string val)
void SetControlledList(vector< string > choices)
@Gb_qual.hpp User-defined methods of the data storage class.
Definition: Gb_qual.hpp:61
static const TLegalRecombinationClassSet & GetSetOfLegalRecombinationClassValues(void)
Definition: Gb_qual.cpp:329
static bool IsParseable(const string &val)
static const vector< string > & GetRegulatoryClassList()
CSingleGbQualSubPanel()
Constructors.
void Init()
Initialises member variables.
void SetGbQual(CRef< objects::CGb_qual > &qual)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CFormattedQualPanel * m_ValueCtrl
void CreateControls()
Creates the controls and sizers.
CRef< objects::CGb_qual > GetGbQual()
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=ID_SINGLEGBQUALSUBPANEL, const wxString &caption=_("SingleGbQual SubPanel"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static bool ShowToolTips()
Should we show tooltips?
CRef< objects::CGb_qual > m_Qual
void SetControlledList(vector< string > choices)
#define _(proto)
Definition: ct_nlmzip_i.h:78
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
USING_SCOPE(objects)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Wed Apr 17 13:09:24 2024 by modify_doxy.py rev. 669887