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