57 virtual bool Run()
override;
59 virtual const wxString
GetName()
const override {
return wxT(
"creepage" ); };
61 virtual const wxString
GetDescription()
const override {
return wxT(
"Tests creepage" ); }
92 std::vector<std::shared_ptr<GraphNode>>& aGraph )
97 for( std::shared_ptr<GraphNode> gn : aGraph )
99 if( aNode->m_pos == gn->m_pos )
121 double creepageValue = constraint.
Value().
Min();
124 if( creepageValue <= 0 )
131 if ( !netA || !netB )
137 std::shared_ptr<GraphNode> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
138 std::shared_ptr<GraphNode> NetB = aGraph.
AddNetElements( aNetCodeB, aLayer, creepageValue );
143 std::vector<std::shared_ptr<GraphNode>> nodes1 = aGraph.
m_nodes;
144 std::vector<std::shared_ptr<GraphNode>> nodes2 = aGraph.
m_nodes;
147 [&]( std::shared_ptr<GraphNode> aN1, std::shared_ptr<GraphNode> aN2 )
155 if( !( aN1->m_parent ) || !( aN2->m_parent ) )
158 if( ( aN1->m_parent ) != ( aN2->m_parent ) )
162 if( aN1->m_parent->IsConductive() )
165 if( aN1->m_connectDirectly || aN2->m_connectDirectly )
170 if( aN1->m_type != GraphNode::POINT )
173 if( aN2->m_type != GraphNode::POINT )
176 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
179 std::vector<std::shared_ptr<GraphConnection>> shortestPath;
180 shortestPath.clear();
184 if( ( shortestPath.size() > 0 ) && (
distance - creepageValue < 0 ) )
187 wxString msg =
formatMsg(
_(
"(%s creepage %s; actual %s)" ), constraint.
GetName(),
189 drce->SetErrorMessage( drce->GetErrorText() + wxS(
" " ) + msg );
192 if( shortestPath.size() >= 4 && shortestPath[1]->n1 && shortestPath[1]->n2 )
193 drce->SetItems( shortestPath[1]->n1->m_parent->GetParent(),
194 shortestPath[shortestPath.size() - 2]->n2->m_parent->GetParent() );
196 std::vector<PCB_SHAPE> shortestPathShapes1, shortestPathShapes2;
198 VECTOR2I startPoint = shortestPath[1]->m_path.a2;
199 VECTOR2I endPoint = shortestPath[shortestPath.size() - 2]->m_path.a2;
206 std::vector<PCB_SHAPE>
path;
207 for( std::shared_ptr<GraphConnection> gc : shortestPath )
212 std::vector<PCB_SHAPE> shapes = gc->GetShapes();
216 path.push_back( sh );
225 shortestPath.clear();
232 double maxConstraint = 0;
240 [&](
int aNet1,
int aNet2 )
245 bci1.SetNetCode( aNet1 );
246 bci2.SetNetCode( aNet2 );
248 for( PCB_LAYER_ID layer : LSET::AllCuMask().CuStack() )
250 bci1.SetLayer( layer );
251 bci2.SetLayer( layer );
252 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1,
254 double value = constraint.Value().Min();
255 maxConstraint = value > maxConstraint ? value : maxConstraint;
259 return maxConstraint;
266 for(
auto it = nets.begin(); it != nets.end(); it++ )
268 aVector.push_back( it->first );
284 aVector.push_back( drawing );
293 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
300 aVector.push_back( drawing );
311 if( p->GetAttribute() != PAD_ATTRIB::NPTH )
317 aVector.push_back( s );
326 std::vector<int> netcodes;
331 if( maxConstraint <= 0 )
362 int beNodeSize = graph.
m_nodes.size();
364 bool prevTestChangedGraph =
false;
367 [&](
int aNet1,
int aNet2 )
372 for( PCB_LAYER_ID layer : LSET::AllCuMask().CuStack() )
374 if( !m_board->IsLayerEnabled( layer ) )
377 if ( prevTestChangedGraph )
379 size_t vectorSize = graph.m_connections.size();
381 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
384 graph.RemoveConnection( graph.m_connections[i], false );
386 graph.m_connections.resize( beConnectionsSize, nullptr );
388 vectorSize = graph.m_nodes.size();
389 graph.m_nodes.resize( beNodeSize, nullptr );
392 prevTestChangedGraph = testCreepage( graph, aNet1, aNet2, layer );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
const NETINFO_LIST & GetNetInfo() const
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
const FOOTPRINTS & Footprints() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const DRAWINGS & Drawings() const
ecoord_type Distance(const Vec &aP) const
A graph with nodes and connections for creepage calculation.
std::vector< CREEP_SHAPE * > m_shapeCollection
void RemoveDuplicatedShapes()
std::vector< std::shared_ptr< GraphNode > > m_nodes
std::shared_ptr< GraphNode > AddNetElements(int aNetCode, PCB_LAYER_ID aLayer, int aMaxCreepage)
std::vector< std::shared_ptr< GraphConnection > > m_connections
void SetTarget(double aTarget)
void TransformCreepShapesToNodes(std::vector< CREEP_SHAPE * > &aShapes)
double Solve(std::shared_ptr< GraphNode > &aFrom, std::shared_ptr< GraphNode > &aTo, std::vector< std::shared_ptr< GraphConnection > > &aResult)
std::vector< BOARD_ITEM * > m_boardEdge
void TransformEdgeToCreepShapes()
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, bool aGenerateBoardEdges=true)
SHAPE_POLY_SET * m_boardOutline
MINOPTMAX< int > & Value()
DRC_RULE * GetParentRule() const
bool IsErrorLimitExceeded(int error_code)
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
DRC_GRAPHICS_HANDLER m_graphicsHandler
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
DRC_GRAPHICS_HANDLER m_GraphicsHandlerBuffer
void ShowPathDRC(const std::vector< PCB_SHAPE > &aShapes, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aLength)
void CollectBoardEdges(std::vector< BOARD_ITEM * > &aVector)
double GetMaxConstraint(const std::vector< int > &aNetCodes)
virtual const wxString GetName() const override
virtual const wxString GetDescription() const override
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
DRC_TEST_PROVIDER_CREEPAGE()
void CollectNetCodes(std::vector< int > &aVector)
virtual ~DRC_TEST_PROVIDER_CREEPAGE()
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, double aConstraint, double aActual)
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
void SetStart(const VECTOR2I &aStart)
void SetEnd(const VECTOR2I &aEnd)
Handle the data for a net.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
const NETCODES_MAP & NetsByNetcode() const
Return the netcode map, at least for python.
void SetPosition(const VECTOR2I &aPos) override
Represent a set of closed polygons.
std::shared_ptr< GraphNode > FindInGraphNodes(std::shared_ptr< GraphNode > aNode, std::vector< std::shared_ptr< GraphNode > > &aGraph)
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
void for_all_pairs(_InputIterator __first, _InputIterator __last, _Function __f)
Apply a function to every possible pair of elements of a sequence.
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)