diff --git a/eeschema/sim/sim_model_tline.cpp b/eeschema/sim/sim_model_tline.cpp index 4b8eadb42e..7325f9a8ba 100644 --- a/eeschema/sim/sim_model_tline.cpp +++ b/eeschema/sim/sim_model_tline.cpp @@ -83,6 +83,9 @@ wxString SIM_MODEL_TLINE::GenerateSpiceModelLine( const wxString& aModelName ) c auto z0 = static_cast( *FindParam( "z0" )->value ); auto td = static_cast( *FindParam( "td" )->value ); + if( !z0.HasValue() || !td.HasValue() ) + return wxString::Format( ".model %s ltra()\n", aModelName ); + r = SIM_VALUE_FLOAT( 0 ).ToSpiceString(); l = ( td * z0 ).ToSpiceString(); g = SIM_VALUE_FLOAT( 0 ).ToSpiceString(); @@ -104,8 +107,8 @@ wxString SIM_MODEL_TLINE::GenerateSpiceModelLine( const wxString& aModelName ) c return ""; } - return wxString::Format( ".model %s %s( r=%s l=%s g=%s c=%s len=%s )\n", - aModelName, "ltra", r, l, g, c, len ); + return wxString::Format( ".model %s ltra( r=%s l=%s g=%s c=%s len=%s )\n", + aModelName, r, l, g, c, len ); } diff --git a/eeschema/sim/sim_value.cpp b/eeschema/sim/sim_value.cpp index 5cb185d117..c5bcde9c37 100644 --- a/eeschema/sim/sim_value.cpp +++ b/eeschema/sim/sim_value.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include @@ -371,15 +370,15 @@ std::unique_ptr SIM_VALUE::Create( TYPE aType ) { switch( aType ) { - case TYPE_BOOL: return std::make_unique>(); - case TYPE_INT: return std::make_unique>(); - case TYPE_FLOAT: return std::make_unique>(); - case TYPE_COMPLEX: return std::make_unique>>(); - case TYPE_STRING: return std::make_unique>(); - case TYPE_BOOL_VECTOR: return std::make_unique>(); - case TYPE_INT_VECTOR: return std::make_unique>(); - case TYPE_FLOAT_VECTOR: return std::make_unique>(); - case TYPE_COMPLEX_VECTOR: return std::make_unique>>(); + case TYPE_BOOL: return std::make_unique(); + case TYPE_INT: return std::make_unique(); + case TYPE_FLOAT: return std::make_unique(); + case TYPE_COMPLEX: return std::make_unique(); + case TYPE_STRING: return std::make_unique(); + case TYPE_BOOL_VECTOR: return std::make_unique(); + case TYPE_INT_VECTOR: return std::make_unique(); + case TYPE_FLOAT_VECTOR: return std::make_unique(); + case TYPE_COMPLEX_VECTOR: return std::make_unique(); } wxFAIL_MSG( _( "Unknown SIM_VALUE type" ) ); @@ -404,15 +403,22 @@ SIM_VALUE_INST::SIM_VALUE_INST( const T& aValue ) : m_value( aValue ) { } -template SIM_VALUE_INST::SIM_VALUE_INST( const bool& aValue ); -template SIM_VALUE_INST::SIM_VALUE_INST( const long& aValue ); -template SIM_VALUE_INST::SIM_VALUE_INST( const double& aValue ); -template SIM_VALUE_INST>::SIM_VALUE_INST( const std::complex& aValue ); -template SIM_VALUE_INST::SIM_VALUE_INST( const wxString& aValue ); +template SIM_VALUE_BOOL::SIM_VALUE_INST( const bool& aValue ); +template SIM_VALUE_INT::SIM_VALUE_INST( const long& aValue ); +template SIM_VALUE_FLOAT::SIM_VALUE_INST( const double& aValue ); +template SIM_VALUE_COMPLEX::SIM_VALUE_INST( const std::complex& aValue ); +template SIM_VALUE_STRING::SIM_VALUE_INST( const wxString& aValue ); + + +template +bool SIM_VALUE_INST::HasValue() const +{ + return m_value.has_value(); +} template <> -bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNotation ) +bool SIM_VALUE_BOOL::FromString( const wxString& aString, NOTATION aNotation ) { SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, aNotation ); m_value = std::nullopt; @@ -438,7 +444,7 @@ bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNotati template <> -bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNotation ) +bool SIM_VALUE_INT::FromString( const wxString& aString, NOTATION aNotation ) { SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, aNotation ); m_value = std::nullopt; @@ -461,7 +467,7 @@ bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNotati template <> -bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNotation ) +bool SIM_VALUE_FLOAT::FromString( const wxString& aString, NOTATION aNotation ) { SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, aNotation ); m_value = std::nullopt; @@ -494,7 +500,7 @@ bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNota template <> -bool SIM_VALUE_INST>::FromString( const wxString& aString, +bool SIM_VALUE_COMPLEX::FromString( const wxString& aString, NOTATION aNotation ) { // TODO @@ -512,7 +518,7 @@ bool SIM_VALUE_INST>::FromString( const wxString& aString, template <> -bool SIM_VALUE_INST::FromString( const wxString& aString, NOTATION aNotation ) +bool SIM_VALUE_STRING::FromString( const wxString& aString, NOTATION aNotation ) { m_value = aString; return true; @@ -537,7 +543,7 @@ wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const template <> -wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const +wxString SIM_VALUE_BOOL::ToString( NOTATION aNotation ) const { LOCALE_IO toggle; @@ -549,7 +555,7 @@ wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const template <> -wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const +wxString SIM_VALUE_INT::ToString( NOTATION aNotation ) const { LOCALE_IO toggle; @@ -575,7 +581,7 @@ wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const template <> -wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const +wxString SIM_VALUE_FLOAT::ToString( NOTATION aNotation ) const { LOCALE_IO toggle; @@ -597,7 +603,7 @@ wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const template <> -wxString SIM_VALUE_INST>::ToString( NOTATION aNotation ) const +wxString SIM_VALUE_COMPLEX::ToString( NOTATION aNotation ) const { LOCALE_IO toggle; @@ -609,7 +615,7 @@ wxString SIM_VALUE_INST>::ToString( NOTATION aNotation ) co template <> -wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const +wxString SIM_VALUE_STRING::ToString( NOTATION aNotation ) const { LOCALE_IO toggle; @@ -635,7 +641,7 @@ wxString SIM_VALUE_INST::ToSimpleString() const template <> -wxString SIM_VALUE_INST>::ToSimpleString() const +wxString SIM_VALUE_COMPLEX::ToSimpleString() const { // TODO @@ -655,7 +661,7 @@ bool SIM_VALUE_INST::operator==( const T& aOther ) const template <> -bool SIM_VALUE_INST::operator==( const bool& aOther ) const +bool SIM_VALUE_BOOL::operator==( const bool& aOther ) const { // Note that we take nullopt as the same as false here. @@ -666,10 +672,10 @@ bool SIM_VALUE_INST::operator==( const bool& aOther ) const } -template bool SIM_VALUE_INST::operator==( const long& aOther ) const; -template bool SIM_VALUE_INST::operator==( const double& aOther ) const; -template bool SIM_VALUE_INST>::operator==( const std::complex& aOther ) const; -template bool SIM_VALUE_INST::operator==( const wxString& aOther ) const; +template bool SIM_VALUE_INT::operator==( const long& aOther ) const; +template bool SIM_VALUE_FLOAT::operator==( const double& aOther ) const; +template bool SIM_VALUE_COMPLEX::operator==( const std::complex& aOther ) const; +template bool SIM_VALUE_STRING::operator==( const wxString& aOther ) const; template @@ -683,48 +689,48 @@ bool SIM_VALUE_INST::operator==( const SIM_VALUE& aOther ) const return false; } -template + template SIM_VALUE_INST operator+( const SIM_VALUE_INST& aLeft, const SIM_VALUE_INST& aRight ) { - return SIM_VALUE_INST( *aLeft.m_value + *aRight.m_value ); + return SIM_VALUE_INST( aLeft.m_value.value() + aRight.m_value.value() ); } -template SIM_VALUE_INST operator+( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); -template SIM_VALUE_INST operator+( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); +template SIM_VALUE_INT operator+( const SIM_VALUE_INT& aLeft, + const SIM_VALUE_INT& aRight ); +template SIM_VALUE_FLOAT operator+( const SIM_VALUE_FLOAT& aLeft, + const SIM_VALUE_FLOAT& aRight ); -template + template SIM_VALUE_INST operator-( const SIM_VALUE_INST& aLeft, const SIM_VALUE_INST& aRight ) { - return SIM_VALUE_INST( *aLeft.m_value - *aRight.m_value ); + return SIM_VALUE_INST( aLeft.m_value.value() - aRight.m_value.value() ); } -template SIM_VALUE_INST operator-( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); -template SIM_VALUE_INST operator-( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); +template SIM_VALUE_INT operator-( const SIM_VALUE_INT& aLeft, + const SIM_VALUE_INT& aRight ); +template SIM_VALUE_FLOAT operator-( const SIM_VALUE_FLOAT& aLeft, + const SIM_VALUE_FLOAT& aRight ); -template + template SIM_VALUE_INST operator*( const SIM_VALUE_INST& aLeft, const SIM_VALUE_INST& aRight ) { - return SIM_VALUE_INST( *aLeft.m_value * *aRight.m_value ); + return SIM_VALUE_INST( aLeft.m_value.value() * aRight.m_value.value() ); } -template SIM_VALUE_INST operator*( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); -template SIM_VALUE_INST operator*( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); +template SIM_VALUE_INT operator*( const SIM_VALUE_INT& aLeft, + const SIM_VALUE_INT& aRight ); +template SIM_VALUE_FLOAT operator*( const SIM_VALUE_FLOAT& aLeft, + const SIM_VALUE_FLOAT& aRight ); -template + template SIM_VALUE_INST operator/( const SIM_VALUE_INST& aLeft, const SIM_VALUE_INST& aRight ) { - return SIM_VALUE_INST( *aLeft.m_value / *aRight.m_value ); + return SIM_VALUE_INST( aLeft.m_value.value() / aRight.m_value.value() ); } -template SIM_VALUE_INST operator/( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); -template SIM_VALUE_INST operator/( const SIM_VALUE_INST& aLeft, - const SIM_VALUE_INST& aRight ); +template SIM_VALUE_INT operator/( const SIM_VALUE_INT& aLeft, + const SIM_VALUE_INT& aRight ); +template SIM_VALUE_FLOAT operator/( const SIM_VALUE_FLOAT& aLeft, + const SIM_VALUE_FLOAT& aRight ); diff --git a/eeschema/sim/sim_value.h b/eeschema/sim/sim_value.h index 410e933046..bdfa016b32 100644 --- a/eeschema/sim/sim_value.h +++ b/eeschema/sim/sim_value.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -70,6 +71,8 @@ public: virtual ~SIM_VALUE() = default; SIM_VALUE() = default; + virtual bool HasValue() const = 0; + void operator=( const wxString& aString ); virtual bool operator==( const SIM_VALUE& aOther ) const = 0; bool operator!=( const SIM_VALUE& aOther ) const; @@ -90,6 +93,8 @@ public: SIM_VALUE_INST() = default; SIM_VALUE_INST( const T& aValue ); + bool HasValue() const override; + // TODO: Don't pass aNotation. Make a FromSpiceString() function instead. bool FromString( const wxString& aString, NOTATION aNotation = NOTATION::SI ) override; wxString ToString( NOTATION aNotation = NOTATION::SI ) const override; @@ -122,8 +127,9 @@ private: }; typedef SIM_VALUE_INST SIM_VALUE_BOOL; -typedef SIM_VALUE_INST SIM_VALUE_LONG; +typedef SIM_VALUE_INST SIM_VALUE_INT; typedef SIM_VALUE_INST SIM_VALUE_FLOAT; +typedef SIM_VALUE_INST> SIM_VALUE_COMPLEX; typedef SIM_VALUE_INST SIM_VALUE_STRING;