Do not use double component primitives in Spice netlist exporter

Fixes: lp:1617768
* https://bugs.launchpad.net/kicad/+bug/1617768
This commit is contained in:
Maciej Suminski 2016-08-30 14:24:01 +02:00
parent b87bac22c7
commit 67573f15be
6 changed files with 30 additions and 11 deletions

View File

@ -118,7 +118,7 @@ bool DIALOG_SIM_SETTINGS::TransferDataFromWindow()
try
{
simCmd += wxString::Format( "v%s %s %s %s",
simCmd += wxString::Format( "%s %s %s %s",
m_dcSource1->GetValue(),
SPICE_VALUE( m_dcStart1->GetValue() ).ToSpiceString(),
SPICE_VALUE( m_dcStop1->GetValue() ).ToSpiceString(),
@ -146,7 +146,7 @@ bool DIALOG_SIM_SETTINGS::TransferDataFromWindow()
try
{
simCmd += wxString::Format( "v%s %s %s %s",
simCmd += wxString::Format( "%s %s %s %s",
m_dcSource2->GetValue(),
SPICE_VALUE( m_dcStart2->GetValue() ).ToSpiceString(),
SPICE_VALUE( m_dcStop2->GetValue() ).ToSpiceString(),
@ -278,7 +278,7 @@ int DIALOG_SIM_SETTINGS::ShowModal()
for( auto item : m_exporter->GetSpiceItems() )
{
if( item.m_primitive == 'V' )
if( item.m_primitive == SP_VSOURCE )
{
for( auto c : cmbSrc )
c.first->Append( item.m_refName );

View File

@ -81,7 +81,7 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl
for( const auto& item : m_spiceItems )
{
aFormatter->Print( 0, "%c%s ", item.m_primitive, (const char*) item.m_refName.c_str() );
aFormatter->Print( 0, "%s ", (const char*) GetSpiceComponentName( item.m_parent, aCtl ).c_str() );
// Pins to node mapping
int activePinIndex = 0;
@ -151,6 +151,23 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl
}
wxString NETLIST_EXPORTER_PSPICE::GetSpiceComponentName( SCH_COMPONENT* aComponent, unsigned aCtl )
{
const wxString compName = aComponent->GetField( REFERENCE )->GetText();
// Get the component number
const char* number = compName.c_str();
while( isalpha( *number ) )
++number;
if( number == nullptr )
number = compName.c_str();
return GetSpiceField( SF_PRIMITIVE, aComponent, aCtl ) + wxString( number );
}
wxString NETLIST_EXPORTER_PSPICE::GetSpiceField( SPICE_FIELD aField,
SCH_COMPONENT* aComponent, unsigned aCtl )
{
@ -286,7 +303,7 @@ bool NETLIST_EXPORTER_PSPICE::ProcessNetlist( unsigned aCtl )
spiceItem.m_primitive = GetSpiceField( SF_PRIMITIVE, comp, aCtl )[0];
spiceItem.m_model = GetSpiceField( SF_MODEL, comp, aCtl );
spiceItem.m_refName = comp->GetRef( &sheetList[sheet_idx] );
spiceItem.m_refName = GetSpiceComponentName( comp, aCtl );
// Duplicate references will result in simulation errors
if( refNames.count( spiceItem.m_refName ) )

View File

@ -138,6 +138,11 @@ public:
return m_spiceFields[(int) aField];
}
/**
* @brief Returns a component name in the Spice world.
*/
static wxString GetSpiceComponentName( SCH_COMPONENT* aComponent, unsigned aCtl );
/**
* @brief Retrieves either the requested field value or the default value.
*/

View File

@ -96,7 +96,7 @@ wxString NETLIST_EXPORTER_PSPICE_SIM::GetSpiceDevice( const wxString& aComponent
if( it == spiceItems.end() )
return wxEmptyString;
return wxString( it->m_primitive + it->m_refName );
return wxString( it->m_refName );
}

View File

@ -562,7 +562,7 @@ void SIM_PLOT_FRAME::applyTuners()
for( auto& tuner : m_tuners )
{
/// @todo no ngspice hardcoding
std::string command( "alter @" + tuner->GetSpiceName()
std::string command( "alter @" + tuner->GetSpiceName().Lower()
+ "=" + tuner->GetValue().ToSpiceString() );
m_simulator->Command( command );

View File

@ -37,10 +37,7 @@ TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_COMPO
m_name->SetLabel( compName );
m_value = SPICE_VALUE( aComponent->GetField( VALUE )->GetText() );
m_changed = false;
// Generate Spice component name
char prim = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, aComponent, 0 )[0];
m_spiceName = wxString( prim + compName ).Lower();
m_spiceName = NETLIST_EXPORTER_PSPICE::GetSpiceComponentName( aComponent, 0 );
// Call Set*() methods to update fields and slider
m_max = SPICE_VALUE( 2.0 ) * m_value;