From 4d0c1577d2ffd52c514e506146fb9440f5d1bd7f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 17 Aug 2017 17:55:05 +0200 Subject: [PATCH] Fix Pcbnew Python: LoadBoard does not rebuild connectivity database, and later, SaveBoard does not save net class memberships Fixes: lp:1711268 https://bugs.launchpad.net/kicad/+bug/1711268 --- pcbnew/class_board.cpp | 6 ++++++ pcbnew/class_board.h | 8 ++++++++ pcbnew/files.cpp | 7 ++----- pcbnew/python/examples/hidePcbValuesShowReferences.py | 6 +++--- pcbnew/swig/pcbnew_scripting_helpers.cpp | 8 +++++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 0eda751bea..148914c1ca 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -123,6 +123,12 @@ BOARD::~BOARD() } +void BOARD::BuildConnectivity() +{ + GetConnectivity()->Build( this ); +} + + const wxPoint& BOARD::GetPosition() const { wxLogWarning( wxT( "This should not be called on the BOARD object") ); diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index a7b154a8a6..689dcfccf7 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -292,6 +292,14 @@ public: return m_connectivity; } + /** + * Builds or rebuilds the board connectivity database for the board, + * especially the list of connected items, list of nets and rastnest data + * Needed after loading a board to have the connectivity database updated. + */ + void BuildConnectivity(); + + /** * Function DeleteMARKERs * deletes ALL MARKERS from the board. diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index a88dc56a11..88b4cdc13c 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -579,11 +579,8 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in SetCurrentNetClass( NETCLASS::Default ); // Rebuild list of nets (full ratsnest rebuild) - { - wxBusyCursor dummy; // Displays an Hourglass while building connectivity - Compile_Ratsnest( NULL, true ); - GetBoard()->GetConnectivity()->Build( GetBoard() ); - } + Compile_Ratsnest( NULL, true ); + GetBoard()->BuildConnectivity(); // Update info shown by the horizontal toolbars ReFillLayerWidget(); diff --git a/pcbnew/python/examples/hidePcbValuesShowReferences.py b/pcbnew/python/examples/hidePcbValuesShowReferences.py index 6b37842df3..44b0738a99 100644 --- a/pcbnew/python/examples/hidePcbValuesShowReferences.py +++ b/pcbnew/python/examples/hidePcbValuesShowReferences.py @@ -6,9 +6,9 @@ filename=sys.argv[1] pcb = LoadBoard(filename) -for module in pcb.GetModules(): +for module in pcb.GetModules(): print "* Module: %s"%module.GetReference() module.Value().SetVisible(False) # set Value as Hidden module.Reference().SetVisible(True) # set Reference as Visible - -pcb.Save("mod_"+filename) + +SaveBoard("mod_"+filename, pcb) diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index 37ff166766..0447c4c993 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -72,12 +72,18 @@ BOARD* LoadBoard( wxString& aFileName ) BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ) { - return IO_MGR::Load( aFormat, aFileName ); + BOARD* brd = IO_MGR::Load( aFormat, aFileName ); + + if( brd ) + brd->BuildConnectivity(); + + return brd; } bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat ) { + aBoard->BuildConnectivity(); aBoard->SynchronizeNetsAndNetClasses(); aBoard->GetDesignSettings().SetCurrentNetClass( NETCLASS::Default );