Eeschema Eagle Import: Improve arc parsing to replicate eagle filled arcs.

This commit is contained in:
Russell Oliver 2017-07-25 23:51:07 +10:00 committed by Maciej Suminski
parent e379329ee6
commit 64f4eaddff
4 changed files with 77 additions and 15 deletions

View File

@ -745,7 +745,7 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )
} }
m_Pos = newCenterPoint; m_Pos = newCenterPoint;
calcRadiusAngles(); CalcRadiusAngles();
} }
else if( m_Flags == IS_NEW ) else if( m_Flags == IS_NEW )
{ {
@ -781,7 +781,7 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )
cY += m_ArcStart.y; cY += m_ArcStart.y;
m_Pos.x = cX; m_Pos.x = cX;
m_Pos.y = cY; m_Pos.y = cY;
calcRadiusAngles(); CalcRadiusAngles();
SetEraseLastDrawItem(); SetEraseLastDrawItem();
} }
@ -792,7 +792,7 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )
} }
void LIB_ARC::calcRadiusAngles() void LIB_ARC::CalcRadiusAngles()
{ {
wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart ); wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart );
wxPoint centerEndVector = twoPointVector( m_Pos, m_ArcEnd ); wxPoint centerEndVector = twoPointVector( m_Pos, m_ArcEnd );

View File

@ -78,10 +78,6 @@ class LIB_ARC : public LIB_ITEM
*/ */
void calcEdit( const wxPoint& aPosition ) override; void calcEdit( const wxPoint& aPosition ) override;
/**
* Calculate the radius and angle of an arc using the start, end, and center points.
*/
void calcRadiusAngles();
public: public:
LIB_ARC( LIB_PART * aParent ); LIB_ARC( LIB_PART * aParent );
@ -153,6 +149,12 @@ public:
void SetEnd( const wxPoint& aPoint ) { m_ArcEnd = aPoint; } void SetEnd( const wxPoint& aPoint ) { m_ArcEnd = aPoint; }
/**
* Calculate the radius and angle of an arc using the start, end, and center points.
*/
void CalcRadiusAngles();
wxString GetSelectMenuText() const override; wxString GetSelectMenuText() const override;
BITMAP_DEF GetMenuImage() const override; BITMAP_DEF GetMenuImage() const override;

View File

@ -36,6 +36,7 @@
#include <class_libentry.h> #include <class_libentry.h>
#include <lib_draw_item.h> #include <lib_draw_item.h>
#include <sch_component.h> #include <sch_component.h>
#include <lib_arc.h>
#include <lib_circle.h> #include <lib_circle.h>
#include <lib_rectangle.h> #include <lib_rectangle.h>
#include <lib_polyline.h> #include <lib_polyline.h>
@ -1373,7 +1374,7 @@ void SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode,
} }
else if( nodeName == "wire" ) else if( nodeName == "wire" )
{ {
LIB_POLYLINE* pline = loadSymbolWire( aPart, currentNode ); LIB_ITEM* pline = loadSymbolWire( aPart, currentNode );
pline->SetUnit( gateNumber ); pline->SetUnit( gateNumber );
aPart->AddDrawItem( pline ); aPart->AddDrawItem( pline );
} }
@ -1423,23 +1424,82 @@ LIB_RECTANGLE* SCH_EAGLE_PLUGIN::loadSymbolRectangle( LIB_PART* aPart, wxXmlNode
} }
LIB_POLYLINE* SCH_EAGLE_PLUGIN::loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWireNode ) LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWireNode )
{ {
// TODO: Layer map // TODO: Layer map
std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart ) );
auto ewire = EWIRE( aWireNode ); auto ewire = EWIRE( aWireNode );
wxPoint begin, end;
wxRealPoint begin, end;
begin.x = ewire.x1 * EUNIT_TO_MIL; begin.x = ewire.x1 * EUNIT_TO_MIL;
begin.y = ewire.y1 * EUNIT_TO_MIL; begin.y = ewire.y1 * EUNIT_TO_MIL;
end.x = ewire.x2 * EUNIT_TO_MIL; end.x = ewire.x2 * EUNIT_TO_MIL;
end.y = ewire.y2 * EUNIT_TO_MIL; end.y = ewire.y2 * EUNIT_TO_MIL;
if( ewire.curve )
{
std::unique_ptr<LIB_ARC> arc( new LIB_ARC( aPart ) );
wxRealPoint center = kicad_arc_center( begin, end, *ewire.curve*-1);
polyLine->AddPoint( begin ); arc->SetPosition(center);
polyLine->AddPoint( end ); arc->SetStart( begin );
arc->SetEnd( end );
arc->SetWidth(ewire.width*EUNIT_TO_MIL);
double radius = sqrt( abs( ( (center.x-begin.x)*(center.x-begin.x) ) + ( (center.y-begin.y)*(center.y-begin.y) ) ) );
arc->SetRadius(radius);
arc->CalcRadiusAngles();
if(ewire.width*2*EUNIT_TO_MIL > radius){
wxRealPoint centerStartVector = center - begin;
wxRealPoint centerEndVector = center - end;
centerStartVector.x = centerStartVector.x/radius;
centerStartVector.y = centerStartVector.y/radius;
centerEndVector.x = centerEndVector.x/radius;
centerEndVector.y = centerEndVector.y/radius;
centerStartVector.x = centerStartVector.x*(ewire.width*EUNIT_TO_MIL+radius);
centerStartVector.y = centerStartVector.y*(ewire.width*EUNIT_TO_MIL+radius);
centerEndVector.x = centerEndVector.x*(ewire.width*EUNIT_TO_MIL+radius);
centerEndVector.y = centerEndVector.y*(ewire.width*EUNIT_TO_MIL+radius);
begin = center + centerStartVector;
end = center + centerEndVector;
radius = sqrt( abs( ( (center.x-begin.x)*(center.x-begin.x) ) + ( (center.y-begin.y)*(center.y-begin.y) ) ) );
center = kicad_arc_center( begin, end, *ewire.curve*-1);
arc->SetPosition(center);
arc->SetStart( begin );
arc->SetEnd( end );
arc->SetRadius(radius);
arc->CalcRadiusAngles();
arc->SetWidth(0.001);
arc->SetFillMode(FILLED_SHAPE);
}
return (LIB_ITEM*) arc.release();
}
else
{
std::unique_ptr<LIB_POLYLINE> polyLine( new LIB_POLYLINE( aPart ) );
polyLine->AddPoint( begin );
polyLine->AddPoint( end );
return (LIB_ITEM*) polyLine.release();
}
return polyLine.release();
} }

View File

@ -152,7 +152,7 @@ private:
LIB_CIRCLE* loadSymbolCircle( LIB_PART* aPart, wxXmlNode* aCircleNode ); LIB_CIRCLE* loadSymbolCircle( LIB_PART* aPart, wxXmlNode* aCircleNode );
LIB_RECTANGLE* loadSymbolRectangle( LIB_PART* aPart, wxXmlNode* aRectNode ); LIB_RECTANGLE* loadSymbolRectangle( LIB_PART* aPart, wxXmlNode* aRectNode );
LIB_POLYLINE* loadSymbolPolyLine( LIB_PART* aPart, wxXmlNode* aPolygonNode ); LIB_POLYLINE* loadSymbolPolyLine( LIB_PART* aPart, wxXmlNode* aPolygonNode );
LIB_POLYLINE* loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWireNode ); LIB_ITEM* loadSymbolWire( LIB_PART* aPart, wxXmlNode* aWireNode );
LIB_PIN* loadPin( LIB_PART*, wxXmlNode* ); LIB_PIN* loadPin( LIB_PART*, wxXmlNode* );
LIB_TEXT* loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibText ); LIB_TEXT* loadSymboltext( LIB_PART* aPart, wxXmlNode* aLibText );