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 SIM_PLOT_FRAME::GetExporter(), SCH_COMPONENT::GetField(), NETLIST_EXPORTER_PSPICE::GetSpiceDevice(), 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, 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 
40  m_changed = false;
41  m_spiceName = aFrame->GetExporter()->GetSpiceDevice( compName ).Lower();
42 
43  // Call Set*() methods to update fields and slider
44  m_max = SPICE_VALUE( 2.0 ) * m_value;
45  m_min = SPICE_VALUE( 0.5 ) * m_value;
46 
47  m_minText->SetValue( m_min.ToOrigString() );
48  m_maxText->SetValue( m_max.ToOrigString() );
49 
51  updateSlider();
52 
53  m_simTimer.SetOwner( this );
54  Connect( wxEVT_TIMER, wxTimerEventHandler( TUNER_SLIDER::onSimTimer ), NULL, this );
55 }
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".
const NETLIST_EXPORTER_PSPICE_SIM * GetExporter() const
Returns the netlist exporter object used for simulations.
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:128
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
wxString GetSpiceDevice(const wxString &aComponent) const
Returns name of Spice device corresponding to a schematic component.
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 ( void  ) 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
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 132 of file tuner_slider.cpp.

References m_frame, and SIM_PLOT_FRAME::RemoveTuner().

Referenced by GetMax().

133 {
134  m_frame->RemoveTuner( this );
135 }
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 154 of file tuner_slider.cpp.

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

Referenced by GetMax().

155 {
156  try
157  {
158  SPICE_VALUE newMax( m_maxText->GetValue() );
159  SetMax( newMax );
160  }
161  catch( const KI_PARAM_ERROR& )
162  {
163  // Restore the previous value
164  m_maxText->SetValue( m_max.ToOrigString() );
165  }
166 }
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)
class KI_PARAM_ERROR is a class used to hold a translatable error message and may be used when throwi...
Definition: ki_exception.h:45
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 185 of file tuner_slider.cpp.

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

Referenced by GetMax().

186 {
187  try
188  {
189  SPICE_VALUE newMin( m_minText->GetValue() );
190  SetMin( newMin );
191  }
192  catch( const KI_PARAM_ERROR& )
193  {
194  // Restore the previous value
195  m_minText->SetValue( m_min.ToOrigString() );
196  }
197 }
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)
class KI_PARAM_ERROR is a class used to hold a translatable error message and may be used when throwi...
Definition: ki_exception.h:45
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 138 of file tuner_slider.cpp.

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

Referenced by GetMax().

139 {
142 }
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:139
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 200 of file tuner_slider.cpp.

References m_changed, and m_frame.

Referenced by GetMax(), and TUNER_SLIDER().

201 {
202  if(m_changed)
203  {
204  wxQueueEvent( m_frame, new wxCommandEvent( EVT_SIM_UPDATE ) );
205  m_changed = false;
206  }
207 }
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 145 of file tuner_slider.cpp.

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

Referenced by GetMax().

146 {
147  m_value = m_min + ( m_max - m_min ) * SPICE_VALUE( m_slider->GetValue() / 100.0 );
148  updateValueText();
150  m_changed = true;
151 }
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 169 of file tuner_slider.cpp.

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

Referenced by GetMax().

170 {
171  try
172  {
173  SPICE_VALUE newCur( m_valueText->GetValue() );
174  SetValue( newCur );
175  m_changed = true;
176  }
177  catch( const KI_PARAM_ERROR& )
178  {
179  // Restore the previous value
180  m_valueText->SetValue( m_value.ToOrigString() );
181  }
182 }
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
class KI_PARAM_ERROR is a class used to hold a translatable error message and may be used when throwi...
Definition: ki_exception.h:45
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 93 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 GetMax(), and onMaxTextEnter().

94 {
95  if( aVal <= m_min )
96  return false;
97 
98  m_max = aVal;
99 
100  if( m_value > aVal ) // Limit the current value
101  SetValue( aVal );
102 
103  m_maxText->SetValue( aVal.ToOrigString() );
104  updateSlider();
105 
106  return true;
107 }
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 76 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 GetMax(), and onMinTextEnter().

77 {
78  if( aVal >= m_max )
79  return false;
80 
81  m_min = aVal;
82 
83  if( m_value < aVal ) // Limit the curent value
84  SetValue( aVal );
85 
86  m_minText->SetValue( aVal.ToOrigString() );
87  updateSlider();
88 
89  return true;
90 }
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 58 of file tuner_slider.cpp.

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

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

59 {
60  // Get the value into the current range boundaries
61  if( aVal > m_max )
62  m_value = m_max;
63  else if( aVal < m_min )
64  m_value = m_min;
65  else
66  m_value = aVal;
67 
69  updateSlider();
71 
72  return true;
73 }
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 110 of file tuner_slider.cpp.

References m_simTimer.

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

111 {
112  // Start simulation in 100 ms, if the value does not change meanwhile
113  m_simTimer.StartOnce( 100 );
114 }
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 117 of file tuner_slider.cpp.

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

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

118 {
119  assert( m_max >= m_value && m_value >= m_min );
120 
121  m_slider->SetValue( ( ( m_value - m_min ) / ( m_max - m_min ) ).ToDouble() * 100.0 );
122 }
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 125 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 GetMax(), onSliderChanged(), SetValue(), and TUNER_SLIDER().

126 {
127  bool spiceString = m_min.IsSpiceString() || m_max.IsSpiceString();
128  m_valueText->SetValue( spiceString ? m_value.ToSpiceString() : m_value.ToString() );
129 }
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: