pcbnew: Refactor D_PAD::AddPrimitives() and allow use from python

Rename all the D_PAD::AddPrimitive methods to clean up their API,
and expose the vector<PAD_CS_PRIMITIVE> type in the python API.
This commit is contained in:
Hufo 2020-02-27 23:54:19 +00:00 committed by Ian McInerney
parent 245b778454
commit 992a553d43
6 changed files with 69 additions and 32 deletions

View File

@ -318,14 +318,18 @@ public:
* a arc * a arc
* a curve * a curve
*/ */
void AddPrimitive( const SHAPE_POLY_SET& aPoly, int aThickness ); ///< add a polygonal basic shape void AddPrimitivePoly( const SHAPE_POLY_SET& aPoly, int aThickness,
void AddPrimitive( const std::vector<wxPoint>& aPoly, int aThickness ); ///< add a polygonal basic shape bool aMergePrimitives = true ); ///< add a polygonal basic shape
void AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness ); ///< segment basic shape void AddPrimitivePoly( const std::vector<wxPoint>& aPoly, int aThickness,
void AddPrimitive( wxPoint aCenter, int aRadius, int aThickness ); ///< ring or circle basic shape bool aMergePrimitives = true ); ///< add a polygonal basic shape
void AddPrimitive( wxPoint aCenter, wxPoint aStart, void AddPrimitiveSegment( wxPoint aStart, wxPoint aEnd, int aThickness,
int aArcAngle, int aThickness ); ///< arc basic shape bool aMergePrimitives = true ); ///< segment basic shape
void AddPrimitive( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, void AddPrimitiveCircle( wxPoint aCenter, int aRadius, int aThickness,
wxPoint aCtrl2, int aThickness ); ///< curve basic shape bool aMergePrimitives = true ); ///< ring or circle basic shape
void AddPrimitiveArc( wxPoint aCenter, wxPoint aStart, int aArcAngle, int aThickness,
bool aMergePrimitives = true ); ///< arc basic shape
void AddPrimitiveCurve( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint aCtrl2,
int aThickness, bool aMergePrimitives = true ); ///< curve basic shape
bool GetBestAnchorPosition( VECTOR2I& aPos ); bool GetBestAnchorPosition( VECTOR2I& aPos );

View File

@ -223,7 +223,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type )
// Close the polygon: // Close the polygon:
polyPoints.push_back( polyPoints[0] ); polyPoints.push_back( polyPoints[0] );
pad->AddPrimitive( polyPoints, 0 ); // add a polygonal basic shape pad->AddPrimitivePoly( polyPoints, 0 ); // add a polygonal basic shape
} }
break; break;

View File

@ -131,7 +131,7 @@ void PAD_CS_PRIMITIVE::Rotate( const wxPoint& aRotCentre, double aAngle )
* the shape is a polygon (can be with thick outline), segment, circle or arc * the shape is a polygon (can be with thick outline), segment, circle or arc
*/ */
void D_PAD::AddPrimitive( const SHAPE_POLY_SET& aPoly, int aThickness ) void D_PAD::AddPrimitivePoly( const SHAPE_POLY_SET& aPoly, int aThickness, bool aMergePrimitives )
{ {
std::vector<wxPoint> points; std::vector<wxPoint> points;
@ -143,21 +143,24 @@ void D_PAD::AddPrimitive( const SHAPE_POLY_SET& aPoly, int aThickness )
for( auto iter = poly_no_hole.CIterate(); iter; iter++ ) for( auto iter = poly_no_hole.CIterate(); iter; iter++ )
points.emplace_back( iter->x, iter->y ); points.emplace_back( iter->x, iter->y );
AddPrimitive( points, aThickness ); AddPrimitivePoly( points, aThickness, aMergePrimitives );
} }
void D_PAD::AddPrimitive( const std::vector<wxPoint>& aPoly, int aThickness ) void D_PAD::AddPrimitivePoly(
const std::vector<wxPoint>& aPoly, int aThickness, bool aMergePrimitives )
{ {
PAD_CS_PRIMITIVE shape( S_POLYGON ); PAD_CS_PRIMITIVE shape( S_POLYGON );
shape.m_Poly = aPoly; shape.m_Poly = aPoly;
shape.m_Thickness = aThickness; shape.m_Thickness = aThickness;
m_basicShapes.push_back( shape ); m_basicShapes.push_back( shape );
MergePrimitivesAsPolygon(); if( aMergePrimitives )
MergePrimitivesAsPolygon();
} }
void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness ) void D_PAD::AddPrimitiveSegment(
wxPoint aStart, wxPoint aEnd, int aThickness, bool aMergePrimitives )
{ {
PAD_CS_PRIMITIVE shape( S_SEGMENT ); PAD_CS_PRIMITIVE shape( S_SEGMENT );
shape.m_Start = aStart; shape.m_Start = aStart;
@ -165,11 +168,13 @@ void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness )
shape.m_Thickness = aThickness; shape.m_Thickness = aThickness;
m_basicShapes.push_back( shape ); m_basicShapes.push_back( shape );
MergePrimitivesAsPolygon(); if( aMergePrimitives )
MergePrimitivesAsPolygon();
} }
void D_PAD::AddPrimitive( wxPoint aCenter, wxPoint aStart, int aArcAngle, int aThickness ) void D_PAD::AddPrimitiveArc(
wxPoint aCenter, wxPoint aStart, int aArcAngle, int aThickness, bool aMergePrimitives )
{ {
PAD_CS_PRIMITIVE shape( S_ARC ); PAD_CS_PRIMITIVE shape( S_ARC );
shape.m_Start = aCenter; shape.m_Start = aCenter;
@ -178,11 +183,13 @@ void D_PAD::AddPrimitive( wxPoint aCenter, wxPoint aStart, int aArcAngle, int aT
shape.m_Thickness = aThickness; shape.m_Thickness = aThickness;
m_basicShapes.push_back( shape ); m_basicShapes.push_back( shape );
MergePrimitivesAsPolygon(); if( aMergePrimitives )
MergePrimitivesAsPolygon();
} }
void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint aCtrl2, int aThickness ) void D_PAD::AddPrimitiveCurve( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint aCtrl2,
int aThickness, bool aMergePrimitives )
{ {
PAD_CS_PRIMITIVE shape( S_CURVE ); PAD_CS_PRIMITIVE shape( S_CURVE );
shape.m_Start = aStart; shape.m_Start = aStart;
@ -192,11 +199,13 @@ void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint
shape.m_Thickness = aThickness; shape.m_Thickness = aThickness;
m_basicShapes.push_back( shape ); m_basicShapes.push_back( shape );
MergePrimitivesAsPolygon(); if( aMergePrimitives )
MergePrimitivesAsPolygon();
} }
void D_PAD::AddPrimitive( wxPoint aCenter, int aRadius, int aThickness ) void D_PAD::AddPrimitiveCircle(
wxPoint aCenter, int aRadius, int aThickness, bool aMergePrimitives )
{ {
PAD_CS_PRIMITIVE shape( S_CIRCLE ); PAD_CS_PRIMITIVE shape( S_CIRCLE );
shape.m_Start = aCenter; shape.m_Start = aCenter;
@ -204,7 +213,8 @@ void D_PAD::AddPrimitive( wxPoint aCenter, int aRadius, int aThickness )
shape.m_Thickness = aThickness; shape.m_Thickness = aThickness;
m_basicShapes.push_back( shape ); m_basicShapes.push_back( shape );
MergePrimitivesAsPolygon(); if( aMergePrimitives )
MergePrimitivesAsPolygon();
} }

View File

@ -3230,33 +3230,34 @@ D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent )
{ {
case T_gr_arc: case T_gr_arc:
dummysegm = parseDRAWSEGMENT(); dummysegm = parseDRAWSEGMENT();
pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetArcStart(), pad->AddPrimitiveArc( dummysegm->GetCenter(), dummysegm->GetArcStart(),
dummysegm->GetAngle(), dummysegm->GetWidth() ); dummysegm->GetAngle(), dummysegm->GetWidth(), false );
break; break;
case T_gr_line: case T_gr_line:
dummysegm = parseDRAWSEGMENT(); dummysegm = parseDRAWSEGMENT();
pad->AddPrimitive( dummysegm->GetStart(), dummysegm->GetEnd(), pad->AddPrimitiveSegment( dummysegm->GetStart(), dummysegm->GetEnd(),
dummysegm->GetWidth() ); dummysegm->GetWidth(), false );
break; break;
case T_gr_circle: case T_gr_circle:
dummysegm = parseDRAWSEGMENT( true ); // Circles with 0 thickness are allowed dummysegm = parseDRAWSEGMENT( true ); // Circles with 0 thickness are allowed
// ( filled circles ) // ( filled circles )
pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetRadius(), pad->AddPrimitiveCircle( dummysegm->GetCenter(), dummysegm->GetRadius(),
dummysegm->GetWidth() ); dummysegm->GetWidth(), false );
break; break;
case T_gr_poly: case T_gr_poly:
dummysegm = parseDRAWSEGMENT(); dummysegm = parseDRAWSEGMENT();
pad->AddPrimitive( dummysegm->BuildPolyPointsList(), dummysegm->GetWidth() ); pad->AddPrimitivePoly(
dummysegm->BuildPolyPointsList(), dummysegm->GetWidth(), false );
break; break;
case T_gr_curve: case T_gr_curve:
dummysegm = parseDRAWSEGMENT(); dummysegm = parseDRAWSEGMENT();
pad->AddPrimitive( dummysegm->GetStart(), dummysegm->GetEnd(), pad->AddPrimitiveCurve( dummysegm->GetStart(), dummysegm->GetEnd(),
dummysegm->GetBezControl1(), dummysegm->GetBezControl2(), dummysegm->GetBezControl1(), dummysegm->GetBezControl2(),
dummysegm->GetWidth() ); dummysegm->GetWidth(), false );
break; break;
default: default:

View File

@ -451,7 +451,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter,
int numSegs = std::max( GetArcToSegmentCount( margin.x, maxError, 360.0 ), 6 ); int numSegs = std::max( GetArcToSegmentCount( margin.x, maxError, 360.0 ), 6 );
shape.InflateWithLinkedHoles( margin.x, numSegs, SHAPE_POLY_SET::PM_FAST ); shape.InflateWithLinkedHoles( margin.x, numSegs, SHAPE_POLY_SET::PM_FAST );
dummy.DeletePrimitivesList(); dummy.DeletePrimitivesList();
dummy.AddPrimitive( shape, 0 ); dummy.AddPrimitivePoly( shape, 0, false );
dummy.MergePrimitivesAsPolygon(); dummy.MergePrimitivesAsPolygon();
// Be sure the anchor pad is not bigger than the deflated shape because this // Be sure the anchor pad is not bigger than the deflated shape because this

View File

@ -1,4 +1,8 @@
%ignore std::vector<PAD_CS_PRIMITIVE>::resize;
%ignore std::vector<PAD_CS_PRIMITIVE>::vector(size_type);
%template(PAD_CS_PRIMITIVE_Vector) std::vector<PAD_CS_PRIMITIVE>;
%include pad_shapes.h %include pad_shapes.h
%include class_pad.h %include class_pad.h
@ -22,5 +26,23 @@
def GetPadName(self): def GetPadName(self):
return self.GetName() return self.GetName()
# AddPrimitive() is the old name for D_PAD::AddPrimitivePoly(),
# D_PAD::AddPrimitiveSegment(), D_PAD::AddPrimitiveCircle(),
# D_PAD::AddPrimitiveArc(), D_PAD::AddPrimitiveCurve()
# define it for compatibility
def AddPrimitive(self, *args):
if len(args) == 2:
return self.AddPrimitivePoly(*args)
elif len(args) == 3:
if type(args[1] in [wxPoint,wxSize]):
return self.AddPrimitiveSegment(*args)
else:
return self.AddPrimitiveCircle(*args)
elif len(args) == 4:
return self.AddPrimitiveArc(*args)
elif len(args) == 5:
return self.AddPrimitiveCurve(*args)
else:
raise TypeError("Arguments not recognized.")
%} %}
} }