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 
79  {
80  public:
82  virtual ~ROUTER_IFACE() {};
83 
84  virtual void SetRouter( ROUTER* aRouter ) = 0;
85  virtual void SyncWorld( NODE* aNode ) = 0;
86  virtual void AddItem( ITEM* aItem ) = 0;
87  virtual void RemoveItem( ITEM* aItem ) = 0;
88  virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1 ) = 0;
89  virtual void HideItem( ITEM* aItem ) = 0;
90  virtual void Commit() = 0;
91 // virtual void Abort () = 0;
92 
93  virtual void EraseView() = 0;
94  virtual void UpdateNet( int aNetCode ) = 0;
95 
96  virtual RULE_RESOLVER* GetRuleResolver() = 0;
97  virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
98 };
99 
100 class ROUTER
101 {
102 private:
104  {
108  };
109 
110 public:
111  ROUTER();
112  ~ROUTER();
113 
114  void SetInterface( ROUTER_IFACE* aIface );
115  void SetMode ( ROUTER_MODE aMode );
116  ROUTER_MODE Mode() const { return m_mode; }
117 
118  static ROUTER* GetInstance();
119 
120  void ClearWorld();
121  void SyncWorld();
122 
123  void SetView( KIGFX::VIEW* aView );
124 
125  bool RoutingInProgress() const;
126  bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
127  void Move( const VECTOR2I& aP, ITEM* aItem );
128  bool FixRoute( const VECTOR2I& aP, ITEM* aItem );
129 
130  void StopRouting();
131 
132  int GetClearance( const ITEM* aA, const ITEM* aB ) const;
133 
134  NODE* GetWorld() const
135  {
136  return m_world.get();
137  }
138 
139  void FlipPosture();
140 
141  void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1 );
142  void DisplayItems( const ITEM_SET& aItems );
143  void DeleteTraces( ITEM* aStartItem, bool aWholeTrack );
144  void SwitchLayer( int layer );
145 
146  void ToggleViaPlacement();
147  void SetOrthoMode( bool aEnable );
148 
149  int GetCurrentLayer() const;
150  const std::vector<int> GetCurrentNets() const;
151 
152  void DumpLog();
153 
155  {
156  return m_iface->GetRuleResolver();
157  }
158 
159  bool IsPlacingVia() const;
160 
161  const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
162  const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
163 
164  bool StartDragging( const VECTOR2I& aP, ITEM* aItem );
165 
166  void SetIterLimit( int aX ) { m_iterLimit = aX; }
167  int GetIterLimit() const { return m_iterLimit; };
168 
169  void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
170  {
171  m_showInterSteps = aX;
172  m_snapshotIter = aSnapshotIter;
173  }
174 
176  int GetShapshotIter() const { return m_snapshotIter; }
177 
179 
180  void CommitRouting( NODE* aNode );
181 
186  void UpdateSizes( const SIZES_SETTINGS& aSizes );
187 
192  void LoadSettings( const ROUTING_SETTINGS& aSettings )
193  {
194  m_settings = aSettings;
195  }
196 
198  {
199  return m_sizes;
200  }
201 
202  ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const;
203 
204  void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
205  const wxString& FailureReason() const { return m_failureReason; }
206 
207  PLACEMENT_ALGO* Placer() { return m_placer.get(); }
208 
210  {
211  return m_iface;
212  }
213 
214 private:
215  void movePlacing( const VECTOR2I& aP, ITEM* aItem );
216  void moveDragging( const VECTOR2I& aP, ITEM* aItem );
217 
218  void eraseView();
219  void updateView( NODE* aNode, ITEM_SET& aCurrent );
220 
221  void clearViewFlags();
222 
223  // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
224 
225  ITEM* pickSingleItem( ITEM_SET& aItems ) const;
226  void splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
227 
228  ITEM* syncPad( D_PAD* aPad );
229  ITEM* syncTrack( TRACK* aTrack );
230  ITEM* syncVia( VIA* aVia );
231 
232  void commitPad( SOLID* aPad );
233  void commitSegment( SEGMENT* aTrack );
234  void commitVia( VIA* aVia );
235 
236  void highlightCurrent( bool enabled );
237 
238  void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
239 
242 
243  std::unique_ptr< NODE > m_world;
245 
246  std::unique_ptr< PLACEMENT_ALGO > m_placer;
247  std::unique_ptr< DRAGGER > m_dragger;
248  std::unique_ptr< SHOVE > m_shove;
249 
251 
256 
260 
262  wxString m_failureReason;
263 };
264 
265 }
266 
267 #endif
Class ITEM.
Definition: pns_item.h:53
Class ROUTING_SETTINGS.
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:222
int m_snapshotIter
Definition: pns_router.h:254
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: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:192
void updateView(NODE *aNode, ITEM_SET &aCurrent)
Definition: pns_router.cpp:264
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:205
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:209
ITEM * syncVia(VIA *aVia)
const ITEM_SET QueryHoverItems(const VECTOR2I &aP)
Definition: pns_router.cpp:125
bool StartDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:134
int GetClearance(const ITEM *aA, const ITEM *aB) const
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:207
virtual void HideItem(ITEM *aItem)=0
void SyncWorld()
Definition: pns_router.cpp:98
Class ROUTER.
Definition: pns_router.h:78
void DeleteTraces(ITEM *aStartItem, bool aWholeTrack)
VECTOR2I m_currentEnd
Definition: pns_router.h:240
int m_iterLimit
Definition: pns_router.h:252
Class RULE_RESOLVER.
Definition: pns_node.h:56
void highlightCurrent(bool enabled)
void DisplayItems(const ITEM_SET &aItems)
Definition: pns_router.cpp:195
bool IsPlacingVia() const
Definition: pns_router.cpp:466
virtual void AddItem(ITEM *aItem)=0
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:426
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:197
void SwitchLayer(int layer)
Definition: pns_router.cpp:403
void SetShowIntermediateSteps(bool aX, int aSnapshotIter=-1)
Definition: pns_router.h:169
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:248
void SetOrthoMode(bool aEnable)
Definition: pns_router.cpp:475
NODE * GetWorld() const
Definition: pns_router.h:134
Class PLACEMENT_ALGO.
void ToggleViaPlacement()
Definition: pns_router.cpp:416
void commitVia(VIA *aVia)
void SetView(KIGFX::VIEW *aView)
void ClearWorld()
Definition: pns_router.cpp:107
bool RoutingInProgress() const
Definition: pns_router.cpp:119
virtual ~ROUTER_IFACE()
Definition: pns_router.h:82
wxString m_toolStatusbarName
Definition: pns_router.h:261
std::unique_ptr< NODE > m_world
Definition: pns_router.h:243
virtual void SyncWorld(NODE *aNode)=0
void commitPad(SOLID *aPad)
bool GetShowIntermediateSteps() const
Definition: pns_router.h:175
virtual void UpdateNet(int aNetCode)=0
bool m_showInterSteps
Definition: pns_router.h:253
int GetShapshotIter() const
Definition: pns_router.h:176
void commitSegment(SEGMENT *aTrack)
void splitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
NODE * m_lastNode
Definition: pns_router.h:244
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:246
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:204
bool FixRoute(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:341
RouterState m_state
Definition: pns_router.h:241
ROUTER_IFACE * m_iface
Definition: pns_router.h:250
virtual void SetRouter(ROUTER *aRouter)=0
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:297
void eraseView()
void Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:202
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:156
void SetIterLimit(int aX)
Definition: pns_router.h:166
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:490
std::unique_ptr< DRAGGER > m_dragger
Definition: pns_router.h:247
void clearViewFlags()
void StopRouting()
Definition: pns_router.cpp:366
virtual void EraseView()=0
int GetIterLimit() const
Definition: pns_router.h:167
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:154
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:285
void SetMode(ROUTER_MODE aMode)
Definition: pns_router.cpp:484
const VECTOR2I SnapToItem(ITEM *aItem, VECTOR2I aP, bool &aSplitsSegment)
void CommitRouting(NODE *aNode)
Definition: pns_router.cpp:324
ITEM * syncPad(D_PAD *aPad)
ROUTER_MODE Mode() const
Definition: pns_router.h:116
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1)=0
ITEM * syncTrack(TRACK *aTrack)
ROUTING_SETTINGS m_settings
Definition: pns_router.h:257
SIZES_SETTINGS m_sizes
Definition: pns_router.h:258
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:255
virtual void RemoveItem(ITEM *aItem)=0
int GetCurrentLayer() const
Definition: pns_router.cpp:435
ROUTER_MODE m_mode
Definition: pns_router.h:259
void DumpLog()
Definition: pns_router.cpp:443
void FlipPosture()
Definition: pns_router.cpp:394
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:178
static ROUTER * GetInstance()
Definition: pns_router.cpp:85
wxString m_failureReason
Definition: pns_router.h:262
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:233