Horizon
pns_diff_pair_placer.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_DIFF_PLACER_H
23 #define __PNS_DIFF_PLACER_H
24 
25 #include <math/vector2d.h>
26 
27 #include <geometry/shape.h>
28 #include <geometry/shape_line_chain.h>
29 
30 #include "pns_sizes_settings.h"
31 #include "pns_node.h"
32 #include "pns_via.h"
33 #include "pns_line.h"
34 #include "pns_algo_base.h"
35 #include "pns_diff_pair.h"
36 
37 #include "pns_placement_algo.h"
38 
39 namespace PNS {
40 
41 class ROUTER;
42 class SHOVE;
43 class OPTIMIZER;
44 class VIA;
45 class SIZES_SETTINGS;
46 
47 
56 {
57 public:
58  DIFF_PAIR_PLACER( ROUTER* aRouter );
60 
67  bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
68 
76  bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
77 
87  bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
88 
94  bool ToggleVia( bool aEnabled ) override;
95 
101  bool SetLayer( int aLayer ) override;
102 
108  const ITEM_SET Traces() override;
109 
116  const VECTOR2I& CurrentEnd() const override
117  {
118  return m_currentEnd;
119  }
120 
126  const std::vector<int> CurrentNets() const override;
127 
133  int CurrentLayer() const override
134  {
135  return m_currentLayer;
136  }
137 
143  NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
144 
150  void FlipPosture() override;
151 
159  void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
160 
161  bool IsPlacingVia() const override { return m_placingVia; }
162 
163  void SetOrthoMode( bool aOrthoMode ) override;
164 
165  void GetModifiedNets( std::vector<int>& aNets ) const override;
166 
167 private:
168  int viaGap() const;
169  int gap() const;
170 
181  bool route( const VECTOR2I& aP );
182 
190  void updateLeadingRatLine();
191 
197  void setWorld( NODE* aWorld );
198 
204  void initPlacement( );
205 
212  void setInitialDirection( const DIRECTION_45& aDirection );
213 
214 
215  bool routeHead( const VECTOR2I& aP );
216  bool tryWalkDp( NODE* aNode, DIFF_PAIR& aPair, bool aSolidsOnly );
217 
219  bool rhWalkOnly( const VECTOR2I& aP );
220 
222  bool rhShoveOnly ( const VECTOR2I& aP );
223 
225  bool rhMarkObstacles( const VECTOR2I& aP );
226 
227  const VIA makeVia ( const VECTOR2I& aP, int aNet );
228 
229  bool findDpPrimitivePair( const VECTOR2I& aP, ITEM* aItem, DP_PRIMITIVE_PAIR& aPair, std::string* aErrorMsg = nullptr );
230  OPT_VECTOR2I getDanglingAnchor( NODE* aNode, ITEM* aItem );
231  bool attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent, DIFF_PAIR& aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly );
232  bool propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNewP );
233 
234  enum State {
235  RT_START = 0,
236  RT_ROUTE = 1,
237  RT_FINISH = 2
238  };
239 
240  State m_state;
241 
242  bool m_chainedPlacement;
243  bool m_initialDiagonal;
244  bool m_startDiagonal;
245  bool m_fitOk;
246 
247  int m_netP, m_netN;
248 
249  DP_PRIMITIVE_PAIR m_start;
250  OPT<DP_PRIMITIVE_PAIR> m_prevPair;
251 
253  int m_iteration;
254 
256  NODE* m_world;
257 
259  VECTOR2I m_p_start;
260 
262  SHOVE* m_shove;
263 
265  NODE* m_currentNode;
266 
268  NODE* m_lastNode;
269 
270  SIZES_SETTINGS m_sizes;
271 
273  bool m_placingVia;
274 
276  int m_viaDiameter;
277 
279  int m_viaDrill;
280 
282  int m_currentWidth;
283 
284  int m_currentNet;
285  int m_currentLayer;
286 
287  bool m_startsOnVia;
288  bool m_orthoMode;
289  bool m_snapOnTarget;
290 
291  VECTOR2I m_currentEnd, m_currentStart;
292  DIFF_PAIR m_currentTrace;
293 
294  ITEM* m_currentEndItem;
295  PNS_MODE m_currentMode;
296 
297  bool m_idle;
298 };
299 
300 }
301 
302 #endif // __PNS_LINE_PLACER_H
Class DIRECTION_45.
Definition: direction45.h:37
Class LINE_PLACER.
Definition: pns_diff_pair_placer.h:56
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Function CurrentNode()
Definition: pns_diff_pair_placer.cpp:372
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
Definition: pns_diff_pair_placer.cpp:90
void GetModifiedNets(std::vector< int > &aNets) const override
Function GetModifiedNets.
Definition: pns_diff_pair_placer.cpp:814
bool ToggleVia(bool aEnabled) override
Function ToggleVia()
Definition: pns_diff_pair_placer.cpp:99
const std::vector< int > CurrentNets() const override
Function CurrentNets()
Definition: pns_diff_pair_placer.cpp:838
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
Definition: pns_diff_pair_placer.cpp:547
const ITEM_SET Traces() override
Function Traces()
Definition: pns_diff_pair_placer.cpp:352
const VECTOR2I & CurrentEnd() const override
Function CurrentEnd()
Definition: pns_diff_pair_placer.h:116
void FlipPosture() override
Function FlipPosture()
Definition: pns_diff_pair_placer.cpp:363
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Function UpdateSizes()
Definition: pns_diff_pair_placer.cpp:734
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
Definition: pns_diff_pair_placer.cpp:712
bool IsPlacingVia() const override
Function IsPlacingVia()
Definition: pns_diff_pair_placer.h:161
bool FixRoute(const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
Function FixRoute()
Definition: pns_diff_pair_placer.cpp:746
int CurrentLayer() const override
Function CurrentLayer()
Definition: pns_diff_pair_placer.h:133
bool SetLayer(int aLayer) override
Function SetLayer()
Definition: pns_diff_pair_placer.cpp:381
Class DIFF_PAIR.
Definition: pns_diff_pair.h:265
Class DP_PRIMITIVE_PAIR.
Definition: pns_diff_pair.h:137
Definition: pns_itemset.h:40
Class ITEM.
Definition: pns_item.h:55
Class NODE.
Definition: pns_node.h:138
Class PLACEMENT_ALGO.
Definition: pns_placement_algo.h:46
Definition: pns_router.h:113
Definition: pns_sizes_settings.h:37
Definition: pns_via.h:38