From 43523a617960c6166400bfaee5fefd774cba7ffb Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 16 Feb 2018 19:26:11 +0100 Subject: [PATCH] Options for board update KiWay request (MAIL_SCH_UPDATE[_REQUEST]) Board update KiWay request may now contain options in the message payload: - "no-annotate": do not enforce annotation - "quiet-annotate": annotate without displaying a dialog - "by-reference": update netlist by reference, no dialog displayed - "by-timestamp": update netlist by timestamp, no dialog displayed --- eeschema/cross-probing.cpp | 4 +--- eeschema/sch_edit_frame.cpp | 28 ++++++++++++++++++++++------ eeschema/sch_edit_frame.h | 10 ++++++++++ pcbnew/cross-probing.cpp | 37 ++++++++++++++++++++++++++++++++----- 4 files changed, 65 insertions(+), 14 deletions(-) diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index ac71abce34..3a14b0f527 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -234,9 +234,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) case MAIL_SCH_PCB_UPDATE_REQUEST: { - wxCommandEvent dummy; - - OnUpdatePCB( dummy ); + doUpdatePcb( payload ); break; } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 9081e611c0..b552b5fd08 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -846,6 +846,12 @@ void SCH_EDIT_FRAME::OnErc( wxCommandEvent& event ) void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event ) +{ + doUpdatePcb( "" ); +} + + +void SCH_EDIT_FRAME::doUpdatePcb( const wxString& aUpdateOptions ) { wxFileName fn = Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); @@ -879,12 +885,22 @@ void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event ) frame->Raise(); } - // Ensure the schematic is OK for a netlist creation - // (especially all components are annotated): - bool success = prepareForNetlist(); + if( aUpdateOptions.Contains( "quiet-annotate" ) ) + { + SCH_SCREENS schematic; + schematic.UpdateSymbolLinks(); + SCH_SHEET_LIST sheets( g_RootSheet ); + sheets.AnnotatePowerSymbols(); + AnnotateComponents( true, UNSORTED, INCREMENTAL_BY_REF, false, false, true ); + } - if( !success ) - return; + if( !aUpdateOptions.Contains( "no-annotate" ) ) + { + // Ensure the schematic is OK for a netlist creation + // (especially all components are annotated): + if( !prepareForNetlist() ) + return; + } NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase(); NETLIST_EXPORTER_KICAD exporter( net_atoms, Prj().SchSymbolLibTable() ); @@ -894,7 +910,7 @@ void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event ) // Now, send the "kicad" (s-expr) netlist to Pcbnew Kiway().ExpressMail( FRAME_PCB, MAIL_SCH_PCB_UPDATE, - formatter.GetString(), this ); + wxString::Format("%s\n%s", aUpdateOptions, formatter.GetString() ).ToStdString(), this ); } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index a5c79a08f9..861a6106d7 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -1483,6 +1483,16 @@ public: wxString GetNetListerCommand() const { return m_netListerCommand; } + /** + * Updates netlist and sends it to pcbnew. + * @param aUpdateOptions is a string defining update options: + * - "no-annotate" does not perform schematic annotation + * - "quiet-annotate" performs schematic annotation without showing annotation dialog + * aUpdateOptions may also contain other options accepted for netlist reader. + * @see PCB_EDIT_FRAME::KiwayMailIn() + */ + void doUpdatePcb( const wxString& aUpdateOptions = "" ); + int GetIconScale() override; void SetIconScale( int aScale ) override; diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index f833975763..b1cfbd8934 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -364,10 +365,21 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) case MAIL_SCH_PCB_UPDATE: { NETLIST netlist; + size_t split = payload.find( '\n' ); + wxCHECK( split != std::string::npos, /*void*/ ); + + // Extract options and netlist + std::string options = payload.substr( 0, split ); + std::string netlistData = payload.substr( split + 1 ); + + // Quiet update options + bool by_reference = options.find( "by-reference" ) != std::string::npos; + bool by_timestamp = options.find( "by-timestamp" ) != std::string::npos; + wxASSERT( !( by_reference && by_timestamp ) ); // only one at a time please try { - STRING_LINE_READER* lineReader = new STRING_LINE_READER( payload, _( "EEschema netlist" ) ); + STRING_LINE_READER* lineReader = new STRING_LINE_READER( netlistData, _( "EEschema netlist" ) ); KICAD_NETLIST_READER netlistReader( lineReader, &netlist ); netlistReader.LoadNetlist(); } @@ -376,10 +388,25 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) assert( false ); // should never happen } - DIALOG_UPDATE_PCB updateDialog( this, &netlist ); - - updateDialog.PerformUpdate( true ); - updateDialog.ShowModal(); + if( by_reference || by_timestamp ) + { + netlist.SetDeleteExtraFootprints( false ); + netlist.SetFindByTimeStamp( by_timestamp ); + netlist.SetReplaceFootprints( true ); + + BOARD_NETLIST_UPDATER updater( this, GetBoard() ); + updater.SetLookupByTimestamp( by_timestamp ); + updater.SetDeleteUnusedComponents( false ); + updater.SetReplaceFootprints( true ); + updater.SetDeleteSinglePadNets( false ); + updater.UpdateNetlist( netlist ); + } + else + { + DIALOG_UPDATE_PCB updateDialog( this, &netlist ); + updateDialog.PerformUpdate( true ); + updateDialog.ShowModal(); + } break; }