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 72 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 110 of file pns_kicad_iface.cpp.

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

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_DESIGN_SETTINGS::GetNetClasses(), BOARD::GetNetCount(), PNS::ROUTER::GetWorld(), m_board, m_defaultClearance, m_localClearanceCache, m_netClearanceCache, m_router, BOARD::Modules(), and NULL.

◆ ~PNS_PCBNEW_RULE_RESOLVER()

PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER ( )
virtual

Definition at line 172 of file pns_kicad_iface.cpp.

173 {
174 }

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 252 of file pns_kicad_iface.cpp.

253 {
254  int net_a = aA->Net();
255  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
256  int net_b = aB->Net();
257  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
258 
259  // Pad clearance is 0 if the ITEM* is not a pad
260  int pad_a = localPadClearance( aA );
261  int pad_b = localPadClearance( aB );
262 
263  if( pad_a > 0 )
264  cl_a = pad_a;
265 
266  if( pad_b > 0 )
267  cl_b = pad_b;
268 
269  return std::max( cl_a, cl_b );
270 }
int localPadClearance(const PNS::ITEM *aItem) const
int Net() const
Definition: pns_item.h:149
std::vector< CLEARANCE_ENT > m_netClearanceCache

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

◆ Clearance() [2/2]

int PNS_PCBNEW_RULE_RESOLVER::Clearance ( int  aNetCode) const
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 273 of file pns_kicad_iface.cpp.

274 {
275  if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
276  return m_netClearanceCache[aNetCode].clearance;
277 
278  return m_defaultClearance;
279 }
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 198 of file pns_kicad_iface.cpp.

200 {
201  VECTOR2I pos_a = aA->Shape()->Centre();
202  VECTOR2I pos_b = aB->Shape()->Centre();
203 
204  // Holes with identical locations are allowable
205  if( pos_a == pos_b )
206  return false;
207 
208  int radius_a = holeRadius( aA );
209  int radius_b = holeRadius( aB );
210 
211  // Do both objects have holes?
212  if( radius_a > 0 && radius_b > 0 )
213  {
214  int holeToHoleMin = m_board->GetDesignSettings().m_HoleToHoleMin;
215 
216  ecoord min_dist = holeToHoleMin + radius_a + radius_b;
217  ecoord min_dist_sq = min_dist * min_dist;
218 
219  const VECTOR2I delta = pos_b - pos_a;
220 
221  ecoord dist_sq = delta.SquaredEuclideanNorm();
222 
223  if( dist_sq == 0 || dist_sq < min_dist_sq )
224  {
225  if( aNeedMTV )
226  *aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
227 
228  return true;
229  }
230  }
231 
232  return false;
233 }
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:306
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:551
virtual VECTOR2I Centre() const
Function Centre()
Definition: shape.h:173
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:214
VECTOR2I::extended_type ecoord
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392

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 341 of file pns_kicad_iface.cpp.

342 {
343  wxString refName = m_board->FindNet( aNet )->GetNetname();
344  wxString dummy, coupledNetName;
345 
346  if( matchDpSuffix( refName, coupledNetName, dummy ) )
347  {
348  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
349 
350  if( !net )
351  return -1;
352 
353  return net->GetNet();
354  }
355 
356  return -1;
357 }
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:231
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:223
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 375 of file pns_kicad_iface.cpp.

376 {
377  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
378  return false;
379 
380  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
381  wxString netNameN, netNameCoupled, netNameBase;
382 
383  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
384 
385  if( r == 0 )
386  return false;
387  else if( r == 1 )
388  {
389  netNameN = netNameCoupled;
390  }
391  else
392  {
393  netNameN = netNameP;
394  netNameP = netNameCoupled;
395  }
396 
397 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
398 
399  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
400  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
401 
402  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
403 
404  if( !netInfoP || !netInfoN )
405  return false;
406 
407  aNetP = netInfoP->GetNet();
408  aNetN = netInfoN->GetNet();
409 
410  return true;
411 }
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:146
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
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 366 of file pns_kicad_iface.cpp.

367 {
368  wxString refName = m_board->FindNet( aNet )->GetNetname();
369  wxString dummy1, dummy2;
370 
371  return matchDpSuffix( refName, dummy1, dummy2 );
372 }
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:231
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 177 of file pns_kicad_iface.cpp.

178 {
179  if( aItem->Kind() == PNS::ITEM::SOLID_T )
180  {
181  const D_PAD* pad = dynamic_cast<const D_PAD*>( aItem->Parent() );
182 
183  if( pad && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
184  return pad->GetDrillSize().x / 2;
185  }
186  else if( aItem->Kind() == PNS::ITEM::VIA_T )
187  {
188  const ::VIA* via = dynamic_cast<const ::VIA*>( aItem->Parent() );
189 
190  if( via )
191  return via->GetDrillValue() / 2;
192  }
193 
194  return 0;
195 }
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:146
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:320
const wxSize & GetDrillSize() const
Definition: class_pad.h:227
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123

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 236 of file pns_kicad_iface.cpp.

237 {
238  if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
239  return 0;
240 
241  const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
242 
243  auto i = m_localClearanceCache.find( pad );
244 
245  if( i == m_localClearanceCache.end() )
246  return 0;
247 
248  return i->second;
249 }
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:146
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
std::unordered_map< const D_PAD *, int > m_localClearanceCache
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References 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 282 of file pns_kicad_iface.cpp.

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

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

◆ NetName()

wxString PNS_PCBNEW_RULE_RESOLVER::NetName ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 360 of file pns_kicad_iface.cpp.

361 {
362  return m_board->FindNet( aNet )->GetNetname();
363 }
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:231

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 106 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 105 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 104 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 101 of file pns_kicad_iface.cpp.

Referenced by PNS_PCBNEW_RULE_RESOLVER().


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