24#ifndef _DRC_CREEPAGE_UTILS_H
25#define _DRC_CREEPAGE_UTILS_H
27#include <unordered_set>
50 const std::vector<BOARD_ITEM*>& aBe,
51 const std::vector<const BOARD_ITEM*>& aDontTestAgainst,
52 int aMinGrooveWidth );
70 const std::vector<BOARD_ITEM*>& aBoardEdges,
71 const std::vector<const BOARD_ITEM*>& aIgnoreForTest,
SHAPE_POLY_SET* aOutline,
72 const std::pair<bool, bool>& aTestLocalConcavity,
int aMinGrooveWidth )
86 if( !( aOutline->
Contains( midPoint, -1, tolerance )
90 if(
false && ( aTestLocalConcavity.first || aTestLocalConcavity.second ) )
94 double extendLine = 1000;
99 double extendPoly = 100;
108 outline2.
Inflate( extendPoly, CORNER_STRATEGY::ROUND_ALL_CORNERS, 3 );
110 if( aTestLocalConcavity.first && !aOutline->
Contains( a - dir, -1, 0 ) )
113 if( aTestLocalConcavity.second && !aOutline->
Contains( b + dir, -1, 0 ) )
126 if( track->Type() == KICAD_T::PCB_TRACE_T && track->IsOnLayer( aLayer ) )
128 std::shared_ptr<SHAPE> sh = track->GetEffectiveShape();
130 if( sh && sh->Type() == SHAPE_TYPE::SH_SEGMENT )
132 SEG segTrack( track->GetStart(), track->GetEnd() );
178 m_type = CREEP_SHAPE::TYPE::UNDEFINED;
194 virtual void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
197 std::vector<PATH_CONNECTION>
ReversePaths(
const std::vector<PATH_CONNECTION>& aV )
const
199 std::vector<PATH_CONNECTION> r;
200 r.reserve( aV.size() );
202 for(
const auto& pc : aV )
204 r.emplace_back( pc );
205 std::swap( r.back().a1, r.back().a2 );
212 double aMaxSquaredWeight )
const
214 std::vector<PATH_CONNECTION> a;
219 double aMaxSquaredWeight )
const
221 std::vector<PATH_CONNECTION> a;
226 double aMaxSquaredWeight )
const
228 std::vector<PATH_CONNECTION> a;
233 double aMaxSquaredWeight )
const
235 std::vector<PATH_CONNECTION> a;
240 double aMaxSquaredWeight )
const
242 std::vector<PATH_CONNECTION> a;
247 double aMaxSquaredWeight )
const
249 std::vector<PATH_CONNECTION> a;
254 double aMaxSquaredWeight )
const
256 std::vector<PATH_CONNECTION> a;
311 double aMaxSquaredWeight )
const override;
313 double aMaxSquaredWeight )
const override;
315 double aMaxSquaredWeight )
const override;
317 double aMaxSquaredWeight )
const override;
319 double aMaxSquaredWeight )
const override;
321 double aMaxSquaredWeight )
const override;
347 double aMaxSquaredWeight )
const override;
349 double aMaxSquaredWeight )
const override;
351 double aMaxSquaredWeight )
const override;
353 double aMaxSquaredWeight )
const override
359 double aMaxSquaredWeight )
const override;
361 double aMaxSquaredWeight )
const override;
381 m_type = CREEP_SHAPE::TYPE::ARC;
386 double aMaxSquaredWeight )
const override;
389 double aMaxSquaredWeight )
const override;
392 double aMaxSquaredWeight )
const override;
395 double aMaxSquaredWeight )
const override
401 double aMaxSquaredWeight )
const override
407 double aMaxSquaredWeight )
const override;
499 std::shared_ptr<GRAPH_NODE>
n1;
500 std::shared_ptr<GRAPH_NODE>
n2;
516 m_type = CREEP_SHAPE::TYPE::POINT;
520 double aMaxSquaredWeight )
const override;
523 double aMaxSquaredWeight )
const override;
526 double aMaxSquaredWeight )
const override;
529 double aMaxSquaredWeight )
const override
535 double aMaxSquaredWeight )
const override
541 double aMaxSquaredWeight )
const override
547 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
562 m_type = CREEP_SHAPE::TYPE::CIRCLE;
566 double aMaxSquaredWeight )
const override
572 double aMaxSquaredWeight )
const override;
575 double aMaxSquaredWeight )
const override;
578 double aMaxSquaredWeight )
const override
584 double aMaxSquaredWeight )
const override
592 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
595 void ShortenChildDueToGV( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
616 m_type = CREEP_SHAPE::TYPE::ARC;
619 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
624 double aMaxSquaredWeight )
const override
629 double aMaxSquaredWeight )
const override
634 double aMaxSquaredWeight )
const override;
637 double aMaxSquaredWeight )
const override
642 double aMaxSquaredWeight )
const override
647 double aMaxSquaredWeight )
const override
718 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
719 std::shared_ptr<GRAPH_NODE>& aN2,
722 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
723 std::shared_ptr<GRAPH_NODE>& aN2 );
728 void RemoveConnection( std::shared_ptr<GRAPH_CONNECTION>,
bool aDelete =
false );
730 void Trim(
double aWeightLimit );
732 void Addshape(
const SHAPE& aShape, std::shared_ptr<GRAPH_NODE>& aConnectTo,
735 double Solve( std::shared_ptr<GRAPH_NODE>& aFrom, std::shared_ptr<GRAPH_NODE>& aTo,
736 std::vector<std::shared_ptr<GRAPH_CONNECTION>>& aResult );
749 std::size_t
operator()(
const std::shared_ptr<GRAPH_NODE>& node)
const
751 return hash_val(node->m_type, node->m_parent, node->m_pos.x, node->m_pos.y);
757 bool operator()(
const std::shared_ptr<GRAPH_NODE>& lhs,
const std::shared_ptr<GRAPH_NODE>& rhs)
const
759 return lhs->m_type == rhs->m_type && lhs->m_parent == rhs->m_parent && lhs->m_pos == rhs->m_pos;
766 std::vector<std::shared_ptr<GRAPH_NODE>>
m_nodes;
Creepage: a board edge arc.
std::pair< bool, bool > IsThereATangentPassingThroughPoint(const BE_SHAPE_POINT aPoint) const
EDA_ANGLE GetStartAngle() const override
int GetRadius() const override
BE_SHAPE_ARC(VECTOR2I aPos, int aRadius, EDA_ANGLE aStartAngle, EDA_ANGLE aEndAngle, VECTOR2D aStartPoint, VECTOR2D aEndPoint)
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
VECTOR2I GetStartPoint() const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const override
EDA_ANGLE GetEndAngle() const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
VECTOR2I GetEndPoint() const override
EDA_ANGLE AngleBetweenStartAndEnd(const VECTOR2I aPoint) const
Creepage: a board edge circle.
int GetRadius() const override
BE_SHAPE_CIRCLE(VECTOR2I aPos=VECTOR2I(0, 0), int aRadius=0)
void ShortenChildDueToGV(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG, double aNormalWeight) const
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const override
Creepage: a board edge point.
BE_SHAPE_POINT(VECTOR2I aPos)
void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
Creepage: a board edge shape.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
const TRACKS & Tracks() const
std::shared_ptr< GRAPH_CONNECTION > AddConnection(std::shared_ptr< GRAPH_NODE > &aN1, std::shared_ptr< GRAPH_NODE > &aN2, const PATH_CONNECTION &aPc)
void SetTarget(double aTarget)
void RemoveConnection(std::shared_ptr< GRAPH_CONNECTION >, bool aDelete=false)
double Solve(std::shared_ptr< GRAPH_NODE > &aFrom, std::shared_ptr< GRAPH_NODE > &aTo, std::vector< std::shared_ptr< GRAPH_CONNECTION > > &aResult)
void Addshape(const SHAPE &aShape, std::shared_ptr< GRAPH_NODE > &aConnectTo, BOARD_ITEM *aParent=nullptr)
std::vector< CREEP_SHAPE * > m_shapeCollection
CREEPAGE_GRAPH(BOARD &aBoard)
std::shared_ptr< GRAPH_NODE > AddNode(GRAPH_NODE::TYPE aType, CREEP_SHAPE *aParent=nullptr, VECTOR2I aPos=VECTOR2I())
void TransformEdgeToCreepShapes()
std::shared_ptr< GRAPH_NODE > AddNodeVirtual()
void TransformCreepShapesToNodes(std::vector< CREEP_SHAPE * > &aShapes)
void Trim(double aWeightLimit)
SHAPE_POLY_SET * m_boardOutline
std::shared_ptr< GRAPH_NODE > FindNode(GRAPH_NODE::TYPE aType, CREEP_SHAPE *aParent, VECTOR2I aPos)
void RemoveDuplicatedShapes()
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, bool aClearance)
std::vector< BOARD_ITEM * > m_boardEdge
double m_creepageTargetSquared
std::unordered_set< std::shared_ptr< GRAPH_NODE >, GraphNodeHash, GraphNodeEqual > m_nodeset
std::vector< std::shared_ptr< GRAPH_NODE > > m_nodes
std::vector< std::shared_ptr< GRAPH_CONNECTION > > m_connections
std::shared_ptr< GRAPH_NODE > AddNetElements(int aNetCode, PCB_LAYER_ID aLayer, int aMaxCreepage)
A class used to represent the shapes for creepage calculation.
virtual VECTOR2I GetStartPoint() const
virtual std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const
CREEP_SHAPE::TYPE GetType() const
std::vector< PATH_CONNECTION > Paths(const CREEP_SHAPE &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual EDA_ANGLE GetEndAngle() const
void SetParent(BOARD_ITEM *aParent)
virtual std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual int GetRadius() const
const BOARD_ITEM * GetParent() const
virtual void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const
virtual std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual EDA_ANGLE GetStartAngle() const
virtual VECTOR2I GetEndPoint() const
virtual std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const
std::vector< PATH_CONNECTION > ReversePaths(const std::vector< PATH_CONNECTION > &aV) const
Creepage: a conductive arc.
VECTOR2I GetStartPoint() const override
EDA_ANGLE AngleBetweenStartAndEnd(const VECTOR2I aPoint) const
VECTOR2I GetEndPoint() const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
EDA_ANGLE GetStartAngle() const override
CU_SHAPE_ARC(VECTOR2I aPos, double aRadius, EDA_ANGLE aStartAngle, EDA_ANGLE aEndAngle, VECTOR2D aStartPoint, VECTOR2D aEndPoint)
int GetRadius() const override
EDA_ANGLE GetEndAngle() const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
Creepage: a conductive circle.
int GetRadius() const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
CU_SHAPE_CIRCLE(VECTOR2I aPos, double aRadius=0)
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
Creepage: a conductive segment.
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
VECTOR2I GetStart() const
CU_SHAPE_SEGMENT(VECTOR2I aStart, VECTOR2I aEnd, double aWidth=0)
Creepage: a conductive shape.
std::vector< PCB_SHAPE > GetShapes()
std::shared_ptr< GRAPH_NODE > n2
std::shared_ptr< GRAPH_NODE > n1
GRAPH_CONNECTION(std::shared_ptr< GRAPH_NODE > &aN1, std::shared_ptr< GRAPH_NODE > &aN2, const PATH_CONNECTION &aPc)
std::set< std::shared_ptr< GRAPH_CONNECTION > > m_node_conns
bool Intersects(const SEG &aSeg) const
Represent a set of closed polygons.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Check if point aP lies on an edge or vertex of some of the outlines or holes.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
An abstract shape on 2D plane.
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
bool SegmentIntersectsBoard(const VECTOR2I &aP1, const VECTOR2I &aP2, const std::vector< BOARD_ITEM * > &aBe, const std::vector< const BOARD_ITEM * > &aDontTestAgainst, int aMinGrooveWidth)
static constexpr EDA_ANGLE ANGLE_360
static constexpr std::size_t hash_val(const Types &... args)
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
bool operator()(const std::shared_ptr< GRAPH_NODE > &lhs, const std::shared_ptr< GRAPH_NODE > &rhs) const
std::size_t operator()(const std::shared_ptr< GRAPH_NODE > &node) const
bool isValid(const BOARD &aBoard, PCB_LAYER_ID aLayer, const std::vector< BOARD_ITEM * > &aBoardEdges, const std::vector< const BOARD_ITEM * > &aIgnoreForTest, SHAPE_POLY_SET *aOutline, const std::pair< bool, bool > &aTestLocalConcavity, int aMinGrooveWidth)
Test if a path is valid.
bool m_forceA2concavityCheck
bool m_forceA1concavityCheck
VECTOR2< int32_t > VECTOR2I