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 wxConceptControl * nwConcept = new wxConceptControl(this, _orientation, minV, maxV, actualV, aConceptName, _configuration);
147 _concepts->push_back( nwConcept );
148 _lastConceptUpdated = nwConcept;
149 _outSizer->Add(nwConcept, wxEXPAND);
150 Connect(nwConcept->GetId(), wxEVT_CONCEPT_RELEASE, (wxObjectEventFunction) (wxCommandEventFunction) &wxInstantChooserPanel::onConceptRelease );
153 void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
155 _eventHandler = theEventHandler;
158 //------------------------------------------------------------------------------------------------------------
159 // Methods for capturing events
160 //------------------------------------------------------------------------------------------------------------
161 void wxInstantChooserPanel :: onResolutionSlider(wxScrollEvent& event)
163 std::string lasConcept = _lastConceptUpdated->getName();
164 int value = _lastConceptUpdated->getActualValue();
165 int min = _lastConceptUpdated->getMinValue();
166 int max = _lastConceptUpdated->getMaxValue();
167 int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
168 int minTmp = value - delta/2;
169 int maxTmp = value + delta/2;
178 _lastConceptUpdated->setRange( minTmp,maxTmp );
180 if (! _resolutionOverALL)
182 changeResolutionAtConceptControl( _lastConceptUpdated );
186 for(int i=0; i< (int)(_concepts->size()); i++)
188 changeResolutionAtConceptControl( (*_concepts)[i] );
193 //------------------------------------------------------------------------------------------------------------
194 void wxInstantChooserPanel :: onCheckBoxClicked( wxCommandEvent& event )
196 /*int groupID = (int)event.GetClientData();
197 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
198 if ( eventConcept->getIfChecked( groupID ) )
200 int i,size = _concepts->size();
201 wxConceptControl * aConcept = NULL;
203 for( i=0; i<size; i++)
205 accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
207 for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
209 aConcept = (*_concepts)[i];
210 if( aConcept!= eventConcept )
212 if( aConcept->getIfChecked( groupID ) )
214 aConcept->clearCheckAt( groupID );
221 int groupID = *(int*)event.GetClientData();
222 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
223 if ( eventConcept->getIfChecked( groupID ) )
225 int size = _concepts->size();
226 wxConceptControl * aConcept = NULL;
229 for(int i = 0; i < eventConcept->getNumCheckBox();i++){
231 eventConcept->clearCheckAt(i);
234 for(int i=0; i<size; i++)
236 aConcept = (*_concepts)[i];
237 if( aConcept!= eventConcept )
239 if( aConcept->getIfChecked( groupID ) )
241 aConcept->clearCheckAt( groupID );
248 //------------------------------------------------------------------------------------------------------------
249 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
251 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
253 std::vector<int> theInstant;
254 getInstant( theInstant );
255 //-------------------------------------------------
256 // Sending the event of wxINSTANT_CHOOSER_CHANGE
257 //-------------------------------------------------
258 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
259 //this->onChangeInstant(newevent);
260 ConceptDataWrap * dataConcept = getLastConceptData();
261 if(getIfConceptCheckedAt( dataConcept->getName(), 0 )){
262 wxContourMainFrame::getInstance()->onChangeInstantInstantPanel(dataConcept->getName(), dataConcept->getActualValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue());
264 //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
265 //_eventHandler->ProcessEvent(newevent);
268 void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
272 //------------------------------------------------------------------------------------------------------------
273 // Methods for sending events
274 //------------------------------------------------------------------------------------------------------------
276 //------------------------------------------------------------------------------------------------------------
277 // Attributes getters and setters
278 //------------------------------------------------------------------------------------------------------------
280 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
282 ConceptDataWrap * conceptData = new ConceptDataWrap();
283 if( _lastConceptUpdated != NULL)
285 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
290 //------------------------------------------------------------------------------------------------------------
291 // Other functional methods
292 //------------------------------------------------------------------------------------------------------------
294 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
296 int max = _concepts->size();
297 if( (int)(choiceInstant.size()) == max )
302 (*_concepts)[i]->setActualValue( choiceInstant[i] );
308 //------------------------------------------------------------------------------------------------------------
309 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
315 int size=_concepts->size();
318 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
323 //------------------------------------------------------------------------------------------------------------
324 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
327 size=_concepts->size();
328 std::map<std::string,int>::iterator iteratorActualInstant;
329 wxConceptControl* concepti;
330 std::string nameConcepti;
333 concepti=(*_concepts)[i];
334 nameConcepti=concepti->getName();
335 iteratorActualInstant=_actualInstant->find(nameConcepti);
336 if(iteratorActualInstant!=_actualInstant->end())
338 int actualValue=iteratorActualInstant->second;
339 concepti->setActualValue(actualValue);
341 nameConcepti.clear();
344 //------------------------------------------------------------------------------------------------------------
345 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
348 wxConceptControl* concepti;
351 bool isEmpty=_actualInstant->empty();
352 if(!isEmpty) _actualInstant->clear();
353 size=_concepts->size();
356 concepti=(*_concepts)[i];
357 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
361 return _actualInstant;
363 //------------------------------------------------------------------------------------------------------------
364 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
367 size=_concepts->size();
370 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
374 //------------------------------------------------------------------------------------------------------------
375 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
377 int minShow = _lastConceptUpdated->getMinShowedValue();
378 int maxShow = _lastConceptUpdated->getMaxShowedValue();
379 _resolutionSlider->SetRange( minShow, maxShow );
383 //------------------------------------------------------------------------------------------------------------
384 void wxInstantChooserPanel :: refreshConceptLabels()
388 //------------------------------------------------------------------------------------------------------------
389 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
391 _configuration = aConfiguration;
393 //------------------------------------------------------------------------------------------------------------
394 std::string wxInstantChooserPanel :: getConfiguration()
396 return _configuration;
398 //------------------------------------------------------------------------------------------------------------
399 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
401 _resolutionOverALL = condition;
403 //------------------------------------------------------------------------------------------------------------
404 bool wxInstantChooserPanel :: getIfResolutionOverAll()
406 return _resolutionOverALL;
409 //------------------------------------------------------------------------------------------------------------
410 void wxInstantChooserPanel :: initializeResolutionSlider()
412 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
413 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
415 //------------------------------------------------------------------------------------------------------------
416 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
418 int value = theConceptToUpdate->getActualValue();
419 int min = theConceptToUpdate->getMinValue();
420 int max = theConceptToUpdate->getMaxValue();
421 int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
422 int minTmp = value - delta/2;
423 int maxTmp = value + delta/2;
432 theConceptToUpdate->setRange( minTmp,maxTmp );
435 //------------------------------------------------------------------------------------------------------------
436 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
439 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
440 std::string::size_type start = 0;
441 while( numberIndex != std::string::npos )
443 endSub = numberIndex;
444 std::string number = groupMaxVertNums.substr( 0, endSub );
445 groupMaxVertNums.erase( 0, endSub+1 );
446 int intReturn = atoi(number.c_str());
448 _verticalMaxSelected.push_back(intReturn);
450 _verticalMaxSelected.push_back( 1 );
451 start += numberIndex;
452 numberIndex = groupMaxVertNums.find(" ", endSub);
455 //------------------------------------------------------------------------------------------------------------
456 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
458 int i, size = _concepts->size();
460 for ( i=0; i<size && !setted; i++ )
462 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
464 (*_concepts)[i]->setActualValue( theValue );
470 //------------------------------------------------------------------------------------------------------------
471 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
473 int i, size = _concepts->size();
475 for ( i=0; i<size && value==-1; i++ )
477 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
479 value = (*_concepts)[i]->getActualValue( );
484 //------------------------------------------------------------------------------------------------------------
485 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
487 ConceptDataWrap * conceptData = new ConceptDataWrap();
489 int i, size = _concepts->size();
491 for ( i=0; i<size && value==-1; i++ )
493 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
495 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
500 //------------------------------------------------------------------------------------------------------------
501 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
503 bool isChecked = false;
505 int i,size = _concepts->size();
506 // wxConceptControl * aConcept = NULL;
507 for ( i=0; i<size && !isChecked; i++ )
509 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
511 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
519 void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
521 int max = conceptNameVect.size();
524 if( conceptNameVect[i].compare("Axe Depth") == 0 )
526 addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
528 addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);