Commit 7e1fe2c2 authored by Charles McDowell's avatar Charles McDowell Committed by Wayne Stambaugh

Option to prefix references U and IC with X when generating spice net lists.

* Fixed minor code formatting issues with submitted patch.
* Change field name to "spice_model" per discussion with Charles McDowell.
parent a041ef9d
...@@ -302,8 +302,10 @@ public: ...@@ -302,8 +302,10 @@ public:
* @param f = the file to write to * @param f = the file to write to
* @param use_netnames = true, to use netnames in netlist, * @param use_netnames = true, to use netnames in netlist,
* false to use net number. * false to use net number.
* @param aUsePrefix = true, adds an 'X' prefix to any reference designator starting with "U" or "IC",
* false to leave reference designator unchanged.
*/ */
bool WriteNetListPspice( FILE* f, bool use_netnames ); bool WriteNetListPspice( FILE* f, bool use_netnames, bool aUsePrefix );
/** /**
* Function MakeCommandLine * Function MakeCommandLine
...@@ -362,10 +364,12 @@ wxString EXPORT_HELP::MakeCommandLine( const wxString& aFormatString, ...@@ -362,10 +364,12 @@ wxString EXPORT_HELP::MakeCommandLine( const wxString& aFormatString,
* @param aUse_netnames = bool. if true, use net names from labels in schematic * @param aUse_netnames = bool. if true, use net names from labels in schematic
* if false, use net numbers (net codes) * if false, use net numbers (net codes)
* bool aUse_netnames is used only for Spice netlist * bool aUse_netnames is used only for Spice netlist
* @param aUsePrefix = true, adds an 'X' prefix to any reference designator starting with "U" or "IC",
* false to leave reference designator unchanged.
* @return true if success. * @return true if success.
*/ */
bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName, bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName,
bool aUse_netnames ) bool aUse_netnames, bool aUsePrefix )
{ {
bool ret = true; bool ret = true;
FILE* f = NULL; FILE* f = NULL;
...@@ -401,7 +405,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam ...@@ -401,7 +405,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam
break; break;
case NET_TYPE_SPICE: case NET_TYPE_SPICE:
ret = helper.WriteNetListPspice( f, aUse_netnames ); ret = helper.WriteNetListPspice( f, aUse_netnames, aUsePrefix );
fclose( f ); fclose( f );
break; break;
...@@ -1189,7 +1193,7 @@ bool EXPORT_HELP::WriteGENERICNetList( const wxString& aOutFileName ) ...@@ -1189,7 +1193,7 @@ bool EXPORT_HELP::WriteGENERICNetList( const wxString& aOutFileName )
} }
bool EXPORT_HELP::WriteNetListPspice( FILE* f, bool use_netnames ) bool EXPORT_HELP::WriteNetListPspice( FILE* f, bool use_netnames, bool aUsePrefix )
{ {
int ret = 0; int ret = 0;
char line[1024]; char line[1024];
...@@ -1354,7 +1358,17 @@ bool EXPORT_HELP::WriteNetListPspice( FILE* f, bool use_netnames ) ...@@ -1354,7 +1358,17 @@ bool EXPORT_HELP::WriteNetListPspice( FILE* f, bool use_netnames )
} }
} }
ret |= fprintf( f, "%s ", TO_UTF8( comp->GetRef( sheet ) ) ); //Get Standard Reference Designator:
wxString RefName = comp->GetRef( sheet );
//Conditionally add Prefix only for devices that begin with U or IC:
if( aUsePrefix )
{
if( RefName.StartsWith( wxT( "U" ) ) || RefName.StartsWith( wxT( "IC" ) ) )
RefName = wxT( "X" ) + RefName;
}
ret |= fprintf( f, "%s ", TO_UTF8( RefName) );
// Write pin list: // Write pin list:
int activePinIndex = 0; int activePinIndex = 0;
...@@ -1407,8 +1421,24 @@ bool EXPORT_HELP::WriteNetListPspice( FILE* f, bool use_netnames ) ...@@ -1407,8 +1421,24 @@ bool EXPORT_HELP::WriteNetListPspice( FILE* f, bool use_netnames )
} }
} }
// Get Component Value Name:
wxString CompValue = comp->GetField( VALUE )->m_Text;
// Check if Override Model Name is Provided:
SCH_FIELD* spiceModelField = comp->FindField( wxT( "spice_model" ) );
if( spiceModelField )
{
// Get Model Name String:
wxString ModelNameStr = spiceModelField->m_Text;
// Verify Field Exists and is not empty:
if( !ModelNameStr.IsEmpty() )
CompValue = ModelNameStr;
}
// Print Component Value: // Print Component Value:
ret |= fprintf( f, " %s\t\t",TO_UTF8( comp->GetField( VALUE )->m_Text ) ); ret |= fprintf( f, " %s\t\t",TO_UTF8( CompValue ) );
// Show Seq Spec on same line as component using line-comment ";": // Show Seq Spec on same line as component using line-comment ";":
for( unsigned i = 0; i < pinSequence.size(); ++i ) for( unsigned i = 0; i < pinSequence.size(); ++i )
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "dialogs/annotate_dialog.h" #include "dialogs/annotate_dialog.h"
//Imported function: //Imported function:
int TestDuplicateSheetNames( bool aCreateMarker ); int TestDuplicateSheetNames( bool aCreateMarker );
...@@ -73,6 +74,8 @@ BEGIN_EVENT_TABLE( NETLIST_DIALOG, wxDialog ) ...@@ -73,6 +74,8 @@ BEGIN_EVENT_TABLE( NETLIST_DIALOG, wxDialog )
EVT_BUTTON( ID_VALIDATE_PLUGIN, NETLIST_DIALOG::ValidatePluginPanel ) EVT_BUTTON( ID_VALIDATE_PLUGIN, NETLIST_DIALOG::ValidatePluginPanel )
EVT_CHECKBOX( ID_CURRENT_FORMAT_IS_DEFAULT, EVT_CHECKBOX( ID_CURRENT_FORMAT_IS_DEFAULT,
NETLIST_DIALOG::SelectNetlistType ) NETLIST_DIALOG::SelectNetlistType )
EVT_CHECKBOX( ID_ADD_SUBCIRCUIT_PREFIX,
NETLIST_DIALOG::EnableSubcircuitPrefix )
EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator ) EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator )
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -238,7 +241,13 @@ void NETLIST_DIALOG::InstallPageSpice() ...@@ -238,7 +241,13 @@ void NETLIST_DIALOG::InstallPageSpice()
page->m_IsCurrentFormat = new wxCheckBox( page, ID_CURRENT_FORMAT_IS_DEFAULT, page->m_IsCurrentFormat = new wxCheckBox( page, ID_CURRENT_FORMAT_IS_DEFAULT,
_( "Default format" ) ); _( "Default format" ) );
page->m_IsCurrentFormat->SetValue( m_Parent->m_NetlistFormat == NET_TYPE_SPICE ); page->m_IsCurrentFormat->SetValue( m_Parent->m_NetlistFormat == NET_TYPE_SPICE );
page->m_LeftBoxSizer->Add( page->m_IsCurrentFormat, 0, wxGROW | wxALL, 5 ); page->m_LeftBoxSizer->Add( page->m_IsCurrentFormat, 1, wxGROW | wxALL, 5 );
page->m_AddSubPrefix = new wxCheckBox( page, ID_ADD_SUBCIRCUIT_PREFIX,
_( "Prefix references 'U' and 'IC' with 'X'" ) );
page->m_AddSubPrefix->SetValue( m_Parent->m_AddSubPrefix );
page->m_LeftBoxSizer->Add( page->m_AddSubPrefix, 0, wxGROW | wxALL, 5 );
wxString netlist_opt[2] = { _( "Use Net Names" ), _( "Use Net Numbers" ) }; wxString netlist_opt[2] = { _( "Use Net Names" ), _( "Use Net Numbers" ) };
m_UseNetNamesInNetlist = new wxRadioBox( page, -1, _( "Netlist Options:" ), m_UseNetNamesInNetlist = new wxRadioBox( page, -1, _( "Netlist Options:" ),
...@@ -402,6 +411,24 @@ void NETLIST_DIALOG::SelectNetlistType( wxCommandEvent& event ) ...@@ -402,6 +411,24 @@ void NETLIST_DIALOG::SelectNetlistType( wxCommandEvent& event )
} }
/* Called when the check box "default format" is clicked
*/
void NETLIST_DIALOG::EnableSubcircuitPrefix( wxCommandEvent& event )
{
NETLIST_PAGE_DIALOG* CurrPage;
CurrPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
if( CurrPage == NULL )
return;
if( CurrPage->m_AddSubPrefix->IsChecked() )
m_Parent->m_AddSubPrefix = true;
else
m_Parent->m_AddSubPrefix = false;
}
void NETLIST_DIALOG::NetlistUpdateOpt() void NETLIST_DIALOG::NetlistUpdateOpt()
{ {
int ii; int ii;
...@@ -486,7 +513,8 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event ) ...@@ -486,7 +513,8 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
else else
g_NetListerCommandLine.Empty(); g_NetListerCommandLine.Empty();
m_Parent->CreateNetlist( CurrPage->m_IdNetType, dlg.GetPath(), g_OptNetListUseNames ); m_Parent->CreateNetlist( CurrPage->m_IdNetType, dlg.GetPath(), g_OptNetListUseNames,
CurrPage->m_AddSubPrefix->GetValue() );
WriteCurrentNetlistSetup(); WriteCurrentNetlistSetup();
...@@ -508,7 +536,8 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event ) ...@@ -508,7 +536,8 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
* @return true if success. * @return true if success.
*/ */
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName, bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
bool aUse_netnames ) bool aUse_netnames,
bool aUsePrefix )
{ {
SCH_SHEET_LIST sheets; SCH_SHEET_LIST sheets;
sheets.AnnotatePowerSymbols(); sheets.AnnotatePowerSymbols();
...@@ -540,7 +569,7 @@ Do you want to annotate schematic?" ) ) ) ...@@ -540,7 +569,7 @@ Do you want to annotate schematic?" ) ) )
screens.SchematicCleanUp(); screens.SchematicCleanUp();
BuildNetListBase(); BuildNetListBase();
bool success = WriteNetListFile( aFormat, aFullFileName, g_OptNetListUseNames ); bool success = WriteNetListFile( aFormat, aFullFileName, g_OptNetListUseNames, aUsePrefix );
return success; return success;
} }
...@@ -558,7 +587,7 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event ) ...@@ -558,7 +587,7 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
wxString ExecFile, CommandLine; wxString ExecFile, CommandLine;
g_SimulatorCommandLine = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue(); g_SimulatorCommandLine = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
g_SimulatorCommandLine.Trim( false ); g_SimulatorCommandLine.Trim( false );
g_SimulatorCommandLine.Trim( true ); g_SimulatorCommandLine.Trim( true );
ExecFile = g_SimulatorCommandLine.BeforeFirst( ' ' ); ExecFile = g_SimulatorCommandLine.BeforeFirst( ' ' );
...@@ -573,7 +602,8 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event ) ...@@ -573,7 +602,8 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
NETLIST_PAGE_DIALOG* CurrPage; NETLIST_PAGE_DIALOG* CurrPage;
CurrPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage(); CurrPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
if( ! m_Parent->CreateNetlist( CurrPage->m_IdNetType, fn.GetFullPath(), g_OptNetListUseNames ) ) if( ! m_Parent->CreateNetlist( CurrPage->m_IdNetType, fn.GetFullPath(),
g_OptNetListUseNames,CurrPage->m_AddSubPrefix->GetValue() ) )
return; return;
ExecuteFile( this, ExecFile, CommandLine ); ExecuteFile( this, ExecFile, CommandLine );
......
...@@ -19,7 +19,8 @@ enum id_netlist { ...@@ -19,7 +19,8 @@ enum id_netlist {
ID_VALIDATE_PLUGIN, ID_VALIDATE_PLUGIN,
ID_DELETE_PLUGIN, ID_DELETE_PLUGIN,
ID_NETLIST_NOTEBOOK, ID_NETLIST_NOTEBOOK,
ID_CHANGE_NOTEBOOK_PAGE ID_CHANGE_NOTEBOOK_PAGE,
ID_ADD_SUBCIRCUIT_PREFIX,
}; };
/* panel (notebook page) identifiers */ /* panel (notebook page) identifiers */
...@@ -46,6 +47,7 @@ class NETLIST_PAGE_DIALOG : public wxPanel ...@@ -46,6 +47,7 @@ class NETLIST_PAGE_DIALOG : public wxPanel
public: public:
int m_IdNetType; int m_IdNetType;
wxCheckBox* m_IsCurrentFormat; wxCheckBox* m_IsCurrentFormat;
wxCheckBox* m_AddSubPrefix;
WinEDA_EnterText* m_CommandStringCtrl; WinEDA_EnterText* m_CommandStringCtrl;
WinEDA_EnterText* m_TitleStringCtrl; WinEDA_EnterText* m_TitleStringCtrl;
wxButton* m_ButtonCancel; wxButton* m_ButtonCancel;
...@@ -112,6 +114,7 @@ private: ...@@ -112,6 +114,7 @@ private:
void NetlistUpdateOpt(); void NetlistUpdateOpt();
void OnCancelClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event );
void SelectNetlistType( wxCommandEvent& event ); void SelectNetlistType( wxCommandEvent& event );
void EnableSubcircuitPrefix( wxCommandEvent& event );
void AddNewPluginPanel( wxCommandEvent& event ); void AddNewPluginPanel( wxCommandEvent& event );
void DeletePluginPanel( wxCommandEvent& event ); void DeletePluginPanel( wxCommandEvent& event );
void ValidatePluginPanel( wxCommandEvent& event ); void ValidatePluginPanel( wxCommandEvent& event );
......
...@@ -62,6 +62,7 @@ public: ...@@ -62,6 +62,7 @@ public:
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on. SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
int m_Multiflag; int m_Multiflag;
int m_NetlistFormat; int m_NetlistFormat;
int m_AddSubPrefix;
bool m_ShowAllPins; bool m_ShowAllPins;
wxPoint m_OldPos; wxPoint m_OldPos;
LIB_EDIT_FRAME* m_LibeditFrame; LIB_EDIT_FRAME* m_LibeditFrame;
...@@ -289,7 +290,8 @@ public: ...@@ -289,7 +290,8 @@ public:
*/ */
bool CreateNetlist( int aFormat, bool CreateNetlist( int aFormat,
const wxString& aFullFileName, const wxString& aFullFileName,
bool aUse_netnames ); bool aUse_netnames,
bool aUsePrefix );
/** /**
* Function WriteNetListFile * Function WriteNetListFile
...@@ -303,7 +305,8 @@ public: ...@@ -303,7 +305,8 @@ public:
*/ */
bool WriteNetListFile( int aFormat, bool WriteNetListFile( int aFormat,
const wxString& aFullFileName, const wxString& aFullFileName,
bool aUse_netnames ); bool aUse_netnames,
bool aUsePrefix );
/** /**
* Function DeleteAnnotation * Function DeleteAnnotation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment