KiCad PCB EDA Suite
PNS::DIFF_PAIR_PLACER Class Reference

Single track placement algorithm. 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
 Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL). More...
 
bool Move (const VECTOR2I &aP, ITEM *aEndItem) override
 Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL). More...
 
bool FixRoute (const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
 Commit the currently routed track to the parent node, taking aP as the final end point and aEndItem as the final anchor (if provided). More...
 
bool CommitPlacement () override
 
bool AbortPlacement () override
 
bool HasPlacedAnything () const override
 
bool ToggleVia (bool aEnabled) override
 Enable/disable a via at the end of currently routed trace. More...
 
bool SetLayer (int aLayer) override
 Set the current routing layer. More...
 
const ITEM_SET Traces () override
 Return the complete routed line, as a single-member ITEM_SET. More...
 
const VECTOR2ICurrentEnd () const override
 Return the current end of the line being placed. More...
 
const std::vector< int > CurrentNets () const override
 Return the net code of currently routed track. More...
 
int CurrentLayer () const override
 Return the layer of currently routed track. More...
 
NODECurrentNode (bool aLoopsRemoved=false) const override
 Return the most recent world state. More...
 
void FlipPosture () override
 Toggle the current posture (straight/diagonal) of the trace head. More...
 
void UpdateSizes (const SIZES_SETTINGS &aSizes) override
 Perform on-the-fly update of the width, via diameter & drill size from a settings class. 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
 Return current router settings. More...
 
ROUTING_SETTINGSSettings () const
 Return the logger object, allowing to dump geometry to a file. More...
 
virtual LOGGERLogger ()
 
void SetLogger (LOGGER *aLogger)
 
void SetDebugDecorator (DEBUG_DECORATOR *aDecorator)
 Assign a debug decorator allowing this algo to draw extra graphics for visual debugging. More...
 
DEBUG_DECORATORDbg () const
 
const BOX2IVisibleViewArea () const
 

Static Public Member Functions

static bool FindDpPrimitivePair (NODE *aWorld, const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
 

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)
 Re-route the current track to point aP. More...
 
void updateLeadingRatLine ()
 Draw the "leading" ratsnest line, which connects the end of currently routed track and the nearest yet unrouted item. More...
 
void setWorld (NODE *aWorld)
 Set the board to route. More...
 
void initPlacement ()
 Initialize placement of a new line with given parameters. More...
 
void setInitialDirection (const DIRECTION_45 &aDirection)
 Set preferred direction of the very first track segment to be laid. More...
 
bool routeHead (const VECTOR2I &aP)
 
bool tryWalkDp (NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)
 route step, walk around mode More...
 
bool rhWalkOnly (const VECTOR2I &aP)
 route step, shove mode More...
 
bool rhShoveOnly (const VECTOR2I &aP)
 route step, mark obstacles mode More...
 
bool rhMarkObstacles (const VECTOR2I &aP)
 
const VIA makeVia (const VECTOR2I &aP, int aNet)
 
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
 current algorithm iteration More...
 
int m_iteration
 pointer to world to search colliding items More...
 
NODEm_world
 current routing start point (end of tail, beginning of head) More...
 
VECTOR2I m_p_start
 The shove engine. More...
 
SHOVEm_shove
 Current world state. More...
 
NODEm_currentNode
 Postprocessed world state (including marked collisions & removed loops) More...
 
NODEm_lastNode
 
SIZES_SETTINGS m_sizes
 Are we placing a via? More...
 
bool m_placingVia
 current via diameter More...
 
int m_viaDiameter
 current via drill More...
 
int m_viaDrill
 current track width More...
 
int m_currentWidth
 
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
 
bool m_currentTraceOk
 
ITEMm_currentEndItem
 
PNS_MODE m_currentMode
 
bool m_idle
 

Detailed Description

Single track placement algorithm.

Interactively routes a track and applies shove and walk around algorithms when needed.

Definition at line 52 of file pns_diff_pair_placer.h.

Member Enumeration Documentation

◆ State

Enumerator
RT_START 
RT_ROUTE 
RT_FINISH 

Definition at line 209 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 32 of file pns_diff_pair_placer.cpp.

32  :
33  PLACEMENT_ALGO( aRouter )
34 {
35  m_state = RT_START;
36  m_chainedPlacement = false;
37  m_initialDiagonal = false;
38  m_startDiagonal = false;
39  m_fitOk = false;
40  m_netP = 0;
41  m_netN = 0;
42  m_iteration = 0;
43  m_world = NULL;
44  m_shove = NULL;
46  m_lastNode = NULL;
47  m_placingVia = false;
48  m_viaDiameter = 0;
49  m_viaDrill = 0;
50  m_currentWidth = 0;
51  m_currentNet = 0;
52  m_currentLayer = 0;
53  m_startsOnVia = false;
54  m_orthoMode = false;
55  m_snapOnTarget = false;
58  m_currentTraceOk = false;
59  m_idle = true;
60 }
int m_iteration
pointer to world to search colliding items
SHOVE * m_shove
Current world state.
int m_viaDiameter
current via drill
NODE * m_world
current routing start point (end of tail, beginning of head)
int m_viaDrill
current track width
#define NULL
bool m_placingVia
current via diameter
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
Ignore collisions, mark obstacles.
PLACEMENT_ALGO(ROUTER *aRouter)

References m_chainedPlacement, m_currentEndItem, m_currentLayer, m_currentMode, m_currentNet, m_currentNode, m_currentTraceOk, 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 62 of file pns_diff_pair_placer.cpp.

63 {
64  if( m_shove )
65  delete m_shove;
66 }
SHOVE * m_shove
Current world state.

References m_shove.

Member Function Documentation

◆ AbortPlacement()

bool PNS::DIFF_PAIR_PLACER::AbortPlacement ( )
overridevirtual

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 812 of file pns_diff_pair_placer.cpp.

813 {
815  return true;
816 }
NODE * m_world
current routing start point (end of tail, beginning of head)
void KillChildren()
Definition: pns_node.cpp:1369

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 189 of file pns_diff_pair_placer.cpp.

191 {
192  WALKAROUND walkaround( aNode, Router() );
194 
195  walkaround.SetSolidsOnly( aSolidsOnly );
196  walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
197 
198  SHOVE shove( aNode, Router() );
199  LINE walkP, walkN;
200 
201  aWalk = *aCurrent;
202 
203  int iter = 0;
204 
205  DIFF_PAIR cur( *aCurrent );
206 
207  bool currentIsP = aPFirst;
208 
209  int mask = aSolidsOnly ? ITEM::SOLID_T : ITEM::ANY_T;
210 
211  do
212  {
213  LINE preWalk = ( currentIsP ? cur.PLine() : cur.NLine() );
214  LINE preShove = ( currentIsP ? cur.NLine() : cur.PLine() );
215  LINE postWalk;
216 
217  if( !aNode->CheckColliding ( &preWalk, mask ) )
218  {
219  currentIsP = !currentIsP;
220 
221  if( !aNode->CheckColliding( &preShove, mask ) )
222  break;
223  else
224  continue;
225  }
226 
227  wf1 = walkaround.Route( preWalk, postWalk, false );
228 
229  if( wf1 != WALKAROUND::DONE )
230  return false;
231 
232  LINE postShove( preShove );
233 
234  shove.ForceClearance( true, cur.Gap() - 2 * PNS_HULL_MARGIN );
235 
237 
238  sh1 = shove.ShoveObstacleLine( postWalk, preShove, postShove );
239 
240  if( sh1 != SHOVE::SH_OK )
241  return false;
242 
243  postWalk.Line().Simplify();
244  postShove.Line().Simplify();
245 
246  cur.SetShape( postWalk.CLine(), postShove.CLine(), !currentIsP );
247 
248  currentIsP = !currentIsP;
249 
250  if( !aNode->CheckColliding( &postShove, mask ) )
251  break;
252 
253  iter++;
254  }
255  while( iter < 3 );
256 
257  if( iter == 3 )
258  return false;
259 
260  aWalk.SetShape( cur.CP(), cur.CN() );
261 
262  return true;
263 }
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
#define PNS_HULL_MARGIN
Definition: pns_line.h:44
ROUTING_SETTINGS & Settings() const
Return the logger object, allowing to dump geometry to a file.

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::WALKAROUND::Route(), PNS::ALGO_BASE::Router(), PNS::WALKAROUND::SetIterationLimit(), PNS::DIFF_PAIR::SetShape(), PNS::WALKAROUND::SetSolidsOnly(), PNS::ALGO_BASE::Settings(), PNS::SHOVE::SH_OK, PNS::SHOVE::ShoveObstacleLine(), 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 826 of file pns_diff_pair_placer.cpp.

827 {
828  if( m_lastNode )
830 
831  m_lastNode = NULL;
833  return true;
834 }
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
void CommitRouting()
Definition: pns_router.cpp:694
#define NULL
NODE * m_currentNode
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

Return 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 110 of file pns_diff_pair_placer.h.

111  {
112  return m_currentEnd;
113  }

References m_currentEnd.

◆ CurrentLayer()

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

Return the layer of currently routed track.

Implements PNS::PLACEMENT_ALGO.

Definition at line 123 of file pns_diff_pair_placer.h.

124  {
125  return m_currentLayer;
126  }

References m_currentLayer.

◆ CurrentNets()

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

Return the net code of currently routed track.

Implements PNS::PLACEMENT_ALGO.

Definition at line 857 of file pns_diff_pair_placer.cpp.

858 {
859  std::vector<int> rv;
860  rv.push_back( m_netP );
861  rv.push_back( m_netN );
862  return rv;
863 }

References m_netN, and m_netP.

◆ CurrentNode()

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

Return the most recent world state.

Implements PNS::PLACEMENT_ALGO.

Definition at line 400 of file pns_diff_pair_placer.cpp.

401 {
402  if( m_lastNode )
403  return m_lastNode;
404 
405  return m_currentNode;
406 }
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)

References m_currentNode, and m_lastNode.

◆ Dbg()

◆ FindDpPrimitivePair()

bool PNS::DIFF_PAIR_PLACER::FindDpPrimitivePair ( NODE aWorld,
const VECTOR2I aP,
ITEM aItem,
DP_PRIMITIVE_PAIR aPair,
wxString *  aErrorMsg = nullptr 
)
static

Definition at line 465 of file pns_diff_pair_placer.cpp.

467 {
468  int netP, netN;
469 
470  bool result = aWorld->GetRuleResolver()->DpNetPair( aItem, netP, netN );
471 
472  if( !result )
473  {
474  if( aErrorMsg )
475  {
476  *aErrorMsg = _( "Unable to find complementary differential pair "
477  "nets. Make sure the names of the nets belonging "
478  "to a differential pair end with either N/P or +/-." );
479  }
480  return false;
481  }
482 
483  int refNet = aItem->Net();
484  int coupledNet = ( refNet == netP ) ? netN : netP;
485 
486  OPT_VECTOR2I refAnchor = getDanglingAnchor( aWorld, aItem );
487  ITEM* primRef = aItem;
488 
489  if( !refAnchor )
490  {
491  if( aErrorMsg )
492  {
493  *aErrorMsg = _( "Can't find a suitable starting point. If starting "
494  "from an existing differential pair make sure you are "
495  "at the end." );
496  }
497  return false;
498  }
499 
500  std::set<ITEM*> coupledItems;
501 
502  aWorld->AllItemsInNet( coupledNet, coupledItems );
503  double bestDist = std::numeric_limits<double>::max();
504  bool found = false;
505 
506  for( ITEM* item : coupledItems )
507  {
508  if( item->Kind() == aItem->Kind() )
509  {
510  OPT_VECTOR2I anchor = getDanglingAnchor( aWorld, item );
511  if( !anchor )
512  continue;
513 
514  double dist = ( *anchor - *refAnchor ).EuclideanNorm();
515 
516  bool shapeMatches = true;
517 
518  if( item->OfKind( ITEM::SOLID_T | ITEM::VIA_T ) && item->Layers() != aItem->Layers() )
519  {
520  shapeMatches = false;
521  }
522 
523  if( dist < bestDist && shapeMatches )
524  {
525  found = true;
526  bestDist = dist;
527 
528  if( refNet != netP )
529  {
530  aPair = DP_PRIMITIVE_PAIR ( item, primRef );
531  aPair.SetAnchors( *anchor, *refAnchor );
532  }
533  else
534  {
535  aPair = DP_PRIMITIVE_PAIR( primRef, item );
536  aPair.SetAnchors( *refAnchor, *anchor );
537  }
538  }
539  }
540  }
541 
542  if( !found )
543  {
544  if( aErrorMsg )
545  {
546  *aErrorMsg = wxString::Format( _( "Can't find a suitable starting point "
547  "for coupled net \"%s\"." ),
548  aWorld->GetRuleResolver()->NetName( coupledNet ) );
549  }
550  return false;
551  }
552 
553  return true;
554 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:38
OPT_VECTOR2I getDanglingAnchor(NODE *aNode, ITEM *aItem)
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

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

Referenced by PNS::ROUTER::isStartingPointRoutable(), routeHead(), and Start().

◆ FixRoute()

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

Commit 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 committed. May return false if the routing result is violating design rules. In such cases, the track is only committed if #Settings.CanViolateDRC() is on.

Implements PNS::PLACEMENT_ALGO.

Definition at line 746 of file pns_diff_pair_placer.cpp.

747 {
748  if( !m_fitOk && !Settings().AllowDRCViolations() )
749  return false;
750 
752  return false;
753 
754  if( m_currentTrace.CP().SegmentCount() > 1 )
755  m_initialDiagonal = !DIRECTION_45( m_currentTrace.CP().CSegment( -2 ) ).IsDiagonal();
756 
757  TOPOLOGY topo( m_lastNode );
758 
759  if( !m_snapOnTarget && !m_currentTrace.EndsWithVias() && !aForceFinish &&
761  {
764 
765  if( newP.SegmentCount() > 1 && newN.SegmentCount() > 1 )
766  {
767  newP.Remove( -1, -1 );
768  newN.Remove( -1, -1 );
769  }
770 
771  m_currentTrace.SetShape( newP, newN );
772  }
773 
775  {
778  m_chainedPlacement = false;
779  }
780  else
781  {
782  m_chainedPlacement = !m_snapOnTarget && !aForceFinish;
783  }
784 
785  LINE lineP( m_currentTrace.PLine() );
786  LINE lineN( m_currentTrace.NLine() );
787 
788  m_lastNode->Add( lineP );
789  m_lastNode->Add( lineN );
790 
791  topo.SimplifyLine( &lineP );
792  topo.SimplifyLine( &lineN );
793 
795 
796  CommitPlacement();
797  m_placingVia = false;
798 
799  if( m_snapOnTarget || aForceFinish )
800  {
801  m_idle = true;
802  return true;
803  }
804  else
805  {
806  initPlacement();
807  return false;
808  }
809 }
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
Return the logger object, allowing to dump geometry to a file.
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:36
bool m_placingVia
current via diameter
void Remove(int aStartIndex, int aEndIndex)
Function Remove()
int SegmentCount() const
Function SegmentCount()
const SHAPE_LINE_CHAIN & CP() const
const SEG CSegment(int aIndex) const
Function CSegment()
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:265
SHAPE_LINE_CHAIN.
void initPlacement()
Initialize placement of a new line with given parameters.
OPT< DP_PRIMITIVE_PAIR > m_prevPair
current algorithm iteration
const VIA & Via() const
Definition: pns_line.h:196
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition: pns_node.cpp:621
DP_PRIMITIVE_PAIR EndingPrimitives()

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(), PNS::ROUTING_SETTINGS::GetFixAllSegments(), 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

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

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 391 of file pns_diff_pair_placer.cpp.

392 {
394 
395  if( !m_idle )
396  Move( m_currentEnd, NULL );
397 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL).

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

◆ gap()

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

Definition at line 564 of file pns_diff_pair_placer.cpp.

565 {
567 }
SIZES_SETTINGS m_sizes
Are we placing a via?

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

Referenced by routeHead().

◆ 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 837 of file pns_diff_pair_placer.cpp.

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

References m_netN, and m_netP.

◆ HasPlacedAnything()

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

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 819 of file pns_diff_pair_placer.cpp.

820 {
821  return m_currentTrace.CP().SegmentCount() > 0 ||
823 }
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

Initialize placement of a new line with given parameters.

Definition at line 597 of file pns_diff_pair_placer.cpp.

598 {
599  m_idle = false;
600  m_orthoMode = false;
603 
604  NODE* world = Router()->GetWorld();
605 
606  world->KillChildren();
607  NODE* rootNode = world->Branch();
608 
609  setWorld( rootNode );
610 
611  m_lastNode = NULL;
612  m_currentNode = rootNode;
614 
615  if( m_shove )
616  delete m_shove;
617 
618  m_shove = NULL;
619 
621  {
622  m_shove = new SHOVE( m_currentNode, Router() );
623  }
624 }
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
SHOVE * m_shove
Current world state.
ROUTING_SETTINGS & Settings() const
Return the logger object, allowing to dump geometry to a file.
void KillChildren()
Definition: pns_node.cpp:1369
#define NULL
PNS_MODE Mode() const
Set the routing mode.
Guess what's better, try to make least mess on the PCB.
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
void setWorld(NODE *aWorld)
Set the board to route.
NODE * GetWorld() const
Definition: pns_router.h:153

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

◆ 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 145 of file pns_diff_pair_placer.h.

145 { return m_placingVia; }
bool m_placingVia
current via diameter

References m_placingVia.

◆ Logger()

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

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::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), PNS::DRAGGER::Start(), and PNS::DRAGGER::tryWalkaround().

◆ makeVia()

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

Definition at line 74 of file pns_diff_pair_placer.cpp.

75 {
77 
78  VIA v( aP, layers, m_sizes.ViaDiameter(), m_sizes.ViaDrill(), -1, m_sizes.ViaType() );
79  v.SetNet( aNet );
80 
81  return v;
82 }
SIZES_SETTINGS m_sizes
Are we placing a via?
VIATYPE ViaType() const
Normal via.
Definition: router_tool.cpp:70
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31

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

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

Implements PNS::PLACEMENT_ALGO.

Definition at line 706 of file pns_diff_pair_placer.cpp.

707 {
708  m_currentEndItem = aEndItem;
709  m_fitOk = false;
710 
711  delete m_lastNode;
712  m_lastNode = NULL;
713 
714  bool retval = route( aP );
715 
716  NODE* latestNode = m_currentNode;
717  m_lastNode = latestNode->Branch();
718 
719  assert( m_lastNode != NULL );
720  m_currentEnd = aP;
721 
723 
724  return retval;
725 }
bool route(const VECTOR2I &aP)
Re-route the current track to point aP.
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:127
#define NULL
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
void updateLeadingRatLine()
Draw the "leading" ratsnest line, which connects the end of currently routed track and the nearest ye...

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

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

◆ propagateDpHeadForces()

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

Definition at line 119 of file pns_diff_pair_placer.cpp.

120 {
121  VIA virtHead = makeVia( aP, -1 );
122 
123  if( m_placingVia )
124  virtHead.SetDiameter( viaGap() + 2 * virtHead.Diameter() );
125  else
126  {
127  virtHead.SetLayer( m_currentLayer );
128  virtHead.SetDiameter( m_sizes.DiffPairGap() + 2 * m_sizes.DiffPairWidth() );
129  }
130 
131  bool solidsOnly = true;
132 
134  {
135  aNewP = aP;
136  return true;
137  }
138  else if( m_currentMode == RM_Walkaround )
139  {
140  solidsOnly = false;
141  }
142 
143  // fixme: I'm too lazy to do it well. Circular approximaton will do for the moment.
144 
145  // Note: this code is lifted from VIA::PushoutForce and then optimized for this use case and to
146  // check proper clearances to the diff pair line. It can be removed if some specialized
147  // pushout for traces / diff pairs is implemented. Just calling VIA::PushoutForce does not work
148  // as the via may have different resolved clearance to items than the diff pair should.
149  int maxIter = 40;
150  int iter = 0;
151  bool collided = false;
152  VECTOR2I force, totalForce;
153  std::set<ITEM*> handled;
154 
155  while( iter < maxIter )
156  {
157  NODE::OPT_OBSTACLE obs = m_currentNode->CheckColliding( &virtHead, solidsOnly ?
158  ITEM::SOLID_T :
159  ITEM::ANY_T );
160  if( !obs || handled.count( obs->m_item ) )
161  break;
162 
163  int clearance = m_currentNode->GetClearance( obs->m_item, &m_currentTrace.PLine() );
164 
165  if( obs->m_item->Shape()->Collide( virtHead.Shape(), clearance, &force ) )
166  {
167  collided = true;
168  totalForce += force;
169  virtHead.SetPos( virtHead.Pos() + force );
170  }
171 
172  handled.insert( obs->m_item );
173 
174  iter++;
175  }
176 
177  bool succeeded = ( !collided || iter != maxIter );
178 
179  if( succeeded )
180  {
181  aNewP = aP + force;
182  return true;
183  }
184 
185  return false;
186 }
SIZES_SETTINGS m_sizes
Are we placing a via?
const VIA makeVia(const VECTOR2I &aP, int aNet)
int GetClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_node.cpp:100
Normal via.
Definition: router_tool.cpp:70
bool m_placingVia
current via diameter
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
Ignore collisions, mark obstacles.
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition: pns_node.cpp:433
Only walk around.
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:147

References PNS::ITEM::ANY_T, PNS::NODE::CheckColliding(), PNS::VIA::Diameter(), PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), PNS::NODE::GetClearance(), m_currentLayer, m_currentMode, m_currentNode, m_currentTrace, m_placingVia, m_sizes, makeVia(), PNS::DIFF_PAIR::PLine(), PNS::VIA::Pos(), PNS::RM_MarkObstacles, PNS::RM_Walkaround, PNS::VIA::SetDiameter(), PNS::ITEM::SetLayer(), PNS::VIA::SetPos(), PNS::VIA::Shape(), PNS::ITEM::SOLID_T, and viaGap().

Referenced by routeHead().

◆ rhMarkObstacles()

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

Definition at line 105 of file pns_diff_pair_placer.cpp.

106 {
107  if( !routeHead( aP ) )
108  return false;
109 
110  bool collP = static_cast<bool>( m_currentNode->CheckColliding( &m_currentTrace.PLine() ) );
111  bool collN = static_cast<bool>( m_currentNode->CheckColliding( &m_currentTrace.NLine() ) );
112 
113  m_fitOk = !( collP || collN ) ;
114 
115  return m_fitOk;
116 }
bool routeHead(const VECTOR2I &aP)
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition: pns_node.cpp:433

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, mark obstacles mode

Definition at line 340 of file pns_diff_pair_placer.cpp.

341 {
343 
344  bool ok = routeHead( aP );
345 
346  m_fitOk = false;
347 
348  if( !ok )
349  return false;
350 
351  if( !tryWalkDp( m_currentNode, m_currentTrace, true ) )
352  return false;
353 
354  LINE pLine( m_currentTrace.PLine() );
355  LINE nLine( m_currentTrace.NLine() );
356  ITEM_SET head;
357 
358  head.Add( &pLine );
359  head.Add( &nLine );
360 
361  SHOVE::SHOVE_STATUS status = m_shove->ShoveMultiLines( head );
362 
364 
365  if( status == SHOVE::SH_OK )
366  {
368 
371  {
372  m_fitOk = true;
373  }
374  }
375 
376  return m_fitOk;
377 }
SHOVE * m_shove
Current world state.
bool routeHead(const VECTOR2I &aP)
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition: pns_node.cpp:433
bool tryWalkDp(NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)
route step, walk around mode
SHOVE_STATUS ShoveMultiLines(const ITEM_SET &aHeadSet)
Definition: pns_shove.cpp:1483
NODE * CurrentNode()
Definition: pns_shove.cpp:1753

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, shove mode

Definition at line 311 of file pns_diff_pair_placer.cpp.

312 {
313  if( !routeHead ( aP ) )
314  return false;
315 
317 
318  return m_fitOk;
319 }
bool routeHead(const VECTOR2I &aP)
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
bool tryWalkDp(NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)
route step, walk around mode

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

Referenced by route().

◆ route()

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

Re-route 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
aPis the ending point of current route.
Returns
true if the routing is complete.

Definition at line 322 of file pns_diff_pair_placer.cpp.

323 {
324  switch( m_currentMode )
325  {
326  case RM_MarkObstacles:
327  return rhMarkObstacles( aP );
328  case RM_Walkaround:
329  return rhWalkOnly( aP );
330  case RM_Shove:
331  return rhShoveOnly( aP );
332  default:
333  break;
334  }
335 
336  return false;
337 }
bool rhWalkOnly(const VECTOR2I &aP)
route step, shove mode
bool rhShoveOnly(const VECTOR2I &aP)
route step, mark obstacles mode
Ignore collisions, mark obstacles.
Only walk around.
bool rhMarkObstacles(const VECTOR2I &aP)

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 627 of file pns_diff_pair_placer.cpp.

628 {
629  m_fitOk = false;
630 
631  DP_GATEWAYS gwsEntry( gap() );
632  DP_GATEWAYS gwsTarget( gap() );
633 
634  if( !m_prevPair )
636 
637  gwsEntry.BuildFromPrimitivePair( *m_prevPair, m_startDiagonal );
638 
639  DP_PRIMITIVE_PAIR target;
640 
642  {
643  gwsTarget.BuildFromPrimitivePair( target, m_startDiagonal );
644  m_snapOnTarget = true;
645  }
646  else
647  {
648  VECTOR2I fp;
649 
650  if( !propagateDpHeadForces( aP, fp ) )
651  return false;
652 
653  VECTOR2I midp, dirV;
654  m_prevPair->CursorOrientation( fp, midp, dirV );
655 
656  VECTOR2I fpProj = SEG( midp, midp + dirV ).LineProject( fp );
657 
658  // compute 'leader point' distance from the cursor (project cursor position
659  // on the extension of the starting segment pair of the DP)
660  int lead_dist = ( fpProj - fp ).EuclideanNorm();
661 
662  gwsTarget.SetFitVias( m_placingVia, m_sizes.ViaDiameter(), viaGap() );
663 
664  // far from the initial segment extension line -> allow a 45-degree obtuse turn
665  if( lead_dist > ( m_sizes.DiffPairGap() + m_sizes.DiffPairWidth() ) / 2 )
666  {
667  gwsTarget.BuildForCursor( fp );
668  }
669  // close to the initial segment extension line -> keep straight part only, project as close
670  // as possible to the cursor
671  else
672  {
673  gwsTarget.BuildForCursor( fpProj );
674  gwsTarget.FilterByOrientation( DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_HALF_FULL,
675  DIRECTION_45( dirV ) );
676  }
677 
678  m_snapOnTarget = false;
679  }
680 
683 
684  bool result = gwsEntry.FitGateways( gwsEntry, gwsTarget, m_startDiagonal, m_currentTrace );
685 
686  if( result )
687  {
688  m_currentTraceOk = true;
692 
693  if( m_placingVia )
694  {
696  makeVia( m_currentTrace.CN().CPoint( -1 ), m_netN ) );
697  }
698 
699  return true;
700  }
701 
702  return m_currentTraceOk;
703 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
SIZES_SETTINGS m_sizes
Are we placing a via?
void SetLayer(int aLayer)
Definition: pns_item.h:155
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()
void SetGap(int aGap)
bool propagateDpHeadForces(const VECTOR2I &aP, VECTOR2I &aNewP)
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.cpp:268
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:36
bool m_placingVia
current via diameter
void SetWidth(int aWidth)
Definition: seg.h:40
const SHAPE_LINE_CHAIN & CP() const
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
static bool FindDpPrimitivePair(NODE *aWorld, const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
OPT< DP_PRIMITIVE_PAIR > m_prevPair
current algorithm iteration
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_currentNode, m_currentTrace, m_currentTraceOk, 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

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

Definition at line 73 of file pns_algo_base.h.

74  {
75  m_debugDecorator = aDecorator;
76  }
DEBUG_DECORATOR * m_debugDecorator
Definition: pns_algo_base.h:86

References PNS::ALGO_BASE::m_debugDecorator.

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

◆ setInitialDirection()

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

Set 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

Set the current routing layer.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 409 of file pns_diff_pair_placer.cpp.

410 {
411  if( m_idle )
412  {
413  m_currentLayer = aLayer;
414  return true;
415  }
416  else if( m_chainedPlacement || !m_prevPair )
417  {
418  return false;
419  }
420  else if( !m_prevPair->PrimP() || ( m_prevPair->PrimP()->OfKind( ITEM::VIA_T ) &&
421  m_prevPair->PrimP()->Layers().Overlaps( aLayer ) ) )
422  {
423  m_currentLayer = aLayer;
424  m_start = *m_prevPair;
425  initPlacement();
426  Move( m_currentEnd, NULL );
427  return true;
428  }
429 
430  return false;
431 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL).
void initPlacement()
Initialize placement of a new line with given parameters.
OPT< DP_PRIMITIVE_PAIR > m_prevPair
current algorithm iteration

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 65 of file pns_algo_base.h.

66  {
67  m_logger = aLogger;
68  }
LOGGER * m_logger
Definition: pns_algo_base.h:88

References PNS::ALGO_BASE::m_logger.

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

◆ 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 85 of file pns_diff_pair_placer.cpp.

86 {
87  m_orthoMode = aOrthoMode;
88 
89  if( !m_idle )
91 }
#define NULL
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL).

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

◆ Settings()

◆ setWorld()

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

Set the board to route.

Definition at line 69 of file pns_diff_pair_placer.cpp.

70 {
71  m_world = aWorld;
72 }
NODE * m_world
current routing start point (end of tail, beginning of head)

References m_world.

Referenced by initPlacement(), and Start().

◆ Start()

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

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

Implements PNS::PLACEMENT_ALGO.

Definition at line 570 of file pns_diff_pair_placer.cpp.

571 {
572  VECTOR2I p( aP );
573 
574  setWorld( Router()->GetWorld() );
576 
577  if( !FindDpPrimitivePair( m_currentNode, aP, aStartItem, m_start ) )
578  return false;
579 
580  m_netP = m_start.PrimP()->Net();
581  m_netN = m_start.PrimN()->Net();
582 
583  m_currentStart = p;
584  m_currentEnd = p;
585  m_placingVia = false;
586  m_chainedPlacement = false;
587  m_currentTraceOk = false;
588  m_currentTrace = DIFF_PAIR();
590 
591  initPlacement();
592 
593  return true;
594 }
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
NODE * m_world
current routing start point (end of tail, beginning of head)
ITEM * PrimP() const
int Net() const
Definition: pns_item.h:150
bool m_placingVia
current via diameter
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
ITEM * PrimN() const
void initPlacement()
Initialize placement of a new line with given parameters.
static bool FindDpPrimitivePair(NODE *aWorld, const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
void setWorld(NODE *aWorld)
Set the board to route.
void SetNets(int aP, int aN)

References FindDpPrimitivePair(), initPlacement(), m_chainedPlacement, m_currentEnd, m_currentNode, m_currentStart, m_currentTrace, m_currentTraceOk, m_netN, m_netP, m_placingVia, m_start, m_world, PNS::ITEM::Net(), PNS::DP_PRIMITIVE_PAIR::PrimN(), PNS::DP_PRIMITIVE_PAIR::PrimP(), PNS::ALGO_BASE::Router(), PNS::DIFF_PAIR::SetNets(), and setWorld().

◆ ToggleVia()

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

Enable/disable a via at the end of currently routed trace.

Reimplemented from PNS::PLACEMENT_ALGO.

Definition at line 94 of file pns_diff_pair_placer.cpp.

95 {
96  m_placingVia = aEnabled;
97 
98  if( !m_idle )
100 
101  return true;
102 }
#define NULL
bool m_placingVia
current via diameter
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL).

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

◆ Traces()

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

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

Implements PNS::PLACEMENT_ALGO.

Definition at line 380 of file pns_diff_pair_placer.cpp.

381 {
382  ITEM_SET t;
383 
384  t.Add( &m_currentTrace.PLine() );
385  t.Add( &m_currentTrace.NLine() );
386 
387  return t;
388 }

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

route step, walk around mode

Definition at line 266 of file pns_diff_pair_placer.cpp.

267 {
268  DIFF_PAIR best;
269  double bestScore = 100000000000000.0;
270 
271  for( int attempt = 0; attempt <= 3; attempt++ )
272  {
273  DIFF_PAIR p;
274  NODE *tmp = m_currentNode->Branch();
275 
276  bool pfirst = ( attempt & 1 ) ? true : false;
277  bool wind_cw = ( attempt & 2 ) ? true : false;
278 
279  if( attemptWalk( tmp, &aPair, p, pfirst, wind_cw, aSolidsOnly ) )
280  {
281  // double len = p.TotalLength();
282  double cl = p.CoupledLength();
283  double skew = p.Skew();
284 
285  double score = cl + fabs( skew ) * 3.0;
286 
287  if( score < bestScore )
288  {
289  bestScore = score;
290  best = p;
291  }
292  }
293 
294  delete tmp;
295  }
296 
297  if( bestScore > 0.0 )
298  {
299  OPTIMIZER optimizer( m_currentNode );
300 
301  aPair.SetShape( best );
302  optimizer.Optimize( &aPair );
303 
304  return true;
305  }
306 
307  return false;
308 }
bool attemptWalk(NODE *aNode, DIFF_PAIR *aCurrent, DIFF_PAIR &aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly)
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:127
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)

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

Draw 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 844 of file pns_diff_pair_placer.cpp.

845 {
846  SHAPE_LINE_CHAIN ratLineN, ratLineP;
847  TOPOLOGY topo( m_lastNode );
848 
849  if( topo.LeadingRatLine( &m_currentTrace.PLine(), ratLineP ) )
850  m_router->GetInterface()->DisplayRatline( ratLineP, 1 );
851 
852  if( topo.LeadingRatLine ( &m_currentTrace.NLine(), ratLineN ) )
853  m_router->GetInterface()->DisplayRatline( ratLineN, 3 );
854 }
virtual void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, int aColor=-1)=0
ROUTER * m_router
Definition: pns_algo_base.h:87
SHAPE_LINE_CHAIN.
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:210

References PNS::ROUTER_IFACE::DisplayRatline(), PNS::ROUTER::GetInterface(), PNS::TOPOLOGY::LeadingRatLine(), m_currentTrace, m_lastNode, PNS::ALGO_BASE::m_router, PNS::DIFF_PAIR::NLine(), and PNS::DIFF_PAIR::PLine().

Referenced by Move().

◆ UpdateSizes()

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

Perform 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 728 of file pns_diff_pair_placer.cpp.

729 {
730  m_sizes = aSizes;
731 
732  if( !m_idle )
733  {
736 
738  {
741  }
742  }
743 }
SIZES_SETTINGS m_sizes
Are we placing a via?
bool EndsWithVias() const
void SetGap(int aGap)
void SetViaDiameter(int aDiameter)
void SetWidth(int aWidth)
void SetViaDrill(int aDrill)

References PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), PNS::DIFF_PAIR::EndsWithVias(), m_currentTrace, m_idle, m_sizes, PNS::DIFF_PAIR::SetGap(), PNS::DIFF_PAIR::SetViaDiameter(), PNS::DIFF_PAIR::SetViaDrill(), PNS::DIFF_PAIR::SetWidth(), PNS::SIZES_SETTINGS::ViaDiameter(), and PNS::SIZES_SETTINGS::ViaDrill().

◆ viaGap()

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

◆ VisibleViewArea()

const BOX2I & PNS::ALGO_BASE::VisibleViewArea ( ) const
inherited

Definition at line 39 of file pns_algo_base.cpp.

40 {
41  return m_router->VisibleViewArea();
42 }
ROUTER * m_router
Definition: pns_algo_base.h:87
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:220

References PNS::ALGO_BASE::m_router, and PNS::ROUTER::VisibleViewArea().

Referenced by PNS::DRAGGER::optimizeAndUpdateDraggedLine(), and PNS::SHOVE::runOptimizer().

Member Data Documentation

◆ m_chainedPlacement

bool PNS::DIFF_PAIR_PLACER::m_chainedPlacement
private

Definition at line 217 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 270 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 259 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_currentNode

NODE* PNS::DIFF_PAIR_PLACER::m_currentNode
private

Postprocessed world state (including marked collisions & removed loops)

Definition at line 240 of file pns_diff_pair_placer.h.

Referenced by CommitPlacement(), CurrentNode(), DIFF_PAIR_PLACER(), initPlacement(), Move(), propagateDpHeadForces(), rhMarkObstacles(), rhShoveOnly(), rhWalkOnly(), routeHead(), Start(), and tryWalkDp().

◆ m_currentStart

VECTOR2I PNS::DIFF_PAIR_PLACER::m_currentStart
private

Definition at line 266 of file pns_diff_pair_placer.h.

Referenced by Start().

◆ m_currentTrace

◆ m_currentTraceOk

bool PNS::DIFF_PAIR_PLACER::m_currentTraceOk
private

Definition at line 268 of file pns_diff_pair_placer.h.

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

◆ m_currentWidth

int PNS::DIFF_PAIR_PLACER::m_currentWidth
private

Definition at line 257 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 86 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 218 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

pointer to world to search colliding items

Definition at line 228 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_lastNode

NODE* PNS::DIFF_PAIR_PLACER::m_lastNode
private

◆ m_logger

LOGGER* PNS::ALGO_BASE::m_logger
protectedinherited

Definition at line 88 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::SetLogger().

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

The shove engine.

Definition at line 234 of file pns_diff_pair_placer.h.

◆ m_placingVia

bool PNS::DIFF_PAIR_PLACER::m_placingVia
private

current via diameter

Definition at line 248 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

current algorithm iteration

Definition at line 225 of file pns_diff_pair_placer.h.

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

◆ m_router

◆ m_shove

SHOVE* PNS::DIFF_PAIR_PLACER::m_shove
private

Current world state.

Definition at line 237 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

Are we placing a via?

Definition at line 245 of file pns_diff_pair_placer.h.

Referenced by gap(), makeVia(), propagateDpHeadForces(), routeHead(), UpdateSizes(), and viaGap().

◆ m_snapOnTarget

bool PNS::DIFF_PAIR_PLACER::m_snapOnTarget
private

Definition at line 264 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 224 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 219 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 262 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 215 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_viaDiameter

int PNS::DIFF_PAIR_PLACER::m_viaDiameter
private

current via drill

Definition at line 251 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_viaDrill

int PNS::DIFF_PAIR_PLACER::m_viaDrill
private

current track width

Definition at line 254 of file pns_diff_pair_placer.h.

Referenced by DIFF_PAIR_PLACER().

◆ m_world

NODE* PNS::DIFF_PAIR_PLACER::m_world
private

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

Definition at line 231 of file pns_diff_pair_placer.h.

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


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