Commit d4a76857 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Pspice netlist generator: add option to use net numbers as net names (feature...

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.
parent 96b6e1a5
Loading
Loading
Loading
Loading
+20 −63
Original line number Diff line number Diff line
@@ -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;
+5 −0
Original line number Diff line number Diff line
@@ -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,
+18 −6
Original line number Diff line number Diff line
@@ -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();

@@ -478,6 +483,12 @@ void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString& aResult,
    aResult.Empty();

    if( netcode != 0 && aPin->GetConnectionType() == PAD_CONNECT )
    {
        if( aUseNetcodeAsNetName )
        {
            aResult.Printf( wxT("%d"), netcode );
        }
        else
        {
        aResult = aPin->GetNetName();

@@ -485,6 +496,7 @@ void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString& aResult,
            aResult.Printf( aNetNameFormat.GetData(), netcode );
        }
    }
}


SCH_COMPONENT* NETLIST_EXPORT_TOOL::findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath )
@@ -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("_"));
+44 −0
Original line number Diff line number Diff line
@@ -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 );

+3 −2
Original line number Diff line number Diff line
@@ -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_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
};


Loading