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 bool IsItemVisible( const PNS::ITEM* aItem ) = 0;
99  virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
100  virtual void HideItem( ITEM* aItem ) = 0;
101  virtual void Commit() = 0;
102 // virtual void Abort () = 0;
103 
104  virtual void EraseView() = 0;
105  virtual void UpdateNet( int aNetCode ) = 0;
106 
107  virtual RULE_RESOLVER* GetRuleResolver() = 0;
108  virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
109 };
110 
111 class ROUTER
112 {
113 private:
115  {
119  };
120 
121 public:
122  ROUTER();
123  ~ROUTER();
124 
125  void SetInterface( ROUTER_IFACE* aIface );
126  void SetMode ( ROUTER_MODE aMode );
127  ROUTER_MODE Mode() const { return m_mode; }
128 
129  static ROUTER* GetInstance();
130 
131  void ClearWorld();
132  void SyncWorld();
133 
134  void SetView( KIGFX::VIEW* aView );
135 
136  bool RoutingInProgress() const;
137  bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
138  void Move( const VECTOR2I& aP, ITEM* aItem );
139  bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
140  void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
141 
142  void StopRouting();
143 
144  int GetClearance( const ITEM* aA, const ITEM* aB ) const;
145 
146  NODE* GetWorld() const
147  {
148  return m_world.get();
149  }
150 
151  void FlipPosture();
152 
153  void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false );
154  void DisplayItems( const ITEM_SET& aItems );
155  void DeleteTraces( ITEM* aStartItem, bool aWholeTrack );
156  void SwitchLayer( int layer );
157 
158  void ToggleViaPlacement();
159  void SetOrthoMode( bool aEnable );
160 
161  int GetCurrentLayer() const;
162  const std::vector<int> GetCurrentNets() const;
163 
164  void DumpLog();
165 
167  {
168  return m_iface->GetRuleResolver();
169  }
170 
171  bool IsPlacingVia() const;
172 
173  const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
174  const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
175 
176  bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
177 
178  void SetIterLimit( int aX ) { m_iterLimit = aX; }
179  int GetIterLimit() const { return m_iterLimit; };
180 
181  void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
182  {
183  m_showInterSteps = aX;
184  m_snapshotIter = aSnapshotIter;
185  }
186 
188  int GetShapshotIter() const { return m_snapshotIter; }
189 
191 
192  void CommitRouting( NODE* aNode );
193 
198  void UpdateSizes( const SIZES_SETTINGS& aSizes );
199 
204  void LoadSettings( const ROUTING_SETTINGS& aSettings )
205  {
206  m_settings = aSettings;
207  }
208 
210  {
211  return m_sizes;
212  }
213 
214  ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const;
215 
216  void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
217  const wxString& FailureReason() const { return m_failureReason; }
218 
219  PLACEMENT_ALGO* Placer() { return m_placer.get(); }
220 
222  {
223  return m_iface;
224  }
225 
226 private:
227  void movePlacing( const VECTOR2I& aP, ITEM* aItem );
228  void moveDragging( const VECTOR2I& aP, ITEM* aItem );
229 
230  void eraseView();
231  void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
232 
233  void clearViewFlags();
234 
235  // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
236 
237  ITEM* pickSingleItem( ITEM_SET& aItems ) const;
238  void splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
239 
240  ITEM* syncPad( D_PAD* aPad );
241  ITEM* syncTrack( TRACK* aTrack );
242  ITEM* syncVia( VIA* aVia );
243 
244  void commitPad( SOLID* aPad );
245  void commitSegment( SEGMENT* aTrack );
246  void commitVia( VIA* aVia );
247 
248  void highlightCurrent( bool enabled );
249 
250  void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
251  bool isStartingPointRoutable( const VECTOR2I& aWhere, int aLayer );
252 
255 
256  std::unique_ptr< NODE > m_world;
258 
259  std::unique_ptr< PLACEMENT_ALGO > m_placer;
260  std::unique_ptr< DRAGGER > m_dragger;
261  std::unique_ptr< SHOVE > m_shove;
262 
264 
270 
274 
276  wxString m_failureReason;
277 };
278 
279 }
280 
281 #endif
const wxString & FailureReason() const
Definition: pns_router.h:217
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:267
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:58
virtual RULE_RESOLVER * GetRuleResolver()=0
void LoadSettings(const ROUTING_SETTINGS &aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:204
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:166
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:219
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:253
int m_iterLimit
Definition: pns_router.h:265
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:188
virtual void AddItem(ITEM *aItem)=0
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:209
void SwitchLayer(int layer)
Definition: pns_router.cpp:434
void SetShowIntermediateSteps(bool aX, int aSnapshotIter=-1)
Definition: pns_router.h:181
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:261
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:275
std::unique_ptr< NODE > m_world
Definition: pns_router.h:256
virtual void SyncWorld(NODE *aNode)=0
void commitPad(SOLID *aPad)
virtual void UpdateNet(int aNetCode)=0
bool GetShowIntermediateSteps() const
Definition: pns_router.h:187
bool m_showInterSteps
Definition: pns_router.h:266
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:257
ITEM * pickSingleItem(ITEM_SET &aItems) const
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:259
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
Definition: pns_router.cpp:372
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:216
RouterState m_state
Definition: pns_router.h:254
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:263
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:178
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:521
std::unique_ptr< DRAGGER > m_dragger
Definition: pns_router.h:260
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
virtual bool IsItemVisible(const PNS::ITEM *aItem)=0
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:271
SIZES_SETTINGS m_sizes
Definition: pns_router.h:272
virtual void Commit()=0
int GetIterLimit() const
Definition: pns_router.h:179
bool m_violation
Definition: pns_router.h:268
virtual void RemoveItem(ITEM *aItem)=0
ROUTER_MODE m_mode
Definition: pns_router.h:273
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:127
Push and Shove diff pair dimensions (gap) settings dialog.
NODE * GetWorld() const
Definition: pns_router.h:146
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:190
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:221
static ROUTER * GetInstance()
Definition: pns_router.cpp:76
Class LAYER_RANGE.
Definition: pns_layerset.h:32
bool m_forceMarkObstaclesMode
Definition: pns_router.h:269
wxString m_failureReason
Definition: pns_router.h:276
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