KiCad PCB EDA Suite
pns_line_placer.h
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2017 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_LINE_PLACER_H
23 #define __PNS_LINE_PLACER_H
24 
25 #include <math/vector2d.h>
26 
27 #include <geometry/shape.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_placement_algo.h"
35 
36 namespace PNS {
37 
38 class ROUTER;
39 class SHOVE;
40 class OPTIMIZER;
41 class VIA;
42 class SIZES_SETTINGS;
43 class NODE;
44 
45 class FIXED_TAIL {
46 public:
47  FIXED_TAIL ( int aLineCount = 1);
48  ~FIXED_TAIL();
49 
50  struct FIX_POINT
51  {
52  int layer;
56  };
57 
58  struct STAGE {
60  std::vector<FIX_POINT> pts;
61  };
62 
63  void Clear();
64  void AddStage( VECTOR2I aStart, int aLayer, bool placingVias, DIRECTION_45 direction, NODE *aNode );
65  bool PopStage( STAGE& aStage );
66  int StageCount() const;
67 
68 private:
69 
70  std::vector<STAGE> m_stages;
71 };
72 
81 {
82 public:
83  LINE_PLACER( ROUTER* aRouter );
84  ~LINE_PLACER();
85 
92  bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
93 
101  bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
102 
112  bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
113 
114  bool UnfixRoute() override;
115 
116  bool CommitPlacement() override;
117 
118  bool AbortPlacement() override;
119 
120  bool HasPlacedAnything() const override;
121 
127  bool ToggleVia( bool aEnabled ) override;
128 
134  bool SetLayer( int aLayer ) override;
135 
142  const LINE& Head() const { return m_head; }
143 
150  const LINE& Tail() const { return m_tail; }
151 
157  const LINE Trace() const;
158 
164  const ITEM_SET Traces() override;
165 
172  const VECTOR2I& CurrentEnd() const override
173  {
174  return m_currentEnd;
175  }
176 
182  const std::vector<int> CurrentNets() const override
183  {
184  return std::vector<int>( 1, m_currentNet );
185  }
186 
192  int CurrentLayer() const override
193  {
194  return m_currentLayer;
195  }
196 
202  NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
203 
209  void FlipPosture() override;
210 
218  void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
219 
220  void SetOrthoMode( bool aOrthoMode ) override;
221 
222  bool IsPlacingVia() const override { return m_placingVia; }
223 
224  void GetModifiedNets( std::vector<int>& aNets ) const override;
225 
232  bool SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
233 
234 
235 private:
246  bool route( const VECTOR2I& aP );
247 
255  void updateLeadingRatLine();
256 
262  void setWorld( NODE* aWorld );
263 
269  void initPlacement();
270 
277  void setInitialDirection( const DIRECTION_45& aDirection );
278 
285  void removeLoops( NODE* aNode, LINE& aLatest );
286 
294  void simplifyNewLine( NODE* aNode, SEGMENT* aLatest );
295 
303  bool checkObtusity( const SEG& aA, const SEG& aB ) const;
304 
314 
322  bool handlePullback();
323 
331  bool mergeHead();
332 
342  bool reduceTail( const VECTOR2I& aEnd );
343 
352 
361  bool routeHead( const VECTOR2I& aP, LINE& aNewHead);
362 
370  void routeStep( const VECTOR2I& aP );
371 
372  const LINE reduceToNearestObstacle( const LINE& aOriginalLine );
373 
374  bool rhStopAtNearestObstacle( const VECTOR2I& aP, LINE& aNewHead );
375 
376 
378  bool rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead);
379 
381  bool rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead);
382 
384  bool rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead );
385 
386  const VIA makeVia( const VECTOR2I& aP );
387 
388  bool buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aInvertPosture = false );
389 
392 
395 
399 
402 
405 
408 
410  std::unique_ptr< SHOVE > m_shove;
411 
414 
417 
419 
422 
425 
428 
431 
432  bool m_idle;
436 
438 };
439 
440 }
441 
442 #endif // __PNS_LINE_PLACER_H
ITEM.
Definition: pns_item.h:53
const ITEM_SET Traces() override
Function Traces()
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
NODE.
Definition: pns_node.h:145
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)
PNS_MODE
Routing modes
void routeStep(const VECTOR2I &aP)
Function routeStep()
std::vector< STAGE > m_stages
NODE * m_world
pointer to world to search colliding items
bool checkObtusity(const SEG &aA, const SEG &aB) const
Function checkObtusity()
void removeLoops(NODE *aNode, LINE &aLatest)
Function removeLoops()
const std::vector< int > CurrentNets() const override
Function CurrentNet()
const LINE reduceToNearestObstacle(const LINE &aOriginalLine)
LINE_PLACER.
LINE m_head
routing "head": volatile part of the track from the previously analyzed point to the current routing ...
bool rhWalkOnly(const VECTOR2I &aP, LINE &aNewHead)
route step, walkaround mode
SIZES_SETTINGS m_sizes
std::vector< FIX_POINT > pts
bool PopStage(STAGE &aStage)
FIXED_TAIL(int aLineCount=1)
const LINE Trace() const
Function Trace()
void simplifyNewLine(NODE *aNode, SEGMENT *aLatest)
Function simplifyNewLine()
bool reduceTail(const VECTOR2I &aEnd)
Function reduceTail()
bool FixRoute(const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
Function FixRoute()
const LINE & Tail() const
Function Tail()
bool handlePullback()
Function handlePullback()
LINE_PLACER(ROUTER *aRouter)
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Function UpdateSizes()
DIRECTION_45 m_initial_direction
routing direction for new traces
LINE m_tail
routing "tail": part of the track that has been already fixed due to collisions with obstacles
void setInitialDirection(const DIRECTION_45 &aDirection)
Function setInitialDirection()
DIRECTION_45.
Definition: direction45.h:37
bool SplitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
Function SplitAdjacentSegments()
DIRECTION_45 m_direction
current routing direction
void initPlacement()
Function startPlacement()
bool buildInitialLine(const VECTOR2I &aP, LINE &aHead, bool aInvertPosture=false)
void updateLeadingRatLine()
Function updateLeadingRatLine()
bool routeHead(const VECTOR2I &aP, LINE &aNewHead)
Function routeHead()
bool HasPlacedAnything() const override
bool handleSelfIntersections()
Function handleSelfIntersections()
bool route(const VECTOR2I &aP)
Function route()
std::unique_ptr< SHOVE > m_shove
The shove engine
void GetModifiedNets(std::vector< int > &aNets) const override
Function GetModifiedNets.
FIXED_TAIL m_fixedTail
bool CommitPlacement() override
bool rhMarkObstacles(const VECTOR2I &aP, LINE &aNewHead)
route step, mark obstacles mode
bool rhShoveOnly(const VECTOR2I &aP, LINE &aNewHead)
route step, shove mode
Definition: seg.h:39
NODE * m_currentNode
Current world state
void setWorld(NODE *aWorld)
Function setWorld()
bool optimizeTailHeadTransition()
Function optimizeTailHeadTransition()
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Function CurrentNode()
bool ToggleVia(bool aEnabled) override
Function ToggleVia()
void AddStage(VECTOR2I aStart, int aLayer, bool placingVias, DIRECTION_45 direction, NODE *aNode)
void FlipPosture() override
Function FlipPosture()
const VECTOR2I & CurrentEnd() const override
Function CurrentEnd()
bool m_placingVia
Are we placing a via?
bool SetLayer(int aLayer) override
Function SetLayer()
VECTOR2I m_p_start
current routing start point (end of tail, beginning of head)
bool IsPlacingVia() const override
Function IsPlacingVia()
bool mergeHead()
Function mergeHead()
bool rhStopAtNearestObstacle(const VECTOR2I &aP, LINE &aNewHead)
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
bool AbortPlacement() override
const VIA makeVia(const VECTOR2I &aP)
int StageCount() const
Push and Shove diff pair dimensions (gap) settings dialog.
bool UnfixRoute() override
const LINE & Head() const
Function Head()
int CurrentLayer() const override
Function CurrentLayer()