]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxConceptControl.cxx
d57743ce20417b7143ca9af16b2086c23aa23d80
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxConceptControl.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 #include "wxConceptControl.h"
31
32 //----------------------------------------------------------------------------------------------------------------
33 // Class implementation
34 //----------------------------------------------------------------------------------------------------------------
35 /** @file wxConceptControl.cxx */
36 //IMPLEMENT_CLASS(wxConceptControl, wxScrolledWindow)
37 //------------------------------------------------------------------------------------------------------------
38 // Generated events declaration and definition
39 //------------------------------------------------------------------------------------------------------------
40
41
42 DEFINE_EVENT_TYPE( wxEVT_CONCEPT_RELEASE )
43
44         //------------------------------------------------------------------------------------------------------------
45         // Constructors & Destructors
46         //------------------------------------------------------------------------------------------------------------
47         
48         wxConceptControl::wxConceptControl(wxWindow *parent, bool orientation, int minV, int maxV,  int actualV, std::string &aConceptName, std::string elementsDef )
49         :wxPanel(parent, -1, wxDefaultPosition, parent->GetSize(), wxTAB_TRAVERSAL)
50         {
51 printf("EED wxConceptControl::wxConceptControl Start\n");
52                 minValue                = minV;
53                 maxValue                = maxV;
54                 _numCheckBox    = 0;    
55                 showLabels              = true;
56
57 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
58 #if wxMAJOR_VERSION <= 2
59                 wxFlexGridSizer* sizer = new wxFlexGridSizer(1, 3, 15, 15);
60 #else
61                 wxFlexGridSizer* sizer = new wxFlexGridSizer(3);
62 #endif
63                 conceptName = new wxStaticText(this, -1, wxString(aConceptName.c_str(),wxConvUTF8), wxDefaultPosition, wxSize(90,20), wxALIGN_CENTRE );         
64 printf("EED wxConceptControl::wxConceptControl 1\n");
65                 sizer->Add( conceptName, 0, wxALIGN_CENTRE |wxALIGN_CENTER_HORIZONTAL);
66 printf("EED wxConceptControl::wxConceptControl 2\n");
67                 if(orientation)
68                 {
69                         sizer->AddGrowableCol(1);
70                         conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8));                    
71                 } else {                        
72 //                      sizer->AddGrowableRow(1);
73                         conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_LEFT| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8) );                 
74                 }
75 printf("EED wxConceptControl::wxConceptControl 3\n");
76                 sizer->Add(conceptSlider, 0, wxGROW |wxALL );           
77 printf("EED wxConceptControl::wxConceptControl 4\n");
78                 createElements( sizer, elementsDef );
79                 SetSizer( sizer );
80                 Connect( conceptSlider->GetId(), wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(wxConceptControl::onSliderTrack));//(wxObjectEventFunction) &wxConceptControl :: onSliderRelease ); 
81                 Connect( conceptSlider->GetId(),  wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(wxConceptControl::onSliderRelease));//(wxObjectEventFunction) &wxConceptControl :: onSliderTrack );     
82                 this->SetAutoLayout( true );
83 printf("EED wxConceptControl::wxConceptControl 5\n");
84                 this->Layout(); 
85 printf("EED wxConceptControl::wxConceptControl End\n");
86         }
87
88         wxConceptControl :: ~wxConceptControl()
89         {
90
91         }
92
93         //------------------------------------------------------------------------------------------------------------
94         // Methods for capturing events
95         //------------------------------------------------------------------------------------------------------------
96         
97
98         void wxConceptControl ::onUpdateUICheckBox( wxCommandEvent& event )
99         {
100                 lastUpdate = (wxCheckBox * ) event.GetEventObject();
101                 std::string groupId = std::string(lastUpdate->GetName().ToAscii());
102                 event.SetClientData( (void *) atoi(groupId.c_str()) );
103                 event.SetId( GetId() );
104                 event.SetEventObject( this );
105                 GetEventHandler()->ProcessEvent( event );
106         }
107         //------------------------------------------------------------------------------------------------------------
108         void wxConceptControl :: onSliderTrack( wxScrollEvent& event )
109         {
110                 
111         }
112   
113         //------------------------------------------------------------------------------------------------------------
114
115         void wxConceptControl :: onSliderRelease( wxScrollEvent& event )
116         {
117         //      if( !resolutionChange )
118                 sendEnvent( wxEVT_CONCEPT_RELEASE );            
119         }
120
121         
122         //------------------------------------------------------------------------------------------------------------
123         //  Methods for sending events
124         //------------------------------------------------------------------------------------------------------------
125
126         void wxConceptControl :: sendEnvent(WXTYPE theEventType)
127         {
128                 wxCommandEvent cevent( theEventType, GetId() );
129                 cevent.SetEventObject( this );
130                 GetEventHandler()->ProcessEvent( cevent );
131         }
132
133         //------------------------------------------------------------------------------------------------------------
134         //  Attributes getters and setters
135         //------------------------------------------------------------------------------------------------------------
136
137         std::string wxConceptControl :: getName()
138         {
139                 return std::string(conceptName->GetLabel().ToAscii());  //wxString to std::string convertor ?
140         }
141
142         int wxConceptControl :: getMinShowedValue()
143         {
144                 return conceptSlider->GetMin();
145         }
146
147         int wxConceptControl :: getMaxShowedValue()
148         {
149                 return conceptSlider->GetMax();
150         }
151
152         void wxConceptControl :: setMinValue(int theMin)
153         {
154                 minValue = theMin;
155         }
156
157         int  wxConceptControl :: getMinValue()
158         {
159                 return minValue;
160         }
161
162         void wxConceptControl :: setMaxValue(int theMax)
163         {
164                 maxValue = theMax;
165         }
166
167         int  wxConceptControl :: getMaxValue()
168         {
169                 return maxValue;
170         }
171
172         void wxConceptControl :: setActualValue(int theActual)
173         {
174                 conceptSlider->SetValue(theActual);
175         }
176
177         int  wxConceptControl :: getActualValue()
178         {
179                 return conceptSlider->GetValue();
180         }
181
182         void wxConceptControl :: setShowLables(bool ifShowCondition)
183         {
184                 showLabels = ifShowCondition;
185                 //TODO -----UPDATE the slider too!!
186         }
187
188         
189
190         //------------------------------------------------------------------------------------------------------------
191         //  Other functional methods
192         //------------------------------------------------------------------------------------------------------------
193
194         void wxConceptControl :: clearCheckAt( int position )
195         {
196                 checkBoxes[position]->SetValue( false );
197         }
198         //------------------------------------------------------------------------------------------------------------
199         bool wxConceptControl :: getIfChecked( int position )
200         {
201                 return checkBoxes[position]->GetValue();
202         }
203         //------------------------------------------------------------------------------------------------------------
204         void wxConceptControl :: setRange(int minShow, int maxShow)
205         {
206                 /*
207                 if( minShow < minVal )
208                         minShow = minVal;
209                 if( maxShow > maxVal )
210                         maxShow = maxVal;
211                 */
212                 conceptSlider->SetRange(minShow, maxShow);
213                 int actual = getActualValue();
214                 if( actual<minShow )
215                         conceptSlider->SetValue( minShow );
216                 else if( actual>maxShow )
217                         conceptSlider->SetValue( maxShow );             
218         }
219         //------------------------------------------------------------------------------------------------------------
220         void wxConceptControl :: reset()
221         {
222                 conceptSlider->SetRange(minValue, maxValue);
223                 conceptSlider->SetValue(minValue);
224                 int i, size = checkBoxes.size();
225                 for(i=0; i<size; i++)
226                 {
227                         (checkBoxes[i])->SetValue( false );
228                 }
229                 size = textBoxes.size();
230                 for ( i =0; i<size; i++)
231                 {
232                         textBoxes[i]->Clear();
233                 }
234         }
235
236         //------------------------------------------------------------------------------------------------------------
237         // Creational and initialization methods
238         //------------------------------------------------------------------------------------------------------------
239         void wxConceptControl::createElements(wxSizer *sizer , std::string elementsDef )
240         {
241                 const char * elements = elementsDef.c_str();
242                 int elementsNum = elementsDef.size();
243 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
244 #if wxMAJOR_VERSION <= 2
245                 wxFlexGridSizer* checkSizer = new wxFlexGridSizer(1, elementsNum, 5, 5);
246 #else
247                 wxFlexGridSizer* checkSizer = new wxFlexGridSizer(elementsNum);
248 #endif
249                 int i,ckecks = 0;
250                 for( i = 0;*elements!= 0; elements++)
251                 {                       
252                         char a = *elements;     
253                         if( a == 67 || a == 99 )// Including C:67 or c:99 as a checkBox (ASCII)
254                         {
255                                 /*if(ckecks==0){
256                                         createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
257                                 }else{
258                                         createCheckBoxAndAddToSizer( checkSizer, "Y", -1, ckecks);
259                                 }*/
260                                 createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
261                                 ckecks++;
262                         } else if ( a == 84 || a==116 )// Including T:84 or t t:116 as textCtrl (ASCII)
263                         {
264
265                         }
266                         i++;
267                 }
268                 _numCheckBox = ckecks;
269                 sizer->Add(checkSizer, 0, wxGROW |wxALL );      
270         }
271
272         int wxConceptControl :: getNumCheckBox(){
273                 return _numCheckBox;
274         }
275
276         //------------------------------------------------------------------------------------------------------------
277         wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
278         {
279                 //char buffer[33];
280                 //itoa( groupID, buffer, 10);
281
282                 std::string buffer;
283                 
284                 if(groupID == 0){
285                         buffer = "0";
286                 }else{
287                         int k=groupID;
288                         while (k > 0){
289                                 char temp = k % 10 + 48;
290                                 k = k / 10;
291                                 buffer = temp + buffer; 
292                         }
293                 }
294
295                 //wxCheckBox *checkbox = new wxCheckBox( this, -1, wxString(  label.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString( buffer, wxConvUTF8) );
296                 wxCheckBox *checkbox = new wxCheckBox( this, -1, wxString(  label.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString( buffer.c_str(), wxConvUTF8) );
297                 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
298                 sizer->Add(0, 2, 0, wxGROW); 
299                 checkBoxes.push_back( checkbox );
300                 Connect( checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) (wxCommandEventFunction) &wxConceptControl::onUpdateUICheckBox );
301
302                 return checkbox;                
303         }
304
305         //------------------------------------------------------------------------------------------------------------
306         /*wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
307         {
308                 wxCheckBox *checkbox = new wxCheckBox(this, -1, wxString(  label.c_str(), wxConvUTF8));
309                 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
310                 sizer->Add(0, 2, 0, wxGROW);            
311                 return checkbox;                
312         }*/
313         
314