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 ARC;
57 class LINE;
58 class SOLID;
59 class SEGMENT;
60 class JOINT;
61 class VIA;
62 class RULE_RESOLVER;
63 class SHOVE;
64 class DRAGGER;
65 class DRAG_ALGO;
66 
73 };
74 
76 {
77  DM_CORNER = 0x1,
78  DM_SEGMENT = 0x2,
79  DM_VIA = 0x4,
81  DM_ARC = 0x10,
82  DM_ANY = 0x17,
83  DM_COMPONENT = 0x20
84 };
92  {
93  public:
95  virtual ~ROUTER_IFACE() {};
96 
97  virtual void SetRouter( ROUTER* aRouter ) = 0;
98  virtual void SyncWorld( NODE* aNode ) = 0;
99  virtual void AddItem( ITEM* aItem ) = 0;
100  virtual void RemoveItem( ITEM* aItem ) = 0;
101  virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) = 0;
102  virtual bool IsItemVisible( const PNS::ITEM* aItem ) = 0;
103  virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
104  virtual void HideItem( ITEM* aItem ) = 0;
105  virtual void Commit() = 0;
106 // virtual void Abort () = 0;
107 
108  virtual void EraseView() = 0;
109  virtual void UpdateNet( int aNetCode ) = 0;
110 
111  virtual RULE_RESOLVER* GetRuleResolver() = 0;
112  virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
113 };
114 
115 class ROUTER
116 {
117 private:
119  {
123  };
124 
125 public:
126  ROUTER();
127  ~ROUTER();
128 
129  void SetInterface( ROUTER_IFACE* aIface );
130  void SetMode ( ROUTER_MODE aMode );
131  ROUTER_MODE Mode() const { return m_mode; }
132 
133  static ROUTER* GetInstance();
134 
135  void ClearWorld();
136  void SyncWorld();
137 
138  void SetView( KIGFX::VIEW* aView );
139 
140  bool RoutingInProgress() const;
141  bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
142  void Move( const VECTOR2I& aP, ITEM* aItem );
143  bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
144  void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
145 
146  void UndoLastSegment();
147  void CommitRouting();
148  void StopRouting();
149 
150  int GetClearance( const ITEM* aA, const ITEM* aB ) const;
151 
152  NODE* GetWorld() const
153  {
154  return m_world.get();
155  }
156 
157  void FlipPosture();
158 
159  void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false );
160  void DisplayItems( const ITEM_SET& aItems );
161  void DeleteTraces( ITEM* aStartItem, bool aWholeTrack );
162  void SwitchLayer( int layer );
163 
164  void ToggleViaPlacement();
165  void SetOrthoMode( bool aEnable );
166 
167  void ToggleRounded();
168 
169  int GetCurrentLayer() const;
170  const std::vector<int> GetCurrentNets() const;
171 
172  void DumpLog();
173 
175  {
176  return m_iface->GetRuleResolver();
177  }
178 
179  bool IsPlacingVia() const;
180 
181  const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
182  const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
183 
184  bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
185  bool StartDragging( const VECTOR2I& aP, ITEM_SET aItems, int aDragMode = DM_COMPONENT );
186 
187  void SetIterLimit( int aX ) { m_iterLimit = aX; }
188  int GetIterLimit() const { return m_iterLimit; };
189 
190  void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
191  {
192  m_showInterSteps = aX;
193  m_snapshotIter = aSnapshotIter;
194  }
195 
197  int GetShapshotIter() const { return m_snapshotIter; }
198 
200 
201  void CommitRouting( NODE* aNode );
202 
207  void UpdateSizes( const SIZES_SETTINGS& aSizes );
208 
213  void LoadSettings( ROUTING_SETTINGS* aSettings )
214  {
215  m_settings = aSettings;
216  }
217 
219  {
220  return m_sizes;
221  }
222 
223  ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const;
224 
225  void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
226  const wxString& FailureReason() const { return m_failureReason; }
227 
228  PLACEMENT_ALGO* Placer() { return m_placer.get(); }
229 
231  {
232  return m_iface;
233  }
234 
235 private:
236  void movePlacing( const VECTOR2I& aP, ITEM* aItem );
237  void moveDragging( const VECTOR2I& aP, ITEM* aItem );
238 
239  void eraseView();
240  void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
241 
242  void clearViewFlags();
243 
244  // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
245 
246  ITEM* pickSingleItem( ITEM_SET& aItems ) const;
247  void splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
248 
249  ITEM* syncPad( D_PAD* aPad );
250  ITEM* syncTrack( TRACK* aTrack );
251  ITEM* syncVia( VIA* aVia );
252 
253  void commitPad( SOLID* aPad );
254  void commitSegment( SEGMENT* aTrack );
255  void commitVia( VIA* aVia );
256 
257  void highlightCurrent( bool enabled );
258 
259  void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
260  bool isStartingPointRoutable( const VECTOR2I& aWhere, int aLayer );
261 
264 
265  std::unique_ptr< NODE > m_world;
267 
268  std::unique_ptr< PLACEMENT_ALGO > m_placer;
269  std::unique_ptr< DRAG_ALGO > m_dragger;
270  std::unique_ptr< SHOVE > m_shove;
271 
273 
279 
283 
285  wxString m_failureReason;
286 };
287 
288 }
289 
290 #endif
const wxString & FailureReason() const
Definition: pns_router.h:226
bool isStartingPointRoutable(const VECTOR2I &aWhere, int aLayer)
Definition: pns_router.cpp:173
ITEM.
Definition: pns_item.h:53
DRAG_MODE
Definition: pns_router.h:75
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:266
int m_snapshotIter
Definition: pns_router.h:276
NODE.
Definition: pns_node.h:145
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: color4d.cpp:131
virtual RULE_RESOLVER * GetRuleResolver()=0
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:269
int GetClearance(const ITEM *aA, const ITEM *aB) const
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:123
void CommitRouting()
Definition: pns_router.cpp:422
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:174
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:228
virtual void HideItem(ITEM *aItem)=0
void SyncWorld()
Definition: pns_router.cpp:96
bool IsPlacingVia() const
Definition: pns_router.cpp:531
void ToggleRounded()
Definition: pns_router.cpp:540
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:491
void DeleteTraces(ITEM *aStartItem, bool aWholeTrack)
VECTOR2I m_currentEnd
Definition: pns_router.h:262
int m_iterLimit
Definition: pns_router.h:274
RULE_RESOLVER.
Definition: pns_node.h:57
void highlightCurrent(bool enabled)
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:280
void DisplayItems(const ITEM_SET &aItems)
Definition: pns_router.cpp:239
int GetShapshotIter() const
Definition: pns_router.h:197
virtual void AddItem(ITEM *aItem)=0
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:218
void SwitchLayer(int layer)
Definition: pns_router.cpp:468
void SetShowIntermediateSteps(bool aX, int aSnapshotIter=-1)
Definition: pns_router.h:190
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:270
void SetOrthoMode(bool aEnable)
Definition: pns_router.cpp:546
void ToggleViaPlacement()
Definition: pns_router.cpp:481
void commitVia(VIA *aVia)
void SetView(KIGFX::VIEW *aView)
void ClearWorld()
Definition: pns_router.cpp:105
virtual ~ROUTER_IFACE()
Definition: pns_router.h:95
wxString m_toolStatusbarName
Definition: pns_router.h:284
void UndoLastSegment()
Definition: pns_router.cpp:413
std::unique_ptr< NODE > m_world
Definition: pns_router.h:265
virtual void SyncWorld(NODE *aNode)=0
void commitPad(SOLID *aPad)
virtual void UpdateNet(int aNetCode)=0
bool GetShowIntermediateSteps() const
Definition: pns_router.h:196
bool m_showInterSteps
Definition: pns_router.h:275
void BreakSegment(ITEM *aItem, const VECTOR2I &aP)
Definition: pns_router.cpp:567
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:308
void commitSegment(SEGMENT *aTrack)
void splitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
NODE * m_lastNode
Definition: pns_router.h:266
ITEM * pickSingleItem(ITEM_SET &aItems) const
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:268
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
Definition: pns_router.cpp:391
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:225
RouterState m_state
Definition: pns_router.h:263
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:272
virtual void SetRouter(ROUTER *aRouter)=0
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:344
ITEM * QueryItemByParent(const BOARD_ITEM *aItem) const
void eraseView()
void Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:246
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:191
void SetIterLimit(int aX)
Definition: pns_router.h:187
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:561
void clearViewFlags()
void StopRouting()
Definition: pns_router.cpp:431
virtual void EraseView()=0
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
ROUTER_MODE
Definition: pns_router.h:67
virtual bool IsItemVisible(const PNS::ITEM *aItem)=0
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:332
void SetMode(ROUTER_MODE aMode)
Definition: pns_router.cpp:555
Board layer functions and definitions.
const VECTOR2I SnapToItem(ITEM *aItem, VECTOR2I aP, bool &aSplitsSegment)
ITEM * syncPad(D_PAD *aPad)
ITEM * syncTrack(TRACK *aTrack)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:131
SIZES_SETTINGS m_sizes
Definition: pns_router.h:281
virtual void Commit()=0
int GetIterLimit() const
Definition: pns_router.h:188
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:213
bool m_violation
Definition: pns_router.h:277
virtual void RemoveItem(ITEM *aItem)=0
ROUTER_MODE m_mode
Definition: pns_router.h:282
void DumpLog()
Definition: pns_router.cpp:508
void FlipPosture()
Definition: pns_router.cpp:459
VIEW.
Definition: view.h:61
bool RoutingInProgress() const
Definition: pns_router.cpp:117
ROUTER_MODE Mode() const
Definition: pns_router.h:131
Push and Shove diff pair dimensions (gap) settings dialog.
NODE * GetWorld() const
Definition: pns_router.h:152
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:199
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:230
static ROUTER * GetInstance()
Definition: pns_router.cpp:83
LAYER_RANGE.
Definition: pns_layerset.h:32
bool m_forceMarkObstaclesMode
Definition: pns_router.h:278
wxString m_failureReason
Definition: pns_router.h:285
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:149
virtual bool IsAnyLayerVisible(const LAYER_RANGE &aLayer)=0
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:277
int GetCurrentLayer() const
Definition: pns_router.cpp:500