KiCad PCB EDA Suite
PNS::DIFF_PAIR_PLACER Class Reference

LINE_PLACER. More...

#include <pns_diff_pair_placer.h>

Inheritance diagram for PNS::DIFF_PAIR_PLACER:
PNS::PLACEMENT_ALGO PNS::ALGO_BASE

Public Member Functions

 DIFF_PAIR_PLACER (ROUTER *aRouter)
 
 ~DIFF_PAIR_PLACER ()
 
bool Start (const VECTOR2I &aP, ITEM *aStartItem) override
 Function Start() More...
 
bool Move (const VECTOR2I &aP, ITEM *aEndItem) override
 Function Move() More...
 
bool FixRoute (const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
 Function FixRoute() More...
 
bool CommitPlacement () override
 
bool AbortPlacement () override
 
bool HasPlacedAnything () const override
 
bool ToggleVia (bool aEnabled) override
 Function ToggleVia() More...
 
bool SetLayer (int aLayer) override
 Function SetLayer() More...
 
const ITEM_SET Traces () override
 Function Traces() More...
 
const VECTOR2ICurrentEnd () const override
 Function CurrentEnd() More...
 
const std::vector< int > CurrentNets () const override
 Function CurrentNets() More...
 
int CurrentLayer () const override
 Function CurrentLayer() More...
 
NODECurrentNode (bool aLoopsRemoved=false) const override
 Function CurrentNode() More...
 
void FlipPosture () override
 Function FlipPosture() More...
 
void UpdateSizes (const SIZES_SETTINGS &aSizes) override
 Function UpdateSizes() More...
 
bool IsPlacingVia () const override
 Function IsPlacingVia() More...
 
void SetOrthoMode (bool aOrthoMode) override
 Function SetOrthoMode() More...
 
void GetModifiedNets (std::vector< int > &aNets) const override
 Function GetModifiedNets. More...
 
virtual bool UnfixRoute ()
 
ROUTERRouter () const
 

Returns the instance of our router

More...
 
ROUTING_SETTINGSSettings () const
 

Returns current router settings

More...
 
virtual LOGGERLogger ()
 

Returns the logger object, allowing to dump geometry to a file.

More...
 
void SetLogger (LOGGER *aLogger)
 
void SetDebugDecorator (DEBUG_DECORATOR *aDecorator)
 Function SetDebugDecorator. More...
 
DEBUG_DECORATORDbg () const
 

Protected Attributes

DEBUG_DECORATORm_debugDecorator
 
ROUTERm_router
 
LOGGERm_logger
 

Private Types

enum  State { RT_START = 0, RT_ROUTE = 1, RT_FINISH = 2 }
 

Private Member Functions

int viaGap () const
 
int gap () const
 
bool route (const VECTOR2I &aP)
 Function route() More...
 
void updateLeadingRatLine ()
 Function updateLeadingRatLine() More...
 
void setWorld (NODE *aWorld)
 Function setWorld() More...
 
void initPlacement ()
 Function startPlacement() More...
 
void setInitialDirection (const DIRECTION_45 &aDirection)
 Function setInitialDirection() More...
 
bool routeHead (const VECTOR2I &aP)
 
bool tryWalkDp (NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)
 
bool rhWalkOnly (const VECTOR2I &aP)
 

route step, walkaround mode

More...
 
bool rhShoveOnly (const VECTOR2I &aP)
 

route step, shove mode

More...
 
bool rhMarkObstacles (const VECTOR2I &aP)
 

route step, mark obstacles mode

More...
 
const VIA makeVia (const VECTOR2I &aP, int aNet)
 
bool findDpPrimitivePair (const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
 
OPT_VECTOR2I getDanglingAnchor (NODE *aNode, ITEM *aItem)
 
bool attemptWalk (NODE *aNode, DIFF_PAIR *aCurrent, DIFF_PAIR &aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly)
 
bool propagateDpHeadForces (const VECTOR2I &aP, VECTOR2I &aNewP)
 

Private Attributes

State m_state
 
bool m_chainedPlacement
 
bool m_initialDiagonal
 
bool m_startDiagonal
 
bool m_fitOk
 
int m_netP
 
int m_netN
 
DP_PRIMITIVE_PAIR m_start
 
OPT< DP_PRIMITIVE_PAIRm_prevPair
 
int m_iteration
 

current algorithm iteration

More...
 
NODEm_world
 

pointer to world to search colliding items

More...
 
VECTOR2I m_p_start
 

current routing start point (end of tail, beginning of head)

More...
 
SHOVEm_shove
 

The shove engine

More...
 
NODEm_currentNode
 

Current world state

More...
 
NODEm_lastNode
 

Postprocessed world state (including marked collisions & removed loops)

More...
 
SIZES_SETTINGS m_sizes
 
bool m_placingVia
 

Are we placing a via?

More...
 
int m_viaDiameter
 

current via diameter

More...
 
int m_viaDrill
 

current via drill

More...
 
int m_currentWidth
 

current track width

More...
 
int m_currentNet
 
int m_currentLayer
 
bool m_startsOnVia
 
bool m_orthoMode
 
bool m_snapOnTarget
 
VECTOR2I m_currentEnd
 
VECTOR2I m_currentStart
 
DIFF_PAIR m_currentTrace
 
ITEMm_currentEndItem
 
PNS_MODE m_currentMode
 
bool m_idle
 

Detailed Description

LINE_PLACER.

Single track placement algorithm. Interactively routes a track. Applies shove and walkaround algorithms when needed.

Definition at line 55 of file pns_diff_pair_placer.h.

Member Enumeration Documentation

◆ State

Enumerator
RT_START 
RT_ROUTE 
RT_FINISH 

Definition at line 243 of file pns_diff_pair_placer.h.

Constructor & Destructor Documentation

◆ DIFF_PAIR_PLACER()

PNS::DIFF_PAIR_PLACER::DIFF_PAIR_PLACER ( ROUTER aRouter)

Definition at line 38 of file pns_diff_pair_placer.cpp.

38  :
39  PLACEMENT_ALGO( aRouter )
40 {
41  m_state = RT_START;
42  m_chainedPlacement = false;
43  m_initialDiagonal = false;
44  m_startDiagonal = false;
45  m_fitOk = false;
46  m_netP = 0;
47  m_netN = 0;
48  m_iteration = 0;
49  m_world = NULL;
50  m_shove = NULL;
52  m_lastNode = NULL;
53  m_placingVia = false;
54  m_viaDiameter = 0;
55  m_viaDrill = 0;
56  m_currentWidth = 0;
57  m_currentNet = 0;
58  m_currentLayer = 0;
59  m_startsOnVia = false;
60  m_orthoMode = false;
61  m_snapOnTarget = false;
64  m_idle = true;
65 }
int m_iteration
current algorithm iteration
SHOVE * m_shove
The shove engine
int m_viaDiameter
current via diameter
NODE * m_world
pointer to world to search colliding items
int m_viaDrill
current via drill
#define NULL
bool m_placingVia
Are we placing a via?
NODE * m_currentNode
Current world state
PLACEMENT_ALGO(ROUTER *aRouter)
int m_currentWidth
current track width
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References m_chainedPlacement, m_currentEndItem, m_currentLayer, m_currentMode, m_currentNet, m_currentNode, m_currentWidth, m_fitOk, m_idle, m_initialDiagonal, m_iteration, m_lastNode, m_netN, m_netP, m_orthoMode, m_placingVia, m_shove, m_snapOnTarget, m_startDiagonal, m_startsOnVia, m_state, m_viaDiameter, m_viaDrill, m_world, NULL, PNS::RM_MarkObstacles, and RT_START.

◆ ~DIFF_PAIR_PLACER()

PNS::DIFF_PAIR_PLACER::~DIFF_PAIR_PLACER ( )

Definition at line 67 of file pns_diff_pair_placer.cpp.

68 {
69  if( m_shove )
70  delete m_shove;
71 }
SHOVE * m_shove
The shove engine

References m_shove.

Member Function Documentation

◆ AbortPlacement()

bool PNS::DIFF_PAIR_PLACER::AbortPlacement ( )
overridevirtual

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 813 of file pns_diff_pair_placer.cpp.

814 {
816  return true;
817 }
NODE * m_world
pointer to world to search colliding items
void KillChildren()
Destroys all child nodes. Applicable only to the root node.
Definition: pns_node.cpp:1288

References PNS::NODE::KillChildren(), and m_world.

◆ attemptWalk()

bool PNS::DIFF_PAIR_PLACER::attemptWalk ( NODE aNode,
DIFF_PAIR aCurrent,
DIFF_PAIR aWalk,
bool  aPFirst,
bool  aWindCw,
bool  aSolidsOnly 
)
private

Definition at line 161 of file pns_diff_pair_placer.cpp.

163 {
164  WALKAROUND walkaround( aNode, Router() );
166 
167  walkaround.SetSolidsOnly( aSolidsOnly );
168  walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
169 
170  SHOVE shove( aNode, Router() );
171  LINE walkP, walkN;
172 
173  aWalk = *aCurrent;
174 
175  int iter = 0;
176 
177  DIFF_PAIR cur( *aCurrent );
178 
179  bool currentIsP = aPFirst;
180 
181  int mask = aSolidsOnly ? ITEM::SOLID_T : ITEM::ANY_T;
182 
183  do
184  {
185  LINE preWalk = ( currentIsP ? cur.PLine() : cur.NLine() );
186  LINE preShove = ( currentIsP ? cur.NLine() : cur.PLine() );
187  LINE postWalk;
188 
189  if( !aNode->CheckColliding ( &preWalk, mask ) )
190  {
191  currentIsP = !currentIsP;
192 
193  if( !aNode->CheckColliding( &preShove, mask ) )
194  break;
195  else
196  continue;
197  }
198 
199  wf1 = walkaround.Route( preWalk, postWalk, false );
200 
201  if( wf1 != WALKAROUND::DONE )
202  return false;
203 
204  LINE postShove( preShove );
205 
206  shove.ForceClearance( true, cur.Gap() - 2 * PNS_HULL_MARGIN );
207 
209 
210  sh1 = shove.ProcessSingleLine( postWalk, preShove, postShove );
211 
212  if( sh1 != SHOVE::SH_OK )
213  return false;
214 
215  postWalk.Line().Simplify();
216  postShove.Line().Simplify();
217 
218  cur.SetShape( postWalk.CLine(), postShove.CLine(), !currentIsP );
219 
220  currentIsP = !currentIsP;
221 
222  if( !aNode->CheckColliding( &postShove, mask ) )
223  break;
224 
225  iter++;
226  }
227  while( iter < 3 );
228 
229  if( iter == 3 )
230  return false;
231 
232  aWalk.SetShape( cur.CP(), cur.CN() );
233 
234  return true;
235 }
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
#define PNS_HULL_MARGIN
LINE.
Definition: pns_line.h:59
ROUTING_SETTINGS & Settings() const
Returns current router settings

References PNS::ITEM::ANY_T, PNS::NODE::CheckColliding(), PNS::LINE::CLine(), PNS::DIFF_PAIR::CN(), PNS::DIFF_PAIR::CP(), PNS::WALKAROUND::DONE, PNS::SHOVE::ForceClearance(), PNS::DIFF_PAIR::Gap(), PNS::LINE::Line(), PNS::DIFF_PAIR::NLine(), PNS::DIFF_PAIR::PLine(), PNS_HULL_MARGIN, PNS::SHOVE::ProcessSingleLine(), PNS::WALKAROUND::Route(), PNS::ALGO_BASE::Router(), PNS::WALKAROUND::SetIterationLimit(), PNS::DIFF_PAIR::SetShape(), PNS::WALKAROUND::SetSolidsOnly(), PNS::ALGO_BASE::Settings(), PNS::SHOVE::SH_OK, SHAPE_LINE_CHAIN::Simplify(), and PNS::ITEM::SOLID_T.

Referenced by tryWalkDp().

◆ CommitPlacement()

bool PNS::DIFF_PAIR_PLACER::CommitPlacement ( )
overridevirtual

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 827 of file pns_diff_pair_placer.cpp.

828 {
829  if( m_lastNode )
831 
832  m_lastNode = NULL;
834  return true;
835 }
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
void CommitRouting()
Definition: pns_router.cpp:422
#define NULL
NODE * m_currentNode
Current world state
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References PNS::ROUTER::CommitRouting(), m_currentNode, m_lastNode, NULL, and PNS::ALGO_BASE::Router().

Referenced by FixRoute().

◆ CurrentEnd()

const VECTOR2I& PNS::DIFF_PAIR_PLACER::CurrentEnd ( ) const
inlineoverridevirtual

Function CurrentEnd()

Returns the current end of the line being placed. It may not be equal to the cursor position due to collisions.

Implements PNS::PLACEMENT_ALGO.

Definition at line 125 of file pns_diff_pair_placer.h.

126  {
127  return m_currentEnd;
128  }

References m_currentEnd.

◆ CurrentLayer()

int PNS::DIFF_PAIR_PLACER::CurrentLayer ( ) const
inlineoverridevirtual

Function CurrentLayer()

Returns the layer of currently routed track.

Implements PNS::PLACEMENT_ALGO.

Definition at line 142 of file pns_diff_pair_placer.h.

143  {
144  return m_currentLayer;
145  }

References m_currentLayer.

◆ CurrentNets()

const std::vector< int > PNS::DIFF_PAIR_PLACER::CurrentNets ( ) const
overridevirtual

Function CurrentNets()

Returns the net code of currently routed track.

Implements PNS::PLACEMENT_ALGO.

Definition at line 862 of file pns_diff_pair_placer.cpp.

863 {
864  std::vector<int> rv;
865  rv.push_back( m_netP );
866  rv.push_back( m_netN );
867  return rv;
868 }

References m_netN, and m_netP.

◆ CurrentNode()

NODE * PNS::DIFF_PAIR_PLACER::CurrentNode ( bool  aLoopsRemoved = false) const
overridevirtual

Function CurrentNode()

Returns the most recent world state.

Implements PNS::PLACEMENT_ALGO.

Definition at line 372 of file pns_diff_pair_placer.cpp.

373 {
374  if( m_lastNode )
375  return m_lastNode;
376 
377  return m_currentNode;
378 }
NODE * m_currentNode
Current world state
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References m_currentNode, and m_lastNode.

◆ Dbg()

◆ findDpPrimitivePair()

bool PNS::DIFF_PAIR_PLACER::findDpPrimitivePair ( const VECTOR2I aP,
ITEM aItem,
DP_PRIMITIVE_PAIR aPair,
wxString *  aErrorMsg = nullptr 
)
private

Definition at line 438 of file pns_diff_pair_placer.cpp.

440 {
441  int netP, netN;
442 
443  wxLogTrace( "PNS", "world %p", m_world );
444 
445  bool result = m_world->GetRuleResolver()->DpNetPair( aItem, netP, netN );
446 
447  if( !result )
448  {
449  if( aErrorMsg )
450  {
451  *aErrorMsg = _( "Unable to find complementary differential pair "
452  "nets. Make sure the names of the nets belonging "
453  "to a differential pair end with either _N/_P or +/-." );
454  }
455  return false;
456  }
457 
458  int refNet = aItem->Net();
459  int coupledNet = ( refNet == netP ) ? netN : netP;
460 
461  wxLogTrace( "PNS", "result %d", !!result );
462 
463  OPT_VECTOR2I refAnchor = getDanglingAnchor( m_currentNode, aItem );
464  ITEM* primRef = aItem;
465 
466  wxLogTrace( "PNS", "refAnchor %p", aItem );
467 
468  if( !refAnchor )
469  {
470  if( aErrorMsg )
471  {
472  *aErrorMsg = _( "Can't find a suitable starting point. If starting "
473  "from an existing differential pair make sure you are "
474  "at the end." );
475  }
476  return false;
477  }
478 
479  std::set<ITEM*> coupledItems;
480 
481  m_currentNode->AllItemsInNet( coupledNet, coupledItems );
482  double bestDist = std::numeric_limits<double>::max();
483  bool found = false;
484 
485  for( ITEM* item : coupledItems )
486  {
487  if( item->Kind() == aItem->Kind() )
488  {
489  OPT_VECTOR2I anchor = getDanglingAnchor( m_currentNode, item );
490  if( !anchor )
491  continue;
492 
493  double dist = ( *anchor - *refAnchor ).EuclideanNorm();
494 
495  bool shapeMatches = true;
496 
497  if( item->OfKind( ITEM::SOLID_T ) && item->Layers() != aItem->Layers() )
498  {
499  shapeMatches = false;
500  }
501 
502  if( dist < bestDist && shapeMatches )
503  {
504  found = true;
505  bestDist = dist;
506 
507  if( refNet != netP )
508  {
509  aPair = DP_PRIMITIVE_PAIR ( item, primRef );
510  aPair.SetAnchors( *anchor, *refAnchor );
511  }
512  else
513  {
514  aPair = DP_PRIMITIVE_PAIR( primRef, item );
515  aPair.SetAnchors( *refAnchor, *anchor );
516  }
517  }
518  }
519  }
520 
521  if( !found )
522  {
523  if( aErrorMsg )
524  {
525  *aErrorMsg = wxString::Format( _( "Can't find a suitable starting point "
526  "for coupled net \"%s\"." ),
527  m_world->GetRuleResolver()->NetName( coupledNet ) );
528  }
529  return false;
530  }
531 
532  return true;
533 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
static const int dist[10][10]
Definition: ar_matrix.cpp:326
void AllItemsInNet(int aNet, std::set< ITEM * > &aItems)
Definition: pns_node.cpp:1294
NODE * m_world
pointer to world to search colliding items
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
virtual bool DpNetPair(ITEM *aItem, int &aNetP, int &aNetN)=0
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_node.h:176
NODE * m_currentNode
Current world state
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
virtual wxString NetName(int aNet)=0
OPT_VECTOR2I getDanglingAnchor(NODE *aNode, ITEM *aItem)

References _, PNS::NODE::AllItemsInNet(), dist, PNS::RULE_RESOLVER::DpNetPair(), EuclideanNorm(), Format(), getDanglingAnchor(), PNS::NODE::GetRuleResolver(), PNS::ITEM::Kind(), PNS::ITEM::Layers(), m_currentNode, m_world, PNS::ITEM::Net(), PNS::RULE_RESOLVER::NetName(), PNS::DP_PRIMITIVE_PAIR::SetAnchors(), and PNS::ITEM::SOLID_T.

Referenced by routeHead(), and Start().

◆ FixRoute()

bool PNS::DIFF_PAIR_PLACER::FixRoute ( const VECTOR2I aP,
ITEM aEndItem,
bool  aForceFinish 
)
overridevirtual

Function FixRoute()

Commits the currently routed track to the parent node, taking aP as the final end point and aEndItem as the final anchor (if provided).

Returns
true, if route has been commited. May return false if the routing result is violating design rules - in such case, the track is only committed if Settings.CanViolateDRC() is on.

Implements PNS::PLACEMENT_ALGO.

Definition at line 747 of file pns_diff_pair_placer.cpp.

748 {
749  if( !m_fitOk && !Settings().CanViolateDRC() )
750  return false;
751 
752  if( m_currentTrace.CP().SegmentCount() < 1 ||
753  m_currentTrace.CN().SegmentCount() < 1 )
754  return false;
755 
756  if( m_currentTrace.CP().SegmentCount() > 1 )
757  m_initialDiagonal = !DIRECTION_45( m_currentTrace.CP().CSegment( -2 ) ).IsDiagonal();
758 
759  TOPOLOGY topo( m_lastNode );
760 
761  if( !m_snapOnTarget && !m_currentTrace.EndsWithVias() && !aForceFinish )
762  {
765 
766  if( newP.SegmentCount() > 1 && newN.SegmentCount() > 1 )
767  {
768  newP.Remove( -1, -1 );
769  newN.Remove( -1, -1 );
770  }
771 
772  m_currentTrace.SetShape( newP, newN );
773  }
774 
776  {
779  m_chainedPlacement = false;
780  }
781  else
782  {
783  m_chainedPlacement = !m_snapOnTarget && !aForceFinish;
784  }
785 
786  LINE lineP( m_currentTrace.PLine() );
787  LINE lineN( m_currentTrace.NLine() );
788 
789  m_lastNode->Add( lineP );
790  m_lastNode->Add( lineN );
791 
792  topo.SimplifyLine( &lineP );
793  topo.SimplifyLine( &lineN );
794 
796 
797  CommitPlacement();
798  m_placingVia = false;
799 
800  if( m_snapOnTarget || aForceFinish )
801  {
802  m_idle = true;
803  return true;
804  }
805  else
806  {
807  initPlacement();
808  return false;
809  }
810 }
void SetShape(const SHAPE_LINE_CHAIN &aP, const SHAPE_LINE_CHAIN &aN, bool aSwapLanes=false)
bool EndsWithVias() const
const SHAPE_LINE_CHAIN & CN() const
ROUTING_SETTINGS & Settings() const
Returns current router settings
DIRECTION_45.
Definition: direction45.h:37
bool m_placingVia
Are we placing a via?
void Remove(int aStartIndex, int aEndIndex)
Function Remove()
int SegmentCount() const
Function SegmentCount()
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271
const SHAPE_LINE_CHAIN & CP() const
const SEG CSegment(int aIndex) const
Function CSegment()
SHAPE_LINE_CHAIN.
void initPlacement()
Function startPlacement()
OPT< DP_PRIMITIVE_PAIR > m_prevPair
const VIA & Via() const
Definition: pns_line.h:281
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620
DP_PRIMITIVE_PAIR EndingPrimitives()
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References PNS::NODE::Add(), PNS::Clone(), PNS::DIFF_PAIR::CN(), CommitPlacement(), PNS::DIFF_PAIR::CP(), SHAPE_LINE_CHAIN::CSegment(), PNS::DIFF_PAIR::EndingPrimitives(), PNS::DIFF_PAIR::EndsWithVias(), initPlacement(), m_chainedPlacement, m_currentTrace, m_fitOk, m_idle, m_initialDiagonal, m_lastNode, m_placingVia, m_prevPair, m_snapOnTarget, PNS::DIFF_PAIR::NLine(), PNS::DIFF_PAIR::PLine(), SHAPE_LINE_CHAIN::Remove(), SHAPE_LINE_CHAIN::SegmentCount(), PNS::DIFF_PAIR::SetShape(), PNS::ALGO_BASE::Settings(), PNS::TOPOLOGY::SimplifyLine(), and PNS::LINE::Via().

◆ FlipPosture()

void PNS::DIFF_PAIR_PLACER::FlipPosture ( )
overridevirtual

Function FlipPosture()

Toggles the current posture (straight/diagonal) of the trace head.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 363 of file pns_diff_pair_placer.cpp.

364 {
366 
367  if( !m_idle )
368  Move( m_currentEnd, NULL );
369 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()

References m_currentEnd, m_idle, m_startDiagonal, Move(), and NULL.

◆ gap()

int PNS::DIFF_PAIR_PLACER::gap ( ) const
private

Definition at line 542 of file pns_diff_pair_placer.cpp.

543 {
545 }

References PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), and m_sizes.

Referenced by routeHead().

◆ getDanglingAnchor()

OPT_VECTOR2I PNS::DIFF_PAIR_PLACER::getDanglingAnchor ( NODE aNode,
ITEM aItem 
)
private

Definition at line 406 of file pns_diff_pair_placer.cpp.

407 {
408  switch( aItem->Kind() )
409  {
410  case ITEM::VIA_T:
411  case ITEM::SOLID_T:
412  return aItem->Anchor( 0 );
413 
414  case ITEM::ARC_T:
415  case ITEM::SEGMENT_T:
416  {
417  SEGMENT* s = static_cast<SEGMENT*>( aItem );
418 
419  JOINT* jA = aNode->FindJoint( aItem->Anchor( 0 ), aItem );
420  JOINT* jB = aNode->FindJoint( aItem->Anchor( 1 ), aItem );
421 
422  if( jA && jA->LinkCount() == 1 )
423  return s->Seg().A;
424  else if( jB && jB->LinkCount() == 1 )
425  return s->Seg().B;
426  else
427  return OPT_VECTOR2I();
428  }
429 
430  default:
431  return OPT_VECTOR2I();
432  break;
433  }
434 }
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37

References SEG::A, PNS::ITEM::Anchor(), PNS::ITEM::ARC_T, SEG::B, PNS::NODE::FindJoint(), PNS::ITEM::Kind(), PNS::JOINT::LinkCount(), PNS::SEGMENT::Seg(), PNS::ITEM::SEGMENT_T, PNS::ITEM::SOLID_T, and PNS::ITEM::VIA_T.

Referenced by findDpPrimitivePair().

◆ GetModifiedNets()

void PNS::DIFF_PAIR_PLACER::GetModifiedNets ( std::vector< int > &  aNets) const
overridevirtual

Function GetModifiedNets.

Returns the net codes of all currently routed trace(s)

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 838 of file pns_diff_pair_placer.cpp.

839 {
840  aNets.push_back( m_netP );
841  aNets.push_back( m_netN );
842 }

References m_netN, and m_netP.

◆ HasPlacedAnything()

bool PNS::DIFF_PAIR_PLACER::HasPlacedAnything ( ) const
overridevirtual

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 820 of file pns_diff_pair_placer.cpp.

821 {
822  return m_currentTrace.CP().SegmentCount() > 0 ||
824 }
const SHAPE_LINE_CHAIN & CN() const
int SegmentCount() const
Function SegmentCount()
const SHAPE_LINE_CHAIN & CP() const

References PNS::DIFF_PAIR::CN(), PNS::DIFF_PAIR::CP(), m_currentTrace, and SHAPE_LINE_CHAIN::SegmentCount().

◆ initPlacement()

void PNS::DIFF_PAIR_PLACER::initPlacement ( )
private

Function startPlacement()

Initializes placement of a new line with given parameters.

Definition at line 605 of file pns_diff_pair_placer.cpp.

606 {
607  m_idle = false;
608  m_orthoMode = false;
611 
612  NODE* world = Router()->GetWorld();
613 
614  world->KillChildren();
615  NODE* rootNode = world->Branch();
616 
617  setWorld( rootNode );
618 
619  m_lastNode = NULL;
620  m_currentNode = rootNode;
622 
623  if( m_shove )
624  delete m_shove;
625 
626  m_shove = NULL;
627 
629  {
630  m_shove = new SHOVE( m_currentNode, Router() );
631  }
632 }
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
Ignore collisions, mark obstacles
SHOVE * m_shove
The shove engine
ROUTING_SETTINGS & Settings() const
Returns current router settings
void KillChildren()
Destroys all child nodes. Applicable only to the root node.
Definition: pns_node.cpp:1288
#define NULL
PNS_MODE Mode() const
Returns the routing mode.
Only walkaround
NODE * m_currentNode
Current world state
void setWorld(NODE *aWorld)
Function setWorld()
NODE * GetWorld() const
Definition: pns_router.h:152
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References PNS::NODE::Branch(), PNS::ROUTER::GetWorld(), PNS::NODE::KillChildren(), m_currentEndItem, m_currentMode, m_currentNode, m_idle, m_initialDiagonal, m_lastNode, m_orthoMode, m_shove, m_startDiagonal, PNS::ROUTING_SETTINGS::Mode(), NULL, PNS::RM_Shove, PNS::RM_Smart, PNS::ALGO_BASE::Router(), PNS::ALGO_BASE::Settings(), and setWorld().

Referenced by FixRoute(), SetLayer(), Start(), and UpdateSizes().

◆ IsPlacingVia()

bool PNS::DIFF_PAIR_PLACER::IsPlacingVia ( ) const
inlineoverridevirtual

Function IsPlacingVia()

Returns true if the placer is placing a via (or more vias).

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 170 of file pns_diff_pair_placer.h.

170 { return m_placingVia; }
bool m_placingVia
Are we placing a via?

References m_placingVia.

◆ Logger()

LOGGER * PNS::ALGO_BASE::Logger ( )
virtualinherited

Returns the logger object, allowing to dump geometry to a file.

Reimplemented in PNS::SHOVE.

Definition at line 34 of file pns_algo_base.cpp.

35 {
36  return NULL;
37 }
#define NULL

References NULL.

Referenced by PNS::DRAGGER::dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::DRAGGER::Start().

◆ makeVia()

const VIA PNS::DIFF_PAIR_PLACER::makeVia ( const VECTOR2I aP,
int  aNet 
)
private

Definition at line 79 of file pns_diff_pair_placer.cpp.

80 {
82 
83  VIA v( aP, layers, m_sizes.ViaDiameter(), m_sizes.ViaDrill(), -1, m_sizes.ViaType() );
84  v.SetNet( aNet );
85 
86  return v;
87 }
VIATYPE ViaType() const
void SetNet(NETINFO_ITEM *aNetInfo)
Function SetNet Sets a NET_INFO object for the item.
LAYER_RANGE.
Definition: pns_layerset.h:32

References PNS::SIZES_SETTINGS::GetLayerBottom(), PNS::SIZES_SETTINGS::GetLayerTop(), m_sizes, PNS::ITEM::SetNet(), PNS::SIZES_SETTINGS::ViaDiameter(), PNS::SIZES_SETTINGS::ViaDrill(), and PNS::SIZES_SETTINGS::ViaType().

Referenced by propagateDpHeadForces(), and routeHead().

◆ Move()

bool PNS::DIFF_PAIR_PLACER::Move ( const VECTOR2I aP,
ITEM aEndItem 
)
overridevirtual

Function Move()

Moves the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL). (unless NULL).

Implements PNS::PLACEMENT_ALGO.

Definition at line 713 of file pns_diff_pair_placer.cpp.

714 {
715  m_currentEndItem = aEndItem;
716  m_fitOk = false;
717 
718  delete m_lastNode;
719  m_lastNode = NULL;
720 
721  bool retval = route( aP );
722 
723  NODE* latestNode = m_currentNode;
724  m_lastNode = latestNode->Branch();
725 
726  assert( m_lastNode != NULL );
727  m_currentEnd = aP;
728 
730 
731  return retval;
732 }
bool route(const VECTOR2I &aP)
Function route()
NODE * Branch()
Function Branch()
Definition: pns_node.cpp:106
#define NULL
NODE * m_currentNode
Current world state
void updateLeadingRatLine()
Function updateLeadingRatLine()
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References PNS::NODE::Branch(), m_currentEnd, m_currentEndItem, m_currentNode, m_fitOk, m_lastNode, NULL, route(), and updateLeadingRatLine().

Referenced by FlipPosture(), SetLayer(), SetOrthoMode(), ToggleVia(), and UpdateSizes().

◆ propagateDpHeadForces()

bool PNS::DIFF_PAIR_PLACER::propagateDpHeadForces ( const VECTOR2I aP,
VECTOR2I aNewP 
)
private

Definition at line 124 of file pns_diff_pair_placer.cpp.

125 {
126  VIA virtHead = makeVia( aP, -1 );
127 
128  if( m_placingVia )
129  virtHead.SetDiameter( viaGap() + 2 * virtHead.Diameter() );
130  else
131  {
132  virtHead.SetLayer( m_currentLayer );
133  virtHead.SetDiameter( m_sizes.DiffPairGap() + 2 * m_sizes.DiffPairWidth() );
134  }
135 
136  VECTOR2I lead( 0, 0 );// = aP - m_currentStart ;
137  VECTOR2I force;
138  bool solidsOnly = true;
139 
141  {
142  aNewP = aP;
143  return true;
144  }
145  else if( m_currentMode == RM_Walkaround )
146  {
147  solidsOnly = false;
148  }
149 
150  // fixme: I'm too lazy to do it well. Circular approximaton will do for the moment.
151  if( virtHead.PushoutForce( m_currentNode, lead, force, solidsOnly, 40 ) )
152  {
153  aNewP = aP + force;
154  return true;
155  }
156 
157  return false;
158 }
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
const VIA makeVia(const VECTOR2I &aP, int aNet)
bool m_placingVia
Are we placing a via?
NODE * m_currentNode
Current world state

References PNS::VIA::Diameter(), PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), m_currentLayer, m_currentMode, m_currentNode, m_placingVia, m_sizes, makeVia(), PNS::VIA::PushoutForce(), PNS::RM_MarkObstacles, PNS::RM_Walkaround, PNS::VIA::SetDiameter(), PNS::ITEM::SetLayer(), and viaGap().

Referenced by routeHead().

◆ rhMarkObstacles()

bool PNS::DIFF_PAIR_PLACER::rhMarkObstacles ( const VECTOR2I aP)
private

route step, mark obstacles mode

Definition at line 110 of file pns_diff_pair_placer.cpp.

111 {
112  if( !routeHead( aP ) )
113  return false;
114 
115  bool collP = static_cast<bool>( m_currentNode->CheckColliding( &m_currentTrace.PLine() ) );
116  bool collN = static_cast<bool>( m_currentNode->CheckColliding( &m_currentTrace.NLine() ) );
117 
118  m_fitOk = !( collP || collN ) ;
119 
120  return m_fitOk;
121 }
bool routeHead(const VECTOR2I &aP)
NODE * m_currentNode
Current world state
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427

References PNS::NODE::CheckColliding(), m_currentNode, m_currentTrace, m_fitOk, PNS::DIFF_PAIR::NLine(), PNS::DIFF_PAIR::PLine(), and routeHead().

Referenced by route().

◆ rhShoveOnly()

bool PNS::DIFF_PAIR_PLACER::rhShoveOnly ( const VECTOR2I aP)
private

route step, shove mode

Definition at line 312 of file pns_diff_pair_placer.cpp.

313 {
315 
316  bool ok = routeHead( aP );
317 
318  m_fitOk = false;
319 
320  if( !ok )
321  return false;
322 
323  if( !tryWalkDp( m_currentNode, m_currentTrace, true ) )
324  return false;
325 
326  LINE pLine( m_currentTrace.PLine() );
327  LINE nLine( m_currentTrace.NLine() );
328  ITEM_SET head;
329 
330  head.Add( &pLine );
331  head.Add( &nLine );
332 
333  SHOVE::SHOVE_STATUS status = m_shove->ShoveMultiLines( head );
334 
336 
337  if( status == SHOVE::SH_OK )
338  {
340 
343  {
344  m_fitOk = true;
345  }
346  }
347 
348  return m_fitOk;
349 }
SHOVE * m_shove
The shove engine
bool routeHead(const VECTOR2I &aP)
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:142
NODE * m_currentNode
Current world state
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427
bool tryWalkDp(NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)
SHOVE_STATUS ShoveMultiLines(const ITEM_SET &aHeadSet)
Definition: pns_shove.cpp:1351
NODE * CurrentNode()
Definition: pns_shove.cpp:1595

References PNS::ITEM_SET::Add(), PNS::NODE::CheckColliding(), PNS::SHOVE::CurrentNode(), m_currentNode, m_currentTrace, m_fitOk, m_shove, PNS::DIFF_PAIR::NLine(), PNS::DIFF_PAIR::PLine(), routeHead(), PNS::SHOVE::SH_OK, PNS::SHOVE::ShoveMultiLines(), and tryWalkDp().

Referenced by route().

◆ rhWalkOnly()

bool PNS::DIFF_PAIR_PLACER::rhWalkOnly ( const VECTOR2I aP)
private

route step, walkaround mode

Definition at line 283 of file pns_diff_pair_placer.cpp.

284 {
285  if( !routeHead ( aP ) )
286  return false;
287 
289 
290  return m_fitOk;
291 }
bool routeHead(const VECTOR2I &aP)
NODE * m_currentNode
Current world state
bool tryWalkDp(NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)

References m_currentNode, m_currentTrace, m_fitOk, routeHead(), and tryWalkDp().

Referenced by route().

◆ route()

bool PNS::DIFF_PAIR_PLACER::route ( const VECTOR2I aP)
private

Function route()

Re-routes the current track to point aP. Returns true, when routing has completed successfully (i.e. the trace end has reached point aP), and false if the trace was stuck somewhere on the way. May call routeStep() repetitively due to mouse smoothing.

Parameters
aPending point of current route.
Returns
true, if the routing is complete.

Definition at line 294 of file pns_diff_pair_placer.cpp.

295 {
296  switch( m_currentMode )
297  {
298  case RM_MarkObstacles:
299  return rhMarkObstacles( aP );
300  case RM_Walkaround:
301  return rhWalkOnly( aP );
302  case RM_Shove:
303  return rhShoveOnly( aP );
304  default:
305  break;
306  }
307 
308  return false;
309 }
bool rhWalkOnly(const VECTOR2I &aP)
route step, walkaround mode
bool rhShoveOnly(const VECTOR2I &aP)
route step, shove mode
Ignore collisions, mark obstacles
bool rhMarkObstacles(const VECTOR2I &aP)
route step, mark obstacles mode

References m_currentMode, rhMarkObstacles(), rhShoveOnly(), rhWalkOnly(), PNS::RM_MarkObstacles, PNS::RM_Shove, and PNS::RM_Walkaround.

Referenced by Move().

◆ routeHead()

bool PNS::DIFF_PAIR_PLACER::routeHead ( const VECTOR2I aP)
private

Definition at line 635 of file pns_diff_pair_placer.cpp.

636 {
637  m_fitOk = false;
638 
639  DP_GATEWAYS gwsEntry( gap() );
640  DP_GATEWAYS gwsTarget( gap() );
641 
642  if( !m_prevPair )
644 
645  gwsEntry.BuildFromPrimitivePair( *m_prevPair, m_startDiagonal );
646 
647  DP_PRIMITIVE_PAIR target;
648 
649  if( findDpPrimitivePair( aP, m_currentEndItem, target ) )
650  {
651  gwsTarget.BuildFromPrimitivePair( target, m_startDiagonal );
652  m_snapOnTarget = true;
653  }
654  else
655  {
656  VECTOR2I fp;
657 
658  if( !propagateDpHeadForces( aP, fp ) )
659  return false;
660 
661  VECTOR2I midp, dirV;
662  m_prevPair->CursorOrientation( fp, midp, dirV );
663 
664  VECTOR2I fpProj = SEG( midp, midp + dirV ).LineProject( fp );
665 
666  // compute 'leader point' distance from the cursor (project cursor position
667  // on the extension of the starting segment pair of the DP)
668  int lead_dist = ( fpProj - fp ).EuclideanNorm();
669 
670  gwsTarget.SetFitVias( m_placingVia, m_sizes.ViaDiameter(), viaGap() );
671 
672  // far from the initial segment extension line -> allow a 45-degree obtuse turn
673  if( lead_dist > m_sizes.DiffPairGap() + m_sizes.DiffPairWidth() )
674  {
675  gwsTarget.BuildForCursor( fp );
676  }
677  // close to the initial segment extension line -> keep straight part only, project as close
678  // as possible to the cursor
679  else
680  {
681  gwsTarget.BuildForCursor( fpProj );
682  gwsTarget.FilterByOrientation( DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_HALF_FULL, DIRECTION_45( dirV ) );
683  }
684 
685  m_snapOnTarget = false;
686  }
687 
688  m_currentTrace = DIFF_PAIR();
691 
692  bool result = gwsEntry.FitGateways( gwsEntry, gwsTarget, m_startDiagonal, m_currentTrace );
693 
694  if( result )
695  {
699 
700  if( m_placingVia )
701  {
703  makeVia( m_currentTrace.CN().CPoint( -1 ), m_netN ) );
704  }
705 
706  return true;
707  }
708 
709  return false;
710 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
void SetLayer(int aLayer)
Definition: pns_item.h:154
void AppendVias(const VIA &aViaP, const VIA &aViaN)
const SHAPE_LINE_CHAIN & CN() const
const VIA makeVia(const VECTOR2I &aP, int aNet)
const VECTOR2I & CPoint(int aIndex) const
Function Point()
bool findDpPrimitivePair(const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
void SetGap(int aGap)
bool propagateDpHeadForces(const VECTOR2I &aP, VECTOR2I &aNewP)
VECTOR2I LineProject(const VECTOR2I &aP) const
Function LineProject()
Definition: seg.h:364
DIRECTION_45.
Definition: direction45.h:37
bool m_placingVia
Are we placing a via?
void SetWidth(int aWidth)
Definition: seg.h:39
const SHAPE_LINE_CHAIN & CP() const
OPT< DP_PRIMITIVE_PAIR > m_prevPair
void SetNets(int aP, int aN)

References DIRECTION_45::ANG_HALF_FULL, DIRECTION_45::ANG_STRAIGHT, PNS::DIFF_PAIR::AppendVias(), PNS::DP_GATEWAYS::BuildForCursor(), PNS::DP_GATEWAYS::BuildFromPrimitivePair(), PNS::DIFF_PAIR::CN(), PNS::DIFF_PAIR::CP(), SHAPE_LINE_CHAIN::CPoint(), PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), EuclideanNorm(), PNS::DP_GATEWAYS::FilterByOrientation(), findDpPrimitivePair(), PNS::DP_GATEWAYS::FitGateways(), gap(), SEG::LineProject(), m_currentEndItem, m_currentLayer, m_currentTrace, m_fitOk, m_netN, m_netP, m_placingVia, m_prevPair, m_sizes, m_snapOnTarget, m_start, m_startDiagonal, makeVia(), propagateDpHeadForces(), PNS::DP_GATEWAYS::SetFitVias(), PNS::DIFF_PAIR::SetGap(), PNS::ITEM::SetLayer(), PNS::DIFF_PAIR::SetNets(), PNS::DIFF_PAIR::SetWidth(), PNS::SIZES_SETTINGS::ViaDiameter(), and viaGap().

Referenced by rhMarkObstacles(), rhShoveOnly(), and rhWalkOnly().

◆ Router()

◆ SetDebugDecorator()

void PNS::ALGO_BASE::SetDebugDecorator ( DEBUG_DECORATOR aDecorator)
inlineinherited

Function SetDebugDecorator.

Assign a debug decorator allowing this algo to draw extra graphics for visual debugging

Definition at line 72 of file pns_algo_base.h.

73  {
74  m_debugDecorator = aDecorator;
75  }
DEBUG_DECORATOR * m_debugDecorator
Definition: pns_algo_base.h:83

References PNS::ALGO_BASE::m_debugDecorator.

Referenced by PNS::DRAGGER::dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::SHOVE::SHOVE().

◆ setInitialDirection()

void PNS::DIFF_PAIR_PLACER::setInitialDirection ( const DIRECTION_45 aDirection)
private

Function setInitialDirection()

Sets preferred direction of the very first track segment to be laid. Used by posture switching mechanism.

◆ SetLayer()

bool PNS::DIFF_PAIR_PLACER::SetLayer ( int  aLayer)
overridevirtual

Function SetLayer()

Sets the current routing layer.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 381 of file pns_diff_pair_placer.cpp.

382 {
383  if( m_idle )
384  {
385  m_currentLayer = aLayer;
386  return true;
387  }
388  else if( m_chainedPlacement || !m_prevPair )
389  {
390  return false;
391  }
392  else if( !m_prevPair->PrimP() || ( m_prevPair->PrimP()->OfKind( ITEM::VIA_T ) &&
393  m_prevPair->PrimP()->Layers().Overlaps( aLayer ) ) )
394  {
395  m_currentLayer = aLayer;
396  m_start = *m_prevPair;
397  initPlacement();
398  Move( m_currentEnd, NULL );
399  return true;
400  }
401 
402  return false;
403 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
void initPlacement()
Function startPlacement()
OPT< DP_PRIMITIVE_PAIR > m_prevPair

References initPlacement(), m_chainedPlacement, m_currentEnd, m_currentLayer, m_idle, m_prevPair, m_start, Move(), NULL, and PNS::ITEM::VIA_T.

◆ SetLogger()

void PNS::ALGO_BASE::SetLogger ( LOGGER aLogger)
inlineinherited

Definition at line 62 of file pns_algo_base.h.

63  {
64  m_logger = aLogger;
65  }
LOGGER * m_logger
Definition: pns_algo_base.h:85

References PNS::ALGO_BASE::m_logger.

Referenced by PNS::DRAGGER::dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), and PNS::LINE_PLACER::rhWalkOnly().

◆ SetOrthoMode()

void PNS::DIFF_PAIR_PLACER::SetOrthoMode ( bool  aOrthoMode)
overridevirtual

Function SetOrthoMode()

Forces the router to place a straight 90/45 degree trace (with the end as near to the cursor as possible) instead of a standard 135 degree two-segment bend.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 90 of file pns_diff_pair_placer.cpp.

91 {
92  m_orthoMode = aOrthoMode;
93 
94  if( !m_idle )
96 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()

References m_currentEnd, m_idle, m_orthoMode, Move(), and NULL.

◆ Settings()

◆ setWorld()

void PNS::DIFF_PAIR_PLACER::setWorld ( NODE aWorld)
private

Function setWorld()

Sets the board to route.

Definition at line 74 of file pns_diff_pair_placer.cpp.

75 {
76  m_world = aWorld;
77 }
NODE * m_world
pointer to world to search colliding items

References m_world.

Referenced by initPlacement(), and Start().

◆ Start()

bool PNS::DIFF_PAIR_PLACER::Start ( const VECTOR2I aP,
ITEM aStartItem 
)
overridevirtual

Function Start()

Starts routing a single track at point aP, taking item aStartItem as anchor (unless NULL).

Implements PNS::PLACEMENT_ALGO.

Definition at line 548 of file pns_diff_pair_placer.cpp.

549 {
550  VECTOR2I p( aP );
551  wxString msg;
552 
553  if( !aStartItem )
554  {
555  Router()->SetFailureReason( _( "Can't start a differential pair "
556  " in the middle of nowhere." ) );
557  return false;
558  }
559 
560  setWorld( Router()->GetWorld() );
562 
563  if( !findDpPrimitivePair( aP, aStartItem, m_start, &msg ) )
564  {
565  Router()->SetFailureReason( msg );
566  return false;
567  }
568 
569  m_netP = m_start.PrimP()->Net();
570  m_netN = m_start.PrimN()->Net();
571 
572  #if 0
573  // FIXME: this also needs to be factored out but not so important right now
574  // Check if the current track/via gap & track width settings are violated
575  BOARD* brd = NULL; // FIXME Router()->GetBoard();
576  NETCLASSPTR netclassP = brd->FindNet( m_netP )->GetNetClass();
577  NETCLASSPTR netclassN = brd->FindNet( m_netN )->GetNetClass();
578  int clearance = std::min( m_sizes.DiffPairGap(), m_sizes.DiffPairViaGap() );
579 
580  if( clearance < netclassP->GetClearance() || clearance < netclassN->GetClearance() )
581  {
582  Router()->SetFailureReason( _( "Current track/via gap setting violates "
583  "design rules for this net." ) );
584  return false;
585  }
586 
588  {
589  Router()->SetFailureReason( _( "Current track width setting violates design rules." ) );
590  return false;
591  }
592  #endif
593 
594  m_currentStart = p;
595  m_currentEnd = p;
596  m_placingVia = false;
597  m_chainedPlacement = false;
598 
599  initPlacement();
600 
601  return true;
602 }
NETCLASS * GetNetClass()
Function GetNetClass.
Definition: netinfo.h:128
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
NODE * m_world
pointer to world to search colliding items
ITEM * PrimP() const
bool findDpPrimitivePair(const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
#define NULL
int Net() const
Definition: pns_item.h:149
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:225
bool m_placingVia
Are we placing a via?
NODE * m_currentNode
Current world state
ITEM * PrimN() const
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:181
#define _(s)
Definition: 3d_actions.cpp:33
void initPlacement()
Function startPlacement()
void setWorld(NODE *aWorld)
Function setWorld()

References _, PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairViaGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), findDpPrimitivePair(), BOARD::FindNet(), BOARD::GetDesignSettings(), NETINFO_ITEM::GetNetClass(), initPlacement(), m_chainedPlacement, m_currentEnd, m_currentNode, m_currentStart, m_netN, m_netP, m_placingVia, m_sizes, m_start, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, m_world, PNS::ITEM::Net(), NULL, PNS::DP_PRIMITIVE_PAIR::PrimN(), PNS::DP_PRIMITIVE_PAIR::PrimP(), PNS::ALGO_BASE::Router(), PNS::ROUTER::SetFailureReason(), and setWorld().

◆ ToggleVia()

bool PNS::DIFF_PAIR_PLACER::ToggleVia ( bool  aEnabled)
overridevirtual

Function ToggleVia()

Enables/disables a via at the end of currently routed trace.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 99 of file pns_diff_pair_placer.cpp.

100 {
101  m_placingVia = aEnabled;
102 
103  if( !m_idle )
104  Move( m_currentEnd, NULL );
105 
106  return true;
107 }
#define NULL
bool m_placingVia
Are we placing a via?
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()

References m_currentEnd, m_idle, m_placingVia, Move(), and NULL.

◆ Traces()

const ITEM_SET PNS::DIFF_PAIR_PLACER::Traces ( )
overridevirtual

Function Traces()

Returns the complete routed line, as a single-member ITEM_SET.

Implements PNS::PLACEMENT_ALGO.

Definition at line 352 of file pns_diff_pair_placer.cpp.

353 {
354  ITEM_SET t;
355 
356  t.Add( const_cast<LINE*>( &m_currentTrace.PLine() ) );
357  t.Add( const_cast<LINE*>( &m_currentTrace.NLine() ) );
358 
359  return t;
360 }
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:142

References PNS::ITEM_SET::Add(), m_currentTrace, PNS::DIFF_PAIR::NLine(), and PNS::DIFF_PAIR::PLine().

◆ tryWalkDp()

bool PNS::DIFF_PAIR_PLACER::tryWalkDp ( NODE aNode,
DIFF_PAIR aPair,
bool  aSolidsOnly 
)
private

Definition at line 238 of file pns_diff_pair_placer.cpp.

239 {
240  DIFF_PAIR best;
241  double bestScore = 100000000000000.0;
242 
243  for( int attempt = 0; attempt <= 3; attempt++ )
244  {
245  DIFF_PAIR p;
246  NODE *tmp = m_currentNode->Branch();
247 
248  bool pfirst = ( attempt & 1 ) ? true : false;
249  bool wind_cw = ( attempt & 2 ) ? true : false;
250 
251  if( attemptWalk( tmp, &aPair, p, pfirst, wind_cw, aSolidsOnly ) )
252  {
253  // double len = p.TotalLength();
254  double cl = p.CoupledLength();
255  double skew = p.Skew();
256 
257  double score = cl + fabs( skew ) * 3.0;
258 
259  if( score < bestScore )
260  {
261  bestScore = score;
262  best = p;
263  }
264  }
265 
266  delete tmp;
267  }
268 
269  if( bestScore > 0.0 )
270  {
271  OPTIMIZER optimizer( m_currentNode );
272 
273  aPair.SetShape( best );
274  optimizer.Optimize( &aPair );
275 
276  return true;
277  }
278 
279  return false;
280 }
bool attemptWalk(NODE *aNode, DIFF_PAIR *aCurrent, DIFF_PAIR &aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly)
NODE * Branch()
Function Branch()
Definition: pns_node.cpp:106
NODE * m_currentNode
Current world state

References attemptWalk(), PNS::NODE::Branch(), PNS::DIFF_PAIR::CoupledLength(), m_currentNode, PNS::OPTIMIZER::Optimize(), PNS::DIFF_PAIR::SetShape(), and PNS::DIFF_PAIR::Skew().

Referenced by rhShoveOnly(), and rhWalkOnly().

◆ UnfixRoute()

virtual bool PNS::PLACEMENT_ALGO::UnfixRoute ( )
inlinevirtualinherited

Reimplemented in PNS::LINE_PLACER.

Definition at line 81 of file pns_placement_algo.h.

81 { return false; };

◆ updateLeadingRatLine()

void PNS::DIFF_PAIR_PLACER::updateLeadingRatLine ( )
private

Function updateLeadingRatLine()

Draws the "leading" ratsnest line, which connects the end of currently routed track and the nearest yet unrouted item. If the routing for current net is complete, draws nothing.

Definition at line 845 of file pns_diff_pair_placer.cpp.

846 {
847  SHAPE_LINE_CHAIN ratLineN, ratLineP;
848  TOPOLOGY topo( m_lastNode );
849 
850  if( topo.LeadingRatLine( &m_currentTrace.PLine(), ratLineP ) )
851  {
852  Dbg()->AddLine( ratLineP, 1, 10000 );
853  }
854 
855  if( topo.LeadingRatLine ( &m_currentTrace.NLine(), ratLineN ) )
856  {
857  Dbg()->AddLine( ratLineN, 3, 10000 );
858  }
859 }
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, int aType=0, int aWidth=0, const std::string aName="")
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:77
SHAPE_LINE_CHAIN.
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)

References PNS::DEBUG_DECORATOR::AddLine(), PNS::ALGO_BASE::Dbg(), PNS::TOPOLOGY::LeadingRatLine(), m_currentTrace, m_lastNode, PNS::DIFF_PAIR::NLine(), and PNS::DIFF_PAIR::PLine().

Referenced by Move().

◆ UpdateSizes()

void PNS::DIFF_PAIR_PLACER::UpdateSizes ( const SIZES_SETTINGS aSizes)
overridevirtual

Function UpdateSizes()

Performs on-the-fly update of the width, via diameter & drill size from a settings class. Used to dynamically change these parameters as the track is routed.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 735 of file pns_diff_pair_placer.cpp.

736 {
737  m_sizes = aSizes;
738 
739  if( !m_idle )
740  {
741  initPlacement();
742  Move( m_currentEnd, NULL );
743  }
744 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
void initPlacement()
Function startPlacement()

References initPlacement(), m_currentEnd, m_idle, m_sizes, Move(), and NULL.

◆ viaGap()

int PNS::DIFF_PAIR_PLACER::viaGap ( ) const
private

Definition at line 536 of file pns_diff_pair_placer.cpp.

537 {
538  return m_sizes.DiffPairViaGap();
539 }

References PNS::SIZES_SETTINGS::DiffPairViaGap(), and m_sizes.

Referenced by propagateDpHeadForces(), and routeHead().

Member Data Documentation

◆ m_chainedPlacement

bool PNS::DIFF_PAIR_PLACER::m_chainedPlacement
private

Definition at line 251 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), FixRoute(), SetLayer(), and Start().

◆ m_currentEnd

VECTOR2I PNS::DIFF_PAIR_PLACER::m_currentEnd
private

◆ m_currentEndItem

ITEM* PNS::DIFF_PAIR_PLACER::m_currentEndItem
private

Definition at line 303 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), initPlacement(), Move(), and routeHead().

◆ m_currentLayer

int PNS::DIFF_PAIR_PLACER::m_currentLayer
private

◆ m_currentMode

PNS_MODE PNS::DIFF_PAIR_PLACER::m_currentMode
private

◆ m_currentNet

int PNS::DIFF_PAIR_PLACER::m_currentNet
private

Definition at line 293 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_currentNode

NODE* PNS::DIFF_PAIR_PLACER::m_currentNode
private

◆ m_currentStart

VECTOR2I PNS::DIFF_PAIR_PLACER::m_currentStart
private

Definition at line 300 of file pns_diff_pair_placer.h.

Referenced by Start().

◆ m_currentTrace

DIFF_PAIR PNS::DIFF_PAIR_PLACER::m_currentTrace
private

◆ m_currentWidth

int PNS::DIFF_PAIR_PLACER::m_currentWidth
private

current track width

Definition at line 291 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_debugDecorator

DEBUG_DECORATOR* PNS::ALGO_BASE::m_debugDecorator
protectedinherited

Definition at line 83 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::Dbg(), and PNS::ALGO_BASE::SetDebugDecorator().

◆ m_fitOk

bool PNS::DIFF_PAIR_PLACER::m_fitOk
private

◆ m_idle

bool PNS::DIFF_PAIR_PLACER::m_idle
private

◆ m_initialDiagonal

bool PNS::DIFF_PAIR_PLACER::m_initialDiagonal
private

Definition at line 252 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), FixRoute(), and initPlacement().

◆ m_iteration

int PNS::DIFF_PAIR_PLACER::m_iteration
private

current algorithm iteration

Definition at line 262 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_lastNode

NODE* PNS::DIFF_PAIR_PLACER::m_lastNode
private

Postprocessed world state (including marked collisions & removed loops)

Definition at line 277 of file pns_diff_pair_placer.h.

Referenced by CommitPlacement(), CurrentNode(), DIFF_PAIR_PLACER(), FixRoute(), initPlacement(), Move(), and updateLeadingRatLine().

◆ m_logger

LOGGER* PNS::ALGO_BASE::m_logger
protectedinherited

Definition at line 85 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::SetLogger(), and PNS::WALKAROUND::singleStep().

◆ m_netN

int PNS::DIFF_PAIR_PLACER::m_netN
private

◆ m_netP

int PNS::DIFF_PAIR_PLACER::m_netP
private

◆ m_orthoMode

bool PNS::DIFF_PAIR_PLACER::m_orthoMode
private

Definition at line 297 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), initPlacement(), and SetOrthoMode().

◆ m_p_start

VECTOR2I PNS::DIFF_PAIR_PLACER::m_p_start
private

current routing start point (end of tail, beginning of head)

Definition at line 268 of file pns_diff_pair_placer.h.

◆ m_placingVia

bool PNS::DIFF_PAIR_PLACER::m_placingVia
private

Are we placing a via?

Definition at line 282 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), FixRoute(), IsPlacingVia(), propagateDpHeadForces(), routeHead(), Start(), and ToggleVia().

◆ m_prevPair

OPT<DP_PRIMITIVE_PAIR> PNS::DIFF_PAIR_PLACER::m_prevPair
private

Definition at line 259 of file pns_diff_pair_placer.h.

Referenced by FixRoute(), routeHead(), and SetLayer().

◆ m_router

ROUTER* PNS::ALGO_BASE::m_router
protectedinherited

Definition at line 84 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::Router(), and PNS::ALGO_BASE::Settings().

◆ m_shove

SHOVE* PNS::DIFF_PAIR_PLACER::m_shove
private

The shove engine

Definition at line 271 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), initPlacement(), rhShoveOnly(), and ~DIFF_PAIR_PLACER().

◆ m_sizes

SIZES_SETTINGS PNS::DIFF_PAIR_PLACER::m_sizes
private

◆ m_snapOnTarget

bool PNS::DIFF_PAIR_PLACER::m_snapOnTarget
private

Definition at line 298 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), FixRoute(), and routeHead().

◆ m_start

DP_PRIMITIVE_PAIR PNS::DIFF_PAIR_PLACER::m_start
private

Definition at line 258 of file pns_diff_pair_placer.h.

Referenced by routeHead(), SetLayer(), and Start().

◆ m_startDiagonal

bool PNS::DIFF_PAIR_PLACER::m_startDiagonal
private

Definition at line 253 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER(), FlipPosture(), initPlacement(), and routeHead().

◆ m_startsOnVia

bool PNS::DIFF_PAIR_PLACER::m_startsOnVia
private

Definition at line 296 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_state

State PNS::DIFF_PAIR_PLACER::m_state
private

Definition at line 249 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_viaDiameter

int PNS::DIFF_PAIR_PLACER::m_viaDiameter
private

current via diameter

Definition at line 285 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_viaDrill

int PNS::DIFF_PAIR_PLACER::m_viaDrill
private

current via drill

Definition at line 288 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_world

NODE* PNS::DIFF_PAIR_PLACER::m_world
private

pointer to world to search colliding items

Definition at line 265 of file pns_diff_pair_placer.h.

Referenced by AbortPlacement(), DIFF_PAIR_PLACER(), findDpPrimitivePair(), setWorld(), and Start().


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