KiCad PCB EDA Suite
TUNER_SLIDER Class Reference

Custom widget to handle quick component values modification and simulation on the fly. More...

#include <tuner_slider.h>

Inheritance diagram for TUNER_SLIDER:
TUNER_SLIDER_BASE

Public Member Functions

 TUNER_SLIDER (SIM_PLOT_FRAME *aFrame, wxWindow *aParent, SCH_COMPONENT *aComponent)
 
wxString GetComponentName () const
 
const wxString & GetSpiceName () const
 
const SPICE_VALUEGetValue () const
 
const SPICE_VALUEGetMin () const
 
const SPICE_VALUEGetMax () const
 
bool SetValue (const SPICE_VALUE &aVal)
 
bool SetMin (const SPICE_VALUE &aVal)
 
bool SetMax (const SPICE_VALUE &aVal)
 

Protected Attributes

wxStaticText * m_name
 
wxButton * m_closeBtn
 
wxSlider * m_slider
 
wxTextCtrl * m_maxText
 
wxTextCtrl * m_valueText
 
wxTextCtrl * m_minText
 
wxButton * m_saveBtn
 

Private Member Functions

void updateComponentValue ()
 
void updateSlider ()
 
void updateValueText ()
 
void onClose (wxCommandEvent &event) override
 
void onSave (wxCommandEvent &event) override
 
void onSliderChanged (wxScrollEvent &event) override
 
void onMaxTextEnter (wxCommandEvent &event) override
 
void onValueTextEnter (wxCommandEvent &event) override
 
void onMinTextEnter (wxCommandEvent &event) override
 
void onSimTimer (wxTimerEvent &event)
 

Private Attributes

wxString m_spiceName
 
wxTimer m_simTimer
 

Timer that restarts the simulation after the slider value has changed

More...
 
SCH_COMPONENTm_component
 
SPICE_VALUE m_min
 
SPICE_VALUE m_max
 
SPICE_VALUE m_value
 
bool m_changed
 
SIM_PLOT_FRAMEm_frame
 

Detailed Description

Custom widget to handle quick component values modification and simulation on the fly.

Definition at line 40 of file tuner_slider.h.

Constructor & Destructor Documentation

TUNER_SLIDER::TUNER_SLIDER ( SIM_PLOT_FRAME aFrame,
wxWindow *  aParent,
SCH_COMPONENT aComponent 
)

Definition at line 32 of file tuner_slider.cpp.

References SCH_COMPONENT::GetField(), NETLIST_EXPORTER_PSPICE::GetSpiceField(), EDA_TEXT::GetText(), m_changed, m_max, TUNER_SLIDER_BASE::m_maxText, m_min, TUNER_SLIDER_BASE::m_minText, TUNER_SLIDER_BASE::m_name, m_simTimer, m_spiceName, m_value, onSimTimer(), REFERENCE, SF_PRIMITIVE, SPICE_VALUE::ToOrigString(), updateSlider(), updateValueText(), and VALUE.

33  : TUNER_SLIDER_BASE( aParent ), m_component( aComponent ),
34  m_min( 0.0 ), m_max( 0.0 ), m_value( 0.0 ), m_frame ( aFrame )
35 {
36  const wxString compName = aComponent->GetField( REFERENCE )->GetText();
37  m_name->SetLabel( compName );
38  m_value = SPICE_VALUE( aComponent->GetField( VALUE )->GetText() );
39  m_changed = false;
40 
41  // Generate Spice component name
42  char prim = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, aComponent, 0 )[0];
43  m_spiceName = wxString( prim + compName ).Lower();
44 
45  // Call Set*() methods to update fields and slider
46  m_max = SPICE_VALUE( 2.0 ) * m_value;
47  m_min = SPICE_VALUE( 0.5 ) * m_value;
48 
49  m_minText->SetValue( m_min.ToOrigString() );
50  m_maxText->SetValue( m_max.ToOrigString() );
51 
53  updateSlider();
54 
55  m_simTimer.SetOwner( this );
56  Connect( wxEVT_TIMER, wxTimerEventHandler( TUNER_SLIDER::onSimTimer ), NULL, this );
57 }
void onSimTimer(wxTimerEvent &event)
void updateSlider()
wxTimer m_simTimer
Timer that restarts the simulation after the slider value has changed
Definition: tuner_slider.h:92
wxStaticText * m_name
Field Reference of part, i.e. "IC21".
SPICE_VALUE m_min
Definition: tuner_slider.h:96
wxString m_spiceName
Definition: tuner_slider.h:89
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SPICE_VALUE m_max
Definition: tuner_slider.h:96
TUNER_SLIDER_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(97, 283), long style=wxTAB_TRAVERSAL)
wxTextCtrl * m_maxText
wxTextCtrl * m_minText
static wxString GetSpiceField(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves either the requested field value or the default value.
void updateValueText()
SCH_COMPONENT * m_component
Definition: tuner_slider.h:94
#define VALUE
SIM_PLOT_FRAME * m_frame
Definition: tuner_slider.h:99
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90

Member Function Documentation

wxString TUNER_SLIDER::GetComponentName ( ) const
inline

Definition at line 45 of file tuner_slider.h.

References TUNER_SLIDER_BASE::m_name.

46  {
47  return m_name->GetLabel();
48  }
wxStaticText * m_name
const SPICE_VALUE& TUNER_SLIDER::GetMax ( ) const
inline

Definition at line 65 of file tuner_slider.h.

References m_max.

66  {
67  return m_max;
68  }
SPICE_VALUE m_max
Definition: tuner_slider.h:96
const SPICE_VALUE& TUNER_SLIDER::GetMin ( ) const
inline

Definition at line 60 of file tuner_slider.h.

References m_min.

61  {
62  return m_min;
63  }
SPICE_VALUE m_min
Definition: tuner_slider.h:96
const wxString& TUNER_SLIDER::GetSpiceName ( ) const
inline

Definition at line 50 of file tuner_slider.h.

References m_spiceName.

51  {
52  return m_spiceName;
53  }
wxString m_spiceName
Definition: tuner_slider.h:89
const SPICE_VALUE& TUNER_SLIDER::GetValue ( ) const
inline

Definition at line 55 of file tuner_slider.h.

References m_value.

56  {
57  return m_value;
58  }
SPICE_VALUE m_value
Definition: tuner_slider.h:96
void TUNER_SLIDER::onClose ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 134 of file tuner_slider.cpp.

References m_frame, and SIM_PLOT_FRAME::RemoveTuner().

135 {
136  m_frame->RemoveTuner( this );
137 }
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Removes an existing tuner.
SIM_PLOT_FRAME * m_frame
Definition: tuner_slider.h:99
void TUNER_SLIDER::onMaxTextEnter ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 156 of file tuner_slider.cpp.

References m_max, TUNER_SLIDER_BASE::m_maxText, SetMax(), and SPICE_VALUE::ToOrigString().

157 {
158  try
159  {
160  SPICE_VALUE newMax( m_maxText->GetValue() );
161  SetMax( newMax );
162  }
163  catch( std::exception& e )
164  {
165  // Restore the previous value
166  m_maxText->SetValue( m_max.ToOrigString() );
167  }
168 }
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
SPICE_VALUE m_max
Definition: tuner_slider.h:96
wxTextCtrl * m_maxText
bool SetMax(const SPICE_VALUE &aVal)
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90
void TUNER_SLIDER::onMinTextEnter ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 187 of file tuner_slider.cpp.

References m_min, TUNER_SLIDER_BASE::m_minText, SetMin(), and SPICE_VALUE::ToOrigString().

188 {
189  try
190  {
191  SPICE_VALUE newMin( m_minText->GetValue() );
192  SetMin( newMin );
193  }
194  catch( std::exception& e )
195  {
196  // Restore the previous value
197  m_minText->SetValue( m_min.ToOrigString() );
198  }
199 }
SPICE_VALUE m_min
Definition: tuner_slider.h:96
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
wxTextCtrl * m_minText
bool SetMin(const SPICE_VALUE &aVal)
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90
void TUNER_SLIDER::onSave ( wxCommandEvent &  event)
overrideprivatevirtual
Todo:
it will crash when component is removed; completely remove m_component

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 140 of file tuner_slider.cpp.

References SCH_COMPONENT::GetField(), m_component, m_value, EDA_TEXT::SetText(), SPICE_VALUE::ToOrigString(), and VALUE.

141 {
144 }
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SCH_COMPONENT * m_component
Definition: tuner_slider.h:94
#define VALUE
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90
void TUNER_SLIDER::onSimTimer ( wxTimerEvent &  event)
private

Definition at line 202 of file tuner_slider.cpp.

References m_changed, and m_frame.

Referenced by TUNER_SLIDER().

203 {
204  if(m_changed)
205  {
206  wxQueueEvent( m_frame, new wxCommandEvent( EVT_SIM_UPDATE ) );
207  m_changed = false;
208  }
209 }
SIM_PLOT_FRAME * m_frame
Definition: tuner_slider.h:99
void TUNER_SLIDER::onSliderChanged ( wxScrollEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 147 of file tuner_slider.cpp.

References m_changed, m_max, m_min, TUNER_SLIDER_BASE::m_slider, m_value, updateComponentValue(), and updateValueText().

148 {
149  m_value = m_min + ( m_max - m_min ) * SPICE_VALUE( m_slider->GetValue() / 100.0 );
150  updateValueText();
152  m_changed = true;
153 }
SPICE_VALUE m_min
Definition: tuner_slider.h:96
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SPICE_VALUE m_max
Definition: tuner_slider.h:96
void updateValueText()
void updateComponentValue()
void TUNER_SLIDER::onValueTextEnter ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 171 of file tuner_slider.cpp.

References m_changed, m_value, TUNER_SLIDER_BASE::m_valueText, SetValue(), and SPICE_VALUE::ToOrigString().

172 {
173  try
174  {
175  SPICE_VALUE newCur( m_valueText->GetValue() );
176  SetValue( newCur );
177  m_changed = true;
178  }
179  catch( std::exception& e )
180  {
181  // Restore the previous value
182  m_valueText->SetValue( m_value.ToOrigString() );
183  }
184 }
wxTextCtrl * m_valueText
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
bool SetValue(const SPICE_VALUE &aVal)
SPICE_VALUE m_value
Definition: tuner_slider.h:96
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90
bool TUNER_SLIDER::SetMax ( const SPICE_VALUE aVal)

Definition at line 95 of file tuner_slider.cpp.

References m_max, TUNER_SLIDER_BASE::m_maxText, m_min, m_value, SetValue(), SPICE_VALUE::ToOrigString(), and updateSlider().

Referenced by onMaxTextEnter().

96 {
97  if( aVal <= m_min )
98  return false;
99 
100  m_max = aVal;
101 
102  if( m_value > aVal ) // Limit the current value
103  SetValue( aVal );
104 
105  m_maxText->SetValue( aVal.ToOrigString() );
106  updateSlider();
107 
108  return true;
109 }
void updateSlider()
SPICE_VALUE m_min
Definition: tuner_slider.h:96
bool SetValue(const SPICE_VALUE &aVal)
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SPICE_VALUE m_max
Definition: tuner_slider.h:96
wxTextCtrl * m_maxText
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90
bool TUNER_SLIDER::SetMin ( const SPICE_VALUE aVal)

Definition at line 78 of file tuner_slider.cpp.

References m_max, m_min, TUNER_SLIDER_BASE::m_minText, m_value, SetValue(), SPICE_VALUE::ToOrigString(), and updateSlider().

Referenced by onMinTextEnter().

79 {
80  if( aVal >= m_max )
81  return false;
82 
83  m_min = aVal;
84 
85  if( m_value < aVal ) // Limit the curent value
86  SetValue( aVal );
87 
88  m_minText->SetValue( aVal.ToOrigString() );
89  updateSlider();
90 
91  return true;
92 }
void updateSlider()
SPICE_VALUE m_min
Definition: tuner_slider.h:96
bool SetValue(const SPICE_VALUE &aVal)
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SPICE_VALUE m_max
Definition: tuner_slider.h:96
wxTextCtrl * m_minText
wxString ToOrigString() const
Returns either a normal string or Spice format string, depending on the original value format...
Definition: spice_value.h:90
bool TUNER_SLIDER::SetValue ( const SPICE_VALUE aVal)

Definition at line 60 of file tuner_slider.cpp.

References m_max, m_min, m_value, updateComponentValue(), updateSlider(), and updateValueText().

Referenced by onValueTextEnter(), SetMax(), and SetMin().

61 {
62  // Get the value into the current range boundaries
63  if( aVal > m_max )
64  m_value = m_max;
65  else if( aVal < m_min )
66  m_value = m_min;
67  else
68  m_value = aVal;
69 
71  updateSlider();
73 
74  return true;
75 }
void updateSlider()
SPICE_VALUE m_min
Definition: tuner_slider.h:96
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SPICE_VALUE m_max
Definition: tuner_slider.h:96
void updateValueText()
void updateComponentValue()
void TUNER_SLIDER::updateComponentValue ( )
private

Definition at line 112 of file tuner_slider.cpp.

References m_simTimer.

Referenced by onSliderChanged(), and SetValue().

113 {
114  // Start simulation in 100 ms, if the value does not change meanwhile
115  m_simTimer.StartOnce( 100 );
116 }
wxTimer m_simTimer
Timer that restarts the simulation after the slider value has changed
Definition: tuner_slider.h:92
void TUNER_SLIDER::updateSlider ( )
private

Definition at line 119 of file tuner_slider.cpp.

References m_max, m_min, TUNER_SLIDER_BASE::m_slider, and m_value.

Referenced by SetMax(), SetMin(), SetValue(), and TUNER_SLIDER().

120 {
121  assert( m_max >= m_value && m_value >= m_min );
122 
123  m_slider->SetValue( ( ( m_value - m_min ) / ( m_max - m_min ) ).ToDouble() * 100.0 );
124 }
SPICE_VALUE m_min
Definition: tuner_slider.h:96
SPICE_VALUE m_value
Definition: tuner_slider.h:96
SPICE_VALUE m_max
Definition: tuner_slider.h:96
void TUNER_SLIDER::updateValueText ( )
private

Definition at line 127 of file tuner_slider.cpp.

References SPICE_VALUE::IsSpiceString(), m_max, m_min, m_value, TUNER_SLIDER_BASE::m_valueText, SPICE_VALUE::ToSpiceString(), and SPICE_VALUE::ToString().

Referenced by onSliderChanged(), SetValue(), and TUNER_SLIDER().

128 {
129  bool spiceString = m_min.IsSpiceString() || m_max.IsSpiceString();
130  m_valueText->SetValue( spiceString ? m_value.ToSpiceString() : m_value.ToString() );
131 }
wxString ToSpiceString() const
Returns string value in Spice format (e.g.
wxTextCtrl * m_valueText
bool IsSpiceString() const
Returns true if the object was initiated with a Spice formatted string value.
Definition: spice_value.h:98
SPICE_VALUE m_min
Definition: tuner_slider.h:96
SPICE_VALUE m_value
Definition: tuner_slider.h:96
wxString ToString() const
Returns string value as when converting double to string (e.g.
SPICE_VALUE m_max
Definition: tuner_slider.h:96

Member Data Documentation

bool TUNER_SLIDER::m_changed
private

Definition at line 97 of file tuner_slider.h.

Referenced by onSimTimer(), onSliderChanged(), onValueTextEnter(), and TUNER_SLIDER().

wxButton* TUNER_SLIDER_BASE::m_closeBtn
protectedinherited
SCH_COMPONENT* TUNER_SLIDER::m_component
private

Definition at line 94 of file tuner_slider.h.

Referenced by onSave().

SIM_PLOT_FRAME* TUNER_SLIDER::m_frame
private

Definition at line 99 of file tuner_slider.h.

Referenced by onClose(), and onSimTimer().

SPICE_VALUE TUNER_SLIDER::m_max
private
wxTextCtrl* TUNER_SLIDER_BASE::m_maxText
protectedinherited
SPICE_VALUE TUNER_SLIDER::m_min
private
wxTextCtrl* TUNER_SLIDER_BASE::m_minText
protectedinherited
wxStaticText* TUNER_SLIDER_BASE::m_name
protectedinherited
wxButton* TUNER_SLIDER_BASE::m_saveBtn
protectedinherited
wxTimer TUNER_SLIDER::m_simTimer
private

Timer that restarts the simulation after the slider value has changed

Definition at line 92 of file tuner_slider.h.

Referenced by TUNER_SLIDER(), and updateComponentValue().

wxSlider* TUNER_SLIDER_BASE::m_slider
protectedinherited
wxString TUNER_SLIDER::m_spiceName
private

Definition at line 89 of file tuner_slider.h.

Referenced by GetSpiceName(), and TUNER_SLIDER().

wxTextCtrl* TUNER_SLIDER_BASE::m_valueText
protectedinherited

The documentation for this class was generated from the following files: