59 virtual bool Run()
override;
61 virtual const wxString
GetName()
const override {
return wxT(
"creepage" ); };
70 std::vector<std::unique_ptr<PCB_SHAPE>>& aOwned );
84 REPORT_AUX( wxT(
"No creepage constraints found. Tests not run." ) );
112 double creepageValue = constraint.
Value().
Min();
115 if( creepageValue <= 0 )
122 if ( !netA || !netB )
128 std::shared_ptr<GRAPH_NODE> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
129 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 ) )
157 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
160 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
161 shortestPath.clear();
164 if( !shortestPath.empty() && ( shortestPath.size() >= 4 ) && (
distance - creepageValue < 0 ) )
167 drcItem->SetErrorDetail(
formatMsg(
_(
"(%s creepage %s; actual %s)" ),
173 std::shared_ptr<GRAPH_CONNECTION> gc1 = shortestPath[1];
174 std::shared_ptr<GRAPH_CONNECTION> gc2 = shortestPath[shortestPath.size() - 2];
176 if( gc1->n1 && gc2->n2 )
178 const BOARD_ITEM* item1 = gc1->n1->m_parent->GetParent();
179 const BOARD_ITEM* item2 = gc2->n2->m_parent->GetParent();
182 drcItem->SetItems( item1, item2 );
187 VECTOR2I startPoint = gc1->m_path.a2;
189 std::vector<PCB_SHAPE>
path;
191 for(
const std::shared_ptr<GRAPH_CONNECTION>& gc : shortestPath )
192 gc->GetShapes(
path );
197 aMarker->SetPath( path, startPoint, endPoint );
207 double maxConstraint = 0;
214 [&](
int aNet1,
int aNet2 )
219 bci1.SetNetCode( aNet1 );
220 bci2.SetNetCode( aNet2 );
222 for( PCB_LAYER_ID layer : LSET::AllCuMask( m_board->GetCopperLayerCount() ) )
224 bci1.SetLayer( layer );
225 bci2.SetLayer( layer );
226 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1, &bci2, layer );
227 double value = constraint.Value().Min();
228 maxConstraint = value > maxConstraint ? value : maxConstraint;
232 return maxConstraint;
240 for(
auto it = nets.begin(); it != nets.end(); it++ )
241 aVector.push_back( it->first );
246 std::vector<std::unique_ptr<PCB_SHAPE>>& aOwned )
251 const int errorMax =
m_board->GetDesignSettings().m_MaxError;
257 auto addEdgeDrawing = [&](
BOARD_ITEM* aDrawing )
259 if( !aDrawing || !aDrawing->IsOnLayer(
Edge_Cuts ) )
272 aVector.push_back( shape );
279 for(
size_t i = 1; i < pts.size(); ++i )
281 if( pts[i - 1] == pts[i] )
285 seg->SetStart( pts[i - 1] );
286 seg->SetEnd( pts[i] );
287 aVector.push_back( seg.get() );
288 aOwned.push_back( std::move( seg ) );
293 addEdgeDrawing( drawing );
300 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
301 addEdgeDrawing( drawing );
312 std::shared_ptr<SHAPE_SEGMENT> hole = p->GetEffectiveHoleShape();
319 int radius = hole->GetWidth() / 2;
326 s->SetPosition( ptA );
327 aVector.push_back( s.get() );
328 aOwned.push_back( std::move( s ) );
339 seg1->SetStart( ptA + perp );
340 seg1->SetEnd( ptB + perp );
341 aVector.push_back( seg1.get() );
342 aOwned.push_back( std::move( seg1 ) );
345 seg2->SetStart( ptA - perp );
346 seg2->SetEnd( ptB - perp );
347 aVector.push_back( seg2.get() );
348 aOwned.push_back( std::move( seg2 ) );
352 auto arcA = std::make_unique<PCB_SHAPE>(
nullptr,
SHAPE_T::ARC );
353 arcA->SetArcGeometry( ptA + perp, midA, ptA - perp );
354 aVector.push_back( arcA.get() );
355 aOwned.push_back( std::move( arcA ) );
359 auto arcB = std::make_unique<PCB_SHAPE>(
nullptr,
SHAPE_T::ARC );
360 arcB->SetArcGeometry( ptB - perp, midB, ptB + perp );
361 aVector.push_back( arcB.get() );
362 aOwned.push_back( std::move( arcB ) );
373 std::vector<int> netcodes;
378 if( maxConstraint <= 0 )
383 if( !
m_board->GetBoardPolygonOutlines( outline,
false ) )
403 int beNodeSize = graph.
m_nodes.size();
405 bool prevTestChangedGraph =
false;
408 size_t total = ( netcodes.size() * ( netcodes.size() - 1 ) ) / 2 *
m_board->GetCopperLayerCount();
412 [&](
int aNet1,
int aNet2 )
417 for( auto it = layers.copper_layers_begin(); it != layers.copper_layers_end(); ++it )
419 PCB_LAYER_ID layer = *it;
421 reportProgress( current++, total );
423 if( prevTestChangedGraph )
425 size_t vectorSize = graph.m_connections.size();
427 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
430 graph.RemoveConnection( graph.m_connections[i], false );
433 graph.m_connections.resize( beConnectionsSize, nullptr );
435 vectorSize = graph.m_nodes.size();
436 graph.m_nodes.resize( beNodeSize, nullptr );
442 graph.m_nodeset.clear();
444 for( int i = 0; i < beNodeSize; ++i )
446 if( graph.m_nodes[i] )
447 graph.m_nodeset.insert( graph.m_nodes[i] );
451 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)
std::vector< std::unique_ptr< PCB_SHAPE > > m_ownedBoardEdges
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.
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
void CollectBoardEdges(std::vector< BOARD_ITEM * > &aVector, std::vector< std::unique_ptr< PCB_SHAPE > > &aOwned)
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)
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
const std::vector< VECTOR2I > & GetBezierPoints() const
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.
Represent a set of closed polygons.
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
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
std::map< int, NETINFO_ITEM * > NETCODES_MAP
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
std::deque< BOARD_ITEM * > DRAWINGS
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
VECTOR2< int32_t > VECTOR2I