From 8e8d95dd7f8d0fb5018b46e26277ce0faadfb139 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 28 Feb 2018 11:31:02 +0100 Subject: [PATCH] Eagle import: process all sheets when adding junctions; fix footprint LIB_IDs --- eeschema/files-io.cpp | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 06da4b5675..dcfaaba0fc 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -802,30 +802,46 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) BreakSegmentsOnJunctions(); SchematicCleanUp( true ); - // Add junctions dots where necessary to get the connectivity right + SCH_TYPE_COLLECTOR components; auto& schLibTable = *Kiway().Prj().SchSymbolLibTable(); - components.Collect( GetScreen()->GetDrawItems(), SCH_COLLECTOR::ComponentsOnly ); - - for( int cmpIdx = 0; cmpIdx < components.GetCount(); ++cmpIdx ) + SCH_SCREENS allScreens; + for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() ) { - std::vector pts; - SCH_COMPONENT* cmp = static_cast( components[cmpIdx] ); + components.Collect( screen->GetDrawItems(), SCH_COLLECTOR::ComponentsOnly ); - cmp->Resolve( schLibTable ); - cmp->UpdatePinCache(); - cmp->GetConnectionPoints( pts ); - - for( auto i = pts.begin(); i != pts.end(); ++i ) + for( int cmpIdx = 0; cmpIdx < components.GetCount(); ++cmpIdx ) { - for( auto j = i + 1; j != pts.end(); ++j ) - TrimWire( *i, *j, true ); + std::vector pts; + SCH_COMPONENT* cmp = static_cast( components[cmpIdx] ); - if( GetScreen()->IsJunctionNeeded( *i, true ) ) - AddJunction( *i, true ); + // Update footprint LIB_ID to point to the imported Eagle library + auto fpField = cmp->GetField( FOOTPRINT ); + + if( !fpField->GetText().IsEmpty() ) + { + LIB_ID fpId( fpField->GetText() ); + fpId.SetLibNickname( newfilename.GetName() ); + fpField->SetText( fpId.Format() ); + } + + // Add junction dots where necessary + cmp->Resolve( schLibTable ); + cmp->UpdatePinCache(); + cmp->GetConnectionPoints( pts ); + + for( auto i = pts.begin(); i != pts.end(); ++i ) + { + for( auto j = i + 1; j != pts.end(); ++j ) + TrimWire( *i, *j, true ); + + if( GetScreen()->IsJunctionNeeded( *i, true ) ) + AddJunction( *i, true ); + } } } + GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); // Only perform the dangling end test on root sheet. GetScreen()->TestDanglingEnds();