KiCad PCB EDA Suite
PNS::ROUTER Class Reference

#include <pns_router.h>

Public Member Functions

 ROUTER ()
 
 ~ROUTER ()
 
void SetInterface (ROUTER_IFACE *aIface)
 
void SetMode (ROUTER_MODE aMode)
 
ROUTER_MODE Mode () const
 
void ClearWorld ()
 
void SyncWorld ()
 
void SetView (KIGFX::VIEW *aView)
 
bool RoutingInProgress () const
 
bool StartRouting (const VECTOR2I &aP, ITEM *aItem, int aLayer)
 
void Move (const VECTOR2I &aP, ITEM *aItem)
 
bool FixRoute (const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
 
void BreakSegment (ITEM *aItem, const VECTOR2I &aP)
 
void UndoLastSegment ()
 
void CommitRouting ()
 
void StopRouting ()
 
int GetClearance (const ITEM *aA, const ITEM *aB) const
 
NODEGetWorld () const
 
void FlipPosture ()
 
void DisplayItem (const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)
 
void DisplayItems (const ITEM_SET &aItems)
 
void DeleteTraces (ITEM *aStartItem, bool aWholeTrack)
 
void SwitchLayer (int layer)
 
void ToggleViaPlacement ()
 
void SetOrthoMode (bool aEnable)
 
void ToggleRounded ()
 
int GetCurrentLayer () const
 
const std::vector< int > GetCurrentNets () const
 
void DumpLog ()
 
LOGGERLogger ()
 
RULE_RESOLVERGetRuleResolver () const
 
bool IsPlacingVia () const
 
const ITEM_SET QueryHoverItems (const VECTOR2I &aP)
 
const VECTOR2I SnapToItem (ITEM *aItem, VECTOR2I aP, bool &aSplitsSegment)
 
bool StartDragging (const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
 
bool StartDragging (const VECTOR2I &aP, ITEM_SET aItems, int aDragMode=DM_COMPONENT)
 
void SetIterLimit (int aX)
 
int GetIterLimit () const
 
void SetShowIntermediateSteps (bool aX, int aSnapshotIter=-1)
 
bool GetShowIntermediateSteps () const
 
int GetShapshotIter () const
 
ROUTING_SETTINGSSettings ()
 
void CommitRouting (NODE *aNode)
 
void UpdateSizes (const SIZES_SETTINGS &aSizes)
 Applies stored settings. More...
 
void LoadSettings (ROUTING_SETTINGS *aSettings)
 Changes routing settings to ones passed in the parameter. More...
 
SIZES_SETTINGSSizes ()
 
ITEMQueryItemByParent (const BOARD_ITEM *aItem) const
 
void SetFailureReason (const wxString &aReason)
 
const wxString & FailureReason () const
 
PLACEMENT_ALGOPlacer ()
 
ROUTER_IFACEGetInterface () const
 

Static Public Member Functions

static ROUTERGetInstance ()
 

Private Types

enum  RouterState { IDLE, DRAG_SEGMENT, ROUTE_TRACK }
 

Private Member Functions

void movePlacing (const VECTOR2I &aP, ITEM *aItem)
 
void moveDragging (const VECTOR2I &aP, ITEM *aItem)
 
void eraseView ()
 
void updateView (NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
 
void clearViewFlags ()
 
ITEMpickSingleItem (ITEM_SET &aItems) const
 
void splitAdjacentSegments (NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
 
ITEMsyncPad (D_PAD *aPad)
 
ITEMsyncTrack (TRACK *aTrack)
 
ITEMsyncVia (VIA *aVia)
 
void commitPad (SOLID *aPad)
 
void commitSegment (SEGMENT *aTrack)
 
void commitVia (VIA *aVia)
 
void highlightCurrent (bool enabled)
 
void markViolations (NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
 
bool isStartingPointRoutable (const VECTOR2I &aWhere, int aLayer)
 

Private Attributes

VECTOR2I m_currentEnd
 
RouterState m_state
 
std::unique_ptr< NODEm_world
 
NODEm_lastNode
 
std::unique_ptr< PLACEMENT_ALGOm_placer
 
std::unique_ptr< DRAG_ALGOm_dragger
 
std::unique_ptr< SHOVEm_shove
 
ROUTER_IFACEm_iface
 
int m_iterLimit
 
bool m_showInterSteps
 
int m_snapshotIter
 
bool m_violation
 
bool m_forceMarkObstaclesMode = false
 
ROUTING_SETTINGSm_settings
 
SIZES_SETTINGS m_sizes
 
ROUTER_MODE m_mode
 
LOGGERm_logger
 
wxString m_toolStatusbarName
 
wxString m_failureReason
 

Detailed Description

Definition at line 117 of file pns_router.h.

Member Enumeration Documentation

◆ RouterState

Enumerator
IDLE 
DRAG_SEGMENT 
ROUTE_TRACK 

Definition at line 120 of file pns_router.h.

Constructor & Destructor Documentation

◆ ROUTER()

PNS::ROUTER::ROUTER ( )

Definition at line 65 of file pns_router.cpp.

66 {
67  theRouter = this;
68 
69  m_state = IDLE;
71 
72  m_logger = new LOGGER;
73 
74  // Initialize all other variables:
75  m_lastNode = nullptr;
76  m_iterLimit = 0;
77  m_settings = nullptr;
78  m_showInterSteps = false;
79  m_snapshotIter = 0;
80  m_violation = false;
81  m_iface = nullptr;
82 }
int m_snapshotIter
Definition: pns_router.h:279
int m_iterLimit
Definition: pns_router.h:277
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:283
bool m_showInterSteps
Definition: pns_router.h:278
NODE * m_lastNode
Definition: pns_router.h:269
RouterState m_state
Definition: pns_router.h:266
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
LOGGER * m_logger
Definition: pns_router.h:286
static ROUTER * theRouter
Definition: pns_router.cpp:63
bool m_violation
Definition: pns_router.h:280
ROUTER_MODE m_mode
Definition: pns_router.h:285

References IDLE, m_iface, m_iterLimit, m_lastNode, m_logger, m_mode, m_settings, m_showInterSteps, m_snapshotIter, m_state, m_violation, PNS::PNS_MODE_ROUTE_SINGLE, and PNS::theRouter.

◆ ~ROUTER()

PNS::ROUTER::~ROUTER ( )

Definition at line 91 of file pns_router.cpp.

92 {
93  ClearWorld();
94  theRouter = nullptr;
95  delete m_logger;
96 }
void ClearWorld()
Definition: pns_router.cpp:108
LOGGER * m_logger
Definition: pns_router.h:286
static ROUTER * theRouter
Definition: pns_router.cpp:63

References ClearWorld(), m_logger, and PNS::theRouter.

Member Function Documentation

◆ BreakSegment()

void PNS::ROUTER::BreakSegment ( ITEM aItem,
const VECTOR2I aP 
)

Definition at line 570 of file pns_router.cpp.

571 {
572  NODE *node = m_world->Branch();
573 
574  LINE_PLACER placer( this );
575 
576  if ( placer.SplitAdjacentSegments( node, aItem, aP ) )
577  {
578  CommitRouting( node );
579  }
580  else
581  {
582  delete node;
583  }
584 
585 }
void CommitRouting()
Definition: pns_router.cpp:443
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268

References CommitRouting(), m_world, and PNS::LINE_PLACER::SplitAdjacentSegments().

Referenced by ROUTER_TOOL::breakTrack().

◆ clearViewFlags()

void PNS::ROUTER::clearViewFlags ( )
private

◆ ClearWorld()

void PNS::ROUTER::ClearWorld ( )

Definition at line 108 of file pns_router.cpp.

109 {
110  if( m_world )
111  {
112  m_world->KillChildren();
113  m_world.reset();
114  }
115 
116  m_placer.reset();
117 }
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271

References m_placer, and m_world.

Referenced by ROUTER_TOOL::MainLoop(), PNS::TOOL_BASE::Reset(), SyncWorld(), and ~ROUTER().

◆ commitPad()

void PNS::ROUTER::commitPad ( SOLID aPad)
private

◆ CommitRouting() [1/2]

◆ CommitRouting() [2/2]

void PNS::ROUTER::CommitRouting ( NODE aNode)

Definition at line 387 of file pns_router.cpp.

388 {
389  if( m_state == ROUTE_TRACK && !m_placer->HasPlacedAnything() )
390  return;
391 
392  NODE::ITEM_VECTOR removed, added;
393 
394  aNode->GetUpdatedItems( removed, added );
395 
396  for( auto item : removed )
397  m_iface->RemoveItem( item );
398 
399  for( auto item : added )
400  m_iface->AddItem( item );
401 
402  m_iface->Commit();
403  m_world->Commit( aNode );
404 }
virtual void AddItem(ITEM *aItem)=0
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
virtual void Commit()=0
virtual void RemoveItem(ITEM *aItem)=0
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:149

References PNS::ROUTER_IFACE::AddItem(), PNS::ROUTER_IFACE::Commit(), PNS::NODE::GetUpdatedItems(), m_iface, m_placer, m_state, m_world, PNS::ROUTER_IFACE::RemoveItem(), and ROUTE_TRACK.

◆ commitSegment()

void PNS::ROUTER::commitSegment ( SEGMENT aTrack)
private

◆ commitVia()

void PNS::ROUTER::commitVia ( VIA aVia)
private

◆ DeleteTraces()

void PNS::ROUTER::DeleteTraces ( ITEM aStartItem,
bool  aWholeTrack 
)

◆ DisplayItem()

void PNS::ROUTER::DisplayItem ( const ITEM aItem,
int  aColor = -1,
int  aClearance = -1,
bool  aEdit = false 
)

◆ DisplayItems()

void PNS::ROUTER::DisplayItems ( const ITEM_SET aItems)

Definition at line 250 of file pns_router.cpp.

251 {
252  for( const ITEM* item : aItems.CItems() )
253  m_iface->DisplayItem( item );
254 }
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:275

References PNS::ITEM_SET::CItems(), PNS::ROUTER_IFACE::DisplayItem(), and m_iface.

◆ DumpLog()

void PNS::ROUTER::DumpLog ( )

◆ eraseView()

void PNS::ROUTER::eraseView ( )
private

◆ FailureReason()

const wxString& PNS::ROUTER::FailureReason ( ) const
inline

Definition at line 229 of file pns_router.h.

229 { return m_failureReason; }
wxString m_failureReason
Definition: pns_router.h:289

References m_failureReason.

Referenced by LENGTH_TUNER_TOOL::performTuning(), and ROUTER_TOOL::prepareInteractive().

◆ FixRoute()

bool PNS::ROUTER::FixRoute ( const VECTOR2I aP,
ITEM aItem,
bool  aForceFinish = false 
)

Definition at line 407 of file pns_router.cpp.

408 {
409  bool rv = false;
410 
411  if( m_logger )
412  {
413  m_logger->Log( LOGGER::EVT_FIX, aP, aEndItem );
414  }
415 
416  switch( m_state )
417  {
418  case ROUTE_TRACK:
419  rv = m_placer->FixRoute( aP, aEndItem, aForceFinish );
420  break;
421 
422  case DRAG_SEGMENT:
423  rv = m_dragger->FixRoute();
424  break;
425 
426  default:
427  break;
428  }
429 
430  return rv;
431 }
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:272
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266
LOGGER * m_logger
Definition: pns_router.h:286
void Log(EVENT_TYPE evt, VECTOR2I pos, const ITEM *item=nullptr)
Definition: pns_logger.cpp:73

References DRAG_SEGMENT, PNS::LOGGER::EVT_FIX, PNS::LOGGER::Log(), m_dragger, m_logger, m_placer, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::InlineDrag(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), and LENGTH_TUNER_TOOL::performTuning().

◆ FlipPosture()

void PNS::ROUTER::FlipPosture ( )

Definition at line 480 of file pns_router.cpp.

481 {
482  if( m_state == ROUTE_TRACK )
483  {
484  m_placer->FlipPosture();
485  }
486 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266

References m_placer, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::performRouting().

◆ GetClearance()

int PNS::ROUTER::GetClearance ( const ITEM aA,
const ITEM aB 
) const

◆ GetCurrentLayer()

int PNS::ROUTER::GetCurrentLayer ( ) const

Definition at line 521 of file pns_router.cpp.

522 {
523  if( m_placer )
524  return m_placer->CurrentLayer();
525  return -1;
526 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271

References m_placer.

Referenced by ROUTER_TOOL::onViaCommand(), ROUTER_TOOL::performRouting(), ROUTER_TOOL::switchLayerOnViaPlacement(), and PNS::TOOL_BASE::updateEndItem().

◆ GetCurrentNets()

const std::vector< int > PNS::ROUTER::GetCurrentNets ( ) const

Definition at line 512 of file pns_router.cpp.

513 {
514  if( m_placer )
515  return m_placer->CurrentNets();
516 
517  return std::vector<int>();
518 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271

References m_placer.

Referenced by PNS::TOOL_BASE::updateEndItem().

◆ GetInstance()

ROUTER * PNS::ROUTER::GetInstance ( )
static

Definition at line 85 of file pns_router.cpp.

86 {
87  return theRouter;
88 }
static ROUTER * theRouter
Definition: pns_router.cpp:63

References PNS::theRouter.

Referenced by PNS::POSTURE_SOLVER::AddTrailPoint(), PNS::clipToLoopStart(), PNS::POSTURE_SOLVER::GetPosture(), and PNS::OPTIMIZER::Optimize().

◆ GetInterface()

ROUTER_IFACE* PNS::ROUTER::GetInterface ( ) const
inline

Definition at line 233 of file pns_router.h.

234  {
235  return m_iface;
236  }
ROUTER_IFACE * m_iface
Definition: pns_router.h:275

References m_iface.

Referenced by PNS::POSTURE_SOLVER::AddTrailPoint(), PNS::clipToLoopStart(), PNS::POSTURE_SOLVER::GetPosture(), PNS::OPTIMIZER::Optimize(), and PNS::SHOVE::SHOVE().

◆ GetIterLimit()

int PNS::ROUTER::GetIterLimit ( ) const
inline

Definition at line 191 of file pns_router.h.

191 { return m_iterLimit; };
int m_iterLimit
Definition: pns_router.h:277

References m_iterLimit.

◆ GetRuleResolver()

RULE_RESOLVER* PNS::ROUTER::GetRuleResolver ( ) const
inline

Definition at line 177 of file pns_router.h.

178  {
179  return m_iface->GetRuleResolver();
180  }
virtual RULE_RESOLVER * GetRuleResolver()=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:275

References PNS::ROUTER_IFACE::GetRuleResolver(), and m_iface.

Referenced by movePlacing(), and updateView().

◆ GetShapshotIter()

int PNS::ROUTER::GetShapshotIter ( ) const
inline

Definition at line 200 of file pns_router.h.

200 { return m_snapshotIter; }
int m_snapshotIter
Definition: pns_router.h:279

References m_snapshotIter.

◆ GetShowIntermediateSteps()

bool PNS::ROUTER::GetShowIntermediateSteps ( ) const
inline

Definition at line 199 of file pns_router.h.

199 { return m_showInterSteps; }
bool m_showInterSteps
Definition: pns_router.h:278

References m_showInterSteps.

◆ GetWorld()

◆ highlightCurrent()

void PNS::ROUTER::highlightCurrent ( bool  enabled)
private

◆ IsPlacingVia()

bool PNS::ROUTER::IsPlacingVia ( ) const

Definition at line 535 of file pns_router.cpp.

536 {
537  if( !m_placer )
538  return false;
539 
540  return m_placer->IsPlacingVia();
541 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271

References m_placer.

Referenced by ROUTER_TOOL::onViaCommand(), ROUTER_TOOL::performRouting(), and PNS::TOOL_BASE::updateEndItem().

◆ isStartingPointRoutable()

bool PNS::ROUTER::isStartingPointRoutable ( const VECTOR2I aWhere,
int  aLayer 
)
private

Definition at line 177 of file pns_router.cpp.

178 {
179  if( Settings().CanViolateDRC() && Settings().Mode() == RM_MarkObstacles )
180  return true;
181 
182  auto candidates = QueryHoverItems( aWhere );
183 
184  for( ITEM* item : candidates.Items() )
185  {
186  if( ! item->IsRoutable() && item->Layers().Overlaps( aLayer ) )
187  {
188  return false;
189  }
190  }
191 
192  return true;
193 }
const ITEM_SET QueryHoverItems(const VECTOR2I &aP)
Definition: pns_router.cpp:126
ROUTER_MODE Mode() const
Definition: pns_router.h:133
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:202

References Mode(), QueryHoverItems(), PNS::RM_MarkObstacles, and Settings().

Referenced by StartRouting().

◆ LoadSettings()

void PNS::ROUTER::LoadSettings ( ROUTING_SETTINGS aSettings)
inline

Changes routing settings to ones passed in the parameter.

Parameters
aSettingsare the new settings.

Definition at line 216 of file pns_router.h.

217  {
218  m_settings = aSettings;
219  }
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:283

References m_settings.

Referenced by PNS::TOOL_BASE::Reset().

◆ Logger()

LOGGER * PNS::ROUTER::Logger ( )

Definition at line 529 of file pns_router.cpp.

530 {
531  return m_logger;
532 }
LOGGER * m_logger
Definition: pns_router.h:286

References m_logger.

Referenced by ROUTER_TOOL::handleCommonEvents().

◆ markViolations()

void PNS::ROUTER::markViolations ( NODE aNode,
ITEM_SET aCurrent,
NODE::ITEM_VECTOR aRemoved 
)
private

Definition at line 293 of file pns_router.cpp.

294 {
295  for( ITEM* item : aCurrent.Items() )
296  {
297  NODE::OBSTACLES obstacles;
298 
299  aNode->QueryColliding( item, obstacles, ITEM::ANY_T );
300 
301  if( item->OfKind( ITEM::LINE_T ) )
302  {
303  LINE* l = static_cast<LINE*>( item );
304 
305  if( l->EndsWithVia() )
306  {
307  VIA v( l->Via() );
308  aNode->QueryColliding( &v, obstacles, ITEM::ANY_T );
309  }
310  }
311 
312  for( OBSTACLE& obs : obstacles )
313  {
314  int clearance = aNode->GetClearance( item, obs.m_item );
315  std::unique_ptr<ITEM> tmp( obs.m_item->Clone() );
316  tmp->Mark( MK_VIOLATION );
317  m_iface->DisplayItem( tmp.get(), -1, clearance );
318  aRemoved.push_back( obs.m_item );
319  }
320  }
321 }
virtual int GetClearance(PCB_LAYER_ID aLayer, BOARD_ITEM *aItem=nullptr, wxString *aSource=nullptr) const
Function GetClearance returns the clearance in internal units.
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
std::vector< OBSTACLE > OBSTACLES
Definition: pns_node.h:150

References PNS::ITEM::ANY_T, PNS::ROUTER_IFACE::DisplayItem(), PNS::LINE::EndsWithVia(), PNS::NODE::GetClearance(), PNS::ITEM_SET::Items(), PNS::ITEM::LINE_T, m_iface, PNS::MK_VIOLATION, PNS::NODE::QueryColliding(), and PNS::LINE::Via().

Referenced by updateView().

◆ Mode()

ROUTER_MODE PNS::ROUTER::Mode ( ) const
inline

Definition at line 133 of file pns_router.h.

133 { return m_mode; }
ROUTER_MODE m_mode
Definition: pns_router.h:285

References m_mode.

Referenced by isStartingPointRoutable(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), and updateView().

◆ Move()

void PNS::ROUTER::Move ( const VECTOR2I aP,
ITEM aItem 
)

Definition at line 257 of file pns_router.cpp.

258 {
259  m_currentEnd = aP;
260 
261  if( m_logger )
262  {
263  m_logger->Log( LOGGER::EVT_MOVE, aP, endItem );
264  }
265 
266  switch( m_state )
267  {
268  case ROUTE_TRACK:
269  movePlacing( aP, endItem );
270  break;
271 
272  case DRAG_SEGMENT:
273  moveDragging( aP, endItem );
274  break;
275 
276  default:
277  break;
278  }
279 }
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:282
VECTOR2I m_currentEnd
Definition: pns_router.h:265
RouterState m_state
Definition: pns_router.h:266
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:360
LOGGER * m_logger
Definition: pns_router.h:286
void Log(EVENT_TYPE evt, VECTOR2I pos, const ITEM *item=nullptr)
Definition: pns_logger.cpp:73

References DRAG_SEGMENT, PNS::LOGGER::EVT_MOVE, PNS::LOGGER::Log(), m_currentEnd, m_logger, m_state, moveDragging(), movePlacing(), and ROUTE_TRACK.

Referenced by ROUTER_TOOL::InlineDrag(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), and LENGTH_TUNER_TOOL::performTuning().

◆ moveDragging()

void PNS::ROUTER::moveDragging ( const VECTOR2I aP,
ITEM aItem 
)
private

Definition at line 282 of file pns_router.cpp.

283 {
284  m_iface->EraseView();
285 
286  m_dragger->Drag( aP );
287  ITEM_SET dragged = m_dragger->Traces();
288 
289  updateView( m_dragger->CurrentNode(), dragged, true );
290 }
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:272
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:324
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:147
virtual void EraseView()=0

References PNS::ROUTER_IFACE::EraseView(), m_dragger, m_iface, and updateView().

Referenced by Move().

◆ movePlacing()

void PNS::ROUTER::movePlacing ( const VECTOR2I aP,
ITEM aItem 
)
private

Definition at line 360 of file pns_router.cpp.

361 {
362  m_iface->EraseView();
363 
364  m_placer->Move( aP, aEndItem );
365  ITEM_SET current = m_placer->Traces();
366 
367  for( const ITEM* item : current.CItems() )
368  {
369  if( !item->OfKind( ITEM::LINE_T ) )
370  continue;
371 
372  const LINE* l = static_cast<const LINE*>( item );
373  int clearance = GetRuleResolver()->Clearance( item->Net() );
374 
375  m_iface->DisplayItem( l, -1, clearance );
376 
377  if( l->EndsWithVia() )
378  m_iface->DisplayItem( &l->Via(), -1, clearance );
379  }
380 
381  //ITEM_SET tmp( &current );
382 
383  updateView( m_placer->CurrentNode( true ), current );
384 }
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:177
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:324
virtual int Clearance(const ITEM *aA, const ITEM *aB) const =0
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:147
virtual void EraseView()=0

References PNS::ITEM_SET::CItems(), PNS::RULE_RESOLVER::Clearance(), PNS::ROUTER_IFACE::DisplayItem(), PNS::LINE::EndsWithVia(), PNS::ROUTER_IFACE::EraseView(), GetRuleResolver(), PNS::ITEM::LINE_T, m_iface, m_placer, updateView(), and PNS::LINE::Via().

Referenced by Move().

◆ pickSingleItem()

ITEM* PNS::ROUTER::pickSingleItem ( ITEM_SET aItems) const
private

◆ Placer()

PLACEMENT_ALGO* PNS::ROUTER::Placer ( )
inline

Definition at line 231 of file pns_router.h.

231 { return m_placer.get(); }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271

References m_placer.

Referenced by LENGTH_TUNER_TOOL::meanderSettingsDialog(), LENGTH_TUNER_TOOL::performTuning(), and PNS_TUNE_STATUS_POPUP::UpdateStatus().

◆ QueryHoverItems()

const ITEM_SET PNS::ROUTER::QueryHoverItems ( const VECTOR2I aP)

Definition at line 126 of file pns_router.cpp.

127 {
128  if( m_state == IDLE || m_placer == nullptr )
129  return m_world->HitTest( aP );
130  else
131  return m_placer->CurrentNode()->HitTest( aP );
132 }
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266

References IDLE, m_placer, m_state, and m_world.

Referenced by isStartingPointRoutable(), and PNS::TOOL_BASE::pickSingleItem().

◆ QueryItemByParent()

ITEM* PNS::ROUTER::QueryItemByParent ( const BOARD_ITEM aItem) const

◆ RoutingInProgress()

bool PNS::ROUTER::RoutingInProgress ( ) const

◆ SetFailureReason()

void PNS::ROUTER::SetFailureReason ( const wxString &  aReason)
inline

◆ SetInterface()

void PNS::ROUTER::SetInterface ( ROUTER_IFACE aIface)

Definition at line 565 of file pns_router.cpp.

566 {
567  m_iface = aIface;
568 }
ROUTER_IFACE * m_iface
Definition: pns_router.h:275

References m_iface.

Referenced by PNS::TOOL_BASE::Reset().

◆ SetIterLimit()

void PNS::ROUTER::SetIterLimit ( int  aX)
inline

Definition at line 190 of file pns_router.h.

190 { m_iterLimit = aX; }
int m_iterLimit
Definition: pns_router.h:277

References m_iterLimit.

◆ SetMode()

void PNS::ROUTER::SetMode ( ROUTER_MODE  aMode)

Definition at line 559 of file pns_router.cpp.

560 {
561  m_mode = aMode;
562 }
ROUTER_MODE m_mode
Definition: pns_router.h:285

References m_mode.

Referenced by ROUTER_TOOL::MainLoop(), and LENGTH_TUNER_TOOL::MainLoop().

◆ SetOrthoMode()

void PNS::ROUTER::SetOrthoMode ( bool  aEnable)

Definition at line 550 of file pns_router.cpp.

551 {
552  if( !m_placer )
553  return;
554 
555  m_placer->SetOrthoMode( aEnable );
556 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271

References m_placer.

Referenced by ROUTER_TOOL::performRouting().

◆ SetShowIntermediateSteps()

void PNS::ROUTER::SetShowIntermediateSteps ( bool  aX,
int  aSnapshotIter = -1 
)
inline

Definition at line 193 of file pns_router.h.

194  {
195  m_showInterSteps = aX;
196  m_snapshotIter = aSnapshotIter;
197  }
int m_snapshotIter
Definition: pns_router.h:279
bool m_showInterSteps
Definition: pns_router.h:278

References m_showInterSteps, and m_snapshotIter.

◆ Settings()

◆ SetView()

void PNS::ROUTER::SetView ( KIGFX::VIEW aView)

◆ Sizes()

◆ SnapToItem()

const VECTOR2I PNS::ROUTER::SnapToItem ( ITEM aItem,
VECTOR2I  aP,
bool &  aSplitsSegment 
)

◆ splitAdjacentSegments()

void PNS::ROUTER::splitAdjacentSegments ( NODE aNode,
ITEM aSeg,
const VECTOR2I aP 
)
private

◆ StartDragging() [1/2]

bool PNS::ROUTER::StartDragging ( const VECTOR2I aP,
ITEM aItem,
int  aDragMode = DM_ANY 
)

Definition at line 134 of file pns_router.cpp.

135 {
136  return StartDragging( aP, ITEM_SET( aItem ), aDragMode );
137 }
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:147
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:134

Referenced by ROUTER_TOOL::InlineDrag(), and ROUTER_TOOL::performDragging().

◆ StartDragging() [2/2]

bool PNS::ROUTER::StartDragging ( const VECTOR2I aP,
ITEM_SET  aItems,
int  aDragMode = DM_COMPONENT 
)

Definition at line 140 of file pns_router.cpp.

141 {
142  if( aStartItems.Empty() )
143  return false;
144 
145  if( aStartItems.Count( ITEM::SOLID_T ) == aStartItems.Size() )
146  {
147  m_dragger = std::make_unique<COMPONENT_DRAGGER>( this );
149  }
150  else
151  {
152  if( aDragMode & DM_FREE_ANGLE )
154  else
155  m_forceMarkObstaclesMode = false;
156 
157  m_dragger = std::make_unique<DRAGGER>( this );
158  }
159 
160  m_dragger->SetMode( aDragMode );
161  m_dragger->SetWorld( m_world.get() );
162  m_dragger->SetLogger( m_logger );
163  m_dragger->SetDebugDecorator ( m_iface->GetDebugDecorator () );
164 
165  if( m_dragger->Start ( aP, aStartItems ) )
167  else
168  {
169  m_dragger.reset();
170  m_state = IDLE;
171  return false;
172  }
173 
174  return true;
175 }
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:272
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268
RouterState m_state
Definition: pns_router.h:266
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
LOGGER * m_logger
Definition: pns_router.h:286
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
bool m_forceMarkObstaclesMode
Definition: pns_router.h:281

References PNS::ITEM_SET::Count(), PNS::DM_FREE_ANGLE, DRAG_SEGMENT, PNS::ITEM_SET::Empty(), PNS::ROUTER_IFACE::GetDebugDecorator(), IDLE, m_dragger, m_forceMarkObstaclesMode, m_iface, m_logger, m_state, m_world, PNS::ITEM_SET::Size(), and PNS::ITEM::SOLID_T.

◆ StartRouting()

bool PNS::ROUTER::StartRouting ( const VECTOR2I aP,
ITEM aItem,
int  aLayer 
)

Definition at line 195 of file pns_router.cpp.

196 {
197 
198  if( ! isStartingPointRoutable( aP, aLayer ) )
199  {
200  SetFailureReason( _("Cannot start routing inside a keepout area or board outline." ) );
201  return false;
202  }
203 
204  m_forceMarkObstaclesMode = false;
205 
206  switch( m_mode )
207  {
209  m_placer = std::make_unique<LINE_PLACER>( this );
210  break;
212  m_placer = std::make_unique<DIFF_PAIR_PLACER>( this );
213  break;
215  m_placer = std::make_unique<MEANDER_PLACER>( this );
216  break;
218  m_placer = std::make_unique<DP_MEANDER_PLACER>( this );
219  break;
221  m_placer = std::make_unique<MEANDER_SKEW_PLACER>( this );
222  break;
223 
224  default:
225  return false;
226  }
227 
228  m_placer->UpdateSizes ( m_sizes );
229  m_placer->SetLayer( aLayer );
230  m_placer->SetDebugDecorator ( m_iface->GetDebugDecorator () );
231  m_placer->SetLogger( m_logger );
232 
233  if( m_logger )
234  {
235  m_logger->Log( LOGGER::EVT_START_ROUTE, aP, aStartItem );
236  }
237 
238 
239  bool rv = m_placer->Start( aP, aStartItem );
240 
241  if( !rv )
242  return false;
243 
244  m_currentEnd = aP;
246  return rv;
247 }
bool isStartingPointRoutable(const VECTOR2I &aWhere, int aLayer)
Definition: pns_router.cpp:177
VECTOR2I m_currentEnd
Definition: pns_router.h:265
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:228
RouterState m_state
Definition: pns_router.h:266
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
LOGGER * m_logger
Definition: pns_router.h:286
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
#define _(s)
Definition: 3d_actions.cpp:33
SIZES_SETTINGS m_sizes
Definition: pns_router.h:284
ROUTER_MODE m_mode
Definition: pns_router.h:285
void Log(EVENT_TYPE evt, VECTOR2I pos, const ITEM *item=nullptr)
Definition: pns_logger.cpp:73
bool m_forceMarkObstaclesMode
Definition: pns_router.h:281

References _, PNS::LOGGER::EVT_START_ROUTE, PNS::ROUTER_IFACE::GetDebugDecorator(), isStartingPointRoutable(), PNS::LOGGER::Log(), m_currentEnd, m_forceMarkObstaclesMode, m_iface, m_logger, m_mode, m_placer, m_sizes, m_state, PNS::PNS_MODE_ROUTE_DIFF_PAIR, PNS::PNS_MODE_ROUTE_SINGLE, PNS::PNS_MODE_TUNE_DIFF_PAIR, PNS::PNS_MODE_TUNE_DIFF_PAIR_SKEW, PNS::PNS_MODE_TUNE_SINGLE, ROUTE_TRACK, and SetFailureReason().

Referenced by LENGTH_TUNER_TOOL::performTuning(), and ROUTER_TOOL::prepareInteractive().

◆ StopRouting()

void PNS::ROUTER::StopRouting ( )

Definition at line 452 of file pns_router.cpp.

453 {
454  // Update the ratsnest with new changes
455 
456  if( m_placer )
457  {
458  std::vector<int> nets;
459  m_placer->GetModifiedNets( nets );
460 
461  // Update the ratsnest with new changes
462  for ( auto n : nets )
463  m_iface->UpdateNet( n );
464  }
465 
466  if( !RoutingInProgress() )
467  return;
468 
469  m_placer.reset();
470  m_dragger.reset();
471 
472  m_iface->EraseView();
473 
474  m_state = IDLE;
475  m_world->KillChildren();
476  m_world->ClearRanks();
477 }
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:272
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268
virtual void UpdateNet(int aNetCode)=0
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
virtual void EraseView()=0
bool RoutingInProgress() const
Definition: pns_router.cpp:120

References PNS::ROUTER_IFACE::EraseView(), IDLE, m_dragger, m_iface, m_placer, m_state, m_world, RoutingInProgress(), and PNS::ROUTER_IFACE::UpdateNet().

Referenced by CommitRouting(), ROUTER_TOOL::finishInteractive(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), and LENGTH_TUNER_TOOL::performTuning().

◆ SwitchLayer()

void PNS::ROUTER::SwitchLayer ( int  layer)

Definition at line 489 of file pns_router.cpp.

490 {
491  switch( m_state )
492  {
493  case ROUTE_TRACK:
494  m_placer->SetLayer( aLayer );
495  break;
496  default:
497  break;
498  }
499 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266

References m_placer, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::MainLoop(), ROUTER_TOOL::performRouting(), and ROUTER_TOOL::switchLayerOnViaPlacement().

◆ syncPad()

ITEM* PNS::ROUTER::syncPad ( D_PAD aPad)
private

◆ syncTrack()

ITEM* PNS::ROUTER::syncTrack ( TRACK aTrack)
private

◆ syncVia()

ITEM* PNS::ROUTER::syncVia ( VIA aVia)
private

◆ SyncWorld()

void PNS::ROUTER::SyncWorld ( )

Definition at line 99 of file pns_router.cpp.

100 {
101  ClearWorld();
102 
103  m_world = std::make_unique<NODE>( );
104  m_iface->SyncWorld( m_world.get() );
105 
106 }
void ClearWorld()
Definition: pns_router.cpp:108
std::unique_ptr< NODE > m_world
Definition: pns_router.h:268
virtual void SyncWorld(NODE *aNode)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:275

References ClearWorld(), m_iface, m_world, and PNS::ROUTER_IFACE::SyncWorld().

Referenced by ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), ROUTER_TOOL::MainLoop(), and PNS::TOOL_BASE::Reset().

◆ ToggleRounded()

void PNS::ROUTER::ToggleRounded ( )

Definition at line 544 of file pns_router.cpp.

545 {
547 }
void SetRounded(bool aRound)
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:283

References PNS::ROUTING_SETTINGS::GetRounded(), m_settings, and PNS::ROUTING_SETTINGS::SetRounded().

Referenced by ROUTER_TOOL::performRouting().

◆ ToggleViaPlacement()

void PNS::ROUTER::ToggleViaPlacement ( )

Definition at line 502 of file pns_router.cpp.

503 {
504  if( m_state == ROUTE_TRACK )
505  {
506  bool toggle = !m_placer->IsPlacingVia();
507  m_placer->ToggleVia( toggle );
508  }
509 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266

References m_placer, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::onViaCommand().

◆ UndoLastSegment()

void PNS::ROUTER::UndoLastSegment ( )

Definition at line 434 of file pns_router.cpp.

435 {
436  if( !RoutingInProgress() )
437  return;
438 
439  m_placer->UnfixRoute();
440 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
bool RoutingInProgress() const
Definition: pns_router.cpp:120

References m_placer, and RoutingInProgress().

Referenced by ROUTER_TOOL::performRouting().

◆ UpdateSizes()

void PNS::ROUTER::UpdateSizes ( const SIZES_SETTINGS aSizes)

Applies stored settings.

See also
Settings()

Definition at line 348 of file pns_router.cpp.

349 {
350  m_sizes = aSizes;
351 
352  // Change track/via size settings
353  if( m_state == ROUTE_TRACK)
354  {
355  m_placer->UpdateSizes( m_sizes );
356  }
357 }
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:271
RouterState m_state
Definition: pns_router.h:266
SIZES_SETTINGS m_sizes
Definition: pns_router.h:284

References m_placer, m_sizes, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::DpDimensionsDialog(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), ROUTER_TOOL::prepareInteractive(), and PNS::TOOL_BASE::Reset().

◆ updateView()

void PNS::ROUTER::updateView ( NODE aNode,
ITEM_SET aCurrent,
bool  aDragging = false 
)
private

Definition at line 324 of file pns_router.cpp.

325 {
326  NODE::ITEM_VECTOR removed, added;
327  NODE::OBSTACLES obstacles;
328 
329  if( !aNode )
330  return;
331 
333  markViolations( aNode, aCurrent, removed );
334 
335  aNode->GetUpdatedItems( removed, added );
336 
337  for( auto item : added )
338  {
339  int clearance = GetRuleResolver()->Clearance( item->Net() );
340  m_iface->DisplayItem( item, -1, clearance, aDragging );
341  }
342 
343  for( auto item : removed )
344  m_iface->HideItem( item );
345 }
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:177
virtual void HideItem(ITEM *aItem)=0
virtual int Clearance(const ITEM *aA, const ITEM *aB) const =0
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:275
std::vector< OBSTACLE > OBSTACLES
Definition: pns_node.h:150
ROUTER_MODE Mode() const
Definition: pns_router.h:133
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:202
bool m_forceMarkObstaclesMode
Definition: pns_router.h:281
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:149
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:293

References PNS::RULE_RESOLVER::Clearance(), PNS::ROUTER_IFACE::DisplayItem(), GetRuleResolver(), PNS::NODE::GetUpdatedItems(), PNS::ROUTER_IFACE::HideItem(), m_forceMarkObstaclesMode, m_iface, markViolations(), Mode(), PNS::RM_MarkObstacles, and Settings().

Referenced by moveDragging(), and movePlacing().

Member Data Documentation

◆ m_currentEnd

VECTOR2I PNS::ROUTER::m_currentEnd
private

Definition at line 265 of file pns_router.h.

Referenced by Move(), and StartRouting().

◆ m_dragger

std::unique_ptr< DRAG_ALGO > PNS::ROUTER::m_dragger
private

Definition at line 272 of file pns_router.h.

Referenced by FixRoute(), moveDragging(), StartDragging(), and StopRouting().

◆ m_failureReason

wxString PNS::ROUTER::m_failureReason
private

Definition at line 289 of file pns_router.h.

Referenced by FailureReason(), and SetFailureReason().

◆ m_forceMarkObstaclesMode

bool PNS::ROUTER::m_forceMarkObstaclesMode = false
private

Definition at line 281 of file pns_router.h.

Referenced by StartDragging(), StartRouting(), and updateView().

◆ m_iface

◆ m_iterLimit

int PNS::ROUTER::m_iterLimit
private

Definition at line 277 of file pns_router.h.

Referenced by GetIterLimit(), ROUTER(), and SetIterLimit().

◆ m_lastNode

NODE* PNS::ROUTER::m_lastNode
private

Definition at line 269 of file pns_router.h.

Referenced by ROUTER().

◆ m_logger

LOGGER* PNS::ROUTER::m_logger
private

Definition at line 286 of file pns_router.h.

Referenced by FixRoute(), Logger(), Move(), ROUTER(), StartDragging(), StartRouting(), and ~ROUTER().

◆ m_mode

ROUTER_MODE PNS::ROUTER::m_mode
private

Definition at line 285 of file pns_router.h.

Referenced by Mode(), ROUTER(), SetMode(), and StartRouting().

◆ m_placer

◆ m_settings

ROUTING_SETTINGS* PNS::ROUTER::m_settings
private

Definition at line 283 of file pns_router.h.

Referenced by LoadSettings(), ROUTER(), Settings(), and ToggleRounded().

◆ m_shove

std::unique_ptr< SHOVE > PNS::ROUTER::m_shove
private

Definition at line 273 of file pns_router.h.

◆ m_showInterSteps

bool PNS::ROUTER::m_showInterSteps
private

Definition at line 278 of file pns_router.h.

Referenced by GetShowIntermediateSteps(), ROUTER(), and SetShowIntermediateSteps().

◆ m_sizes

SIZES_SETTINGS PNS::ROUTER::m_sizes
private

Definition at line 284 of file pns_router.h.

Referenced by Sizes(), StartRouting(), and UpdateSizes().

◆ m_snapshotIter

int PNS::ROUTER::m_snapshotIter
private

Definition at line 279 of file pns_router.h.

Referenced by GetShapshotIter(), ROUTER(), and SetShowIntermediateSteps().

◆ m_state

◆ m_toolStatusbarName

wxString PNS::ROUTER::m_toolStatusbarName
private

Definition at line 288 of file pns_router.h.

◆ m_violation

bool PNS::ROUTER::m_violation
private

Definition at line 280 of file pns_router.h.

Referenced by ROUTER().

◆ m_world

std::unique_ptr< NODE > PNS::ROUTER::m_world
private

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