creaImageIO_lib
creaImageIOWxAttributeSelectionPanel.cpp
Go to the documentation of this file.
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
16 #
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
21 # liability.
22 #
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27 
28 
30 #include <creaImageIOSystem.h>
31 
32 #include <creaImageIOGimmick.h>
33 #ifdef _DEBUG
34 #define new DEBUG_NEW
35 #endif
36 namespace creaImageIO
37 {
38  const int ID_COMBO = 180;
39  // CTor
41  wxDialog* dial,
42  WxGimmickView* view,
43  std::vector<std::string> sAtts,
44  std::vector<std::string> nsAtts,
45  int numLev)
46  : wxPanel( parent,
47  -1, wxDefaultPosition,
48  wxDefaultSize,
49  wxRESIZE_BORDER |
50  wxSYSTEM_MENU |
51  wxCLOSE_BOX |
52  wxMAXIMIZE_BOX |
53  wxMINIMIZE_BOX |
54  wxCAPTION
55  ),
56  dialog(dial),
57  shownA(sAtts),
58  notShownA(nsAtts),
59  mView(view)
60  {
61  GimmickDebugMessage(1,"WxCustomizeConfigPanel::WxCustomizeConfigPanel"
62  <<std::endl);
64  wxStaticText * aa = new wxStaticText(this,-1,_T(" Currently shown attributes for level: "), wxPoint(5,10));
65  wxArrayString as;
66  std::stringstream out;
67  for(int i=1;i<=numLev;i++)
68  {
69  out<<i;
70  as.Add(crea::std2wx(out.str()));
71  out.str("");
72  }
73  levels=new wxComboBox(this, ID_COMBO,_T("1"),wxPoint(190, 5),wxDefaultSize,as);
75  wxStaticText * na=new wxStaticText(this,-1,_T(" Currently hidden attributes: "), wxPoint(255,10));
76 
77  shownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(5,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
78 
79  shownAtts->InsertColumn(0,
80  crea::std2wx(""),
81  wxLIST_FORMAT_LEFT);
82  shownAtts->SetColumnWidth(0,155);
83  shownAtts->Show();
84 
85  wxButton *add = new wxButton(this,wxID_ANY,_T(">>"), wxPoint(170,50) );
86  Connect( add->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnAdd );
87 
88  wxButton *remove = new wxButton(this,wxID_ANY,_T("<<"), wxPoint(170,70) );
89  Connect( remove->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnRemove );
90 
91  notShownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(255,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
92 
93  notShownAtts->InsertColumn(0,
94  crea::std2wx(""),
95  wxLIST_FORMAT_LEFT);
96  notShownAtts->SetColumnWidth(0,155);
97  notShownAtts->Show();
98  LoadCtrls();
99 
100  wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(5,130) );
101  Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnSaveConfig );
102 
103  Layout();
104  }
105 
108  {
109  GimmickDebugMessage(1,"WxAttributeSelectionPanel::~WxAttributeSelectionPanel"
110  <<std::endl);
111  }
112 
113  void WxAttributeSelectionPanel::OnSaveConfig(wxCommandEvent& event)
114  {
115  int n=levels->GetSelection();
116  if(n<0){n=0;}
118  dialog->Destroy();
119  }
120 
121  void WxAttributeSelectionPanel::OnAdd(wxCommandEvent& event)
122  {
123  long item = -1;
124  for ( ;; )
125  {
126  item = shownAtts->GetNextItem(item,
127  wxLIST_NEXT_ALL,
128  wxLIST_STATE_SELECTED);
129  if ( item == -1 )
130  break;
131 
132  std::string change = crea::wx2std(shownAtts->GetItemText(item));
133  std::vector<std::string>::iterator it;
134  bool found=false;
135  for(it=shownA.begin();it!=shownA.end()&&!found;++it)
136  {
137  if((*it).compare(change)==0)
138  {
139  found=true;
140  }
141  }
142  shownA.erase(it-1);
143  notShownA.push_back(change);
144  }
145  LoadCtrls();
146 
147  }
148 
149  void WxAttributeSelectionPanel::OnRemove(wxCommandEvent& event)
150  {
151 
152  long item = -1;
153  for ( ;; )
154  {
155  item = notShownAtts->GetNextItem(item,
156  wxLIST_NEXT_ALL,
157  wxLIST_STATE_SELECTED);
158  if ( item == -1 )
159  break;
160 
161  std::string change = crea::wx2std(notShownAtts->GetItemText(item));
162  std::vector<std::string>::iterator it;
163  bool found=false;
164  for(it=notShownA.begin();it!=notShownA.end()&&!found;++it)
165  {
166  if((*it).compare(change)==0)
167  {
168  found=true;
169  }
170  }
171  notShownA.erase(it-1);
172  shownA.push_back(change);
173 
174  }
175  LoadCtrls();
176 
177  }
178 
179 
181  {
182 
183  wxListItem item;
184  item.SetMask(wxLIST_MASK_STATE |
185  wxLIST_MASK_TEXT |
186  // wxLIST_MASK_IMAGE |
187  wxLIST_MASK_DATA |
188  // wxLIST_MASK_WIDTH |
189  wxLIST_MASK_FORMAT
190  );
191  std::vector<std::string>::iterator it;
192  shownAtts->DeleteAllItems();
193  notShownAtts->DeleteAllItems();
194  for(it=shownA.begin();it!=shownA.end();++it)
195  {
196  item.SetText(crea::std2wx(*it));
197  shownAtts->InsertItem(item);
198  }
199 
200 
201  for(it=notShownA.begin();it!=notShownA.end();++it)
202  {
203  item.SetText(crea::std2wx(*it));
204  notShownAtts->InsertItem(item);
205  }
206 
207  }
208  void WxAttributeSelectionPanel::OnComboChange(wxCommandEvent& event)
209  {
210  int n=levels->GetSelection()+1;
212  LoadCtrls();
213  }
214 
215 //======================================================================
216 BEGIN_EVENT_TABLE(WxAttributeSelectionPanel, wxPanel)
217 EVT_COMBOBOX (ID_COMBO,WxAttributeSelectionPanel::OnComboChange)
218 END_EVENT_TABLE()
219 //======================================================================
220 
221 } // EO namespace creaImageIO
222 
223