Eagle schematic import: Added missing plain elements

This commit is contained in:
Dag Lem 2023-01-09 14:18:23 +00:00 committed by Wayne Stambaugh
parent c3ded7a03d
commit 8c8b4f43e7
2 changed files with 90 additions and 2 deletions

View File

@ -52,6 +52,7 @@
#include <sch_plugins/legacy/sch_legacy_plugin.h>
#include <sch_marker.h>
#include <sch_screen.h>
#include <sch_shape.h>
#include <sch_sheet.h>
#include <sch_sheet_path.h>
#include <sch_label.h>
@ -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<SCH_LINE*> 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<SCH_SHAPE> poly = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY );
EPOLYGON epoly( aPolygonNode );
wxXmlNode* vertex = aPolygonNode->GetChildren();
VECTOR2I pt;
while( vertex )
{
if( vertex->GetName() == wxT( "vertex" ) ) // skip <xmlattr> 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<SCH_LINE> wire = std::make_unique<SCH_LINE>();
@ -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<SCH_SHAPE> circle = std::make_unique<SCH_SHAPE>( 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<SCH_SHAPE> rectangle = std::make_unique<SCH_SHAPE>( 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<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();

View File

@ -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 );