| 
    KiCad PCB EDA Suite
    
   | 
 
#include <unordered_set>#include <deque>#include <trigo.h>#include <macros.h>#include <math/vector2d.h>#include <pcb_shape.h>#include <footprint.h>#include <pad.h>#include <base_units.h>#include <convert_basic_shapes_to_polygon.h>#include <geometry/shape_poly_set.h>#include <geometry/geometry_utils.h>#include <geometry/roundrect.h>#include <convert_shape_list_to_polygon.h>#include <board.h>#include <collectors.h>#include <nanoflann.hpp>#include <wx/log.h>Go to the source code of this file.
Classes | |
| class | SCOPED_FLAGS_CLEANER | 
| struct | PCB_SHAPE_ENDPOINTS_ADAPTOR | 
Typedefs | |
| using | KDTree | 
Functions | |
| static bool | close_enough (VECTOR2I aLeft, VECTOR2I aRight, unsigned aLimit) | 
| Local and tunable method of qualifying the proximity of two points.   | |
| static bool | closer_to_first (VECTOR2I aRef, VECTOR2I aFirst, VECTOR2I aSecond) | 
| Local method which qualifies whether the start or end point of a segment is closest to a point.   | |
| static bool | isCopperOutside (const FOOTPRINT *aFootprint, SHAPE_POLY_SET &aShape) | 
| static void | processClosedShape (PCB_SHAPE *aShape, SHAPE_LINE_CHAIN &aContour, std::map< std::pair< VECTOR2I, VECTOR2I >, PCB_SHAPE * > &aShapeOwners, int aErrorMax, bool aAllowUseArcsInPolygons) | 
| static void | processShapeSegment (PCB_SHAPE *aShape, SHAPE_LINE_CHAIN &aContour, VECTOR2I &aPrevPt, std::map< std::pair< VECTOR2I, VECTOR2I >, PCB_SHAPE * > &aShapeOwners, int aErrorMax, int aChainingEpsilon, bool aAllowUseArcsInPolygons) | 
| static std::map< int, std::vector< int > > | buildContourHierarchy (const std::vector< SHAPE_LINE_CHAIN > &aContours) | 
| static bool | addOutlinesToPolygon (const std::vector< SHAPE_LINE_CHAIN > &aContours, const std::map< int, std::vector< int > > &aContourHierarchy, SHAPE_POLY_SET &aPolygons, bool aAllowDisjoint, OUTLINE_ERROR_HANDLER *aErrorHandler, const std::function< PCB_SHAPE *(const SEG &)> &aFetchOwner, std::map< int, int > &aContourToOutlineIdxMap) | 
| static void | addHolesToPolygon (const std::vector< SHAPE_LINE_CHAIN > &aContours, const std::map< int, std::vector< int > > &aContourHierarchy, const std::map< int, int > &aContourToOutlineIdxMap, SHAPE_POLY_SET &aPolygons) | 
| static bool | checkSelfIntersections (SHAPE_POLY_SET &aPolygons, OUTLINE_ERROR_HANDLER *aErrorHandler, const std::function< PCB_SHAPE *(const SEG &)> &aFetchOwner) | 
| static PCB_SHAPE * | findNext (PCB_SHAPE *aShape, const VECTOR2I &aPoint, const KDTree &kdTree, const PCB_SHAPE_ENDPOINTS_ADAPTOR &adaptor, double aChainingEpsilon) | 
| bool | doConvertOutlineToPolygon (std::vector< PCB_SHAPE * > &aShapeList, SHAPE_POLY_SET &aPolygons, int aErrorMax, int aChainingEpsilon, bool aAllowDisjoint, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons, SCOPED_FLAGS_CLEANER &aCleaner) | 
| bool | ConvertOutlineToPolygon (std::vector< PCB_SHAPE * > &aShapeList, SHAPE_POLY_SET &aPolygons, int aErrorMax, int aChainingEpsilon, bool aAllowDisjoint, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons) | 
| Build a polygon set with holes from a PCB_SHAPE list.   | |
| bool | TestBoardOutlinesGraphicItems (BOARD *aBoard, int aMinDist, OUTLINE_ERROR_HANDLER *aErrorHandler) | 
| Test a board graphic items on edge cut layer for validity.   | |
| bool | BuildBoardPolygonOutlines (BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons) | 
| Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut layer.   | |
| void | buildBoardBoundingBoxPoly (const BOARD *aBoard, SHAPE_POLY_SET &aOutline) | 
| Get the complete bounding box of the board (including all items).   | |
| VECTOR2I | projectPointOnSegment (const VECTOR2I &aEndPoint, const SHAPE_POLY_SET &aOutline, int aOutlineNum=0) | 
| int | findEndSegments (SHAPE_LINE_CHAIN &aChain, SEG &aStartSeg, SEG &aEndSeg) | 
| bool | BuildFootprintPolygonOutlines (BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, OUTLINE_ERROR_HANDLER *aErrorHandler) | 
| Extract a board outline for a footprint view.   | |
Variables | |
| const wxChar * | traceBoardOutline = wxT( "KICAD_BOARD_OUTLINE" ) | 
| Flag to enable debug tracing for the board outline creation.   | |
| using KDTree | 
Definition at line 173 of file convert_shape_list_to_polygon.cpp.
      
  | 
  static | 
Definition at line 431 of file convert_shape_list_to_polygon.cpp.
References SHAPE_POLY_SET::AddHole().
Referenced by doConvertOutlineToPolygon().
      
  | 
  static | 
Definition at line 396 of file convert_shape_list_to_polygon.cpp.
References _, SHAPE_POLY_SET::AddOutline(), SHAPE_LINE_CHAIN::GetSegment(), SHAPE_POLY_SET::IsEmpty(), SHAPE_POLY_SET::Outline(), and SHAPE_POLY_SET::OutlineCount().
Referenced by doConvertOutlineToPolygon().
| void buildBoardBoundingBoxPoly | ( | const BOARD * | aBoard, | 
| SHAPE_POLY_SET & | aOutline ) | 
Get the complete bounding box of the board (including all items).
The vertex numbers and segment numbers of the rectangle returned. 1 ------------— |1 2| 0| |2 |0 3| ------------— 3
Definition at line 1145 of file convert_shape_list_to_polygon.cpp.
References SHAPE_POLY_SET::AddOutline(), chain, BOARD::ComputeBoundingBox(), BOARD::GetBoundingBox(), BOX2< Vec >::GetEnd(), BOX2< Vec >::GetHeight(), BOX2< Vec >::GetOrigin(), BOX2< Vec >::GetWidth(), BOX2< Vec >::Inflate(), pcbIUScale, SHAPE_POLY_SET::RemoveAllContours(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by BuildFootprintPolygonOutlines(), and RENDER_3D_RAYTRACE_BASE::Reload().
| bool BuildBoardPolygonOutlines | ( | BOARD * | aBoard, | 
| SHAPE_POLY_SET & | aOutlines, | ||
| int | aErrorMax, | ||
| int | aChainingEpsilon, | ||
| OUTLINE_ERROR_HANDLER * | aErrorHandler = nullptr, | ||
| bool | aAllowUseArcsInPolygons = false ) | 
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut layer.
Any closed outline inside the main outline is a hole. All contours should be closed, i.e. are valid vertices for a closed polygon.
| aBoard | is the board to build outlines. | 
| aOutlines | will contain the outlines ( complex polygons ). | 
| aErrorMax | is the max error distance when polygonizing a curve (internal units). | 
| aChainingEpsilon | is the max distance from one endPt to the next startPt (internal units), | 
| aErrorHandler | = an optional error handler. | 
| aAllowUseArcsInPolygons | is an option to allow adding arcs in SHAPE_LINE_CHAIN polylines/polygons when building outlines from aShapeList This is mainly for export to STEP files. | 
Definition at line 968 of file convert_shape_list_to_polygon.cpp.
References SHAPE_POLY_SET::AddHole(), SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::BooleanSubtract(), SHAPE_POLY_SET::CloneDropTriangulation(), PCB_TYPE_COLLECTOR::Collect(), BOARD::ComputeBoundingBox(), SHAPE_LINE_CHAIN::CPoint(), doConvertOutlineToPolygon(), Edge_Cuts, BOARD::Footprints(), BOARD::GetBoardEdgesBoundingBox(), COLLECTOR::GetCount(), BOX2< Vec >::GetEnd(), EDA_ITEM::GetFlags(), BOX2< Vec >::GetHeight(), PCB_SHAPE::GetLayer(), BOX2< Vec >::GetOrigin(), BOX2< Vec >::GetWidth(), SHAPE_POLY_SET::Hole(), SHAPE_POLY_SET::HoleCount(), BOX2< Vec >::Inflate(), isCopperOutside(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), PCB_SHAPE_T, pcbIUScale, SHAPE_LINE_CHAIN_BASE::PointInside(), SHAPE_POLY_SET::RemoveAllContours(), result, SKIP_STRUCT, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by BOARD::GetBoardPolygonOutlines(), DIALOG_EXPORT_STEP::onExportButton(), and DRC_TEST_PROVIDER_MISC::testOutline().
      
  | 
  static | 
Definition at line 370 of file convert_shape_list_to_polygon.cpp.
References SHAPE_LINE_CHAIN_BASE::PointInside().
Referenced by doConvertOutlineToPolygon().
| bool BuildFootprintPolygonOutlines | ( | BOARD * | aBoard, | 
| SHAPE_POLY_SET & | aOutlines, | ||
| int | aErrorMax, | ||
| int | aChainingEpsilon, | ||
| OUTLINE_ERROR_HANDLER * | aErrorHandler = nullptr ) | 
Extract a board outline for a footprint view.
Definition at line 1247 of file convert_shape_list_to_polygon.cpp.
References SHAPE_POLY_SET::AddHole(), SHAPE_LINE_CHAIN::Append(), SHAPE_POLY_SET::Append(), buildBoardBoundingBoxPoly(), chain, PCB_TYPE_COLLECTOR::Collect(), SEG::Contains(), doConvertOutlineToPolygon(), Edge_Cuts, findEndSegments(), COLLECTOR::GetCount(), BOARD::GetFirstFootprint(), SHAPE_LINE_CHAIN::GetPoint(), SHAPE_POLY_SET::Hole(), SHAPE_POLY_SET::HoleCount(), SEG::IntersectLines(), SHAPE_LINE_CHAIN::IsClosed(), isCopperOutside(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), PCB_SHAPE_T, SHAPE_LINE_CHAIN::Segment(), SHAPE_LINE_CHAIN::SetClosed(), SKIP_STRUCT, and traceBoardOutline.
Referenced by BOARD_ADAPTER::createBoardPolygon().
      
  | 
  static | 
Definition at line 456 of file convert_shape_list_to_polygon.cpp.
References _, SEG::A, SEG::B, SHAPE_POLY_SET::Hole(), SHAPE_POLY_SET::HoleCount(), SEG::Intersect(), SHAPE_POLY_SET::IterateSegmentsWithHoles(), LexicographicalCompare(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), and SHAPE_LINE_CHAIN::SegmentCount().
Referenced by doConvertOutlineToPolygon().
Local and tunable method of qualifying the proximity of two points.
| aLeft | is the first point. | 
| aRight | is the second point. | 
| aLimit | is a measure of proximity that the caller knows about. | 
Definition at line 83 of file convert_shape_list_to_polygon.cpp.
References SEG::Square().
Referenced by doConvertOutlineToPolygon(), and processShapeSegment().
Local method which qualifies whether the start or end point of a segment is closest to a point.
| aRef | is the reference point | 
| aFirst | is the first point | 
| aSecond | is the second point | 
Definition at line 97 of file convert_shape_list_to_polygon.cpp.
Referenced by ConnectBoardShapes(), doConvertOutlineToPolygon(), and processShapeSegment().
| bool ConvertOutlineToPolygon | ( | std::vector< PCB_SHAPE * > & | aShapeList, | 
| SHAPE_POLY_SET & | aPolygons, | ||
| int | aErrorMax, | ||
| int | aChainingEpsilon, | ||
| bool | aAllowDisjoint, | ||
| OUTLINE_ERROR_HANDLER * | aErrorHandler, | ||
| bool | aAllowUseArcsInPolygons = false ) | 
Build a polygon set with holes from a PCB_SHAPE list.
The shape list is expected to be one or more top-level closed outlines with zero or more holes in each. Optionally, it can be limited to a single top-level closed outline.
| aShapeList | the initial list of drawsegments (only lines, circles and arcs). | 
| aPolygons | will contain the complex polygon. | 
| aErrorMax | is the max error distance when polygonizing a curve (internal units). | 
| aChainingEpsilon | is the max distance from one endPt to the next startPt (internal units). | 
| aAllowDisjoint | indicates multiple top-level outlines are allowed. | 
| aErrorHandler | is an optional error handler. | 
| aAllowUseArcsInPolygons | is an option to allow adding arcs in SHAPE_LINE_CHAIN polylines/polygons when building outlines from aShapeList This is mainly for export to STEP files. | 
Definition at line 836 of file convert_shape_list_to_polygon.cpp.
References doConvertOutlineToPolygon(), and SKIP_STRUCT.
Referenced by FOOTPRINT::BuildCourtyardCaches().
| bool doConvertOutlineToPolygon | ( | std::vector< PCB_SHAPE * > & | aShapeList, | 
| SHAPE_POLY_SET & | aPolygons, | ||
| int | aErrorMax, | ||
| int | aChainingEpsilon, | ||
| bool | aAllowDisjoint, | ||
| OUTLINE_ERROR_HANDLER * | aErrorHandler, | ||
| bool | aAllowUseArcsInPolygons, | ||
| SCOPED_FLAGS_CLEANER & | aCleaner ) | 
Definition at line 570 of file convert_shape_list_to_polygon.cpp.
References _, addHolesToPolygon(), addOutlinesToPolygon(), SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::Arc(), SHAPE_LINE_CHAIN::ArcIndex(), buildContourHierarchy(), chain, checkSelfIntersections(), CIRCLE, SHAPE_LINE_CHAIN::CLastPoint(), SHAPE_LINE_CHAIN::ClearArcs(), close_enough(), closer_to_first(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CPoints(), SHAPE_LINE_CHAIN::CSegment(), PCB_SHAPE_ENDPOINTS_ADAPTOR::endpoints, findNext(), SHAPE_LINE_CHAIN::GenerateBBoxCache(), SHAPE_ARC::GetArcMid(), SHAPE_LINE_CHAIN::GetCachedBBox(), PCB_SHAPE::GetEffectiveShape(), EDA_SHAPE::GetEnd(), SHAPE_ARC::GetP0(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), PCB_SHAPE::GetWidth(), SHAPE_LINE_CHAIN::IsArcEnd(), BOX2< Vec >::IsValid(), next(), SHAPE_LINE_CHAIN::PointCount(), POLY, processClosedShape(), processShapeSegment(), RECTANGLE, SHAPE_LINE_CHAIN::RemoveShape(), SHAPE_LINE_CHAIN::SetClosed(), EDA_ITEM::SetFlags(), SHAPE_LINE_CHAIN::SetPoint(), SHAPE_LINE_CHAIN::SetWidth(), and SKIP_STRUCT.
Referenced by BuildBoardPolygonOutlines(), BuildFootprintPolygonOutlines(), and ConvertOutlineToPolygon().
| int findEndSegments | ( | SHAPE_LINE_CHAIN & | aChain, | 
| SEG & | aStartSeg, | ||
| SEG & | aEndSeg ) | 
Definition at line 1194 of file convert_shape_list_to_polygon.cpp.
References SEG::A, SEG::B, SEG::Contains(), SHAPE_LINE_CHAIN::Segment(), SHAPE_LINE_CHAIN::SegmentCount(), traceBoardOutline, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by BuildFootprintPolygonOutlines().
      
  | 
  static | 
Definition at line 534 of file convert_shape_list_to_polygon.cpp.
References PCB_SHAPE_ENDPOINTS_ADAPTOR::endpoints, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by doConvertOutlineToPolygon(), and PAD::Recombine().
      
  | 
  static | 
Definition at line 103 of file convert_shape_list_to_polygon.cpp.
References SHAPE_POLY_SET::BooleanIntersection(), SHAPE_POLY_SET::ClearArcs(), SHAPE_POLY_SET::CloneDropTriangulation(), ERROR_INSIDE, SHAPE_POLY_SET::OutlineCount(), pad, FOOTPRINT::Pads(), traceBoardOutline, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by BuildBoardPolygonOutlines(), and BuildFootprintPolygonOutlines().
      
  | 
  static | 
Definition at line 177 of file convert_shape_list_to_polygon.cpp.
References ANGLE_360, SHAPE_LINE_CHAIN::Append(), center, CIRCLE, SHAPE_POLY_SET::CIterate(), SHAPE_LINE_CHAIN::ClearArcs(), SHAPE_LINE_CHAIN::CPoint(), PCB_SHAPE::GetCenter(), EDA_SHAPE::GetCornerRadius(), BOARD_ITEM::GetMaxError(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetRadius(), EDA_SHAPE::GetRectangleHeight(), EDA_SHAPE::GetRectangleWidth(), EDA_SHAPE::GetRectCorners(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::PointCount(), POLY, radius, RECTANGLE, SHAPE_LINE_CHAIN::SetClosed(), ROUNDRECT::TransformToPolygon(), and VECTOR2< T >::x.
Referenced by doConvertOutlineToPolygon().
      
  | 
  static | 
Definition at line 267 of file convert_shape_list_to_polygon.cpp.
References SHAPE_LINE_CHAIN::Append(), ARC, BEZIER, SHAPE_LINE_CHAIN::ClearArcs(), close_enough(), closer_to_first(), SHAPE_LINE_CHAIN::CPoint(), EDA_SHAPE::GetArcMid(), EDA_SHAPE::GetBezierPoints(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), SHAPE_LINE_CHAIN::PointCount(), EDA_SHAPE::RebuildBezierToSegmentsPointsList(), and SEGMENT.
Referenced by doConvertOutlineToPolygon().
| VECTOR2I projectPointOnSegment | ( | const VECTOR2I & | aEndPoint, | 
| const SHAPE_POLY_SET & | aOutline, | ||
| int | aOutlineNum = 0 ) | 
Definition at line 1172 of file convert_shape_list_to_polygon.cpp.
References SHAPE_POLY_SET::CIterateSegments().
| bool TestBoardOutlinesGraphicItems | ( | BOARD * | aBoard, | 
| int | aMinDist, | ||
| OUTLINE_ERROR_HANDLER * | aErrorHandler ) | 
Test a board graphic items on edge cut layer for validity.
| aBoard | is the board to test. | 
| aMinDist | is the min length of a segment (or radius, or diagonal size of a rect) to be valid. | 
| aErrorHandler | is an optional error handler. | 
Definition at line 848 of file convert_shape_list_to_polygon.cpp.
References _, ARC, BEZIER, CIRCLE, PCB_TYPE_COLLECTOR::Collect(), Edge_Cuts, VECTOR2< T >::EuclideanNorm(), COLLECTOR::GetCount(), PCB_SHAPE::GetLayer(), PCB_SHAPE_T, POLY, RECTANGLE, SEGMENT, and UNIMPLEMENTED_FOR.
Referenced by DRC_TEST_PROVIDER_MISC::testOutline().