diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 48d57eaf96..0889dfcc50 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -384,6 +384,13 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); SetSheetNumberAndCount(); + + // re-create junctions if needed. EEschema optimizes wires by merging + // colinear segments. If a schematic is saved without a valid + // cache library or missing installed libraries, this can cause connectivity errors + // unless junctions are added. + FixupJunctions(); + SyncView(); GetScreen()->ClearDrawingState(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 452b6cf178..37d1368bff 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1139,3 +1139,38 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents() const return BOX2I( VECTOR2I(0, 0), VECTOR2I( sizeX, sizeY ) ); } + +void SCH_EDIT_FRAME::FixupJunctions() +{ + SCH_SHEET_LIST sheetList; + + sheetList.BuildSheetList( g_RootSheet ); + + for( unsigned i = 0; i < sheetList.size(); i++ ) + { + std::vector anchors; + + SetCurrentSheet( sheetList[i] ); + GetCurrentSheet().UpdateAllScreenReferences(); + + auto screen = GetCurrentSheet().LastScreen(); + + for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() ) + { + if( item->Type() == SCH_COMPONENT_T ) + { + auto cmp = static_cast( item ); + auto xform = cmp->GetTransform(); + + for( auto pin : cmp->GetPins() ) + { + auto pos = cmp->GetPosition() + xform.TransformCoordinate( pin.GetPosition() ); + if ( screen->IsJunctionNeeded( pos ) ) + { + AddJunction( pos ); + } + } + } + } + } +} \ No newline at end of file diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 10f01c61b5..126f3e1fef 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -1026,6 +1026,8 @@ public: const BOX2I GetDocumentExtents() const override; + void FixupJunctions(); + DECLARE_EVENT_TABLE() };