]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxConceptControl.cxx
*** empty log message ***
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxConceptControl.cxx
1
2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "wxConceptControl.h"
6
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file wxConceptControl.cxx */
11 //IMPLEMENT_CLASS(wxConceptControl, wxScrolledWindow)
12 //------------------------------------------------------------------------------------------------------------
13 // Generated events declaration and definition
14 //------------------------------------------------------------------------------------------------------------
15
16
17 DEFINE_EVENT_TYPE( wxEVT_CONCEPT_RELEASE )
18
19         //------------------------------------------------------------------------------------------------------------
20         // Constructors & Destructors
21         //------------------------------------------------------------------------------------------------------------
22         
23         wxConceptControl :: wxConceptControl(wxWindow *parent, bool orientation, int minV, int maxV,  int actualV, std::string &aConceptName, std::string elementsDef )
24         :wxPanel(parent, -1, wxDefaultPosition, parent->GetSize(), wxTAB_TRAVERSAL)
25         {
26
27                 minValue = minV;
28                 maxValue = maxV;
29                 
30                 showLabels = true;
31
32                 wxFlexGridSizer* sizer = new wxFlexGridSizer (1, 3, 15, 15);
33
34                 conceptName = new wxStaticText(this, -1, wxString(aConceptName.c_str(),wxConvUTF8), wxDefaultPosition, wxSize(90,20), wxALIGN_CENTRE );         
35                 sizer->Add( conceptName, 0, wxALIGN_CENTRE |wxALIGN_CENTER_HORIZONTAL);
36                 
37                 if(orientation)
38                 {
39                         sizer->AddGrowableCol(1);
40                         conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8));                    
41                 }
42                 else
43                 {                       
44                         sizer->AddGrowableRow(1);
45                         conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_LEFT| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8) );                 
46                 }
47                 sizer->Add(conceptSlider, 0, wxGROW |wxALL );           
48                 createElements( sizer, elementsDef );
49                 SetSizer( sizer );
50
51                 Connect( conceptSlider->GetId(), wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(wxConceptControl::onSliderTrack));//(wxObjectEventFunction) &wxConceptControl :: onSliderRelease ); 
52                 Connect( conceptSlider->GetId(),  wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(wxConceptControl::onSliderRelease));//(wxObjectEventFunction) &wxConceptControl :: onSliderTrack );     
53
54                 this->SetAutoLayout( true );
55                 this->Layout(); 
56         }
57
58         wxConceptControl :: ~wxConceptControl()
59         {
60
61         }
62
63         //------------------------------------------------------------------------------------------------------------
64         // Methods for capturing events
65         //------------------------------------------------------------------------------------------------------------
66         
67
68         void wxConceptControl ::onUpdateUICheckBox( wxCommandEvent& event )
69         {
70                 lastUpdate = (wxCheckBox * ) event.GetEventObject();
71                 std::string groupId = std::string(lastUpdate->GetName().ToAscii());
72                 event.SetClientData( (void *) atoi(groupId.c_str()) );
73                 event.SetId( GetId() );
74                 event.SetEventObject( this );
75                 GetEventHandler()->ProcessEvent( event );
76         }
77         //------------------------------------------------------------------------------------------------------------
78         void wxConceptControl :: onSliderTrack( wxScrollEvent& event )
79         {
80                 
81         }
82   
83         //------------------------------------------------------------------------------------------------------------
84
85         void wxConceptControl :: onSliderRelease( wxScrollEvent& event )
86         {
87         //      if( !resolutionChange )
88                 sendEnvent( wxEVT_CONCEPT_RELEASE );            
89         }
90
91         
92         //------------------------------------------------------------------------------------------------------------
93         //  Methods for sending events
94         //------------------------------------------------------------------------------------------------------------
95
96         void wxConceptControl :: sendEnvent(WXTYPE theEventType)
97         {
98                 wxCommandEvent cevent( theEventType, GetId() );
99                 cevent.SetEventObject( this );
100                 GetEventHandler()->ProcessEvent( cevent );
101         }
102
103         //------------------------------------------------------------------------------------------------------------
104         //  Attributes getters and setters
105         //------------------------------------------------------------------------------------------------------------
106
107         std::string wxConceptControl :: getName()
108         {
109                 return std::string(conceptName->GetLabel().ToAscii());  //wxString to std::string convertor ?
110         }
111
112         int wxConceptControl :: getMinShowedValue()
113         {
114                 return conceptSlider->GetMin();
115         }
116
117         int wxConceptControl :: getMaxShowedValue()
118         {
119                 return conceptSlider->GetMax();
120         }
121
122         void wxConceptControl :: setMinValue(int theMin)
123         {
124                 minValue = theMin;
125         }
126
127         int  wxConceptControl :: getMinValue()
128         {
129                 return minValue;
130         }
131
132         void wxConceptControl :: setMaxValue(int theMax)
133         {
134                 maxValue = theMax;
135         }
136
137         int  wxConceptControl :: getMaxValue()
138         {
139                 return maxValue;
140         }
141
142         void wxConceptControl :: setActualValue(int theActual)
143         {
144                 conceptSlider->SetValue(theActual);
145         }
146
147         int  wxConceptControl :: getActualValue()
148         {
149                 return conceptSlider->GetValue();
150         }
151
152         void wxConceptControl :: setShowLables(bool ifShowCondition)
153         {
154                 showLabels = ifShowCondition;
155                 //TODO -----UPDATE the slider too!!
156         }
157
158         
159
160         //------------------------------------------------------------------------------------------------------------
161         //  Other functional methods
162         //------------------------------------------------------------------------------------------------------------
163
164         void wxConceptControl :: clearCheckAt( int position )
165         {
166                 checkBoxes[position]->SetValue( false );
167         }
168         //------------------------------------------------------------------------------------------------------------
169         bool wxConceptControl :: getIfChecked( int position )
170         {
171                 return checkBoxes[position]->GetValue();
172         }
173         //------------------------------------------------------------------------------------------------------------
174         void wxConceptControl :: setRange(int minShow, int maxShow)
175         {
176                 /*
177                 if( minShow < minVal )
178                         minShow = minVal;
179                 if( maxShow > maxVal )
180                         maxShow = maxVal;
181                 */
182                 conceptSlider->SetRange(minShow, maxShow);
183                 int actual = getActualValue();
184                 if( actual<minShow )
185                         conceptSlider->SetValue( minShow );
186                 else if( actual>maxShow )
187                         conceptSlider->SetValue( maxShow );             
188         }
189         //------------------------------------------------------------------------------------------------------------
190         void wxConceptControl :: reset()
191         {
192                 conceptSlider->SetRange(minValue, maxValue);
193                 conceptSlider->SetValue(minValue);
194                 int i, size = checkBoxes.size();
195                 for(i=0; i<size; i++)
196                 {
197                         (checkBoxes[i])->SetValue( false );
198                 }
199                 size = textBoxes.size();
200                 for ( i =0; i<size; i++)
201                 {
202                         textBoxes[i]->Clear();
203                 }
204         }
205
206         //------------------------------------------------------------------------------------------------------------
207         // Creational and initialization methods
208         //------------------------------------------------------------------------------------------------------------
209         void wxConceptControl :: createElements(wxSizer *sizer , std::string elementsDef )
210         {
211                 const char * elements = elementsDef.c_str();
212                 int elementsNum = elementsDef.size();
213                 wxFlexGridSizer* checkSizer = new wxFlexGridSizer (1, elementsNum, 5, 5);
214                 int i,ckecks = 0;
215                 for( i = 0;*elements!= 0; elements++)
216                 {                       
217                         char a = *elements;     
218                         if( a == 67 || a == 99 )// Including C:67 or c:99 as a checkBox (ASCII)
219                         {
220                                 createCheckBoxAndAddToSizer( checkSizer, "", -1, ckecks);
221                                 ckecks++;
222                         }
223                         else if ( a == 84 || a==116 )// Including T:84 or t t:116 as textCtrl (ASCII)
224                         {
225
226                         }
227                         i++;
228                 }
229                 sizer->Add(checkSizer, 0, wxGROW |wxALL );      
230         }
231
232         //------------------------------------------------------------------------------------------------------------
233         wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
234         {
235                 char buffer[33];
236                 itoa( groupID, buffer, 10);
237                 wxCheckBox *checkbox = new wxCheckBox( this, -1, wxString(  label.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString( buffer, wxConvUTF8) );
238                 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
239                 sizer->Add(0, 2, 0, wxGROW); 
240                 checkBoxes.push_back( checkbox );
241                 Connect( checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) (wxCommandEventFunction) &wxConceptControl::onUpdateUICheckBox );
242
243                 return checkbox;                
244         }
245
246         //------------------------------------------------------------------------------------------------------------
247         /*wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
248         {
249                 wxCheckBox *checkbox = new wxCheckBox(this, -1, wxString(  label.c_str(), wxConvUTF8));
250                 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
251                 sizer->Add(0, 2, 0, wxGROW);            
252                 return checkbox;                
253         }*/
254         
255