KiCad PCB EDA Suite
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 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 
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 
40 namespace KIGFX
41 {
42 
43 class VIEW;
44 class VIEW_GROUP;
45 
46 }
47 
48 namespace PNS {
49 
50 class DEBUG_DECORATOR;
51 class NODE;
52 class DIFF_PAIR_PLACER;
53 class PLACEMENT_ALGO;
54 class LINE_PLACER;
55 class ITEM;
56 class LINE;
57 class SOLID;
58 class SEGMENT;
59 class JOINT;
60 class VIA;
61 class RULE_RESOLVER;
62 class SHOVE;
63 class DRAGGER;
64 
71 };
72 
74 {
75  DM_CORNER = 0x1,
76  DM_SEGMENT = 0x2,
77  DM_VIA = 0x4,
79  DM_ANY = 0x7
80 };
88  {
89  public:
91  virtual ~ROUTER_IFACE() {};
92 
93  virtual void SetRouter( ROUTER* aRouter ) = 0;
94  virtual void SyncWorld( NODE* aNode ) = 0;
95  virtual void AddItem( ITEM* aItem ) = 0;
96  virtual void RemoveItem( ITEM* aItem ) = 0;
97  virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) = 0;
98  virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
99  virtual void HideItem( ITEM* aItem ) = 0;
100  virtual void Commit() = 0;
101 // virtual void Abort () = 0;
102 
103  virtual void EraseView() = 0;
104  virtual void UpdateNet( int aNetCode ) = 0;
105 
106  virtual RULE_RESOLVER* GetRuleResolver() = 0;
107  virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
108 };
109 
110 class ROUTER
111 {
112 private:
114  {
118  };
119 
120 public:
121  ROUTER();
122  ~ROUTER();
123 
124  void SetInterface( ROUTER_IFACE* aIface );
125  void SetMode ( ROUTER_MODE aMode );
126  ROUTER_MODE Mode() const { return m_mode; }
127 
128  static ROUTER* GetInstance();
129 
130  void ClearWorld();
131  void SyncWorld();
132 
133  void SetView( KIGFX::VIEW* aView );
134 
135  bool RoutingInProgress() const;
136  bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
137  void Move( const VECTOR2I& aP, ITEM* aItem );
138  bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
139  void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
140 
141  void StopRouting();
142 
143  int GetClearance( const ITEM* aA, const ITEM* aB ) const;
144 
145  NODE* GetWorld() const
146  {
147  return m_world.get();
148  }
149 
150  void FlipPosture();
151 
152  void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false );
153  void DisplayItems( const ITEM_SET& aItems );
154  void DeleteTraces( ITEM* aStartItem, bool aWholeTrack );
155  void SwitchLayer( int layer );
156 
157  void ToggleViaPlacement();
158  void SetOrthoMode( bool aEnable );
159 
160  int GetCurrentLayer() const;
161  const std::vector<int> GetCurrentNets() const;
162 
163  void DumpLog();
164 
166  {
167  return m_iface->GetRuleResolver();
168  }
169 
170  bool IsPlacingVia() const;
171 
172  const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
173  const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
174 
175  bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
176 
177  void SetIterLimit( int aX ) { m_iterLimit = aX; }
178  int GetIterLimit() const { return m_iterLimit; };
179 
180  void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
181  {
182  m_showInterSteps = aX;
183  m_snapshotIter = aSnapshotIter;
184  }
185 
187  int GetShapshotIter() const { return m_snapshotIter; }
188 
190 
191  void CommitRouting( NODE* aNode );
192 
197  void UpdateSizes( const SIZES_SETTINGS& aSizes );
198 
203  void LoadSettings( const ROUTING_SETTINGS& aSettings )
204  {
205  m_settings = aSettings;
206  }
207 
209  {
210  return m_sizes;
211  }
212 
213  ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const;
214 
215  void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
216  const wxString& FailureReason() const { return m_failureReason; }
217 
218  PLACEMENT_ALGO* Placer() { return m_placer.get(); }
219 
221  {
222  return m_iface;
223  }
224 
225 private:
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 
254 
255  std::unique_ptr< NODE > m_world;
257 
258  std::unique_ptr< PLACEMENT_ALGO > m_placer;
259  std::unique_ptr< DRAGGER > m_dragger;
260  std::unique_ptr< SHOVE > m_shove;
261 
263 
269 
273 
275  wxString m_failureReason;
276 };
277 
278 }
279 
280 #endif
const wxString & FailureReason() const
Definition: pns_router.h:216
bool isStartingPointRoutable(const VECTOR2I &aWhere, int aLayer)
Definition: pns_router.cpp:156
Class ITEM.
Definition: pns_item.h:53
Class ROUTING_SETTINGS.
DRAG_MODE
Definition: pns_router.h:73
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:249
int m_snapshotIter
Definition: pns_router.h:266
Class NODE.
Definition: pns_node.h:140
void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
virtual RULE_RESOLVER * GetRuleResolver()=0
void LoadSettings(const ROUTING_SETTINGS &aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:203
int GetClearance(const ITEM *aA, const ITEM *aB) const
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
ITEM * syncVia(VIA *aVia)
const ITEM_SET QueryHoverItems(const VECTOR2I &aP)
Definition: pns_router.cpp:116
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:165
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:218
virtual void HideItem(ITEM *aItem)=0
void SyncWorld()
Definition: pns_router.cpp:89
Class ROUTER.
Definition: pns_router.h:87
bool IsPlacingVia() const
Definition: pns_router.cpp:497
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:457
void DeleteTraces(ITEM *aStartItem, bool aWholeTrack)
VECTOR2I m_currentEnd
Definition: pns_router.h:252
int m_iterLimit
Definition: pns_router.h:264
Class RULE_RESOLVER.
Definition: pns_node.h:56
void highlightCurrent(bool enabled)
void DisplayItems(const ITEM_SET &aItems)
Definition: pns_router.cpp:222
int GetShapshotIter() const
Definition: pns_router.h:187
virtual void AddItem(ITEM *aItem)=0
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:208
void SwitchLayer(int layer)
Definition: pns_router.cpp:434
void SetShowIntermediateSteps(bool aX, int aSnapshotIter=-1)
Definition: pns_router.h:180
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:260
void SetOrthoMode(bool aEnable)
Definition: pns_router.cpp:506
Class PLACEMENT_ALGO.
void ToggleViaPlacement()
Definition: pns_router.cpp:447
void commitVia(VIA *aVia)
void SetView(KIGFX::VIEW *aView)
void ClearWorld()
Definition: pns_router.cpp:98
virtual ~ROUTER_IFACE()
Definition: pns_router.h:91
wxString m_toolStatusbarName
Definition: pns_router.h:274
std::unique_ptr< NODE > m_world
Definition: pns_router.h:255
virtual void SyncWorld(NODE *aNode)=0
void commitPad(SOLID *aPad)
virtual void UpdateNet(int aNetCode)=0
bool GetShowIntermediateSteps() const
Definition: pns_router.h:186
bool m_showInterSteps
Definition: pns_router.h:265
void BreakSegment(ITEM *aItem, const VECTOR2I &aP)
Definition: pns_router.cpp:527
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:291
void commitSegment(SEGMENT *aTrack)
void splitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
NODE * m_lastNode
Definition: pns_router.h:256
ITEM * pickSingleItem(ITEM_SET &aItems) const
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:258
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
Definition: pns_router.cpp:372
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:215
RouterState m_state
Definition: pns_router.h:253
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:262
virtual void SetRouter(ROUTER *aRouter)=0
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:328
ITEM * QueryItemByParent(const BOARD_ITEM *aItem) const
void eraseView()
void Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:229
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:174
void SetIterLimit(int aX)
Definition: pns_router.h:177
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:521
std::unique_ptr< DRAGGER > m_dragger
Definition: pns_router.h:259
void clearViewFlags()
void StopRouting()
Definition: pns_router.cpp:397
virtual void EraseView()=0
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
ROUTER_MODE
Definition: pns_router.h:65
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:316
void SetMode(ROUTER_MODE aMode)
Definition: pns_router.cpp:515
Board layer functions and definitions.
const VECTOR2I SnapToItem(ITEM *aItem, VECTOR2I aP, bool &aSplitsSegment)
void CommitRouting(NODE *aNode)
Definition: pns_router.cpp:355
ITEM * syncPad(D_PAD *aPad)
ITEM * syncTrack(TRACK *aTrack)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:125
ROUTING_SETTINGS m_settings
Definition: pns_router.h:270
SIZES_SETTINGS m_sizes
Definition: pns_router.h:271
virtual void Commit()=0
int GetIterLimit() const
Definition: pns_router.h:178
bool m_violation
Definition: pns_router.h:267
virtual void RemoveItem(ITEM *aItem)=0
ROUTER_MODE m_mode
Definition: pns_router.h:272
void DumpLog()
Definition: pns_router.cpp:474
void FlipPosture()
Definition: pns_router.cpp:425
Class VIEW.
Definition: view.h:61
bool RoutingInProgress() const
Definition: pns_router.cpp:110
ROUTER_MODE Mode() const
Definition: pns_router.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
NODE * GetWorld() const
Definition: pns_router.h:145
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:189
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:220
static ROUTER * GetInstance()
Definition: pns_router.cpp:76
Class LAYER_RANGE.
Definition: pns_layerset.h:32
bool m_forceMarkObstaclesMode
Definition: pns_router.h:268
wxString m_failureReason
Definition: pns_router.h:275
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:144
virtual bool IsAnyLayerVisible(const LAYER_RANGE &aLayer)=0
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:260
int GetCurrentLayer() const
Definition: pns_router.cpp:466