wxInstantChooserPanel.cxx

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------------------------------------------
00002 // Class definition include
00003 //----------------------------------------------------------------------------------------------------------------
00004 #include "wxInstantChooserPanel.h"
00005 #include "wxContourMainFrame.h"
00006 
00007 //Test JCP 13-10-08
00008 //#include "wxContourEventHandler.h"
00009 //Test JCP 13-10-08
00010 
00011 //----------------------------------------------------------------------------------------------------------------
00012 // Class implementation
00013 //----------------------------------------------------------------------------------------------------------------
00014 
00015 //----------------------------------------------------------------------------------------------------------------
00016 // Throwed Events definition
00017 //----------------------------------------------------------------------------------------------------------------
00018 
00019 
00020 DEFINE_EVENT_TYPE( wxINSTANT_CHOOSER_CHANGE )
00021         
00022 
00023 
00025         //------------------------------------------------------------------------------------------------------------
00026         // Constructors & Destructors
00027         //------------------------------------------------------------------------------------------------------------
00028         
00029 
00030 
00031         wxInstantChooserPanel :: wxInstantChooserPanel (wxWindow * parent, std::string title, bool theOrientation, bool resolutionALL,std::string configurationElem, std::string groupConfig )
00032         :wxPanel(parent, -1, wxPoint(20,20), wxDefaultSize, wxTAB_TRAVERSAL)
00033         {
00034                 _lastConceptUpdated = NULL;             
00035                 _concepts = new std::vector<wxConceptControl*>();
00036                 _resolutionOverALL = resolutionALL;
00037                 _configuration = configurationElem;
00038                 //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
00039                 setVerticalMaxSelectedNums( groupConfig );
00040                 
00041                 //_configuration = "CCCc";
00042                 //setVerticalMaxSelectedNums( "1 2 3 3 ");//groupConfig );
00043 
00044                 SetSize(300,300);
00045                 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
00046                 _orientation = theOrientation;
00047                 initializeResolutionSlider();
00048                 _actualInstant=new std::map<std::string,int>();
00049                 
00050                 wxFlexGridSizer * resolutionSizer = new wxFlexGridSizer( 3,1,10,10 );
00051                 resolutionSizer->AddSpacer(10);
00052                 resolutionSizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
00053                 resolutionSizer->AddSpacer(10);
00054                 
00055                 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
00056                 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
00057                 sizer->Add( resolutionSizer, 1, wxEXPAND | wxGROW );
00058                 SetSizer( sizer );
00059                 Connect( wxID_ANY,  wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );               
00060 
00061         }
00062 
00063         wxInstantChooserPanel ::wxInstantChooserPanel (wxWindow * parent,wxWindowID id ,std::string title, const wxPoint& pos, const wxSize& size , bool theOrientation, std::string configurationElem , std::string groupConfig  )
00064                 :wxPanel(parent, id ,pos, size) 
00065         {
00066                 _lastConceptUpdated = NULL;             
00067                 _concepts = new std::vector<wxConceptControl*>();
00068                 _resolutionOverALL = false;
00069                 _configuration = configurationElem;
00070                 //--- groupConfig -> format: ("## ## # ## "), #:any positive integer number, : space needed between the numbers and at the end of the string.
00071                 setVerticalMaxSelectedNums( groupConfig );
00072                 
00073                 SetSize(size);
00074                 _outSizer = new wxFlexGridSizer ( 1, 10, 10);
00075                 _orientation = theOrientation;
00076                 initializeResolutionSlider();
00077                 _actualInstant=new std::map<std::string,int>();
00078                 wxFlexGridSizer * sizer = new wxFlexGridSizer( 1,2,10,10 );
00079                 sizer->Add( _outSizer, 1, wxEXPAND| wxGROW );
00080                 sizer->Add( _resolutionSlider, 1, wxEXPAND | wxGROW );
00081                 SetSizer( sizer );
00082                 Connect( wxID_ANY,  wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxInstantChooserPanel:: onCheckBoxClicked );               
00083         }
00084 
00085         wxInstantChooserPanel :: ~wxInstantChooserPanel()
00086         {
00087                 int size,i;
00088                 //deleting the _concepts
00089                 if(_concepts!=NULL)
00090                 {
00091                         size=_concepts->size();
00092                         for(i=0; i< size ; i++)
00093                                 {
00094                                         delete (*_concepts)[i];
00095                                 }
00096                         _concepts->clear();
00097                 }
00098                 _verticalMaxSelected.clear();
00099                 //deleting the actual instant
00100                 _actualInstant->clear();
00101         }
00102 
00103         //------------------------------------------------------------------------------------------------------------
00104         // Creational and initialization methods
00105         //------------------------------------------------------------------------------------------------------------
00106         
00114         void wxInstantChooserPanel :: addConcept(std::string aConceptName, int minV, int maxV, int actualV)
00115         {
00116                 wxConceptControl * nwConcept = new wxConceptControl(this, _orientation, minV, maxV, actualV, aConceptName, _configuration);
00117                 _concepts->push_back( nwConcept );
00118                 _lastConceptUpdated = nwConcept;
00119                 _outSizer->Add(nwConcept, wxEXPAND);
00120                 Connect(nwConcept->GetId(), wxEVT_CONCEPT_RELEASE, (wxObjectEventFunction) (wxCommandEventFunction)  &wxInstantChooserPanel::onConceptRelease );
00121         }
00122 
00123         void wxInstantChooserPanel :: setWxEventHandler( wxEvtHandler * theEventHandler )
00124         {
00125                 _eventHandler = theEventHandler;
00126         }
00127 
00128         //------------------------------------------------------------------------------------------------------------
00129         // Methods for capturing events
00130         //------------------------------------------------------------------------------------------------------------
00131         void wxInstantChooserPanel :: onResolutionSlider(wxScrollEvent& event)
00132         {
00133                 std::string lasConcept = _lastConceptUpdated->getName();
00134                 int value = _lastConceptUpdated->getActualValue();
00135                 int min = _lastConceptUpdated->getMinValue();
00136                 int max = _lastConceptUpdated->getMaxValue();
00137                 int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
00138                 int minTmp   = value - delta/2;
00139                 int maxTmp   = value + delta/2;
00140                 if (minTmp<min)
00141                         {
00142                                 minTmp = min;   
00143                         }
00144                 if (maxTmp>max)
00145                         {
00146                                 maxTmp = max;
00147                         }                       
00148                 _lastConceptUpdated->setRange( minTmp,maxTmp );
00149 
00150                 if (! _resolutionOverALL)
00151                 {
00152                         changeResolutionAtConceptControl( _lastConceptUpdated );
00153                 }
00154                 else
00155                 {
00156                         for(int i=0; i< (int)(_concepts->size()); i++)
00157                         {
00158                                 changeResolutionAtConceptControl( (*_concepts)[i] );
00159                         }
00160                 }               
00161 
00162         }
00163         //------------------------------------------------------------------------------------------------------------
00164         void wxInstantChooserPanel :: onCheckBoxClicked( wxCommandEvent& event )
00165         {
00166                 /*int groupID = (int)event.GetClientData();
00167                 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
00168                 if ( eventConcept->getIfChecked( groupID ) )
00169                 {
00170                         int i,size = _concepts->size();
00171                         wxConceptControl * aConcept = NULL;
00172                         int accum = 0;          
00173                         for( i=0; i<size; i++)
00174                         {
00175                                 accum+= (*_concepts)[i]->getIfChecked( groupID ) ? 1 :0;
00176                         }               
00177                         for( i=0; i<size && _verticalMaxSelected[groupID] < accum; i++)
00178                         {
00179                                 aConcept = (*_concepts)[i]; 
00180                                 if( aConcept!= eventConcept )
00181                                 {
00182                                         if( aConcept->getIfChecked( groupID ) )
00183                                         {       
00184                                                 aConcept->clearCheckAt( groupID );
00185                                                 accum--;
00186                                         }                                       
00187                                 }
00188                         }                                       
00189                 }*/
00190 
00191                 int groupID = *(int*)event.GetClientData();
00192                 wxConceptControl * eventConcept = (wxConceptControl *)event.GetEventObject();
00193                 if ( eventConcept->getIfChecked( groupID ) )
00194                 {
00195                         int size = _concepts->size();
00196                         wxConceptControl * aConcept = NULL;
00197 //                      int accum = 0;
00198 
00199                         for(int i = 0; i < eventConcept->getNumCheckBox();i++){
00200                                 if(i!=groupID){
00201                                         eventConcept->clearCheckAt(i);
00202                                 }
00203                         }
00204                         for(int i=0; i<size; i++)
00205                         {
00206                                 aConcept = (*_concepts)[i]; 
00207                                 if( aConcept!= eventConcept )
00208                                 {
00209                                         if( aConcept->getIfChecked( groupID ) )
00210                                         {       
00211                                                 aConcept->clearCheckAt( groupID );
00212                                         }                                       
00213                                 }
00214                         }                       
00215                 }
00216         }
00217 
00218         //------------------------------------------------------------------------------------------------------------
00219         void wxInstantChooserPanel :: onConceptRelease( wxCommandEvent& event )
00220         {
00221                 _lastConceptUpdated = (wxConceptControl*) event.GetEventObject();
00222 
00223                 std::vector<int> theInstant;
00224         getInstant( theInstant );
00225                 //-------------------------------------------------
00226                 //  Sending the event of wxINSTANT_CHOOSER_CHANGE
00227                 //-------------------------------------------------
00228                 wxCommandEvent newevent(wxINSTANT_CHOOSER_CHANGE,GetId());  
00229                 //this->onChangeInstant(newevent);
00230                 ConceptDataWrap * dataConcept = getLastConceptData(); 
00231                 if(getIfConceptCheckedAt( dataConcept->getName(), 0 )){
00232                         wxContourMainFrame::getInstance()->onChangeInstantInstantPanel(dataConcept->getName(), dataConcept->getActualValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue());
00233                 }
00234                 //((wxContourEventHandler*)_eventHandler)->onChangeInstant(newevent);
00235                 //_eventHandler->ProcessEvent(newevent);
00236         }
00237 
00238         void wxInstantChooserPanel :: onChangeInstant( wxCommandEvent& event ){
00239                 
00240         }
00241 
00242         //------------------------------------------------------------------------------------------------------------
00243         //  Methods for sending events
00244         //------------------------------------------------------------------------------------------------------------
00245 
00246         //------------------------------------------------------------------------------------------------------------
00247         //  Attributes getters and setters
00248         //------------------------------------------------------------------------------------------------------------
00249                 
00250         ConceptDataWrap * wxInstantChooserPanel :: getLastConceptData()
00251         {
00252                 ConceptDataWrap * conceptData = new ConceptDataWrap();
00253                 if( _lastConceptUpdated != NULL)
00254                 {
00255                         conceptData -> fillData( _lastConceptUpdated->getName(), _lastConceptUpdated->getMinValue(), _lastConceptUpdated->getMaxValue(), _lastConceptUpdated->getMinShowedValue(), _lastConceptUpdated->getMaxShowedValue(), _lastConceptUpdated->getActualValue());
00256                 }
00257                 return conceptData;
00258         }
00259 
00260         //------------------------------------------------------------------------------------------------------------
00261         //  Other functional methods
00262         //------------------------------------------------------------------------------------------------------------
00263 
00264         void wxInstantChooserPanel :: setInstant(std::vector<int> choiceInstant)
00265         {               
00266                 int max = _concepts->size();
00267                 if( (int)(choiceInstant.size()) == max )
00268                 {
00269                         int i = 0;
00270                         while(i< max)
00271                         {
00272                                 (*_concepts)[i]->setActualValue( choiceInstant[i] );
00273                                 i++;
00274                         }
00275                 }
00276         }
00277         
00278         //------------------------------------------------------------------------------------------------------------
00279         void wxInstantChooserPanel :: getInstant(std::vector<int> & choiceInstant)
00280         {
00281                 if(_concepts!=NULL)
00282                 {
00283                         int i = 0;
00284 
00285                         int size=_concepts->size();
00286                         while( i< size )
00287                         {
00288                                 choiceInstant.push_back( ((*_concepts))[i]->getActualValue());
00289                                 i++;
00290                         }
00291                 }               
00292         }
00293         //------------------------------------------------------------------------------------------------------------
00294         void wxInstantChooserPanel :: setInstant(std::map<std::string,int>* _actualInstant )
00295         {
00296                 int size,i;
00297                 size=_concepts->size();
00298                 std::map<std::string,int>::iterator iteratorActualInstant;
00299                 wxConceptControl* concepti;
00300                 std::string nameConcepti;
00301                 for(i=0;i<size;i++)
00302                 {
00303                         concepti=(*_concepts)[i];
00304                         nameConcepti=concepti->getName();
00305                         iteratorActualInstant=_actualInstant->find(nameConcepti);
00306                         if(iteratorActualInstant!=_actualInstant->end())
00307                         {
00308                                 int actualValue=iteratorActualInstant->second;
00309                                 concepti->setActualValue(actualValue);
00310                         }
00311                         nameConcepti.clear();
00312                 }
00313         }
00314         //------------------------------------------------------------------------------------------------------------
00315         std::map<std::string,int>* wxInstantChooserPanel :: getInstantData()
00316         {
00317                 int size,i=0;   
00318                 wxConceptControl* concepti;
00319                 if(_concepts!=NULL)
00320                 {
00321                         bool isEmpty=_actualInstant->empty();
00322                         if(!isEmpty) _actualInstant->clear();
00323                         size=_concepts->size();
00324                         while( i< size )
00325                         {
00326                                 concepti=(*_concepts)[i];
00327                                 _actualInstant->insert(std::pair<std::string,int>(concepti->getName(),concepti->getActualValue()));
00328                                 i++;
00329                         }
00330                 }
00331                 return _actualInstant;          
00332         }
00333         //------------------------------------------------------------------------------------------------------------
00334         void wxInstantChooserPanel :: getInstantData(std::map<std::string,int> & choiceInstantData)
00335         {
00336                 int i = 0,size;
00337                 size=_concepts->size();
00338                 while(i< size)
00339                 {
00340                         choiceInstantData.insert(std::pair < std::string, int> ((*_concepts)[i]->getName(), (*_concepts)[i]->getActualValue()));
00341                         i++;
00342                 }
00343         }
00344         //------------------------------------------------------------------------------------------------------------
00345         void wxInstantChooserPanel :: setResolutionRangeWithLasUpdate()
00346         {
00347                 int minShow = _lastConceptUpdated->getMinShowedValue();
00348                 int maxShow = _lastConceptUpdated->getMaxShowedValue();
00349                 _resolutionSlider->SetRange( minShow, maxShow );
00350         }
00351 
00352         
00353         //------------------------------------------------------------------------------------------------------------
00354         void wxInstantChooserPanel :: refreshConceptLabels()
00355         {
00356                 
00357         }
00358         //------------------------------------------------------------------------------------------------------------
00359         void wxInstantChooserPanel :: setConfiguration(std::string aConfiguration)
00360         {
00361                 _configuration = aConfiguration;
00362         }
00363         //------------------------------------------------------------------------------------------------------------
00364         std::string wxInstantChooserPanel :: getConfiguration()
00365         {
00366                 return _configuration;
00367         }
00368         //------------------------------------------------------------------------------------------------------------
00369         void wxInstantChooserPanel :: setResolutionOverAll( bool condition )
00370         {
00371                 _resolutionOverALL = condition;
00372         }
00373         //------------------------------------------------------------------------------------------------------------
00374         bool wxInstantChooserPanel :: getIfResolutionOverAll()
00375         {
00376                 return _resolutionOverALL;
00377         }
00378 
00379    //------------------------------------------------------------------------------------------------------------
00380         void wxInstantChooserPanel :: initializeResolutionSlider()
00381         {       
00382                 _resolutionSlider = new wxSlider(this , -1,5,1,8,wxDefaultPosition, wxSize(25,45), wxSL_LEFT | wxSL_AUTOTICKS  );               
00383                 Connect( _resolutionSlider->GetId(), wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEventHandler(wxInstantChooserPanel::onResolutionSlider));//(wxObjectEventFunction) &wxInstantChooserPanel::onResolutionSlider ); 
00384         }
00385         //------------------------------------------------------------------------------------------------------------
00386         void wxInstantChooserPanel :: changeResolutionAtConceptControl( wxConceptControl * theConceptToUpdate )
00387         {
00388                 int value = theConceptToUpdate->getActualValue();
00389                 int min = theConceptToUpdate->getMinValue();
00390                 int max = theConceptToUpdate->getMaxValue();
00391                 int delta = (int) (pow((double) 2, _resolutionSlider->GetValue() ));
00392                 int minTmp   = value - delta/2;
00393                 int maxTmp   = value + delta/2;
00394                 if (minTmp<min)
00395                 {
00396                         minTmp = min;   
00397                 }
00398                 if (maxTmp>max)
00399                 {
00400                         maxTmp = max;
00401                 }                       
00402                 theConceptToUpdate->setRange( minTmp,maxTmp );
00403         }
00404 
00405         //------------------------------------------------------------------------------------------------------------
00406         void wxInstantChooserPanel :: setVerticalMaxSelectedNums( std::string groupMaxVertNums )
00407         {
00408                 int endSub;
00409                 std::string::size_type numberIndex = groupMaxVertNums.find(" ", 0);
00410                 std::string::size_type start = 0;
00411                 while( numberIndex != std::string::npos ) 
00412                 {       
00413             endSub = numberIndex;
00414                         std::string number = groupMaxVertNums.substr( 0, endSub );
00415                         groupMaxVertNums.erase( 0, endSub+1 ); 
00416                         int intReturn = atoi(number.c_str());                   
00417                         if( intReturn>0 )
00418                                 _verticalMaxSelected.push_back(intReturn);      
00419                         else
00420                                 _verticalMaxSelected.push_back( 1 );    
00421                         start += numberIndex;
00422                         numberIndex = groupMaxVertNums.find(" ", endSub);                       
00423                 }                               
00424         }
00425         //------------------------------------------------------------------------------------------------------------
00426         void wxInstantChooserPanel :: setConceptValue( std::string theConceptName, int theValue )
00427         {
00428                 int i, size = _concepts->size();
00429                 bool setted = false;
00430                 for ( i=0; i<size && !setted; i++ )
00431                 {       
00432                         if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
00433                         {
00434                                 (*_concepts)[i]->setActualValue( theValue );
00435                                 setted = true;
00436                         }
00437                 }
00438         }
00439         
00440         //------------------------------------------------------------------------------------------------------------
00441         int wxInstantChooserPanel :: getConceptValue( std::string theConceptName )
00442         {
00443                 int i, size = _concepts->size();
00444                 int value = -1;
00445                 for ( i=0; i<size && value==-1; i++ )
00446                 {       
00447                         if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
00448                         {
00449                                 value = (*_concepts)[i]->getActualValue(  );
00450                         }
00451                 }
00452                 return value;
00453         }
00454         //------------------------------------------------------------------------------------------------------------
00455         ConceptDataWrap * wxInstantChooserPanel :: getConceptDataOf( std::string theConceptName )
00456         {
00457                 ConceptDataWrap * conceptData = new ConceptDataWrap();
00458 
00459                 int i, size = _concepts->size();
00460                 int value = -1;
00461                 for ( i=0; i<size && value==-1; i++ )
00462                 {       
00463                         if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
00464                         {               
00465                                 conceptData -> fillData( (*_concepts)[i]->getName(), (*_concepts)[i]->getMinValue(), (*_concepts)[i]->getMaxValue(), (*_concepts)[i]->getMinShowedValue(), (*_concepts)[i]->getMaxShowedValue(), (*_concepts)[i]->getActualValue());                    
00466                         }
00467                 }
00468                 return conceptData;
00469         }
00470         //------------------------------------------------------------------------------------------------------------
00471         bool wxInstantChooserPanel :: getIfConceptCheckedAt( std::string theConceptName, int atChecksPosition )
00472         {
00473                 bool isChecked = false;
00474 
00475                 int i,size = _concepts->size();
00476 //              wxConceptControl * aConcept = NULL;                     
00477                 for ( i=0; i<size && !isChecked; i++ )
00478                 {       
00479                         if( (*_concepts)[i]->getName().compare( theConceptName ) == 0 )
00480                         {               
00481                                 isChecked = (*_concepts)[i]->getIfChecked( atChecksPosition );
00482                         }
00483                 }
00484 
00485                 return isChecked;
00486         }
00487          
00488          
00489         void wxInstantChooserPanel::addConcepts(std::vector<std::string> conceptNameVect,std::vector<int> conceptSizeVect){
00490                 int i=0;
00491                 int max = conceptNameVect.size();                       
00492                 for( ; i<max; i++)
00493                 {
00494                         if( conceptNameVect[i].compare("Axe Depth") == 0 )
00495                         {
00496                                 addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);                                      
00497                         } else {
00498                                 addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);
00499                         } // if
00500                 }
00501         }
00502         

Generated on Wed Jun 27 23:28:32 2012 for creaContours_lib by  doxygen 1.5.7.1