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 <boost/optional.hpp>
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  {
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 );
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 
185  int GetShapshotIter() const { return m_snapshotIter; }
186 
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 
251 
252  std::unique_ptr< NODE > m_world;
254 
255  std::unique_ptr< PLACEMENT_ALGO > m_placer;
256  std::unique_ptr< DRAGGER > m_dragger;
257  std::unique_ptr< SHOVE > m_shove;
258 
260 
266 
270 
272  wxString m_failureReason;
273 };
274 
275 }
276 
277 #endif
Class ITEM.
Definition: pns_item.h:53
Class ROUTING_SETTINGS.
DRAG_MODE
Definition: pns_router.h:72
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:224
int m_snapshotIter
Definition: pns_router.h:263
void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1)
Class NODE.
Definition: pns_node.h:137
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:201
void updateView(NODE *aNode, ITEM_SET &aCurrent)
Definition: pns_router.cpp:266
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
ITEM * syncVia(VIA *aVia)
const ITEM_SET QueryHoverItems(const VECTOR2I &aP)
Definition: pns_router.cpp:118
int GetClearance(const ITEM *aA, const ITEM *aB) const
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:216
virtual void HideItem(ITEM *aItem)=0
void SyncWorld()
Definition: pns_router.cpp:91
Class ROUTER.
Definition: pns_router.h:86
void DeleteTraces(ITEM *aStartItem, bool aWholeTrack)
VECTOR2I m_currentEnd
Definition: pns_router.h:249
int m_iterLimit
Definition: pns_router.h:261
Class RULE_RESOLVER.
Definition: pns_node.h:56
void highlightCurrent(bool enabled)
void DisplayItems(const ITEM_SET &aItems)
Definition: pns_router.cpp:197
bool IsPlacingVia() const
Definition: pns_router.cpp:468
virtual void AddItem(ITEM *aItem)=0
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:428
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:206
void SwitchLayer(int layer)
Definition: pns_router.cpp:405
void SetShowIntermediateSteps(bool aX, int aSnapshotIter=-1)
Definition: pns_router.h:178
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:257
void SetOrthoMode(bool aEnable)
Definition: pns_router.cpp:477
NODE * GetWorld() const
Definition: pns_router.h:143
Class PLACEMENT_ALGO.
void ToggleViaPlacement()
Definition: pns_router.cpp:418
void commitVia(VIA *aVia)
void SetView(KIGFX::VIEW *aView)
void ClearWorld()
Definition: pns_router.cpp:100
bool RoutingInProgress() const
Definition: pns_router.cpp:112
virtual ~ROUTER_IFACE()
Definition: pns_router.h:90
wxString m_toolStatusbarName
Definition: pns_router.h:271
std::unique_ptr< NODE > m_world
Definition: pns_router.h:252
virtual void SyncWorld(NODE *aNode)=0
void commitPad(SOLID *aPad)
bool GetShowIntermediateSteps() const
Definition: pns_router.h:184
virtual void UpdateNet(int aNetCode)=0
bool m_showInterSteps
Definition: pns_router.h:262
void BreakSegment(ITEM *aItem, const VECTOR2I &aP)
Definition: pns_router.cpp:498
int GetShapshotIter() const
Definition: pns_router.h:185
void commitSegment(SEGMENT *aTrack)
void splitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
NODE * m_lastNode
Definition: pns_router.h:253
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:255
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:213
bool FixRoute(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:343
RouterState m_state
Definition: pns_router.h:250
ROUTER_IFACE * m_iface
Definition: pns_router.h:259
virtual void SetRouter(ROUTER *aRouter)=0
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:299
void eraseView()
void Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:204
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:156
void SetIterLimit(int aX)
Definition: pns_router.h:175
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:492
std::unique_ptr< DRAGGER > m_dragger
Definition: pns_router.h:256
void clearViewFlags()
void StopRouting()
Definition: pns_router.cpp:368
virtual void EraseView()=0
int GetIterLimit() const
Definition: pns_router.h:176
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:163
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
ROUTER_MODE
Definition: pns_router.h:64
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:287
void SetMode(ROUTER_MODE aMode)
Definition: pns_router.cpp:486
const VECTOR2I SnapToItem(ITEM *aItem, VECTOR2I aP, bool &aSplitsSegment)
void CommitRouting(NODE *aNode)
Definition: pns_router.cpp:326
ITEM * syncPad(D_PAD *aPad)
ROUTER_MODE Mode() const
Definition: pns_router.h:124
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1)=0
ITEM * syncTrack(TRACK *aTrack)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:127
ROUTING_SETTINGS m_settings
Definition: pns_router.h:267
SIZES_SETTINGS m_sizes
Definition: pns_router.h:268
virtual void Commit()=0
Struct SEGMENT is a simple container used when filling areas with segments.
Definition: class_zone.h:57
bool m_violation
Definition: pns_router.h:264
virtual void RemoveItem(ITEM *aItem)=0
int GetCurrentLayer() const
Definition: pns_router.cpp:437
ROUTER_MODE m_mode
Definition: pns_router.h:269
void DumpLog()
Definition: pns_router.cpp:445
void FlipPosture()
Definition: pns_router.cpp:396
Class VIEW.
Definition: view.h:58
ITEM * pickSingleItem(ITEM_SET &aItems) const
Push and Shove diff pair dimensions (gap) settings dialog.
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:187
static ROUTER * GetInstance()
Definition: pns_router.cpp:78
bool m_forceMarkObstaclesMode
Definition: pns_router.h:265
wxString m_failureReason
Definition: pns_router.h:272
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:141
ITEM * QueryItemByParent(const BOARD_ITEM *aItem) const
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:235