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 66 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 99 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().

99  :
100  m_router( aRouter ),
101  m_board( aBoard )
102 {
103  PNS::NODE* world = m_router->GetWorld();
104 
105  PNS::TOPOLOGY topo( world );
107 
108  // Build clearance cache for net classes
109  for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
110  {
111  NETINFO_ITEM* ni = m_board->FindNet( i );
112 
113  if( ni == NULL )
114  continue;
115 
116  CLEARANCE_ENT ent;
117  ent.coupledNet = DpCoupledNet( i );
118 
119  wxString netClassName = ni->GetClassName();
120  NETCLASSPTR nc = m_board->GetDesignSettings().m_NetClasses.Find( netClassName );
121 
122  int clearance = nc->GetClearance();
123  ent.clearance = clearance;
124  ent.dpClearance = nc->GetDiffPairGap();
125  m_netClearanceCache[i] = ent;
126 
127  wxLogTrace( "PNS", "Add net %u netclass %s clearance %d Diff Pair clearance %d",
128  i, netClassName.mb_str(), clearance, ent.dpClearance );
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  auto defaultRule = m_board->GetDesignSettings().m_NetClasses.Find ("Default");
149 
150  if( defaultRule )
151  {
152  m_defaultClearance = defaultRule->GetClearance();
153  }
154  else
155  {
156  m_defaultClearance = Millimeter2iu(0.254);
157  }
158 }
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:136
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:535
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
DLIST< MODULE > m_Modules
Definition: class_board.h:247
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:776
PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER ( )
virtual

Definition at line 161 of file pns_kicad_iface.cpp.

162 {
163 }

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

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

183 {
184  int net_a = aA->Net();
185  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
186  int net_b = aB->Net();
187  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
188 
189  // Clearance in differential pairs can only happen when there is a specific net
190  if( net_a >= 0 && net_b >= 0 && m_netClearanceCache[net_a].coupledNet == net_b )
191  {
192  cl_a = m_netClearanceCache[net_a].dpClearance;
193  cl_b = m_netClearanceCache[net_b].dpClearance;
194  }
195 
196  // Pad clearance is 0 if the ITEM* is not a pad
197  int pad_a = localPadClearance( aA );
198  int pad_b = localPadClearance( aB );
199 
200  if( pad_a > 0 )
201  cl_a = pad_a;
202 
203  if( pad_b > 0 )
204  cl_b = pad_b;
205 
206  return std::max( cl_a, cl_b );
207 }
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 210 of file pns_kicad_iface.cpp.

References m_defaultClearance, and m_netClearanceCache.

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

Implements PNS::RULE_RESOLVER.

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

278 {
279  wxString refName = m_board->FindNet( aNet )->GetNetname();
280  wxString dummy, coupledNetName;
281 
282  if( matchDpSuffix( refName, coupledNetName, dummy ) )
283  {
284  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
285 
286  if( !net )
287  return -1;
288 
289  return net->GetNet();
290  }
291 
292  return -1;
293 }
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 311 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().

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

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

303 {
304  wxString refName = m_board->FindNet( aNet )->GetNetname();
305  wxString dummy1, dummy2;
306 
307  return matchDpSuffix( refName, dummy1, dummy2 );
308 }
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 166 of file pns_kicad_iface.cpp.

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

Referenced by Clearance().

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

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

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

Implements PNS::RULE_RESOLVER.

Definition at line 296 of file pns_kicad_iface.cpp.

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

297 {
298  return m_board->FindNet( aNet )->GetNetname();
299 }
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

Member Data Documentation

int PNS_PCBNEW_RULE_RESOLVER::m_defaultClearance
private

Definition at line 95 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 94 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 93 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: