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 (C) 2016-2024 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 along
19 * with this program. If not, see <http://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
34namespace KIGFX
35{
36
37class VIEW;
38class VIEW_GROUP;
39
40}
41
42namespace PNS {
43
44class DEBUG_DECORATOR;
45class NODE;
46class DIFF_PAIR_PLACER;
47class PLACEMENT_ALGO;
48class LINE_PLACER;
49class ITEM;
50class ARC;
51class LINE;
52class SOLID;
53class SEGMENT;
54class JOINT;
55class VIA;
56class RULE_RESOLVER;
57class SHOVE;
58class DRAGGER;
59class DRAG_ALGO;
60class LOGGER;
61
68};
69
71{
72 DM_CORNER = 0x1,
74 DM_VIA = 0x4,
76 DM_ARC = 0x10,
77 DM_ANY = 0x17,
78 DM_COMPONENT = 0x20
79};
87 {
88 public:
90 virtual ~ROUTER_IFACE() {};
91
92 virtual void SyncWorld( NODE* aNode ) = 0;
93 virtual void AddItem( ITEM* aItem ) = 0;
94 virtual void UpdateItem( ITEM* aItem ) = 0;
95 virtual void RemoveItem( ITEM* aItem ) = 0;
96 virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) const = 0;
97 virtual bool IsItemVisible( const PNS::ITEM* aItem ) const = 0;
98 virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const = 0;
99 virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, const LAYER_RANGE& aLayer ) const = 0;
100 virtual void DisplayItem( const ITEM* aItem, int aClearance, bool aEdit = false,
101 int aFlags = 0 ) = 0;
102 virtual void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) = 0;
103 virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, NET_HANDLE aNetCode ) = 0;
104 virtual void HideItem( ITEM* aItem ) = 0;
105 virtual void Commit() = 0;
106 virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, NET_HANDLE aNet,
107 VECTOR2D aStartPosition ) = 0;
108 virtual int StackupHeight( int aFirstLayer, int aSecondLayer ) const = 0;
109 virtual void EraseView() = 0;
110 virtual int GetNetCode( NET_HANDLE aNet ) const = 0;
111 virtual wxString GetNetName( PNS::NET_HANDLE aNet ) const = 0;
112 virtual void UpdateNet( NET_HANDLE aNet ) = 0;
114 virtual PNS::NODE* GetWorld() const = 0;
115
118};
119
121{
122public:
124 {
129 };
130
131public:
132 ROUTER();
133 ~ROUTER();
134
135 void SetInterface( ROUTER_IFACE* aIface );
136 void SetMode ( ROUTER_MODE aMode );
137 ROUTER_MODE Mode() const { return m_mode; }
138
139 RouterState GetState() const { return m_state; }
140
141 DRAG_ALGO* GetDragger() { return m_dragger.get(); }
142
143 static ROUTER* GetInstance();
144
145 void ClearWorld();
146 void SyncWorld();
147
148 bool RoutingInProgress() const;
149 bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
150 bool Move( const VECTOR2I& aP, ITEM* aItem );
151 bool Finish();
152 bool ContinueFromEnd( ITEM** aNewStartItem );
153 bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish, bool aForceCommit );
154 void BreakSegmentOrArc( ITEM *aItem, const VECTOR2I& aP );
155
156 std::optional<VECTOR2I> UndoLastSegment();
157 void CommitRouting();
158
159 void GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS::ITEM*>& aAdded,
160 std::vector<PNS::ITEM*>& aHeads );
161
162 void StopRouting();
164
165 NODE* GetWorld() const { return m_world.get(); }
166
167 void FlipPosture();
168
169 bool SwitchLayer( int layer );
170
171 void ToggleViaPlacement();
172 void SetOrthoMode( bool aEnable );
173
174 void ToggleCornerMode();
175
176 int GetCurrentLayer() const;
177 const std::vector<NET_HANDLE> GetCurrentNets() const;
178
179 LOGGER* Logger();
180
182
183 bool IsPlacingVia() const;
184
185 const ITEM_SET QueryHoverItems( const VECTOR2I& aP, int aSlopRadius = 0 );
186
187 bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
188 bool StartDragging( const VECTOR2I& aP, ITEM_SET aItems, int aDragMode = DM_COMPONENT );
189
190 void SetIterLimit( int aX ) { m_iterLimit = aX; }
191 int GetIterLimit() const { return m_iterLimit; };
192
194
195 void CommitRouting( NODE* aNode );
196
201 void UpdateSizes( const SIZES_SETTINGS& aSizes );
202
208 {
209 m_settings = aSettings;
210 }
211
213
214 void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
215 const wxString& FailureReason() const { return m_failureReason; }
216
217 PLACEMENT_ALGO* Placer() { return m_placer.get(); }
218
219 ROUTER_IFACE* GetInterface() const { return m_iface; }
220
221 void SetVisibleViewArea( const BOX2I& aExtents ) { m_visibleViewArea = aExtents; }
222 const BOX2I& VisibleViewArea() const { return m_visibleViewArea; }
223
224private:
225 bool movePlacing( const VECTOR2I& aP, ITEM* aItem );
226 bool moveDragging( const VECTOR2I& aP, ITEM* aItem );
227
228 void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
229
230 // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
231
232 void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
233 bool isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aItem, int aLayer );
234
235 bool getNearestRatnestAnchor( VECTOR2I& aOtherEnd, LAYER_RANGE& aOtherEndLayers,
236 ITEM*& aOtherEndItem );
237
238
239private:
242
243 std::unique_ptr<NODE> m_world;
245
246 std::unique_ptr<PLACEMENT_ALGO> m_placer;
247 std::unique_ptr<DRAG_ALGO> m_dragger;
248 std::unique_ptr<SHOVE> m_shove;
249
251
253
258
261};
262
263}
264
265#endif
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
DRAG_ALGO.
Definition: pns_drag_algo.h:44
Base class for PNS router board items.
Definition: pns_item.h:97
Keep the router "world" - i.e.
Definition: pns_node.h:207
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:218
virtual void DisplayPathLine(const SHAPE_LINE_CHAIN &aLine, int aImportance)=0
virtual void RemoveItem(ITEM *aItem)=0
virtual void UpdateItem(ITEM *aItem)=0
virtual ~ROUTER_IFACE()
Definition: pns_router.h:90
virtual wxString GetNetName(PNS::NET_HANDLE aNet) const =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 void HideItem(ITEM *aItem)=0
virtual bool IsFlashedOnLayer(const PNS::ITEM *aItem, const LAYER_RANGE &aLayer) const =0
virtual int GetNetCode(NET_HANDLE aNet) const =0
virtual void Commit()=0
virtual RULE_RESOLVER * GetRuleResolver()=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 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 IsAnyLayerVisible(const LAYER_RANGE &aLayer) const =0
virtual PNS::NODE * GetWorld() const =0
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:699
void SetMode(ROUTER_MODE aMode)
bool moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:615
bool SwitchLayer(int layer)
Definition: pns_router.cpp:951
void StopRouting()
Definition: pns_router.cpp:908
void SetIterLimit(int aX)
Definition: pns_router.h:190
void ClearViewDecorations()
Definition: pns_router.cpp:936
bool getNearestRatnestAnchor(VECTOR2I &aOtherEnd, LAYER_RANGE &aOtherEndLayers, ITEM *&aOtherEndItem)
Definition: pns_router.cpp:477
void ToggleCornerMode()
int m_iterLimit
Definition: pns_router.h:252
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:217
NODE * m_lastNode
Definition: pns_router.h:244
void ClearWorld()
Definition: pns_router.cpp:104
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:219
void BreakSegmentOrArc(ITEM *aItem, const VECTOR2I &aP)
bool ContinueFromEnd(ITEM **aNewStartItem)
Definition: pns_router.cpp:576
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:725
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:214
LOGGER * Logger()
Definition: pns_router.cpp:995
ROUTER_MODE Mode() const
Definition: pns_router.h:137
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:207
RouterState m_state
Definition: pns_router.h:241
void CommitRouting()
Definition: pns_router.cpp:899
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:247
const ITEM_SET QueryHoverItems(const VECTOR2I &aP, int aSlopRadius=0)
Definition: pns_router.cpp:123
void SetInterface(ROUTER_IFACE *aIface)
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:222
bool Finish()
Definition: pns_router.cpp:528
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:627
void SyncWorld()
Definition: pns_router.cpp:94
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:246
int GetIterLimit() const
Definition: pns_router.h:191
const wxString & FailureReason() const
Definition: pns_router.h:215
bool isStartingPointRoutable(const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:204
ROUTER_IFACE * m_iface
Definition: pns_router.h:250
bool IsPlacingVia() const
void FlipPosture()
Definition: pns_router.cpp:942
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:181
SIZES_SETTINGS m_sizes
Definition: pns_router.h:255
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:193
DRAG_ALGO * GetDragger()
Definition: pns_router.h:141
bool movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:735
bool RoutingInProgress() const
Definition: pns_router.cpp:117
RouterState GetState() const
Definition: pns_router.h:139
BOX2I m_visibleViewArea
Definition: pns_router.h:240
static ROUTER * GetInstance()
Definition: pns_router.cpp:80
std::optional< VECTOR2I > UndoLastSegment()
Definition: pns_router.cpp:887
LOGGER * m_logger
Definition: pns_router.h:257
void SetOrthoMode(bool aEnable)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:156
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:393
void SetVisibleViewArea(const BOX2I &aExtents)
Definition: pns_router.h:221
int GetCurrentLayer() const
Definition: pns_router.cpp:984
void GetUpdatedItems(std::vector< PNS::ITEM * > &aRemoved, std::vector< PNS::ITEM * > &aAdded, std::vector< PNS::ITEM * > &aHeads)
Definition: pns_router.cpp:779
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:212
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:248
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish, bool aForceCommit)
Definition: pns_router.cpp:861
std::unique_ptr< NODE > m_world
Definition: pns_router.h:243
void ToggleViaPlacement()
Definition: pns_router.cpp:960
NODE * GetWorld() const
Definition: pns_router.h:165
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:254
wxString m_failureReason
Definition: pns_router.h:260
const std::vector< NET_HANDLE > GetCurrentNets() const
Definition: pns_router.cpp:973
ROUTER_MODE m_mode
Definition: pns_router.h:256
wxString m_toolStatusbarName
Definition: pns_router.h:259
bool Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:453
Contain all persistent settings of the router, such as the mode, optimization effort,...
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54
ROUTER_MODE
Definition: pns_router.h:62
@ PNS_MODE_ROUTE_SINGLE
Definition: pns_router.h:63
@ PNS_MODE_ROUTE_DIFF_PAIR
Definition: pns_router.h:64
@ 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
DRAG_MODE
Definition: pns_router.h:71
@ DM_CORNER
Definition: pns_router.h:72
@ DM_ANY
Definition: pns_router.h:77
@ DM_FREE_ANGLE
Definition: pns_router.h:75
@ DM_VIA
Definition: pns_router.h:74
@ DM_SEGMENT
Definition: pns_router.h:73
@ DM_ARC
Definition: pns_router.h:76
@ DM_COMPONENT
Definition: pns_router.h:78
@ VIA
Normal via.
Definition: router_tool.cpp:95