KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SIM_SIGNAL Namespace Reference

Text handling for simulator signal expressions and measurement commands. More...

Enumerations

enum class  PART { VALUE , GAIN , PHASE , AMPLITUDE }
 Which part of a complex signal a plotted row shows. More...
 

Functions

bool IsSingleVoltageRef (const wxString &aExpression)
 
bool IsMeasVector (const wxString &aSignal)
 
bool MeasurableSignal (const wxString &aBase, PART aPart, wxString &aResult)
 Build the signal a measurement should read so it matches what is plotted.
 
void SplitMeasurement (const wxString &aCmd, wxString &aFunc, wxString &aSignal, wxString &aParams)
 Split "MAX V(out) from=1m to=2m" into its function, signal and trailing parameters.
 
wxString ExpandDeviceVoltages (const wxString &aExpression, const std::map< wxString, wxString > &aDeviceExprs)
 Replace V(R1), VDB(R1), VM(R1), ... with the terminal voltage expression of the part.
 
wxString QuoteNetNames (const wxString &aExpression, const std::vector< wxString > &aNetnames)
 Quote every whole occurrence of a net name that ngspice would otherwise parse as an expression.
 
bool ParensBalanced (const wxString &aExpression)
 
std::vector< wxString > ExtractSignalRefs (const wxString &aExpression)
 Extract the V() and I() and P() node or device references from an expression, unquoted.
 
wxString DeviceVoltageExpression (const std::vector< std::string > &aModelPins, const std::vector< std::string > &aPinNumbers, const std::vector< std::string > &aPinNetNames)
 Build the voltage across a two-terminal part in its model's pin order, matching the sign of I() and P().
 
bool IsDerivedSignalVector (const wxString &aVectorName)
 

Variables

const wxString DEVICE_VECTOR_PREFIX = wxS( "kicad_vdev" )
 Vector name prefix for the voltage across a component, "kicad_vdev3".
 

Detailed Description

Text handling for simulator signal expressions and measurement commands.

These work on the strings the simulator frame hands to ngspice and hold no frame state.

Enumeration Type Documentation

◆ PART

enum class SIM_SIGNAL::PART
strong

Which part of a complex signal a plotted row shows.

Enumerator
VALUE 
GAIN 

AC magnitude, plotted in dB.

PHASE 
AMPLITUDE 

S-parameter magnitude, plotted linear.

Definition at line 38 of file sim_signal_utils.h.

Function Documentation

◆ DeviceVoltageExpression()

wxString SIM_SIGNAL::DeviceVoltageExpression ( const std::vector< std::string > & aModelPins,
const std::vector< std::string > & aPinNumbers,
const std::vector< std::string > & aPinNetNames )

Build the voltage across a two-terminal part in its model's pin order, matching the sign of I() and P().

Parameters
aModelPinssymbol pin numbers in the order the SPICE model declares its terminals.
aPinNumberssymbol pin numbers of the netlist item.
aPinNetNamesSPICE net names, parallel to aPinNumbers.
Returns
the expression, or empty if the part has no voltage across it.

Definition at line 482 of file sim_signal_utils.cpp.

References index.

Referenced by BOOST_AUTO_TEST_CASE(), and SIMULATOR_FRAME_UI::rebuildDeviceVoltages().

◆ ExpandDeviceVoltages()

wxString SIM_SIGNAL::ExpandDeviceVoltages ( const wxString & aExpression,
const std::map< wxString, wxString > & aDeviceExprs )

Replace V(R1), VDB(R1), VM(R1), ... with the terminal voltage expression of the part.

Parameters
aDeviceExprsmaps a reference ("R1") to its expression ("V(a) - V(b)"). Matching ignores case, like ngspice. Inserted text is never rescanned.

Definition at line 200 of file sim_signal_utils.cpp.

References result.

Referenced by BOOST_AUTO_TEST_CASE(), and SIMULATOR_FRAME_UI::expandDeviceVoltages().

◆ ExtractSignalRefs()

std::vector< wxString > SIM_SIGNAL::ExtractSignalRefs ( const wxString & aExpression)

Extract the V() and I() and P() node or device references from an expression, unquoted.

A two-node V(a,b) yields one reference per node; ground is omitted. VDB(), VM(), VP(), VR() and VI() count as voltage references.

Definition at line 382 of file sim_signal_utils.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and DIALOG_USER_DEFINED_SIGNALS::onCheckSyntax().

◆ IsDerivedSignalVector()

bool SIM_SIGNAL::IsDerivedSignalVector ( const wxString & aVectorName)
Returns
true for a vector KiCad derives with a let command, "user3" or "kicad_vdev3", in any case.

Definition at line 525 of file sim_signal_utils.cpp.

References DEVICE_VECTOR_PREFIX.

Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_USER_DEFINED_SIGNALS::onScintillaCharAdded(), SIMULATOR_FRAME_UI::UpdateMeasurement(), and SIMULATOR_FRAME_UI::updateTrace().

◆ IsMeasVector()

bool SIM_SIGNAL::IsMeasVector ( const wxString & aSignal)
Returns
true if a .meas function takes aSignal as it is: a vector name or a V(), VDB(), ..., I() reference.

Definition at line 71 of file sim_signal_utils.cpp.

Referenced by SIMULATOR_FRAME_UI::UpdateMeasurement().

◆ IsSingleVoltageRef()

bool SIM_SIGNAL::IsSingleVoltageRef ( const wxString & aExpression)
Returns
true for a single V(...) reference, not a compound expression.

Definition at line 48 of file sim_signal_utils.cpp.

Referenced by MeasurableSignal().

◆ MeasurableSignal()

bool SIM_SIGNAL::MeasurableSignal ( const wxString & aBase,
PART aPart,
wxString & aResult )

Build the signal a measurement should read so it matches what is plotted.

Returns
false if the part cannot be measured (phase).

Definition at line 103 of file sim_signal_utils.cpp.

References AMPLITUDE, GAIN, IsSingleVoltageRef(), PHASE, and VALUE.

Referenced by BOOST_AUTO_TEST_CASE(), and SIMULATOR_FRAME_UI::measurementSignal().

◆ ParensBalanced()

bool SIM_SIGNAL::ParensBalanced ( const wxString & aExpression)
Returns
true if every parenthesis outside quotes is closed in order.

Definition at line 350 of file sim_signal_utils.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and DIALOG_USER_DEFINED_SIGNALS::onCheckSyntax().

◆ QuoteNetNames()

wxString SIM_SIGNAL::QuoteNetNames ( const wxString & aExpression,
const std::vector< wxString > & aNetnames )

Quote every whole occurrence of a net name that ngspice would otherwise parse as an expression.

Matching ignores case because ngspice node names do; the text keeps the user's spelling. Names already in quotes are left alone.

Definition at line 264 of file sim_signal_utils.cpp.

References end.

Referenced by BOOST_AUTO_TEST_CASE(), and SIMULATOR_FRAME_UI::quoteNetNames().

◆ SplitMeasurement()

void SIM_SIGNAL::SplitMeasurement ( const wxString & aCmd,
wxString & aFunc,
wxString & aSignal,
wxString & aParams )

Split "MAX V(out) from=1m to=2m" into its function, signal and trailing parameters.

Parameters start at the first whitespace-delimited "name=" outside quotes and parentheses, so comparison operators such as ">=" stay part of the signal.

Definition at line 131 of file sim_signal_utils.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), SIMULATOR_FRAME_UI::rebuildMeasurementsTree(), and SIMULATOR_FRAME_UI::UpdateMeasurement().

Variable Documentation

◆ DEVICE_VECTOR_PREFIX

const wxString SIM_SIGNAL::DEVICE_VECTOR_PREFIX = wxS( "kicad_vdev" )
inline

Vector name prefix for the voltage across a component, "kicad_vdev3".

Definition at line 47 of file sim_signal_utils.h.

Referenced by deviceVectorName(), and IsDerivedSignalVector().