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<GRAPH_NODE>>& aGraph )
97 for( std::shared_ptr<GRAPH_NODE> 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<GRAPH_NODE> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
138 std::shared_ptr<GRAPH_NODE> NetB = aGraph.
AddNetElements( aNetCodeB, aLayer, creepageValue );
143 std::vector<std::shared_ptr<GRAPH_NODE>> temp_nodes;
145 std::copy_if( aGraph.
m_nodes.begin(), aGraph.
m_nodes.end(), std::back_inserter( temp_nodes ),
146 []( std::shared_ptr<GRAPH_NODE> aNode )
148 return !!aNode && aNode->m_parent && aNode->m_parent->IsConductive()
149 && aNode->m_connectDirectly && aNode->m_type == GRAPH_NODE::POINT;
153 [&]( std::shared_ptr<GRAPH_NODE> aN1, std::shared_ptr<GRAPH_NODE> aN2 )
161 if( !( aN1->m_parent ) || !( aN2->m_parent ) )
164 if( ( aN1->m_parent ) != ( aN2->m_parent ) )
168 if( aN1->m_parent->IsConductive() )
171 if( aN1->m_connectDirectly || aN2->m_connectDirectly )
176 if( aN1->m_type != GRAPH_NODE::POINT )
179 if( aN2->m_type != GRAPH_NODE::POINT )
182 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
185 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
186 shortestPath.clear();
189 if( !shortestPath.empty() && ( shortestPath.size() >= 4 ) && (
distance - creepageValue < 0 ) )
192 wxString msg =
formatMsg(
_(
"(%s creepage %s; actual %s)" ), constraint.
GetName(),
194 drce->SetErrorMessage( drce->GetErrorText() + wxS(
" " ) + msg );
197 std::shared_ptr<GRAPH_CONNECTION> gc1 = shortestPath[1];
198 std::shared_ptr<GRAPH_CONNECTION> gc2 = shortestPath[shortestPath.size() - 2];
200 if( gc1->n1 && gc2->n2 )
206 drce->SetItems( item1, item2 );
211 std::vector<PCB_SHAPE> shortestPathShapes1, shortestPathShapes2;
213 VECTOR2I startPoint = gc1->m_path.a2;
215 std::vector<PCB_SHAPE>
path;
217 for( std::shared_ptr<GRAPH_CONNECTION> gc : shortestPath )
222 std::vector<PCB_SHAPE> shapes = gc->GetShapes();
226 path.push_back( sh );
240 double maxConstraint = 0;
248 [&](
int aNet1,
int aNet2 )
253 bci1.SetNetCode( aNet1 );
254 bci2.SetNetCode( aNet2 );
256 for( PCB_LAYER_ID layer : LSET::AllCuMask().CuStack() )
258 bci1.SetLayer( layer );
259 bci2.SetLayer( layer );
260 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1,
262 double value = constraint.Value().Min();
263 maxConstraint = value > maxConstraint ? value : maxConstraint;
267 return maxConstraint;
274 for(
auto it = nets.begin(); it != nets.end(); it++ )
276 aVector.push_back( it->first );
292 aVector.push_back( drawing );
301 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
308 aVector.push_back( drawing );
319 if( p->GetAttribute() != PAD_ATTRIB::NPTH )
325 aVector.push_back( s );
334 std::vector<int> netcodes;
339 if( maxConstraint <= 0 )
370 int beNodeSize = graph.
m_nodes.size();
372 bool prevTestChangedGraph =
false;
379 [&](
int aNet1,
int aNet2 )
384 for( auto it = m_board->GetLayerSet().copper_layers_begin();
385 it != m_board->GetLayerSet().copper_layers_end();
388 PCB_LAYER_ID layer = *it;
390 reportProgress( current++, total );
392 if ( prevTestChangedGraph )
394 size_t vectorSize = graph.m_connections.size();
396 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
399 graph.RemoveConnection( graph.m_connections[i], false );
401 graph.m_connections.resize( beConnectionsSize, nullptr );
403 vectorSize = graph.m_nodes.size();
404 graph.m_nodes.resize( beNodeSize, nullptr );
407 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.
int GetCopperLayerCount() const
const FOOTPRINTS & Footprints() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const DRAWINGS & Drawings() const
ecoord_type Distance(const Vec &aP) const
void SetTarget(double aTarget)
double Solve(std::shared_ptr< GRAPH_NODE > &aFrom, std::shared_ptr< GRAPH_NODE > &aTo, std::vector< std::shared_ptr< GRAPH_CONNECTION > > &aResult)
std::vector< CREEP_SHAPE * > m_shapeCollection
void TransformEdgeToCreepShapes()
void TransformCreepShapesToNodes(std::vector< CREEP_SHAPE * > &aShapes)
SHAPE_POLY_SET * m_boardOutline
void RemoveDuplicatedShapes()
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, bool aClearance)
std::vector< BOARD_ITEM * > m_boardEdge
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)
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)
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
DRC_CUSTOM_MARKER_HANDLER GetGraphicsHandler(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)
std::set< std::pair< const BOARD_ITEM *, const BOARD_ITEM * > > m_reportedPairs
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, DRC_CUSTOM_MARKER_HANDLER *aCustomHandler=nullptr)
EDA_ITEM * GetParent() const
EDA_ITEM * m_parent
Linked list: Link (parent struct).
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::function< void(PCB_MARKER *aMarker)> DRC_CUSTOM_MARKER_HANDLER
std::shared_ptr< GRAPH_NODE > FindInGraphNodes(std::shared_ptr< GRAPH_NODE > aNode, std::vector< std::shared_ptr< GRAPH_NODE > > &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)