From 992a553d439db81197ed3c735afe43ed41e6991c Mon Sep 17 00:00:00 2001 From: Hufo Date: Thu, 27 Feb 2020 23:54:19 +0000 Subject: [PATCH] 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 type in the python API. --- pcbnew/class_pad.h | 20 +++++++++------- pcbnew/microwave.cpp | 2 +- pcbnew/pad_custom_shape_functions.cpp | 34 +++++++++++++++++---------- pcbnew/pcb_parser.cpp | 21 +++++++++-------- pcbnew/plot_board_layers.cpp | 2 +- pcbnew/swig/pad.i | 22 +++++++++++++++++ 6 files changed, 69 insertions(+), 32 deletions(-) diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 71249e1f64..72b5b5a6c9 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -318,14 +318,18 @@ public: * a arc * a curve */ - void AddPrimitive( const SHAPE_POLY_SET& aPoly, int aThickness ); ///< add a polygonal basic shape - void AddPrimitive( const std::vector& aPoly, int aThickness ); ///< add a polygonal basic shape - void AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness ); ///< segment basic shape - void AddPrimitive( wxPoint aCenter, int aRadius, int aThickness ); ///< ring or circle basic shape - void AddPrimitive( wxPoint aCenter, wxPoint aStart, - int aArcAngle, int aThickness ); ///< arc basic shape - void AddPrimitive( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, - wxPoint aCtrl2, int aThickness ); ///< curve basic shape + void AddPrimitivePoly( const SHAPE_POLY_SET& aPoly, int aThickness, + bool aMergePrimitives = true ); ///< add a polygonal basic shape + void AddPrimitivePoly( const std::vector& aPoly, int aThickness, + bool aMergePrimitives = true ); ///< add a polygonal basic shape + void AddPrimitiveSegment( wxPoint aStart, wxPoint aEnd, int aThickness, + bool aMergePrimitives = true ); ///< segment basic shape + void AddPrimitiveCircle( wxPoint aCenter, int aRadius, int aThickness, + 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 ); diff --git a/pcbnew/microwave.cpp b/pcbnew/microwave.cpp index 6071279823..96afe85167 100644 --- a/pcbnew/microwave.cpp +++ b/pcbnew/microwave.cpp @@ -223,7 +223,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) // Close the polygon: polyPoints.push_back( polyPoints[0] ); - pad->AddPrimitive( polyPoints, 0 ); // add a polygonal basic shape + pad->AddPrimitivePoly( polyPoints, 0 ); // add a polygonal basic shape } break; diff --git a/pcbnew/pad_custom_shape_functions.cpp b/pcbnew/pad_custom_shape_functions.cpp index 38da24075f..c47cef8589 100644 --- a/pcbnew/pad_custom_shape_functions.cpp +++ b/pcbnew/pad_custom_shape_functions.cpp @@ -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 */ -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 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++ ) points.emplace_back( iter->x, iter->y ); - AddPrimitive( points, aThickness ); + AddPrimitivePoly( points, aThickness, aMergePrimitives ); } -void D_PAD::AddPrimitive( const std::vector& aPoly, int aThickness ) +void D_PAD::AddPrimitivePoly( + const std::vector& aPoly, int aThickness, bool aMergePrimitives ) { PAD_CS_PRIMITIVE shape( S_POLYGON ); shape.m_Poly = aPoly; shape.m_Thickness = aThickness; 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 ); shape.m_Start = aStart; @@ -165,11 +168,13 @@ void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness ) shape.m_Thickness = aThickness; 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 ); shape.m_Start = aCenter; @@ -178,11 +183,13 @@ void D_PAD::AddPrimitive( wxPoint aCenter, wxPoint aStart, int aArcAngle, int aT shape.m_Thickness = aThickness; 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 ); shape.m_Start = aStart; @@ -192,11 +199,13 @@ void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint shape.m_Thickness = aThickness; 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 ); shape.m_Start = aCenter; @@ -204,7 +213,8 @@ void D_PAD::AddPrimitive( wxPoint aCenter, int aRadius, int aThickness ) shape.m_Thickness = aThickness; m_basicShapes.push_back( shape ); - MergePrimitivesAsPolygon(); + if( aMergePrimitives ) + MergePrimitivesAsPolygon(); } diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 0423c18581..7f84c1fa23 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -3230,33 +3230,34 @@ D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent ) { case T_gr_arc: dummysegm = parseDRAWSEGMENT(); - pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetArcStart(), - dummysegm->GetAngle(), dummysegm->GetWidth() ); + pad->AddPrimitiveArc( dummysegm->GetCenter(), dummysegm->GetArcStart(), + dummysegm->GetAngle(), dummysegm->GetWidth(), false ); break; case T_gr_line: dummysegm = parseDRAWSEGMENT(); - pad->AddPrimitive( dummysegm->GetStart(), dummysegm->GetEnd(), - dummysegm->GetWidth() ); + pad->AddPrimitiveSegment( dummysegm->GetStart(), dummysegm->GetEnd(), + dummysegm->GetWidth(), false ); break; case T_gr_circle: dummysegm = parseDRAWSEGMENT( true ); // Circles with 0 thickness are allowed // ( filled circles ) - pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetRadius(), - dummysegm->GetWidth() ); + pad->AddPrimitiveCircle( dummysegm->GetCenter(), dummysegm->GetRadius(), + dummysegm->GetWidth(), false ); break; case T_gr_poly: dummysegm = parseDRAWSEGMENT(); - pad->AddPrimitive( dummysegm->BuildPolyPointsList(), dummysegm->GetWidth() ); + pad->AddPrimitivePoly( + dummysegm->BuildPolyPointsList(), dummysegm->GetWidth(), false ); break; case T_gr_curve: dummysegm = parseDRAWSEGMENT(); - pad->AddPrimitive( dummysegm->GetStart(), dummysegm->GetEnd(), - dummysegm->GetBezControl1(), dummysegm->GetBezControl2(), - dummysegm->GetWidth() ); + pad->AddPrimitiveCurve( dummysegm->GetStart(), dummysegm->GetEnd(), + dummysegm->GetBezControl1(), dummysegm->GetBezControl2(), + dummysegm->GetWidth(), false ); break; default: diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 39ba4ea4ae..4eafc8b871 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -451,7 +451,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, int numSegs = std::max( GetArcToSegmentCount( margin.x, maxError, 360.0 ), 6 ); shape.InflateWithLinkedHoles( margin.x, numSegs, SHAPE_POLY_SET::PM_FAST ); dummy.DeletePrimitivesList(); - dummy.AddPrimitive( shape, 0 ); + dummy.AddPrimitivePoly( shape, 0, false ); dummy.MergePrimitivesAsPolygon(); // Be sure the anchor pad is not bigger than the deflated shape because this diff --git a/pcbnew/swig/pad.i b/pcbnew/swig/pad.i index f0b3e8dc07..0025e23ebf 100644 --- a/pcbnew/swig/pad.i +++ b/pcbnew/swig/pad.i @@ -1,4 +1,8 @@ +%ignore std::vector::resize; +%ignore std::vector::vector(size_type); +%template(PAD_CS_PRIMITIVE_Vector) std::vector; + %include pad_shapes.h %include class_pad.h @@ -22,5 +26,23 @@ def GetPadName(self): 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.") %} }