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

Go to the SVN repository for this file.

1 /* $Id: string_constraint_select.cpp 37302 2016-12-21 21:25:04Z asztalos $
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: Igor Filippov
27  */
28 
29 
30 // Generated by DialogBlocks (unregistered), 14/05/2014 15:44:27
31 
32 #include <ncbi_pch.hpp>
33 
34 // For compilers that support precompilation, includes "wx/wx.h".
35 #include "wx/wxprec.h"
36 
37 #ifdef __BORLANDC__
38 #pragma hdrstop
39 #endif
40 
41 #ifndef WX_PRECOMP
42 #include "wx/wx.h"
43 #endif
44 
45 ////@begin includes
46 ////@end includes
47 
49 
51 
52 ////@begin XPM images
53 ////@end XPM images
54 
55 
56 /*
57  * CStringConstraintSelect type definition
58  */
59 
60 IMPLEMENT_DYNAMIC_CLASS( CStringConstraintSelect, wxPanel )
61 
62 
63 /*
64  * CStringConstraintSelect event table definition
65  */
66 
67 BEGIN_EVENT_TABLE( CStringConstraintSelect, wxPanel )
68 
69 ////@begin CStringConstraintSelect event table entries
70 ////@end CStringConstraintSelect event table entries
71 
72 
76 
78 
79 
80 /*
81  * CStringConstraintSelect constructors
82  */
83 
85 {
86  Init();
87 }
88 
89 CStringConstraintSelect::CStringConstraintSelect( wxWindow* parent, CSeqTableGridPanel* grid_panel, wxArrayString &choices, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
90  : m_GridPanel(grid_panel), m_Grid(grid_panel->GetGrid()), m_Choices(&choices)
91 {
92  Init();
93  Create(parent, id, pos, size, style);
94 }
95 
96 
97 /*
98  * CStringConstraintSelect creator
99  */
100 
101 bool CStringConstraintSelect::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
102 {
103 ////@begin CStringConstraintSelect creation
104  wxPanel::Create( parent, id, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CStringConstraintSelect creation
113  return true;
114 }
115 
116 
117 /*
118  * CStringConstraintSelect destructor
119  */
120 
122 {
123 ////@begin CStringConstraintSelect destruction
124 ////@end CStringConstraintSelect destruction
125 }
126 
127 
128 /*
129  * Member initialisation
130  */
131 
133 {
134 ////@begin CStringConstraintSelect member initialisation
135 ////@end CStringConstraintSelect member initialisation
136 }
137 
138 
139 /*
140  * Control creation for CStringConstraintSelect
141  */
142 
144 {
145 ////@begin CStringConstraintSelect content construction
146  // Generated by DialogBlocks, 14/05/2014 15:57:15 (unregistered)
147 
148  CStringConstraintSelect* itemPanel1 = this;
149 
150  wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Select Rows"));
151  wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
152  itemPanel1->SetSizer(itemStaticBoxSizer2);
153 
154  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
155  itemStaticBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxEXPAND|wxALL, 0);
156 
157  wxButton* itemButton4 = new wxButton( itemStaticBoxSizer2->GetStaticBox(), ID_CSTRINGCONSTRAINTSELECT_BUTTON, _("Select All"), wxDefaultPosition, wxDefaultSize, 0 );
158  itemBoxSizer3->Add(itemButton4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
159 
160  wxButton* itemButton5 = new wxButton( itemStaticBoxSizer2->GetStaticBox(), ID_CSTRINGCONSTRAINTSELECT_BUTTON1, _("Unselect All"), wxDefaultPosition, wxDefaultSize, 0 );
161  itemBoxSizer3->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
162 
163  itemBoxSizer3->AddStretchSpacer(1);
164 
165  m_AddButton = new wxRadioButton( itemStaticBoxSizer2->GetStaticBox(), wxID_ANY, _("Add To Selection"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
166  m_AddButton->SetValue(true);
167  itemBoxSizer3->Add(m_AddButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  m_ExtractButton = new wxRadioButton( itemStaticBoxSizer2->GetStaticBox(), wxID_ANY, _("Extract From Selection"), wxDefaultPosition, wxDefaultSize, 0 );
170  m_ExtractButton->SetValue(false);
171  itemBoxSizer3->Add(m_ExtractButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
172 
173  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
174  itemStaticBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
175 
176  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxVERTICAL);
177  itemBoxSizer6->Add(itemBoxSizer7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
178 
179  m_CheckWhereButton = new wxRadioButton( itemStaticBoxSizer2->GetStaticBox(), ID_CSTRINGCONSTRAINTSELECT_RADIOBUTTON, _("Select Where"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
180  m_CheckWhereButton->SetValue(true);
181  itemBoxSizer7->Add(m_CheckWhereButton, 0, wxALIGN_LEFT|wxALL, 5);
182 
183  m_UncheckWhereButton = new wxRadioButton( itemStaticBoxSizer2->GetStaticBox(), ID_CSTRINGCONSTRAINTSELECT_RADIOBUTTON1, _("Unselect Where"), wxDefaultPosition, wxDefaultSize, 0 );
184  m_UncheckWhereButton->SetValue(false);
185  itemBoxSizer7->Add(m_UncheckWhereButton, 0, wxALIGN_LEFT|wxALL, 5);
186 
187  m_ChoiceList = new wxChoice( itemStaticBoxSizer2->GetStaticBox(), ID_CSTRINGCONSTRAINTSELECT_CHOICE, wxDefaultPosition, wxDefaultSize, *m_Choices, 0 );
188  m_ChoiceList->SetSelection(0);
189  itemBoxSizer6->Add(m_ChoiceList, 0, wxALIGN_TOP|wxALL, 5);
190 
191  m_StringConstraintPanel = new CStringConstraintPanel( itemStaticBoxSizer2->GetStaticBox(), false, ID_CSTRINGCONSTRAINTSELECT_PANEL, wxDefaultPosition, wxDefaultSize, 0, true);
192  itemBoxSizer6->Add(m_StringConstraintPanel, 0, wxALIGN_TOP|wxALL|wxFIXED_MINSIZE, 0);
193 
194  wxButton* itemButton12 = new wxButton( itemStaticBoxSizer2->GetStaticBox(), ID_CSTRINGCONSTRAINTSELECT_BUTTON2, _("Select"), wxDefaultPosition, wxDefaultSize, 0 );
195  itemBoxSizer6->Add(itemButton12, 0, wxALIGN_TOP|wxALL, 5);
196 
197  m_Num = new wxStaticText( itemStaticBoxSizer2->GetStaticBox(), wxID_STATIC, wxEmptyString, wxDefaultPosition, wxSize(itemStaticBoxSizer2->GetStaticBox()->ConvertDialogToPixels(wxSize(100, -1)).x, -1), wxNO_BORDER );
198  itemStaticBoxSizer2->Add(m_Num, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
199 ////@end CStringConstraintSelect content construction
200 }
201 
202 
203 /*
204  * Should we show tooltips?
205  */
206 
208 {
209  return true;
210 }
211 
212 /*
213  * Get bitmap resources
214  */
215 
216 wxBitmap CStringConstraintSelect::GetBitmapResource( const wxString& name )
217 {
218  // Bitmap retrieval
219 ////@begin CStringConstraintSelect bitmap retrieval
220  wxUnusedVar(name);
221  return wxNullBitmap;
222 ////@end CStringConstraintSelect bitmap retrieval
223 }
224 
225 /*
226  * Get icon resources
227  */
228 
229 wxIcon CStringConstraintSelect::GetIconResource( const wxString& name )
230 {
231  // Icon retrieval
232 ////@begin CStringConstraintSelect icon retrieval
233  wxUnusedVar(name);
234  return wxNullIcon;
235 ////@end CStringConstraintSelect icon retrieval
236 }
237 
238 void CStringConstraintSelect::OnSelectAll( wxCommandEvent& event )
239 {
240  int collapsed_col = m_GridPanel->GetCollapseColAndExpand();
241  m_Grid->SelectAll();
242  int num = m_Grid->GetNumberRows();
243  m_GridPanel->CollapseByCol(collapsed_col);
245 }
246 
247 void CStringConstraintSelect::OnUnselectAll( wxCommandEvent& event )
248 {
249  int collapsed_col = m_GridPanel->GetCollapseColAndExpand();
250  m_Grid->ClearSelection();
251  m_GridPanel->CollapseByCol(collapsed_col);
253 }
254 
256 {
257  int col = -1;
258  int sel = m_ChoiceList->GetSelection();
259  if (sel == wxNOT_FOUND) return col;
260  for (unsigned int i=0; i < m_Grid->GetNumberCols(); i++)
261  if (m_Grid->GetColLabelValue(i) == m_ChoiceList->GetString(sel))
262  {
263  col = i;
264  break;
265  }
266  return col;
267 }
268 
270 {
271  wxArrayInt wx_selected = m_Grid->GetSelectedRows();
272  if (wx_selected.IsEmpty())
273  {
274  if (m_Grid->GetSelectionBlockTopLeft().size() == 1 && m_Grid->GetSelectionBlockTopLeft().size() == m_Grid->GetSelectionBlockBottomRight().size())
275  {
276  int top_row = m_Grid->GetSelectionBlockTopLeft()[0].GetRow();
277  int bot_row = m_Grid->GetSelectionBlockBottomRight()[0].GetRow();
278  for (unsigned int i = top_row; i <= bot_row; i++)
279  {
280  selected.insert(i);
281  }
282  }
283  }
284  else
285  {
286  for (unsigned int i = 0; i < wx_selected.GetCount(); i++)
287  {
288  selected.insert(wx_selected.Item(i));
289  }
290  }
291 }
292 
293 void CStringConstraintSelect::OnApply( wxCommandEvent& event )
294 {
295  int col = GetConstrainedColumn();
296  if (col < 0) return;
297 
298  int collapsed_col = m_GridPanel->GetCollapseColAndExpand();
299  set<int> selected;
300  GetSelectedRows(selected);
301 
302  bool select = m_CheckWhereButton->GetValue();
303  bool add_selection = m_AddButton->GetValue();
304  if (add_selection)
305  {
306  for (unsigned i=0; i < m_Grid->GetNumberRows(); i++)
307  {
308  wxString cell = m_Grid->GetCellValue(i,col);
309  if (m_StringConstraintPanel->Match(cell.ToStdString()))
310  {
311  if (select)
312  selected.insert(i);
313  else
314  selected.erase(i);
315  }
316  }
317  }
318  else
319  {
320  set<int> extracted;
321  for (set<int>::iterator i = selected.begin(); i != selected.end(); ++i)
322  {
323  wxString cell = m_Grid->GetCellValue(*i,col);
324  if (m_StringConstraintPanel->Match(cell.ToStdString()))
325  {
326  if (select) // Only keep those which match the constraint
327  extracted.insert(*i);
328  }
329  else
330  {
331  if (!select) // only keep those that do not match the constraint
332  extracted.insert(*i);
333  }
334  }
335  swap(selected,extracted);
336  }
337  int num = 0;
338  m_Grid->ClearSelection();
339  for (set<int>::iterator i = selected.begin(); i != selected.end(); ++i)
340  {
341  m_Grid->SelectRow(*i,true);
342  num++;
343  }
344  m_GridPanel->CollapseByCol(collapsed_col);
346 }
347 
349 {
350  if (num > 0)
351  {
352  wxString label;
353  label << num << " rows currently selected";
354  m_Num->SetLabel(label);
355  }
356  else
357  {
358  m_Num->SetLabel(wxEmptyString);
359  }
360 }
361 
void CollapseByCol(int col)
int GetCollapseColAndExpand(void)
bool Match(const string &str)
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=10000, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void OnUnselectAll(wxCommandEvent &event)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnApply(wxCommandEvent &event)
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
CStringConstraintPanel * m_StringConstraintPanel
void OnSelectAll(wxCommandEvent &event)
void GetSelectedRows(set< int > &selected)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
static void Init(void)
Definition: cursor6.c:76
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#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 const char label[]
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
#define ID_CSTRINGCONSTRAINTSELECT_RADIOBUTTON
#define ID_CSTRINGCONSTRAINTSELECT_BUTTON
#define ID_CSTRINGCONSTRAINTSELECT_BUTTON1
#define ID_CSTRINGCONSTRAINTSELECT_PANEL
#define ID_CSTRINGCONSTRAINTSELECT_CHOICE
#define ID_CSTRINGCONSTRAINTSELECT_BUTTON2
#define ID_CSTRINGCONSTRAINTSELECT_RADIOBUTTON1
Modified on Fri Jun 14 16:52:37 2024 by modify_doxy.py rev. 669887