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;
238 NETCODES_MAP nets =
m_board->GetNetInfo().NetsByNetcode();
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 )
257 aVector.push_back( drawing );
265 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
271 aVector.push_back( drawing );
284 s->SetRadius( p->GetDrillSize().x / 2 );
285 s->SetPosition( p->GetPosition() );
286 aVector.push_back( s.get() );
287 aOwned.push_back( std::move( s ) );
297 std::vector<int> netcodes;
302 if( maxConstraint <= 0 )
307 if( !
m_board->GetBoardPolygonOutlines( outline,
false ) )
310 const DRAWINGS drawings =
m_board->Drawings();
327 int beNodeSize = graph.
m_nodes.size();
329 bool prevTestChangedGraph =
false;
332 size_t total = ( netcodes.size() * ( netcodes.size() - 1 ) ) / 2 *
m_board->GetCopperLayerCount();
336 [&](
int aNet1,
int aNet2 )
341 for( auto it = layers.copper_layers_begin(); it != layers.copper_layers_end(); ++it )
343 PCB_LAYER_ID layer = *it;
345 reportProgress( current++, total );
347 if( prevTestChangedGraph )
349 size_t vectorSize = graph.m_connections.size();
351 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
354 graph.RemoveConnection( graph.m_connections[i], false );
357 graph.m_connections.resize( beConnectionsSize, nullptr );
359 vectorSize = graph.m_nodes.size();
360 graph.m_nodes.resize( beNodeSize, nullptr );
366 graph.m_nodeset.clear();
368 for( int i = 0; i < beNodeSize; ++i )
370 if( graph.m_nodes[i] )
371 graph.m_nodeset.insert( graph.m_nodes[i] );
375 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)
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.
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