From 9ba9f0288ea79f70b77f002e2a5b378cf05d4b9c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 19 Jun 2020 16:09:25 +0100 Subject: [PATCH] Read files with rectangle primitives in custom pads. --- pcbnew/class_pad.h | 22 ++++++++++++---------- pcbnew/pad_custom_shape_functions.cpp | 26 ++++++++++++++++++++------ pcbnew/pcb_parser.cpp | 24 ++++++++++++++++-------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index eb3e888855..8d2babe825 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -304,17 +304,19 @@ public: * a curve */ void AddPrimitivePoly( const SHAPE_POLY_SET& aPoly, int aThickness, - bool aMergePrimitives = true ); ///< add a polygonal basic shape + bool aMergePrimitives = true ); 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 aMergePrimitives = true ); + void AddPrimitiveSegment( const wxPoint& aStart, const wxPoint& aEnd, int aThickness, + bool aMergePrimitives = true ); + void AddPrimitiveCircle( const wxPoint& aCenter, int aRadius, int aThickness, + bool aMergePrimitives = true ); ///< ring or circle basic shape + void AddPrimitiveRect( const wxPoint& aStart, const wxPoint& aEnd, int aThickness, + bool aMergePrimitives = true ); + void AddPrimitiveArc( const wxPoint& aCenter, const wxPoint& aStart, int aArcAngle, + int aThickness, bool aMergePrimitives = true ); + void AddPrimitiveCurve( const wxPoint& aStart, const wxPoint& aEnd, const wxPoint& aCtrl1, + const wxPoint& aCtrl2, int aThickness, bool aMergePrimitives = true ); bool GetBestAnchorPosition( VECTOR2I& aPos ); diff --git a/pcbnew/pad_custom_shape_functions.cpp b/pcbnew/pad_custom_shape_functions.cpp index e741522db6..ac81e891ee 100644 --- a/pcbnew/pad_custom_shape_functions.cpp +++ b/pcbnew/pad_custom_shape_functions.cpp @@ -174,7 +174,7 @@ void D_PAD::AddPrimitivePoly( const std::vector& aPoly, int aThickness, } -void D_PAD::AddPrimitiveSegment( wxPoint aStart, wxPoint aEnd, int aThickness, +void D_PAD::AddPrimitiveSegment( const wxPoint& aStart, const wxPoint& aEnd, int aThickness, bool aMergePrimitives ) { PAD_CS_PRIMITIVE shape( S_SEGMENT ); @@ -188,8 +188,8 @@ void D_PAD::AddPrimitiveSegment( wxPoint aStart, wxPoint aEnd, int aThickness, } -void D_PAD::AddPrimitiveArc( wxPoint aCenter, wxPoint aStart, int aArcAngle, int aThickness, - bool aMergePrimitives ) +void D_PAD::AddPrimitiveArc( const wxPoint& aCenter, const wxPoint& aStart, int aArcAngle, + int aThickness, bool aMergePrimitives ) { PAD_CS_PRIMITIVE shape( S_ARC ); shape.m_Start = aCenter; @@ -203,8 +203,8 @@ void D_PAD::AddPrimitiveArc( wxPoint aCenter, wxPoint aStart, int aArcAngle, int } -void D_PAD::AddPrimitiveCurve( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint aCtrl2, - int aThickness, bool aMergePrimitives ) +void D_PAD::AddPrimitiveCurve( const wxPoint& aStart, const wxPoint& aEnd, const wxPoint& aCtrl1, + const wxPoint& aCtrl2, int aThickness, bool aMergePrimitives ) { PAD_CS_PRIMITIVE shape( S_CURVE ); shape.m_Start = aStart; @@ -219,7 +219,7 @@ void D_PAD::AddPrimitiveCurve( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxP } -void D_PAD::AddPrimitiveCircle( wxPoint aCenter, int aRadius, int aThickness, +void D_PAD::AddPrimitiveCircle( const wxPoint& aCenter, int aRadius, int aThickness, bool aMergePrimitives ) { PAD_CS_PRIMITIVE shape( S_CIRCLE ); @@ -233,6 +233,20 @@ void D_PAD::AddPrimitiveCircle( wxPoint aCenter, int aRadius, int aThickness, } +void D_PAD::AddPrimitiveRect( const wxPoint& aStart, const wxPoint& aEnd, int aThickness, + bool aMergePrimitives ) +{ + PAD_CS_PRIMITIVE shape( S_RECT ); + shape.m_Start = aStart; + shape.m_End = aEnd; + shape.m_Thickness = aThickness; + m_basicShapes.push_back( shape ); + + if( aMergePrimitives ) + MergePrimitivesAsPolygon(); +} + + bool D_PAD::SetPrimitives( const std::vector& aPrimitivesList ) { // clear old list diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 6b12c149f3..2874bfb062 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -3352,37 +3352,45 @@ D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent ) case T_gr_arc: dummysegm = parseDRAWSEGMENT(); pad->AddPrimitiveArc( dummysegm->GetCenter(), dummysegm->GetArcStart(), - dummysegm->GetAngle(), dummysegm->GetWidth(), false ); + dummysegm->GetAngle(), dummysegm->GetWidth(), false ); break; case T_gr_line: dummysegm = parseDRAWSEGMENT(); pad->AddPrimitiveSegment( dummysegm->GetStart(), dummysegm->GetEnd(), - dummysegm->GetWidth(), false ); + dummysegm->GetWidth(), false ); break; case T_gr_circle: dummysegm = parseDRAWSEGMENT( true ); // Circles with 0 thickness are allowed // ( filled circles ) pad->AddPrimitiveCircle( dummysegm->GetCenter(), dummysegm->GetRadius(), - dummysegm->GetWidth(), false ); + dummysegm->GetWidth(), false ); break; + case T_gr_rect: + dummysegm = parseDRAWSEGMENT( true ); + pad->AddPrimitiveRect( dummysegm->GetStart(), dummysegm->GetEnd(), + dummysegm->GetWidth(), false ); + break; + + case T_gr_poly: dummysegm = parseDRAWSEGMENT(); - pad->AddPrimitivePoly( - dummysegm->BuildPolyPointsList(), dummysegm->GetWidth(), false ); + pad->AddPrimitivePoly( dummysegm->BuildPolyPointsList(), + dummysegm->GetWidth(), false ); break; case T_gr_curve: dummysegm = parseDRAWSEGMENT(); pad->AddPrimitiveCurve( dummysegm->GetStart(), dummysegm->GetEnd(), - dummysegm->GetBezControl1(), dummysegm->GetBezControl2(), - dummysegm->GetWidth(), false ); + dummysegm->GetBezControl1(), + dummysegm->GetBezControl2(), + dummysegm->GetWidth(), false ); break; default: - Expecting( "gr_line, gr_arc, gr_circle, gr_curve or gr_poly" ); + Expecting( "gr_line, gr_arc, gr_circle, gr_curve, gr_rect or gr_poly" ); break; }