From e7377c0a26d7a1b4abcf3f4e7028f6556edc3ae7 Mon Sep 17 00:00:00 2001 From: Russell Oliver Date: Sun, 9 Jul 2017 12:37:02 +1000 Subject: [PATCH] Eeschema Eagle Import: dynamically size sheet based on positions of wires and junctions within the sheet. --- eeschema/sch_eagle_plugin.cpp | 50 ++++++++++++++++++++++++++++++++++- eeschema/sch_eagle_plugin.h | 3 ++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 46d8993c8b..83f569f1de 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -511,9 +511,39 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode ) plainNode = plainNode->GetNext(); } + + wxSize targetSheetSize( (sheetTopRight.x - sheetBottomLeft.x) * 1.5, + -( sheetTopRight.y - sheetBottomLeft.y) * 1.5 ); + + + wxPoint itemsCentre( (sheetTopRight.x - sheetBottomLeft.x) / 2, + (sheetTopRight.y - sheetBottomLeft.y) / 2 ); + + SCH_ITEM* item = m_currentSheet->GetScreen()->GetDrawItems(); + wxSize pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU(); + + PAGE_INFO pageInfo = m_currentSheet->GetScreen()->GetPageSettings(); + + if( pageSizeIU.xGetScreen()->SetPageSettings( pageInfo ); + + pageSizeIU = m_currentSheet->GetScreen()->GetPageSettings().GetSizeIU(); + wxPoint sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 ); + + while( item ) + { + item->SetPosition( item->GetPosition() - itemsCentre + sheetcentre ); + item = item->Next(); + } } + void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& netName, const wxString& netClass ) { @@ -611,6 +641,17 @@ SCH_LINE* SCH_EAGLE_PLUGIN::loadSignalWire( wxXmlNode* aWireNode ) wire->SetStartPoint( begin ); wire->SetEndPoint( end ); + if( begin.x > sheetTopRight.x) sheetTopRight.x = begin.x; + if( begin.y < sheetTopRight.y) sheetTopRight.y = begin.y; + + if( end.x > sheetTopRight.x) sheetTopRight.x = end.x; + if( end.y < sheetTopRight.y) sheetTopRight.y = end.y; + + if( begin.x < sheetBottomLeft.x) sheetBottomLeft.x = begin.x; + if( begin.y > sheetBottomLeft.y) sheetBottomLeft.y = begin.y; + + if( end.x < sheetBottomLeft.x) sheetBottomLeft.x = end.x; + if( end.y > sheetBottomLeft.y) sheetBottomLeft.y = end.y; return wire.release(); } @@ -620,8 +661,15 @@ SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction( wxXmlNode* aJunction ) std::unique_ptr junction( new SCH_JUNCTION ); auto ejunction = EJUNCTION( aJunction ); + wxPoint pos( ejunction.x * EUNIT_TO_MIL, -ejunction.y * EUNIT_TO_MIL ); - junction->SetPosition( wxPoint( ejunction.x * EUNIT_TO_MIL, -ejunction.y * EUNIT_TO_MIL ) ); + junction->SetPosition( pos ); + + if( pos.x > sheetTopRight.x) sheetTopRight.x = pos.x; + if( pos.y < sheetTopRight.y) sheetTopRight.y = pos.y; + + if( pos.x < sheetBottomLeft.x) sheetBottomLeft.x = pos.x; + if( pos.y > sheetBottomLeft.y) sheetBottomLeft.y = pos.y; return junction.release(); } diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index bdc6b58f8d..90029e67b5 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -159,7 +159,8 @@ private: EPART_LIST m_partlist; std::map m_eaglelibraries; - + wxPoint sheetTopRight; + wxPoint sheetBottomLeft; protected: