From 3c6e8c4a40c7347c76926db5f772550fd5efcc89 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 9 Jul 2018 19:15:36 +0200 Subject: [PATCH] More support of DRW_SEGMENT Bezier curve (support in 3D viewer, and PnS router). --- .../3d_canvas/create_3Dgraphic_brd_items.cpp | 4 +- .../convert_drawsegment_list_to_polygon.cpp | 92 ++++++++++++++++++- pcbnew/router/pns_kicad_iface.cpp | 18 +++- 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index f1763428e1..b7914e8fd0 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -821,6 +821,7 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSeg } break; + case S_CURVE: case S_POLYGON: { const int segcountforcircle = 16; @@ -843,9 +844,6 @@ void CINFO3D_VISU::AddShapeWithClearanceToContainer( const DRAWSEGMENT* aDrawSeg } break; - case S_CURVE: // Bezier curve (not yet in use in KiCad) - break; - default: break; } diff --git a/pcbnew/convert_drawsegment_list_to_polygon.cpp b/pcbnew/convert_drawsegment_list_to_polygon.cpp index 1003ddb84a..59a8288593 100644 --- a/pcbnew/convert_drawsegment_list_to_polygon.cpp +++ b/pcbnew/convert_drawsegment_list_to_polygon.cpp @@ -264,6 +264,23 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SE } break; + case S_CURVE: + { + graphic->RebuildBezierToSegmentsPointsList( graphic->GetWidth() ); + + for( unsigned int jj = 0; jj < graphic->GetBezierPoints().size(); jj++ ) + { + wxPoint pt = graphic->GetBezierPoints()[jj]; + + if( pt.x < xmin.x ) + { + xmin = pt; + xmini = i; + } + } + } + break; + default: break; } @@ -295,7 +312,7 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SE aPolygons.Append( prevPt ); // Do not append the other end point yet of this 'graphic', this first - // 'graphic' might be an arc. + // 'graphic' might be an arc or a curve. for(;;) { @@ -354,6 +371,43 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SE } break; + case S_CURVE: + // We do not support Bezier curves in polygons, so approximate + // with a series of short lines and put those + // line segments into the !same! PATH. + { + wxPoint nextPt; + bool reverse = false; + + // Use the end point furthest away from + // prevPt as we assume the other end to be ON prevPt or + // very close to it. + + if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) ) + nextPt = graphic->GetEnd(); + else + { + nextPt = graphic->GetStart(); + reverse = true; + } + + if( reverse ) + { + for( int jj = graphic->GetBezierPoints().size()-1; + jj >= 0; jj-- ) + aPolygons.Append( graphic->GetBezierPoints()[jj] ); + } + else + { + for( unsigned int jj = 0; + jj < graphic->GetBezierPoints().size(); jj++ ) + aPolygons.Append( graphic->GetBezierPoints()[jj] ); + } + + prevPt = nextPt; + } + break; + default: if( aErrorText ) { @@ -499,6 +553,42 @@ bool ConvertOutlineToPolygon( std::vector& aSegList, SHAPE_POLY_SE prevPt = nextPt; } + + case S_CURVE: + // We do not support Bezier curves in polygons, so approximate + // with a series of short lines and put those + // line segments into the !same! PATH. + { + wxPoint nextPt; + bool reverse = false; + + // Use the end point furthest away from + // prevPt as we assume the other end to be ON prevPt or + // very close to it. + + if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) ) + nextPt = graphic->GetEnd(); + else + { + nextPt = graphic->GetStart(); + reverse = true; + } + + if( reverse ) + { + for( int jj = graphic->GetBezierPoints().size()-1; + jj >= 0; jj-- ) + aPolygons.Append( graphic->GetBezierPoints()[jj], -1, hole ); + } + else + { + for( unsigned int jj = 0; + jj < graphic->GetBezierPoints().size(); jj++ ) + aPolygons.Append( graphic->GetBezierPoints()[jj], -1, hole ); + } + + prevPt = nextPt; + } break; default: diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 71125e55fd..17d2c0a61f 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -151,7 +151,7 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* { m_defaultClearance = defaultRule->GetClearance(); } - else + else { m_defaultClearance = Millimeter2iu(0.254); } @@ -891,6 +891,22 @@ bool PNS_KICAD_IFACE::syncGraphicalItem( PNS::NODE* aWorld, DRAWSEGMENT* aItem ) break; } + case S_CURVE: + { + aItem->RebuildBezierToSegmentsPointsList( aItem->GetWidth() ); + wxPoint start_pt = aItem->GetBezierPoints()[0]; + + for( unsigned int jj = 1; jj < aItem->GetBezierPoints().size(); jj++ ) + { + wxPoint end_pt = aItem->GetBezierPoints()[jj]; + SHAPE_SEGMENT *seg = new SHAPE_SEGMENT( + VECTOR2I( start_pt ), VECTOR2I( end_pt ), aItem->GetWidth() ); + segs.push_back( seg ); + start_pt = end_pt; + } + } + break; + default: break; }