diff --git a/eeschema/dialogs/dialog_sim_settings.cpp b/eeschema/dialogs/dialog_sim_settings.cpp index 23a5901c6b..c02a934e1a 100644 --- a/eeschema/dialogs/dialog_sim_settings.cpp +++ b/eeschema/dialogs/dialog_sim_settings.cpp @@ -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 ); diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp index e962b542f3..d29440c623 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp @@ -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 ) ) diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.h b/eeschema/netlist_exporters/netlist_exporter_pspice.h index e20bf6f6ec..6669606733 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pspice.h +++ b/eeschema/netlist_exporters/netlist_exporter_pspice.h @@ -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. */ diff --git a/eeschema/sim/netlist_exporter_pspice_sim.cpp b/eeschema/sim/netlist_exporter_pspice_sim.cpp index 516618e8c7..c35331d5f6 100644 --- a/eeschema/sim/netlist_exporter_pspice_sim.cpp +++ b/eeschema/sim/netlist_exporter_pspice_sim.cpp @@ -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 ); } diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 1fd9ca685a..53fe7f0c6e 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -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 ); diff --git a/eeschema/widgets/tuner_slider.cpp b/eeschema/widgets/tuner_slider.cpp index 9f863ba16d..5e77bb154c 100644 --- a/eeschema/widgets/tuner_slider.cpp +++ b/eeschema/widgets/tuner_slider.cpp @@ -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;