KiCad PCB EDA Suite
PNS::TOPOLOGY Class Reference

#include <pns_topology.h>

Public Types

typedef std::set< JOINT * > JOINT_SET
 

Public Member Functions

 TOPOLOGY (NODE *aNode)
 
 ~TOPOLOGY ()
 
bool SimplifyLine (LINE *aLine)
 
ITEMNearestUnconnectedItem (JOINT *aStart, int *aAnchor=NULL, int aKindMask=ITEM::ANY_T)
 
bool LeadingRatLine (const LINE *aTrack, SHAPE_LINE_CHAIN &aRatLine)
 
const JOINT_SET ConnectedJoints (JOINT *aStart)
 
const ITEM_SET ConnectedItems (JOINT *aStart, int aKindMask=ITEM::ANY_T)
 
const ITEM_SET ConnectedItems (ITEM *aStart, int aKindMask=ITEM::ANY_T)
 
int64_t ShortestConnectionLength (ITEM *aFrom, ITEM *aTo)
 
const ITEM_SET AssembleTrivialPath (ITEM *aStart)
 
const DIFF_PAIR AssembleDiffPair (SEGMENT *aStart)
 
int DpCoupledNet (int aNet)
 
int DpNetPolarity (int aNet)
 
const LINE DpCoupledLine (LINE *aLine)
 
bool AssembleDiffPair (ITEM *aStart, DIFF_PAIR &aPair)
 
const std::set< ITEM * > AssembleCluster (ITEM *aStart, int aLayer)
 

Private Member Functions

bool followTrivialPath (LINE *aLine, bool aLeft, ITEM_SET &aSet, std::set< ITEM * > &aVisited)
 

Private Attributes

NODEm_world
 

Detailed Description

Definition at line 39 of file pns_topology.h.

Member Typedef Documentation

typedef std::set<JOINT*> PNS::TOPOLOGY::JOINT_SET

Definition at line 42 of file pns_topology.h.

Constructor & Destructor Documentation

PNS::TOPOLOGY::TOPOLOGY ( NODE aNode)
inline

Definition at line 44 of file pns_topology.h.

44  :
45  m_world( aNode ) {};
NODE * m_world
Definition: pns_topology.h:71
PNS::TOPOLOGY::~TOPOLOGY ( )
inline

Definition at line 47 of file pns_topology.h.

47 {};

Member Function Documentation

const std::set< ITEM * > PNS::TOPOLOGY::AssembleCluster ( ITEM aStart,
int  aLayer 
)

Definition at line 360 of file pns_topology.cpp.

References PNS::ITEM::ANY_T, m_world, PNS::MK_HEAD, and PNS::NODE::QueryColliding().

Referenced by PNS::SHOVE::onCollidingSolid().

361 {
362  std::set<ITEM*> visited;
363  std::deque<ITEM*> pending;
364 
365  pending.push_back( aStart );
366 
367  while( !pending.empty() )
368  {
369  NODE::OBSTACLES obstacles;
370  ITEM* top = pending.front();
371 
372  pending.pop_front();
373 
374  visited.insert( top );
375 
376  m_world->QueryColliding( top, obstacles, ITEM::ANY_T, -1, false );
377 
378  for( OBSTACLE& obs : obstacles )
379  {
380  if( visited.find( obs.m_item ) == visited.end() && obs.m_item->Layers().Overlaps( aLayer ) && !( obs.m_item->Marker() & MK_HEAD ) )
381  {
382  visited.insert( obs.m_item );
383  pending.push_back( obs.m_item );
384  }
385  }
386  }
387 
388  return visited;
389 }
NODE * m_world
Definition: pns_topology.h:71
std::vector< OBSTACLE > OBSTACLES
Definition: pns_node.h:142
int QueryColliding(const ITEM *aItem, OBSTACLES &aObstacles, int aKindMask=ITEM::ANY_T, int aLimitCount=-1, bool aDifferentNetsOnly=true, int aForceClearance=-1)
Function QueryColliding()
Definition: pns_node.cpp:276
const DIFF_PAIR PNS::TOPOLOGY::AssembleDiffPair ( SEGMENT aStart)
bool PNS::TOPOLOGY::AssembleDiffPair ( ITEM aStart,
DIFF_PAIR aPair 
)

Definition at line 288 of file pns_topology.cpp.

References abs, PNS::NODE::AllItemsInNet(), PNS::SEGMENT::Anchor(), PNS::NODE::AssembleLine(), PNS::commonParallelProjection(), VECTOR2< T >::Cross(), dist, PNS::RULE_RESOLVER::DpCoupledNet(), PNS::RULE_RESOLVER::DpNetPolarity(), VECTOR2< T >::EuclideanNorm(), PNS::NODE::GetRuleResolver(), PNS::ITEM::Layers(), m_world, max, PNS::ITEM::Net(), PNS::SEGMENT::Seg(), PNS::DIFF_PAIR::SetGap(), PNS::ITEM::SetLayers(), PNS::DIFF_PAIR::SetWidth(), and PNS::LINE::Width().

289 {
290  int refNet = aStart->Net();
291  int coupledNet = m_world->GetRuleResolver()->DpCoupledNet( refNet );
292 
293  if( coupledNet < 0 )
294  return false;
295 
296  std::set<ITEM*> coupledItems;
297 
298  m_world->AllItemsInNet( coupledNet, coupledItems );
299 
300  SEGMENT* coupledSeg = NULL, *refSeg;
301  int minDist = std::numeric_limits<int>::max();
302 
303  if( ( refSeg = dyn_cast<SEGMENT*>( aStart ) ) != NULL )
304  {
305  for( ITEM* item : coupledItems )
306  {
307  if( SEGMENT* s = dyn_cast<SEGMENT*>( item ) )
308  {
309  if( s->Layers().Start() == refSeg->Layers().Start() && s->Width() == refSeg->Width() )
310  {
311  int dist = s->Seg().Distance( refSeg->Seg() );
312  bool isParallel = refSeg->Seg().ApproxParallel( s->Seg() );
313  SEG p_clip, n_clip;
314 
315  bool isCoupled = commonParallelProjection( refSeg->Seg(), s->Seg(), p_clip, n_clip );
316 
317  if( isParallel && isCoupled && dist < minDist )
318  {
319  minDist = dist;
320  coupledSeg = s;
321  }
322  }
323  }
324  }
325  }
326  else
327  {
328  return false;
329  }
330 
331  if( !coupledSeg )
332  return false;
333 
334  LINE lp = m_world->AssembleLine( refSeg );
335  LINE ln = m_world->AssembleLine( coupledSeg );
336 
337  if( m_world->GetRuleResolver()->DpNetPolarity( refNet ) < 0 )
338  {
339  std::swap( lp, ln );
340  }
341 
342  int gap = -1;
343 
344  if( refSeg->Seg().ApproxParallel( coupledSeg->Seg() ) )
345  {
346  // Segments are parallel -> compute pair gap
347  const VECTOR2I refDir = refSeg->Anchor( 1 ) - refSeg->Anchor( 0 );
348  const VECTOR2I displacement = refSeg->Anchor( 1 ) - coupledSeg->Anchor( 1 );
349  gap = (int) std::abs( refDir.Cross( displacement ) / refDir.EuclideanNorm() ) - lp.Width();
350  }
351 
352  aPair = DIFF_PAIR( lp, ln );
353  aPair.SetWidth( lp.Width() );
354  aPair.SetLayers( lp.Layers() );
355  aPair.SetGap( gap );
356 
357  return true;
358 }
virtual int DpCoupledNet(int aNet)=0
const LINE AssembleLine(SEGMENT *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:832
void AllItemsInNet(int aNet, std::set< ITEM * > &aItems)
Definition: pns_node.cpp:1232
static const int dist[10][10]
Definition: dist.cpp:57
#define abs(a)
Definition: auxiliary.h:84
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:294
NODE * m_world
Definition: pns_topology.h:71
extended_type Cross(const VECTOR2< T > &aVector) const
Function Cross() computes cross product of self with aVector.
Definition: vector2d.h:479
Definition: seg.h:36
RULE_RESOLVER * GetRuleResolver()
Definition: pns_node.h:168
#define max(a, b)
Definition: auxiliary.h:86
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
virtual int DpNetPolarity(int aNet)=0
bool commonParallelProjection(SEG n, SEG p, SEG &pClip, SEG &nClip)
const ITEM_SET PNS::TOPOLOGY::AssembleTrivialPath ( ITEM aStart)

Definition at line 238 of file pns_topology.cpp.

References PNS::ITEM_SET::Add(), PNS::NODE::AssembleLine(), dyn_cast(), PNS::NODE::FindJoint(), followTrivialPath(), PNS::JOINT::IsNonFanoutVia(), PNS::ITEM_SET::Items(), PNS::JOINT::Links(), m_world, and PNS::VIA::Pos().

Referenced by PNS::TOOL_BASE::deleteTraces(), PNS::MEANDER_SKEW_PLACER::Start(), PNS::MEANDER_PLACER::Start(), and PNS::DP_MEANDER_PLACER::Start().

239 {
240  ITEM_SET path;
241  std::set<ITEM*> visited;
242  SEGMENT* seg;
243  VIA* via;
244 
245  seg = dyn_cast<SEGMENT*> (aStart);
246 
247  if(!seg && (via = dyn_cast<VIA*>( aStart ) ) )
248  {
249  JOINT *jt = m_world->FindJoint( via->Pos(), via );
250 
251  if( !jt->IsNonFanoutVia() )
252  return ITEM_SET();
253 
254  for( auto entry : jt->Links().Items() )
255  if( ( seg = dyn_cast<SEGMENT*>( entry.item ) ) )
256  break;
257  }
258 
259  if( !seg )
260  return ITEM_SET();
261 
262  LINE l = m_world->AssembleLine( seg );
263 
264  path.Add( l );
265 
266  followTrivialPath( &l, false, path, visited );
267  followTrivialPath( &l, true, path, visited );
268 
269  return path;
270 }
bool followTrivialPath(LINE *aLine, bool aLeft, ITEM_SET &aSet, std::set< ITEM * > &aVisited)
const LINE AssembleLine(SEGMENT *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:832
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
NODE * m_world
Definition: pns_topology.h:71
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Function FindJoint()
Definition: pns_node.cpp:966
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
const ITEM_SET PNS::TOPOLOGY::ConnectedItems ( JOINT aStart,
int  aKindMask = ITEM::ANY_T 
)

Definition at line 273 of file pns_topology.cpp.

274 {
275  return ITEM_SET();
276 }
const ITEM_SET PNS::TOPOLOGY::ConnectedItems ( ITEM aStart,
int  aKindMask = ITEM::ANY_T 
)

Definition at line 279 of file pns_topology.cpp.

280 {
281  return ITEM_SET();
282 }
const TOPOLOGY::JOINT_SET PNS::TOPOLOGY::ConnectedJoints ( JOINT aStart)

Definition at line 61 of file pns_topology.cpp.

References SEG::A, SEG::B, PNS::NODE::FindJoint(), PNS::JOINT::LinkList(), m_world, next(), PNS::SEGMENT::Seg(), and PNS::ITEM::SEGMENT_T.

Referenced by NearestUnconnectedItem().

62 {
63  std::deque<JOINT*> searchQueue;
64  JOINT_SET processed;
65 
66  searchQueue.push_back( aStart );
67  processed.insert( aStart );
68 
69  while( !searchQueue.empty() )
70  {
71  JOINT* current = searchQueue.front();
72  searchQueue.pop_front();
73 
74  for( ITEM* item : current->LinkList() )
75  {
76  if( item->OfKind( ITEM::SEGMENT_T ) )
77  {
78  SEGMENT* seg = static_cast<SEGMENT*>( item );
79  JOINT* a = m_world->FindJoint( seg->Seg().A, seg );
80  JOINT* b = m_world->FindJoint( seg->Seg().B, seg );
81  JOINT* next = ( *a == *current ) ? b : a;
82 
83  if( processed.find( next ) == processed.end() )
84  {
85  processed.insert( next );
86  searchQueue.push_back( next );
87  }
88  }
89  }
90  }
91 
92  return processed;
93 }
CITER next(CITER it)
Definition: ptree.cpp:130
NODE * m_world
Definition: pns_topology.h:71
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Function FindJoint()
Definition: pns_node.cpp:966
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
std::set< JOINT * > JOINT_SET
Definition: pns_topology.h:42
const LINE PNS::TOPOLOGY::DpCoupledLine ( LINE aLine)
int PNS::TOPOLOGY::DpCoupledNet ( int  aNet)
int PNS::TOPOLOGY::DpNetPolarity ( int  aNet)
bool PNS::TOPOLOGY::followTrivialPath ( LINE aLine,
bool  aLeft,
ITEM_SET aSet,
std::set< ITEM * > &  aVisited 
)
private

Definition at line 179 of file pns_topology.cpp.

References PNS::ITEM_SET::Add(), PNS::NODE::AssembleLine(), PNS::LINE::CLine(), PNS::LINE::CPoint(), SHAPE_LINE_CHAIN::CPoint(), PNS::NODE::FindJoint(), PNS::LINE::IsLinked(), PNS::JOINT::IsNonFanoutVia(), PNS::JOINT::IsTraceWidthChange(), PNS::ITEM_SET::Items(), PNS::LINE::LinkedSegments(), PNS::JOINT::Links(), m_world, PNS::ITEM_SET::Prepend(), PNS::LINE::Reverse(), and PNS::ITEM::VIA_T.

Referenced by AssembleTrivialPath().

180 {
181  assert( aLine->IsLinked() );
182 
183  VECTOR2I anchor = aLeft ? aLine->CPoint( 0 ) : aLine->CPoint( -1 );
184  SEGMENT* last = aLeft ? aLine->LinkedSegments().front() : aLine->LinkedSegments().back();
185  JOINT* jt = m_world->FindJoint( anchor, aLine );
186 
187  assert( jt != NULL );
188 
189  aVisited.insert( last );
190 
191  if( jt->IsNonFanoutVia() || jt->IsTraceWidthChange() )
192  {
193  ITEM* via = NULL;
194  SEGMENT* next_seg = NULL;
195 
196  for( ITEM* link : jt->Links().Items() )
197  {
198  if( link->OfKind( ITEM::VIA_T ) )
199  via = link;
200  else if( aVisited.find( link ) == aVisited.end() )
201  next_seg = static_cast<SEGMENT*>( link );
202  }
203 
204  if( !next_seg )
205  return false;
206 
207  LINE l = m_world->AssembleLine( next_seg );
208 
209  VECTOR2I nextAnchor = ( aLeft ? l.CLine().CPoint( -1 ) : l.CLine().CPoint( 0 ) );
210 
211  if( nextAnchor != anchor )
212  {
213  l.Reverse();
214  }
215 
216  if( aLeft )
217  {
218  if( via )
219  aSet.Prepend( via );
220 
221  aSet.Prepend( l );
222  }
223  else
224  {
225  if( via )
226  aSet.Add( via );
227 
228  aSet.Add( l );
229  }
230 
231  return followTrivialPath( &l, aLeft, aSet, aVisited );
232  }
233 
234  return false;
235 }
bool followTrivialPath(LINE *aLine, bool aLeft, ITEM_SET &aSet, std::set< ITEM * > &aVisited)
const LINE AssembleLine(SEGMENT *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:832
NODE * m_world
Definition: pns_topology.h:71
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Function FindJoint()
Definition: pns_node.cpp:966
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
bool PNS::TOPOLOGY::LeadingRatLine ( const LINE aTrack,
SHAPE_LINE_CHAIN aRatLine 
)

Definition at line 96 of file pns_topology.cpp.

References SHAPE_LINE_CHAIN::Append(), PNS::NODE::Branch(), SHAPE_LINE_CHAIN::Clear(), PNS::LINE::CPoint(), PNS::LINE::EndsWithVia(), PNS::JOINT::LinkCount(), m_world, PNS::LINE::PointCount(), and PNS::JOINT::Pos().

Referenced by PNS::DIFF_PAIR_PLACER::updateLeadingRatLine(), and PNS::LINE_PLACER::updateLeadingRatLine().

97 {
98  LINE track( *aTrack );
99  VECTOR2I end;
100 
101  if( !track.PointCount() )
102  return false;
103 
104  std::unique_ptr<NODE> tmpNode( m_world->Branch() );
105  tmpNode->Add( track );
106 
107  JOINT* jt = tmpNode->FindJoint( track.CPoint( -1 ), &track );
108 
109  if( !jt )
110  return false;
111 
112  if( ( !track.EndsWithVia() && jt->LinkCount() >= 2 ) || ( track.EndsWithVia() && jt->LinkCount() >= 3 ) ) // we got something connected
113  {
114  end = jt->Pos();
115  }
116  else
117  {
118  int anchor;
119 
120  TOPOLOGY topo( tmpNode.get() );
121  ITEM* it = topo.NearestUnconnectedItem( jt, &anchor );
122 
123  if( !it )
124  return false;
125 
126  end = it->Anchor( anchor );
127  }
128 
129  aRatLine.Clear();
130  aRatLine.Append( track.CPoint( -1 ) );
131  aRatLine.Append( end );
132  return true;
133 }
TOPOLOGY(NODE *aNode)
Definition: pns_topology.h:44
NODE * Branch()
Function Branch()
Definition: pns_node.cpp:107
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
NODE * m_world
Definition: pns_topology.h:71
void Clear()
Function Clear() Removes all points from the line chain.
ITEM * PNS::TOPOLOGY::NearestUnconnectedItem ( JOINT aStart,
int *  aAnchor = NULL,
int  aKindMask = ITEM::ANY_T 
)

Definition at line 136 of file pns_topology.cpp.

References PNS::NODE::AllItemsInNet(), ConnectedJoints(), EuclideanNorm(), m_world, PNS::JOINT::Net(), and PNS::JOINT::Pos().

137 {
138  std::set<ITEM*> disconnected;
139 
140  m_world->AllItemsInNet( aStart->Net(), disconnected );
141 
142  for( const JOINT* jt : ConnectedJoints( aStart ) )
143  {
144  for( ITEM* link : jt->LinkList() )
145  {
146  if( disconnected.find( link ) != disconnected.end() )
147  disconnected.erase( link );
148  }
149  }
150 
151  int best_dist = INT_MAX;
152  ITEM* best = NULL;
153 
154  for( ITEM* item : disconnected )
155  {
156  if( item->OfKind( aKindMask ) )
157  {
158  for( int i = 0; i < item->AnchorCount(); i++ )
159  {
160  VECTOR2I p = item->Anchor( i );
161  int d = ( p - aStart->Pos() ).EuclideanNorm();
162 
163  if( d < best_dist )
164  {
165  best_dist = d;
166  best = item;
167 
168  if( aAnchor )
169  *aAnchor = i;
170  }
171  }
172  }
173  }
174 
175  return best;
176 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
const JOINT_SET ConnectedJoints(JOINT *aStart)
void AllItemsInNet(int aNet, std::set< ITEM * > &aItems)
Definition: pns_node.cpp:1232
NODE * m_world
Definition: pns_topology.h:71
int64_t PNS::TOPOLOGY::ShortestConnectionLength ( ITEM aFrom,
ITEM aTo 
)
bool PNS::TOPOLOGY::SimplifyLine ( LINE aLine)

Definition at line 37 of file pns_topology.cpp.

References PNS::NODE::Add(), PNS::NODE::AssembleLine(), PNS::LINE::CLine(), PNS::LINE::GetLink(), PNS::LINE::IsLinked(), m_world, PNS::LINE::PointCount(), PNS::NODE::Remove(), PNS::LINE::SegmentCount(), PNS::LINE::SetShape(), and SHAPE_LINE_CHAIN::Simplify().

Referenced by PNS::DIFF_PAIR_PLACER::FixRoute().

38 {
39  if( !aLine->IsLinked() || !aLine->SegmentCount() )
40  return false;
41 
42  SEGMENT* root = aLine->GetLink(0);
43  LINE l = m_world->AssembleLine( root );
44  SHAPE_LINE_CHAIN simplified( l.CLine() );
45 
46  simplified.Simplify();
47 
48  if( simplified.PointCount() != l.PointCount() )
49  {
50  m_world->Remove( l );
51  LINE lnew( l );
52  lnew.SetShape( simplified );
53  m_world->Add( lnew );
54  return true;
55  }
56 
57  return false;
58 }
const LINE AssembleLine(SEGMENT *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:832
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
NODE * m_world
Definition: pns_topology.h:71
void Remove(SOLID *aSolid)
Function Remove()
Definition: pns_node.cpp:727
Class SHAPE_LINE_CHAIN.
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
void Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:594

Member Data Documentation


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