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 );
219 //------------------------------------------------------------------------------------------------------------
220 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
222 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
224 std::vector<int> theInstant;
225 getInstant( theInstant );
226 //-------------------------------------------------
227 // Sending the event of wxINSTANT_CHOOSER_CHANGE
228 //-------------------------------------------------
229 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
230 //this->onChangeInstant(newevent);
231 ConceptDataWrap * dataConcept = getLastConceptData();
232 if(getIfConceptCheckedAt( dataConcept->getName(), 0 )){
233 wxContourMainFrame::getInstance()->onChangeInstantInstantPanel(dataConcept->getName(), dataConcept->getActualValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue());
235 //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
236 //_eventHandler->ProcessEvent(newevent);
239 void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
243 //------------------------------------------------------------------------------------------------------------
244 // Methods for sending events
245 //------------------------------------------------------------------------------------------------------------
247 //------------------------------------------------------------------------------------------------------------
248 // Attributes getters and setters
249 //------------------------------------------------------------------------------------------------------------
251 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
253 ConceptDataWrap * conceptData = new ConceptDataWrap();
254 if( _lastConceptUpdated != NULL)
256 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
261 //------------------------------------------------------------------------------------------------------------
262 // Other functional methods
263 //------------------------------------------------------------------------------------------------------------
265 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
267 int max = _concepts->size();
268 if( choiceInstant.size() == max )
273 (*_concepts)[i]->setActualValue( choiceInstant[i] );
279 //------------------------------------------------------------------------------------------------------------
280 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
286 int size=_concepts->size();
289 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
294 //------------------------------------------------------------------------------------------------------------
295 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
298 size=_concepts->size();
299 std::map<std::string,int>::iterator iteratorActualInstant;
300 wxConceptControl* concepti;
301 std::string nameConcepti;
304 concepti=(*_concepts)[i];
305 nameConcepti=concepti->getName();
306 iteratorActualInstant=_actualInstant->find(nameConcepti);
307 if(iteratorActualInstant!=_actualInstant->end())
309 int actualValue=iteratorActualInstant->second;
310 concepti->setActualValue(actualValue);
312 nameConcepti.clear();
315 //------------------------------------------------------------------------------------------------------------
316 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
319 wxConceptControl* concepti;
322 bool isEmpty=_actualInstant->empty();
323 if(!isEmpty) _actualInstant->clear();
324 size=_concepts->size();
327 concepti=(*_concepts)[i];
328 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
332 return _actualInstant;
334 //------------------------------------------------------------------------------------------------------------
335 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
338 size=_concepts->size();
341 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
345 //------------------------------------------------------------------------------------------------------------
346 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
348 int minShow = _lastConceptUpdated->getMinShowedValue();
349 int maxShow = _lastConceptUpdated->getMaxShowedValue();
350 _resolutionSlider->SetRange( minShow, maxShow );
354 //------------------------------------------------------------------------------------------------------------
355 void wxInstantChooserPanel :: refreshConceptLabels()
359 //------------------------------------------------------------------------------------------------------------
360 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
362 _configuration = aConfiguration;
364 //------------------------------------------------------------------------------------------------------------
365 std::string wxInstantChooserPanel :: getConfiguration()
367 return _configuration;
369 //------------------------------------------------------------------------------------------------------------
370 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
372 _resolutionOverALL = condition;
374 //------------------------------------------------------------------------------------------------------------
375 bool wxInstantChooserPanel :: getIfResolutionOverAll()
377 return _resolutionOverALL;
380 //------------------------------------------------------------------------------------------------------------
381 void wxInstantChooserPanel :: initializeResolutionSlider()
383 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
384 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
386 //------------------------------------------------------------------------------------------------------------
387 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
389 int value = theConceptToUpdate->getActualValue();
390 int min = theConceptToUpdate->getMinValue();
391 int max = theConceptToUpdate->getMaxValue();
392 int delta = (int) (pow( 2, _resolutionSlider->GetValue() ));
393 int minTmp = value - delta/2;
394 int maxTmp = value + delta/2;
403 theConceptToUpdate->setRange( minTmp,maxTmp );
406 //------------------------------------------------------------------------------------------------------------
407 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
410 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
411 std::string::size_type start = 0;
412 while( numberIndex != std::string::npos )
414 endSub = numberIndex;
415 std::string number = groupMaxVertNums.substr( 0, endSub );
416 groupMaxVertNums.erase( 0, endSub+1 );
417 int intReturn = atoi(number.c_str());
419 _verticalMaxSelected.push_back(intReturn);
421 _verticalMaxSelected.push_back( 1 );
422 start += numberIndex;
423 numberIndex = groupMaxVertNums.find(" ", endSub);
426 //------------------------------------------------------------------------------------------------------------
427 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
429 int i, size = _concepts->size();
431 for ( i=0; i<size && !setted; i++ )
433 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
435 (*_concepts)[i]->setActualValue( theValue );
441 //------------------------------------------------------------------------------------------------------------
442 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
444 int i, size = _concepts->size();
446 for ( i=0; i<size && value==-1; i++ )
448 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
450 value = (*_concepts)[i]->getActualValue( );
455 //------------------------------------------------------------------------------------------------------------
456 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
458 ConceptDataWrap * conceptData = new ConceptDataWrap();
460 int i, size = _concepts->size();
462 for ( i=0; i<size && value==-1; i++ )
464 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
466 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
471 //------------------------------------------------------------------------------------------------------------
472 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
474 bool isChecked = false;
476 int i,size = _concepts->size();
477 wxConceptControl * aConcept = NULL;
478 for ( i=0; i<size && !isChecked; i++ )
480 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
482 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
490 void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
492 int max = conceptNameVect.size();
495 if( conceptNameVect[i].compare("Axe Depth") == 0 )
497 addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
499 addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);