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 int Clearance (const PNS::ITEM *aA, const PNS::ITEM *aB) const override
 
virtual int Clearance (int aNetCode) const override
 
virtual void OverrideClearance (bool aEnable, int aNetA=0, int aNetB=0, int aClearance=0) override
 
virtual void UseDpGap (bool aUseDpGap) override
 
virtual int DpCoupledNet (int aNet) override
 
virtual int DpNetPolarity (int aNet) override
 
virtual bool DpNetPair (PNS::ITEM *aItem, int &aNetP, int &aNetN) override
 

Private Member Functions

int localPadClearance (const PNS::ITEM *aItem) const
 
int matchDpSuffix (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
 
bool m_overrideEnabled
 
int m_overrideNetA
 
int m_overrideNetB
 
int m_overrideClearance
 
bool m_useDpGap
 

Detailed Description

Definition at line 64 of file pns_kicad_iface.cpp.

Constructor & Destructor Documentation

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

Definition at line 101 of file pns_kicad_iface.cpp.

References PNS_PCBNEW_RULE_RESOLVER::CLEARANCE_ENT::clearance, PNS_PCBNEW_RULE_RESOLVER::CLEARANCE_ENT::coupledNet, DpCoupledNet(), NETCLASSES::Find(), BOARD::FindNet(), NETINFO_ITEM::GetClassName(), BOARD::GetDesignSettings(), BOARD::GetNetCount(), PNS::ROUTER::GetWorld(), m_board, m_defaultClearance, m_localClearanceCache, BOARD::m_Modules, BOARD_DESIGN_SETTINGS::m_NetClasses, m_netClearanceCache, m_overrideClearance, m_overrideEnabled, m_overrideNetA, m_overrideNetB, m_router, m_useDpGap, and mod.

101  :
102  m_router( aRouter ),
103  m_board( aBoard )
104 {
105  PNS::NODE* world = m_router->GetWorld();
106 
107  PNS::TOPOLOGY topo( world );
109 
110  // Build clearance cache for net classes
111  for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
112  {
113  NETINFO_ITEM* ni = m_board->FindNet( i );
114 
115  if( ni == NULL )
116  continue;
117 
118  CLEARANCE_ENT ent;
119  ent.coupledNet = DpCoupledNet( i );
120 
121  wxString netClassName = ni->GetClassName();
122  NETCLASSPTR nc = m_board->GetDesignSettings().m_NetClasses.Find( netClassName );
123 
124  int clearance = nc->GetClearance();
125  ent.clearance = clearance;
126  m_netClearanceCache[i] = ent;
127 
128  wxLogTrace( "PNS", "Add net %u netclass %s clearance %d", i, netClassName.mb_str(), clearance );
129  }
130 
131  // Build clearance cache for pads
132  for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() )
133  {
134  auto moduleClearance = mod->GetLocalClearance();
135 
136  for( D_PAD* pad = mod->PadsList(); pad; pad = pad->Next() )
137  {
138  int padClearance = pad->GetLocalClearance();
139 
140  if( padClearance > 0 )
141  m_localClearanceCache[ pad ] = padClearance;
142 
143  else if( moduleClearance > 0 )
144  m_localClearanceCache[ pad ] = moduleClearance;
145  }
146  }
147 
148  //printf("DefaultCL : %d\n", m_board->GetDesignSettings().m_NetClasses.Find ("Default clearance")->GetClearance());
149 
150  m_overrideEnabled = false;
151  m_defaultClearance = Millimeter2iu( 0.254 ); // m_board->m_NetClasses.Find ("Default clearance")->GetClearance();
152  m_overrideNetA = 0;
153  m_overrideNetB = 0;
155  m_useDpGap = false;
156 }
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Class NODE.
Definition: pns_node.h:137
wxString GetClassName() const
Function GetClassName returns the class name.
NODE * GetWorld() const
Definition: pns_router.h:143
virtual int DpCoupledNet(int aNet) override
std::vector< CLEARANCE_ENT > m_netClearanceCache
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
DLIST< MODULE > m_Modules
Definition: class_board.h:245
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
std::unordered_map< const D_PAD *, int > m_localClearanceCache
#define mod(a, n)
Definition: greymap.cpp:24
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:772
PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER ( )
virtual

Definition at line 159 of file pns_kicad_iface.cpp.

160 {
161 }

Member Function Documentation

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

Implements PNS::RULE_RESOLVER.

Definition at line 180 of file pns_kicad_iface.cpp.

References PNS::SIZES_SETTINGS::DiffPairGap(), PNS::ITEM::LINE_T, localPadClearance(), m_defaultClearance, m_netClearanceCache, m_router, max, PNS::ITEM::Net(), PNS::ITEM::OfKind(), PNS_HULL_MARGIN, PNS::ITEM::SEGMENT_T, and PNS::ROUTER::Sizes().

181 {
182  int net_a = aA->Net();
183  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
184  int net_b = aB->Net();
185  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
186 
187  bool linesOnly = aA->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T )
189 
190  if( linesOnly && net_a >= 0 && net_b >= 0 && m_netClearanceCache[net_a].coupledNet == net_b )
191  {
192  cl_a = cl_b = m_router->Sizes().DiffPairGap() - 2 * PNS_HULL_MARGIN;
193  }
194 
195  int pad_a = localPadClearance( aA );
196  int pad_b = localPadClearance( aB );
197 
198  if( pad_a > 0 )
199  cl_a = pad_a;
200 
201  if( pad_b > 0 )
202  cl_b = pad_b;
203 
204  return std::max( cl_a, cl_b );
205 }
int localPadClearance(const PNS::ITEM *aItem) const
#define PNS_HULL_MARGIN
Class LINE.
Definition: pns_line.h:58
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:206
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:130
std::vector< CLEARANCE_ENT > m_netClearanceCache
#define max(a, b)
Definition: auxiliary.h:86
int Net() const
Function Net()
Definition: pns_item.h:177
int PNS_PCBNEW_RULE_RESOLVER::Clearance ( int  aNetCode) const
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 208 of file pns_kicad_iface.cpp.

References m_defaultClearance, and m_netClearanceCache.

209 {
210  if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
211  return m_netClearanceCache[aNetCode].clearance;
212 
213  return m_defaultClearance;
214 }
std::vector< CLEARANCE_ENT > m_netClearanceCache
int PNS_PCBNEW_RULE_RESOLVER::DpCoupledNet ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 285 of file pns_kicad_iface.cpp.

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

Referenced by PNS_PCBNEW_RULE_RESOLVER().

286 {
287  wxString refName = m_board->FindNet( aNet )->GetNetname();
288  wxString dummy, coupledNetName;
289 
290  if( matchDpSuffix( refName, coupledNetName, dummy ) )
291  {
292  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
293 
294  if( !net )
295  return -1;
296 
297  return net->GetNet();
298  }
299 
300  return -1;
301 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const wxString & GetNetname() const
Function GetNetname.
bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair ( PNS::ITEM aItem,
int &  aNetP,
int &  aNetN 
)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 313 of file pns_kicad_iface.cpp.

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

314 {
315  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
316  return false;
317 
318  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
319  wxString netNameN, netNameCoupled, netNameBase;
320 
321  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
322 
323  if( r == 0 )
324  return false;
325  else if( r == 1 )
326  {
327  netNameN = netNameCoupled;
328  }
329  else
330  {
331  netNameN = netNameP;
332  netNameP = netNameCoupled;
333  }
334 
335 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
336 
337  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
338  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
339 
340  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
341 
342  if( !netInfoP || !netInfoN )
343  return false;
344 
345  aNetP = netInfoP->GetNet();
346  aNetN = netInfoN->GetNet();
347 
348  return true;
349 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const wxString & GetNetname() const
Function GetNetname.
BOARD_CONNECTED_ITEM * Parent() const
Function Parent()
Definition: pns_item.h:157
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
int PNS_PCBNEW_RULE_RESOLVER::DpNetPolarity ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 304 of file pns_kicad_iface.cpp.

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

305 {
306  wxString refName = m_board->FindNet( aNet )->GetNetname();
307  wxString dummy1, dummy2;
308 
309  return matchDpSuffix( refName, dummy1, dummy2 );
310 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
const wxString & GetNetname() const
Function GetNetname.
int PNS_PCBNEW_RULE_RESOLVER::localPadClearance ( const PNS::ITEM aItem) const
private

Definition at line 164 of file pns_kicad_iface.cpp.

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

Referenced by Clearance().

165 {
166  if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
167  return 0;
168 
169  const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
170 
171  auto i = m_localClearanceCache.find( pad );
172 
173  if( i == m_localClearanceCache.end() )
174  return 0;
175 
176  return i->second;
177 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
std::unordered_map< const D_PAD *, int > m_localClearanceCache
BOARD_CONNECTED_ITEM * Parent() const
Function Parent()
Definition: pns_item.h:157
int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix ( wxString  aNetName,
wxString &  aComplementNet,
wxString &  aBaseDpName 
)
private

Definition at line 227 of file pns_kicad_iface.cpp.

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

228 {
229  int rv = 0;
230 
231  if( aNetName.EndsWith( "+" ) )
232  {
233  aComplementNet = "-";
234  rv = 1;
235  }
236  else if( aNetName.EndsWith( "P" ) )
237  {
238  aComplementNet = "N";
239  rv = 1;
240  }
241  else if( aNetName.EndsWith( "-" ) )
242  {
243  aComplementNet = "+";
244  rv = -1;
245  }
246  else if( aNetName.EndsWith( "N" ) )
247  {
248  aComplementNet = "P";
249  rv = -1;
250  }
251  // Match P followed by 2 digits
252  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
253  {
254  aComplementNet = "N" + aNetName.Right( 2 );
255  rv = 1;
256  }
257  // Match P followed by 1 digit
258  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
259  {
260  aComplementNet = "N" + aNetName.Right( 1 );
261  rv = 1;
262  }
263  // Match N followed by 2 digits
264  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
265  {
266  aComplementNet = "P" + aNetName.Right( 2 );
267  rv = -1;
268  }
269  // Match N followed by 1 digit
270  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
271  {
272  aComplementNet = "P" + aNetName.Right( 1 );
273  rv = -1;
274  }
275  if( rv != 0 )
276  {
277  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
278  aComplementNet = aBaseDpName + aComplementNet;
279  }
280 
281  return rv;
282 }
void PNS_PCBNEW_RULE_RESOLVER::OverrideClearance ( bool  aEnable,
int  aNetA = 0,
int  aNetB = 0,
int  aClearance = 0 
)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 218 of file pns_kicad_iface.cpp.

References m_overrideClearance, m_overrideEnabled, m_overrideNetA, and m_overrideNetB.

219 {
220  m_overrideEnabled = aEnable;
221  m_overrideNetA = aNetA;
222  m_overrideNetB = aNetB;
223  m_overrideClearance = aClearance;
224 }
virtual void PNS_PCBNEW_RULE_RESOLVER::UseDpGap ( bool  aUseDpGap)
inlineoverridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 73 of file pns_kicad_iface.cpp.

References m_useDpGap.

73 { m_useDpGap = aUseDpGap; }

Member Data Documentation

BOARD* PNS_PCBNEW_RULE_RESOLVER::m_board
private
int PNS_PCBNEW_RULE_RESOLVER::m_defaultClearance
private

Definition at line 93 of file pns_kicad_iface.cpp.

Referenced by Clearance(), and PNS_PCBNEW_RULE_RESOLVER().

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

Definition at line 92 of file pns_kicad_iface.cpp.

Referenced by localPadClearance(), and PNS_PCBNEW_RULE_RESOLVER().

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

Definition at line 91 of file pns_kicad_iface.cpp.

Referenced by Clearance(), and PNS_PCBNEW_RULE_RESOLVER().

int PNS_PCBNEW_RULE_RESOLVER::m_overrideClearance
private

Definition at line 96 of file pns_kicad_iface.cpp.

Referenced by OverrideClearance(), and PNS_PCBNEW_RULE_RESOLVER().

bool PNS_PCBNEW_RULE_RESOLVER::m_overrideEnabled
private

Definition at line 94 of file pns_kicad_iface.cpp.

Referenced by OverrideClearance(), and PNS_PCBNEW_RULE_RESOLVER().

int PNS_PCBNEW_RULE_RESOLVER::m_overrideNetA
private

Definition at line 95 of file pns_kicad_iface.cpp.

Referenced by OverrideClearance(), and PNS_PCBNEW_RULE_RESOLVER().

int PNS_PCBNEW_RULE_RESOLVER::m_overrideNetB
private

Definition at line 95 of file pns_kicad_iface.cpp.

Referenced by OverrideClearance(), and PNS_PCBNEW_RULE_RESOLVER().

PNS::ROUTER* PNS_PCBNEW_RULE_RESOLVER::m_router
private

Definition at line 88 of file pns_kicad_iface.cpp.

Referenced by Clearance(), and PNS_PCBNEW_RULE_RESOLVER().

bool PNS_PCBNEW_RULE_RESOLVER::m_useDpGap
private

Definition at line 97 of file pns_kicad_iface.cpp.

Referenced by PNS_PCBNEW_RULE_RESOLVER(), and UseDpGap().


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