From a63df2fbf0c031ff377e77ae629e37e9dceb2b9e Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 23 May 2020 13:14:05 -0400 Subject: [PATCH] Remove BuildNetListBase from netlisting paths --- eeschema/cross-probing.cpp | 2 +- eeschema/dialogs/dialog_bom.cpp | 6 +-- eeschema/dialogs/dialog_netlist.cpp | 8 ++-- eeschema/files-io.cpp | 3 +- eeschema/netlist_generator.cpp | 66 ++++++++++----------------- eeschema/sch_edit_frame.cpp | 2 +- eeschema/sch_edit_frame.h | 22 ++------- eeschema/tools/sch_editor_control.cpp | 1 + 8 files changed, 39 insertions(+), 71 deletions(-) diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index d56afdc2b1..fd94b27a05 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -399,7 +399,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) if( payload.find( "no-annotate" ) == std::string::npos ) { // Ensure schematic is OK for netlist creation (especially that it is fully annotated): - if( !prepareForNetlist() ) + if( !ReadyToNetlist() ) return; } diff --git a/eeschema/dialogs/dialog_bom.cpp b/eeschema/dialogs/dialog_bom.cpp index f4228c7702..6ac6e6c345 100644 --- a/eeschema/dialogs/dialog_bom.cpp +++ b/eeschema/dialogs/dialog_bom.cpp @@ -474,10 +474,8 @@ void DIALOG_BOM::OnRunGenerator( wxCommandEvent& event ) m_parent->SetExecFlags( wxEXEC_SHOW_CONSOLE ); #endif - auto netlist = m_parent->CreateNetlist( false, false ); - - m_parent->WriteNetListFile( netlist, -1, - fullfilename, 0, &reporter ); + if( m_parent->ReadyToNetlist( false, false ) ) + m_parent->WriteNetListFile( -1, fullfilename, 0, &reporter ); m_Messages->SetValue( reportmsg ); diff --git a/eeschema/dialogs/dialog_netlist.cpp b/eeschema/dialogs/dialog_netlist.cpp index 2f87e41b2c..a325aba13f 100644 --- a/eeschema/dialogs/dialog_netlist.cpp +++ b/eeschema/dialogs/dialog_netlist.cpp @@ -498,12 +498,10 @@ bool NETLIST_DIALOG::TransferDataFromWindow() else m_Parent->SetNetListerCommand( wxEmptyString ); - auto netlist = m_Parent->CreateNetlist( false, false ); - - if( netlist == nullptr ) - wxMessageBox( _( "Schematic netlist not available" ) ); + if( m_Parent->ReadyToNetlist( false, false ) ) + m_Parent->WriteNetListFile( currPage->m_IdNetType, fullpath, netlist_opt, nullptr ); else - m_Parent->WriteNetListFile( netlist, currPage->m_IdNetType, fullpath, netlist_opt, NULL ); + wxMessageBox( _( "Schematic netlist not available" ) ); WriteCurrentNetlistSetup(); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index fc9cc4a67e..441ab7a75a 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -518,8 +518,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in if( m_generateNetlistAndExit ) { wxLogDebug( wxT( "Writing netlist to %s and exiting..." ), m_netlistFilename ); - NETLIST_OBJECT_LIST* netlist = CreateNetlist( false, false ); - WriteNetListFile( netlist, NET_TYPE_PCBNEW, m_netlistFilename, 0, nullptr ); + WriteNetListFile( NET_TYPE_PCBNEW, m_netlistFilename, 0, nullptr ); Close( false ); } diff --git a/eeschema/netlist_generator.cpp b/eeschema/netlist_generator.cpp index cf2a1b86ae..37b419715c 100644 --- a/eeschema/netlist_generator.cpp +++ b/eeschema/netlist_generator.cpp @@ -23,11 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file eeschema/netform.cpp - * @brief Net list generation code. - */ - #include #include #include @@ -46,13 +41,14 @@ #include #include -#include -bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, - int aFormat, const wxString& aFullFileName, +bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions, REPORTER* aReporter ) { - if( aConnectedItemsList == nullptr ) // Schematic netlist not available. + // Ensure all power symbols have a valid reference + Schematic().GetSheets().AnnotatePowerSymbols(); + + if( !ReadyToNetlist( false ) ) return false; bool res = true; @@ -163,25 +159,37 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, int TestDuplicateSheetNames( SCHEMATIC* aSchematic, bool aCreateMarker ); -bool SCH_EDIT_FRAME::prepareForNetlist() +bool SCH_EDIT_FRAME::ReadyToNetlist( bool aSilent, bool aSilentAnnotate ) { // Ensure all power symbols have a valid reference Schematic().GetSheets().AnnotatePowerSymbols(); - // Performs some controls: - if( CheckAnnotate( NULL_REPORTER::GetInstance(), 0 ) ) + // Components must be annotated + if( CheckAnnotate( NULL_REPORTER::GetInstance(), false ) ) { - // Schematic must be annotated: call Annotate dialog and tell the user why. - ModalAnnotate( _( "Exporting the netlist requires a completely annotated schematic." ) ); + if( aSilentAnnotate ) + { + AnnotateComponents( true, UNSORTED, INCREMENTAL_BY_REF, 0, false, false, true, + NULL_REPORTER::GetInstance() ); + } + else + { + if( aSilent ) + return false; - if( CheckAnnotate( NULL_REPORTER::GetInstance(), 0 ) ) - return false; + // Schematic must be annotated: call Annotate dialog and tell the user why. + ModalAnnotate( + _( "Exporting the netlist requires a completely annotated schematic." ) ); + + if( CheckAnnotate( NULL_REPORTER::GetInstance(), false ) ) + return false; + } } // Test duplicate sheet names: if( TestDuplicateSheetNames( &Schematic(), false ) > 0 ) { - if( !IsOK( this, _( "Error: duplicate sheet names. Continue?" ) ) ) + if( aSilent || !IsOK( this, _( "Error: duplicate sheet names. Continue?" ) ) ) return false; } @@ -202,30 +210,6 @@ void SCH_EDIT_FRAME::sendNetlistToCvpcb() } -NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::CreateNetlist( bool aSilent, - bool aSilentAnnotate ) -{ - if( !aSilent ) // checks for errors and invokes annotation dialog as necessary - { - if( !prepareForNetlist() ) - return nullptr; - } - else // performs similar function as prepareForNetlist but without a dialog. - { - Schematic().GetSheets().AnnotatePowerSymbols(); - - if( aSilentAnnotate ) - AnnotateComponents( true, UNSORTED, INCREMENTAL_BY_REF, 0, false, false, true, - NULL_REPORTER::GetInstance() ); - } - - // TODO(JE) This is really going to turn into "PrepareForNetlist" - // when the old netlister (BuildNetListBase) is removed - - return BuildNetListBase(); -} - - NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase( bool updateStatusText ) { // Ensure netlist is up to date diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 69027fad46..0f0c9146a9 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -839,7 +839,7 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() ); fn.SetExt( NetlistFileExtension ); - if( !prepareForNetlist() ) + if( !ReadyToNetlist() ) return; try diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 969c32a752..009d6a0a33 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -167,14 +167,6 @@ protected: */ bool isAutoSaveRequired() const override; - /** - * Verify that annotation is complete so that a proper netlist is even - * possible. If not, asks the user if annotation should be done. - * - * @return bool - true if annotation is complete, else false. - */ - bool prepareForNetlist(); - /** * Send the kicad netlist over to CVPCB. */ @@ -400,6 +392,7 @@ public: /** * Create a flat list which stores all connected objects. + * TODO(JE) Remove this once ERC is moved off of it * * @param updateStatusText decides if window StatusText should be modified. * @return NETLIST_OBJECT_LIST* - caller owns the object. @@ -407,23 +400,19 @@ public: NETLIST_OBJECT_LIST* BuildNetListBase( bool updateStatusText = true ); /** - * Create a netlist for the current schematic. + * Checks if we are ready to write a netlist file for the current schematic * * - Test for some issues (missing or duplicate references and sheet names) - * - Build netlist info - * - Create the netlist file (different formats) * * @param aSilent is true if annotation error dialog should be skipped * @param aSilentAnnotate is true if components should be reannotated silently - * @returns a unique_ptr to the netlist + * @returns true if all is well (i.e. you can call WriteNetListFile next) */ - NETLIST_OBJECT_LIST* CreateNetlist( bool aSilent = false, - bool aSilentAnnotate = false ); + bool ReadyToNetlist( bool aSilent = false, bool aSilentAnnotate = false ); /** * Create a netlist file. * - * @param aConnectedItemsList = the initialized list of connected items, take ownership. * @param aFormat = netlist format (NET_TYPE_PCBNEW ...) * @param aFullFileName = full netlist file name * @param aNetlistOptions = netlist options using OR'ed bits. @@ -437,8 +426,7 @@ public: * mainly if a command line must be run (can be NULL * @return true if success. */ - bool WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, - int aFormat, + bool WriteNetListFile( int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions, REPORTER* aReporter = NULL ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 5e6a6806cf..80718a8c8e 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -638,6 +638,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) if( item->IsType( wires ) ) { + // TODO(JE) Port to connection graph std::unique_ptr netlist( m_frame->BuildNetListBase() ); for( NETLIST_OBJECT* obj : *netlist )