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_SYMBOL *aSymbol)
 
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 updateMax ()
 
void updateValue ()
 
void updateMin ()
 
void onClose (wxCommandEvent &event) override
 
void onSave (wxCommandEvent &event) override
 
void onSliderChanged (wxScrollEvent &event) override
 
void onMaxKillFocus (wxFocusEvent &event) override
 
void onValueKillFocus (wxFocusEvent &event) override
 
void onMinKillFocus (wxFocusEvent &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
 Timer that restarts the simulation after the slider value has changed. More...
 
wxTimer m_simTimer
 
SCH_SYMBOLm_symbol
 
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 42 of file tuner_slider.h.

Constructor & Destructor Documentation

◆ TUNER_SLIDER()

TUNER_SLIDER::TUNER_SLIDER ( SIM_PLOT_FRAME aFrame,
wxWindow *  aParent,
SCH_SYMBOL aSymbol 
)

Definition at line 34 of file tuner_slider.cpp.

35  : TUNER_SLIDER_BASE( aParent ), m_symbol( aSymbol ),
36  m_min( 0.0 ), m_max( 0.0 ), m_value( 0.0 ), m_frame ( aFrame )
37 {
38  const wxString compName = aSymbol->GetField( REFERENCE_FIELD )->GetText();
39  m_name->SetLabel( compName );
40  m_value = SPICE_VALUE( aSymbol->GetField( VALUE_FIELD )->GetText() );
41 
42  m_changed = false;
43  m_spiceName = aFrame->GetExporter()->GetSpiceDevice( 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 ), nullptr, this );
57 }
Field Reference of part, i.e. "IC21".
void onSimTimer(wxTimerEvent &event)
void updateSlider()
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:675
wxTimer m_simTimer
Definition: tuner_slider.h:102
wxStaticText * m_name
wxString ToOrigString() const
Return either a normal string or Spice format string, depending on the original value format.
Definition: spice_value.h:92
SPICE_VALUE m_min
Definition: tuner_slider.h:106
TUNER_SLIDER_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(126, 283), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxString m_spiceName
Timer that restarts the simulation after the slider value has changed.
Definition: tuner_slider.h:99
Field Value of part, i.e. "3.3K".
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
Definition: spice_value.h:34
SPICE_VALUE m_value
Definition: tuner_slider.h:106
wxString GetSpiceDevice(const wxString &aSymbol) const
Return name of Spice device corresponding to a schematic symbol.
SPICE_VALUE m_max
Definition: tuner_slider.h:106
wxTextCtrl * m_maxText
SCH_SYMBOL * m_symbol
Definition: tuner_slider.h:104
wxTextCtrl * m_minText
const NETLIST_EXPORTER_PSPICE_SIM * GetExporter() const
Return the netlist exporter object used for simulations.
void updateValueText()
SIM_PLOT_FRAME * m_frame
Definition: tuner_slider.h:109
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154

References SIM_PLOT_FRAME::GetExporter(), SCH_SYMBOL::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_FIELD, SPICE_VALUE::ToOrigString(), updateSlider(), updateValueText(), and VALUE_FIELD.

Member Function Documentation

◆ GetComponentName()

wxString TUNER_SLIDER::GetComponentName ( ) const
inline

Definition at line 47 of file tuner_slider.h.

48  {
49  return m_name->GetLabel();
50  }
wxStaticText * m_name

References TUNER_SLIDER_BASE::m_name.

◆ GetMax()

const SPICE_VALUE& TUNER_SLIDER::GetMax ( ) const
inline

Definition at line 67 of file tuner_slider.h.

68  {
69  return m_max;
70  }
SPICE_VALUE m_max
Definition: tuner_slider.h:106

References m_max.

◆ GetMin()

const SPICE_VALUE& TUNER_SLIDER::GetMin ( ) const
inline

Definition at line 62 of file tuner_slider.h.

63  {
64  return m_min;
65  }
SPICE_VALUE m_min
Definition: tuner_slider.h:106

References m_min.

◆ GetSpiceName()

const wxString& TUNER_SLIDER::GetSpiceName ( ) const
inline

Definition at line 52 of file tuner_slider.h.

53  {
54  return m_spiceName;
55  }
wxString m_spiceName
Timer that restarts the simulation after the slider value has changed.
Definition: tuner_slider.h:99

References m_spiceName.

◆ GetValue()

const SPICE_VALUE& TUNER_SLIDER::GetValue ( ) const
inline

Definition at line 57 of file tuner_slider.h.

58  {
59  return m_value;
60  }
SPICE_VALUE m_value
Definition: tuner_slider.h:106

References m_value.

◆ onClose()

void TUNER_SLIDER::onClose ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 180 of file tuner_slider.cpp.

181 {
182  m_frame->RemoveTuner( this );
183 }
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Remove an existing tuner.
SIM_PLOT_FRAME * m_frame
Definition: tuner_slider.h:109

References m_frame, and SIM_PLOT_FRAME::RemoveTuner().

◆ onMaxKillFocus()

void TUNER_SLIDER::onMaxKillFocus ( wxFocusEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 202 of file tuner_slider.cpp.

203 {
204  updateMax();
205 }

References updateMax().

◆ onMaxTextEnter()

void TUNER_SLIDER::onMaxTextEnter ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 220 of file tuner_slider.cpp.

221 {
222  updateMax();
223 }

References updateMax().

◆ onMinKillFocus()

void TUNER_SLIDER::onMinKillFocus ( wxFocusEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 214 of file tuner_slider.cpp.

215 {
216  updateMin();
217 }

References updateMin().

◆ onMinTextEnter()

void TUNER_SLIDER::onMinTextEnter ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 232 of file tuner_slider.cpp.

233 {
234  updateMin();
235 }

References updateMin().

◆ onSave()

void TUNER_SLIDER::onSave ( wxCommandEvent &  event)
overrideprivatevirtual
Todo:
it will crash when component is removed; completely remove m_symbol

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 186 of file tuner_slider.cpp.

187 {
190 }
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:675
wxString ToOrigString() const
Return either a normal string or Spice format string, depending on the original value format.
Definition: spice_value.h:92
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
SPICE_VALUE m_value
Definition: tuner_slider.h:106
SCH_SYMBOL * m_symbol
Definition: tuner_slider.h:104

References SCH_SYMBOL::GetField(), m_symbol, m_value, EDA_TEXT::SetText(), SPICE_VALUE::ToOrigString(), and VALUE_FIELD.

◆ onSimTimer()

void TUNER_SLIDER::onSimTimer ( wxTimerEvent &  event)
private

Definition at line 238 of file tuner_slider.cpp.

239 {
240  if( m_changed )
241  {
242  wxQueueEvent( m_frame, new wxCommandEvent( EVT_SIM_UPDATE ) );
243  m_changed = false;
244  }
245 }
SIM_PLOT_FRAME * m_frame
Definition: tuner_slider.h:109

References m_changed, and m_frame.

Referenced by TUNER_SLIDER().

◆ onSliderChanged()

void TUNER_SLIDER::onSliderChanged ( wxScrollEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 193 of file tuner_slider.cpp.

194 {
195  m_value = m_min + ( m_max - m_min ) * SPICE_VALUE( m_slider->GetValue() / 100.0 );
196  updateValueText();
198  m_changed = true;
199 }
SPICE_VALUE m_min
Definition: tuner_slider.h:106
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
Definition: spice_value.h:34
SPICE_VALUE m_value
Definition: tuner_slider.h:106
SPICE_VALUE m_max
Definition: tuner_slider.h:106
void updateValueText()
void updateComponentValue()

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

◆ onValueKillFocus()

void TUNER_SLIDER::onValueKillFocus ( wxFocusEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 208 of file tuner_slider.cpp.

209 {
210  updateValue();
211 }
void updateValue()

References updateValue().

◆ onValueTextEnter()

void TUNER_SLIDER::onValueTextEnter ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from TUNER_SLIDER_BASE.

Definition at line 226 of file tuner_slider.cpp.

227 {
228  updateValue();
229 }
void updateValue()

References updateValue().

◆ SetMax()

bool TUNER_SLIDER::SetMax ( const SPICE_VALUE aVal)

Definition at line 95 of file tuner_slider.cpp.

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()
wxString ToOrigString() const
Return either a normal string or Spice format string, depending on the original value format.
Definition: spice_value.h:92
SPICE_VALUE m_min
Definition: tuner_slider.h:106
bool SetValue(const SPICE_VALUE &aVal)
SPICE_VALUE m_value
Definition: tuner_slider.h:106
SPICE_VALUE m_max
Definition: tuner_slider.h:106
wxTextCtrl * m_maxText

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

Referenced by updateMax().

◆ SetMin()

bool TUNER_SLIDER::SetMin ( const SPICE_VALUE aVal)

Definition at line 78 of file tuner_slider.cpp.

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

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

Referenced by updateMin().

◆ SetValue()

bool TUNER_SLIDER::SetValue ( const SPICE_VALUE aVal)

Definition at line 60 of file tuner_slider.cpp.

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:106
SPICE_VALUE m_value
Definition: tuner_slider.h:106
SPICE_VALUE m_max
Definition: tuner_slider.h:106
void updateValueText()
void updateComponentValue()

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

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

◆ updateComponentValue()

void TUNER_SLIDER::updateComponentValue ( )
private

Definition at line 112 of file tuner_slider.cpp.

113 {
114  // Start simulation in 100 ms, if the value does not change meanwhile
115  m_simTimer.StartOnce( 100 );
116 }
wxTimer m_simTimer
Definition: tuner_slider.h:102

References m_simTimer.

Referenced by onSliderChanged(), and SetValue().

◆ updateMax()

void TUNER_SLIDER::updateMax ( )
private

Definition at line 134 of file tuner_slider.cpp.

135 {
136  try
137  {
138  SPICE_VALUE newMax( m_maxText->GetValue() );
139  SetMax( newMax );
140  }
141  catch( const KI_PARAM_ERROR& )
142  {
143  // Restore the previous value
144  m_maxText->SetValue( m_max.ToOrigString() );
145  }
146 }
wxString ToOrigString() const
Return either a normal string or Spice format string, depending on the original value format.
Definition: spice_value.h:92
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
Definition: spice_value.h:34
SPICE_VALUE m_max
Definition: tuner_slider.h:106
wxTextCtrl * m_maxText
bool SetMax(const SPICE_VALUE &aVal)
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
Definition: ki_exception.h:44

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

Referenced by onMaxKillFocus(), and onMaxTextEnter().

◆ updateMin()

void TUNER_SLIDER::updateMin ( )
private

Definition at line 165 of file tuner_slider.cpp.

166 {
167  try
168  {
169  SPICE_VALUE newMin( m_minText->GetValue() );
170  SetMin( newMin );
171  }
172  catch( const KI_PARAM_ERROR& )
173  {
174  // Restore the previous value
175  m_minText->SetValue( m_min.ToOrigString() );
176  }
177 }
wxString ToOrigString() const
Return either a normal string or Spice format string, depending on the original value format.
Definition: spice_value.h:92
SPICE_VALUE m_min
Definition: tuner_slider.h:106
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
Definition: spice_value.h:34
wxTextCtrl * m_minText
bool SetMin(const SPICE_VALUE &aVal)
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
Definition: ki_exception.h:44

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

Referenced by onMinKillFocus(), and onMinTextEnter().

◆ updateSlider()

void TUNER_SLIDER::updateSlider ( )
private

Definition at line 119 of file tuner_slider.cpp.

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:106
SPICE_VALUE m_value
Definition: tuner_slider.h:106
SPICE_VALUE m_max
Definition: tuner_slider.h:106

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

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

◆ updateValue()

void TUNER_SLIDER::updateValue ( )
private

Definition at line 149 of file tuner_slider.cpp.

150 {
151  try
152  {
153  SPICE_VALUE newCur( m_valueText->GetValue() );
154  SetValue( newCur );
155  m_changed = true;
156  }
157  catch( const KI_PARAM_ERROR& )
158  {
159  // Restore the previous value
160  m_valueText->SetValue( m_value.ToOrigString() );
161  }
162 }
wxTextCtrl * m_valueText
wxString ToOrigString() const
Return either a normal string or Spice format string, depending on the original value format.
Definition: spice_value.h:92
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
Definition: spice_value.h:34
bool SetValue(const SPICE_VALUE &aVal)
SPICE_VALUE m_value
Definition: tuner_slider.h:106
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
Definition: ki_exception.h:44

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

Referenced by onValueKillFocus(), and onValueTextEnter().

◆ updateValueText()

void TUNER_SLIDER::updateValueText ( )
private

Definition at line 127 of file tuner_slider.cpp.

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
Return string value in Spice format (e.g.
wxTextCtrl * m_valueText
bool IsSpiceString() const
Return true if the object was initiated with a Spice formatted string value.
Definition: spice_value.h:100
SPICE_VALUE m_min
Definition: tuner_slider.h:106
wxString ToString() const
Return string value as when converting double to string (e.g.
SPICE_VALUE m_value
Definition: tuner_slider.h:106
SPICE_VALUE m_max
Definition: tuner_slider.h:106

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().

Member Data Documentation

◆ m_changed

bool TUNER_SLIDER::m_changed
private

Definition at line 107 of file tuner_slider.h.

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

◆ m_closeBtn

wxButton* TUNER_SLIDER_BASE::m_closeBtn
protectedinherited

◆ m_frame

SIM_PLOT_FRAME* TUNER_SLIDER::m_frame
private

Definition at line 109 of file tuner_slider.h.

Referenced by onClose(), and onSimTimer().

◆ m_max

SPICE_VALUE TUNER_SLIDER::m_max
private

◆ m_maxText

wxTextCtrl* TUNER_SLIDER_BASE::m_maxText
protectedinherited

◆ m_min

SPICE_VALUE TUNER_SLIDER::m_min
private

◆ m_minText

wxTextCtrl* TUNER_SLIDER_BASE::m_minText
protectedinherited

◆ m_name

wxStaticText* TUNER_SLIDER_BASE::m_name
protectedinherited

◆ m_saveBtn

wxButton* TUNER_SLIDER_BASE::m_saveBtn
protectedinherited

◆ m_simTimer

wxTimer TUNER_SLIDER::m_simTimer
private

Definition at line 102 of file tuner_slider.h.

Referenced by TUNER_SLIDER(), and updateComponentValue().

◆ m_slider

wxSlider* TUNER_SLIDER_BASE::m_slider
protectedinherited

◆ m_spiceName

wxString TUNER_SLIDER::m_spiceName
private

Timer that restarts the simulation after the slider value has changed.

Definition at line 99 of file tuner_slider.h.

Referenced by GetSpiceName(), and TUNER_SLIDER().

◆ m_symbol

SCH_SYMBOL* TUNER_SLIDER::m_symbol
private

Definition at line 104 of file tuner_slider.h.

Referenced by onSave().

◆ m_value

SPICE_VALUE TUNER_SLIDER::m_value
private

◆ m_valueText

wxTextCtrl* TUNER_SLIDER_BASE::m_valueText
protectedinherited

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