diff --git a/eeschema/netlist_object.h b/eeschema/netlist_object.h index 6dd7b9f874..3227bab67b 100644 --- a/eeschema/netlist_object.h +++ b/eeschema/netlist_object.h @@ -403,6 +403,12 @@ public: */ void TestforSimilarLabels(); + /** + * Function ListNets + * return a the list of net names. + */ + wxArrayString ListNets(); + #if defined(DEBUG) void DumpNetTable() diff --git a/eeschema/netlist_object_list.cpp b/eeschema/netlist_object_list.cpp index 40f33e7f2c..7b6d1ed1ee 100644 --- a/eeschema/netlist_object_list.cpp +++ b/eeschema/netlist_object_list.cpp @@ -866,3 +866,29 @@ void NETLIST_OBJECT_LIST::setUnconnectedFlag() } } } + +wxArrayString NETLIST_OBJECT_LIST::ListNets() +{ + wxArrayString netNames; + wxString netName; + wxString ref; + + int netCode; + int lastNetCode = -1; + int sameNetcodeCount = 0; + + for( unsigned ii = 0; ii < size(); ii++ ) + { + NETLIST_OBJECT* nitem = GetItem( ii ); + + // New net found, write net id; + if( ( netCode = nitem->GetNet() ) != lastNetCode ) + { + netName = nitem->GetNetName(); + netNames.Add( netName ); + lastNetCode = netCode; + } + } + + return netNames; +} diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index d74fabfa08..ae4c5f8a8a 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1520,3 +1520,12 @@ void SCH_EDIT_FRAME::SetIconScale( int aScale ) Layout(); SendSizeEvent(); } + +wxArrayString SCH_EDIT_FRAME::ListNets() +{ + NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase(); + + wxArrayString netnames = net_atoms->ListNets(); + + return netnames; +} diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 7f23d9840a..568df46441 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -577,6 +577,11 @@ public: unsigned aNetlistOptions, REPORTER* aReporter = NULL ); + /** + * Create a list of net names currently in the schematic. + */ + wxArrayString ListNets() override; + /** * Clear the current component annotation. * diff --git a/include/kiway_player.h b/include/kiway_player.h index 3bf0e97b82..88c21ffa4a 100644 --- a/include/kiway_player.h +++ b/include/kiway_player.h @@ -192,6 +192,25 @@ public: return false; } + /** + * Rematch ophaned zones and vias to schematic nets. + */ + VTBL_ENTRY bool FixEagleNets() + { + return false; + }; + + + /** + * Create a list of net names currently in use by the player . + */ + VTBL_ENTRY wxArrayString ListNets() + { + wxArrayString a; + return a; + }; + + /** * Function ShowModal * puts up this wxFrame as if it were a modal dialog, with all other instantiated diff --git a/kicad/import_project.cpp b/kicad/import_project.cpp index 3727005a53..5ed616d835 100644 --- a/kicad/import_project.cpp +++ b/kicad/import_project.cpp @@ -116,10 +116,8 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) } wxFileName pcb( sch ); - wxFileName netlist( pro ); pro.SetExt( ProjectFileExtension ); // enforce extension pcb.SetExt( LegacyPcbFileExtension ); // enforce extension - netlist.SetExt( NetlistFileExtension ); if( !pro.IsAbsolute() ) pro.MakeAbsolute(); @@ -199,6 +197,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) // - second, perform schematic annotation and update footprint references pcbframe->Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_PCB_UPDATE_REQUEST, "no-annotate;by-reference", this ); pcbframe->Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_PCB_UPDATE_REQUEST, "quiet-annotate;by-timestamp", this ); + pcbframe->FixEagleNets(); } ReCreateTreePrj(); diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 9b5afd6f06..af5657d663 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -882,7 +882,7 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType ) if( !GetBoard()->GetFileName().IsEmpty() ) { - wxString tblName = Prj().FootprintLibTblName(); + wxString tblName = Prj().FootprintLibTblName(); try { @@ -891,15 +891,14 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType ) catch( const IO_ERROR& ioe ) { wxString msg = wxString::Format( _( - "Error occurred saving project specific footprint library " - "table:\n\n%s" ), - GetChars( ioe.What() ) - ); + "Error occurred saving project specific footprint library " + "table:\n\n%s" ), + GetChars( ioe.What() ) + ); wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); } } - return true; } @@ -911,3 +910,58 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType ) return false; } + + +bool PCB_EDIT_FRAME::FixEagleNets() +{ + KIWAY_PLAYER* schematicFrame = Kiway().Player( FRAME_SCH, false ); + + // if the schematic file was also loaded. Fix any instances of ophaned zones and vias. + if( schematicFrame ) + { + // Get list of nets from schematic. + wxArrayString nets = schematicFrame->ListNets(); + + // perform netlist matching to prevent ophaned zones. + for( auto zone : GetBoard()->Zones() ) + { + wxString zoneNet = zone->GetNet()->GetNetname(); + wxString localNet = "/" + zoneNet; + + for( int i = 0; i < nets.GetCount(); i++ ) + { + if( nets[i].EndsWith( localNet ) ) + { + NETINFO_ITEM* net = GetBoard()->FindNet( nets[i] ); + + if( net ) + { + zone->SetNetCode( net->GetNet() ); + } + } + } + } + + // perform netlist matching to prevent ophaned tracks/vias. + for( auto track : GetBoard()->Tracks() ) + { + wxString trackNet = track->GetNet()->GetNetname(); + wxString localNet = "/" + trackNet; + + for( int i = 0; i < nets.GetCount(); i++ ) + { + if( nets[i].EndsWith( localNet ) ) + { + NETINFO_ITEM* net = GetBoard()->FindNet( nets[i] ); + + if( net ) + { + track->SetNetCode( net->GetNet() ); + } + } + } + } + } + + return true; +} diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 6deb9a15b1..b9793cd867 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -877,6 +877,11 @@ public: */ bool ImportFile( const wxString& aFileName, int aFileType ) override; + /** + * Rematch ophaned zones and vias to schematic nets. + */ + bool FixEagleNets() override; + /** * Function SavePcbFile * writes the board data structures to \a a aFileName