59 virtual bool Run()
override;
61 virtual const wxString
GetName()
const override {
return wxT(
"creepage" ); };
83 REPORT_AUX( wxT(
"No creepage constraints found. Tests not run." ) );
111 double creepageValue = constraint.
Value().
Min();
114 if( creepageValue <= 0 )
121 if ( !netA || !netB )
127 std::shared_ptr<GRAPH_NODE> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
128 std::shared_ptr<GRAPH_NODE> NetB = aGraph.
AddNetElements( aNetCodeB, aLayer, creepageValue );
133 std::vector<std::shared_ptr<GRAPH_NODE>> temp_nodes;
135 std::copy_if( aGraph.
m_nodes.begin(), aGraph.
m_nodes.end(), std::back_inserter( temp_nodes ),
136 []( std::shared_ptr<GRAPH_NODE> aNode )
138 return !!aNode && aNode->m_parent && aNode->m_parent->IsConductive()
139 && aNode->m_connectDirectly && aNode->m_type == GRAPH_NODE::POINT;
143 [&]( std::shared_ptr<GRAPH_NODE> aN1, std::shared_ptr<GRAPH_NODE> aN2 )
151 if( !( aN1->m_parent ) || !( aN2->m_parent ) )
154 if( ( aN1->m_parent ) != ( aN2->m_parent ) )
158 if( aN1->m_parent->IsConductive() )
161 if( aN1->m_connectDirectly || aN2->m_connectDirectly )
166 if( aN1->m_type != GRAPH_NODE::POINT )
169 if( aN2->m_type != GRAPH_NODE::POINT )
172 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
175 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
176 shortestPath.clear();
179 if( !shortestPath.empty() && ( shortestPath.size() >= 4 ) && (
distance - creepageValue < 0 ) )
182 drcItem->SetErrorDetail(
formatMsg(
_(
"(%s creepage %s; actual %s)" ),
188 std::shared_ptr<GRAPH_CONNECTION> gc1 = shortestPath[1];
189 std::shared_ptr<GRAPH_CONNECTION> gc2 = shortestPath[shortestPath.size() - 2];
191 if( gc1->n1 && gc2->n2 )
193 const BOARD_ITEM* item1 = gc1->n1->m_parent->GetParent();
194 const BOARD_ITEM* item2 = gc2->n2->m_parent->GetParent();
197 drcItem->SetItems( item1, item2 );
202 VECTOR2I startPoint = gc1->m_path.a2;
204 std::vector<PCB_SHAPE>
path;
206 for(
const std::shared_ptr<GRAPH_CONNECTION>& gc : shortestPath )
207 gc->GetShapes(
path );
212 aMarker->SetPath( path, startPoint, endPoint );
222 double maxConstraint = 0;
229 [&](
int aNet1,
int aNet2 )
234 bci1.SetNetCode( aNet1 );
235 bci2.SetNetCode( aNet2 );
237 for( PCB_LAYER_ID layer : LSET::AllCuMask( m_board->GetCopperLayerCount() ) )
239 bci1.SetLayer( layer );
240 bci2.SetLayer( layer );
241 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1, &bci2, layer );
242 double value = constraint.Value().Min();
243 maxConstraint = value > maxConstraint ? value : maxConstraint;
247 return maxConstraint;
253 NETCODES_MAP nets =
m_board->GetNetInfo().NetsByNetcode();
255 for(
auto it = nets.begin(); it != nets.end(); it++ )
256 aVector.push_back( it->first );
271 aVector.push_back( drawing );
279 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
285 aVector.push_back( drawing );
300 aVector.push_back( s );
310 std::vector<int> netcodes;
315 if( maxConstraint <= 0 )
320 if( !
m_board->GetBoardPolygonOutlines( outline,
false ) )
323 const DRAWINGS drawings =
m_board->Drawings();
340 int beNodeSize = graph.
m_nodes.size();
342 bool prevTestChangedGraph =
false;
345 size_t total = ( netcodes.size() * ( netcodes.size() - 1 ) ) / 2 *
m_board->GetCopperLayerCount();
349 [&](
int aNet1,
int aNet2 )
354 for( auto it = layers.copper_layers_begin(); it != layers.copper_layers_end(); ++it )
356 PCB_LAYER_ID layer = *it;
358 reportProgress( current++, total );
360 if( prevTestChangedGraph )
362 size_t vectorSize = graph.m_connections.size();
364 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
367 graph.RemoveConnection( graph.m_connections[i], false );
370 graph.m_connections.resize( beConnectionsSize, nullptr );
372 vectorSize = graph.m_nodes.size();
373 graph.m_nodes.resize( beNodeSize, nullptr );
376 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.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
ecoord_type Distance(const Vec &aP) const
A graph with nodes and connections for creepage calculation.
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()
std::vector< BOARD_ITEM * > m_boardEdge
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer)
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
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
void CollectBoardEdges(std::vector< BOARD_ITEM * > &aVector)
virtual ~DRC_TEST_PROVIDER_CREEPAGE()=default
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 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 bool reportPhase(const wxString &aStageName)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
wxString formatMsg(const wxString &aFormatString, const wxString &aSource, double aConstraint, double aActual, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
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.
void SetPosition(const VECTOR2I &aPos) override
Represent a set of closed polygons.
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
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
VECTOR2< int32_t > VECTOR2I