1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 #include "wxConceptControl.h"
32 //----------------------------------------------------------------------------------------------------------------
33 // Class implementation
34 //----------------------------------------------------------------------------------------------------------------
35 /** @file wxConceptControl.cxx */
36 //IMPLEMENT_CLASS(wxConceptControl, wxScrolledWindow)
37 //------------------------------------------------------------------------------------------------------------
38 // Generated events declaration and definition
39 //------------------------------------------------------------------------------------------------------------
42 DEFINE_EVENT_TYPE( wxEVT_CONCEPT_RELEASE )
44 //------------------------------------------------------------------------------------------------------------
45 // Constructors & Destructors
46 //------------------------------------------------------------------------------------------------------------
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)
58 wxFlexGridSizer* sizer = new wxFlexGridSizer (1, 3, 15, 15);
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);
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));
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) );
73 sizer->Add(conceptSlider, 0, wxGROW |wxALL );
74 createElements( sizer, elementsDef );
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 );
80 this->SetAutoLayout( true );
84 wxConceptControl :: ~wxConceptControl()
89 //------------------------------------------------------------------------------------------------------------
90 // Methods for capturing events
91 //------------------------------------------------------------------------------------------------------------
94 void wxConceptControl ::onUpdateUICheckBox( wxCommandEvent& event )
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 );
103 //------------------------------------------------------------------------------------------------------------
104 void wxConceptControl :: onSliderTrack( wxScrollEvent& event )
109 //------------------------------------------------------------------------------------------------------------
111 void wxConceptControl :: onSliderRelease( wxScrollEvent& event )
113 // if( !resolutionChange )
114 sendEnvent( wxEVT_CONCEPT_RELEASE );
118 //------------------------------------------------------------------------------------------------------------
119 // Methods for sending events
120 //------------------------------------------------------------------------------------------------------------
122 void wxConceptControl :: sendEnvent(WXTYPE theEventType)
124 wxCommandEvent cevent( theEventType, GetId() );
125 cevent.SetEventObject( this );
126 GetEventHandler()->ProcessEvent( cevent );
129 //------------------------------------------------------------------------------------------------------------
130 // Attributes getters and setters
131 //------------------------------------------------------------------------------------------------------------
133 std::string wxConceptControl :: getName()
135 return std::string(conceptName->GetLabel().ToAscii()); //wxString to std::string convertor ?
138 int wxConceptControl :: getMinShowedValue()
140 return conceptSlider->GetMin();
143 int wxConceptControl :: getMaxShowedValue()
145 return conceptSlider->GetMax();
148 void wxConceptControl :: setMinValue(int theMin)
153 int wxConceptControl :: getMinValue()
158 void wxConceptControl :: setMaxValue(int theMax)
163 int wxConceptControl :: getMaxValue()
168 void wxConceptControl :: setActualValue(int theActual)
170 conceptSlider->SetValue(theActual);
173 int wxConceptControl :: getActualValue()
175 return conceptSlider->GetValue();
178 void wxConceptControl :: setShowLables(bool ifShowCondition)
180 showLabels = ifShowCondition;
181 //TODO -----UPDATE the slider too!!
186 //------------------------------------------------------------------------------------------------------------
187 // Other functional methods
188 //------------------------------------------------------------------------------------------------------------
190 void wxConceptControl :: clearCheckAt( int position )
192 checkBoxes[position]->SetValue( false );
194 //------------------------------------------------------------------------------------------------------------
195 bool wxConceptControl :: getIfChecked( int position )
197 return checkBoxes[position]->GetValue();
199 //------------------------------------------------------------------------------------------------------------
200 void wxConceptControl :: setRange(int minShow, int maxShow)
203 if( minShow < minVal )
205 if( maxShow > maxVal )
208 conceptSlider->SetRange(minShow, maxShow);
209 int actual = getActualValue();
211 conceptSlider->SetValue( minShow );
212 else if( actual>maxShow )
213 conceptSlider->SetValue( maxShow );
215 //------------------------------------------------------------------------------------------------------------
216 void wxConceptControl :: reset()
218 conceptSlider->SetRange(minValue, maxValue);
219 conceptSlider->SetValue(minValue);
220 int i, size = checkBoxes.size();
221 for(i=0; i<size; i++)
223 (checkBoxes[i])->SetValue( false );
225 size = textBoxes.size();
226 for ( i =0; i<size; i++)
228 textBoxes[i]->Clear();
232 //------------------------------------------------------------------------------------------------------------
233 // Creational and initialization methods
234 //------------------------------------------------------------------------------------------------------------
235 void wxConceptControl :: createElements(wxSizer *sizer , std::string elementsDef )
237 const char * elements = elementsDef.c_str();
238 int elementsNum = elementsDef.size();
239 wxFlexGridSizer* checkSizer = new wxFlexGridSizer (1, elementsNum, 5, 5);
241 for( i = 0;*elements!= 0; elements++)
244 if( a == 67 || a == 99 )// Including C:67 or c:99 as a checkBox (ASCII)
247 createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
249 createCheckBoxAndAddToSizer( checkSizer, "Y", -1, ckecks);
251 createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
254 else if ( a == 84 || a==116 )// Including T:84 or t t:116 as textCtrl (ASCII)
260 _numCheckBox = ckecks;
261 sizer->Add(checkSizer, 0, wxGROW |wxALL );
264 int wxConceptControl :: getNumCheckBox(){
268 //------------------------------------------------------------------------------------------------------------
269 wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
272 //itoa( groupID, buffer, 10);
281 char temp = k % 10 + 48;
283 buffer = temp + buffer;
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 );
297 //------------------------------------------------------------------------------------------------------------
298 /*wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
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);