56 virtual bool Run()
override;
58 virtual const wxString
GetName()
const override {
return wxT(
"creepage" ); };
72 std::vector<std::unique_ptr<PCB_SHAPE>>& aOwned );
86 REPORT_AUX( wxT(
"No creepage constraints found. Tests not run." ) );
114 double creepageValue = constraint.
Value().
Min();
117 if( creepageValue <= 0 )
124 if ( !netA || !netB )
130 std::shared_ptr<GRAPH_NODE> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
131 std::shared_ptr<GRAPH_NODE> NetB = aGraph.
AddNetElements( aNetCodeB, aLayer, creepageValue );
135 std::vector<std::shared_ptr<GRAPH_NODE>> temp_nodes;
137 std::copy_if( aGraph.
m_nodes.begin(), aGraph.
m_nodes.end(), std::back_inserter( temp_nodes ),
138 []( std::shared_ptr<GRAPH_NODE> aNode )
140 return !!aNode && aNode->m_parent && !aNode->m_parent->IsConductive()
141 && !aNode->m_connectDirectly && aNode->m_type == GRAPH_NODE::POINT;
145 [&]( std::shared_ptr<GRAPH_NODE> aN1, std::shared_ptr<GRAPH_NODE> aN2 )
153 if( !( aN1->m_parent ) || !( aN2->m_parent ) )
156 if( ( aN1->m_parent ) != ( aN2->m_parent ) )
159 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
162 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
163 shortestPath.clear();
166 if( !shortestPath.empty() && ( shortestPath.size() >= 4 ) && (
distance - creepageValue < 0 ) )
169 drcItem->SetErrorDetail(
formatMsg(
_(
"(%s creepage %s; actual %s)" ),
175 std::shared_ptr<GRAPH_CONNECTION> gc1 = shortestPath[1];
176 std::shared_ptr<GRAPH_CONNECTION> gc2 = shortestPath[shortestPath.size() - 2];
178 if( gc1->n1 && gc2->n2 )
180 const BOARD_ITEM* item1 = gc1->n1->m_parent->GetParent();
181 const BOARD_ITEM* item2 = gc2->n2->m_parent->GetParent();
184 drcItem->SetItems( item1, item2 );
189 VECTOR2I startPoint = gc1->m_path.a2;
191 std::vector<PCB_SHAPE>
path;
193 for(
const std::shared_ptr<GRAPH_CONNECTION>& gc : shortestPath )
194 gc->GetShapes(
path );
199 aMarker->SetPath( path, startPoint, endPoint );
209 double maxConstraint = 0;
216 [&](
int aNet1,
int aNet2 )
221 bci1.SetNetCode( aNet1 );
222 bci2.SetNetCode( aNet2 );
224 for( PCB_LAYER_ID layer : LSET::AllCuMask( m_board->GetCopperLayerCount() ) )
226 bci1.SetLayer( layer );
227 bci2.SetLayer( layer );
228 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1, &bci2, layer );
229 double value = constraint.Value().Min();
230 maxConstraint = value > maxConstraint ? value : maxConstraint;
234 return maxConstraint;
242 for(
auto it = nets.begin(); it != nets.end(); it++ )
243 aVector.push_back( it->first );
248 std::vector<std::unique_ptr<PCB_SHAPE>>& aOwned )
262 std::vector<int> netcodes;
267 if( maxConstraint <= 0 )
279 bool hasValidOutline =
m_board->GetBoardPolygonOutlines( outline,
false,
nullptr,
false,
true );
298 int beNodeSize = graph.
m_nodes.size();
300 bool prevTestChangedGraph =
false;
303 size_t total = ( netcodes.size() * ( netcodes.size() - 1 ) ) / 2 *
m_board->GetCopperLayerCount();
307 [&](
int aNet1,
int aNet2 )
312 for( auto it = layers.copper_layers_begin(); it != layers.copper_layers_end(); ++it )
314 PCB_LAYER_ID layer = *it;
316 reportProgress( current++, total );
318 if( prevTestChangedGraph )
319 graph.TruncateToPrefix( beNodeSize, beConnectionsSize );
321 prevTestChangedGraph = testCreepage( graph, aNet1, aNet2, layer );
340 drcItem->SetErrorDetail(
formatMsg(
_(
"(%s creepage %s; actual %s)" ), aConstraint.
GetName(),
349 aMarker->SetPath( aResult.m_path, aResult.m_start, aResult.m_end );
363 size_t total = ( aNetcodes.size() * ( aNetcodes.size() - 1 ) ) / 2 *
m_board->GetCopperLayerCount();
366 [&](
int aNet1,
int aNet2 )
371 for( auto it = layers.copper_layers_begin(); it != layers.copper_layers_end(); ++it )
373 PCB_LAYER_ID layer = *it;
375 reportProgress( current++, total );
377 PCB_TRACK bci1( m_board );
378 PCB_TRACK bci2( m_board );
379 bci1.SetNetCode( aNet1 );
380 bci2.SetNetCode( aNet2 );
381 bci1.SetLayer( layer );
382 bci2.SetLayer( layer );
384 DRC_CONSTRAINT constraint =
385 m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1, &bci2, layer );
386 double creepageValue = constraint.Value().Min();
388 std::optional<CREEPAGE_RESULT> result =
389 engine.SolveNetPairWholeBoard( aNet1, aNet2, layer, creepageValue );
392 reportCreepageViolation( *result, constraint, layer );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual 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
Reusable creepage solver shared by the batch DRC provider and the realtime drag overlay.
void SetMinGrooveWidth(int aWidth)
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 GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer, const std::set< int > *aRelevantNets=nullptr)
Generate creepage paths between graph nodes.
void TransformEdgeToCreepShapes()
void TransformCreepShapesToNodes(std::vector< CREEP_SHAPE * > &aShapes)
SHAPE_POLY_SET * m_boardOutline
void RemoveDuplicatedShapes()
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)
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()
int testCreepageV2(const std::vector< int > &aNetcodes)
Realtime (V2) engine batch path, selected by the RealtimeCreepage advanced config flag.
void reportCreepageViolation(const CREEPAGE_RESULT &aResult, const DRC_CONSTRAINT &aConstraint, PCB_LAYER_ID aLayer)
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.
Represent a set of closed polygons.
void BuildCreepageBoardEdges(BOARD &aBoard, std::vector< BOARD_ITEM * > &aVector, std::vector< std::unique_ptr< PCB_SHAPE > > &aOwned, const std::set< const BOARD_ITEM * > *aExclude)
Collect the board-edge items used by the creepage graph.
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
std::deque< BOARD_ITEM * > DRAWINGS
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
Result of a single creepage query between two nets on one layer.
const BOARD_ITEM * m_itemB
const BOARD_ITEM * m_itemA
VECTOR2< int32_t > VECTOR2I