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" ); }
93 std::vector<std::shared_ptr<GRAPH_NODE>>& aGraph )
98 for( std::shared_ptr<GRAPH_NODE> gn : aGraph )
100 if( aNode->m_pos == gn->m_pos )
122 double creepageValue = constraint.
Value().
Min();
125 if( creepageValue <= 0 )
132 if ( !netA || !netB )
138 std::shared_ptr<GRAPH_NODE> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
139 std::shared_ptr<GRAPH_NODE> NetB = aGraph.
AddNetElements( aNetCodeB, aLayer, creepageValue );
144 std::vector<std::shared_ptr<GRAPH_NODE>> temp_nodes;
146 std::copy_if( aGraph.
m_nodes.begin(), aGraph.
m_nodes.end(), std::back_inserter( temp_nodes ),
147 []( std::shared_ptr<GRAPH_NODE> aNode )
149 return !!aNode && aNode->m_parent && aNode->m_parent->IsConductive()
150 && aNode->m_connectDirectly && aNode->m_type == GRAPH_NODE::POINT;
154 [&]( std::shared_ptr<GRAPH_NODE> aN1, std::shared_ptr<GRAPH_NODE> aN2 )
162 if( !( aN1->m_parent ) || !( aN2->m_parent ) )
165 if( ( aN1->m_parent ) != ( aN2->m_parent ) )
169 if( aN1->m_parent->IsConductive() )
172 if( aN1->m_connectDirectly || aN2->m_connectDirectly )
177 if( aN1->m_type != GRAPH_NODE::POINT )
180 if( aN2->m_type != GRAPH_NODE::POINT )
183 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
186 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
187 shortestPath.clear();
190 if( !shortestPath.empty() && ( shortestPath.size() >= 4 ) && (
distance - creepageValue < 0 ) )
193 wxString msg =
formatMsg(
_(
"(%s creepage %s; actual %s)" ), constraint.
GetName(),
195 drce->SetErrorMessage( drce->GetErrorText() + wxS(
" " ) + msg );
198 std::shared_ptr<GRAPH_CONNECTION> gc1 = shortestPath[1];
199 std::shared_ptr<GRAPH_CONNECTION> gc2 = shortestPath[shortestPath.size() - 2];
201 if( gc1->n1 && gc2->n2 )
207 drce->SetItems( item1, item2 );
212 std::vector<PCB_SHAPE> shortestPathShapes1, shortestPathShapes2;
214 VECTOR2I startPoint = gc1->m_path.a2;
216 std::vector<PCB_SHAPE>
path;
218 for( std::shared_ptr<GRAPH_CONNECTION> gc : shortestPath )
223 std::vector<PCB_SHAPE> shapes = gc->GetShapes();
227 path.push_back( sh );
241 double maxConstraint = 0;
249 [&](
int aNet1,
int aNet2 )
254 bci1.SetNetCode( aNet1 );
255 bci2.SetNetCode( aNet2 );
257 for( PCB_LAYER_ID layer : LSET::AllCuMask( m_board->GetCopperLayerCount() ) )
259 bci1.SetLayer( layer );
260 bci2.SetLayer( layer );
261 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1,
263 double value = constraint.Value().Min();
264 maxConstraint = value > maxConstraint ? value : maxConstraint;
268 return maxConstraint;
275 for(
auto it = nets.begin(); it != nets.end(); it++ )
277 aVector.push_back( it->first );
293 aVector.push_back( drawing );
302 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
309 aVector.push_back( drawing );
320 if( p->GetAttribute() != PAD_ATTRIB::NPTH )
326 aVector.push_back( s );
335 std::vector<int> netcodes;
340 if( maxConstraint <= 0 )
371 int beNodeSize = graph.
m_nodes.size();
373 bool prevTestChangedGraph =
false;
381 [&](
int aNet1,
int aNet2 )
388 for( auto it = layers.copper_layers_begin();
389 it != layers.copper_layers_end();
392 PCB_LAYER_ID layer = *it;
394 reportProgress( current++, total );
396 if ( prevTestChangedGraph )
398 size_t vectorSize = graph.m_connections.size();
400 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
403 graph.RemoveConnection( graph.m_connections[i], false );
405 graph.m_connections.resize( beConnectionsSize, nullptr );
407 vectorSize = graph.m_nodes.size();
408 graph.m_nodes.resize( beNodeSize, nullptr );
411 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
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
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).
LSET is a set of PCB_LAYER_IDs.
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)