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

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
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -302,8 +302,10 @@ public:
     * @param f = the file to write to
     * @param use_netnames = true, to use netnames in netlist,
     *                      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
@@ -362,10 +364,12 @@ wxString EXPORT_HELP::MakeCommandLine( const wxString& aFormatString,
 * @param aUse_netnames = bool. if true, use net names from labels in schematic
 *                              if false, use net numbers (net codes)
 *   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.
 */
bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName,
                                       bool aUse_netnames )
                                       bool aUse_netnames, bool aUsePrefix )
{
    bool        ret = true;
    FILE*       f = NULL;
@@ -401,7 +405,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam
        break;

    case NET_TYPE_SPICE:
        ret = helper.WriteNetListPspice( f, aUse_netnames );
        ret = helper.WriteNetListPspice( f, aUse_netnames, aUsePrefix );
        fclose( f );
        break;

@@ -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;
    char                line[1024];
@@ -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:
            int activePinIndex = 0;
@@ -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:
            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 ";":
            for( unsigned i = 0;  i < pinSequence.size();  ++i )
+36 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "dialogs/annotate_dialog.h"



//Imported function:
int TestDuplicateSheetNames( bool aCreateMarker );

@@ -73,6 +74,8 @@ BEGIN_EVENT_TABLE( NETLIST_DIALOG, wxDialog )
    EVT_BUTTON( ID_VALIDATE_PLUGIN, NETLIST_DIALOG::ValidatePluginPanel )
    EVT_CHECKBOX( ID_CURRENT_FORMAT_IS_DEFAULT,
                  NETLIST_DIALOG::SelectNetlistType )
    EVT_CHECKBOX( ID_ADD_SUBCIRCUIT_PREFIX,
                  NETLIST_DIALOG::EnableSubcircuitPrefix )
    EVT_BUTTON( ID_RUN_SIMULATOR, NETLIST_DIALOG::RunSimulator )
END_EVENT_TABLE()

@@ -238,7 +241,13 @@ void NETLIST_DIALOG::InstallPageSpice()
    page->m_IsCurrentFormat = new wxCheckBox( page, ID_CURRENT_FORMAT_IS_DEFAULT,
                                              _( "Default format" ) );
    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" ) };
    m_UseNetNamesInNetlist = new wxRadioBox( page, -1, _( "Netlist Options:" ),
@@ -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()
{
    int ii;
@@ -486,7 +513,8 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
    else
        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();

@@ -508,7 +536,8 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
 * @return true if success.
 */
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
                                    bool aUse_netnames )
                                    bool aUse_netnames,
                                    bool aUsePrefix )
{
    SCH_SHEET_LIST sheets;
    sheets.AnnotatePowerSymbols();
@@ -540,7 +569,7 @@ Do you want to annotate schematic?" ) ) )
    screens.SchematicCleanUp();

    BuildNetListBase();
    bool success = WriteNetListFile( aFormat, aFullFileName, g_OptNetListUseNames );
    bool success = WriteNetListFile( aFormat, aFullFileName, g_OptNetListUseNames, aUsePrefix );

    return success;
}
@@ -573,7 +602,8 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event )
    NETLIST_PAGE_DIALOG* CurrPage;
    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;

    ExecuteFile( this, ExecFile, CommandLine );
+4 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ enum id_netlist {
    ID_VALIDATE_PLUGIN,
    ID_DELETE_PLUGIN,
    ID_NETLIST_NOTEBOOK,
    ID_CHANGE_NOTEBOOK_PAGE
    ID_CHANGE_NOTEBOOK_PAGE,
    ID_ADD_SUBCIRCUIT_PREFIX,
};

/* panel (notebook page) identifiers */
@@ -46,6 +47,7 @@ class NETLIST_PAGE_DIALOG : public wxPanel
public:
    int               m_IdNetType;
    wxCheckBox*       m_IsCurrentFormat;
    wxCheckBox*       m_AddSubPrefix;
    WinEDA_EnterText* m_CommandStringCtrl;
    WinEDA_EnterText* m_TitleStringCtrl;
    wxButton*         m_ButtonCancel;
@@ -112,6 +114,7 @@ private:
    void    NetlistUpdateOpt();
    void    OnCancelClick( wxCommandEvent& event );
    void    SelectNetlistType( wxCommandEvent& event );
    void    EnableSubcircuitPrefix( wxCommandEvent& event );
    void    AddNewPluginPanel( wxCommandEvent& event );
    void    DeletePluginPanel( wxCommandEvent& event );
    void    ValidatePluginPanel( wxCommandEvent& event );
+5 −2
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public:
    SCH_SHEET_PATH*       m_CurrentSheet;    ///< which sheet we are presently working on.
    int m_Multiflag;
    int m_NetlistFormat;
    int m_AddSubPrefix;
    bool                  m_ShowAllPins;
    wxPoint               m_OldPos;
    LIB_EDIT_FRAME*       m_LibeditFrame;
@@ -289,7 +290,8 @@ public:
     */
    bool         CreateNetlist( int             aFormat,
                                const wxString& aFullFileName,
                                bool            aUse_netnames );
                                bool            aUse_netnames,
                                bool            aUsePrefix );

    /**
     * Function  WriteNetListFile
@@ -303,7 +305,8 @@ public:
     */
    bool         WriteNetListFile( int             aFormat,
                                   const wxString& aFullFileName,
                                   bool            aUse_netnames );
                                   bool            aUse_netnames,
                                   bool aUsePrefix );

    /**
     * Function DeleteAnnotation