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)
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);
60 wxFlexGridSizer* sizer = new wxFlexGridSizer(3);
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);
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));
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) );
72 sizer->Add(conceptSlider, 0, wxGROW |wxALL );
73 createElements( sizer, elementsDef );
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 );
81 wxConceptControl :: ~wxConceptControl()
86 //------------------------------------------------------------------------------------------------------------
87 // Methods for capturing events
88 //------------------------------------------------------------------------------------------------------------
91 void wxConceptControl ::onUpdateUICheckBox( wxCommandEvent& event )
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 );
100 //------------------------------------------------------------------------------------------------------------
101 void wxConceptControl :: onSliderTrack( wxScrollEvent& event )
106 //------------------------------------------------------------------------------------------------------------
108 void wxConceptControl :: onSliderRelease( wxScrollEvent& event )
110 // if( !resolutionChange )
111 sendEnvent( wxEVT_CONCEPT_RELEASE );
115 //------------------------------------------------------------------------------------------------------------
116 // Methods for sending events
117 //------------------------------------------------------------------------------------------------------------
119 void wxConceptControl :: sendEnvent(WXTYPE theEventType)
121 wxCommandEvent cevent( theEventType, GetId() );
122 cevent.SetEventObject( this );
123 GetEventHandler()->ProcessEvent( cevent );
126 //------------------------------------------------------------------------------------------------------------
127 // Attributes getters and setters
128 //------------------------------------------------------------------------------------------------------------
130 std::string wxConceptControl :: getName()
132 return std::string(conceptName->GetLabel().ToAscii()); //wxString to std::string convertor ?
135 int wxConceptControl :: getMinShowedValue()
137 return conceptSlider->GetMin();
140 int wxConceptControl :: getMaxShowedValue()
142 return conceptSlider->GetMax();
145 void wxConceptControl :: setMinValue(int theMin)
150 int wxConceptControl :: getMinValue()
155 void wxConceptControl :: setMaxValue(int theMax)
160 int wxConceptControl :: getMaxValue()
165 void wxConceptControl :: setActualValue(int theActual)
167 conceptSlider->SetValue(theActual);
170 int wxConceptControl :: getActualValue()
172 return conceptSlider->GetValue();
175 void wxConceptControl :: setShowLables(bool ifShowCondition)
177 showLabels = ifShowCondition;
178 //TODO -----UPDATE the slider too!!
183 //------------------------------------------------------------------------------------------------------------
184 // Other functional methods
185 //------------------------------------------------------------------------------------------------------------
187 void wxConceptControl :: clearCheckAt( int position )
189 checkBoxes[position]->SetValue( false );
191 //------------------------------------------------------------------------------------------------------------
192 bool wxConceptControl :: getIfChecked( int position )
194 return checkBoxes[position]->GetValue();
196 //------------------------------------------------------------------------------------------------------------
197 void wxConceptControl :: setRange(int minShow, int maxShow)
200 if( minShow < minVal )
202 if( maxShow > maxVal )
205 conceptSlider->SetRange(minShow, maxShow);
206 int actual = getActualValue();
208 conceptSlider->SetValue( minShow );
209 else if( actual>maxShow )
210 conceptSlider->SetValue( maxShow );
212 //------------------------------------------------------------------------------------------------------------
213 void wxConceptControl :: reset()
215 conceptSlider->SetRange(minValue, maxValue);
216 conceptSlider->SetValue(minValue);
217 int i, size = checkBoxes.size();
218 for(i=0; i<size; i++)
220 (checkBoxes[i])->SetValue( false );
222 size = textBoxes.size();
223 for ( i =0; i<size; i++)
225 textBoxes[i]->Clear();
229 //------------------------------------------------------------------------------------------------------------
230 // Creational and initialization methods
231 //------------------------------------------------------------------------------------------------------------
232 void wxConceptControl::createElements(wxSizer *sizer , std::string elementsDef )
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);
240 wxFlexGridSizer* checkSizer = new wxFlexGridSizer(elementsNum);
243 for( i = 0;*elements!= 0; elements++)
246 if( a == 67 || a == 99 )// Including C:67 or c:99 as a checkBox (ASCII)
249 createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
251 createCheckBoxAndAddToSizer( checkSizer, "Y", -1, ckecks);
253 createCheckBoxAndAddToSizer( checkSizer, "X", -1, ckecks);
255 } else if ( a == 84 || a==116 )// Including T:84 or t t:116 as textCtrl (ASCII)
261 _numCheckBox = ckecks;
262 sizer->Add(checkSizer, 0, wxGROW |wxALL );
265 int wxConceptControl :: getNumCheckBox(){
269 //------------------------------------------------------------------------------------------------------------
270 wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
273 //itoa( groupID, buffer, 10);
282 char temp = k % 10 + 48;
284 buffer = temp + buffer;
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 );
298 //------------------------------------------------------------------------------------------------------------
299 /*wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
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);