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