1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxInstantChooserPanel.h"
5 #include "wxContourMainFrame.h"
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
11 //----------------------------------------------------------------------------------------------------------------
12 // Throwed Events definition
13 //----------------------------------------------------------------------------------------------------------------
16 DEFINE_EVENT_TYPE( wxINSTANT_CHOOSER_CHANGE )
19 /** @file wxInstantChooserPanel.cxx */
21 //------------------------------------------------------------------------------------------------------------
22 // Constructors & Destructors
23 //------------------------------------------------------------------------------------------------------------
27 wxInstantChooserPanel :: wxInstantChooserPanel (wxWindow * parent, std::string title, bool theOrientation, bool resolutionALL,std::string configurationElem, std::string groupConfig )
28 :wxPanel(parent, -1, wxPoint(20,20), wxDefaultSize, wxTAB_TRAVERSAL)
30 _lastConceptUpdated = NULL;
31 _concepts = new std::vector<wxConceptControl*>();
32 _resolutionOverALL = resolutionALL;
33 _configuration = configurationElem;
34 //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
35 setVerticalMaxSelectedNums( groupConfig );
37 //_configuration = "CCCc";
38 //setVerticalMaxSelectedNums( "1 2 3 3 ");//groupConfig );
41 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
42 _orientation = theOrientation;
43 initializeResolutionSlider();
44 _actualInstant=new std::map<std::string,int>();
46 wxFlexGridSizer * resolutionSizer = new wxFlexGridSizer( 3,1,10,10 );
47 resolutionSizer->AddSpacer(10);
48 resolutionSizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
49 resolutionSizer->AddSpacer(10);
51 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
52 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
53 sizer->Add( resolutionSizer, 1, wxEXPAND | wxGROW );
55 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onChechBoxClicked );
59 wxInstantChooserPanel ::wxInstantChooserPanel (wxWindow * parent,wxWindowID id ,std::string title, const wxPoint& pos, const wxSize& size , bool theOrientation, std::string configurationElem , std::string groupConfig )
60 :wxPanel(parent, id ,pos, size)
62 _lastConceptUpdated = NULL;
63 _concepts = new std::vector<wxConceptControl*>();
64 _resolutionOverALL = false;
65 _configuration = configurationElem;
66 //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
67 setVerticalMaxSelectedNums( groupConfig );
70 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
71 _orientation = theOrientation;
72 initializeResolutionSlider();
73 _actualInstant=new std::map<std::string,int>();
74 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
75 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
76 sizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
78 Connect( wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onChechBoxClicked );
81 wxInstantChooserPanel :: ~wxInstantChooserPanel()
84 //deleting the _concepts
87 size=_concepts->size();
88 for(i=0; i< size ; i++)
90 delete (*_concepts)[i];
94 _verticalMaxSelected.clear();
95 //deleting the actual instant
96 _actualInstant->clear();
99 //------------------------------------------------------------------------------------------------------------
100 // Creational and initialization methods
101 //------------------------------------------------------------------------------------------------------------
104 * Adds a concept to the instant managment. PRE: The concept doesn't exists in the included _concepts->
105 * @param aConceptName
110 void wxInstantChooserPanel :: addConcept(std::string aConceptName, int minV, int maxV, int actualV)
112 wxConceptControl * nwConcept = new wxConceptControl(this, _orientation, minV, maxV, actualV, aConceptName, _configuration);
113 _concepts->push_back( nwConcept );
114 _lastConceptUpdated = nwConcept;
115 _outSizer->Add(nwConcept, wxEXPAND);
116 Connect(nwConcept->GetId(), wxEVT_CONCEPT_RELEASE, (wxObjectEventFunction) (wxCommandEventFunction) &wxInstantChooserPanel::onConceptRelease );
119 void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
121 _eventHandler = theEventHandler;
124 //------------------------------------------------------------------------------------------------------------
125 // Methods for capturing events
126 //------------------------------------------------------------------------------------------------------------
127 void wxInstantChooserPanel :: onResolutionSlider(wxScrollEvent& event)
129 std::string lasConcept = _lastConceptUpdated->getName();
130 int value = _lastConceptUpdated->getActualValue();
131 int min = _lastConceptUpdated->getMinValue();
132 int max = _lastConceptUpdated->getMaxValue();
133 int delta = (int) (pow( 2, _resolutionSlider->GetValue() ));
134 int minTmp = value - delta/2;
135 int maxTmp = value + delta/2;
144 _lastConceptUpdated->setRange( minTmp,maxTmp );
146 if (! _resolutionOverALL)
148 changeResolutionAtConceptControl( _lastConceptUpdated );
152 for(int i=0; i<_concepts->size(); i++)
154 changeResolutionAtConceptControl( (*_concepts)[i] );
159 //------------------------------------------------------------------------------------------------------------
160 void wxInstantChooserPanel :: onChechBoxClicked( wxCommandEvent& event )
162 int groupID = (int)event.GetClientData();
163 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
164 if ( eventConcept->getIfChecked( groupID ) )
166 int i,size = _concepts->size();
167 wxConceptControl * aConcept = NULL;
169 for( i=0; i<size; i++)
171 accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
173 for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
175 aConcept = (*_concepts)[i];
176 if( aConcept!= eventConcept )
178 if( aConcept->getIfChecked( groupID ) )
180 aConcept->clearCheckAt( groupID );
188 //------------------------------------------------------------------------------------------------------------
189 void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
191 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
193 std::vector<int> theInstant;
194 getInstant( theInstant );
195 //-------------------------------------------------
196 // Sending the event of wxINSTANT_CHOOSER_CHANGE
197 //-------------------------------------------------
198 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());
199 _eventHandler->ProcessEvent(newevent);
201 //------------------------------------------------------------------------------------------------------------
202 // Methods for sending events
203 //------------------------------------------------------------------------------------------------------------
205 //------------------------------------------------------------------------------------------------------------
206 // Attributes getters and setters
207 //------------------------------------------------------------------------------------------------------------
209 ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
211 ConceptDataWrap * conceptData = new ConceptDataWrap();
212 if( _lastConceptUpdated != NULL)
214 conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
219 //------------------------------------------------------------------------------------------------------------
220 // Other functional methods
221 //------------------------------------------------------------------------------------------------------------
223 void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
225 int max = _concepts->size();
226 if( choiceInstant.size() == max )
231 (*_concepts)[i]->setActualValue( choiceInstant[i] );
237 //------------------------------------------------------------------------------------------------------------
238 void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
244 int size=_concepts->size();
247 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
252 //------------------------------------------------------------------------------------------------------------
253 void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
256 size=_concepts->size();
257 std::map<std::string,int>::iterator iteratorActualInstant;
258 wxConceptControl* concepti;
259 std::string nameConcepti;
262 concepti=(*_concepts)[i];
263 nameConcepti=concepti->getName();
264 iteratorActualInstant=_actualInstant->find(nameConcepti);
265 if(iteratorActualInstant!=_actualInstant->end())
267 int actualValue=iteratorActualInstant->second;
268 concepti->setActualValue(actualValue);
270 nameConcepti.clear();
273 //------------------------------------------------------------------------------------------------------------
274 std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
277 wxConceptControl* concepti;
280 bool isEmpty=_actualInstant->empty();
281 if(!isEmpty) _actualInstant->clear();
282 size=_concepts->size();
285 concepti=(*_concepts)[i];
286 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
290 return _actualInstant;
292 //------------------------------------------------------------------------------------------------------------
293 void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
296 size=_concepts->size();
299 choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
303 //------------------------------------------------------------------------------------------------------------
304 void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
306 int minShow = _lastConceptUpdated->getMinShowedValue();
307 int maxShow = _lastConceptUpdated->getMaxShowedValue();
308 _resolutionSlider->SetRange( minShow, maxShow );
312 //------------------------------------------------------------------------------------------------------------
313 void wxInstantChooserPanel :: refreshConceptLabels()
317 //------------------------------------------------------------------------------------------------------------
318 void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
320 _configuration = aConfiguration;
322 //------------------------------------------------------------------------------------------------------------
323 std::string wxInstantChooserPanel :: getConfiguration()
325 return _configuration;
327 //------------------------------------------------------------------------------------------------------------
328 void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
330 _resolutionOverALL = condition;
332 //------------------------------------------------------------------------------------------------------------
333 bool wxInstantChooserPanel :: getIfResolutionOverAll()
335 return _resolutionOverALL;
338 //------------------------------------------------------------------------------------------------------------
339 void wxInstantChooserPanel :: initializeResolutionSlider()
341 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS );
342 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider );
344 //------------------------------------------------------------------------------------------------------------
345 void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
347 int value = theConceptToUpdate->getActualValue();
348 int min = theConceptToUpdate->getMinValue();
349 int max = theConceptToUpdate->getMaxValue();
350 int delta = (int) (pow( 2, _resolutionSlider->GetValue() ));
351 int minTmp = value - delta/2;
352 int maxTmp = value + delta/2;
361 theConceptToUpdate->setRange( minTmp,maxTmp );
364 //------------------------------------------------------------------------------------------------------------
365 void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
368 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
369 std::string::size_type start = 0;
370 while( numberIndex != std::string::npos )
372 endSub = numberIndex;
373 std::string number = groupMaxVertNums.substr( 0, endSub );
374 groupMaxVertNums.erase( 0, endSub+1 );
375 int intReturn = atoi(number.c_str());
377 _verticalMaxSelected.push_back(intReturn);
379 _verticalMaxSelected.push_back( 1 );
380 start += numberIndex;
381 numberIndex = groupMaxVertNums.find(" ", endSub);
384 //------------------------------------------------------------------------------------------------------------
385 void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
387 int i, size = _concepts->size();
389 for ( i=0; i<size && !setted; i++ )
391 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
393 (*_concepts)[i]->setActualValue( theValue );
399 //------------------------------------------------------------------------------------------------------------
400 int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
402 int i, size = _concepts->size();
404 for ( i=0; i<size && value==-1; i++ )
406 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
408 value = (*_concepts)[i]->getActualValue( );
413 //------------------------------------------------------------------------------------------------------------
414 ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
416 ConceptDataWrap * conceptData = new ConceptDataWrap();
418 int i, size = _concepts->size();
420 for ( i=0; i<size && value==-1; i++ )
422 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
424 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());
429 //------------------------------------------------------------------------------------------------------------
430 bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
432 bool isChecked = false;
434 int i,size = _concepts->size();
435 wxConceptControl * aConcept = NULL;
436 for ( i=0; i<size && !isChecked; i++ )
438 if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
440 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );