98 m_world = std::make_unique<NODE>( );
108 m_world->SetRuleResolver(
nullptr );
128 wxCHECK( node, ret );
130 if( aSlopRadius > 0 )
144 for(
const OBSTACLE& obstacle : obs )
145 ret.
Add( obstacle.m_item,
false );
164 if( aStartItems.
Empty() )
171 m_dragger = std::make_unique<COMPONENT_DRAGGER>(
this );
176 m_dragger = std::make_unique<DRAGGER>(
this );
191 if(
m_dragger->Start( aP, aStartItems ) )
206 if(
Settings().AllowDRCViolations() )
219 wxString failureReason;
224 if( item->BoardItem() && item->BoardItem()->GetLayer() ==
Edge_Cuts )
227 if( !item->Layers().Overlaps( aLayer ) )
230 if( item->IsRoutable() )
232 failureReason = wxEmptyString;
239 switch( parent->
Type() )
245 if(
pad->GetAttribute() == PAD_ATTRIB::NPTH )
246 failureReason =
_(
"Cannot start routing from a non-plated hole." );
252 ZONE* zone =
static_cast<ZONE*
>( parent );
256 failureReason = wxString::Format(
_(
"Rule area '%s' disallows tracks." ),
261 failureReason =
_(
"Rule area disallows tracks." );
269 failureReason =
_(
"Cannot start routing from a text item." );
278 if( !failureReason.IsEmpty() )
291 dummyStartSeg.
Append( startPoint );
292 dummyStartSeg.
Append( startPoint,
true );
294 dummyStartLine.
SetShape( dummyStartSeg );
296 dummyStartLine.
SetNet( aStartItem ? aStartItem->
Net() : 0 );
307 ITEM_SET dummyStartSet( &dummyStartLine );
312 for(
ITEM* item : highlightedItems )
324 SetFailureReason(
_(
"Cannot start a differential pair in the middle of nowhere." ) );
340 LINE dummyStartLineA;
341 LINE dummyStartLineB;
349 dummyStartLineA.
SetShape( dummyStartSegA );
354 dummyStartLineB.
SetShape( dummyStartSegB );
373 dummyStartSet.
Add( dummyStartLineA );
374 dummyStartSet.
Add( dummyStartLineB );
377 for(
ITEM* item : highlightedItems )
400 m_placer = std::make_unique<LINE_PLACER>(
this );
404 m_placer = std::make_unique<DIFF_PAIR_PLACER>(
this );
408 m_placer = std::make_unique<MEANDER_PLACER>(
this );
412 m_placer = std::make_unique<DP_MEANDER_PLACER>(
this );
416 m_placer = std::make_unique<MEANDER_SKEW_PLACER>(
this );
428 if(
m_placer->Start( aP, aStartItem ) )
475 ITEM*& aOtherEndItem )
483 if( placer ==
nullptr || placer->
Traces().
Size() == 0 )
488 if( trace ==
nullptr )
518 aOtherEndLayers = it->
Layers();
532 if( placer ==
nullptr || placer->
Traces().
Size() == 0 )
537 if( current ==
nullptr )
543 ITEM* otherEndItem =
nullptr;
556 Move( otherEnd, otherEndItem );
558 }
while( placer->
CurrentEnd() != moveResultPoint && triesLeft );
563 bool forceFinish =
false;
564 bool allowViolations =
false;
566 return FixRoute( otherEnd, otherEndItem, forceFinish, allowViolations );
577 if( placer ==
nullptr || placer->
Traces().
Size() == 0 )
582 if( current ==
nullptr )
589 ITEM* otherEndItem =
nullptr;
598 int nextLayer = otherEndLayers.
Overlaps( currentLayer ) ? currentLayer : otherEndLayers.
Start();
600 if( !
StartRouting( otherEnd, otherEndItem, nextLayer ) )
604 Move( currentEnd,
nullptr );
606 *aNewStartItem = otherEndItem;
627 [&](
ITEM* currentItem,
ITEM* itemToMark )
629 std::unique_ptr<ITEM> tmp( itemToMark->Clone() );
632 bool removeOriginal =
true;
634 clearance = aNode->
GetClearance( currentItem, itemToMark );
637 tmp->SetLayer( currentItem->
Layer() );
639 if( itemToMark->IsCompoundShapePrimitive() )
643 removeOriginal =
false;
649 aRemoved.push_back( itemToMark );
660 LINE* l =
static_cast<LINE*
>( item );
674 for(
const OBSTACLE& obs : obstacles )
677 if( draggedItems.
Contains( obs.m_item ) )
680 obs.m_item->Mark( obs.m_item->Marker() |
MK_VIOLATION );
681 updateItem( item, obs.m_item );
686 LINE* line =
static_cast<LINE*
>( item );
708 std::vector<const PNS::ITEM*> cacheCheckItems( added.begin(), added.end() );
711 for(
ITEM* item : added )
717 for(
ITEM* item : removed )
736 bool ret =
m_placer->Move( aP, aEndItem );
744 const LINE* l =
static_cast<const LINE*
>( item );
757 int annularWidth = std::max( 0,
via.Diameter() -
via.Drill() ) / 2;
758 int excessHoleClearance = holeClearance - annularWidth;
760 if( excessHoleClearance > clearance )
761 clearance = excessHoleClearance;
777 std::vector<PNS::ITEM*>& aHeads )
779 NODE *node =
nullptr;
784 node =
m_placer->CurrentNode(
true );
801 aHeads.push_back( item->Clone() );
816 for(
ITEM* item : removed )
818 bool is_changed =
false;
824 for( NODE::ITEM_VECTOR::iterator added_it = added.begin();
825 added_it != added.end(); ++added_it )
827 if( ( *added_it )->Parent() && ( *added_it )->Parent() == item->Parent() )
829 changed.push_back( *added_it );
830 added.erase( added_it );
837 if( !is_changed && !item->IsVirtual() )
841 for(
ITEM* item : added )
843 if( !item->IsVirtual() )
847 for(
ITEM* item : changed )
849 if( !item->IsVirtual() )
868 rv =
m_placer->FixRoute( aP, aEndItem, aForceFinish );
873 rv =
m_dragger->FixRoute( aForceCommit );
911 std::vector<NET_HANDLE> nets;
951 return m_placer->SetLayer( aLayer );
961 bool toggle = !
m_placer->IsPlacingVia();
977 return std::vector<NET_HANDLE>();
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
@ ROUNDED_90
H/V with filleted corners.
@ MITERED_90
H/V only (90-degree corners)
@ ROUNDED_45
H/V/45 with filleted corners.
@ MITERED_45
H/V/45 with mitered corners (default)
KICAD_T Type() const
Returns the type of object.
Represent a contiguous set of PCB layers.
bool IsMultilayer() const
bool Overlaps(const LAYER_RANGE &aOther) const
static bool FindDpPrimitivePair(NODE *aWorld, const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
Store starting/ending primitives (pads, vias or segments) for a differential pair.
const VECTOR2I & AnchorN() const
const VECTOR2I & AnchorP() const
virtual const ITEM_SET Traces()=0
Function Traces()
int Count(int aKindMask=-1) const
void Add(const LINE &aLine)
bool Contains(ITEM *aItem) const
std::vector< ITEM * > & Items()
const std::vector< ITEM * > & CItems() const
Base class for PNS router board items.
virtual NET_HANDLE Net() const
void SetNet(NET_HANDLE aNet)
virtual int Layer() const
void SetLayer(int aLayer)
const LAYER_RANGE & Layers() const
bool OfKind(int aKindMask) const
virtual VECTOR2I Anchor(int n) const
A 2D point on a given set of layers and belonging to a certain net, that links together a number of b...
Single track placement algorithm.
bool SplitAdjacentArcs(NODE *aNode, ITEM *aArc, const VECTOR2I &aP)
Snaps the point aP to arc aArc.
bool SplitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
Snaps the point aP to segment aSeg.
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
ITEM * GetBlockingObstacle() const
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
void SetWidth(int aWidth)
Return line width.
void Log(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), const ITEM *item=nullptr, const SIZES_SETTINGS *sizes=nullptr)
Keep the router "world" - i.e.
std::vector< ITEM * > ITEM_VECTOR
int GetClearance(const ITEM *aA, const ITEM *aB, bool aUseClearanceEpsilon=true) const
Return the pre-set worst case clearance between any pair of items.
void GetUpdatedItems(ITEM_VECTOR &aRemoved, ITEM_VECTOR &aAdded)
Return the list of items removed and added in this branch with respect to the root branch.
const JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, NET_HANDLE aNet) const
Search for a joint at a given position, layer and belonging to given net.
std::set< OBSTACLE > OBSTACLES
int QueryColliding(const ITEM *aItem, OBSTACLES &aObstacles, const COLLISION_SEARCH_OPTIONS &aOpts=COLLISION_SEARCH_OPTIONS()) const
Find items colliding (closer than clearance) with the item aItem.
const ITEM_SET HitTest(const VECTOR2I &aPoint) const
Find all items that contain the point aPoint.
virtual NODE * CurrentNode(bool aLoopsRemoved=false) const =0
Function CurrentNode()
virtual const VECTOR2I & CurrentEnd() const =0
Function CurrentEnd()
virtual const ITEM_SET Traces()=0
Function Traces()
virtual const VECTOR2I & CurrentStart() const =0
Function CurrentStart()
virtual int CurrentLayer() const =0
Function CurrentLayer()
virtual const std::vector< NET_HANDLE > CurrentNets() const =0
Function CurrentNets()
virtual void RemoveItem(ITEM *aItem)=0
virtual void UpdateItem(ITEM *aItem)=0
virtual void DisplayItem(const ITEM *aItem, int aClearance, bool aEdit=false, int aFlags=0)=0
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
virtual void HideItem(ITEM *aItem)=0
virtual void UpdateNet(NET_HANDLE aNet)=0
virtual void AddItem(ITEM *aItem)=0
virtual void EraseView()=0
virtual void SyncWorld(NODE *aNode)=0
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
void SetMode(ROUTER_MODE aMode)
bool moveDragging(const VECTOR2I &aP, ITEM *aItem)
bool SwitchLayer(int layer)
void ClearViewDecorations()
bool getNearestRatnestAnchor(VECTOR2I &aOtherEnd, LAYER_RANGE &aOtherEndLayers, ITEM *&aOtherEndItem)
PLACEMENT_ALGO * Placer()
void BreakSegmentOrArc(ITEM *aItem, const VECTOR2I &aP)
bool ContinueFromEnd(ITEM **aNewStartItem)
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
void SetFailureReason(const wxString &aReason)
std::unique_ptr< DRAG_ALGO > m_dragger
const ITEM_SET QueryHoverItems(const VECTOR2I &aP, int aSlopRadius=0)
void SetInterface(ROUTER_IFACE *aIface)
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
std::unique_ptr< PLACEMENT_ALGO > m_placer
bool isStartingPointRoutable(const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
bool IsPlacingVia() const
RULE_RESOLVER * GetRuleResolver() const
ROUTING_SETTINGS & Settings()
bool movePlacing(const VECTOR2I &aP, ITEM *aItem)
bool RoutingInProgress() const
static ROUTER * GetInstance()
std::optional< VECTOR2I > UndoLastSegment()
void SetOrthoMode(bool aEnable)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
int GetCurrentLayer() const
void GetUpdatedItems(std::vector< PNS::ITEM * > &aRemoved, std::vector< PNS::ITEM * > &aAdded, std::vector< PNS::ITEM * > &aHeads)
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish, bool aForceCommit)
std::unique_ptr< NODE > m_world
void ToggleViaPlacement()
ROUTING_SETTINGS * m_settings
const std::vector< NET_HANDLE > GetCurrentNets() const
bool Move(const VECTOR2I &aP, ITEM *aItem)
void SetCornerMode(DIRECTION_45::CORNER_MODE aMode)
DIRECTION_45::CORNER_MODE GetCornerMode() const
virtual void ClearCacheForItems(std::vector< const ITEM * > &aItems)
virtual void ClearTemporaryCaches()
virtual int Clearance(const ITEM *aA, const ITEM *aB, bool aUseClearanceEpsilon=true)=0
virtual void ClearCaches()
int DiffPairWidth() const
int BoardMinTrackWidth() const
ITEM * NearestUnconnectedItem(const JOINT *aStart, int *aAnchor=nullptr, int aKindMask=ITEM::ANY_T)
bool NearestUnconnectedAnchorPoint(const LINE *aTrack, VECTOR2I &aPoint, LAYER_RANGE &aLayers, ITEM *&aItem)
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.
const wxString & GetZoneName() const
static bool empty(const wxTextEntryBase *aCtrl)
Push and Shove diff pair dimensions (gap) settings dialog.
static ROUTER * theRouter
@ PNS_MODE_ROUTE_DIFF_PAIR
@ PNS_MODE_TUNE_DIFF_PAIR
@ PNS_MODE_TUNE_DIFF_PAIR_SKEW
Hold an object colliding with another object, along with some useful data about the collision.
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_PAD_T
class PAD, a pad in a footprint