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:: onChechBoxClicked );
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:: onChechBoxClicked );
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 :: onChechBoxClicked( 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 );
192 //------------------------------------------------------------------------------------------------------------
193 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
195 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
197 std::vector<int> theInstant;
198 getInstant( theInstant );
199 //-------------------------------------------------
200 // Sending the event of wxINSTANT_CHOOSER_CHANGE
201 //-------------------------------------------------
202 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
203 //this->onChangeInstant(newevent);
204 ((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
205 //_eventHandler->ProcessEvent(newevent);
208 void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
212 //------------------------------------------------------------------------------------------------------------
213 // Methods for sending events
214 //------------------------------------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------------------------------------
217 // Attributes getters and setters
218 //------------------------------------------------------------------------------------------------------------
220 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
222 ConceptDataWrap * conceptData = new ConceptDataWrap();
223 if( _lastConceptUpdated != NULL)
225 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
230 //------------------------------------------------------------------------------------------------------------
231 // Other functional methods
232 //------------------------------------------------------------------------------------------------------------
234 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
236 int max = _concepts->size();
237 if( choiceInstant.size() == max )
242 (*_concepts)[i]->setActualValue( choiceInstant[i] );
248 //------------------------------------------------------------------------------------------------------------
249 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
255 int size=_concepts->size();
258 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
263 //------------------------------------------------------------------------------------------------------------
264 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
267 size=_concepts->size();
268 std::map<std::string,int>::iterator iteratorActualInstant;
269 wxConceptControl* concepti;
270 std::string nameConcepti;
273 concepti=(*_concepts)[i];
274 nameConcepti=concepti->getName();
275 iteratorActualInstant=_actualInstant->find(nameConcepti);
276 if(iteratorActualInstant!=_actualInstant->end())
278 int actualValue=iteratorActualInstant->second;
279 concepti->setActualValue(actualValue);
281 nameConcepti.clear();
284 //------------------------------------------------------------------------------------------------------------
285 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
288 wxConceptControl* concepti;
291 bool isEmpty=_actualInstant->empty();
292 if(!isEmpty) _actualInstant->clear();
293 size=_concepts->size();
296 concepti=(*_concepts)[i];
297 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
301 return _actualInstant;
303 //------------------------------------------------------------------------------------------------------------
304 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
307 size=_concepts->size();
310 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
314 //------------------------------------------------------------------------------------------------------------
315 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
317 int minShow = _lastConceptUpdated->getMinShowedValue();
318 int maxShow = _lastConceptUpdated->getMaxShowedValue();
319 _resolutionSlider->SetRange( minShow, maxShow );
323 //------------------------------------------------------------------------------------------------------------
324 void wxInstantChooserPanel :: refreshConceptLabels()
328 //------------------------------------------------------------------------------------------------------------
329 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
331 _configuration = aConfiguration;
333 //------------------------------------------------------------------------------------------------------------
334 std::string wxInstantChooserPanel :: getConfiguration()
336 return _configuration;
338 //------------------------------------------------------------------------------------------------------------
339 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
341 _resolutionOverALL = condition;
343 //------------------------------------------------------------------------------------------------------------
344 bool wxInstantChooserPanel :: getIfResolutionOverAll()
346 return _resolutionOverALL;
349 //------------------------------------------------------------------------------------------------------------
350 void wxInstantChooserPanel :: initializeResolutionSlider()
352 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
353 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
355 //------------------------------------------------------------------------------------------------------------
356 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
358 int value = theConceptToUpdate->getActualValue();
359 int min = theConceptToUpdate->getMinValue();
360 int max = theConceptToUpdate->getMaxValue();
361 int delta = (int) (pow( 2, _resolutionSlider->GetValue() ));
362 int minTmp = value - delta/2;
363 int maxTmp = value + delta/2;
372 theConceptToUpdate->setRange( minTmp,maxTmp );
375 //------------------------------------------------------------------------------------------------------------
376 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
379 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
380 std::string::size_type start = 0;
381 while( numberIndex != std::string::npos )
383 endSub = numberIndex;
384 std::string number = groupMaxVertNums.substr( 0, endSub );
385 groupMaxVertNums.erase( 0, endSub+1 );
386 int intReturn = atoi(number.c_str());
388 _verticalMaxSelected.push_back(intReturn);
390 _verticalMaxSelected.push_back( 1 );
391 start += numberIndex;
392 numberIndex = groupMaxVertNums.find(" ", endSub);
395 //------------------------------------------------------------------------------------------------------------
396 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
398 int i, size = _concepts->size();
400 for ( i=0; i<size && !setted; i++ )
402 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
404 (*_concepts)[i]->setActualValue( theValue );
410 //------------------------------------------------------------------------------------------------------------
411 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
413 int i, size = _concepts->size();
415 for ( i=0; i<size && value==-1; i++ )
417 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
419 value = (*_concepts)[i]->getActualValue( );
424 //------------------------------------------------------------------------------------------------------------
425 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
427 ConceptDataWrap * conceptData = new ConceptDataWrap();
429 int i, size = _concepts->size();
431 for ( i=0; i<size && value==-1; i++ )
433 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
435 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
440 //------------------------------------------------------------------------------------------------------------
441 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
443 bool isChecked = false;
445 int i,size = _concepts->size();
446 wxConceptControl * aConcept = NULL;
447 for ( i=0; i<size && !isChecked; i++ )
449 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
451 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );