1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxInstantChooserPanel.h"
30 #include "wxContourMainFrame.h"
33 //#include "wxContourEventHandler.h"
36 //----------------------------------------------------------------------------------------------------------------
37 // Class implementation
38 //----------------------------------------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------------------------------------
41 // Throwed Events definition
42 //----------------------------------------------------------------------------------------------------------------
45 DEFINE_EVENT_TYPE( wxINSTANT_CHOOSER_CHANGE )
48 /** @file wxInstantChooserPanel.cxx */
50 //------------------------------------------------------------------------------------------------------------
51 // Constructors & Destructors
52 //------------------------------------------------------------------------------------------------------------
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)
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 );
66 //_configuration = "CCCc";
67 //setVerticalMaxSelectedNums( "1 2 3 3 ");//groupConfig );
70 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
71 _orientation = theOrientation;
72 initializeResolutionSlider();
73 _actualInstant=new std::map<std::string,int>();
75 wxFlexGridSizer * resolutionSizer = new wxFlexGridSizer( 3,1,10,10 );
76 resolutionSizer->AddSpacer(10);
77 resolutionSizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
78 resolutionSizer->AddSpacer(10);
80 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
81 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
82 sizer->Add( resolutionSizer, 1, wxEXPAND | wxGROW );
84 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
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)
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 );
99 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
100 _orientation = theOrientation;
101 initializeResolutionSlider();
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 );
107 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
110 wxInstantChooserPanel :: ~wxInstantChooserPanel()
113 //deleting the _concepts
116 size=_concepts->size();
117 for(i=0; i< size ; i++)
119 delete (*_concepts)[i];
123 _verticalMaxSelected.clear();
124 //deleting the actual instant
125 _actualInstant->clear();
128 //------------------------------------------------------------------------------------------------------------
129 // Creational and initialization methods
130 //------------------------------------------------------------------------------------------------------------
133 * Adds a concept to the instant managment. PRE: The concept doesn't exists in the included _concepts->
134 * @param aConceptName
139 void wxInstantChooserPanel :: addConcept(std::string aConceptName, int minV, int maxV, int actualV)
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 );
148 void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
150 _eventHandler = theEventHandler;
153 //------------------------------------------------------------------------------------------------------------
154 // Methods for capturing events
155 //------------------------------------------------------------------------------------------------------------
156 void wxInstantChooserPanel :: onResolutionSlider(wxScrollEvent& event)
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;
173 _lastConceptUpdated->setRange( minTmp,maxTmp );
175 if (! _resolutionOverALL)
177 changeResolutionAtConceptControl( _lastConceptUpdated );
181 for(int i=0; i< (int)(_concepts->size()); i++)
183 changeResolutionAtConceptControl( (*_concepts)[i] );
188 //------------------------------------------------------------------------------------------------------------
189 void wxInstantChooserPanel :: onCheckBoxClicked( wxCommandEvent& event )
191 /*int groupID = (int)event.GetClientData();
192 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
193 if ( eventConcept->getIfChecked( groupID ) )
195 int i,size = _concepts->size();
196 wxConceptControl * aConcept = NULL;
198 for( i=0; i<size; i++)
200 accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
202 for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
204 aConcept = (*_concepts)[i];
205 if( aConcept!= eventConcept )
207 if( aConcept->getIfChecked( groupID ) )
209 aConcept->clearCheckAt( groupID );
216 int groupID = *(int*)event.GetClientData();
217 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
218 if ( eventConcept->getIfChecked( groupID ) )
220 int size = _concepts->size();
221 wxConceptControl * aConcept = NULL;
224 for(int i = 0; i < eventConcept->getNumCheckBox();i++){
226 eventConcept->clearCheckAt(i);
229 for(int i=0; i<size; i++)
231 aConcept = (*_concepts)[i];
232 if( aConcept!= eventConcept )
234 if( aConcept->getIfChecked( groupID ) )
236 aConcept->clearCheckAt( groupID );
243 //------------------------------------------------------------------------------------------------------------
244 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
246 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
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());
259 //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
260 //_eventHandler->ProcessEvent(newevent);
263 void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
267 //------------------------------------------------------------------------------------------------------------
268 // Methods for sending events
269 //------------------------------------------------------------------------------------------------------------
271 //------------------------------------------------------------------------------------------------------------
272 // Attributes getters and setters
273 //------------------------------------------------------------------------------------------------------------
275 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
277 ConceptDataWrap * conceptData = new ConceptDataWrap();
278 if( _lastConceptUpdated != NULL)
280 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
285 //------------------------------------------------------------------------------------------------------------
286 // Other functional methods
287 //------------------------------------------------------------------------------------------------------------
289 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
291 int max = _concepts->size();
292 if( (int)(choiceInstant.size()) == max )
297 (*_concepts)[i]->setActualValue( choiceInstant[i] );
303 //------------------------------------------------------------------------------------------------------------
304 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
310 int size=_concepts->size();
313 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
318 //------------------------------------------------------------------------------------------------------------
319 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
322 size=_concepts->size();
323 std::map<std::string,int>::iterator iteratorActualInstant;
324 wxConceptControl* concepti;
325 std::string nameConcepti;
328 concepti=(*_concepts)[i];
329 nameConcepti=concepti->getName();
330 iteratorActualInstant=_actualInstant->find(nameConcepti);
331 if(iteratorActualInstant!=_actualInstant->end())
333 int actualValue=iteratorActualInstant->second;
334 concepti->setActualValue(actualValue);
336 nameConcepti.clear();
339 //------------------------------------------------------------------------------------------------------------
340 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
343 wxConceptControl* concepti;
346 bool isEmpty=_actualInstant->empty();
347 if(!isEmpty) _actualInstant->clear();
348 size=_concepts->size();
351 concepti=(*_concepts)[i];
352 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
356 return _actualInstant;
358 //------------------------------------------------------------------------------------------------------------
359 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
362 size=_concepts->size();
365 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
369 //------------------------------------------------------------------------------------------------------------
370 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
372 int minShow = _lastConceptUpdated->getMinShowedValue();
373 int maxShow = _lastConceptUpdated->getMaxShowedValue();
374 _resolutionSlider->SetRange( minShow, maxShow );
378 //------------------------------------------------------------------------------------------------------------
379 void wxInstantChooserPanel :: refreshConceptLabels()
383 //------------------------------------------------------------------------------------------------------------
384 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
386 _configuration = aConfiguration;
388 //------------------------------------------------------------------------------------------------------------
389 std::string wxInstantChooserPanel :: getConfiguration()
391 return _configuration;
393 //------------------------------------------------------------------------------------------------------------
394 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
396 _resolutionOverALL = condition;
398 //------------------------------------------------------------------------------------------------------------
399 bool wxInstantChooserPanel :: getIfResolutionOverAll()
401 return _resolutionOverALL;
404 //------------------------------------------------------------------------------------------------------------
405 void wxInstantChooserPanel :: initializeResolutionSlider()
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 );
410 //------------------------------------------------------------------------------------------------------------
411 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
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;
427 theConceptToUpdate->setRange( minTmp,maxTmp );
430 //------------------------------------------------------------------------------------------------------------
431 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
434 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
435 std::string::size_type start = 0;
436 while( numberIndex != std::string::npos )
438 endSub = numberIndex;
439 std::string number = groupMaxVertNums.substr( 0, endSub );
440 groupMaxVertNums.erase( 0, endSub+1 );
441 int intReturn = atoi(number.c_str());
443 _verticalMaxSelected.push_back(intReturn);
445 _verticalMaxSelected.push_back( 1 );
446 start += numberIndex;
447 numberIndex = groupMaxVertNums.find(" ", endSub);
450 //------------------------------------------------------------------------------------------------------------
451 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
453 int i, size = _concepts->size();
455 for ( i=0; i<size && !setted; i++ )
457 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
459 (*_concepts)[i]->setActualValue( theValue );
465 //------------------------------------------------------------------------------------------------------------
466 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
468 int i, size = _concepts->size();
470 for ( i=0; i<size && value==-1; i++ )
472 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
474 value = (*_concepts)[i]->getActualValue( );
479 //------------------------------------------------------------------------------------------------------------
480 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
482 ConceptDataWrap * conceptData = new ConceptDataWrap();
484 int i, size = _concepts->size();
486 for ( i=0; i<size && value==-1; i++ )
488 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
490 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
495 //------------------------------------------------------------------------------------------------------------
496 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
498 bool isChecked = false;
500 int i,size = _concepts->size();
501 // wxConceptControl * aConcept = NULL;
502 for ( i=0; i<size && !isChecked; i++ )
504 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
506 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
514 void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
516 int max = conceptNameVect.size();
519 if( conceptNameVect[i].compare("Axe Depth") == 0 )
521 addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
523 addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);