Pspice netlist generator: add option to use net numbers as net names (feature removed a long time ago, but needed by Oscad team)

Note these options are saved in project config.
This commit is contained in:
jean-pierre charras 2014-06-26 21:20:05 +02:00
parent 96b6e1a5cb
commit d4a7685761
7 changed files with 102 additions and 74 deletions

View File

@ -41,7 +41,6 @@
#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <confirm.h>
#include <gestfich.h>
#include <wxEeschemaStruct.h>
@ -79,6 +78,7 @@ public:
NETLIST_TYPE_ID m_IdNetType;
wxCheckBox* m_IsCurrentFormat;
wxCheckBox* m_AddSubPrefix;
wxCheckBox* m_SpiceUseNetcodeAsNetname;
wxTextCtrl* m_CommandStringCtrl;
wxTextCtrl* m_TitleStringCtrl;
wxButton* m_ButtonCancel;
@ -144,7 +144,6 @@ private:
void OnCancelClick( wxCommandEvent& event );
void OnNetlistTypeSelection( wxNotebookEvent& event );
void SelectDefaultNetlistType( wxCommandEvent& event );
void EnableSubcircuitPrefix( wxCommandEvent& event );
/**
* Function OnAddPlugin
@ -232,11 +231,10 @@ enum id_netlist {
ID_CREATE_NETLIST = ID_END_EESCHEMA_ID_LIST + 1,
ID_CURRENT_FORMAT_IS_DEFAULT,
ID_RUN_SIMULATOR,
ID_ADD_SUBCIRCUIT_PREFIX
ID_ADD_SUBCIRCUIT_PREFIX,
ID_USE_NETCODE_AS_NETNAME
};
//Imported function:
int TestDuplicateSheetNames( bool aCreateMarker );
// ID for configuration:
#define CUSTOM_NETLIST_TITLE wxT( "CustomNetlistTitle" )
@ -252,8 +250,6 @@ BEGIN_EVENT_TABLE( NETLIST_DIALOG, NETLIST_DIALOG_BASE )
EVT_BUTTON( ID_CREATE_NETLIST, NETLIST_DIALOG::GenNetlist )
EVT_CHECKBOX( ID_CURRENT_FORMAT_IS_DEFAULT,
NETLIST_DIALOG::SelectDefaultNetlistType )
EVT_CHECKBOX( ID_ADD_SUBCIRCUIT_PREFIX,
NETLIST_DIALOG::EnableSubcircuitPrefix )
EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator )
END_EVENT_TABLE()
@ -271,6 +267,7 @@ NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* parent,
m_TitleStringCtrl = NULL;
m_IsCurrentFormat = NULL;
m_AddSubPrefix = NULL;
m_SpiceUseNetcodeAsNetname = NULL;
m_ButtonCancel = NULL;
m_NetOption = NULL;
@ -417,12 +414,16 @@ void NETLIST_DIALOG::InstallPageSpice()
page = m_PanelNetType[PANELSPICE] =
new NETLIST_PAGE_DIALOG( m_NoteBook, title, NET_TYPE_SPICE );
page->m_AddSubPrefix = new wxCheckBox( page, ID_ADD_SUBCIRCUIT_PREFIX,
_( "Prefix references 'U' and 'IC' with 'X'" ) );
page->m_AddSubPrefix->SetValue( m_Parent->GetAddReferencePrefix() );
page->m_AddSubPrefix->SetValue( m_Parent->GetSpiceAddReferencePrefix() );
page->m_LeftBoxSizer->Add( page->m_AddSubPrefix, 0, wxGROW | wxALL, 5 );
page->m_SpiceUseNetcodeAsNetname = new wxCheckBox( page, ID_USE_NETCODE_AS_NETNAME,
_( "Use net number as net name" ) );
page->m_SpiceUseNetcodeAsNetname->SetValue( m_Parent->GetSpiceUseNetcodeAsNetname() );
page->m_LeftBoxSizer->Add( page->m_SpiceUseNetcodeAsNetname, 0, wxGROW | wxALL, 5 );
page->m_LowBoxSizer->Add( new wxStaticText( page, -1, _( "Simulator command:" ) ), 0,
wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
@ -544,24 +545,12 @@ void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event )
}
void NETLIST_DIALOG::EnableSubcircuitPrefix( wxCommandEvent& event )
{
NETLIST_PAGE_DIALOG* currPage;
currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
if( currPage == NULL || currPage->m_AddSubPrefix == NULL )
return;
m_Parent->SetAddReferencePrefix( currPage->m_AddSubPrefix->IsChecked() );
}
void NETLIST_DIALOG::NetlistUpdateOpt()
{
int ii;
m_Parent->SetSpiceAddReferencePrefix( m_PanelNetType[PANELSPICE]->m_AddSubPrefix->IsChecked() );
m_Parent->SetSpiceUseNetcodeAsNetname( m_PanelNetType[PANELSPICE]->m_SpiceUseNetcodeAsNetname->IsChecked() );
m_Parent->SetSimulatorCommand( m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue() );
m_Parent->SetNetListFormatName( wxEmptyString );
@ -601,6 +590,9 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
// Set spice netlist options:
if( currPage->m_AddSubPrefix->GetValue() )
netlist_opt |= NET_USE_X_PREFIX;
if( currPage->m_SpiceUseNetcodeAsNetname->GetValue() )
netlist_opt |= NET_USE_NETCODES_AS_NETNAMES;
break;
case NET_TYPE_CADSTAR:
@ -695,46 +687,6 @@ bool NETLIST_DIALOG::FilenamePrms( NETLIST_TYPE_ID aNetTypeId,
}
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions )
{
SCH_SHEET_LIST sheets;
sheets.AnnotatePowerSymbols();
// Performs some controls:
if( CheckAnnotate( NULL, 0 ) )
{
if( !IsOK( NULL, _( "Some items are not annotated\n\
Do you want to annotate schematic?" ) ) )
return false;
// Schematic must be annotated: call Annotate dialog:
wxCommandEvent event;
OnAnnotate( event );
if( CheckAnnotate( NULL, 0 ) )
return false;
}
// Test duplicate sheet names:
if( TestDuplicateSheetNames( false ) > 0 )
{
if( !IsOK( NULL, _( "Error: duplicate sheet names. Continue?" ) ) )
return false;
}
// Cleanup the entire hierarchy
SCH_SCREENS screens;
screens.SchematicCleanUp();
NETLIST_OBJECT_LIST * connectedItemsList = BuildNetListBase();
bool success = WriteNetListFile( connectedItemsList, aFormat,
aFullFileName, aNetlistOptions );
return success;
}
void NETLIST_DIALOG::OnCancelClick( wxCommandEvent& event )
{
EndModal( wxID_CANCEL );
@ -746,6 +698,8 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
wxFileName fn;
wxString ExecFile, CommandLine;
NetlistUpdateOpt();
wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
tmp.Trim( false );
tmp.Trim( true );
@ -767,6 +721,9 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
if( currPage->m_AddSubPrefix && currPage->m_AddSubPrefix->GetValue() )
netlist_opt |= NET_USE_X_PREFIX;
if( currPage->m_SpiceUseNetcodeAsNetname && currPage->m_SpiceUseNetcodeAsNetname->GetValue() )
netlist_opt |= NET_USE_NETCODES_AS_NETNAMES;
if( ! m_Parent->CreateNetlist( currPage->m_IdNetType, fn.GetFullPath(),
netlist_opt ) )
return;

View File

@ -404,8 +404,13 @@ PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParametersList()
m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ),
&m_componentLibFiles,
GROUP_SCH_LIBS ) );
m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "NetFmtName" ),
&m_netListFormat) );
m_projectFileParams.push_back( new PARAM_CFG_BOOL( wxT( "SpiceForceRefPrefix" ),
&m_spiceNetlistAddReferencePrefix, false ) );
m_projectFileParams.push_back( new PARAM_CFG_BOOL( wxT( "SpiceUseNetNumbers" ),
&m_spiceNetlistUseNetcodeAsNetname, false ) );
m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "RptD_X" ),
&g_RepeatStep.x,

View File

@ -119,9 +119,10 @@ class NETLIST_EXPORT_TOOL
* <li> "netname" for global net (like gnd, vcc ..
* <li> "/path/netname" for the usual nets
* </ul>
* if aUseNetcodeAsNetName is true, the net name is just the net code (SPICE only)
*/
static void sprintPinNetName( wxString& aResult, const wxString& aNetNameFormat,
NETLIST_OBJECT* aPin );
NETLIST_OBJECT* aPin, bool aUseNetcodeAsNetName = false );
/**
* Function findNextComponentAndCreatePinList
@ -303,8 +304,10 @@ public:
* @param f = the file to write to
* @param aUsePrefix = true, adds an 'X' prefix to any reference designator starting with "U" or "IC",
* false to leave reference designator unchanged.
* @param aUseNetcodeAsNetName = true to use numbers (net codes) as net names.
* false to use net names from schematic.
*/
bool WriteNetListPspice( FILE* f, bool aUsePrefix );
bool WriteNetListPspice( FILE* f, bool aUsePrefix, bool aUseNetcodeAsNetName );
/**
* Function MakeCommandLine
@ -415,7 +418,8 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList
break;
case NET_TYPE_SPICE:
ret = helper.WriteNetListPspice( f, aNetlistOptions & NET_USE_X_PREFIX );
ret = helper.WriteNetListPspice( f, aNetlistOptions & NET_USE_X_PREFIX,
aNetlistOptions & NET_USE_NETCODES_AS_NETNAMES );
fclose( f );
break;
@ -468,7 +472,8 @@ static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 )
void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString& aResult,
const wxString& aNetNameFormat, NETLIST_OBJECT* aPin )
const wxString& aNetNameFormat, NETLIST_OBJECT* aPin,
bool aUseNetcodeAsNetName )
{
int netcode = aPin->GetNet();
@ -479,10 +484,17 @@ void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString& aResult,
if( netcode != 0 && aPin->GetConnectionType() == PAD_CONNECT )
{
if( aUseNetcodeAsNetName )
{
aResult.Printf( wxT("%d"), netcode );
}
else
{
aResult = aPin->GetNetName();
if( aResult.IsEmpty() ) // No net name: give a name from net code
aResult.Printf( aNetNameFormat.GetData(), netcode );
}
}
}
@ -1073,7 +1085,7 @@ bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
}
bool NETLIST_EXPORT_TOOL::WriteNetListPspice( FILE* f, bool aUsePrefix )
bool NETLIST_EXPORT_TOOL::WriteNetListPspice( FILE* f, bool aUsePrefix, bool aUseNetcodeAsNetName )
{
int ret = 0;
int nbitems;
@ -1285,7 +1297,7 @@ bool NETLIST_EXPORT_TOOL::WriteNetListPspice( FILE* f, bool aUsePrefix )
if( !pin )
continue;
sprintPinNetName( netName , wxT( "N-%.6d" ), pin );
sprintPinNetName( netName , wxT( "N-%.6d" ), pin, aUseNetcodeAsNetName );
//Replace parenthesis with underscore to prevent parse issues with Simulators:
netName.Replace(wxT("("),wxT("_"));

View File

@ -29,6 +29,7 @@
#include <fctsys.h>
#include <wxEeschemaStruct.h>
#include <confirm.h>
#include <netlist.h>
#include <class_netlist_object.h>
@ -47,6 +48,49 @@
#define IS_WIRE false
#define IS_BUS true
//Imported function:
int TestDuplicateSheetNames( bool aCreateMarker );
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions )
{
SCH_SHEET_LIST sheets;
sheets.AnnotatePowerSymbols();
// Performs some controls:
if( CheckAnnotate( NULL, 0 ) )
{
if( !IsOK( NULL, _( "Some items are not annotated\n"
"Do you want to annotate schematic?" ) ) )
return false;
// Schematic must be annotated: call Annotate dialog:
wxCommandEvent event;
OnAnnotate( event );
if( CheckAnnotate( NULL, 0 ) )
return false;
}
// Test duplicate sheet names:
if( TestDuplicateSheetNames( false ) > 0 )
{
if( !IsOK( NULL, _( "Error: duplicate sheet names. Continue?" ) ) )
return false;
}
// Cleanup the entire hierarchy
SCH_SCREENS screens;
screens.SchematicCleanUp();
NETLIST_OBJECT_LIST * connectedItemsList = BuildNetListBase();
bool success = WriteNetListFile( connectedItemsList, aFormat,
aFullFileName, aNetlistOptions );
return success;
}
// Buffer to build the list of items used in netlist and erc calculations
NETLIST_OBJECT_LIST s_NetObjectslist( true );

View File

@ -58,8 +58,9 @@ enum NETLIST_TYPE_ID {
/// Options for Spice netlist generation (OR'ed bits
enum netlistOptions {
NET_USE_X_PREFIX = 2, // for Spice netlist : change "U" and "IC" reference prefix to "X"
NET_PCBNEW_USE_NEW_FORMAT = 1, // For Pcbnew use the new format (S expression and SWEET)
NET_PCBNEW_USE_NEW_FORMAT = 1, // For Pcbnew use the new format (S expression and SWEET)
NET_USE_X_PREFIX = 2, // for Spice netlist : change "U" and "IC" reference prefix to "X"
NET_USE_NETCODES_AS_NETNAMES = 4 // for Spice netlist : use netcode numbers as netnames
};

View File

@ -199,6 +199,8 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ):
m_hasAutoSave = true;
SetForceHVLines( true );
SetSpiceAddReferencePrefix( false );
SetSpiceUseNetcodeAsNetname( false );
CreateScreens();

View File

@ -156,7 +156,10 @@ private:
wxString m_netListFormat;
/// Add X prefix to component references when generating spice net lists.
bool m_addReferencPrefix;
bool m_spiceNetlistAddReferencePrefix;
/// Use netcodes (net number) as net names when generating spice net lists.
bool m_spiceNetlistUseNetcodeAsNetname;
wxString m_userLibraryPath;
@ -218,9 +221,13 @@ public:
void SetNetListFormatName( const wxString& aFormat ) { m_netListFormat = aFormat; }
bool GetAddReferencePrefix() const { return m_addReferencPrefix; }
bool GetSpiceAddReferencePrefix() const { return m_spiceNetlistAddReferencePrefix; }
void SetAddReferencePrefix( bool aEnable ) { m_addReferencPrefix = aEnable; }
void SetSpiceAddReferencePrefix( bool aEnable ) { m_spiceNetlistAddReferencePrefix = aEnable; }
bool GetSpiceUseNetcodeAsNetname() const { return m_spiceNetlistUseNetcodeAsNetname; }
void SetSpiceUseNetcodeAsNetname( bool aEnable ) { m_spiceNetlistUseNetcodeAsNetname = aEnable; }
wxString GetUserLibraryPath() const { return m_userLibraryPath; }