KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_router.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef __PNS_ROUTER_H
23#define __PNS_ROUTER_H
24
25#include <list>
26#include <memory>
27#include <optional>
28#include <math/box2.h>
29
31#include "pns_sizes_settings.h"
32#include "pns_node.h"
33
34#include <layer_ids.h>
35
36
37class NETCLASS;
38
39namespace KIGFX
40{
41
42class VIEW;
43class VIEW_GROUP;
44
45}
46
47namespace PNS {
48
49class DEBUG_DECORATOR;
50class NODE;
52class PLACEMENT_ALGO;
53class LINE_PLACER;
54class ITEM;
55class ARC;
56class LINE;
57class SOLID;
58class SEGMENT;
59class JOINT;
60class VIA;
61class RULE_RESOLVER;
62class SHOVE;
63class DRAGGER;
64class DRAG_ALGO;
65class LOGGER;
66class DIFF_PAIR;
67
76
78{
79 DM_CORNER = 0x1,
81 DM_VIA = 0x4,
83 DM_ARC = 0x10,
84 DM_ANY = 0x17,
86 DM_BLOCK = 0x40
87};
88
93
95 {
96 public:
98 virtual ~ROUTER_IFACE() {};
99
100 virtual void SyncWorld( NODE* aNode ) = 0;
101 virtual void AddItem( ITEM* aItem ) = 0;
102 virtual void UpdateItem( ITEM* aItem ) = 0;
103 virtual void RemoveItem( ITEM* aItem ) = 0;
104 virtual bool IsAnyLayerVisible( const PNS_LAYER_RANGE& aLayer ) const = 0;
105 virtual bool IsItemVisible( const PNS::ITEM* aItem ) const = 0;
106 virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const = 0;
107 virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, const PNS_LAYER_RANGE& aLayer ) const = 0;
108 virtual bool IsPNSCopperLayer( int aPNSLayer ) const = 0;
109 virtual void DisplayItem( const ITEM* aItem, int aClearance, bool aEdit = false,
110 int aFlags = 0 ) = 0;
111 virtual void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) = 0;
112 virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, NET_HANDLE aNetCode ) = 0;
113 virtual void HideItem( ITEM* aItem ) = 0;
114 virtual void Commit() = 0;
115 virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, NET_HANDLE aNet, VECTOR2D aStartPosition ) = 0;
116 virtual int StackupHeight( int aFirstLayer, int aSecondLayer ) const = 0;
117 virtual void EraseView() = 0;
118 virtual int GetNetCode( NET_HANDLE aNet ) const = 0;
119 virtual wxString GetNetName( PNS::NET_HANDLE aNet ) const = 0;
120 virtual void UpdateNet( NET_HANDLE aNet ) = 0;
122 virtual PNS::NODE* GetWorld() const = 0;
123
126
127 virtual long long int CalculateRoutedPathLength( const ITEM_SET& aLine, const SOLID* aStartPad,
128 const SOLID* aEndPad, const NETCLASS* aNetClass ) = 0;
129 virtual int64_t CalculateRoutedPathDelay( const ITEM_SET& aLine, const SOLID* aStartPad, const SOLID* aEndPad,
130 const NETCLASS* aNetClass ) = 0;
131 virtual int64_t CalculateLengthForDelay( int64_t aDesiredDelay, int aWidth, bool aIsDiffPairCoupled,
132 int aDiffPairCouplingGap, int aPNSLayer, const NETCLASS* aNetClass ) = 0;
133 virtual int64_t CalculateDelayForShapeLineChain( const SHAPE_LINE_CHAIN& aShape, int aWidth,
134 bool aIsDiffPairCoupled, int aDiffPairCouplingGap, int aPNSLayer,
135 const NETCLASS* aNetClass ) = 0;
136 virtual PCB_LAYER_ID GetBoardLayerFromPNSLayer( int aLayer ) const = 0;
137 virtual int GetPNSLayerFromBoardLayer( PCB_LAYER_ID aLayer ) const = 0;
138 virtual bool GetSignalAggregate( NET_HANDLE aNetP, NET_HANDLE aNetN,
139 long long& aExtraLength, long long& aExtraDelay ) const = 0;
140
141 virtual long long GetNetBoardLength( NET_HANDLE aNet ) const { return 0; }
142
147 virtual void RemoveBoardConnected( const std::vector<const ITEM*>& aJoined, std::set<ITEM*>& aItems ) const {}
148
150 virtual bool TouchesCopperZone( const ITEM* aItem ) const { return true; }
151
157 {
158 if( aSizes.ViaType() == VIATYPE::THROUGH )
161
162 return PNS_LAYER_RANGE( aSizes.GetLayerTop(), aSizes.GetLayerBottom() );
163 }
164};
165
167{
168public:
176
177public:
178 ROUTER();
179 ~ROUTER();
180
181 void SetInterface( ROUTER_IFACE* aIface );
182 void SetMode ( ROUTER_MODE aMode );
183 ROUTER_MODE Mode() const { return m_mode; }
184
185 RouterState GetState() const { return m_state; }
186
187 DRAG_ALGO* GetDragger() { return m_dragger.get(); }
188
189 static ROUTER* GetInstance();
190
191 void ClearWorld();
192 void SyncWorld();
193
194 bool RoutingInProgress() const;
195 bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer, const ITEM_SET& aAuxItems = ITEM_SET() );
196 bool Move( const VECTOR2I& aP, ITEM* aItem );
197 bool Finish();
198 bool ContinueFromEnd( ITEM** aNewStartItem );
199 bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish, bool aForceCommit );
200 void BreakSegmentOrArc( ITEM *aItem, const VECTOR2I& aP );
201
202 std::optional<VECTOR2I> UndoLastSegment();
203 void CommitRouting();
204
205 void GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS::ITEM*>& aAdded,
206 std::vector<PNS::ITEM*>& aHeads );
207
208 void AbortPlacement();
209 void StopRouting();
211
212 NODE* GetWorld() const { return m_world.get(); }
213
214 void FlipPosture();
215
216 bool SwitchLayer( int layer );
217
218 void ToggleViaPlacement();
219 void SetOrthoMode( bool aEnable );
220
221 void ToggleCornerMode();
222
223 int GetCurrentLayer() const;
224 const std::vector<NET_HANDLE> GetCurrentNets() const;
225
226 LOGGER* Logger();
227
228 RULE_RESOLVER* GetRuleResolver() const { return m_iface->GetRuleResolver(); }
229
230 bool IsPlacingVia() const;
231
232 const ITEM_SET QueryHoverItems( const VECTOR2I& aP, int aSlopRadius = 0 );
233
234 bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
235 bool StartDragging( const VECTOR2I& aP, ITEM_SET aItems, int aDragMode = DM_COMPONENT );
236
237 void SetIterLimit( int aX ) { m_iterLimit = aX; }
238 int GetIterLimit() const { return m_iterLimit; };
239
241
242 void CommitRouting( NODE* aNode );
243
248 void UpdateSizes( const SIZES_SETTINGS& aSizes );
249
255 {
256 m_settings = aSettings;
257 }
258
260
261 void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
262 const wxString& FailureReason() const { return m_failureReason; }
263
264 PLACEMENT_ALGO* Placer() { return m_placer.get(); }
265
266 ROUTER_IFACE* GetInterface() const { return m_iface; }
267
268 void SetVisibleViewArea( const BOX2I& aExtents ) { m_visibleViewArea = aExtents; }
269 const BOX2I& VisibleViewArea() const { return m_visibleViewArea; }
270
271 std::vector<PNS::ITEM*> GetLastCommittedLeaderSegments();
272
273 bool GetNearestRatnestAnchor( VECTOR2I& aOtherEnd, PNS_LAYER_RANGE& aOtherEndLayers,
274 ITEM*& aOtherEndItem );
275
276
277private:
278
280 {
282 }
283
284 bool areWeLengthTuning() const;
285 bool hasDiffPairMembers( const ITEM_SET& aItems ) const;
286
287 bool movePlacing( const VECTOR2I& aP, ITEM* aItem );
288 bool moveDragging( const VECTOR2I& aP, ITEM* aItem );
289
290 void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
291
292 // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
293
294 void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
295 bool isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aItem, int aLayer );
296
297
298private:
301
302 std::unique_ptr<NODE> m_world;
304
305 std::unique_ptr<PLACEMENT_ALGO> m_placer;
306 std::unique_ptr<DRAG_ALGO> m_dragger;
307 std::unique_ptr<SHOVE> m_shove;
308 std::vector<PNS::ITEM*> m_leaderSegments;
309
311
313
318
321};
322
323}
324
325#endif
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition view_group.h:39
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
Single track placement algorithm.
Basic class for a differential pair.
DRAGGER.
Definition pns_dragger.h:48
Base class for PNS router board items.
Definition pns_item.h:98
A 2D point on a given set of layers and belonging to a certain net, that links together a number of b...
Definition pns_joint.h:43
Single track placement algorithm.
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
Keep the router "world" - i.e.
Definition pns_node.h:274
std::vector< ITEM * > ITEM_VECTOR
Definition pns_node.h:285
Abstract class for a P&S placement/dragging algorithm.
virtual void DisplayPathLine(const SHAPE_LINE_CHAIN &aLine, int aImportance)=0
virtual long long GetNetBoardLength(NET_HANDLE aNet) const
Definition pns_router.h:141
virtual int GetPNSLayerFromBoardLayer(PCB_LAYER_ID aLayer) const =0
virtual void RemoveItem(ITEM *aItem)=0
virtual void UpdateItem(ITEM *aItem)=0
virtual ~ROUTER_IFACE()
Definition pns_router.h:98
virtual wxString GetNetName(PNS::NET_HANDLE aNet) const =0
virtual bool TouchesCopperZone(const ITEM *aItem) const
Copper zones are absent from NODE joints, so tail pruning must keep items that touch one.
Definition pns_router.h:150
virtual int64_t CalculateDelayForShapeLineChain(const SHAPE_LINE_CHAIN &aShape, int aWidth, bool aIsDiffPairCoupled, int aDiffPairCouplingGap, int aPNSLayer, const NETCLASS *aNetClass)=0
virtual bool IsItemVisible(const PNS::ITEM *aItem) const =0
virtual void DisplayItem(const ITEM *aItem, int aClearance, bool aEdit=false, int aFlags=0)=0
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
virtual bool GetSignalAggregate(NET_HANDLE aNetP, NET_HANDLE aNetN, long long &aExtraLength, long long &aExtraDelay) const =0
virtual long long int CalculateRoutedPathLength(const ITEM_SET &aLine, const SOLID *aStartPad, const SOLID *aEndPad, const NETCLASS *aNetClass)=0
virtual void HideItem(ITEM *aItem)=0
virtual int GetNetCode(NET_HANDLE aNet) const =0
virtual bool IsPNSCopperLayer(int aPNSLayer) const =0
PNS_LAYER_RANGE GetViaLayerRange(const SIZES_SETTINGS &aSizes) const
Return the layer span a via placed with aSizes occupies.
Definition pns_router.h:156
virtual void Commit()=0
virtual RULE_RESOLVER * GetRuleResolver()=0
virtual PCB_LAYER_ID GetBoardLayerFromPNSLayer(int aLayer) const =0
virtual void UpdateNet(NET_HANDLE aNet)=0
virtual void AddItem(ITEM *aItem)=0
virtual void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, NET_HANDLE aNetCode)=0
virtual int64_t CalculateLengthForDelay(int64_t aDesiredDelay, int aWidth, bool aIsDiffPairCoupled, int aDiffPairCouplingGap, int aPNSLayer, const NETCLASS *aNetClass)=0
virtual bool ImportSizes(SIZES_SETTINGS &aSizes, ITEM *aStartItem, NET_HANDLE aNet, VECTOR2D aStartPosition)=0
virtual void EraseView()=0
virtual void SyncWorld(NODE *aNode)=0
virtual bool IsFlashedOnLayer(const PNS::ITEM *aItem, int aLayer) const =0
virtual NET_HANDLE GetOrphanedNetHandle()=0
virtual int StackupHeight(int aFirstLayer, int aSecondLayer) const =0
virtual bool IsFlashedOnLayer(const PNS::ITEM *aItem, const PNS_LAYER_RANGE &aLayer) const =0
virtual int64_t CalculateRoutedPathDelay(const ITEM_SET &aLine, const SOLID *aStartPad, const SOLID *aEndPad, const NETCLASS *aNetClass)=0
virtual bool IsAnyLayerVisible(const PNS_LAYER_RANGE &aLayer) const =0
virtual void RemoveBoardConnected(const std::vector< const ITEM * > &aJoined, std::set< ITEM * > &aItems) const
Remove from aItems every item the board already joins to one of aJoined through objects the router do...
Definition pns_router.h:147
virtual PNS::NODE * GetWorld() const =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 StopRouting()
void SetIterLimit(int aX)
Definition pns_router.h:237
void ClearViewDecorations()
std::vector< PNS::ITEM * > m_leaderSegments
Definition pns_router.h:308
void ToggleCornerMode()
PLACEMENT_ALGO * Placer()
Definition pns_router.h:264
std::vector< PNS::ITEM * > GetLastCommittedLeaderSegments()
NODE * m_lastNode
Definition pns_router.h:303
void ClearWorld()
ROUTER_IFACE * GetInterface() const
Definition pns_router.h:266
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)
Definition pns_router.h:261
LOGGER * Logger()
ROUTER_MODE Mode() const
Definition pns_router.h:183
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition pns_router.h:254
RouterState m_state
Definition pns_router.h:300
void CommitRouting()
std::unique_ptr< DRAG_ALGO > m_dragger
Definition pns_router.h:306
const ITEM_SET QueryHoverItems(const VECTOR2I &aP, int aSlopRadius=0)
void SetInterface(ROUTER_IFACE *aIface)
const BOX2I & VisibleViewArea() const
Definition pns_router.h:269
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
void SyncWorld()
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition pns_router.h:305
int GetIterLimit() const
Definition pns_router.h:238
const wxString & FailureReason() const
Definition pns_router.h:262
bool isStartingPointRoutable(const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
ROUTER_IFACE * m_iface
Definition pns_router.h:310
bool IsPlacingVia() const
void FlipPosture()
RULE_RESOLVER * GetRuleResolver() const
Definition pns_router.h:228
SIZES_SETTINGS m_sizes
Definition pns_router.h:315
DEBUG_DECORATOR * dbg() const
Definition pns_router.h:279
ROUTING_SETTINGS & Settings()
Definition pns_router.h:240
DRAG_ALGO * GetDragger()
Definition pns_router.h:187
bool movePlacing(const VECTOR2I &aP, ITEM *aItem)
bool RoutingInProgress() const
RouterState GetState() const
Definition pns_router.h:185
BOX2I m_visibleViewArea
Definition pns_router.h:299
static ROUTER * GetInstance()
std::optional< VECTOR2I > UndoLastSegment()
void AbortPlacement()
LOGGER * m_logger
Definition pns_router.h:317
void SetOrthoMode(bool aEnable)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
void SetVisibleViewArea(const BOX2I &aExtents)
Definition pns_router.h:268
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer, const ITEM_SET &aAuxItems=ITEM_SET())
bool areWeLengthTuning() const
int GetCurrentLayer() const
void GetUpdatedItems(std::vector< PNS::ITEM * > &aRemoved, std::vector< PNS::ITEM * > &aAdded, std::vector< PNS::ITEM * > &aHeads)
SIZES_SETTINGS & Sizes()
Definition pns_router.h:259
std::unique_ptr< SHOVE > m_shove
Definition pns_router.h:307
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish, bool aForceCommit)
std::unique_ptr< NODE > m_world
Definition pns_router.h:302
void ToggleViaPlacement()
NODE * GetWorld() const
Definition pns_router.h:212
ROUTING_SETTINGS * m_settings
Definition pns_router.h:314
wxString m_failureReason
Definition pns_router.h:320
bool hasDiffPairMembers(const ITEM_SET &aItems) const
const std::vector< NET_HANDLE > GetCurrentNets() const
ROUTER_MODE m_mode
Definition pns_router.h:316
wxString m_toolStatusbarName
Definition pns_router.h:319
bool GetNearestRatnestAnchor(VECTOR2I &aOtherEnd, PNS_LAYER_RANGE &aOtherEndLayers, ITEM *&aOtherEndItem)
bool Move(const VECTOR2I &aP, ITEM *aItem)
Contain all persistent settings of the router, such as the mode, optimization effort,...
The actual Push and Shove algorithm.
Definition pns_shove.h:48
Represent a contiguous set of PCB layers.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition pns_item.h:55
ROUTER_MODE
Definition pns_router.h:68
@ PNS_MODE_ROUTE_SINGLE
Definition pns_router.h:69
@ PNS_MODE_ROUTE_DIFF_PAIR
Definition pns_router.h:70
@ PNS_MODE_SPREAD_TRACKS
Definition pns_router.h:74
@ PNS_MODE_TUNE_DIFF_PAIR
Definition pns_router.h:72
@ PNS_MODE_TUNE_SINGLE
Definition pns_router.h:71
@ PNS_MODE_TUNE_DIFF_PAIR_SKEW
Definition pns_router.h:73
DRAG_MODE
Definition pns_router.h:78
@ DM_CORNER
Definition pns_router.h:79
@ DM_ANY
Definition pns_router.h:84
@ DM_FREE_ANGLE
Definition pns_router.h:82
@ DM_VIA
Definition pns_router.h:81
@ DM_BLOCK
Definition pns_router.h:86
@ DM_SEGMENT
Definition pns_router.h:80
@ DM_ARC
Definition pns_router.h:83
@ DM_COMPONENT
Definition pns_router.h:85
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707