KiCad PCB EDA Suite
PNS::ROUTER Class Reference

#include <pns_router.h>

Public Types

enum  RouterState { IDLE , DRAG_SEGMENT , DRAG_COMPONENT , ROUTE_TRACK }
 

Public Member Functions

 ROUTER ()
 
 ~ROUTER ()
 
void SetInterface (ROUTER_IFACE *aIface)
 
void SetMode (ROUTER_MODE aMode)
 
ROUTER_MODE Mode () const
 
RouterState GetState () const
 
DRAG_ALGOGetDragger ()
 
void ClearWorld ()
 
void SyncWorld ()
 
bool RoutingInProgress () const
 
bool StartRouting (const VECTOR2I &aP, ITEM *aItem, int aLayer)
 
bool Move (const VECTOR2I &aP, ITEM *aItem)
 
bool Finish ()
 
bool ContinueFromEnd ()
 
bool FixRoute (const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
 
void BreakSegment (ITEM *aItem, const VECTOR2I &aP)
 
void UndoLastSegment ()
 
void CommitRouting ()
 
void GetUpdatedItems (std::vector< PNS::ITEM * > &aRemoved, std::vector< PNS::ITEM * > &aAdded, std::vector< PNS::ITEM * > &aHeads)
 
void StopRouting ()
 
void ClearViewDecorations ()
 
NODEGetWorld () const
 
void FlipPosture ()
 
bool SwitchLayer (int layer)
 
void ToggleViaPlacement ()
 
void SetOrthoMode (bool aEnable)
 
void ToggleCornerMode ()
 
int GetCurrentLayer () const
 
const std::vector< int > GetCurrentNets () const
 
LOGGERLogger ()
 
RULE_RESOLVERGetRuleResolver () const
 
bool IsPlacingVia () const
 
const ITEM_SET QueryHoverItems (const VECTOR2I &aP, bool aUseClearance=false)
 
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
 
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 ()
 
void SetFailureReason (const wxString &aReason)
 
const wxString & FailureReason () const
 
PLACEMENT_ALGOPlacer ()
 
ROUTER_IFACEGetInterface () const
 
void SetVisibleViewArea (const BOX2I &aExtents)
 
const BOX2IVisibleViewArea () const
 

Static Public Member Functions

static ROUTERGetInstance ()
 

Private Member Functions

bool movePlacing (const VECTOR2I &aP, ITEM *aItem)
 
bool moveDragging (const VECTOR2I &aP, ITEM *aItem)
 
void updateView (NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
 
void markViolations (NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
 
bool isStartingPointRoutable (const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
 
bool getNearestRatnestAnchor (VECTOR2I &aOtherEnd, LAYER_RANGE &aOtherEndLayers)
 

Private Attributes

BOX2I m_visibleViewArea
 
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_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 115 of file pns_router.h.

Member Enumeration Documentation

◆ RouterState

Enumerator
IDLE 
DRAG_SEGMENT 
DRAG_COMPONENT 
ROUTE_TRACK 

Definition at line 118 of file pns_router.h.

119 {
120 IDLE,
124 };

Constructor & Destructor Documentation

◆ ROUTER()

PNS::ROUTER::ROUTER ( )

Definition at line 60 of file pns_router.cpp.

61{
62 theRouter = this;
63
64 m_state = IDLE;
66
67 m_logger = new LOGGER;
68
69 // Initialize all other variables:
70 m_lastNode = nullptr;
71 m_iterLimit = 0;
72 m_settings = nullptr;
73 m_iface = nullptr;
75}
void SetMaximum()
Definition: box2.h:63
int m_iterLimit
Definition: pns_router.h:246
NODE * m_lastNode
Definition: pns_router.h:238
RouterState m_state
Definition: pns_router.h:235
ROUTER_IFACE * m_iface
Definition: pns_router.h:244
BOX2I m_visibleViewArea
Definition: pns_router.h:234
LOGGER * m_logger
Definition: pns_router.h:252
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:249
ROUTER_MODE m_mode
Definition: pns_router.h:251
static ROUTER * theRouter
Definition: pns_router.cpp:58
@ PNS_MODE_ROUTE_SINGLE
Definition: pns_router.h:63

References IDLE, m_iface, m_iterLimit, m_lastNode, m_logger, m_mode, m_settings, m_state, m_visibleViewArea, PNS::PNS_MODE_ROUTE_SINGLE, BOX2< Vec >::SetMaximum(), and PNS::theRouter.

◆ ~ROUTER()

PNS::ROUTER::~ROUTER ( )

Definition at line 84 of file pns_router.cpp.

85{
86 ClearWorld();
87 theRouter = nullptr;
88 delete m_logger;
89}
void ClearWorld()
Definition: pns_router.cpp:102

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

Member Function Documentation

◆ BreakSegment()

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

Definition at line 1044 of file pns_router.cpp.

1045{
1046 NODE *node = m_world->Branch();
1047
1048 LINE_PLACER placer( this );
1049
1050 if( placer.SplitAdjacentSegments( node, aItem, aP ) )
1051 {
1052 CommitRouting( node );
1053 }
1054 else
1055 {
1056 delete node;
1057 }
1058}
void CommitRouting()
Definition: pns_router.cpp:895
std::unique_ptr< NODE > m_world
Definition: pns_router.h:237

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

Referenced by ROUTER_TOOL::breakTrack().

◆ ClearViewDecorations()

void PNS::ROUTER::ClearViewDecorations ( )

Definition at line 932 of file pns_router.cpp.

933{
935}
virtual void EraseView()=0

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

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

◆ ClearWorld()

void PNS::ROUTER::ClearWorld ( )

Definition at line 102 of file pns_router.cpp.

103{
104 if( m_world )
105 {
106 m_world->KillChildren();
107 m_world.reset();
108 }
109
110 m_placer.reset();
111}
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:240

References m_placer, and m_world.

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

◆ CommitRouting() [1/2]

◆ CommitRouting() [2/2]

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

Definition at line 802 of file pns_router.cpp.

803{
804 if( m_state == ROUTE_TRACK && !m_placer->HasPlacedAnything() )
805 return;
806
807 NODE::ITEM_VECTOR removed;
808 NODE::ITEM_VECTOR added;
809 NODE::ITEM_VECTOR changed;
810
811 aNode->GetUpdatedItems( removed, added );
812
813 for( ITEM* item : removed )
814 {
815 bool is_changed = false;
816
817 // Items in remove/add that share the same parent are just updated versions
818 // We move them to the updated vector to preserve attributes such as UUID and pad data
819 if( item->Parent() )
820 {
821 for( NODE::ITEM_VECTOR::iterator added_it = added.begin();
822 added_it != added.end(); ++added_it )
823 {
824 if( ( *added_it )->Parent() && ( *added_it )->Parent() == item->Parent() )
825 {
826 changed.push_back( *added_it );
827 added.erase( added_it );
828 is_changed = true;
829 break;
830 }
831 }
832 }
833
834 if( !is_changed && !item->IsVirtual() )
835 m_iface->RemoveItem( item );
836 }
837
838 for( ITEM* item : added )
839 {
840 if( !item->IsVirtual() )
841 {
842 m_iface->AddItem( item );
843 }
844 }
845
846 for( ITEM* item : changed )
847 {
848 if( !item->IsVirtual() )
849 {
850 m_iface->UpdateItem( item );
851 }
852 }
853
854 m_iface->Commit();
855 m_world->Commit( aNode );
856}
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:167
virtual void RemoveItem(ITEM *aItem)=0
virtual void UpdateItem(ITEM *aItem)=0
virtual void Commit()=0
virtual void AddItem(ITEM *aItem)=0

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

◆ ContinueFromEnd()

bool PNS::ROUTER::ContinueFromEnd ( )

Definition at line 564 of file pns_router.cpp.

565{
566 LINE_PLACER* placer = dynamic_cast<LINE_PLACER*>( Placer() );
567
568 if( placer == nullptr )
569 return false;
570
571 LINE current = placer->Trace();
572 int currentLayer = GetCurrentLayer();
573 VECTOR2I currentEnd = placer->CurrentEnd();
574 VECTOR2I otherEnd;
575 LAYER_RANGE otherEndLayers;
576
577 // Get the anchor nearest to the end of the trace the user is routing
578 if( !getNearestRatnestAnchor( otherEnd, otherEndLayers ) )
579 return false;
580
582
583 // Commit whatever we've fixed and restart routing from the other end
584 int nextLayer = otherEndLayers.Overlaps( currentLayer ) ? currentLayer : otherEndLayers.Start();
585
586 if( !StartRouting( otherEnd, &current, nextLayer ) )
587 return false;
588
589 // Attempt to route to our current position
590 Move( currentEnd, &current );
591
592 return true;
593}
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
int Start() const
Definition: pns_layerset.h:82
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:212
bool getNearestRatnestAnchor(VECTOR2I &aOtherEnd, LAYER_RANGE &aOtherEndLayers)
Definition: pns_router.cpp:481
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:390
int GetCurrentLayer() const
Definition: pns_router.cpp:982
bool Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:459

References CommitRouting(), PNS::LINE_PLACER::CurrentEnd(), GetCurrentLayer(), getNearestRatnestAnchor(), Move(), LAYER_RANGE::Overlaps(), Placer(), LAYER_RANGE::Start(), StartRouting(), and PNS::LINE_PLACER::Trace().

Referenced by ROUTER_TOOL::performRouting().

◆ FailureReason()

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

Definition at line 210 of file pns_router.h.

210{ return m_failureReason; }
wxString m_failureReason
Definition: pns_router.h:255

References m_failureReason.

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

◆ Finish()

bool PNS::ROUTER::Finish ( )

Definition at line 523 of file pns_router.cpp.

524{
525 if( m_state != ROUTE_TRACK )
526 return false;
527
528 LINE_PLACER* placer = dynamic_cast<LINE_PLACER*>( Placer() );
529
530 if( placer == nullptr )
531 return false;
532
533 // Get our current line and position and nearest ratsnest to them if it exists
534 PNS::LINE current = placer->Trace();
535 VECTOR2I currentEnd = placer->CurrentEnd();
536 VECTOR2I otherEnd;
537 LAYER_RANGE otherEndLayers;
538
539 // Get the anchor nearest to the end of the trace the user is routing
540 if( !getNearestRatnestAnchor( otherEnd, otherEndLayers ) )
541 return false;
542
543 // Keep moving until we don't change position or hit the limit
544 int triesLeft = 5;
545 VECTOR2I moveResultPoint;
546
547 do
548 {
549 moveResultPoint = Placer()->CurrentEnd();
550 Move( otherEnd, &current );
551 triesLeft--;
552 } while( Placer()->CurrentEnd() != moveResultPoint && triesLeft );
553
554 // If we've made it, fix the route and we're done
555 if( moveResultPoint == otherEnd && otherEndLayers.Overlaps( GetCurrentLayer() ) )
556 {
557 return FixRoute( otherEnd, &current, false );
558 }
559
560 return false;
561}
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
virtual const VECTOR2I & CurrentEnd() const =0
Function CurrentEnd()
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
Definition: pns_router.cpp:859

References PNS::PLACEMENT_ALGO::CurrentEnd(), PNS::LINE_PLACER::CurrentEnd(), FixRoute(), GetCurrentLayer(), getNearestRatnestAnchor(), m_state, Move(), LAYER_RANGE::Overlaps(), Placer(), ROUTE_TRACK, and PNS::LINE_PLACER::Trace().

Referenced by ROUTER_TOOL::performRouting().

◆ FixRoute()

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

Definition at line 859 of file pns_router.cpp.

860{
861 bool rv = false;
862
863 if( m_logger )
864 m_logger->Log( LOGGER::EVT_FIX, aP, aEndItem );
865
866 switch( m_state )
867 {
868 case ROUTE_TRACK:
869 rv = m_placer->FixRoute( aP, aEndItem, aForceFinish );
870 break;
871
872 case DRAG_SEGMENT:
873 case DRAG_COMPONENT:
874 rv = m_dragger->FixRoute();
875 break;
876
877 default:
878 break;
879 }
880
881 return rv;
882}
void Log(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), const ITEM *item=nullptr, const SIZES_SETTINGS *sizes=nullptr)
Definition: pns_logger.cpp:64
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:241

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

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

◆ FlipPosture()

void PNS::ROUTER::FlipPosture ( )

Definition at line 938 of file pns_router.cpp.

939{
940 if( m_state == ROUTE_TRACK )
941 {
942 m_placer->FlipPosture();
943 }
944}

References m_placer, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::performRouting().

◆ GetCurrentLayer()

int PNS::ROUTER::GetCurrentLayer ( ) const

Definition at line 982 of file pns_router.cpp.

983{
984 if( m_placer )
985 return m_placer->CurrentLayer();
986 else if( m_dragger )
987 return m_dragger->CurrentLayer();
988
989 return -1;
990}

References m_dragger, and m_placer.

Referenced by ContinueFromEnd(), Finish(), ROUTER_TOOL::handleLayerSwitch(), 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 971 of file pns_router.cpp.

972{
973 if( m_placer )
974 return m_placer->CurrentNets();
975 else if( m_dragger )
976 return m_dragger->CurrentNets();
977
978 return std::vector<int>();
979}

References m_dragger, and m_placer.

Referenced by getNearestRatnestAnchor(), ROUTER_TOOL::handleLayerSwitch(), ROUTER_TOOL::Init(), ROUTER_TOOL::onTrackViaSizeChanged(), PNS::TOOL_BASE::updateEndItem(), ROUTER_TOOL::UpdateMessagePanel(), and ROUTER_TOOL::updateSizesAfterLayerSwitch().

◆ GetDragger()

DRAG_ALGO * PNS::ROUTER::GetDragger ( )
inline

Definition at line 136 of file pns_router.h.

136{ return m_dragger.get(); }

References m_dragger.

Referenced by PNS::TOOL_BASE::checkSnap(), and markViolations().

◆ GetInstance()

◆ GetInterface()

◆ GetIterLimit()

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

Definition at line 186 of file pns_router.h.

186{ return m_iterLimit; };

References m_iterLimit.

◆ getNearestRatnestAnchor()

bool PNS::ROUTER::getNearestRatnestAnchor ( VECTOR2I aOtherEnd,
LAYER_RANGE aOtherEndLayers 
)
private

Definition at line 481 of file pns_router.cpp.

482{
483 // Can't finish something with no connections
484 if( GetCurrentNets().empty() )
485 return false;
486
487 PNS::LINE_PLACER* placer = dynamic_cast<PNS::LINE_PLACER*>( Placer() );
488
489 if( placer == nullptr )
490 return false;
491
492 PNS::LINE trace = placer->Trace();
493 PNS::NODE* lastNode = placer->CurrentNode( true );
494 PNS::TOPOLOGY topo( lastNode );
495
496 // If the user has drawn a line, get the anchor nearest to the line end
497 if( trace.SegmentCount() > 0 )
498 return topo.NearestUnconnectedAnchorPoint( &trace, aOtherEnd, aOtherEndLayers );
499
500 // Otherwise, find the closest anchor to our start point
501
502 // Get joint from placer start item
503 JOINT* jt = lastNode->FindJoint( placer->CurrentStart(), placer->CurrentLayer(),
504 placer->CurrentNets()[0] );
505
506 if( !jt )
507 return false;
508
509 // Get unconnected item from joint
510 int anchor;
511 PNS::ITEM* it = topo.NearestUnconnectedItem( jt, &anchor );
512
513 if( !it )
514 return false;
515
516 aOtherEnd = it->Anchor( anchor );
517 aOtherEndLayers = it->Layers();
518
519 return true;
520}
Base class for PNS router board items.
Definition: pns_item.h:56
const LAYER_RANGE & Layers() const
Definition: pns_item.h:156
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:219
Single track placement algorithm.
const LINE Trace() const
Return the complete routed line.
const std::vector< int > CurrentNets() const override
Return the net code of currently routed track.
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Return the most recent world state.
int CurrentLayer() const override
Return the layer of currently routed track.
const VECTOR2I & CurrentStart() const override
Return the current start of the line being placed.
int SegmentCount() const
Definition: pns_line.h:144
Keep the router "world" - i.e.
Definition: pns_node.h:156
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Search for a joint at a given position, layer and belonging to given net.
Definition: pns_node.cpp:1197
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:971
static bool empty(const wxTextEntryBase *aCtrl)

References anchor, PNS::ITEM::Anchor(), PNS::LINE_PLACER::CurrentLayer(), PNS::LINE_PLACER::CurrentNets(), PNS::LINE_PLACER::CurrentNode(), PNS::LINE_PLACER::CurrentStart(), empty(), PNS::NODE::FindJoint(), GetCurrentNets(), PNS::ITEM::Layers(), PNS::TOPOLOGY::NearestUnconnectedAnchorPoint(), PNS::TOPOLOGY::NearestUnconnectedItem(), Placer(), PNS::LINE::SegmentCount(), and PNS::LINE_PLACER::Trace().

Referenced by ContinueFromEnd(), and Finish().

◆ GetRuleResolver()

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

◆ GetState()

◆ GetUpdatedItems()

void PNS::ROUTER::GetUpdatedItems ( std::vector< PNS::ITEM * > &  aRemoved,
std::vector< PNS::ITEM * > &  aAdded,
std::vector< PNS::ITEM * > &  aHeads 
)

Definition at line 776 of file pns_router.cpp.

778{
779 NODE *node;
780 ITEM_SET current;
781
782 if( m_state == ROUTE_TRACK )
783 {
784 node = m_placer->CurrentNode( true );
785 current = m_placer->Traces();
786 }
787 else if ( m_state == DRAG_SEGMENT )
788 {
789 node = m_dragger->CurrentNode();
790 current = m_dragger->Traces();
791 }
792
793 node->GetUpdatedItems( aRemoved, aAdded );
794
795 for( auto item : current.CItems() )
796 {
797 aHeads.push_back( item.item->Clone() );
798 }
799}

References PNS::ITEM_SET::CItems(), DRAG_SEGMENT, PNS::NODE::GetUpdatedItems(), m_dragger, m_placer, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::saveRouterDebugLog().

◆ GetWorld()

◆ IsPlacingVia()

bool PNS::ROUTER::IsPlacingVia ( ) const

Definition at line 999 of file pns_router.cpp.

1000{
1001 if( !m_placer )
1002 return false;
1003
1004 return m_placer->IsPlacingVia();
1005}

References m_placer.

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

◆ isStartingPointRoutable()

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

Definition at line 214 of file pns_router.cpp.

215{
216 if( Settings().AllowDRCViolations() )
217 return true;
218
220 {
222 {
223 SetFailureReason( _( "Diff pair gap is less than board minimum clearance." ) );
224 return false;
225 }
226 }
227
228 ITEM_SET candidates = QueryHoverItems( aWhere );
229 wxString failureReason;
230
231 for( ITEM* item : candidates.Items() )
232 {
233 // Edge cuts are put on all layers, but they're not *really* on all layers
234 if( item->Parent() && item->Parent()->GetLayer() == Edge_Cuts )
235 continue;
236
237 if( !item->Layers().Overlaps( aLayer ) )
238 continue;
239
240 if( item->IsRoutable() )
241 {
242 failureReason = wxEmptyString;
243 break;
244 }
245 else
246 {
247 BOARD_ITEM* parent = item->Parent();
248
249 switch( parent->Type() )
250 {
251 case PCB_PAD_T:
252 {
253 PAD* pad = static_cast<PAD*>( parent );
254
255 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
256 failureReason = _( "Cannot start routing from a non-plated hole." );
257 }
258 break;
259
260 case PCB_ZONE_T:
261 case PCB_FP_ZONE_T:
262 {
263 ZONE* zone = static_cast<ZONE*>( parent );
264
265 if( !zone->GetZoneName().IsEmpty() )
266 {
267 failureReason = wxString::Format( _( "Rule area '%s' disallows tracks." ),
268 zone->GetZoneName() );
269 }
270 else
271 {
272 failureReason = _( "Rule area disallows tracks." );
273 }
274 }
275 break;
276
277 case PCB_TEXT_T:
278 case PCB_FP_TEXT_T:
279 case PCB_TEXTBOX_T:
280 case PCB_FP_TEXTBOX_T:
281 failureReason = _( "Cannot start routing from a text item." );
282 break;
283
284 case PCB_SHAPE_T:
285 case PCB_FP_SHAPE_T:
286 failureReason = _( "Cannot start routing from a graphic." );
287
288 default:
289 break;
290 }
291 }
292 }
293
294 if( !failureReason.IsEmpty() )
295 {
296 SetFailureReason( failureReason );
297 return false;
298 }
299
300 VECTOR2I startPoint = aWhere;
301
303 {
304 SHAPE_LINE_CHAIN dummyStartSeg;
305 LINE dummyStartLine;
306
307 dummyStartSeg.Append( startPoint );
308 dummyStartSeg.Append( startPoint, true );
309
310 dummyStartLine.SetShape( dummyStartSeg );
311 dummyStartLine.SetLayer( aLayer );
312 dummyStartLine.SetNet( aStartItem ? aStartItem->Net() : 0 );
313 dummyStartLine.SetWidth( m_sizes.TrackWidth() );
314
315 if( m_world->CheckColliding( &dummyStartLine, ITEM::ANY_T ) )
316 {
317 ITEM_SET dummyStartSet( &dummyStartLine );
318 NODE::ITEM_VECTOR highlightedItems;
319
320 markViolations( m_world.get(), dummyStartSet, highlightedItems );
321
322 for( ITEM* item : highlightedItems )
323 m_iface->HideItem( item );
324
325 SetFailureReason( _( "The routing start point violates DRC." ) );
326 return false;
327 }
328 }
329 else if( m_mode == PNS_MODE_ROUTE_DIFF_PAIR )
330 {
331 if( !aStartItem )
332 {
333 SetFailureReason( _( "Cannot start a differential pair in the middle of nowhere." ) );
334 return false;
335 }
336
337 DP_PRIMITIVE_PAIR dpPair;
338 wxString errorMsg;
339
340 if( !DIFF_PAIR_PLACER::FindDpPrimitivePair( m_world.get(), startPoint, aStartItem, dpPair,
341 &errorMsg ) )
342 {
343 SetFailureReason( errorMsg );
344 return false;
345 }
346
347 SHAPE_LINE_CHAIN dummyStartSegA;
348 SHAPE_LINE_CHAIN dummyStartSegB;
349 LINE dummyStartLineA;
350 LINE dummyStartLineB;
351
352 dummyStartSegA.Append( dpPair.AnchorN() );
353 dummyStartSegA.Append( dpPair.AnchorN(), true );
354
355 dummyStartSegB.Append( dpPair.AnchorP() );
356 dummyStartSegB.Append( dpPair.AnchorP(), true );
357
358 dummyStartLineA.SetShape( dummyStartSegA );
359 dummyStartLineA.SetLayer( aLayer );
360 dummyStartLineA.SetNet( dpPair.PrimN()->Net() );
361 dummyStartLineA.SetWidth( m_sizes.DiffPairWidth() );
362
363 dummyStartLineB.SetShape( dummyStartSegB );
364 dummyStartLineB.SetLayer( aLayer );
365 dummyStartLineB.SetNet( dpPair.PrimP()->Net() );
366 dummyStartLineB.SetWidth( m_sizes.DiffPairWidth() );
367
368 if( m_world->CheckColliding( &dummyStartLineA, ITEM::ANY_T )
369 || m_world->CheckColliding( &dummyStartLineB, ITEM::ANY_T ) )
370 {
371 ITEM_SET dummyStartSet;
372 NODE::ITEM_VECTOR highlightedItems;
373
374 dummyStartSet.Add( dummyStartLineA );
375 dummyStartSet.Add( dummyStartLineB );
376 markViolations( m_world.get(), dummyStartSet, highlightedItems );
377
378 for( ITEM* item : highlightedItems )
379 m_iface->HideItem( item );
380
381 SetFailureReason( _( "The routing start point violates DRC." ) );
382 return false;
383 }
384 }
385
386 return true;
387}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
Definition: pad.h:59
static bool FindDpPrimitivePair(NODE *aWorld, const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
virtual void HideItem(ITEM *aItem)=0
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:209
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:608
SIZES_SETTINGS m_sizes
Definition: pns_router.h:250
const ITEM_SET QueryHoverItems(const VECTOR2I &aP, bool aUseClearance=false)
Definition: pns_router.cpp:120
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:188
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
wxString GetZoneName() const
Definition: zone.h:124
#define _(s)
@ Edge_Cuts
Definition: layer_ids.h:113
@ PNS_MODE_ROUTE_DIFF_PAIR
Definition: pns_router.h:64
@ NPTH
like PAD_PTH, but not plated
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
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_FP_ZONE_T
class ZONE, managed by a footprint
Definition: typeinfo.h:100
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92

References _, PNS::ITEM_SET::Add(), PNS::DP_PRIMITIVE_PAIR::AnchorN(), PNS::DP_PRIMITIVE_PAIR::AnchorP(), PNS::ITEM::ANY_T, SHAPE_LINE_CHAIN::Append(), PNS::SIZES_SETTINGS::DiffPairGap(), PNS::SIZES_SETTINGS::DiffPairWidth(), Edge_Cuts, PNS::DIFF_PAIR_PLACER::FindDpPrimitivePair(), Format(), ZONE::GetZoneName(), PNS::ROUTER_IFACE::HideItem(), PNS::ITEM_SET::Items(), m_iface, m_mode, m_sizes, m_world, markViolations(), PNS::SIZES_SETTINGS::MinClearance(), PNS::ITEM::Net(), NPTH, pad, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_FP_ZONE_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_ZONE_T, PNS::PNS_MODE_ROUTE_DIFF_PAIR, PNS::PNS_MODE_ROUTE_SINGLE, PNS::DP_PRIMITIVE_PAIR::PrimN(), PNS::DP_PRIMITIVE_PAIR::PrimP(), QueryHoverItems(), SetFailureReason(), PNS::ITEM::SetLayer(), PNS::ITEM::SetNet(), PNS::LINE::SetShape(), Settings(), PNS::LINE::SetWidth(), PNS::SIZES_SETTINGS::TrackWidth(), and EDA_ITEM::Type().

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 202 of file pns_router.h.

203 {
204 m_settings = aSettings;
205 }

References m_settings.

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

◆ Logger()

LOGGER * PNS::ROUTER::Logger ( )

Definition at line 993 of file pns_router.cpp.

994{
995 return m_logger;
996}

References m_logger.

Referenced by ROUTER_TOOL::saveRouterDebugLog().

◆ markViolations()

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

Definition at line 608 of file pns_router.cpp.

609{
610 auto updateItem =
611 [&]( ITEM* currentItem, ITEM* itemToMark )
612 {
613 std::unique_ptr<ITEM> tmp( itemToMark->Clone() );
614
615 int clearance;
616 bool removeOriginal = true;
617 bool holeOnly = ( ( itemToMark->Marker() & MK_HOLE )
618 && !( itemToMark->Marker() & MK_VIOLATION ) );
619
620 if( holeOnly )
621 clearance = aNode->GetHoleClearance( currentItem, itemToMark );
622 else
623 clearance = aNode->GetClearance( currentItem, itemToMark );
624
625 if( itemToMark->Layers().IsMultilayer() && !currentItem->Layers().IsMultilayer() )
626 tmp->SetLayer( currentItem->Layer() );
627
628 if( itemToMark->Kind() == ITEM::SOLID_T )
629 {
630 if( holeOnly || !m_iface->IsFlashedOnLayer( itemToMark, currentItem->Layer() ) )
631 {
632 SOLID* solid = static_cast<SOLID*>( tmp.get() );
633
634 if( solid->Hole() )
635 {
636 solid->SetShape( solid->Hole()->Clone() );
637
638 // Leave the pad flashing around the highlighted hole
639 removeOriginal = false;
640 }
641 }
642
643 if( itemToMark->IsCompoundShapePrimitive() )
644 {
645 // We're only highlighting one (or more) of several primitives so we
646 // don't want all the other parts of the object to disappear
647 removeOriginal = false;
648 }
649 }
650
651 m_iface->DisplayItem( tmp.get(), clearance );
652
653 if( removeOriginal )
654 aRemoved.push_back( itemToMark );
655 };
656
657 for( ITEM* item : aCurrent.Items() )
658 {
659 NODE::OBSTACLES obstacles;
660
661 aNode->QueryColliding( item, obstacles, ITEM::ANY_T );
662
663 if( item->OfKind( ITEM::LINE_T ) )
664 {
665 LINE* l = static_cast<LINE*>( item );
666
667 if( l->EndsWithVia() )
668 {
669 VIA v( l->Via() );
670 aNode->QueryColliding( &v, obstacles, ITEM::ANY_T );
671 }
672 }
673
674 ITEM_SET draggedItems;
675
676 if( GetDragger() )
677 draggedItems = GetDragger()->Traces();
678
679 for( OBSTACLE& obs : obstacles )
680 {
681 // Don't mark items being dragged; only board items they collide with
682 if( draggedItems.Contains( obs.m_item ) )
683 continue;
684
685 obs.m_item->Mark( obs.m_item->Marker() | MK_VIOLATION );
686 updateItem( item, obs.m_item );
687 }
688
689 if( item->Kind() == ITEM::LINE_T )
690 {
691 LINE* line = static_cast<LINE*>( item );
692
693 // Show clearance on any blocking obstacles
694 if( line->GetBlockingObstacle() )
695 updateItem( item, line->GetBlockingObstacle() );
696 }
697 }
698}
virtual const ITEM_SET Traces()=0
Function Traces()
@ SOLID_T
Definition: pns_item.h:63
@ LINE_T
Definition: pns_item.h:64
std::vector< OBSTACLE > OBSTACLES
Definition: pns_node.h:168
virtual void DisplayItem(const ITEM *aItem, int aClearance, bool aEdit=false, bool aIsHeadTrace=false)=0
virtual bool IsFlashedOnLayer(const PNS::ITEM *aItem, int aLayer) const =0
DRAG_ALGO * GetDragger()
Definition: pns_router.h:136
@ MK_VIOLATION
Definition: pns_item.h:42
@ MK_HOLE
Definition: pns_item.h:45
@ VIA
Normal via.
Definition: router_tool.cpp:89

References PNS::ITEM::ANY_T, SHAPE::Clone(), PNS::ITEM_SET::Contains(), PNS::ROUTER_IFACE::DisplayItem(), PNS::LINE::EndsWithVia(), PNS::LINE::GetBlockingObstacle(), PNS::NODE::GetClearance(), GetDragger(), PNS::NODE::GetHoleClearance(), PNS::SOLID::Hole(), PNS::ROUTER_IFACE::IsFlashedOnLayer(), LAYER_RANGE::IsMultilayer(), PNS::ITEM_SET::Items(), PNS::ITEM::Layer(), PNS::ITEM::Layers(), PNS::ITEM::LINE_T, m_iface, PNS::MK_HOLE, PNS::MK_VIOLATION, PNS::NODE::QueryColliding(), PNS::SOLID::SetShape(), PNS::ITEM::SOLID_T, PNS::DRAG_ALGO::Traces(), and PNS::LINE::Via().

Referenced by isStartingPointRoutable(), and updateView().

◆ Mode()

◆ Move()

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

Definition at line 459 of file pns_router.cpp.

460{
461 if( m_logger )
462 m_logger->Log( LOGGER::EVT_MOVE, aP, endItem );
463
464 switch( m_state )
465 {
466 case ROUTE_TRACK:
467 return movePlacing( aP, endItem );
468
469 case DRAG_SEGMENT:
470 case DRAG_COMPONENT:
471 return moveDragging( aP, endItem );
472
473 default:
474 break;
475 }
476
477 return false;
478}
bool moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:596
bool movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:738

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

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

◆ moveDragging()

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

Definition at line 596 of file pns_router.cpp.

597{
599
600 bool ret = m_dragger->Drag( aP );
601 ITEM_SET dragged = m_dragger->Traces();
602
603 updateView( m_dragger->CurrentNode(), dragged, true );
604 return ret;
605}
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:701

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

Referenced by Move().

◆ movePlacing()

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

Definition at line 738 of file pns_router.cpp.

739{
741
742 bool ret = m_placer->Move( aP, aEndItem );
743 ITEM_SET current = m_placer->Traces();
744
745 for( const ITEM* item : current.CItems() )
746 {
747 if( !item->OfKind( ITEM::LINE_T ) )
748 continue;
749
750 const LINE* l = static_cast<const LINE*>( item );
751 int clearance = GetRuleResolver()->Clearance( item, nullptr );
752
753 m_iface->DisplayItem( l, clearance, false, true );
754
755 if( l->EndsWithVia() )
756 {
757 const VIA& via = l->Via();
758 int viaClearance = GetRuleResolver()->Clearance( &via, nullptr );
759 int holeClearance = GetRuleResolver()->HoleClearance( &via, nullptr );
760
761 if( holeClearance + via.Drill() / 2 > viaClearance + via.Diameter() / 2 )
762 viaClearance = holeClearance + via.Drill() / 2 - via.Diameter() / 2;
763
764 m_iface->DisplayItem( &l->Via(), viaClearance, false, true );
765 }
766 }
767
768 //ITEM_SET tmp( &current );
769
770 updateView( m_placer->CurrentNode( true ), current );
771
772 return ret;
773}
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:176
virtual int Clearance(const ITEM *aA, const ITEM *aB, bool aUseClearanceEpsilon=true)=0
virtual int HoleClearance(const ITEM *aA, const ITEM *aB, bool aUseClearanceEpsilon=true)=0

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

Referenced by Move().

◆ Placer()

◆ QueryHoverItems()

const ITEM_SET PNS::ROUTER::QueryHoverItems ( const VECTOR2I aP,
bool  aUseClearance = false 
)

Definition at line 120 of file pns_router.cpp.

121{
122 if( m_state == IDLE || m_placer == nullptr )
123 {
124 if( aUseClearance )
125 {
126 SEGMENT test( SEG( aP, aP ), -1 );
127 test.SetWidth( 1 );
128 test.SetLayers( LAYER_RANGE::All() );
129 NODE::OBSTACLES obs;
130 m_world->QueryColliding( &test, obs, ITEM::ANY_T, -1, false );
131
132 PNS::ITEM_SET ret;
133
134 for( OBSTACLE& obstacle : obs )
135 ret.Add( obstacle.m_item, false );
136
137 return ret;
138 }
139 else
140 {
141 return m_world->HitTest( aP );
142 }
143 }
144 else
145 return m_placer->CurrentNode()->HitTest( aP );
146}
static LAYER_RANGE All()
Definition: pns_layerset.h:125
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
Definition: seg.h:42

References PNS::ITEM_SET::Add(), LAYER_RANGE::All(), PNS::ITEM::ANY_T, IDLE, m_placer, m_state, and m_world.

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

◆ RoutingInProgress()

◆ SetFailureReason()

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

◆ SetInterface()

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

Definition at line 1039 of file pns_router.cpp.

1040{
1041 m_iface = aIface;
1042}

References m_iface.

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

◆ SetIterLimit()

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

Definition at line 185 of file pns_router.h.

185{ m_iterLimit = aX; }

References m_iterLimit.

◆ SetMode()

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

Definition at line 1033 of file pns_router.cpp.

1034{
1035 m_mode = aMode;
1036}

References m_mode.

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

◆ SetOrthoMode()

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

Definition at line 1024 of file pns_router.cpp.

1025{
1026 if( !m_placer )
1027 return;
1028
1029 m_placer->SetOrthoMode( aEnable );
1030}

References m_placer.

◆ Settings()

◆ SetVisibleViewArea()

void PNS::ROUTER::SetVisibleViewArea ( const BOX2I aExtents)
inline

Definition at line 216 of file pns_router.h.

216{ m_visibleViewArea = aExtents; }

References m_visibleViewArea.

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

◆ Sizes()

◆ StartDragging() [1/2]

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

Definition at line 149 of file pns_router.cpp.

150{
151 return StartDragging( aP, ITEM_SET( aItem ), aDragMode );
152}
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:149

References StartDragging().

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

◆ StartDragging() [2/2]

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

Definition at line 155 of file pns_router.cpp.

156{
157 if( aStartItems.Empty() )
158 return false;
159
160 if( Settings().Mode() == RM_MarkObstacles )
161 {
162 m_world->SetCollisionQueryScope( NODE::CQS_ALL_RULES );
163 }
164 else
165 {
166 m_world->SetCollisionQueryScope( NODE::CQS_IGNORE_HOLE_CLEARANCE );
167 }
168
170
171 if( aStartItems.Count( ITEM::SOLID_T ) == aStartItems.Size() )
172 {
173 m_dragger = std::make_unique<COMPONENT_DRAGGER>( this );
176 }
177 else
178 {
179 if( aDragMode & DM_FREE_ANGLE )
181 else
183
184 m_dragger = std::make_unique<DRAGGER>( this );
186 }
187
188 m_dragger->SetMode( static_cast<PNS::DRAG_MODE>( aDragMode ) );
189 m_dragger->SetWorld( m_world.get() );
190 m_dragger->SetLogger( m_logger );
191 m_dragger->SetDebugDecorator( m_iface->GetDebugDecorator() );
192
193 if( m_logger )
194 m_logger->Clear();
195
196 if( m_logger && aStartItems.Size() )
197 {
198 m_logger->Log( LOGGER::EVT_START_DRAG, aP, aStartItems[0] );
199 }
200
201 if( m_dragger->Start( aP, aStartItems ) )
202 {
203 return true;
204 }
205 else
206 {
207 m_dragger.reset();
208 m_state = IDLE;
209 return false;
210 }
211}
void Clear()
Definition: pns_logger.cpp:40
@ EVT_START_DRAG
Definition: pns_logger.h:48
@ CQS_IGNORE_HOLE_CLEARANCE
check everything except hole2hole / hole2copper
Definition: pns_node.h:163
@ CQS_ALL_RULES
check all rules
Definition: pns_node.h:162
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
ROUTER_MODE Mode() const
Definition: pns_router.h:132
bool m_forceMarkObstaclesMode
Definition: pns_router.h:247
virtual void ClearCaches()
Definition: pns_node.h:106
@ RM_MarkObstacles
Ignore collisions, mark obstacles.
DRAG_MODE
Definition: pns_router.h:71
@ DM_FREE_ANGLE
Definition: pns_router.h:75

References PNS::LOGGER::Clear(), PNS::RULE_RESOLVER::ClearCaches(), PNS::ITEM_SET::Count(), PNS::NODE::CQS_ALL_RULES, PNS::NODE::CQS_IGNORE_HOLE_CLEARANCE, PNS::DM_FREE_ANGLE, DRAG_COMPONENT, DRAG_SEGMENT, PNS::ITEM_SET::Empty(), PNS::LOGGER::EVT_START_DRAG, PNS::ROUTER_IFACE::GetDebugDecorator(), GetRuleResolver(), IDLE, PNS::LOGGER::Log(), m_dragger, m_forceMarkObstaclesMode, m_iface, m_logger, m_state, m_world, Mode(), PNS::RM_MarkObstacles, Settings(), PNS::ITEM_SET::Size(), and PNS::ITEM::SOLID_T.

◆ StartRouting()

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

Definition at line 390 of file pns_router.cpp.

391{
392 if( Settings().Mode() == RM_MarkObstacles )
393 {
394 m_world->SetCollisionQueryScope( NODE::CQS_ALL_RULES );
395 }
396 else
397 {
398 m_world->SetCollisionQueryScope( NODE::CQS_IGNORE_HOLE_CLEARANCE );
399 }
400
402
403 if( !isStartingPointRoutable( aP, aStartItem, aLayer ) )
404 return false;
405
407
408 switch( m_mode )
409 {
411 m_placer = std::make_unique<LINE_PLACER>( this );
412 break;
413
415 m_placer = std::make_unique<DIFF_PAIR_PLACER>( this );
416 break;
417
419 m_placer = std::make_unique<MEANDER_PLACER>( this );
420 break;
421
423 m_placer = std::make_unique<DP_MEANDER_PLACER>( this );
424 break;
425
427 m_placer = std::make_unique<MEANDER_SKEW_PLACER>( this );
428 break;
429
430 default:
431 return false;
432 }
433
434 m_placer->UpdateSizes( m_sizes );
435 m_placer->SetLayer( aLayer );
436 m_placer->SetDebugDecorator( m_iface->GetDebugDecorator() );
437 m_placer->SetLogger( m_logger );
438
439 if( m_placer->Start( aP, aStartItem ) )
440 {
442
443 if( m_logger )
444 {
445 m_logger->Clear();
446 m_logger->Log( LOGGER::EVT_START_ROUTE, aP, aStartItem, &m_sizes );
447 }
448
449 return true;
450 }
451 else
452 {
453 m_state = IDLE;
454 return false;
455 }
456}
@ EVT_START_ROUTE
Definition: pns_logger.h:47
bool isStartingPointRoutable(const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:214
@ PNS_MODE_TUNE_DIFF_PAIR
Definition: pns_router.h:66
@ PNS_MODE_TUNE_SINGLE
Definition: pns_router.h:65
@ PNS_MODE_TUNE_DIFF_PAIR_SKEW
Definition: pns_router.h:67

References PNS::LOGGER::Clear(), PNS::RULE_RESOLVER::ClearCaches(), PNS::NODE::CQS_ALL_RULES, PNS::NODE::CQS_IGNORE_HOLE_CLEARANCE, PNS::LOGGER::EVT_START_ROUTE, PNS::ROUTER_IFACE::GetDebugDecorator(), GetRuleResolver(), IDLE, isStartingPointRoutable(), PNS::LOGGER::Log(), m_forceMarkObstaclesMode, m_iface, m_logger, m_mode, m_placer, m_sizes, m_state, m_world, Mode(), 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, PNS::RM_MarkObstacles, ROUTE_TRACK, and Settings().

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

◆ StopRouting()

void PNS::ROUTER::StopRouting ( )

Definition at line 904 of file pns_router.cpp.

905{
906 // Update the ratsnest with new changes
907
908 if( m_placer )
909 {
910 std::vector<int> nets;
911 m_placer->GetModifiedNets( nets );
912
913 // Update the ratsnest with new changes
914 for( int n : nets )
915 m_iface->UpdateNet( n );
916 }
917
918 if( !RoutingInProgress() )
919 return;
920
921 m_placer.reset();
922 m_dragger.reset();
923
925
926 m_state = IDLE;
927 m_world->KillChildren();
928 m_world->ClearRanks();
929}
virtual void UpdateNet(int aNetCode)=0
bool RoutingInProgress() const
Definition: pns_router.cpp:114

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::MainLoop(), ROUTER_TOOL::performDragging(), and LENGTH_TUNER_TOOL::performTuning().

◆ SwitchLayer()

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

Definition at line 947 of file pns_router.cpp.

948{
949 if( m_state == ROUTE_TRACK )
950 return m_placer->SetLayer( aLayer );
951
952 return false;
953}

References m_placer, m_state, and ROUTE_TRACK.

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

◆ SyncWorld()

void PNS::ROUTER::SyncWorld ( )

Definition at line 92 of file pns_router.cpp.

93{
94 ClearWorld();
95
96 m_world = std::make_unique<NODE>( );
97 m_iface->SyncWorld( m_world.get() );
98 m_world->FixupVirtualVias();
99}
virtual void SyncWorld(NODE *aNode)=0

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

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

◆ ToggleCornerMode()

void PNS::ROUTER::ToggleCornerMode ( )

Definition at line 1008 of file pns_router.cpp.

1009{
1011
1012 switch( m_settings->GetCornerMode() )
1013 {
1014 case DIRECTION_45::CORNER_MODE::MITERED_45: mode = DIRECTION_45::CORNER_MODE::ROUNDED_45; break;
1015 case DIRECTION_45::CORNER_MODE::ROUNDED_45: mode = DIRECTION_45::CORNER_MODE::MITERED_90; break;
1016 case DIRECTION_45::CORNER_MODE::MITERED_90: mode = DIRECTION_45::CORNER_MODE::ROUNDED_90; break;
1017 case DIRECTION_45::CORNER_MODE::ROUNDED_90: mode = DIRECTION_45::CORNER_MODE::MITERED_45; break;
1018 }
1019
1020 m_settings->SetCornerMode( mode );
1021}
CORNER_MODE
Corner modes.
Definition: direction45.h:67
void SetCornerMode(DIRECTION_45::CORNER_MODE aMode)
DIRECTION_45::CORNER_MODE GetCornerMode() const

References PNS::ROUTING_SETTINGS::GetCornerMode(), m_settings, and PNS::ROUTING_SETTINGS::SetCornerMode().

Referenced by ROUTER_TOOL::performRouting().

◆ ToggleViaPlacement()

void PNS::ROUTER::ToggleViaPlacement ( )

Definition at line 956 of file pns_router.cpp.

957{
958 if( m_state == ROUTE_TRACK )
959 {
960 bool toggle = !m_placer->IsPlacingVia();
961 m_placer->ToggleVia( toggle );
962
963 if( m_logger )
964 {
966 }
967 }
968}
@ EVT_TOGGLE_VIA
Definition: pns_logger.h:52
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References PNS::LOGGER::EVT_TOGGLE_VIA, PNS::LOGGER::Log(), m_logger, m_placer, m_sizes, m_state, and ROUTE_TRACK.

Referenced by ROUTER_TOOL::handleLayerSwitch(), and ROUTER_TOOL::onViaCommand().

◆ UndoLastSegment()

void PNS::ROUTER::UndoLastSegment ( )

Definition at line 885 of file pns_router.cpp.

886{
887 if( !RoutingInProgress() )
888 return;
889
891 m_placer->UnfixRoute();
892}

References PNS::LOGGER::EVT_UNFIX, PNS::LOGGER::Log(), m_logger, 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 726 of file pns_router.cpp.

727{
728 m_sizes = aSizes;
729
730 // Change track/via size settings
731 if( m_state == ROUTE_TRACK )
732 {
733 m_placer->UpdateSizes( m_sizes );
734 }
735}

References m_placer, m_sizes, m_state, and ROUTE_TRACK.

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

◆ updateView()

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

Definition at line 701 of file pns_router.cpp.

702{
703 NODE::ITEM_VECTOR removed, added;
704 NODE::OBSTACLES obstacles;
705
706 if( !aNode )
707 return;
708
710 markViolations( aNode, aCurrent, removed );
711
712 aNode->GetUpdatedItems( removed, added );
713
714 for( ITEM* item : added )
715 {
717 int clearance = GetRuleResolver()->Clearance( item, nullptr );
718 m_iface->DisplayItem( item, clearance, aDragging );
719 }
720
721 for( ITEM* item : removed )
722 m_iface->HideItem( item );
723}
virtual void ClearCacheForItem(const ITEM *aItem)
Definition: pns_node.h:105

References PNS::RULE_RESOLVER::Clearance(), PNS::RULE_RESOLVER::ClearCacheForItem(), 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().

◆ VisibleViewArea()

const BOX2I & PNS::ROUTER::VisibleViewArea ( ) const
inline

Definition at line 217 of file pns_router.h.

217{ return m_visibleViewArea; }

References m_visibleViewArea.

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

Member Data Documentation

◆ m_dragger

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

◆ m_failureReason

wxString PNS::ROUTER::m_failureReason
private

Definition at line 255 of file pns_router.h.

Referenced by FailureReason(), and SetFailureReason().

◆ m_forceMarkObstaclesMode

bool PNS::ROUTER::m_forceMarkObstaclesMode = false
private

Definition at line 247 of file pns_router.h.

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

◆ m_iface

◆ m_iterLimit

int PNS::ROUTER::m_iterLimit
private

Definition at line 246 of file pns_router.h.

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

◆ m_lastNode

NODE* PNS::ROUTER::m_lastNode
private

Definition at line 238 of file pns_router.h.

Referenced by ROUTER().

◆ m_logger

LOGGER* PNS::ROUTER::m_logger
private

◆ m_mode

ROUTER_MODE PNS::ROUTER::m_mode
private

Definition at line 251 of file pns_router.h.

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

◆ m_placer

◆ m_settings

ROUTING_SETTINGS* PNS::ROUTER::m_settings
private

Definition at line 249 of file pns_router.h.

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

◆ m_shove

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

Definition at line 242 of file pns_router.h.

◆ m_sizes

SIZES_SETTINGS PNS::ROUTER::m_sizes
private

◆ m_state

◆ m_toolStatusbarName

wxString PNS::ROUTER::m_toolStatusbarName
private

Definition at line 254 of file pns_router.h.

◆ m_visibleViewArea

BOX2I PNS::ROUTER::m_visibleViewArea
private

Definition at line 234 of file pns_router.h.

Referenced by ROUTER(), SetVisibleViewArea(), and VisibleViewArea().

◆ m_world

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

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