creaContours_lib
wxInstantChooserPanel.cxx
Go to the documentation of this file.
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 # pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
15 #
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
20 # liability.
21 #
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25 
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxInstantChooserPanel.h"
30 #include "wxContourMainFrame.h"
31 
32 //Test JCP 13-10-08
33 //#include "wxContourEventHandler.h"
34 //Test JCP 13-10-08
35 
36 //----------------------------------------------------------------------------------------------------------------
37 // Class implementation
38 //----------------------------------------------------------------------------------------------------------------
39 
40 //----------------------------------------------------------------------------------------------------------------
41 // Throwed Events definition
42 //----------------------------------------------------------------------------------------------------------------
43 
44 
45 DEFINE_EVENT_TYPE( wxINSTANT_CHOOSER_CHANGE )
46 
47 
48 
50  //------------------------------------------------------------------------------------------------------------
51  // Constructors & Destructors
52  //------------------------------------------------------------------------------------------------------------
53 
54 
55 
56  wxInstantChooserPanel :: wxInstantChooserPanel (wxWindow * parent, std::string title, bool theOrientation, bool resolutionALL,std::string configurationElem, std::string groupConfig )
57  :wxPanel(parent, -1, wxPoint(20,20), wxDefaultSize, wxTAB_TRAVERSAL)
58  {
59  _lastConceptUpdated = NULL;
60  _concepts = new std::vector<wxConceptControl*>();
61  _resolutionOverALL = resolutionALL;
62  _configuration = configurationElem;
63  //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
64  setVerticalMaxSelectedNums( groupConfig );
65 
66  //_configuration = "CCCc";
67  //setVerticalMaxSelectedNums( "1 2 3 3 ");//groupConfig );
68 
69  SetSize(300,300);
70  _outSizer = new wxFlexGridSizer ( 1, 10, 10);
71  _orientation = theOrientation;
72  initializeResolutionSlider();
73  _actualInstant=new std::map<std::string,int>();
74 
75  wxFlexGridSizer * resolutionSizer = new wxFlexGridSizer( 3,1,10,10 );
76  resolutionSizer->AddSpacer(10);
77  resolutionSizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
78  resolutionSizer->AddSpacer(10);
79 
80  wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
81  sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
82  sizer->Add( resolutionSizer, 1, wxEXPAND | wxGROW );
83  SetSizer( sizer );
84  Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
85 
86  }
87 
88  wxInstantChooserPanel ::wxInstantChooserPanel (wxWindow * parent,wxWindowID id ,std::string title, const wxPoint& pos, const wxSize& size , bool theOrientation, std::string configurationElem , std::string groupConfig )
89  :wxPanel(parent, id ,pos, size)
90  {
91  _lastConceptUpdated = NULL;
92  _concepts = new std::vector<wxConceptControl*>();
93  _resolutionOverALL = false;
94  _configuration = configurationElem;
95  //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
96  setVerticalMaxSelectedNums( groupConfig );
97 
98  SetSize(size);
99  _outSizer = new wxFlexGridSizer ( 1, 10, 10);
100  _orientation = theOrientation;
102  _actualInstant=new std::map<std::string,int>();
103  wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
104  sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
105  sizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
106  SetSizer( sizer );
107  Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
108  }
109 
111  {
112  int size,i;
113  //deleting the _concepts
114  if(_concepts!=NULL)
115  {
116  size=_concepts->size();
117  for(i=0; i< size ; i++)
118  {
119  delete (*_concepts)[i];
120  }
121  _concepts->clear();
122  }
123  _verticalMaxSelected.clear();
124  //deleting the actual instant
125  _actualInstant->clear();
126  }
127 
128  //------------------------------------------------------------------------------------------------------------
129  // Creational and initialization methods
130  //------------------------------------------------------------------------------------------------------------
131 
139  void wxInstantChooserPanel :: addConcept(std::string aConceptName, int minV, int maxV, int actualV)
140  {
141  wxConceptControl * nwConcept = new wxConceptControl(this, _orientation, minV, maxV, actualV, aConceptName, _configuration);
142  _concepts->push_back( nwConcept );
143  _lastConceptUpdated = nwConcept;
144  _outSizer->Add(nwConcept, wxEXPAND);
145  Connect(nwConcept->GetId(), wxEVT_CONCEPT_RELEASE, (wxObjectEventFunction) (wxCommandEventFunction) &wxInstantChooserPanel::onConceptRelease );
146  }
147 
148  void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
149  {
150  _eventHandler = theEventHandler;
151  }
152 
153  //------------------------------------------------------------------------------------------------------------
154  // Methods for capturing events
155  //------------------------------------------------------------------------------------------------------------
157  {
158  std::string lasConcept = _lastConceptUpdated->getName();
159  int value = _lastConceptUpdated->getActualValue();
160  int min = _lastConceptUpdated->getMinValue();
161  int max = _lastConceptUpdated->getMaxValue();
162  int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
163  int minTmp = value - delta/2;
164  int maxTmp = value + delta/2;
165  if (minTmp<min)
166  {
167  minTmp = min;
168  }
169  if (maxTmp>max)
170  {
171  maxTmp = max;
172  }
173  _lastConceptUpdated->setRange( minTmp,maxTmp );
174 
175  if (! _resolutionOverALL)
176  {
178  }
179  else
180  {
181  for(int i=0; i< (int)(_concepts->size()); i++)
182  {
184  }
185  }
186 
187  }
188  //------------------------------------------------------------------------------------------------------------
189  void wxInstantChooserPanel :: onCheckBoxClicked( wxCommandEvent& event )
190  {
191  /*int groupID = (int)event.GetClientData();
192  wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
193  if ( eventConcept->getIfChecked( groupID ) )
194  {
195  int i,size = _concepts->size();
196  wxConceptControl * aConcept = NULL;
197  int accum = 0;
198  for( i=0; i<size; i++)
199  {
200  accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
201  }
202  for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
203  {
204  aConcept = (*_concepts)[i];
205  if( aConcept!= eventConcept )
206  {
207  if( aConcept->getIfChecked( groupID ) )
208  {
209  aConcept->clearCheckAt( groupID );
210  accum--;
211  }
212  }
213  }
214  }*/
215 
216  int groupID = *(int*)event.GetClientData();
217  wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
218  if ( eventConcept->getIfChecked( groupID ) )
219  {
220  int size = _concepts->size();
221  wxConceptControl * aConcept = NULL;
222 // int accum = 0;
223 
224  for(int i = 0; i < eventConcept->getNumCheckBox();i++){
225  if(i!=groupID){
226  eventConcept->clearCheckAt(i);
227  }
228  }
229  for(int i=0; i<size; i++)
230  {
231  aConcept = (*_concepts)[i];
232  if( aConcept!= eventConcept )
233  {
234  if( aConcept->getIfChecked( groupID ) )
235  {
236  aConcept->clearCheckAt( groupID );
237  }
238  }
239  }
240  }
241  }
242 
243  //------------------------------------------------------------------------------------------------------------
244  void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
245  {
246  _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
247 
248  std::vector<int> theInstant;
249  getInstant( theInstant );
250  //-------------------------------------------------
251  // Sending the event of wxINSTANT_CHOOSER_CHANGE
252  //-------------------------------------------------
253  wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
254  //this->onChangeInstant(newevent);
255  ConceptDataWrap * dataConcept = getLastConceptData();
256  if(getIfConceptCheckedAt( dataConcept->getName(), 0 )){
257  wxContourMainFrame::getInstance()->onChangeInstantInstantPanel(dataConcept->getName(), dataConcept->getActualValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue());
258  }
259  //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
260  //_eventHandler->ProcessEvent(newevent);
261  }
262 
263  void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
264 
265  }
266 
267  //------------------------------------------------------------------------------------------------------------
268  // Methods for sending events
269  //------------------------------------------------------------------------------------------------------------
270 
271  //------------------------------------------------------------------------------------------------------------
272  // Attributes getters and setters
273  //------------------------------------------------------------------------------------------------------------
274 
276  {
277  ConceptDataWrap * conceptData = new ConceptDataWrap();
278  if( _lastConceptUpdated != NULL)
279  {
281  }
282  return conceptData;
283  }
284 
285  //------------------------------------------------------------------------------------------------------------
286  // Other functional methods
287  //------------------------------------------------------------------------------------------------------------
288 
289  void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
290  {
291  int max = _concepts->size();
292  if( (int)(choiceInstant.size()) == max )
293  {
294  int i = 0;
295  while(i< max)
296  {
297  (*_concepts)[i]->setActualValue( choiceInstant[i] );
298  i++;
299  }
300  }
301  }
302 
303  //------------------------------------------------------------------------------------------------------------
304  void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
305  {
306  if(_concepts!=NULL)
307  {
308  int i = 0;
309 
310  int size=_concepts->size();
311  while( i< size )
312  {
313  choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
314  i++;
315  }
316  }
317  }
318  //------------------------------------------------------------------------------------------------------------
319  void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
320  {
321  int size,i;
322  size=_concepts->size();
323  std::map<std::string,int>::iterator iteratorActualInstant;
324  wxConceptControl* concepti;
325  std::string nameConcepti;
326  for(i=0;i<size;i++)
327  {
328  concepti=(*_concepts)[i];
329  nameConcepti=concepti->getName();
330  iteratorActualInstant=_actualInstant->find(nameConcepti);
331  if(iteratorActualInstant!=_actualInstant->end())
332  {
333  int actualValue=iteratorActualInstant->second;
334  concepti->setActualValue(actualValue);
335  }
336  nameConcepti.clear();
337  }
338  }
339  //------------------------------------------------------------------------------------------------------------
340  std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
341  {
342  int size,i=0;
343  wxConceptControl* concepti;
344  if(_concepts!=NULL)
345  {
346  bool isEmpty=_actualInstant->empty();
347  if(!isEmpty) _actualInstant->clear();
348  size=_concepts->size();
349  while( i< size )
350  {
351  concepti=(*_concepts)[i];
352  _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
353  i++;
354  }
355  }
356  return _actualInstant;
357  }
358  //------------------------------------------------------------------------------------------------------------
359  void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
360  {
361  int i = 0,size;
362  size=_concepts->size();
363  while(i< size)
364  {
365  choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
366  i++;
367  }
368  }
369  //------------------------------------------------------------------------------------------------------------
371  {
372  int minShow = _lastConceptUpdated->getMinShowedValue();
373  int maxShow = _lastConceptUpdated->getMaxShowedValue();
374  _resolutionSlider->SetRange( minShow, maxShow );
375  }
376 
377 
378  //------------------------------------------------------------------------------------------------------------
380  {
381 
382  }
383  //------------------------------------------------------------------------------------------------------------
384  void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
385  {
386  _configuration = aConfiguration;
387  }
388  //------------------------------------------------------------------------------------------------------------
390  {
391  return _configuration;
392  }
393  //------------------------------------------------------------------------------------------------------------
395  {
396  _resolutionOverALL = condition;
397  }
398  //------------------------------------------------------------------------------------------------------------
400  {
401  return _resolutionOverALL;
402  }
403 
404  //------------------------------------------------------------------------------------------------------------
406  {
407  _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
408  Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
409  }
410  //------------------------------------------------------------------------------------------------------------
412  {
413  int value = theConceptToUpdate->getActualValue();
414  int min = theConceptToUpdate->getMinValue();
415  int max = theConceptToUpdate->getMaxValue();
416  int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
417  int minTmp = value - delta/2;
418  int maxTmp = value + delta/2;
419  if (minTmp<min)
420  {
421  minTmp = min;
422  }
423  if (maxTmp>max)
424  {
425  maxTmp = max;
426  }
427  theConceptToUpdate->setRange( minTmp,maxTmp );
428  }
429 
430  //------------------------------------------------------------------------------------------------------------
431  void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
432  {
433  int endSub;
434  std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
435  std::string::size_type start = 0;
436  while( numberIndex != std::string::npos )
437  {
438  endSub = numberIndex;
439  std::string number = groupMaxVertNums.substr( 0, endSub );
440  groupMaxVertNums.erase( 0, endSub+1 );
441  int intReturn = atoi(number.c_str());
442  if( intReturn>0 )
443  _verticalMaxSelected.push_back(intReturn);
444  else
445  _verticalMaxSelected.push_back( 1 );
446  start += numberIndex;
447  numberIndex = groupMaxVertNums.find(" ", endSub);
448  }
449  }
450  //------------------------------------------------------------------------------------------------------------
451  void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
452  {
453  int i, size = _concepts->size();
454  bool setted = false;
455  for ( i=0; i<size && !setted; i++ )
456  {
457  if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
458  {
459  (*_concepts)[i]->setActualValue( theValue );
460  setted = true;
461  }
462  }
463  }
464 
465  //------------------------------------------------------------------------------------------------------------
466  int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
467  {
468  int i, size = _concepts->size();
469  int value = -1;
470  for ( i=0; i<size && value==-1; i++ )
471  {
472  if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
473  {
474  value = (*_concepts)[i]->getActualValue( );
475  }
476  }
477  return value;
478  }
479  //------------------------------------------------------------------------------------------------------------
481  {
482  ConceptDataWrap * conceptData = new ConceptDataWrap();
483 
484  int i, size = _concepts->size();
485  int value = -1;
486  for ( i=0; i<size && value==-1; i++ )
487  {
488  if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
489  {
490  conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
491  }
492  }
493  return conceptData;
494  }
495  //------------------------------------------------------------------------------------------------------------
496  bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
497  {
498  bool isChecked = false;
499 
500  int i,size = _concepts->size();
501 // wxConceptControl * aConcept = NULL;
502  for ( i=0; i<size && !isChecked; i++ )
503  {
504  if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
505  {
506  isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
507  }
508  }
509 
510  return isChecked;
511  }
512 
513 
514  void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
515  int i=0;
516  int max = conceptNameVect.size();
517  for( ; i<max; i++)
518  {
519  if( conceptNameVect[i].compare("Axe Depth") == 0 )
520  {
521  addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
522  } else {
523  addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);
524  } // if
525  }
526  }
527