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