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 65 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 102 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(), i, 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.

Referenced by PNS_KICAD_IFACE::SyncWorld().

102  :
103  m_router( aRouter ),
104  m_board( aBoard )
105 {
106  PNS::NODE* world = m_router->GetWorld();
107 
108  PNS::TOPOLOGY topo( world );
110 
111  // Build clearance cache for net classes
112  for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
113  {
114  NETINFO_ITEM* ni = m_board->FindNet( i );
115 
116  if( ni == NULL )
117  continue;
118 
119  CLEARANCE_ENT ent;
120  ent.coupledNet = DpCoupledNet( i );
121 
122  wxString netClassName = ni->GetClassName();
123  NETCLASSPTR nc = m_board->GetDesignSettings().m_NetClasses.Find( netClassName );
124 
125  int clearance = nc->GetClearance();
126  ent.clearance = clearance;
127  m_netClearanceCache[i] = ent;
128 
129  wxLogTrace( "PNS", "Add net %u netclass %s clearance %d", i, netClassName.mb_str(), clearance );
130  }
131 
132  // Build clearance cache for pads
133  for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() )
134  {
135  auto moduleClearance = mod->GetLocalClearance();
136 
137  for( D_PAD* pad = mod->PadsList(); pad; pad = pad->Next() )
138  {
139  int padClearance = pad->GetLocalClearance();
140 
141  if( padClearance > 0 )
142  m_localClearanceCache[ pad ] = padClearance;
143 
144  else if( moduleClearance > 0 )
145  m_localClearanceCache[ pad ] = moduleClearance;
146  }
147  }
148 
149  m_overrideEnabled = false;
150 
151  auto defaultRule = m_board->GetDesignSettings().m_NetClasses.Find ("Default");
152 
153  if( defaultRule )
154  {
155  m_defaultClearance = defaultRule->GetClearance();
156  }
157  else
158  {
159  m_defaultClearance = Millimeter2iu(0.254);
160  }
161 
162  m_overrideNetA = 0;
163  m_overrideNetB = 0;
165  m_useDpGap = false;
166 }
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:144
Class NODE.
Definition: pns_node.h:137
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:131
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: netinfo.h:69
DLIST< MODULE > m_Modules
Definition: class_board.h:245
size_t i
Definition: json11.cpp:597
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 169 of file pns_kicad_iface.cpp.

170 {
171 }

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 190 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().

191 {
192  int net_a = aA->Net();
193  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
194  int net_b = aB->Net();
195  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
196 
197  bool linesOnly = aA->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T )
199 
200  if( linesOnly && net_a >= 0 && net_b >= 0 && m_netClearanceCache[net_a].coupledNet == net_b )
201  {
202  cl_a = cl_b = m_router->Sizes().DiffPairGap() - 2 * PNS_HULL_MARGIN;
203  }
204 
205  int pad_a = localPadClearance( aA );
206  int pad_b = localPadClearance( aB );
207 
208  if( pad_a > 0 )
209  cl_a = pad_a;
210 
211  if( pad_b > 0 )
212  cl_b = pad_b;
213 
214  return std::max( cl_a, cl_b );
215 }
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:132
std::vector< CLEARANCE_ENT > m_netClearanceCache
#define max(a, b)
Definition: auxiliary.h:86
int Net() const
Function Net()
Definition: pns_item.h:179
int PNS_PCBNEW_RULE_RESOLVER::Clearance ( int  aNetCode) const
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 218 of file pns_kicad_iface.cpp.

References m_defaultClearance, and m_netClearanceCache.

219 {
220  if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
221  return m_netClearanceCache[aNetCode].clearance;
222 
223  return m_defaultClearance;
224 }
std::vector< CLEARANCE_ENT > m_netClearanceCache
int PNS_PCBNEW_RULE_RESOLVER::DpCoupledNet ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 295 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(), and UseDpGap().

296 {
297  wxString refName = m_board->FindNet( aNet )->GetNetname();
298  wxString dummy, coupledNetName;
299 
300  if( matchDpSuffix( refName, coupledNetName, dummy ) )
301  {
302  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
303 
304  if( !net )
305  return -1;
306 
307  return net->GetNet();
308  }
309 
310  return -1;
311 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Definition: netinfo.h:227
Class NETINFO_ITEM handles the data for a net.
Definition: 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.
Definition: netinfo.h:235
bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair ( PNS::ITEM aItem,
int &  aNetP,
int &  aNetN 
)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 323 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().

Referenced by UseDpGap().

324 {
325  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
326  return false;
327 
328  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
329  wxString netNameN, netNameCoupled, netNameBase;
330 
331  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
332 
333  if( r == 0 )
334  return false;
335  else if( r == 1 )
336  {
337  netNameN = netNameCoupled;
338  }
339  else
340  {
341  netNameN = netNameP;
342  netNameP = netNameCoupled;
343  }
344 
345 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
346 
347  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
348  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
349 
350  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
351 
352  if( !netInfoP || !netInfoN )
353  return false;
354 
355  aNetP = netInfoP->GetNet();
356  aNetN = netInfoN->GetNet();
357 
358  return true;
359 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Definition: netinfo.h:227
Class NETINFO_ITEM handles the data for a net.
Definition: 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.
Definition: netinfo.h:235
BOARD_CONNECTED_ITEM * Parent() const
Function Parent()
Definition: pns_item.h:159
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 314 of file pns_kicad_iface.cpp.

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

Referenced by UseDpGap().

315 {
316  wxString refName = m_board->FindNet( aNet )->GetNetname();
317  wxString dummy1, dummy2;
318 
319  return matchDpSuffix( refName, dummy1, dummy2 );
320 }
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.
Definition: netinfo.h:235
int PNS_PCBNEW_RULE_RESOLVER::localPadClearance ( const PNS::ITEM aItem) const
private

Definition at line 174 of file pns_kicad_iface.cpp.

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

Referenced by Clearance().

175 {
176  if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
177  return 0;
178 
179  const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
180 
181  auto i = m_localClearanceCache.find( pad );
182 
183  if( i == m_localClearanceCache.end() )
184  return 0;
185 
186  return i->second;
187 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
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
BOARD_CONNECTED_ITEM * Parent() const
Function Parent()
Definition: pns_item.h:159
int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix ( wxString  aNetName,
wxString &  aComplementNet,
wxString &  aBaseDpName 
)
private

Definition at line 237 of file pns_kicad_iface.cpp.

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

238 {
239  int rv = 0;
240 
241  if( aNetName.EndsWith( "+" ) )
242  {
243  aComplementNet = "-";
244  rv = 1;
245  }
246  else if( aNetName.EndsWith( "P" ) )
247  {
248  aComplementNet = "N";
249  rv = 1;
250  }
251  else if( aNetName.EndsWith( "-" ) )
252  {
253  aComplementNet = "+";
254  rv = -1;
255  }
256  else if( aNetName.EndsWith( "N" ) )
257  {
258  aComplementNet = "P";
259  rv = -1;
260  }
261  // Match P followed by 2 digits
262  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
263  {
264  aComplementNet = "N" + aNetName.Right( 2 );
265  rv = 1;
266  }
267  // Match P followed by 1 digit
268  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
269  {
270  aComplementNet = "N" + aNetName.Right( 1 );
271  rv = 1;
272  }
273  // Match N followed by 2 digits
274  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
275  {
276  aComplementNet = "P" + aNetName.Right( 2 );
277  rv = -1;
278  }
279  // Match N followed by 1 digit
280  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
281  {
282  aComplementNet = "P" + aNetName.Right( 1 );
283  rv = -1;
284  }
285  if( rv != 0 )
286  {
287  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
288  aComplementNet = aBaseDpName + aComplementNet;
289  }
290 
291  return rv;
292 }
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 228 of file pns_kicad_iface.cpp.

References m_overrideClearance, m_overrideEnabled, m_overrideNetA, and m_overrideNetB.

229 {
230  m_overrideEnabled = aEnable;
231  m_overrideNetA = aNetA;
232  m_overrideNetB = aNetB;
233  m_overrideClearance = aClearance;
234 }
virtual void PNS_PCBNEW_RULE_RESOLVER::UseDpGap ( bool  aUseDpGap)
inlineoverridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 74 of file pns_kicad_iface.cpp.

References DpCoupledNet(), DpNetPair(), DpNetPolarity(), and m_useDpGap.

74 { m_useDpGap = aUseDpGap; }

Member Data Documentation

int PNS_PCBNEW_RULE_RESOLVER::m_defaultClearance
private

Definition at line 94 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 93 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 92 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 97 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 95 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 96 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 96 of file pns_kicad_iface.cpp.

Referenced by OverrideClearance(), and PNS_PCBNEW_RULE_RESOLVER().

bool PNS_PCBNEW_RULE_RESOLVER::m_useDpGap
private

Definition at line 98 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: