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 class LOGGER;
67 
74 };
75 
77 {
78  DM_CORNER = 0x1,
79  DM_SEGMENT = 0x2,
80  DM_VIA = 0x4,
82  DM_ARC = 0x10,
83  DM_ANY = 0x17,
84  DM_COMPONENT = 0x20
85 };
93  {
94  public:
96  virtual ~ROUTER_IFACE() {};
97 
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 ) const = 0;
102  virtual bool IsItemVisible( const PNS::ITEM* aItem ) const = 0;
103  virtual bool IsOnLayer( const PNS::ITEM* aItem, int aLayer ) const = 0;
104  virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
105  virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor = -1 ) = 0;
106  virtual void HideItem( ITEM* aItem ) = 0;
107  virtual void Commit() = 0;
108  virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, int aNet ) = 0;
109 // virtual void Abort () = 0;
110 
111  virtual void EraseView() = 0;
112  virtual void UpdateNet( int aNetCode ) = 0;
113 
114  virtual PNS::NODE* GetWorld() const = 0;
115 
116  virtual RULE_RESOLVER* GetRuleResolver() = 0;
117  virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
118 };
119 
120 class ROUTER
121 {
122 private:
124  {
128  };
129 
130 public:
131  ROUTER();
132  ~ROUTER();
133 
134  void SetInterface( ROUTER_IFACE* aIface );
135  void SetMode ( ROUTER_MODE aMode );
136  ROUTER_MODE Mode() const { return m_mode; }
137 
138  static ROUTER* GetInstance();
139 
140  void ClearWorld();
141  void SyncWorld();
142 
143  void SetView( KIGFX::VIEW* aView );
144 
145  bool RoutingInProgress() const;
146  bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
147  void Move( const VECTOR2I& aP, ITEM* aItem );
148  bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
149  void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
150 
151  void UndoLastSegment();
152  void CommitRouting();
153  void StopRouting();
154 
155  NODE* GetWorld() const
156  {
157  return m_world.get();
158  }
159 
160  void FlipPosture();
161 
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  LOGGER* Logger();
174 
176  {
177  return m_iface->GetRuleResolver();
178  }
179 
180  bool IsPlacingVia() const;
181 
182  const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
183  const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
184 
185  bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
186  bool StartDragging( const VECTOR2I& aP, ITEM_SET aItems, int aDragMode = DM_COMPONENT );
187 
188  void SetIterLimit( int aX ) { m_iterLimit = aX; }
189  int GetIterLimit() const { return m_iterLimit; };
190 
191  void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
192  {
193  m_showInterSteps = aX;
194  m_snapshotIter = aSnapshotIter;
195  }
196 
198  int GetShapshotIter() const { return m_snapshotIter; }
199 
201 
202  void CommitRouting( NODE* aNode );
203 
208  void UpdateSizes( const SIZES_SETTINGS& aSizes );
209 
214  void LoadSettings( ROUTING_SETTINGS* aSettings )
215  {
216  m_settings = aSettings;
217  }
218 
220  {
221  return m_sizes;
222  }
223 
224  ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const;
225 
226  void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
227  const wxString& FailureReason() const { return m_failureReason; }
228 
229  PLACEMENT_ALGO* Placer() { return m_placer.get(); }
230 
232  {
233  return m_iface;
234  }
235 
236 private:
237  void movePlacing( const VECTOR2I& aP, ITEM* aItem );
238  void moveDragging( const VECTOR2I& aP, ITEM* aItem );
239 
240  void eraseView();
241  void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
242 
243  void clearViewFlags();
244 
245  // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
246 
247  ITEM* pickSingleItem( ITEM_SET& aItems ) const;
248  void splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
249 
250  ITEM* syncPad( PAD* aPad );
251  ITEM* syncTrack( TRACK* aTrack );
252  ITEM* syncVia( VIA* aVia );
253 
254  void commitPad( SOLID* aPad );
255  void commitSegment( SEGMENT* aTrack );
256  void commitVia( VIA* aVia );
257 
258  void highlightCurrent( bool enabled );
259 
260  void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
261  bool isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aItem, int aLayer );
262 
265 
266  std::unique_ptr< NODE > m_world;
268 
269  std::unique_ptr< PLACEMENT_ALGO > m_placer;
270  std::unique_ptr< DRAG_ALGO > m_dragger;
271  std::unique_ptr< SHOVE > m_shove;
272 
274 
280 
285 
287  wxString m_failureReason;
288 };
289 
290 }
291 
292 #endif
const wxString & FailureReason() const
Definition: pns_router.h:227
ITEM.
Definition: pns_item.h:54
DRAG_MODE
Definition: pns_router.h:76
Definition: track.h:354
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:279
int m_snapshotIter
Definition: pns_router.h:277
NODE.
Definition: pns_node.h:169
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
virtual RULE_RESOLVER * GetRuleResolver()=0
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:270
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
ITEM * syncVia(VIA *aVia)
const ITEM_SET QueryHoverItems(const VECTOR2I &aP)
Definition: pns_router.cpp:120
void CommitRouting()
Definition: pns_router.cpp:440
virtual PNS::NODE * GetWorld() const =0
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:175
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:229
virtual void HideItem(ITEM *aItem)=0
bool isStartingPointRoutable(const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:173
void SyncWorld()
Definition: pns_router.cpp:93
bool IsPlacingVia() const
Definition: pns_router.cpp:537
void ToggleRounded()
Definition: pns_router.cpp:546
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:509
VECTOR2I m_currentEnd
Definition: pns_router.h:263
int m_iterLimit
Definition: pns_router.h:275
virtual void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, int aColor=-1)=0
void highlightCurrent(bool enabled)
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:281
int GetShapshotIter() const
Definition: pns_router.h:198
virtual void AddItem(ITEM *aItem)=0
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:219
void SwitchLayer(int layer)
Definition: pns_router.cpp:486
void SetShowIntermediateSteps(bool aX, int aSnapshotIter=-1)
Definition: pns_router.h:191
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:271
void SetOrthoMode(bool aEnable)
Definition: pns_router.cpp:552
void ToggleViaPlacement()
Definition: pns_router.cpp:499
void commitVia(VIA *aVia)
void SetView(KIGFX::VIEW *aView)
void ClearWorld()
Definition: pns_router.cpp:102
virtual bool IsAnyLayerVisible(const LAYER_RANGE &aLayer) const =0
virtual ~ROUTER_IFACE()
Definition: pns_router.h:96
wxString m_toolStatusbarName
Definition: pns_router.h:286
void UndoLastSegment()
Definition: pns_router.cpp:431
std::unique_ptr< NODE > m_world
Definition: pns_router.h:266
virtual void SyncWorld(NODE *aNode)=0
void commitPad(SOLID *aPad)
virtual void UpdateNet(int aNetCode)=0
bool GetShowIntermediateSteps() const
Definition: pns_router.h:197
bool m_showInterSteps
Definition: pns_router.h:276
void BreakSegment(ITEM *aItem, const VECTOR2I &aP)
Definition: pns_router.cpp:572
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:321
void commitSegment(SEGMENT *aTrack)
void splitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
NODE * m_lastNode
Definition: pns_router.h:267
ITEM * pickSingleItem(ITEM_SET &aItems) const
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:269
virtual bool IsItemVisible(const PNS::ITEM *aItem) const =0
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
Definition: pns_router.cpp:404
ITEM * syncPad(PAD *aPad)
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:226
RouterState m_state
Definition: pns_router.h:264
virtual void DisplayItem(const ITEM *aItem, int aColor=-1, int aClearance=-1, bool aEdit=false)=0
ROUTER_IFACE * m_iface
Definition: pns_router.h:273
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:357
ITEM * QueryItemByParent(const BOARD_ITEM *aItem) const
void eraseView()
void Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:256
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:205
void SetIterLimit(int aX)
Definition: pns_router.h:188
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:567
void clearViewFlags()
void StopRouting()
Definition: pns_router.cpp:449
virtual void EraseView()=0
virtual bool IsOnLayer(const PNS::ITEM *aItem, int aLayer) const =0
LOGGER * m_logger
Definition: pns_router.h:284
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
ROUTER_MODE
Definition: pns_router.h:68
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:345
void SetMode(ROUTER_MODE aMode)
Definition: pns_router.cpp:561
Board layer functions and definitions.
const VECTOR2I SnapToItem(ITEM *aItem, VECTOR2I aP, bool &aSplitsSegment)
Definition: track.h:272
SHAPE_LINE_CHAIN.
LOGGER * Logger()
Definition: pns_router.cpp:531
ITEM * syncTrack(TRACK *aTrack)
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:128
SIZES_SETTINGS m_sizes
Definition: pns_router.h:282
virtual void Commit()=0
int GetIterLimit() const
Definition: pns_router.h:189
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:214
bool m_violation
Definition: pns_router.h:278
virtual void RemoveItem(ITEM *aItem)=0
ROUTER_MODE m_mode
Definition: pns_router.h:283
void DumpLog()
void FlipPosture()
Definition: pns_router.cpp:477
VIEW.
Definition: view.h:63
bool RoutingInProgress() const
Definition: pns_router.cpp:114
Definition: pad.h:59
ROUTER_MODE Mode() const
Definition: pns_router.h:136
Push and Shove diff pair dimensions (gap) settings dialog.
NODE * GetWorld() const
Definition: pns_router.h:155
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:200
virtual bool ImportSizes(SIZES_SETTINGS &aSizes, ITEM *aStartItem, int aNet)=0
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:231
static ROUTER * GetInstance()
Definition: pns_router.cpp:79
LAYER_RANGE.
Definition: pns_layerset.h:32
Definition: track.h:83
bool m_forceMarkObstaclesMode
Definition: pns_router.h:279
wxString m_failureReason
Definition: pns_router.h:287
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:173
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:290
int GetCurrentLayer() const
Definition: pns_router.cpp:520