KiCad PCB EDA Suite
PNS_PCBNEW_RULE_RESOLVER Class Reference
Inheritance diagram for PNS_PCBNEW_RULE_RESOLVER:
PNS::RULE_RESOLVER

Classes

struct  CLEARANCE_ENT
 

Public Member Functions

 PNS_PCBNEW_RULE_RESOLVER (BOARD *aBoard, PNS::ROUTER *aRouter)
 
virtual ~PNS_PCBNEW_RULE_RESOLVER ()
 
virtual bool CollideHoles (const PNS::ITEM *aA, const PNS::ITEM *aB, bool aNeedMTV, VECTOR2I *aMTV) const override
 
virtual int Clearance (const PNS::ITEM *aA, const PNS::ITEM *aB) const override
 
virtual int Clearance (int aNetCode) const override
 
virtual int DpCoupledNet (int aNet) override
 
virtual int DpNetPolarity (int aNet) override
 
virtual bool DpNetPair (PNS::ITEM *aItem, int &aNetP, int &aNetN) override
 
virtual wxString NetName (int aNet) override
 

Private Member Functions

int holeRadius (const PNS::ITEM *aItem) const
 
int localPadClearance (const PNS::ITEM *aItem) const
 
int matchDpSuffix (const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
 

Private Attributes

PNS::ROUTERm_router
 
BOARDm_board
 
std::vector< CLEARANCE_ENTm_netClearanceCache
 
std::unordered_map< const D_PAD *, int > m_localClearanceCache
 
int m_defaultClearance
 

Detailed Description

Definition at line 65 of file pns_kicad_iface.cpp.

Constructor & Destructor Documentation

◆ PNS_PCBNEW_RULE_RESOLVER()

PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER ( BOARD aBoard,
PNS::ROUTER aRouter 
)

Definition at line 103 of file pns_kicad_iface.cpp.

103  :
104  m_router( aRouter ),
105  m_board( aBoard )
106 {
107  PNS::NODE* world = m_router->GetWorld();
108 
109  PNS::TOPOLOGY topo( world );
111 
112  // Build clearance cache for net classes
113  for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
114  {
115  NETINFO_ITEM* ni = m_board->FindNet( i );
116 
117  if( ni == NULL )
118  continue;
119 
120  CLEARANCE_ENT ent;
121  ent.coupledNet = DpCoupledNet( i );
122 
123  wxString netClassName = ni->GetClassName();
124  NETCLASSPTR nc = m_board->GetDesignSettings().m_NetClasses.Find( netClassName );
125 
126  int clearance = nc->GetClearance();
127  ent.clearance = clearance;
128  ent.dpClearance = nc->GetDiffPairGap();
129  m_netClearanceCache[i] = ent;
130 
131  wxLogTrace( "PNS", "Add net %u netclass %s clearance %d Diff Pair clearance %d",
132  i, netClassName.mb_str(), clearance, ent.dpClearance );
133  }
134 
135  // Build clearance cache for pads
136  for( auto mod : m_board->Modules() )
137  {
138  auto moduleClearance = mod->GetLocalClearance();
139 
140  for( auto pad : mod->Pads() )
141  {
142  int padClearance = pad->GetLocalClearance();
143 
144  if( padClearance > 0 )
145  m_localClearanceCache[ pad ] = padClearance;
146 
147  else if( moduleClearance > 0 )
148  m_localClearanceCache[ pad ] = moduleClearance;
149  }
150  }
151 
152  auto defaultRule = m_board->GetDesignSettings().m_NetClasses.Find ("Default");
153 
154  if( defaultRule )
155  {
156  m_defaultClearance = defaultRule->GetClearance();
157  }
158  else
159  {
160  m_defaultClearance = Millimeter2iu(0.254);
161  }
162 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
Class NODE.
Definition: pns_node.h:140
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:141
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:779
MODULES & Modules()
Definition: class_board.h:236
virtual int DpCoupledNet(int aNet) override
std::vector< CLEARANCE_ENT > m_netClearanceCache
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
size_t i
Definition: json11.cpp:597
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:131
NODE * GetWorld() const
Definition: pns_router.h:145
std::unordered_map< const D_PAD *, int > m_localClearanceCache
#define mod(a, n)
Definition: greymap.cpp:24

References PNS_PCBNEW_RULE_RESOLVER::CLEARANCE_ENT::clearance, PNS_PCBNEW_RULE_RESOLVER::CLEARANCE_ENT::coupledNet, PNS_PCBNEW_RULE_RESOLVER::CLEARANCE_ENT::dpClearance, DpCoupledNet(), NETCLASSES::Find(), BOARD::FindNet(), NETINFO_ITEM::GetClassName(), BOARD::GetDesignSettings(), BOARD::GetNetCount(), PNS::ROUTER::GetWorld(), i, m_board, m_defaultClearance, m_localClearanceCache, BOARD_DESIGN_SETTINGS::m_NetClasses, m_netClearanceCache, m_router, mod, and BOARD::Modules().

◆ ~PNS_PCBNEW_RULE_RESOLVER()

PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER ( )
virtual

Definition at line 165 of file pns_kicad_iface.cpp.

166 {
167 }

Member Function Documentation

◆ Clearance() [1/2]

int PNS_PCBNEW_RULE_RESOLVER::Clearance ( const PNS::ITEM aA,
const PNS::ITEM aB 
) const
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 245 of file pns_kicad_iface.cpp.

246 {
247  int net_a = aA->Net();
248  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
249  int net_b = aB->Net();
250  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
251 
252  // Pad clearance is 0 if the ITEM* is not a pad
253  int pad_a = localPadClearance( aA );
254  int pad_b = localPadClearance( aB );
255 
256  if( pad_a > 0 )
257  cl_a = pad_a;
258 
259  if( pad_b > 0 )
260  cl_b = pad_b;
261 
262  return std::max( cl_a, cl_b );
263 }
int localPadClearance(const PNS::ITEM *aItem) const
int Net() const
Definition: pns_item.h:148
std::vector< CLEARANCE_ENT > m_netClearanceCache
#define max(a, b)
Definition: auxiliary.h:86

References localPadClearance(), m_defaultClearance, m_netClearanceCache, max, and PNS::ITEM::Net().

◆ Clearance() [2/2]

int PNS_PCBNEW_RULE_RESOLVER::Clearance ( int  aNetCode) const
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 266 of file pns_kicad_iface.cpp.

267 {
268  if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
269  return m_netClearanceCache[aNetCode].clearance;
270 
271  return m_defaultClearance;
272 }
std::vector< CLEARANCE_ENT > m_netClearanceCache

References m_defaultClearance, and m_netClearanceCache.

◆ CollideHoles()

bool PNS_PCBNEW_RULE_RESOLVER::CollideHoles ( const PNS::ITEM aA,
const PNS::ITEM aB,
bool  aNeedMTV,
VECTOR2I aMTV 
) const
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 191 of file pns_kicad_iface.cpp.

193 {
194  VECTOR2I pos_a = aA->Shape()->Centre();
195  VECTOR2I pos_b = aB->Shape()->Centre();
196 
197  // Holes with identical locations are allowable
198  if( pos_a == pos_b )
199  return false;
200 
201  int radius_a = holeRadius( aA );
202  int radius_b = holeRadius( aB );
203 
204  // Do both objects have holes?
205  if( radius_a > 0 && radius_b > 0 )
206  {
207  int holeToHoleMin = m_board->GetDesignSettings().m_HoleToHoleMin;
208 
209  ecoord min_dist = holeToHoleMin + radius_a + radius_b;
210  ecoord min_dist_sq = min_dist * min_dist;
211 
212  const VECTOR2I delta = pos_b - pos_a;
213 
214  ecoord dist_sq = delta.SquaredEuclideanNorm();
215 
216  if( dist_sq < min_dist_sq )
217  {
218  if( aNeedMTV )
219  *aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
220 
221  return true;
222  }
223  }
224 
225  return false;
226 }
int holeRadius(const PNS::ITEM *aItem) const
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:299
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
virtual VECTOR2I Centre() const
Function Centre()
Definition: shape.h:151
VECTOR2I::extended_type ecoord
Definition: pns_item.cpp:26
int m_HoleToHoleMin
Min width of peninsula between two drilled holes.
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:213
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385

References SHAPE::Centre(), BOARD::GetDesignSettings(), holeRadius(), m_board, BOARD_DESIGN_SETTINGS::m_HoleToHoleMin, VECTOR2< T >::Resize(), PNS::ITEM::Shape(), and VECTOR2< T >::SquaredEuclideanNorm().

◆ DpCoupledNet()

int PNS_PCBNEW_RULE_RESOLVER::DpCoupledNet ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 334 of file pns_kicad_iface.cpp.

335 {
336  wxString refName = m_board->FindNet( aNet )->GetNetname();
337  wxString dummy, coupledNetName;
338 
339  if( matchDpSuffix( refName, coupledNetName, dummy ) )
340  {
341  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
342 
343  if( !net )
344  return -1;
345 
346  return net->GetNet();
347  }
348 
349  return -1;
350 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
int matchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)

References dummy(), BOARD::FindNet(), NETINFO_ITEM::GetNet(), NETINFO_ITEM::GetNetname(), m_board, and matchDpSuffix().

Referenced by PNS_PCBNEW_RULE_RESOLVER().

◆ DpNetPair()

bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair ( PNS::ITEM aItem,
int &  aNetP,
int &  aNetN 
)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 368 of file pns_kicad_iface.cpp.

369 {
370  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
371  return false;
372 
373  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
374  wxString netNameN, netNameCoupled, netNameBase;
375 
376  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
377 
378  if( r == 0 )
379  return false;
380  else if( r == 1 )
381  {
382  netNameN = netNameCoupled;
383  }
384  else
385  {
386  netNameN = netNameP;
387  netNameP = netNameCoupled;
388  }
389 
390 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
391 
392  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
393  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
394 
395  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
396 
397  if( !netInfoP || !netInfoN )
398  return false;
399 
400  aNetP = netInfoP->GetNet();
401  aNetN = netInfoN->GetNet();
402 
403  return true;
404 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:145
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
int matchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)

References BOARD::FindNet(), BOARD_CONNECTED_ITEM::GetNet(), NETINFO_ITEM::GetNet(), NETINFO_ITEM::GetNetname(), m_board, matchDpSuffix(), and PNS::ITEM::Parent().

◆ DpNetPolarity()

int PNS_PCBNEW_RULE_RESOLVER::DpNetPolarity ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 359 of file pns_kicad_iface.cpp.

360 {
361  wxString refName = m_board->FindNet( aNet )->GetNetname();
362  wxString dummy1, dummy2;
363 
364  return matchDpSuffix( refName, dummy1, dummy2 );
365 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233
int matchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)

References BOARD::FindNet(), NETINFO_ITEM::GetNetname(), m_board, and matchDpSuffix().

◆ holeRadius()

int PNS_PCBNEW_RULE_RESOLVER::holeRadius ( const PNS::ITEM aItem) const
private

Definition at line 170 of file pns_kicad_iface.cpp.

171 {
172  if( aItem->Kind() == PNS::ITEM::SOLID_T )
173  {
174  const D_PAD* pad = dynamic_cast<const D_PAD*>( aItem->Parent() );
175 
176  if( pad && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
177  return pad->GetDrillSize().x / 2;
178  }
179  else if( aItem->Kind() == PNS::ITEM::VIA_T )
180  {
181  const ::VIA* via = dynamic_cast<const ::VIA*>( aItem->Parent() );
182 
183  if( via )
184  return via->GetDrillValue() / 2;
185  }
186 
187  return 0;
188 }
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:145
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:412
const wxSize & GetDrillSize() const
Definition: class_pad.h:290
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122

References D_PAD::GetDrillShape(), D_PAD::GetDrillSize(), PNS::ITEM::Kind(), PAD_DRILL_SHAPE_CIRCLE, PNS::ITEM::Parent(), PNS::ITEM::SOLID_T, VIA, and PNS::ITEM::VIA_T.

Referenced by CollideHoles().

◆ localPadClearance()

int PNS_PCBNEW_RULE_RESOLVER::localPadClearance ( const PNS::ITEM aItem) const
private

Definition at line 229 of file pns_kicad_iface.cpp.

230 {
231  if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
232  return 0;
233 
234  const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
235 
236  auto i = m_localClearanceCache.find( pad );
237 
238  if( i == m_localClearanceCache.end() )
239  return 0;
240 
241  return i->second;
242 }
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:145
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
size_t i
Definition: json11.cpp:597
std::unordered_map< const D_PAD *, int > m_localClearanceCache
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References i, m_localClearanceCache, PNS::ITEM::Parent(), PCB_PAD_T, and EDA_ITEM::Type().

Referenced by Clearance().

◆ matchDpSuffix()

int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix ( const wxString &  aNetName,
wxString &  aComplementNet,
wxString &  aBaseDpName 
)
private

Definition at line 275 of file pns_kicad_iface.cpp.

277 {
278  int rv = 0;
279 
280  if( aNetName.EndsWith( "+" ) )
281  {
282  aComplementNet = "-";
283  rv = 1;
284  }
285  else if( aNetName.EndsWith( "P" ) )
286  {
287  aComplementNet = "N";
288  rv = 1;
289  }
290  else if( aNetName.EndsWith( "-" ) )
291  {
292  aComplementNet = "+";
293  rv = -1;
294  }
295  else if( aNetName.EndsWith( "N" ) )
296  {
297  aComplementNet = "P";
298  rv = -1;
299  }
300  // Match P followed by 2 digits
301  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
302  {
303  aComplementNet = "N" + aNetName.Right( 2 );
304  rv = 1;
305  }
306  // Match P followed by 1 digit
307  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
308  {
309  aComplementNet = "N" + aNetName.Right( 1 );
310  rv = 1;
311  }
312  // Match N followed by 2 digits
313  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
314  {
315  aComplementNet = "P" + aNetName.Right( 2 );
316  rv = -1;
317  }
318  // Match N followed by 1 digit
319  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
320  {
321  aComplementNet = "P" + aNetName.Right( 1 );
322  rv = -1;
323  }
324  if( rv != 0 )
325  {
326  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
327  aComplementNet = aBaseDpName + aComplementNet;
328  }
329 
330  return rv;
331 }

Referenced by DpCoupledNet(), DpNetPair(), and DpNetPolarity().

◆ NetName()

wxString PNS_PCBNEW_RULE_RESOLVER::NetName ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 353 of file pns_kicad_iface.cpp.

354 {
355  return m_board->FindNet( aNet )->GetNetname();
356 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233

References BOARD::FindNet(), NETINFO_ITEM::GetNetname(), and m_board.

Member Data Documentation

◆ m_board

BOARD* PNS_PCBNEW_RULE_RESOLVER::m_board
private

◆ m_defaultClearance

int PNS_PCBNEW_RULE_RESOLVER::m_defaultClearance
private

Definition at line 99 of file pns_kicad_iface.cpp.

Referenced by Clearance(), and PNS_PCBNEW_RULE_RESOLVER().

◆ m_localClearanceCache

std::unordered_map<const D_PAD*, int> PNS_PCBNEW_RULE_RESOLVER::m_localClearanceCache
private

Definition at line 98 of file pns_kicad_iface.cpp.

Referenced by localPadClearance(), and PNS_PCBNEW_RULE_RESOLVER().

◆ m_netClearanceCache

std::vector<CLEARANCE_ENT> PNS_PCBNEW_RULE_RESOLVER::m_netClearanceCache
private

Definition at line 97 of file pns_kicad_iface.cpp.

Referenced by Clearance(), and PNS_PCBNEW_RULE_RESOLVER().

◆ m_router

PNS::ROUTER* PNS_PCBNEW_RULE_RESOLVER::m_router
private

Definition at line 94 of file pns_kicad_iface.cpp.

Referenced by PNS_PCBNEW_RULE_RESOLVER().


The documentation for this class was generated from the following file: