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 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
100 #if wxMAJOR_VERSION <= 2
101 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
103 _outSizer = new wxFlexGridSizer ( 10);
105 _orientation = theOrientation;
106 initializeResolutionSlider();
107 _actualInstant=new std::map<std::string,int>();
108 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
109 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
110 sizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
112 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
115 wxInstantChooserPanel :: ~wxInstantChooserPanel()
118 //deleting the _concepts
121 size=_concepts->size();
122 for(i=0; i< size ; i++)
124 delete (*_concepts)[i];
128 _verticalMaxSelected.clear();
129 //deleting the actual instant
130 _actualInstant->clear();
133 //------------------------------------------------------------------------------------------------------------
134 // Creational and initialization methods
135 //------------------------------------------------------------------------------------------------------------
138 * Adds a concept to the instant managment. PRE: The concept doesn't exists in the included _concepts->
139 * @param aConceptName
144 void wxInstantChooserPanel :: addConcept(std::string aConceptName, int minV, int maxV, int actualV)
146 printf("EED wxInstantChooserPanel :: addConcept Start\n");
147 wxConceptControl * nwConcept = new wxConceptControl(this, _orientation, minV, maxV, actualV, aConceptName, _configuration);
148 _concepts->push_back( nwConcept );
149 _lastConceptUpdated = nwConcept;
150 printf("EED wxInstantChooserPanel :: addConcept 1\n");
151 _outSizer->Add(nwConcept, wxEXPAND);
152 printf("EED wxInstantChooserPanel :: addConcept 2\n");
153 Connect(nwConcept->GetId(), wxEVT_CONCEPT_RELEASE, (wxObjectEventFunction) (wxCommandEventFunction) &wxInstantChooserPanel::onConceptRelease );
154 printf("EED wxInstantChooserPanel :: addConcept End\n");
157 void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
159 _eventHandler = theEventHandler;
162 //------------------------------------------------------------------------------------------------------------
163 // Methods for capturing events
164 //------------------------------------------------------------------------------------------------------------
165 void wxInstantChooserPanel :: onResolutionSlider(wxScrollEvent& event)
167 std::string lasConcept = _lastConceptUpdated->getName();
168 int value = _lastConceptUpdated->getActualValue();
169 int min = _lastConceptUpdated->getMinValue();
170 int max = _lastConceptUpdated->getMaxValue();
171 int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
172 int minTmp = value - delta/2;
173 int maxTmp = value + delta/2;
182 _lastConceptUpdated->setRange( minTmp,maxTmp );
184 if (! _resolutionOverALL)
186 changeResolutionAtConceptControl( _lastConceptUpdated );
190 for(int i=0; i< (int)(_concepts->size()); i++)
192 changeResolutionAtConceptControl( (*_concepts)[i] );
197 //------------------------------------------------------------------------------------------------------------
198 void wxInstantChooserPanel :: onCheckBoxClicked( wxCommandEvent& event )
200 /*int groupID = (int)event.GetClientData();
201 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
202 if ( eventConcept->getIfChecked( groupID ) )
204 int i,size = _concepts->size();
205 wxConceptControl * aConcept = NULL;
207 for( i=0; i<size; i++)
209 accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
211 for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
213 aConcept = (*_concepts)[i];
214 if( aConcept!= eventConcept )
216 if( aConcept->getIfChecked( groupID ) )
218 aConcept->clearCheckAt( groupID );
225 int groupID = *(int*)event.GetClientData();
226 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
227 if ( eventConcept->getIfChecked( groupID ) )
229 int size = _concepts->size();
230 wxConceptControl * aConcept = NULL;
233 for(int i = 0; i < eventConcept->getNumCheckBox();i++){
235 eventConcept->clearCheckAt(i);
238 for(int i=0; i<size; i++)
240 aConcept = (*_concepts)[i];
241 if( aConcept!= eventConcept )
243 if( aConcept->getIfChecked( groupID ) )
245 aConcept->clearCheckAt( groupID );
252 //------------------------------------------------------------------------------------------------------------
253 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
255 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
257 std::vector<int> theInstant;
258 getInstant( theInstant );
259 //-------------------------------------------------
260 // Sending the event of wxINSTANT_CHOOSER_CHANGE
261 //-------------------------------------------------
262 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
263 //this->onChangeInstant(newevent);
264 ConceptDataWrap * dataConcept = getLastConceptData();
265 if(getIfConceptCheckedAt( dataConcept->getName(), 0 )){
266 wxContourMainFrame::getInstance()->onChangeInstantInstantPanel(dataConcept->getName(), dataConcept->getActualValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue());
268 //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
269 //_eventHandler->ProcessEvent(newevent);
272 void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
276 //------------------------------------------------------------------------------------------------------------
277 // Methods for sending events
278 //------------------------------------------------------------------------------------------------------------
280 //------------------------------------------------------------------------------------------------------------
281 // Attributes getters and setters
282 //------------------------------------------------------------------------------------------------------------
284 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
286 ConceptDataWrap * conceptData = new ConceptDataWrap();
287 if( _lastConceptUpdated != NULL)
289 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
294 //------------------------------------------------------------------------------------------------------------
295 // Other functional methods
296 //------------------------------------------------------------------------------------------------------------
298 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
300 int max = _concepts->size();
301 if( (int)(choiceInstant.size()) == max )
306 (*_concepts)[i]->setActualValue( choiceInstant[i] );
312 //------------------------------------------------------------------------------------------------------------
313 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
319 int size=_concepts->size();
322 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
327 //------------------------------------------------------------------------------------------------------------
328 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
331 size=_concepts->size();
332 std::map<std::string,int>::iterator iteratorActualInstant;
333 wxConceptControl* concepti;
334 std::string nameConcepti;
337 concepti=(*_concepts)[i];
338 nameConcepti=concepti->getName();
339 iteratorActualInstant=_actualInstant->find(nameConcepti);
340 if(iteratorActualInstant!=_actualInstant->end())
342 int actualValue=iteratorActualInstant->second;
343 concepti->setActualValue(actualValue);
345 nameConcepti.clear();
348 //------------------------------------------------------------------------------------------------------------
349 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
352 wxConceptControl* concepti;
355 bool isEmpty=_actualInstant->empty();
356 if(!isEmpty) _actualInstant->clear();
357 size=_concepts->size();
360 concepti=(*_concepts)[i];
361 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
365 return _actualInstant;
367 //------------------------------------------------------------------------------------------------------------
368 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
371 size=_concepts->size();
374 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
378 //------------------------------------------------------------------------------------------------------------
379 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
381 int minShow = _lastConceptUpdated->getMinShowedValue();
382 int maxShow = _lastConceptUpdated->getMaxShowedValue();
383 _resolutionSlider->SetRange( minShow, maxShow );
387 //------------------------------------------------------------------------------------------------------------
388 void wxInstantChooserPanel :: refreshConceptLabels()
392 //------------------------------------------------------------------------------------------------------------
393 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
395 _configuration = aConfiguration;
397 //------------------------------------------------------------------------------------------------------------
398 std::string wxInstantChooserPanel :: getConfiguration()
400 return _configuration;
402 //------------------------------------------------------------------------------------------------------------
403 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
405 _resolutionOverALL = condition;
407 //------------------------------------------------------------------------------------------------------------
408 bool wxInstantChooserPanel :: getIfResolutionOverAll()
410 return _resolutionOverALL;
413 //------------------------------------------------------------------------------------------------------------
414 void wxInstantChooserPanel :: initializeResolutionSlider()
416 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
417 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
419 //------------------------------------------------------------------------------------------------------------
420 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
422 int value = theConceptToUpdate->getActualValue();
423 int min = theConceptToUpdate->getMinValue();
424 int max = theConceptToUpdate->getMaxValue();
425 int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
426 int minTmp = value - delta/2;
427 int maxTmp = value + delta/2;
436 theConceptToUpdate->setRange( minTmp,maxTmp );
439 //------------------------------------------------------------------------------------------------------------
440 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
443 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
444 std::string::size_type start = 0;
445 while( numberIndex != std::string::npos )
447 endSub = numberIndex;
448 std::string number = groupMaxVertNums.substr( 0, endSub );
449 groupMaxVertNums.erase( 0, endSub+1 );
450 int intReturn = atoi(number.c_str());
452 _verticalMaxSelected.push_back(intReturn);
454 _verticalMaxSelected.push_back( 1 );
455 start += numberIndex;
456 numberIndex = groupMaxVertNums.find(" ", endSub);
459 //------------------------------------------------------------------------------------------------------------
460 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
462 int i, size = _concepts->size();
464 for ( i=0; i<size && !setted; i++ )
466 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
468 (*_concepts)[i]->setActualValue( theValue );
474 //------------------------------------------------------------------------------------------------------------
475 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
477 int i, size = _concepts->size();
479 for ( i=0; i<size && value==-1; i++ )
481 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
483 value = (*_concepts)[i]->getActualValue( );
488 //------------------------------------------------------------------------------------------------------------
489 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
491 ConceptDataWrap * conceptData = new ConceptDataWrap();
493 int i, size = _concepts->size();
495 for ( i=0; i<size && value==-1; i++ )
497 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
499 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
504 //------------------------------------------------------------------------------------------------------------
505 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
507 bool isChecked = false;
509 int i,size = _concepts->size();
510 // wxConceptControl * aConcept = NULL;
511 for ( i=0; i<size && !isChecked; i++ )
513 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
515 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
523 void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
525 int max = conceptNameVect.size();
528 if( conceptNameVect[i].compare("Axe Depth") == 0 )
530 addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
532 addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);