From 8c8b4f43e7efc7297bca4909b2be84f3567b058f Mon Sep 17 00:00:00 2001 From: Dag Lem Date: Mon, 9 Jan 2023 14:18:23 +0000 Subject: [PATCH] Eagle schematic import: Added missing plain elements --- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 88 ++++++++++++++++++- eeschema/sch_plugins/eagle/sch_eagle_plugin.h | 4 + 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 8678552352..7814ce37fd 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -938,14 +939,26 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex ) wxString nodeName = plainNode->GetName(); - if( nodeName == wxT( "text" ) ) + if( nodeName == wxT( "polygon" ) ) { - screen->Append( loadPlainText( plainNode ) ); + screen->Append( loadPolyLine( plainNode ) ); } else if( nodeName == wxT( "wire" ) ) { screen->Append( loadWire( plainNode ) ); } + else if( nodeName == wxT( "text" ) ) + { + screen->Append( loadPlainText( plainNode ) ); + } + else if( nodeName == wxT( "circle" ) ) + { + screen->Append( loadCircle( plainNode ) ); + } + else if( nodeName == wxT( "rectangle" ) ) + { + screen->Append( loadRectangle( plainNode ) ); + } else if( nodeName == wxT( "frame" ) ) { std::vector lines; @@ -1181,6 +1194,32 @@ void SCH_EAGLE_PLUGIN::loadSegments( wxXmlNode* aSegmentsNode, const wxString& n } +SCH_SHAPE* SCH_EAGLE_PLUGIN::loadPolyLine( wxXmlNode* aPolygonNode ) +{ + std::unique_ptr poly = std::make_unique( SHAPE_T::POLY ); + EPOLYGON epoly( aPolygonNode ); + wxXmlNode* vertex = aPolygonNode->GetChildren(); + VECTOR2I pt; + + while( vertex ) + { + if( vertex->GetName() == wxT( "vertex" ) ) // skip node + { + EVERTEX evertex( vertex ); + pt = VECTOR2I( evertex.x.ToSchUnits(), -evertex.y.ToSchUnits() ); + poly->AddPoint( pt ); + } + + vertex = vertex->GetNext(); + } + + poly->SetLayer( kiCadLayer( epoly.layer ) ); + poly->SetFillMode( FILL_T::FILLED_SHAPE ); + + return poly.release(); +} + + SCH_LINE* SCH_EAGLE_PLUGIN::loadWire( wxXmlNode* aWireNode ) { std::unique_ptr wire = std::make_unique(); @@ -1188,6 +1227,7 @@ SCH_LINE* SCH_EAGLE_PLUGIN::loadWire( wxXmlNode* aWireNode ) EWIRE ewire = EWIRE( aWireNode ); wire->SetLayer( kiCadLayer( ewire.layer ) ); + wire->SetStroke( STROKE_PARAMS( ewire.width.ToSchUnits(), PLOT_DASH_TYPE::SOLID ) ); VECTOR2I begin, end; @@ -1206,6 +1246,50 @@ SCH_LINE* SCH_EAGLE_PLUGIN::loadWire( wxXmlNode* aWireNode ) } +SCH_SHAPE* SCH_EAGLE_PLUGIN::loadCircle( wxXmlNode* aCircleNode ) +{ + std::unique_ptr circle = std::make_unique( SHAPE_T::CIRCLE ); + ECIRCLE c( aCircleNode ); + VECTOR2I center( c.x.ToSchUnits(), -c.y.ToSchUnits() ); + + circle->SetLayer( kiCadLayer( c.layer ) ); + circle->SetPosition( center ); + circle->SetEnd( VECTOR2I( center.x + c.radius.ToSchUnits(), center.y ) ); + circle->SetStroke( STROKE_PARAMS( c.width.ToSchUnits(), PLOT_DASH_TYPE::SOLID ) ); + + return circle.release(); +} + + +SCH_SHAPE* SCH_EAGLE_PLUGIN::loadRectangle( wxXmlNode* aRectNode ) +{ + std::unique_ptr rectangle = std::make_unique( SHAPE_T::RECT ); + ERECT rect( aRectNode ); + + rectangle->SetLayer( kiCadLayer( rect.layer ) ); + rectangle->SetPosition( VECTOR2I( rect.x1.ToSchUnits(), -rect.y1.ToSchUnits() ) ); + rectangle->SetEnd( VECTOR2I( rect.x2.ToSchUnits(), -rect.y2.ToSchUnits() ) ); + + if( rect.rot ) + { + VECTOR2I pos( rectangle->GetPosition() ); + VECTOR2I end( rectangle->GetEnd() ); + VECTOR2I center( rectangle->GetCenter() ); + + RotatePoint( pos, center, EDA_ANGLE( rect.rot->degrees, DEGREES_T ) ); + RotatePoint( end, center, EDA_ANGLE( rect.rot->degrees, DEGREES_T ) ); + + rectangle->SetPosition( pos ); + rectangle->SetEnd( end ); + } + + // Eagle rectangles are filled by definition. + rectangle->SetFillMode( FILL_T::FILLED_SHAPE ); + + return rectangle.release(); +} + + SCH_JUNCTION* SCH_EAGLE_PLUGIN::loadJunction( wxXmlNode* aJunction ) { std::unique_ptr junction = std::make_unique(); diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.h b/eeschema/sch_plugins/eagle/sch_eagle_plugin.h index 73dcd899b4..7ce3ee0770 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.h +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.h @@ -41,6 +41,7 @@ class SCH_SHEET; class SCH_BITMAP; class SCH_JUNCTION; class SCH_NO_CONNECT; +class SCH_SHAPE; class SCH_LINE; class SCH_BUS_ENTRY_BASE; class SCH_TEXT; @@ -130,7 +131,10 @@ private: void loadSegments( wxXmlNode* aSegmentsNode, const wxString& aNetName, const wxString& aNetClass ); + SCH_SHAPE* loadPolyLine( wxXmlNode* aPolygonNode ); SCH_LINE* loadWire( wxXmlNode* aWireNode ); + SCH_SHAPE* loadCircle( wxXmlNode* aCircleNode ); + SCH_SHAPE* loadRectangle( wxXmlNode* aRectNode ); SCH_TEXT* loadLabel( wxXmlNode* aLabelNode, const wxString& aNetName ); SCH_JUNCTION* loadJunction( wxXmlNode* aJunction ); SCH_TEXT* loadPlainText( wxXmlNode* aSchText );