59 virtual bool Run()
override;
61 virtual const wxString
GetName()
const override {
return wxT(
"creepage" ); };
105 double creepageValue = constraint.
Value().
Min();
108 if( creepageValue <= 0 )
115 if ( !netA || !netB )
121 std::shared_ptr<GRAPH_NODE> NetA = aGraph.
AddNetElements( aNetCodeA, aLayer, creepageValue );
122 std::shared_ptr<GRAPH_NODE> NetB = aGraph.
AddNetElements( aNetCodeB, aLayer, creepageValue );
127 std::vector<std::shared_ptr<GRAPH_NODE>> temp_nodes;
129 std::copy_if( aGraph.
m_nodes.begin(), aGraph.
m_nodes.end(), std::back_inserter( temp_nodes ),
130 []( std::shared_ptr<GRAPH_NODE> aNode )
132 return !!aNode && aNode->m_parent && aNode->m_parent->IsConductive()
133 && aNode->m_connectDirectly && aNode->m_type == GRAPH_NODE::POINT;
137 [&]( std::shared_ptr<GRAPH_NODE> aN1, std::shared_ptr<GRAPH_NODE> aN2 )
145 if( !( aN1->m_parent ) || !( aN2->m_parent ) )
148 if( ( aN1->m_parent ) != ( aN2->m_parent ) )
152 if( aN1->m_parent->IsConductive() )
155 if( aN1->m_connectDirectly || aN2->m_connectDirectly )
160 if( aN1->m_type != GRAPH_NODE::POINT )
163 if( aN2->m_type != GRAPH_NODE::POINT )
166 aN1->m_parent->ConnectChildren( aN1, aN2, aGraph );
169 std::vector<std::shared_ptr<GRAPH_CONNECTION>> shortestPath;
170 shortestPath.clear();
173 if( !shortestPath.empty() && ( shortestPath.size() >= 4 ) && (
distance - creepageValue < 0 ) )
176 wxString msg =
formatMsg(
_(
"(%s creepage %s; actual %s)" ),
179 drce->SetErrorMessage( drce->GetErrorText() + wxS(
" " ) + msg );
182 std::shared_ptr<GRAPH_CONNECTION> gc1 = shortestPath[1];
183 std::shared_ptr<GRAPH_CONNECTION> gc2 = shortestPath[shortestPath.size() - 2];
185 if( gc1->n1 && gc2->n2 )
187 const BOARD_ITEM* item1 = gc1->n1->m_parent->GetParent();
188 const BOARD_ITEM* item2 = gc2->n2->m_parent->GetParent();
191 drce->SetItems( item1, item2 );
196 VECTOR2I startPoint = gc1->m_path.a2;
198 std::vector<PCB_SHAPE>
path;
200 for(
const std::shared_ptr<GRAPH_CONNECTION>& gc : shortestPath )
201 gc->GetShapes(
path );
212 double maxConstraint = 0;
219 [&](
int aNet1,
int aNet2 )
224 bci1.SetNetCode( aNet1 );
225 bci2.SetNetCode( aNet2 );
227 for( PCB_LAYER_ID layer : LSET::AllCuMask( m_board->GetCopperLayerCount() ) )
229 bci1.SetLayer( layer );
230 bci2.SetLayer( layer );
231 constraint = m_drcEngine->EvalRules( CREEPAGE_CONSTRAINT, &bci1, &bci2, layer );
232 double value = constraint.Value().Min();
233 maxConstraint = value > maxConstraint ? value : maxConstraint;
237 return maxConstraint;
243 NETCODES_MAP nets =
m_board->GetNetInfo().NetsByNetcode();
245 for(
auto it = nets.begin(); it != nets.end(); it++ )
246 aVector.push_back( it->first );
261 aVector.push_back( drawing );
269 for(
BOARD_ITEM* drawing : fp->GraphicalItems() )
275 aVector.push_back( drawing );
290 aVector.push_back( s );
300 std::vector<int> netcodes;
305 if( maxConstraint <= 0 )
310 if( !
m_board->GetBoardPolygonOutlines( outline ) )
313 const DRAWINGS drawings =
m_board->Drawings();
330 int beNodeSize = graph.
m_nodes.size();
332 bool prevTestChangedGraph =
false;
335 size_t total = ( netcodes.size() * ( netcodes.size() - 1 ) ) / 2 *
m_board->GetCopperLayerCount();
339 [&](
int aNet1,
int aNet2 )
344 for( auto it = layers.copper_layers_begin(); it != layers.copper_layers_end(); ++it )
346 PCB_LAYER_ID layer = *it;
348 reportProgress( current++, total );
350 if ( prevTestChangedGraph )
352 size_t vectorSize = graph.m_connections.size();
354 for( size_t i = beConnectionsSize; i < vectorSize; i++ )
357 graph.RemoveConnection( graph.m_connections[i], false );
359 graph.m_connections.resize( beConnectionsSize, nullptr );
361 vectorSize = graph.m_nodes.size();
362 graph.m_nodes.resize( beNodeSize, nullptr );
365 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.
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.
std::vector< PCB_SHAPE > GetShapes(const std::vector< PCB_SHAPE > &aShapes, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aLength)
DRC_TEST_PROVIDER_CLEARANCE_BASE()
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)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::vector< PCB_SHAPE > &aShapes={})
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