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

Go to the SVN repository for this file.

1 /* $Id: vcf_column_sel_panel.cpp 46536 2021-06-28 12:37:36Z shkeda $
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 
29 
30 #include <ncbi_pch.hpp>
35 #include <wx/statbox.h>
36 #include <wx/sizer.h>
37 #include <wx/button.h>
38 #include <wx/wupdlock.h>
39 #include <wx/stattext.h>
40 
41 
43 
44 /*!
45  * CVcfColumnSelectionPanel type definition
46  */
47 
48 IMPLEMENT_DYNAMIC_CLASS( CVcfColumnSelectionPanel, wxPanel )
49 
50 
51 /*!
52  * CVcfColumnSelectionPanel event table definition
53  */
54 
55 BEGIN_EVENT_TABLE( CVcfColumnSelectionPanel, wxPanel )
56  EVT_BUTTON(ID_SelectAllINFO, CVcfColumnSelectionPanel::OnSelectAllClick)
57  EVT_BUTTON(ID_DeselectAllINFO, CVcfColumnSelectionPanel::OnDeselectAllClick)
59 
60 
61 /*!
62  * CVcfColumnSelectionPanel constructors
63  */
64 
66 {
67  Init();
68 }
69 
70 CVcfColumnSelectionPanel::CVcfColumnSelectionPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
71 {
72  Init();
73  Create(parent, id, pos, size, style);
74 }
75 
76 
77 /*!
78  * CVcfColumnSelectionPanel creator
79  */
80 
81 bool CVcfColumnSelectionPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
82 {
83 ////@begin CVcfColumnSelectionPanel creation
84  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
85  wxPanel::Create( parent, id, pos, size, style );
86 
88  if (GetSizer())
89  {
90  GetSizer()->SetSizeHints(this);
91  }
92  Centre();
93 ////@end CVcfColumnSelectionPanel creation
94  return true;
95 }
96 
97 
98 /*!
99  * CVcfColumnSelectionPanel destructor
100  */
101 
103 {
104 ////@begin CVcfColumnSelectionPanel destruction
105 ////@end CVcfColumnSelectionPanel destruction
106 }
107 
108 
109 /*!
110  * Member initialisation
111  */
112 
114 {
115 ////@begin CVcfColumnSelectionPanel member initialisation
117 ////@end CVcfColumnSelectionPanel member initialisation
118 
119 }
120 
121 
122 /*!
123  * Control creation for CVcfColumnSelectionPanel
124  */
125 
127 {
128 ////@begin CVcfColumnSelectionPanel content construction
129  CVcfColumnSelectionPanel* itemPanel1 = this;
130 
131  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
132  itemPanel1->SetSizer(itemBoxSizer2);
133 
134  wxStaticText* itemStaticText1 = new wxStaticText( itemPanel1, wxID_STATIC, _("INFO Fields"), wxDefaultPosition, wxDefaultSize, 0 );
135  itemBoxSizer2->Add(itemStaticText1, 0, wxALIGN_LEFT|wxALL, 5);
136 
137  wxArrayString m_InfoSubColsStrings;
138  m_InfoSubCols = new wxCheckedListCtrl( itemPanel1, ID_INFOFIELDSLIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );
139  itemBoxSizer2->Add(m_InfoSubCols, 1, wxGROW|wxALL, 5);
140 
141  wxStaticText* itemStaticText2 = new wxStaticText( itemPanel1, wxID_STATIC, _("Some fields cannot be deselected because they are needed by Genome Workbench in order to display this file."), wxDefaultPosition, wxDefaultSize, 0 );
142  itemBoxSizer2->Add(itemStaticText2, 0, wxGROW|wxLEFT|wxRIGHT, 5);
143 
144  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
145  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxTOP, 5);
146 
147  wxButton* itemButton4 = new wxButton( itemPanel1, ID_SelectAllINFO, _("Select All"), wxDefaultPosition, wxDefaultSize, 0 );
148  itemBoxSizer3->Add(itemButton4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
149 
150  wxButton* itemButton5 = new wxButton( itemPanel1, ID_DeselectAllINFO, _("Deselect All"), wxDefaultPosition, wxDefaultSize, 0 );
151  itemBoxSizer3->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
152 
153 ////@end CVcfColumnSelectionPanel content construction
154  m_InfoSubCols->InsertColumn(0, wxT("Name"));
155  m_InfoSubCols->InsertColumn(1, wxT("Description"));
156 
157 }
158 
159 static
161 {
163  string s = reg.GetString("import_vcf", "mandatory_fields", "");
164  if (s.empty()) {
165  fields = { "SVTYPE", "END", "CIPOS", "CIEND", "SVLEN", "CLNSIG", "CLNREVSTAT", "CLNVC", "CLNVCSO", "MC", "RS", "DBVARID" };
166  } else {
167  vector<string> str_list;
168  NStr::Split(s, ",", str_list);
169  for (auto v : str_list) {
171  if (!v.empty())
172  fields.insert(v);
173 
174  }
175  }
176 
177 }
178 
179 
181 {
182  wxWindowUpdateLocker upd(m_InfoSubCols);
183  m_InfoSubCols->DeleteAllItems();
184 
185  m_FieldData = fields;
186  int row = 0;
187  static wxColour light_gray{ _T("#808080") };
188 
189  set<string> mandatory_fields;
190  s_GetMandatoryFields(mandatory_fields);
191 
192  for (const auto& it : m_FieldData) {
193 
194  // Insert a row
195  wxListItem item;
196  item.SetId(row);
197  m_InfoSubCols->InsertItem(item);
198  bool is_mandatory = mandatory_fields.count(it->m_Name) != 0;
199  if (is_mandatory) {
200  m_InfoSubCols->SetItemImage(row, 3); // CHECK AND DISABLED
201  m_InfoSubCols->SetItemTextColour(row, light_gray);
202  } else {
203  // Column to indicate selected or not
204  m_InfoSubCols->SetChecked(row, it->m_Number != ".");
205  }
206  m_InfoSubCols->SetItem(row, 0, it->m_Name);
207 
208  m_InfoSubCols->SetItem(row, 1, it->m_Description);
209 
210  ++row;
211  }
212  m_InfoSubCols->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER);
213  m_InfoSubCols->SetColumnWidth(1, wxLIST_AUTOSIZE);
214 }
215 
217 {
218  selected.clear();
219  int row = 0;
220  for (const auto& it : m_FieldData) {
221  if (m_InfoSubCols->IsChecked(row)) {
222  selected.insert(it->m_Name);
223  }
224  ++row;
225  }
226 }
227 
229 {
230  bool checked = true;
231  int row = 0;
232  for (auto it = m_FieldData.begin(); checked && it != m_FieldData.end(); ++it) {
233  checked = m_InfoSubCols->IsChecked(row);
234  ++row;
235  }
236  return checked;
237 }
238 
239 /*!
240  * Should we show tooltips?
241  */
242 
244 {
245  return true;
246 }
247 
248 /*!
249  * Get bitmap resources
250  */
251 
252 wxBitmap CVcfColumnSelectionPanel::GetBitmapResource( const wxString& name )
253 {
254  // Bitmap retrieval
255 ////@begin CVcfColumnSelectionPanel bitmap retrieval
256  wxUnusedVar(name);
257  return wxNullBitmap;
258 ////@end CVcfColumnSelectionPanel bitmap retrieval
259 }
260 
261 /*!
262  * Get icon resources
263  */
264 
265 wxIcon CVcfColumnSelectionPanel::GetIconResource( const wxString& name )
266 {
267  // Icon retrieval
268 ////@begin CVcfColumnSelectionPanel icon retrieval
269  wxUnusedVar(name);
270  return wxNullIcon;
271 ////@end CVcfColumnSelectionPanel icon retrieval
272 }
273 
274 /*!
275  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SelectAllINFO
276  */
277 
279 {
280  for (int row = 0; row < m_FieldData.size(); ++row) {
281  m_InfoSubCols->SetChecked(row, true);
282  }
283 }
284 
285 
286 /*!
287  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DeselectAllINFO
288  */
289 
291 {
292  for (int row = 0; row < m_FieldData.size(); ++row) {
293  m_InfoSubCols->SetChecked(row, false);
294  }
295 }
296 
297 
298 
300 
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:244
CNcbiRegistry –.
Definition: ncbireg.hpp:913
static bool ShowToolTips()
Should we show tooltips?
void OnSelectAllClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SelectAllINFO
void SetInfoFields(const set< CConstRef< SVcfFieldData >> &fields)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxCheckedListCtrl * m_InfoSubCols
bool Create(wxWindow *parent, wxWindowID id=ID_CVCFCOLUMNSELECTIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void Init()
Initialises member variables.
set< CConstRef< SVcfFieldData > > m_FieldData
void OnDeselectAllClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DeselectAllINFO
void GetSelectedInfoFields(set< string > &selected)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void CreateControls()
Creates the controls and sizers.
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
size_type size() const
Definition: set.hpp:132
const_iterator end() const
Definition: set.hpp:136
bool IsChecked(long item) const
void SetChecked(long item, bool checked)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define NULL
Definition: ncbistd.hpp:225
virtual string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3197
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static void s_GetMandatoryFields(set< string > &fields)
Modified on Sun Mar 03 03:14:05 2024 by modify_doxy.py rev. 669887