1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxInstantChooserPanel.h"
5 #include "wxContourMainFrame.h"
8 //#include "wxContourEventHandler.h"
11 //----------------------------------------------------------------------------------------------------------------
12 // Class implementation
13 //----------------------------------------------------------------------------------------------------------------
15 //----------------------------------------------------------------------------------------------------------------
16 // Throwed Events definition
17 //----------------------------------------------------------------------------------------------------------------
20 DEFINE_EVENT_TYPE( wxINSTANT_CHOOSER_CHANGE )
23 /** @file wxInstantChooserPanel.cxx */
25 //------------------------------------------------------------------------------------------------------------
26 // Constructors & Destructors
27 //------------------------------------------------------------------------------------------------------------
31 wxInstantChooserPanel :: wxInstantChooserPanel (wxWindow * parent, std::string title, bool theOrientation, bool resolutionALL,std::string configurationElem, std::string groupConfig )
32 :wxPanel(parent, -1, wxPoint(20,20), wxDefaultSize, wxTAB_TRAVERSAL)
34 _lastConceptUpdated = NULL;
35 _concepts = new std::vector<wxConceptControl*>();
36 _resolutionOverALL = resolutionALL;
37 _configuration = configurationElem;
38 //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
39 setVerticalMaxSelectedNums( groupConfig );
41 //_configuration = "CCCc";
42 //setVerticalMaxSelectedNums( "1 2 3 3 ");//groupConfig );
45 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
46 _orientation = theOrientation;
47 initializeResolutionSlider();
48 _actualInstant=new std::map<std::string,int>();
50 wxFlexGridSizer * resolutionSizer = new wxFlexGridSizer( 3,1,10,10 );
51 resolutionSizer->AddSpacer(10);
52 resolutionSizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
53 resolutionSizer->AddSpacer(10);
55 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
56 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
57 sizer->Add( resolutionSizer, 1, wxEXPAND | wxGROW );
59 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
63 wxInstantChooserPanel ::wxInstantChooserPanel (wxWindow * parent,wxWindowID id ,std::string title, const wxPoint& pos, const wxSize& size , bool theOrientation, std::string configurationElem , std::string groupConfig )
64 :wxPanel(parent, id ,pos, size)
66 _lastConceptUpdated = NULL;
67 _concepts = new std::vector<wxConceptControl*>();
68 _resolutionOverALL = false;
69 _configuration = configurationElem;
70 //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
71 setVerticalMaxSelectedNums( groupConfig );
74 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
75 _orientation = theOrientation;
76 initializeResolutionSlider();
77 _actualInstant=new std::map<std::string,int>();
78 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
79 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
80 sizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
82 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );
85 wxInstantChooserPanel :: ~wxInstantChooserPanel()
88 //deleting the _concepts
91 size=_concepts->size();
92 for(i=0; i< size ; i++)
94 delete (*_concepts)[i];
98 _verticalMaxSelected.clear();
99 //deleting the actual instant
100 _actualInstant->clear();
103 //------------------------------------------------------------------------------------------------------------
104 // Creational and initialization methods
105 //------------------------------------------------------------------------------------------------------------
108 * Adds a concept to the instant managment. PRE: The concept doesn't exists in the included _concepts->
109 * @param aConceptName
114 void wxInstantChooserPanel :: addConcept(std::string aConceptName, int minV, int maxV, int actualV)
116 wxConceptControl * nwConcept = new wxConceptControl(this, _orientation, minV, maxV, actualV, aConceptName, _configuration);
117 _concepts->push_back( nwConcept );
118 _lastConceptUpdated = nwConcept;
119 _outSizer->Add(nwConcept, wxEXPAND);
120 Connect(nwConcept->GetId(), wxEVT_CONCEPT_RELEASE, (wxObjectEventFunction) (wxCommandEventFunction) &wxInstantChooserPanel::onConceptRelease );
123 void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
125 _eventHandler = theEventHandler;
128 //------------------------------------------------------------------------------------------------------------
129 // Methods for capturing events
130 //------------------------------------------------------------------------------------------------------------
131 void wxInstantChooserPanel :: onResolutionSlider(wxScrollEvent& event)
133 std::string lasConcept = _lastConceptUpdated->getName();
134 int value = _lastConceptUpdated->getActualValue();
135 int min = _lastConceptUpdated->getMinValue();
136 int max = _lastConceptUpdated->getMaxValue();
137 int delta = (int) (pow( 2, _resolutionSlider->GetValue() ));
138 int minTmp = value - delta/2;
139 int maxTmp = value + delta/2;
148 _lastConceptUpdated->setRange( minTmp,maxTmp );
150 if (! _resolutionOverALL)
152 changeResolutionAtConceptControl( _lastConceptUpdated );
156 for(int i=0; i<_concepts->size(); i++)
158 changeResolutionAtConceptControl( (*_concepts)[i] );
163 //------------------------------------------------------------------------------------------------------------
164 void wxInstantChooserPanel :: onCheckBoxClicked( wxCommandEvent& event )
166 /*int groupID = (int)event.GetClientData();
167 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
168 if ( eventConcept->getIfChecked( groupID ) )
170 int i,size = _concepts->size();
171 wxConceptControl * aConcept = NULL;
173 for( i=0; i<size; i++)
175 accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
177 for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
179 aConcept = (*_concepts)[i];
180 if( aConcept!= eventConcept )
182 if( aConcept->getIfChecked( groupID ) )
184 aConcept->clearCheckAt( groupID );
191 int groupID = (int)event.GetClientData();
192 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
193 if ( eventConcept->getIfChecked( groupID ) )
195 int size = _concepts->size();
196 wxConceptControl * aConcept = NULL;
199 for(int i = 0; i < eventConcept->getNumCheckBox();i++){
201 eventConcept->clearCheckAt(i);
204 for(int i=0; i<size; i++)
206 aConcept = (*_concepts)[i];
207 if( aConcept!= eventConcept )
209 if( aConcept->getIfChecked( groupID ) )
211 aConcept->clearCheckAt( groupID );
218 //------------------------------------------------------------------------------------------------------------
219 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
221 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
223 std::vector<int> theInstant;
224 getInstant( theInstant );
225 //-------------------------------------------------
226 // Sending the event of wxINSTANT_CHOOSER_CHANGE
227 //-------------------------------------------------
228 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
229 //this->onChangeInstant(newevent);
230 ConceptDataWrap * dataConcept = getLastConceptData();
231 if(getIfConceptCheckedAt( dataConcept->getName(), 0 )){
232 wxContourMainFrame::getInstance()->onChangeInstantInstantPanel(dataConcept->getName(), dataConcept->getActualValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue());
234 //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
235 //_eventHandler->ProcessEvent(newevent);
238 void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
242 //------------------------------------------------------------------------------------------------------------
243 // Methods for sending events
244 //------------------------------------------------------------------------------------------------------------
246 //------------------------------------------------------------------------------------------------------------
247 // Attributes getters and setters
248 //------------------------------------------------------------------------------------------------------------
250 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
252 ConceptDataWrap * conceptData = new ConceptDataWrap();
253 if( _lastConceptUpdated != NULL)
255 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
260 //------------------------------------------------------------------------------------------------------------
261 // Other functional methods
262 //------------------------------------------------------------------------------------------------------------
264 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
266 int max = _concepts->size();
267 if( choiceInstant.size() == max )
272 (*_concepts)[i]->setActualValue( choiceInstant[i] );
278 //------------------------------------------------------------------------------------------------------------
279 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
285 int size=_concepts->size();
288 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
293 //------------------------------------------------------------------------------------------------------------
294 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
297 size=_concepts->size();
298 std::map<std::string,int>::iterator iteratorActualInstant;
299 wxConceptControl* concepti;
300 std::string nameConcepti;
303 concepti=(*_concepts)[i];
304 nameConcepti=concepti->getName();
305 iteratorActualInstant=_actualInstant->find(nameConcepti);
306 if(iteratorActualInstant!=_actualInstant->end())
308 int actualValue=iteratorActualInstant->second;
309 concepti->setActualValue(actualValue);
311 nameConcepti.clear();
314 //------------------------------------------------------------------------------------------------------------
315 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
318 wxConceptControl* concepti;
321 bool isEmpty=_actualInstant->empty();
322 if(!isEmpty) _actualInstant->clear();
323 size=_concepts->size();
326 concepti=(*_concepts)[i];
327 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
331 return _actualInstant;
333 //------------------------------------------------------------------------------------------------------------
334 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
337 size=_concepts->size();
340 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
344 //------------------------------------------------------------------------------------------------------------
345 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
347 int minShow = _lastConceptUpdated->getMinShowedValue();
348 int maxShow = _lastConceptUpdated->getMaxShowedValue();
349 _resolutionSlider->SetRange( minShow, maxShow );
353 //------------------------------------------------------------------------------------------------------------
354 void wxInstantChooserPanel :: refreshConceptLabels()
358 //------------------------------------------------------------------------------------------------------------
359 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
361 _configuration = aConfiguration;
363 //------------------------------------------------------------------------------------------------------------
364 std::string wxInstantChooserPanel :: getConfiguration()
366 return _configuration;
368 //------------------------------------------------------------------------------------------------------------
369 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
371 _resolutionOverALL = condition;
373 //------------------------------------------------------------------------------------------------------------
374 bool wxInstantChooserPanel :: getIfResolutionOverAll()
376 return _resolutionOverALL;
379 //------------------------------------------------------------------------------------------------------------
380 void wxInstantChooserPanel :: initializeResolutionSlider()
382 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
383 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
385 //------------------------------------------------------------------------------------------------------------
386 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
388 int value = theConceptToUpdate->getActualValue();
389 int min = theConceptToUpdate->getMinValue();
390 int max = theConceptToUpdate->getMaxValue();
391 int delta = (int) (pow( 2, _resolutionSlider->GetValue() ));
392 int minTmp = value - delta/2;
393 int maxTmp = value + delta/2;
402 theConceptToUpdate->setRange( minTmp,maxTmp );
405 //------------------------------------------------------------------------------------------------------------
406 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
409 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
410 std::string::size_type start = 0;
411 while( numberIndex != std::string::npos )
413 endSub = numberIndex;
414 std::string number = groupMaxVertNums.substr( 0, endSub );
415 groupMaxVertNums.erase( 0, endSub+1 );
416 int intReturn = atoi(number.c_str());
418 _verticalMaxSelected.push_back(intReturn);
420 _verticalMaxSelected.push_back( 1 );
421 start += numberIndex;
422 numberIndex = groupMaxVertNums.find(" ", endSub);
425 //------------------------------------------------------------------------------------------------------------
426 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
428 int i, size = _concepts->size();
430 for ( i=0; i<size && !setted; i++ )
432 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
434 (*_concepts)[i]->setActualValue( theValue );
440 //------------------------------------------------------------------------------------------------------------
441 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
443 int i, size = _concepts->size();
445 for ( i=0; i<size && value==-1; i++ )
447 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
449 value = (*_concepts)[i]->getActualValue( );
454 //------------------------------------------------------------------------------------------------------------
455 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
457 ConceptDataWrap * conceptData = new ConceptDataWrap();
459 int i, size = _concepts->size();
461 for ( i=0; i<size && value==-1; i++ )
463 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
465 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
470 //------------------------------------------------------------------------------------------------------------
471 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
473 bool isChecked = false;
475 int i,size = _concepts->size();
476 wxConceptControl * aConcept = NULL;
477 for ( i=0; i<size && !isChecked; i++ )
479 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
481 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
489 void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
491 int max = conceptNameVect.size();
494 if( conceptNameVect[i].compare("Axe Depth") == 0 )
496 addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
498 addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);