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

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->Pads(); 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  //printf("DefaultCL : %d\n", m_board->GetDesignSettings().m_NetClasses.Find ("Default clearance")->GetClearance());
150 
151  m_overrideEnabled = false;
152  m_defaultClearance = Millimeter2iu( 0.254 ); // m_board->m_NetClasses.Find ("Default clearance")->GetClearance();
153  m_overrideNetA = 0;
154  m_overrideNetB = 0;
156  m_useDpGap = false;
157 }
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Class NODE.
Definition: pns_node.h:137
NODE * GetWorld() const
Definition: pns_router.h:134
virtual int DpCoupledNet(int aNet) override
std::vector< CLEARANCE_ENT > m_netClearanceCache
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
Class NETINFO_ITEM handles the data for a net.
const wxString & GetClassName() const
Function GetClassName returns the class name.
DLIST< MODULE > m_Modules
Definition: class_board.h:243
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:814
PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER ( )
virtual

Definition at line 160 of file pns_kicad_iface.cpp.

161 {
162 }

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

182 {
183  int net_a = aA->Net();
184  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
185  int net_b = aB->Net();
186  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
187 
188  bool linesOnly = aA->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T )
190 
191  if( linesOnly && net_a >= 0 && net_b >= 0 && m_netClearanceCache[net_a].coupledNet == net_b )
192  {
193  cl_a = cl_b = m_router->Sizes().DiffPairGap() - 2 * PNS_HULL_MARGIN;
194  }
195 
196  int pad_a = localPadClearance( aA );
197  int pad_b = localPadClearance( aB );
198 
199  if( pad_a > 0 )
200  cl_a = pad_a;
201 
202  if( pad_b > 0 )
203  cl_b = pad_b;
204 
205  return std::max( cl_a, cl_b );
206 }
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:197
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 209 of file pns_kicad_iface.cpp.

References m_defaultClearance, and m_netClearanceCache.

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

Implements PNS::RULE_RESOLVER.

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

264 {
265  wxString refName = m_board->FindNet( aNet )->GetNetname();
266  wxString dummy, coupledNetName;
267 
268  if( matchDpSuffix( refName, coupledNetName, dummy ) )
269  {
270  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
271 
272  if( !net )
273  return -1;
274 
275  return net->GetNet();
276  }
277 
278  return -1;
279 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Class NETINFO_ITEM handles the data for a net.
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 291 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().

292 {
293  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
294  return false;
295 
296  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
297  wxString netNameN, netNameCoupled, netNameBase;
298 
299  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
300 
301  if( r == 0 )
302  return false;
303  else if( r == 1 )
304  {
305  netNameN = netNameCoupled;
306  }
307  else
308  {
309  netNameN = netNameP;
310  netNameP = netNameCoupled;
311  }
312 
313 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
314 
315  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
316  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
317 
318  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
319 
320  if( !netInfoP || !netInfoN )
321  return false;
322 
323  aNetP = netInfoP->GetNet();
324  aNetN = netInfoN->GetNet();
325 
326  return true;
327 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Class NETINFO_ITEM handles the data for a net.
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 282 of file pns_kicad_iface.cpp.

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

283 {
284  wxString refName = m_board->FindNet( aNet )->GetNetname();
285  wxString dummy1, dummy2;
286 
287  return matchDpSuffix( refName, dummy1, dummy2 );
288 }
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 165 of file pns_kicad_iface.cpp.

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

Referenced by Clearance().

166 {
167  if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
168  return 0;
169 
170  const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
171 
172  auto i = m_localClearanceCache.find( pad );
173 
174  if( i == m_localClearanceCache.end() )
175  return 0;
176 
177  return i->second;
178 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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 228 of file pns_kicad_iface.cpp.

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

229 {
230  int rv = 0;
231 
232  if( aNetName.EndsWith( "+" ) )
233  {
234  aComplementNet = "-";
235  rv = 1;
236  }
237  else if( aNetName.EndsWith( "_P" ) )
238  {
239  aComplementNet = "_N";
240  rv = 1;
241  }
242  else if( aNetName.EndsWith( "-" ) )
243  {
244  aComplementNet = "+";
245  rv = -1;
246  }
247  else if( aNetName.EndsWith( "_N" ) )
248  {
249  aComplementNet = "_P";
250  rv = -1;
251  }
252 
253  if( rv != 0 )
254  {
255  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
256  aComplementNet = aBaseDpName + aComplementNet;
257  }
258 
259  return rv;
260 }
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 219 of file pns_kicad_iface.cpp.

References m_overrideClearance, m_overrideEnabled, m_overrideNetA, and m_overrideNetB.

220 {
221  m_overrideEnabled = aEnable;
222  m_overrideNetA = aNetA;
223  m_overrideNetB = aNetB;
224  m_overrideClearance = aClearance;
225 }
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 m_useDpGap.

74 { 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 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().

PNS::ROUTER* PNS_PCBNEW_RULE_RESOLVER::m_router
private

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