2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "wxConceptControl.h"
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file wxConceptControl.cxx */
11 //IMPLEMENT_CLASS(wxConceptControl, wxScrolledWindow)
12 //------------------------------------------------------------------------------------------------------------
13 // Generated events declaration and definition
14 //------------------------------------------------------------------------------------------------------------
17 DEFINE_EVENT_TYPE( wxEVT_CONCEPT_RELEASE )
19 //------------------------------------------------------------------------------------------------------------
20 // Constructors & Destructors
21 //------------------------------------------------------------------------------------------------------------
23 wxConceptControl :: wxConceptControl(wxWindow *parent, bool orientation, int minV, int maxV, int actualV, std::string &aConceptName, std::string elementsDef )
24 :wxPanel(parent, -1, wxDefaultPosition, parent->GetSize(), wxTAB_TRAVERSAL)
32 wxFlexGridSizer* sizer = new wxFlexGridSizer (1, 3, 15, 15);
34 conceptName = new wxStaticText(this, -1, wxString(aConceptName.c_str(),wxConvUTF8), wxDefaultPosition, wxSize(90,20), wxALIGN_CENTRE );
35 sizer->Add( conceptName, 0, wxALIGN_CENTRE |wxALIGN_CENTER_HORIZONTAL);
39 sizer->AddGrowableCol(1);
40 conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8));
44 sizer->AddGrowableRow(1);
45 conceptSlider = new wxSlider(this, -1, actualV, minV, maxV, wxDefaultPosition, wxDefaultSize, wxSL_LEFT| wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator, wxString(aConceptName.c_str(),wxConvUTF8) );
47 sizer->Add(conceptSlider, 0, wxGROW |wxALL );
48 createElements( sizer, elementsDef );
51 Connect( conceptSlider->GetId(), wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(wxConceptControl::onSliderTrack));//(wxObjectEventFunction) &wxConceptControl :: onSliderRelease );
52 Connect( conceptSlider->GetId(), wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(wxConceptControl::onSliderRelease));//(wxObjectEventFunction) &wxConceptControl :: onSliderTrack );
54 this->SetAutoLayout( true );
58 wxConceptControl :: ~wxConceptControl()
63 //------------------------------------------------------------------------------------------------------------
64 // Methods for capturing events
65 //------------------------------------------------------------------------------------------------------------
68 void wxConceptControl ::onUpdateUICheckBox( wxCommandEvent& event )
70 lastUpdate = (wxCheckBox * ) event.GetEventObject();
71 std::string groupId = std::string(lastUpdate->GetName().ToAscii());
72 event.SetClientData( (void *) atoi(groupId.c_str()) );
73 event.SetId( GetId() );
74 event.SetEventObject( this );
75 GetEventHandler()->ProcessEvent( event );
77 //------------------------------------------------------------------------------------------------------------
78 void wxConceptControl :: onSliderTrack( wxScrollEvent& event )
83 //------------------------------------------------------------------------------------------------------------
85 void wxConceptControl :: onSliderRelease( wxScrollEvent& event )
87 // if( !resolutionChange )
88 sendEnvent( wxEVT_CONCEPT_RELEASE );
92 //------------------------------------------------------------------------------------------------------------
93 // Methods for sending events
94 //------------------------------------------------------------------------------------------------------------
96 void wxConceptControl :: sendEnvent(WXTYPE theEventType)
98 wxCommandEvent cevent( theEventType, GetId() );
99 cevent.SetEventObject( this );
100 GetEventHandler()->ProcessEvent( cevent );
103 //------------------------------------------------------------------------------------------------------------
104 // Attributes getters and setters
105 //------------------------------------------------------------------------------------------------------------
107 std::string wxConceptControl :: getName()
109 return std::string(conceptName->GetLabel().ToAscii()); //wxString to std::string convertor ?
112 int wxConceptControl :: getMinShowedValue()
114 return conceptSlider->GetMin();
117 int wxConceptControl :: getMaxShowedValue()
119 return conceptSlider->GetMax();
122 void wxConceptControl :: setMinValue(int theMin)
127 int wxConceptControl :: getMinValue()
132 void wxConceptControl :: setMaxValue(int theMax)
137 int wxConceptControl :: getMaxValue()
142 void wxConceptControl :: setActualValue(int theActual)
144 conceptSlider->SetValue(theActual);
147 int wxConceptControl :: getActualValue()
149 return conceptSlider->GetValue();
152 void wxConceptControl :: setShowLables(bool ifShowCondition)
154 showLabels = ifShowCondition;
155 //TODO -----UPDATE the slider too!!
160 //------------------------------------------------------------------------------------------------------------
161 // Other functional methods
162 //------------------------------------------------------------------------------------------------------------
164 void wxConceptControl :: clearCheckAt( int position )
166 checkBoxes[position]->SetValue( false );
168 //------------------------------------------------------------------------------------------------------------
169 bool wxConceptControl :: getIfChecked( int position )
171 return checkBoxes[position]->GetValue();
173 //------------------------------------------------------------------------------------------------------------
174 void wxConceptControl :: setRange(int minShow, int maxShow)
177 if( minShow < minVal )
179 if( maxShow > maxVal )
182 conceptSlider->SetRange(minShow, maxShow);
183 int actual = getActualValue();
185 conceptSlider->SetValue( minShow );
186 else if( actual>maxShow )
187 conceptSlider->SetValue( maxShow );
189 //------------------------------------------------------------------------------------------------------------
190 void wxConceptControl :: reset()
192 conceptSlider->SetRange(minValue, maxValue);
193 conceptSlider->SetValue(minValue);
194 int i, size = checkBoxes.size();
195 for(i=0; i<size; i++)
197 (checkBoxes[i])->SetValue( false );
199 size = textBoxes.size();
200 for ( i =0; i<size; i++)
202 textBoxes[i]->Clear();
206 //------------------------------------------------------------------------------------------------------------
207 // Creational and initialization methods
208 //------------------------------------------------------------------------------------------------------------
209 void wxConceptControl :: createElements(wxSizer *sizer , std::string elementsDef )
211 const char * elements = elementsDef.c_str();
212 int elementsNum = elementsDef.size();
213 wxFlexGridSizer* checkSizer = new wxFlexGridSizer (1, elementsNum, 5, 5);
215 for( i = 0;*elements!= 0; elements++)
218 if( a == 67 || a == 99 )// Including C:67 or c:99 as a checkBox (ASCII)
220 createCheckBoxAndAddToSizer( checkSizer, "", -1, ckecks);
223 else if ( a == 84 || a==116 )// Including T:84 or t t:116 as textCtrl (ASCII)
229 sizer->Add(checkSizer, 0, wxGROW |wxALL );
232 //------------------------------------------------------------------------------------------------------------
233 wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
236 itoa( groupID, buffer, 10);
237 wxCheckBox *checkbox = new wxCheckBox( this, -1, wxString( label.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString( buffer, wxConvUTF8) );
238 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
239 sizer->Add(0, 2, 0, wxGROW);
240 checkBoxes.push_back( checkbox );
241 Connect( checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) (wxCommandEventFunction) &wxConceptControl::onUpdateUICheckBox );
246 //------------------------------------------------------------------------------------------------------------
247 /*wxCheckBox * wxConceptControl :: createCheckBoxAndAddToSizer(wxSizer *sizer, std::string label, wxWindowID id,int groupID)
249 wxCheckBox *checkbox = new wxCheckBox(this, -1, wxString( label.c_str(), wxConvUTF8));
250 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
251 sizer->Add(0, 2, 0, wxGROW);