]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxConceptControl.cxx
a205f95a1bccf7d77466cdbc0c30a273bd8b8597
[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                 minValue                = minV;
52                 maxValue                = maxV;
53                 _numCheckBox    = 0;    
54                 showLabels              = true;
55
56 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
57 #if wxMAJOR_VERSION <= 2
58                 wxFlexGridSizer* sizer = new wxFlexGridSizer(1, 3, 15, 15);
59 #else
60                 wxFlexGridSizer* sizer = new wxFlexGridSizer(3);
61 #endif
62                 conceptName = new wxStaticText(this, -1, wxString(aConceptName.c_str(),wxConvUTF8), wxDefaultPosition, wxSize(90,20), wxALIGN_CENTRE );         
63                 sizer->Add( conceptName, 0, wxALIGN_CENTRE |wxALIGN_CENTER_HORIZONTAL);
64                 if(orientation)
65                 {
66                         sizer->AddGrowableCol(1);
67                         conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8));                    
68                 } else {                        
69 //                      sizer->AddGrowableRow(1);
70                         conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_LEFT| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8) );                 
71                 }
72                 sizer->Add(conceptSlider, 0, wxGROW |wxALL );           
73                 createElements( sizer, elementsDef );
74                 SetSizer( sizer );
75                 Connect( conceptSlider->GetId(), wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(wxConceptControl::onSliderTrack));//(wxObjectEventFunction) &wxConceptControl :: onSliderRelease ); 
76                 Connect( conceptSlider->GetId(),  wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(wxConceptControl::onSliderRelease));//(wxObjectEventFunction) &wxConceptControl :: onSliderTrack );     
77                 this->SetAutoLayout( true );
78                 this->Layout(); 
79         }
80
81         wxConceptControl :: ~wxConceptControl()
82         {
83
84         }
85
86         //------------------------------------------------------------------------------------------------------------
87         // Methods for capturing events
88         //------------------------------------------------------------------------------------------------------------
89         
90
91         void wxConceptControl ::onUpdateUICheckBox( wxCommandEvent& event )
92         {
93                 lastUpdate = (wxCheckBox * ) event.GetEventObject();
94                 std::string groupId = std::string(lastUpdate->GetName().ToAscii());
95                 event.SetClientData( (void *) atoi(groupId.c_str()) );
96                 event.SetId( GetId() );
97                 event.SetEventObject( this );
98                 GetEventHandler()->ProcessEvent( event );
99         }
100         //------------------------------------------------------------------------------------------------------------
101         void wxConceptControl :: onSliderTrack( wxScrollEvent& event )
102         {
103                 
104         }
105   
106         //------------------------------------------------------------------------------------------------------------
107
108         void wxConceptControl :: onSliderRelease( wxScrollEvent& event )
109         {
110         //      if( !resolutionChange )
111                 sendEnvent( wxEVT_CONCEPT_RELEASE );            
112         }
113
114         
115         //------------------------------------------------------------------------------------------------------------
116         //  Methods for sending events
117         //------------------------------------------------------------------------------------------------------------
118
119         void wxConceptControl :: sendEnvent(WXTYPE theEventType)
120         {
121                 wxCommandEvent cevent( theEventType, GetId() );
122                 cevent.SetEventObject( this );
123                 GetEventHandler()->ProcessEvent( cevent );
124         }
125
126         //------------------------------------------------------------------------------------------------------------
127         //  Attributes getters and setters
128         //------------------------------------------------------------------------------------------------------------
129
130         std::string wxConceptControl :: getName()
131         {
132                 return std::string(conceptName->GetLabel().ToAscii());  //wxString to std::string convertor ?
133         }
134
135         int wxConceptControl :: getMinShowedValue()
136         {
137                 return conceptSlider->GetMin();
138         }
139
140         int wxConceptControl :: getMaxShowedValue()
141         {
142                 return conceptSlider->GetMax();
143         }
144
145         void wxConceptControl :: setMinValue(int theMin)
146         {
147                 minValue = theMin;
148         }
149
150         int  wxConceptControl :: getMinValue()
151         {
152                 return minValue;
153         }
154
155         void wxConceptControl :: setMaxValue(int theMax)
156         {
157                 maxValue = theMax;
158         }
159
160         int  wxConceptControl :: getMaxValue()
161         {
162                 return maxValue;
163         }
164
165         void wxConceptControl :: setActualValue(int theActual)
166         {
167                 conceptSlider->SetValue(theActual);
168         }
169
170         int  wxConceptControl :: getActualValue()
171         {
172                 return conceptSlider->GetValue();
173         }
174
175         void wxConceptControl :: setShowLables(bool ifShowCondition)
176         {
177                 showLabels = ifShowCondition;
178                 //TODO -----UPDATE the slider too!!
179         }
180
181         
182
183         //------------------------------------------------------------------------------------------------------------
184         //  Other functional methods
185         //------------------------------------------------------------------------------------------------------------
186
187         void wxConceptControl :: clearCheckAt( int position )
188         {
189                 checkBoxes[position]->SetValue( false );
190         }
191         //------------------------------------------------------------------------------------------------------------
192         bool wxConceptControl :: getIfChecked( int position )
193         {
194                 return checkBoxes[position]->GetValue();
195         }
196         //------------------------------------------------------------------------------------------------------------
197         void wxConceptControl :: setRange(int minShow, int maxShow)
198         {
199                 /*
200                 if( minShow < minVal )
201                         minShow = minVal;
202                 if( maxShow > maxVal )
203                         maxShow = maxVal;
204                 */
205                 conceptSlider->SetRange(minShow, maxShow);
206                 int actual = getActualValue();
207                 if( actual<minShow )
208                         conceptSlider->SetValue( minShow );
209                 else if( actual>maxShow )
210                         conceptSlider->SetValue( maxShow );             
211         }
212         //------------------------------------------------------------------------------------------------------------
213         void wxConceptControl :: reset()
214         {
215                 conceptSlider->SetRange(minValue, maxValue);
216                 conceptSlider->SetValue(minValue);
217                 int i, size = checkBoxes.size();
218                 for(i=0; i<size; i++)
219                 {
220                         (checkBoxes[i])->SetValue( false );
221                 }
222                 size = textBoxes.size();
223                 for ( i =0; i<size; i++)
224                 {
225                         textBoxes[i]->Clear();
226                 }
227         }
228
229         //------------------------------------------------------------------------------------------------------------
230         // Creational and initialization methods
231         //------------------------------------------------------------------------------------------------------------
232         void wxConceptControl::createElements(wxSizer *sizer , std::string elementsDef )
233         {
234                 const char * elements = elementsDef.c_str();
235                 int elementsNum = elementsDef.size();
236 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
237 #if wxMAJOR_VERSION <= 2
238                 wxFlexGridSizer* checkSizer = new wxFlexGridSizer(1, elementsNum, 5, 5);
239 #else
240                 wxFlexGridSizer* checkSizer = new wxFlexGridSizer(elementsNum);
241 #endif
242                 int i,ckecks = 0;
243                 for( i = 0;*elements!= 0; elements++)
244                 {                       
245                         char a = *elements;     
246                         if( a == 67 || a == 99 )// Including C:67 or c:99 as a checkBox (ASCII)
247                         {
248                                 /*if(ckecks==0){
249                                         createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
250                                 }else{
251                                         createCheckBoxAndAddToSizer( checkSizer, "Y", -1, ckecks);
252                                 }*/
253                                 createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
254                                 ckecks++;
255                         } else if ( a == 84 || a==116 )// Including T:84 or t t:116 as textCtrl (ASCII)
256                         {
257
258                         }
259                         i++;
260                 }
261                 _numCheckBox = ckecks;
262                 sizer->Add(checkSizer, 0, wxGROW |wxALL );      
263         }
264
265         int wxConceptControl :: getNumCheckBox(){
266                 return _numCheckBox;
267         }
268
269         //------------------------------------------------------------------------------------------------------------
270         wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
271         {
272                 //char buffer[33];
273                 //itoa( groupID, buffer, 10);
274
275                 std::string buffer;
276                 
277                 if(groupID == 0){
278                         buffer = "0";
279                 }else{
280                         int k=groupID;
281                         while (k > 0){
282                                 char temp = k % 10 + 48;
283                                 k = k / 10;
284                                 buffer = temp + buffer; 
285                         }
286                 }
287
288                 //wxCheckBox *checkbox = new wxCheckBox( this, -1, wxString(  label.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString( buffer, wxConvUTF8) );
289                 wxCheckBox *checkbox = new wxCheckBox( this, -1, wxString(  label.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString( buffer.c_str(), wxConvUTF8) );
290                 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
291                 sizer->Add(0, 2, 0, wxGROW); 
292                 checkBoxes.push_back( checkbox );
293                 Connect( checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) (wxCommandEventFunction) &wxConceptControl::onUpdateUICheckBox );
294
295                 return checkbox;                
296         }
297
298         //------------------------------------------------------------------------------------------------------------
299         /*wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
300         {
301                 wxCheckBox *checkbox = new wxCheckBox(this, -1, wxString(  label.c_str(), wxConvUTF8));
302                 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
303                 sizer->Add(0, 2, 0, wxGROW);            
304                 return checkbox;                
305         }*/
306         
307