Sim: Move SPICE_GENERATOR class to a new file
This commit is contained in:
parent
da9be1a812
commit
907ad27e7f
|
@ -276,6 +276,7 @@ set( EESCHEMA_SRCS
|
|||
|
||||
# Some simulation features must be built even if libngspice is not linked.
|
||||
sim/spice_settings.cpp
|
||||
sim/spice_generator.cpp
|
||||
sim/sim_library.cpp
|
||||
sim/sim_library_spice.cpp
|
||||
sim/sim_model.cpp
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <sim/sim_plot_frame.h>
|
||||
|
||||
#include <sim/ngspice_helpers.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
DIALOG_SIGNAL_LIST::DIALOG_SIGNAL_LIST( SIM_PLOT_FRAME* aParent,
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
|
||||
#include <iterator>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL::SPICE_GENERATOR;
|
||||
using DEVICE_TYPE = SIM_MODEL::DEVICE_TYPE_;
|
||||
using TYPE = SIM_MODEL::TYPE;
|
||||
|
||||
|
@ -82,192 +81,6 @@ namespace SIM_MODEL_SPICE_PARSER
|
|||
|
||||
template <> struct spiceUnitSelector<dotSubckt> : std::true_type {};
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
if( !m_model.HasSpiceNonInstanceOverrides() && !m_model.requiresSpiceModelLine() )
|
||||
return "";
|
||||
|
||||
wxString result = "";
|
||||
|
||||
result << wxString::Format( ".model %s ", aModelName );
|
||||
size_t indentLength = result.Length();
|
||||
|
||||
result << wxString::Format( "%s \n", m_model.GetSpiceInfo().modelType );
|
||||
|
||||
for( const PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
if( param.info.isSpiceInstanceParam )
|
||||
continue;
|
||||
|
||||
wxString name = ( param.info.spiceModelName == "" ) ?
|
||||
param.info.name : param.info.spiceModelName;
|
||||
wxString value = param.value->ToSpiceString();
|
||||
|
||||
if( value == "" )
|
||||
continue;
|
||||
|
||||
result << wxString::Format( "+%s%s=%s\n", wxString( ' ', indentLength - 1 ), name, value );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName ) const
|
||||
{
|
||||
// Use linear symbol pin numbers enumeration. Used in model preview.
|
||||
|
||||
std::vector<wxString> pinNumbers;
|
||||
|
||||
for( int i = 0; i < m_model.GetPinCount(); ++i )
|
||||
pinNumbers.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
|
||||
return ItemLine( aRefName, aModelName, pinNumbers );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const
|
||||
{
|
||||
std::vector<wxString> pinNetNames;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
pinNetNames.push_back( pin.name );
|
||||
|
||||
return ItemLine( aRefName, aModelName, aSymbolPinNumbers, pinNetNames );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
result << ItemName( aRefName );
|
||||
result << ItemPins( aRefName, aModelName, aSymbolPinNumbers, aPinNetNames );
|
||||
result << ItemModelName( aModelName );
|
||||
result << ItemParams();
|
||||
result << "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemName( const wxString& aRefName ) const
|
||||
{
|
||||
if( aRefName != "" && aRefName.StartsWith( m_model.GetSpiceInfo().itemType ) )
|
||||
return aRefName;
|
||||
else
|
||||
return m_model.GetSpiceInfo().itemType + aRefName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
int ncCounter = 0;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
{
|
||||
auto it = std::find( aSymbolPinNumbers.begin(), aSymbolPinNumbers.end(),
|
||||
pin.symbolPinNumber );
|
||||
|
||||
if( it == aSymbolPinNumbers.end() )
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
result << wxString::Format( " NC-%s-%u", aRefName, ncCounter++ );
|
||||
}
|
||||
else
|
||||
{
|
||||
long symbolPinIndex = std::distance( aSymbolPinNumbers.begin(), it );
|
||||
result << " " << aPinNetNames.at( symbolPinIndex );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemModelName( const wxString& aModelName ) const
|
||||
{
|
||||
return " " + aModelName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
for( const PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
wxString name = ( param.info.spiceInstanceName == "" ) ?
|
||||
param.info.name : param.info.spiceInstanceName;
|
||||
wxString value = param.value->ToSpiceString();
|
||||
|
||||
if( value != "" )
|
||||
result << " " << name << "=" << value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::TuningLine( const wxString& aSymbol ) const
|
||||
{
|
||||
// TODO.
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
return { wxString::Format( "I(%s)", ItemName( aRefName ) ) };
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::Preview( const wxString& aModelName ) const
|
||||
{
|
||||
wxString spiceCode = ModelLine( aModelName );
|
||||
|
||||
if( spiceCode == "" )
|
||||
spiceCode = m_model.m_spiceCode;
|
||||
|
||||
if( spiceCode == "" && m_model.GetBaseModel() )
|
||||
spiceCode = m_model.GetBaseModel()->m_spiceCode;
|
||||
|
||||
wxString itemLine = ItemLine( "", aModelName );
|
||||
if( spiceCode != "" )
|
||||
spiceCode << "\n";
|
||||
|
||||
spiceCode << itemLine;
|
||||
return spiceCode.Trim();
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> SPICE_GENERATOR::GetInstanceParams() const
|
||||
{
|
||||
std::vector<std::reference_wrapper<const PARAM>> instanceParams;
|
||||
|
||||
for( const PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
if( param.info.isSpiceInstanceParam )
|
||||
instanceParams.emplace_back( param );
|
||||
}
|
||||
|
||||
return instanceParams;
|
||||
}
|
||||
|
||||
|
||||
SIM_MODEL::DEVICE_INFO SIM_MODEL::DeviceTypeInfo( DEVICE_TYPE_ aDeviceType )
|
||||
{
|
||||
switch( aDeviceType )
|
||||
|
@ -1025,6 +838,9 @@ void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldNa
|
|||
}
|
||||
|
||||
|
||||
SIM_MODEL::~SIM_MODEL() = default;
|
||||
|
||||
|
||||
void SIM_MODEL::ReadSpiceCode( const wxString& aSpiceCode )
|
||||
{
|
||||
// The default behavior is to treat the Spice param=value pairs as the model parameters and
|
||||
|
@ -1244,6 +1060,12 @@ bool SIM_MODEL::HasSpiceNonInstanceOverrides() const
|
|||
}
|
||||
|
||||
|
||||
SIM_MODEL::SIM_MODEL( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator ) :
|
||||
m_spiceGenerator( std::move( aSpiceGenerator ) ),
|
||||
m_baseModel( nullptr ),
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <enum_vector.h>
|
||||
|
||||
class SIM_LIBRARY;
|
||||
class SPICE_GENERATOR;
|
||||
|
||||
|
||||
namespace SIM_MODEL_GRAMMAR
|
||||
|
@ -108,50 +109,11 @@ namespace SIM_MODEL_GRAMMAR
|
|||
class SIM_MODEL
|
||||
{
|
||||
public:
|
||||
friend class SPICE_GENERATOR;
|
||||
|
||||
struct PIN;
|
||||
struct PARAM;
|
||||
|
||||
class SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
SPICE_GENERATOR( const SIM_MODEL& aModel ) : m_model( aModel ) {}
|
||||
|
||||
virtual wxString ModelLine( const wxString& aModelName ) const;
|
||||
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName ) const;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const;
|
||||
virtual wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const;
|
||||
virtual wxString ItemName( const wxString& aRefName ) const;
|
||||
virtual wxString ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const;
|
||||
virtual wxString ItemModelName( const wxString& aModelName ) const;
|
||||
virtual wxString ItemParams() const;
|
||||
|
||||
virtual wxString TuningLine( const wxString& aSymbol ) const;
|
||||
|
||||
virtual std::vector<wxString> CurrentNames( const wxString& aRefName ) const;
|
||||
|
||||
virtual wxString Preview( const wxString& aModelName ) const;
|
||||
|
||||
protected:
|
||||
virtual std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> GetPins() const
|
||||
{
|
||||
return m_model.GetPins();
|
||||
}
|
||||
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> GetInstanceParams() const;
|
||||
|
||||
const SIM_MODEL& m_model;
|
||||
};
|
||||
|
||||
static constexpr auto REFERENCE_FIELD = "Reference";
|
||||
static constexpr auto VALUE_FIELD = "Value";
|
||||
|
||||
|
@ -512,7 +474,7 @@ public:
|
|||
|
||||
// Move semantics.
|
||||
// Rule of five.
|
||||
virtual ~SIM_MODEL() = default;
|
||||
virtual ~SIM_MODEL(); // = default in implementation file.
|
||||
SIM_MODEL() = delete;
|
||||
SIM_MODEL( const SIM_MODEL& aOther ) = delete;
|
||||
SIM_MODEL( SIM_MODEL&& aOther ) = default;
|
||||
|
@ -592,7 +554,7 @@ public:
|
|||
bool IsEnabled() const { return m_isEnabled; }
|
||||
|
||||
protected:
|
||||
SIM_MODEL( TYPE aType ) : SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) ) {}
|
||||
SIM_MODEL( TYPE aType );
|
||||
SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator );
|
||||
|
||||
virtual void CreatePins( unsigned aSymbolPinCount );
|
||||
|
|
|
@ -25,43 +25,41 @@
|
|||
#include <sim/sim_model_behavioral.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_BEHAVIORAL::SPICE_GENERATOR;
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_BEHAVIORAL::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
wxString SPICE_GENERATOR_BEHAVIORAL::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case TYPE::R_BEHAVIORAL:
|
||||
case TYPE::C_BEHAVIORAL:
|
||||
case TYPE::L_BEHAVIORAL:
|
||||
return SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName,
|
||||
m_model.GetParam( 0 ).value->ToString(),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
case SIM_MODEL::TYPE::R_BEHAVIORAL:
|
||||
case SIM_MODEL::TYPE::C_BEHAVIORAL:
|
||||
case SIM_MODEL::TYPE::L_BEHAVIORAL:
|
||||
return SPICE_GENERATOR::ItemLine( aRefName,
|
||||
m_model.GetParam( 0 ).value->ToString(),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
|
||||
case TYPE::V_BEHAVIORAL:
|
||||
return SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName,
|
||||
wxString::Format( "V=%s", m_model.GetParam( 0 ).value->ToString() ),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
case SIM_MODEL::TYPE::V_BEHAVIORAL:
|
||||
return SPICE_GENERATOR::ItemLine( aRefName,
|
||||
wxString::Format( "V=%s", m_model.GetParam( 0 ).value->ToString() ),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
|
||||
case TYPE::I_BEHAVIORAL:
|
||||
return SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName,
|
||||
wxString::Format( "I=%s", m_model.GetParam( 0 ).value->ToString() ),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
case SIM_MODEL::TYPE::I_BEHAVIORAL:
|
||||
return SPICE_GENERATOR::ItemLine( aRefName,
|
||||
wxString::Format( "I=%s", m_model.GetParam( 0 ).value->ToString() ),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_BEHAVIORAL" );
|
||||
|
@ -71,7 +69,7 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
|
||||
|
||||
SIM_MODEL_BEHAVIORAL::SIM_MODEL_BEHAVIORAL( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) ),
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_BEHAVIORAL>( *this ) ),
|
||||
m_isInferred( false )
|
||||
{
|
||||
static PARAM::INFO resistor = makeParams( "r", "Expression for resistance", "Ω" );
|
||||
|
|
|
@ -26,24 +26,25 @@
|
|||
#define SIM_MODEL_BEHAVIORAL_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_BEHAVIORAL : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_BEHAVIORAL : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_BEHAVIORAL( TYPE aType );
|
||||
|
||||
void ReadDataSchFields( unsigned aSymbolPinCount,
|
||||
|
|
|
@ -26,32 +26,30 @@
|
|||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_IDEAL::SPICE_GENERATOR;
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_IDEAL::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
wxString SPICE_GENERATOR_IDEAL::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString valueStr = m_model.GetParam( 0 ).value->ToString( SIM_VALUE::NOTATION::SPICE );
|
||||
|
||||
if( valueStr != "" )
|
||||
return SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName, valueStr, aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
return SPICE_GENERATOR::ItemLine( aRefName, valueStr, aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
SIM_MODEL_IDEAL::SIM_MODEL_IDEAL( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) ),
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_IDEAL>( *this ) ),
|
||||
m_isInferred( false )
|
||||
{
|
||||
static PARAM::INFO resistor = makeParamInfo( "r", "Resistance", "Ω" );
|
||||
|
|
|
@ -26,24 +26,25 @@
|
|||
#define SIM_MODEL_IDEAL_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_IDEAL : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_IDEAL : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_IDEAL( TYPE aType );
|
||||
|
||||
void ReadDataSchFields( unsigned aSymbolPinCount, const std::vector<SCH_FIELD>* aFields ) override;
|
||||
|
|
|
@ -24,14 +24,12 @@
|
|||
|
||||
#include <sim/sim_model_mutual_inductor.h>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_MUTUAL_INDUCTOR::SPICE_GENERATOR;
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemParams() const
|
||||
wxString SPICE_GENERATOR_MUTUAL_INDUCTOR::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
for( const PARAM& param : GetInstanceParams() )
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
result << " " << param.value->ToSpiceString();
|
||||
|
||||
return result;
|
||||
|
@ -39,7 +37,8 @@ wxString SPICE_GENERATOR::ItemParams() const
|
|||
|
||||
|
||||
SIM_MODEL_MUTUAL_INDUCTOR::SIM_MODEL_MUTUAL_INDUCTOR() :
|
||||
SIM_MODEL( SIM_MODEL::TYPE::L_MUTUAL, std::make_unique<SPICE_GENERATOR>( *this ) )
|
||||
SIM_MODEL( SIM_MODEL::TYPE::L_MUTUAL,
|
||||
std::make_unique<SPICE_GENERATOR_MUTUAL_INDUCTOR>( *this ) )
|
||||
{
|
||||
static std::vector<PARAM::INFO> paramInfos = makeParamInfos();
|
||||
|
||||
|
|
|
@ -26,18 +26,21 @@
|
|||
#define SIM_MODEL_MUTUAL_INDUCTOR_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_MUTUAL_INDUCTOR : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ItemParams() const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_MUTUAL_INDUCTOR : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ItemParams() const override;
|
||||
};
|
||||
|
||||
SIM_MODEL_MUTUAL_INDUCTOR();
|
||||
|
||||
|
|
|
@ -25,36 +25,33 @@
|
|||
#include <sim/sim_model_ngspice.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_NGSPICE::SPICE_GENERATOR;
|
||||
using TYPE = SIM_MODEL::TYPE;
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName ) const
|
||||
std::vector<wxString> SPICE_GENERATOR_NGSPICE::CurrentNames( const wxString& aRefName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
switch( m_model.GetTypeInfo().deviceType )
|
||||
{
|
||||
case DEVICE_TYPE_::NPN:
|
||||
case DEVICE_TYPE_::PNP:
|
||||
case SIM_MODEL::DEVICE_TYPE_::NPN:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PNP:
|
||||
return { wxString::Format( "I(%s:c)", aRefName ),
|
||||
wxString::Format( "I(%s:b)", aRefName ),
|
||||
wxString::Format( "I(%s:e)", aRefName ) };
|
||||
|
||||
case DEVICE_TYPE_::NJFET:
|
||||
case DEVICE_TYPE_::PJFET:
|
||||
case DEVICE_TYPE_::NMES:
|
||||
case DEVICE_TYPE_::PMES:
|
||||
case DEVICE_TYPE_::NMOS:
|
||||
case DEVICE_TYPE_::PMOS:
|
||||
case SIM_MODEL::DEVICE_TYPE_::NJFET:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PJFET:
|
||||
case SIM_MODEL::DEVICE_TYPE_::NMES:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PMES:
|
||||
case SIM_MODEL::DEVICE_TYPE_::NMOS:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PMOS:
|
||||
return { wxString::Format( "I(%s:d)", aRefName ),
|
||||
wxString::Format( "I(%s:g)", aRefName ),
|
||||
wxString::Format( "I(%s:s)", aRefName ) };
|
||||
|
||||
case DEVICE_TYPE_::R:
|
||||
case DEVICE_TYPE_::C:
|
||||
case DEVICE_TYPE_::L:
|
||||
case DEVICE_TYPE_::D:
|
||||
case SIM_MODEL::DEVICE_TYPE_::R:
|
||||
case SIM_MODEL::DEVICE_TYPE_::C:
|
||||
case SIM_MODEL::DEVICE_TYPE_::L:
|
||||
case SIM_MODEL::DEVICE_TYPE_::D:
|
||||
return CurrentNames( aRefName );
|
||||
|
||||
default:
|
||||
|
@ -65,7 +62,7 @@ std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName )
|
|||
|
||||
|
||||
SIM_MODEL_NGSPICE::SIM_MODEL_NGSPICE( TYPE aType )
|
||||
: SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) )
|
||||
: SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_NGSPICE>( *this ) )
|
||||
{
|
||||
const MODEL_INFO& modelInfo = ModelInfo( getModelType() );
|
||||
|
||||
|
|
|
@ -26,6 +26,16 @@
|
|||
#define SIM_MODEL_NGSPICE_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_NGSPICE : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
std::vector<wxString> CurrentNames( const wxString& aRefName ) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_NGSPICE : public SIM_MODEL
|
||||
|
@ -33,14 +43,6 @@ class SIM_MODEL_NGSPICE : public SIM_MODEL
|
|||
public:
|
||||
friend struct MODEL_INFO_MAP;
|
||||
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
std::vector<wxString> CurrentNames( const wxString& aRefName ) const override;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_NGSPICE( TYPE aType );
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
#include <locale_io.h>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_SOURCE::SPICE_GENERATOR;
|
||||
|
||||
|
||||
namespace SIM_MODEL_SOURCE_PARSER
|
||||
{
|
||||
|
@ -40,13 +38,13 @@ namespace SIM_MODEL_SOURCE_PARSER
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_SOURCE::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
wxString SPICE_GENERATOR_SOURCE::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
|
@ -66,8 +64,8 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case TYPE::V_PWL:
|
||||
case TYPE::I_PWL:
|
||||
case SIM_MODEL::TYPE::V_PWL:
|
||||
case SIM_MODEL::TYPE::I_PWL:
|
||||
{
|
||||
tao::pegtl::string_input<> in( m_model.GetParam( 0 ).value->ToString().ToUTF8(),
|
||||
"from_content" );
|
||||
|
@ -102,15 +100,15 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
|
||||
// TODO: dt should be tstep by default.
|
||||
|
||||
case TYPE::V_WHITENOISE:
|
||||
case TYPE::I_WHITENOISE:
|
||||
case SIM_MODEL::TYPE::V_WHITENOISE:
|
||||
case SIM_MODEL::TYPE::I_WHITENOISE:
|
||||
args << getParamValueString( "rms", "0" ) << " ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << "0 0 0 0 0 ";
|
||||
break;
|
||||
|
||||
case TYPE::V_PINKNOISE:
|
||||
case TYPE::I_PINKNOISE:
|
||||
case SIM_MODEL::TYPE::V_PINKNOISE:
|
||||
case SIM_MODEL::TYPE::I_PINKNOISE:
|
||||
args << "0 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "slope", "0" ) << " ";
|
||||
|
@ -118,16 +116,16 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
args << "0 0 0 ";
|
||||
break;
|
||||
|
||||
case TYPE::V_BURSTNOISE:
|
||||
case TYPE::I_BURSTNOISE:
|
||||
case SIM_MODEL::TYPE::V_BURSTNOISE:
|
||||
case SIM_MODEL::TYPE::I_BURSTNOISE:
|
||||
args << "0 0 0 0 ";
|
||||
args << getParamValueString( "ampl", "0" ) << " ";
|
||||
args << getParamValueString( "tcapt", "0" ) << " ";
|
||||
args << getParamValueString( "temit", "0" ) << " ";
|
||||
break;
|
||||
|
||||
case TYPE::V_RANDUNIFORM:
|
||||
case TYPE::I_RANDUNIFORM:
|
||||
case SIM_MODEL::TYPE::V_RANDUNIFORM:
|
||||
case SIM_MODEL::TYPE::I_RANDUNIFORM:
|
||||
{
|
||||
args << "1 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
|
@ -143,8 +141,8 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
}
|
||||
break;
|
||||
|
||||
case TYPE::V_RANDNORMAL:
|
||||
case TYPE::I_RANDNORMAL:
|
||||
case SIM_MODEL::TYPE::V_RANDNORMAL:
|
||||
case SIM_MODEL::TYPE::I_RANDNORMAL:
|
||||
args << "2 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "td", "0" ) << " ";
|
||||
|
@ -152,8 +150,8 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
args << getParamValueString( "mean", "0" ) << " ";
|
||||
break;
|
||||
|
||||
case TYPE::V_RANDEXP:
|
||||
case TYPE::I_RANDEXP:
|
||||
case SIM_MODEL::TYPE::V_RANDEXP:
|
||||
case SIM_MODEL::TYPE::I_RANDEXP:
|
||||
args << "3 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "td", "0" ) << " ";
|
||||
|
@ -161,8 +159,8 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
args << getParamValueString( "offset", "0" ) << " ";
|
||||
break;
|
||||
|
||||
/*case TYPE::V_RANDPOISSON:
|
||||
case TYPE::I_RANDPOISSON:
|
||||
/*case SIM_MODEL::TYPE::V_RANDPOISSON:
|
||||
case SIM_MODEL::TYPE::I_RANDPOISSON:
|
||||
args << "4 ";
|
||||
args << FindParam( "dt" )->value->ToSpiceString() << " ";
|
||||
args << FindParam( "td" )->value->ToSpiceString() << " ";
|
||||
|
@ -171,7 +169,7 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
break;*/
|
||||
|
||||
default:
|
||||
for( const PARAM& param : m_model.GetParams() )
|
||||
for( const SIM_MODEL::PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
wxString argStr = param.value->ToString( SIM_VALUE_GRAMMAR::NOTATION::SPICE );
|
||||
|
||||
|
@ -186,11 +184,11 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
else
|
||||
model << m_model.GetParam( 0 ).value->ToSpiceString();
|
||||
|
||||
return SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName, model, aSymbolPinNumbers, aPinNetNames );
|
||||
return SPICE_GENERATOR::ItemLine( aRefName, model, aSymbolPinNumbers, aPinNetNames );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::getParamValueString( const wxString& aParamName,
|
||||
wxString SPICE_GENERATOR_SOURCE::getParamValueString( const wxString& aParamName,
|
||||
const wxString& aDefaultValue ) const
|
||||
{
|
||||
wxString result = m_model.FindParam( aParamName )->value->ToSpiceString();
|
||||
|
@ -203,7 +201,7 @@ wxString SPICE_GENERATOR::getParamValueString( const wxString& aParamName,
|
|||
|
||||
|
||||
SIM_MODEL_SOURCE::SIM_MODEL_SOURCE( TYPE aType )
|
||||
: SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) ),
|
||||
: SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_SOURCE>( *this ) ),
|
||||
m_isInferred( false )
|
||||
{
|
||||
for( const SIM_MODEL::PARAM::INFO& paramInfo : makeParamInfos( aType ) )
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define SIM_MODEL_SOURCE_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
namespace SIM_MODEL_SOURCE_GRAMMAR
|
||||
|
@ -43,26 +44,26 @@ namespace SIM_MODEL_SOURCE_GRAMMAR
|
|||
}
|
||||
|
||||
|
||||
class SPICE_GENERATOR_SOURCE : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
|
||||
private:
|
||||
wxString getParamValueString( const wxString& aParamName,
|
||||
const wxString& aDefaultValue ) const;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_SOURCE : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
|
||||
private:
|
||||
wxString getParamValueString( const wxString& aParamName,
|
||||
const wxString& aDefaultValue ) const;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_SOURCE( TYPE aType );
|
||||
|
||||
void WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const override;
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_SPICE::SPICE_GENERATOR;
|
||||
|
||||
|
||||
namespace SIM_MODEL_SPICE_PARSER
|
||||
{
|
||||
|
@ -38,15 +36,16 @@ namespace SIM_MODEL_SPICE_PARSER
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_SPICE::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemName( const wxString& aRefName ) const
|
||||
wxString SPICE_GENERATOR_SPICE::ItemName( const wxString& aRefName ) const
|
||||
{
|
||||
wxString elementType = m_model.GetParam( static_cast<int>( SPICE_PARAM::TYPE ) ).value->ToString();
|
||||
wxString elementType = m_model.GetParam(
|
||||
static_cast<int>( SIM_MODEL_SPICE::SPICE_PARAM::TYPE ) ).value->ToString();
|
||||
|
||||
if( aRefName != "" && aRefName.StartsWith( elementType ) )
|
||||
return aRefName;
|
||||
|
@ -55,14 +54,14 @@ wxString SPICE_GENERATOR::ItemName( const wxString& aRefName ) const
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
wxString SPICE_GENERATOR_SPICE::ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
{
|
||||
auto it = std::find( aSymbolPinNumbers.begin(), aSymbolPinNumbers.end(),
|
||||
pin.symbolPinNumber );
|
||||
|
@ -78,17 +77,17 @@ wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemModelName( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_SPICE::ItemModelName( const wxString& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemParams() const
|
||||
wxString SPICE_GENERATOR_SPICE::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
for( const PARAM& param : GetInstanceParams() )
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
if( param.info.name != "model" )
|
||||
result << "";
|
||||
|
@ -100,7 +99,7 @@ wxString SPICE_GENERATOR::ItemParams() const
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::Preview( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_SPICE::Preview( const wxString& aModelName ) const
|
||||
{
|
||||
std::vector<wxString> pinNumbers;
|
||||
std::vector<wxString> pinNetNames;
|
||||
|
@ -116,7 +115,7 @@ wxString SPICE_GENERATOR::Preview( const wxString& aModelName ) const
|
|||
|
||||
|
||||
SIM_MODEL_SPICE::SIM_MODEL_SPICE( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) )
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_SPICE>( *this ) )
|
||||
{
|
||||
static std::vector<PARAM::INFO> paramInfos = makeParamInfos();
|
||||
|
||||
|
|
|
@ -26,30 +26,31 @@
|
|||
#define SIM_MODEL_SPICE_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_SPICE : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
|
||||
wxString ItemName( const wxString& aRefName ) const override;
|
||||
wxString ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
wxString ItemModelName( const wxString& aModelName ) const override;
|
||||
wxString ItemParams() const override;
|
||||
|
||||
wxString Preview( const wxString& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_SPICE : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
|
||||
wxString ItemName( const wxString& aRefName ) const override;
|
||||
wxString ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
wxString ItemModelName( const wxString& aModelName ) const override;
|
||||
wxString ItemParams() const override;
|
||||
|
||||
wxString Preview( const wxString& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_ENUM_CLASS_WITH_ITERATOR( SPICE_PARAM,
|
||||
TYPE,
|
||||
MODEL,
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_SUBCKT::SPICE_GENERATOR;
|
||||
|
||||
|
||||
namespace SIM_MODEL_SUBCKT_SPICE_PARSER
|
||||
{
|
||||
|
@ -48,17 +46,17 @@ namespace SIM_MODEL_SUBCKT_SPICE_PARSER
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_SUBCKT::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName ) const
|
||||
std::vector<wxString> SPICE_GENERATOR_SUBCKT::CurrentNames( const wxString& aRefName ) const
|
||||
{
|
||||
std::vector<wxString> currentNames;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
{
|
||||
currentNames.push_back( wxString::Format( "I(%s:%s)",
|
||||
ItemName( aRefName ),
|
||||
|
@ -70,7 +68,7 @@ std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName )
|
|||
|
||||
|
||||
SIM_MODEL_SUBCKT::SIM_MODEL_SUBCKT( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) )
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_SUBCKT>( *this ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -26,21 +26,22 @@
|
|||
#define SIM_MODEL_SUBCIRCUIT_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_SUBCKT : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
std::vector<wxString> CurrentNames( const wxString& aRefName ) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_SUBCKT : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
std::vector<wxString> CurrentNames( const wxString& aRefName ) const override;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_SUBCKT( TYPE aType );
|
||||
|
||||
void ReadSpiceCode( const wxString& aSpiceCode ) override;
|
||||
|
|
|
@ -24,34 +24,32 @@
|
|||
|
||||
#include <sim/sim_model_switch.h>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_SWITCH::SPICE_GENERATOR;
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
wxString SPICE_GENERATOR_SWITCH::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case TYPE::SW_V:
|
||||
case SIM_MODEL::TYPE::SW_V:
|
||||
{
|
||||
result << SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName, aModelName, aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
result << SPICE_GENERATOR::ItemLine( aRefName, aModelName, aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE::SW_I:
|
||||
case SIM_MODEL::TYPE::SW_I:
|
||||
{
|
||||
wxString vsourceName = "V__" + aRefName;
|
||||
|
||||
// Current switches measure input current through a voltage source.
|
||||
result << vsourceName << " " << aPinNetNames[0] << " " << aPinNetNames[1] << " 0\n";
|
||||
|
||||
result << SIM_MODEL::SPICE_GENERATOR::ItemLine( aRefName, vsourceName + " " + aModelName,
|
||||
aSymbolPinNumbers, aPinNetNames );
|
||||
result << SPICE_GENERATOR::ItemLine( aRefName, vsourceName + " " + aModelName,
|
||||
aSymbolPinNumbers, aPinNetNames );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -64,11 +62,11 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemParams() const
|
||||
wxString SPICE_GENERATOR_SWITCH::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
for( const PARAM& param : GetInstanceParams() )
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
// The only instance param is "ic", which is positional.
|
||||
wxString value = param.value->ToSpiceString();
|
||||
|
@ -83,14 +81,14 @@ wxString SPICE_GENERATOR::ItemParams() const
|
|||
}
|
||||
|
||||
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> SPICE_GENERATOR::GetPins() const
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> SPICE_GENERATOR_SWITCH::GetPins() const
|
||||
{
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case TYPE::SW_V:
|
||||
case SIM_MODEL::TYPE::SW_V:
|
||||
return { m_model.GetPin( 2 ), m_model.GetPin( 3 ), m_model.GetPin( 0 ), m_model.GetPin( 1 ) };
|
||||
|
||||
case TYPE::SW_I:
|
||||
case SIM_MODEL::TYPE::SW_I:
|
||||
return { m_model.GetPin( 2 ), m_model.GetPin( 3 ) };
|
||||
|
||||
default:
|
||||
|
@ -101,7 +99,7 @@ std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> SPICE_GENERATOR::GetPi
|
|||
|
||||
|
||||
SIM_MODEL_SWITCH::SIM_MODEL_SWITCH( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) )
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_SWITCH>( *this ) )
|
||||
{
|
||||
static std::vector<PARAM::INFO> vsw = makeSwVParamInfos();
|
||||
static std::vector<PARAM::INFO> isw = makeSwIParamInfos();
|
||||
|
|
|
@ -26,24 +26,25 @@
|
|||
#define SIM_MODEL_SWITCH_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_SWITCH : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ItemLine( const wxString& aRefName, const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
wxString ItemParams() const override;
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> GetPins() const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_SWITCH : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ItemLine( const wxString& aRefName, const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
wxString ItemParams() const override;
|
||||
std::vector<std::reference_wrapper<const PIN>> GetPins() const override;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_SWITCH( TYPE aType );
|
||||
|
||||
protected:
|
||||
|
|
|
@ -25,17 +25,16 @@
|
|||
#include <sim/sim_model_tline.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
using SPICE_GENERATOR = SIM_MODEL_TLINE::SPICE_GENERATOR;
|
||||
using PARAM = SIM_MODEL::PARAM;
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
wxString SPICE_GENERATOR_TLINE::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
wxString r, l, g, c, len;
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case TYPE::TLINE_Z0:
|
||||
case SIM_MODEL::TYPE::TLINE_Z0:
|
||||
{
|
||||
auto z0 = static_cast<const SIM_VALUE_FLOAT&>( *m_model.FindParam( "z0" )->value );
|
||||
auto td = static_cast<const SIM_VALUE_FLOAT&>( *m_model.FindParam( "td" )->value );
|
||||
|
@ -51,7 +50,7 @@ wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
|||
break;
|
||||
}
|
||||
|
||||
case TYPE::TLINE_RLGC:
|
||||
case SIM_MODEL::TYPE::TLINE_RLGC:
|
||||
r = m_model.FindParam( "r" )->value->ToSpiceString();
|
||||
l = m_model.FindParam( "l" )->value->ToSpiceString();
|
||||
g = m_model.FindParam( "g" )->value->ToSpiceString();
|
||||
|
@ -70,7 +69,8 @@ wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
|||
|
||||
|
||||
SIM_MODEL_TLINE::SIM_MODEL_TLINE( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) ),
|
||||
SIM_MODEL( aType,
|
||||
std::make_unique<SPICE_GENERATOR_TLINE>( *this ) ),
|
||||
m_isInferred( false )
|
||||
{
|
||||
static std::vector<PARAM::INFO> z0 = makeZ0ParamInfos();
|
||||
|
|
|
@ -26,20 +26,21 @@
|
|||
#define SIM_MODEL_TLINE_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
#include <sim/spice_generator.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR_TLINE : public SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIM_MODEL_TLINE : public SIM_MODEL
|
||||
{
|
||||
public:
|
||||
class SPICE_GENERATOR : public SIM_MODEL::SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
using SIM_MODEL::SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
SIM_MODEL_TLINE( TYPE aType );
|
||||
|
||||
void WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const override;
|
||||
|
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mikolaj Wielgus
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* https://www.gnu.org/licenses/gpl-3.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 3 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <sim/spice_generator.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
if( !m_model.HasSpiceNonInstanceOverrides() && !m_model.requiresSpiceModelLine() )
|
||||
return "";
|
||||
|
||||
wxString result = "";
|
||||
|
||||
result << wxString::Format( ".model %s ", aModelName );
|
||||
size_t indentLength = result.Length();
|
||||
|
||||
result << wxString::Format( "%s \n", m_model.GetSpiceInfo().modelType );
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
if( param.info.isSpiceInstanceParam )
|
||||
continue;
|
||||
|
||||
wxString name = ( param.info.spiceModelName == "" ) ?
|
||||
param.info.name : param.info.spiceModelName;
|
||||
wxString value = param.value->ToSpiceString();
|
||||
|
||||
if( value == "" )
|
||||
continue;
|
||||
|
||||
result << wxString::Format( "+%s%s=%s\n", wxString( ' ', indentLength - 1 ), name, value );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName ) const
|
||||
{
|
||||
// Use linear symbol pin numbers enumeration. Used in model preview.
|
||||
|
||||
std::vector<wxString> pinNumbers;
|
||||
|
||||
for( int i = 0; i < m_model.GetPinCount(); ++i )
|
||||
pinNumbers.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
|
||||
return ItemLine( aRefName, aModelName, pinNumbers );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const
|
||||
{
|
||||
std::vector<wxString> pinNetNames;
|
||||
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
pinNetNames.push_back( pin.name );
|
||||
|
||||
return ItemLine( aRefName, aModelName, aSymbolPinNumbers, pinNetNames );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
result << ItemName( aRefName );
|
||||
result << ItemPins( aRefName, aModelName, aSymbolPinNumbers, aPinNetNames );
|
||||
result << ItemModelName( aModelName );
|
||||
result << ItemParams();
|
||||
result << "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemName( const wxString& aRefName ) const
|
||||
{
|
||||
if( aRefName != "" && aRefName.StartsWith( m_model.GetSpiceInfo().itemType ) )
|
||||
return aRefName;
|
||||
else
|
||||
return m_model.GetSpiceInfo().itemType + aRefName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
int ncCounter = 0;
|
||||
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
{
|
||||
auto it = std::find( aSymbolPinNumbers.begin(), aSymbolPinNumbers.end(),
|
||||
pin.symbolPinNumber );
|
||||
|
||||
if( it == aSymbolPinNumbers.end() )
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
result << wxString::Format( " NC-%s-%u", aRefName, ncCounter++ );
|
||||
}
|
||||
else
|
||||
{
|
||||
long symbolPinIndex = std::distance( aSymbolPinNumbers.begin(), it );
|
||||
result << " " << aPinNetNames.at( symbolPinIndex );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemModelName( const wxString& aModelName ) const
|
||||
{
|
||||
return " " + aModelName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
wxString name = ( param.info.spiceInstanceName == "" ) ?
|
||||
param.info.name : param.info.spiceInstanceName;
|
||||
wxString value = param.value->ToSpiceString();
|
||||
|
||||
if( value != "" )
|
||||
result << " " << name << "=" << value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::TuningLine( const wxString& aSymbol ) const
|
||||
{
|
||||
// TODO.
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
return { wxString::Format( "I(%s)", ItemName( aRefName ) ) };
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::Preview( const wxString& aModelName ) const
|
||||
{
|
||||
wxString spiceCode = ModelLine( aModelName );
|
||||
|
||||
if( spiceCode == "" )
|
||||
spiceCode = m_model.m_spiceCode;
|
||||
|
||||
if( spiceCode == "" && m_model.GetBaseModel() )
|
||||
spiceCode = m_model.GetBaseModel()->m_spiceCode;
|
||||
|
||||
wxString itemLine = ItemLine( "", aModelName );
|
||||
if( spiceCode != "" )
|
||||
spiceCode << "\n";
|
||||
|
||||
spiceCode << itemLine;
|
||||
return spiceCode.Trim();
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> SPICE_GENERATOR::GetInstanceParams() const
|
||||
{
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> instanceParams;
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
if( param.info.isSpiceInstanceParam )
|
||||
instanceParams.emplace_back( param );
|
||||
}
|
||||
|
||||
return instanceParams;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mikolaj Wielgus
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* https://www.gnu.org/licenses/gpl-3.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 3 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef SPICE_GENERATOR_H
|
||||
#define SPICE_GENERATOR_H
|
||||
|
||||
#include <sim/sim_model.h>
|
||||
|
||||
|
||||
class SPICE_GENERATOR
|
||||
{
|
||||
public:
|
||||
SPICE_GENERATOR( const SIM_MODEL& aModel ) : m_model( aModel ) {}
|
||||
|
||||
virtual wxString ModelLine( const wxString& aModelName ) const;
|
||||
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName ) const;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const;
|
||||
virtual wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const;
|
||||
virtual wxString ItemName( const wxString& aRefName ) const;
|
||||
virtual wxString ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const;
|
||||
virtual wxString ItemModelName( const wxString& aModelName ) const;
|
||||
virtual wxString ItemParams() const;
|
||||
|
||||
virtual wxString TuningLine( const wxString& aSymbol ) const;
|
||||
|
||||
virtual std::vector<wxString> CurrentNames( const wxString& aRefName ) const;
|
||||
|
||||
virtual wxString Preview( const wxString& aModelName ) const;
|
||||
|
||||
protected:
|
||||
virtual std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> GetPins() const
|
||||
{
|
||||
return m_model.GetPins();
|
||||
}
|
||||
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> GetInstanceParams() const;
|
||||
|
||||
const SIM_MODEL& m_model;
|
||||
};
|
||||
|
||||
#endif // SPICE_GENERATOR_H
|
|
@ -50,6 +50,7 @@
|
|||
#include <schematic.h>
|
||||
#include <advanced_config.h>
|
||||
#include <sim/sim_plot_frame.h>
|
||||
#include <sim/spice_generator.h>
|
||||
#include <symbol_viewer_frame.h>
|
||||
#include <status_popup.h>
|
||||
#include <tool/picker_tool.h>
|
||||
|
|
Loading…
Reference in New Issue