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 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 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
 

Detailed Description

Definition at line 69 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, 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::m_Modules, BOARD_DESIGN_SETTINGS::m_NetClasses, m_netClearanceCache, m_router, 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  ent.dpClearance = nc->GetDiffPairGap();
128  m_netClearanceCache[i] = ent;
129 
130  wxLogTrace( "PNS", "Add net %u netclass %s clearance %d Diff Pair clearance %d",
131  i, netClassName.mb_str(), clearance, ent.dpClearance );
132  }
133 
134  // Build clearance cache for pads
135  for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() )
136  {
137  auto moduleClearance = mod->GetLocalClearance();
138 
139  for( D_PAD* pad = mod->PadsList(); pad; pad = pad->Next() )
140  {
141  int padClearance = pad->GetLocalClearance();
142 
143  if( padClearance > 0 )
144  m_localClearanceCache[ pad ] = padClearance;
145 
146  else if( moduleClearance > 0 )
147  m_localClearanceCache[ pad ] = moduleClearance;
148  }
149  }
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 }
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:146
Class NODE.
Definition: pns_node.h:136
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:135
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:538
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
DLIST< MODULE > m_Modules
Definition: class_board.h:248
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
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:779
PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER ( )
virtual

Definition at line 164 of file pns_kicad_iface.cpp.

165 {
166 }

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

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

186 {
187  int net_a = aA->Net();
188  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
189  int net_b = aB->Net();
190  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
191 
192  // Pad clearance is 0 if the ITEM* is not a pad
193  int pad_a = localPadClearance( aA );
194  int pad_b = localPadClearance( aB );
195 
196  if( pad_a > 0 )
197  cl_a = pad_a;
198 
199  if( pad_b > 0 )
200  cl_b = pad_b;
201 
202  return std::max( cl_a, cl_b );
203 }
int localPadClearance(const PNS::ITEM *aItem) const
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 206 of file pns_kicad_iface.cpp.

References m_defaultClearance, and m_netClearanceCache.

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

Implements PNS::RULE_RESOLVER.

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

274 {
275  wxString refName = m_board->FindNet( aNet )->GetNetname();
276  wxString dummy, coupledNetName;
277 
278  if( matchDpSuffix( refName, coupledNetName, dummy ) )
279  {
280  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
281 
282  if( !net )
283  return -1;
284 
285  return net->GetNet();
286  }
287 
288  return -1;
289 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
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:239
bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair ( PNS::ITEM aItem,
int &  aNetP,
int &  aNetN 
)
overridevirtual

Implements PNS::RULE_RESOLVER.

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

308 {
309  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
310  return false;
311 
312  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
313  wxString netNameN, netNameCoupled, netNameBase;
314 
315  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
316 
317  if( r == 0 )
318  return false;
319  else if( r == 1 )
320  {
321  netNameN = netNameCoupled;
322  }
323  else
324  {
325  netNameN = netNameP;
326  netNameP = netNameCoupled;
327  }
328 
329 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
330 
331  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
332  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
333 
334  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
335 
336  if( !netInfoP || !netInfoN )
337  return false;
338 
339  aNetP = netInfoP->GetNet();
340  aNetN = netInfoN->GetNet();
341 
342  return true;
343 }
int matchDpSuffix(wxString aNetName, wxString &aComplementNet, wxString &aBaseDpName)
int GetNet() const
Function GetNet.
Definition: netinfo.h:231
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:239
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 298 of file pns_kicad_iface.cpp.

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

299 {
300  wxString refName = m_board->FindNet( aNet )->GetNetname();
301  wxString dummy1, dummy2;
302 
303  return matchDpSuffix( refName, dummy1, dummy2 );
304 }
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:239
int PNS_PCBNEW_RULE_RESOLVER::localPadClearance ( const PNS::ITEM aItem) const
private

Definition at line 169 of file pns_kicad_iface.cpp.

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

Referenced by Clearance().

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

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

216 {
217  int rv = 0;
218 
219  if( aNetName.EndsWith( "+" ) )
220  {
221  aComplementNet = "-";
222  rv = 1;
223  }
224  else if( aNetName.EndsWith( "P" ) )
225  {
226  aComplementNet = "N";
227  rv = 1;
228  }
229  else if( aNetName.EndsWith( "-" ) )
230  {
231  aComplementNet = "+";
232  rv = -1;
233  }
234  else if( aNetName.EndsWith( "N" ) )
235  {
236  aComplementNet = "P";
237  rv = -1;
238  }
239  // Match P followed by 2 digits
240  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
241  {
242  aComplementNet = "N" + aNetName.Right( 2 );
243  rv = 1;
244  }
245  // Match P followed by 1 digit
246  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
247  {
248  aComplementNet = "N" + aNetName.Right( 1 );
249  rv = 1;
250  }
251  // Match N followed by 2 digits
252  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
253  {
254  aComplementNet = "P" + aNetName.Right( 2 );
255  rv = -1;
256  }
257  // Match N followed by 1 digit
258  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
259  {
260  aComplementNet = "P" + aNetName.Right( 1 );
261  rv = -1;
262  }
263  if( rv != 0 )
264  {
265  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
266  aComplementNet = aBaseDpName + aComplementNet;
267  }
268 
269  return rv;
270 }
wxString PNS_PCBNEW_RULE_RESOLVER::NetName ( int  aNet)
overridevirtual

Implements PNS::RULE_RESOLVER.

Definition at line 292 of file pns_kicad_iface.cpp.

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

293 {
294  return m_board->FindNet( aNet )->GetNetname();
295 }
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:239

Member Data Documentation

int PNS_PCBNEW_RULE_RESOLVER::m_defaultClearance
private

Definition at line 98 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 97 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 96 of file pns_kicad_iface.cpp.

Referenced by Clearance(), and PNS_PCBNEW_RULE_RESOLVER().

PNS::ROUTER* PNS_PCBNEW_RULE_RESOLVER::m_router
private

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