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 #include <memory>
27 #include <core/optional.h>
28 #include <math/box2.h>
29 
30 #include "pns_routing_settings.h"
31 #include "pns_sizes_settings.h"
32 #include "pns_node.h"
33 
34 namespace KIGFX
35 {
36 
37 class VIEW;
38 class VIEW_GROUP;
39 
40 }
41 
42 namespace PNS {
43 
44 class DEBUG_DECORATOR;
45 class NODE;
46 class DIFF_PAIR_PLACER;
47 class PLACEMENT_ALGO;
48 class LINE_PLACER;
49 class ITEM;
50 class ARC;
51 class LINE;
52 class SOLID;
53 class SEGMENT;
54 class JOINT;
55 class VIA;
56 class RULE_RESOLVER;
57 class SHOVE;
58 class DRAGGER;
59 class DRAG_ALGO;
60 class LOGGER;
61 
68 };
69 
71 {
72  DM_CORNER = 0x1,
73  DM_SEGMENT = 0x2,
74  DM_VIA = 0x4,
76  DM_ARC = 0x10,
77  DM_ANY = 0x17,
78  DM_COMPONENT = 0x20
79 };
87  {
88  public:
90  virtual ~ROUTER_IFACE() {};
91 
92  virtual void SyncWorld( NODE* aNode ) = 0;
93  virtual void AddItem( ITEM* aItem ) = 0;
94  virtual void UpdateItem( ITEM* aItem ) = 0;
95  virtual void RemoveItem( ITEM* aItem ) = 0;
96  virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) const = 0;
97  virtual bool IsItemVisible( const PNS::ITEM* aItem ) const = 0;
98  virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const = 0;
99  virtual void DisplayItem( const ITEM* aItem, int aClearance, bool aEdit = false ) = 0;
100  virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor = -1 ) = 0;
101  virtual void HideItem( ITEM* aItem ) = 0;
102  virtual void Commit() = 0;
103  virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, int aNet ) = 0;
104  virtual int StackupHeight( int aFirstLayer, int aSecondLayer ) const = 0;
105 
106  virtual void EraseView() = 0;
107  virtual void UpdateNet( int aNetCode ) = 0;
108 
109  virtual PNS::NODE* GetWorld() const = 0;
110 
111  virtual RULE_RESOLVER* GetRuleResolver() = 0;
112  virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
113 };
114 
115 class ROUTER
116 {
117 public:
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  RouterState GetState() const { return m_state; }
134 
135  DRAG_ALGO* GetDragger() { return m_dragger.get(); }
136 
137  static ROUTER* GetInstance();
138 
139  void ClearWorld();
140  void SyncWorld();
141 
142  bool RoutingInProgress() const;
143  bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
144  void Move( const VECTOR2I& aP, ITEM* aItem );
145  bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
146  void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
147 
148  void UndoLastSegment();
149  void CommitRouting();
150  void StopRouting();
151  void ClearViewDecorations();
152 
153  NODE* GetWorld() const { return m_world.get(); }
154 
155  void FlipPosture();
156 
157  bool SwitchLayer( int layer );
158 
159  void ToggleViaPlacement();
160  void SetOrthoMode( bool aEnable );
161 
162  void ToggleRounded();
163 
164  int GetCurrentLayer() const;
165  const std::vector<int> GetCurrentNets() const;
166 
167  LOGGER* Logger();
168 
170  {
171  return m_iface->GetRuleResolver();
172  }
173 
174  bool IsPlacingVia() const;
175 
176  const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
177 
178  bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
179  bool StartDragging( const VECTOR2I& aP, ITEM_SET aItems, int aDragMode = DM_COMPONENT );
180 
181  void SetIterLimit( int aX ) { m_iterLimit = aX; }
182  int GetIterLimit() const { return m_iterLimit; };
183 
185 
186  void CommitRouting( NODE* aNode );
187 
192  void UpdateSizes( const SIZES_SETTINGS& aSizes );
193 
198  void LoadSettings( ROUTING_SETTINGS* aSettings )
199  {
200  m_settings = aSettings;
201  }
202 
203  SIZES_SETTINGS& Sizes() { return m_sizes; }
204 
205  void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
206  const wxString& FailureReason() const { return m_failureReason; }
207 
208  PLACEMENT_ALGO* Placer() { return m_placer.get(); }
209 
211  {
212  return m_iface;
213  }
214 
215  void SetVisibleViewArea( const BOX2I& aExtents )
216  {
217  m_visibleViewArea = aExtents;
218  }
219 
220  const BOX2I& VisibleViewArea() const
221  {
222  return m_visibleViewArea;
223  }
224 
225 private:
226  void movePlacing( const VECTOR2I& aP, ITEM* aItem );
227  void moveDragging( const VECTOR2I& aP, ITEM* aItem );
228 
229  void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
230 
231  // optHoverItem queryHoverItemEx(const VECTOR2I& aP);
232 
233  void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
234  bool isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aItem, int aLayer );
235 
239 
240  std::unique_ptr<NODE> m_world;
242 
243  std::unique_ptr<PLACEMENT_ALGO> m_placer;
244  std::unique_ptr<DRAG_ALGO> m_dragger;
245  std::unique_ptr<SHOVE> m_shove;
246 
248 
251 
256 
258  wxString m_failureReason;
259 };
260 
261 }
262 
263 #endif
const wxString & FailureReason() const
Definition: pns_router.h:206
Base class for PNS router board items.
Definition: pns_item.h:55
Contain all persistent settings of the router, such as the mode, optimization effort,...
DRAG_MODE
Definition: pns_router.h:70
Definition: track.h:343
void moveDragging(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:429
Keep the router "world" - i.e.
Definition: pns_node.h:144
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
virtual RULE_RESOLVER * GetRuleResolver()=0
const ITEM_SET QueryHoverItems(const VECTOR2I &aP)
Definition: pns_router.cpp:120
void CommitRouting()
Definition: pns_router.cpp:664
DRAG_ALGO.
Definition: pns_drag_algo.h:42
virtual PNS::NODE * GetWorld() const =0
RULE_RESOLVER * GetRuleResolver() const
Definition: pns_router.h:169
void ClearViewDecorations()
Definition: pns_router.cpp:701
PLACEMENT_ALGO * Placer()
Definition: pns_router.h:208
virtual void HideItem(ITEM *aItem)=0
bool isStartingPointRoutable(const VECTOR2I &aWhere, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:183
void SyncWorld()
Definition: pns_router.cpp:93
bool IsPlacingVia() const
Definition: pns_router.cpp:763
void ToggleRounded()
Definition: pns_router.cpp:772
std::unique_ptr< PLACEMENT_ALGO > m_placer
Definition: pns_router.h:243
BOX2I m_visibleViewArea
Definition: pns_router.h:236
const std::vector< int > GetCurrentNets() const
Definition: pns_router.cpp:735
VECTOR2I m_currentEnd
Definition: pns_router.h:237
int m_iterLimit
Definition: pns_router.h:249
virtual void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, int aColor=-1)=0
ROUTING_SETTINGS * m_settings
Definition: pns_router.h:252
virtual void AddItem(ITEM *aItem)=0
SIZES_SETTINGS & Sizes()
Definition: pns_router.h:203
std::unique_ptr< SHOVE > m_shove
Definition: pns_router.h:245
void SetOrthoMode(bool aEnable)
Definition: pns_router.cpp:790
void ToggleViaPlacement()
Definition: pns_router.cpp:725
std::unique_ptr< NODE > m_world
Definition: pns_router.h:240
void ClearWorld()
Definition: pns_router.cpp:102
std::unique_ptr< DRAG_ALGO > m_dragger
Definition: pns_router.h:244
virtual bool IsAnyLayerVisible(const LAYER_RANGE &aLayer) const =0
virtual ~ROUTER_IFACE()
Definition: pns_router.h:90
wxString m_toolStatusbarName
Definition: pns_router.h:257
void UndoLastSegment()
Definition: pns_router.cpp:655
virtual void SyncWorld(NODE *aNode)=0
virtual void DisplayItem(const ITEM *aItem, int aClearance, bool aEdit=false)=0
virtual void UpdateNet(int aNetCode)=0
void BreakSegment(ITEM *aItem, const VECTOR2I &aP)
Definition: pns_router.cpp:810
void updateView(NODE *aNode, ITEM_SET &aCurrent, bool aDragging=false)
Definition: pns_router.cpp:511
NODE * m_lastNode
Definition: pns_router.h:241
virtual bool IsItemVisible(const PNS::ITEM *aItem) const =0
bool FixRoute(const VECTOR2I &aP, ITEM *aItem, bool aForceFinish=false)
Definition: pns_router.cpp:630
void SetVisibleViewArea(const BOX2I &aExtents)
Definition: pns_router.h:215
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:205
RouterState m_state
Definition: pns_router.h:238
ROUTER_IFACE * m_iface
Definition: pns_router.h:247
void movePlacing(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:547
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:220
void Move(const VECTOR2I &aP, ITEM *aItem)
Definition: pns_router.cpp:406
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
Definition: pns_router.cpp:351
void SetIterLimit(int aX)
Definition: pns_router.h:181
void SetInterface(ROUTER_IFACE *aIface)
Definition: pns_router.cpp:805
virtual void UpdateItem(ITEM *aItem)=0
void StopRouting()
Definition: pns_router.cpp:673
virtual void EraseView()=0
LOGGER * m_logger
Definition: pns_router.h:255
virtual DEBUG_DECORATOR * GetDebugDecorator()=0
ROUTER_MODE
Definition: pns_router.h:62
virtual bool IsFlashedOnLayer(const PNS::ITEM *aItem, int aLayer) const =0
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:535
void SetMode(ROUTER_MODE aMode)
Definition: pns_router.cpp:799
Definition: track.h:262
SHAPE_LINE_CHAIN.
LOGGER * Logger()
Definition: pns_router.cpp:757
virtual int StackupHeight(int aFirstLayer, int aSecondLayer) const =0
DRAG_ALGO * GetDragger()
Definition: pns_router.h:135
bool StartDragging(const VECTOR2I &aP, ITEM *aItem, int aDragMode=DM_ANY)
Definition: pns_router.cpp:129
bool SwitchLayer(int layer)
Definition: pns_router.cpp:716
usual segment : line with rounded ends
SIZES_SETTINGS m_sizes
Definition: pns_router.h:253
virtual void Commit()=0
int GetIterLimit() const
Definition: pns_router.h:182
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:198
virtual void RemoveItem(ITEM *aItem)=0
ROUTER_MODE m_mode
Definition: pns_router.h:254
void FlipPosture()
Definition: pns_router.cpp:707
bool RoutingInProgress() const
Definition: pns_router.cpp:114
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:153
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:184
RouterState GetState() const
Definition: pns_router.h:133
virtual bool ImportSizes(SIZES_SETTINGS &aSizes, ITEM *aStartItem, int aNet)=0
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:210
static ROUTER * GetInstance()
Definition: pns_router.cpp:79
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
bool m_forceMarkObstaclesMode
Definition: pns_router.h:250
wxString m_failureReason
Definition: pns_router.h:258
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:148
void markViolations(NODE *aNode, ITEM_SET &aCurrent, NODE::ITEM_VECTOR &aRemoved)
Definition: pns_router.cpp:440
int GetCurrentLayer() const
Definition: pns_router.cpp:746