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