Horizon
pns_router.h
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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
27#include <memory>
28#include <core/optional.h>
29#include <boost/unordered_set.hpp>
30
32#include <geometry/shape_line_chain.h>
33
34#include "pns_routing_settings.h"
35#include "pns_sizes_settings.h"
36#include "pns_item.h"
37#include "pns_itemset.h"
38#include "pns_node.h"
39#include "../wx_compat.h"
40
41namespace KIGFX
42{
43
44class VIEW;
45class VIEW_GROUP;
46
47}
48
49namespace PNS {
50
51class DEBUG_DECORATOR;
52class NODE;
53class DIFF_PAIR_PLACER;
54class PLACEMENT_ALGO;
55class LINE_PLACER;
56class ITEM;
57class LINE;
58class SOLID;
59class SEGMENT;
60class JOINT;
61class VIA;
62class RULE_RESOLVER;
63class SHOVE;
64class DRAGGER;
65
66enum ROUTER_MODE {
67 PNS_MODE_ROUTE_SINGLE = 1,
68 PNS_MODE_ROUTE_DIFF_PAIR,
69 PNS_MODE_TUNE_SINGLE,
70 PNS_MODE_TUNE_DIFF_PAIR,
71 PNS_MODE_TUNE_DIFF_PAIR_SKEW
72};
73
74enum DRAG_MODE
75{
76 DM_CORNER = 0x1,
77 DM_SEGMENT = 0x2,
78 DM_VIA = 0x4,
79 DM_FREE_ANGLE = 0x8,
80 DM_ANY = 0x7
81};
89 {
90 public:
91 ROUTER_IFACE() {};
92 virtual ~ROUTER_IFACE() {};
93
94 virtual void SetRouter( ROUTER* aRouter ) = 0;
95 virtual void SyncWorld( NODE* aNode ) = 0;
96 virtual void AddItem( ITEM* aItem ) = 0;
97 virtual void RemoveItem( ITEM* aItem ) = 0;
98 virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) = 0;
99 virtual bool IsItemVisible( const PNS::ITEM* aItem ) = 0;
100 virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
101 virtual void HideItem( ITEM* aItem ) = 0;
102 virtual void Commit() = 0;
103// virtual void Abort () = 0;
104
105 virtual void EraseView() = 0;
106 virtual void UpdateNet( int aNetCode ) = 0;
107
108 virtual RULE_RESOLVER* GetRuleResolver() = 0;
109 virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
110};
111
113{
114private:
115 enum RouterState
116 {
117 IDLE,
118 DRAG_SEGMENT,
119 ROUTE_TRACK
120 };
121
122public:
123 ROUTER();
124 ~ROUTER();
125
126 void SetInterface( ROUTER_IFACE* aIface );
127 void SetMode ( ROUTER_MODE aMode );
128 ROUTER_MODE Mode() const { return m_mode; }
129
130 static ROUTER* GetInstance();
131
132 void ClearWorld();
133 void SyncWorld();
134
135 void SetView( KIGFX::VIEW* aView );
136
137 bool RoutingInProgress() const;
138 bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
139 void Move( const VECTOR2I& aP, ITEM* aItem );
140 bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
141 void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
142
143 void StopRouting();
144
145 int GetClearance( const ITEM* aA, const ITEM* aB ) const;
146
147 NODE* GetWorld() const
148 {
149 return m_world.get();
150 }
151
152 void FlipPosture();
153
154 void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false );
155 void DisplayItems( const ITEM_SET& aItems );
156 void DeleteTraces( ITEM* aStartItem, bool aWholeTrack );
157 void SwitchLayer( int layer );
158
159 void ToggleViaPlacement();
160 void SetOrthoMode( bool aEnable );
161
162 int GetCurrentLayer() const;
163 const std::vector<int> GetCurrentNets() const;
164
165 void DumpLog();
166
167 RULE_RESOLVER* GetRuleResolver() const
168 {
169 return m_iface->GetRuleResolver();
170 }
171
172 bool IsPlacingVia() const;
173
174 const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
175 const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
176
177 bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
178
179 void SetIterLimit( int aX ) { m_iterLimit = aX; }
180 int GetIterLimit() const { return m_iterLimit; };
181
182 void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
183 {
184 m_showInterSteps = aX;
185 m_snapshotIter = aSnapshotIter;
186 }
187
188 bool GetShowIntermediateSteps() const { return m_showInterSteps; }
189 int GetShapshotIter() const { return m_snapshotIter; }
190
191 ROUTING_SETTINGS& Settings() { return m_settings; }
192
193 void CommitRouting( NODE* aNode );
194
199 void UpdateSizes( const SIZES_SETTINGS& aSizes );
200
205 void LoadSettings( const ROUTING_SETTINGS& aSettings )
206 {
207 m_settings = aSettings;
208 }
209
210 SIZES_SETTINGS& Sizes()
211 {
212 return m_sizes;
213 }
214
215 void SetFailureReason( const std::string& aReason ) { m_failureReason = aReason; }
216 const std::string& FailureReason() const { return m_failureReason; }
217
218 PLACEMENT_ALGO* Placer() { return m_placer.get(); }
219
220 ROUTER_IFACE* GetInterface() const
221 {
222 return m_iface;
223 }
224
225private:
226 void movePlacing( const VECTOR2I& aP, ITEM* aItem );
227 void moveDragging( const VECTOR2I& aP, ITEM* aItem );
228
229 void eraseView();
230 void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
231
232 void clearViewFlags();
233
234 // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
235
236 ITEM* pickSingleItem( ITEM_SET& aItems ) const;
237 void splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
238
239 ITEM* syncPad( D_PAD* aPad );
240 ITEM* syncTrack( TRACK* aTrack );
241 ITEM* syncVia( VIA* aVia );
242
243 void commitPad( SOLID* aPad );
244 void commitSegment( SEGMENT* aTrack );
245 void commitVia( VIA* aVia );
246
247 void highlightCurrent( bool enabled );
248
249 void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
250 bool isStartingPointRoutable( const VECTOR2I& aWhere, int aLayer );
251
252 VECTOR2I m_currentEnd;
253 RouterState m_state;
254
255 std::unique_ptr< NODE > m_world;
256 NODE* m_lastNode;
257
258 std::unique_ptr< PLACEMENT_ALGO > m_placer;
259 std::unique_ptr< DRAGGER > m_dragger;
260 std::unique_ptr< SHOVE > m_shove;
261
262 ROUTER_IFACE* m_iface;
263
264 int m_iterLimit;
265 bool m_showInterSteps;
266 int m_snapshotIter;
267 bool m_violation;
268 bool m_forceMarkObstaclesMode = false;
269
270 ROUTING_SETTINGS m_settings;
271 SIZES_SETTINGS m_sizes;
272 ROUTER_MODE m_mode;
273
274 std::string m_toolStatusbarName;
275 std::string m_failureReason;
276};
277
278}
279
280#endif
Class LAYER_RANGE.
Definition: pns_layerset.h:33
Definition: pns_debug_decorator.h:33
Definition: pns_itemset.h:40
Class ITEM.
Definition: pns_item.h:55
Class NODE.
Definition: pns_node.h:138
Class ROUTER.
Definition: pns_router.h:89
Definition: pns_router.h:113
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:319
void LoadSettings(const ROUTING_SETTINGS &aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:205
Class ROUTING_SETTINGS.
Definition: pns_routing_settings.h:58
Class RULE_RESOLVER.
Definition: pns_node.h:58
Definition: pns_sizes_settings.h:37
Board layer functions and definitions.