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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  *
9  * This program is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef __PNS_LINE_PLACER_H
24 #define __PNS_LINE_PLACER_H
25 
26 #include <math/vector2d.h>
27 
28 #include <geometry/shape.h>
30 
31 #include "pns_line.h"
32 #include "pns_mouse_trail_tracer.h"
33 #include "pns_node.h"
34 #include "pns_placement_algo.h"
35 #include "pns_sizes_settings.h"
36 #include "pns_via.h"
37 
38 namespace PNS {
39 
40 class ROUTER;
41 class SHOVE;
42 class OPTIMIZER;
43 class VIA;
44 class SIZES_SETTINGS;
45 class NODE;
46 
48 {
49 public:
50  FIXED_TAIL( int aLineCount = 1);
51  ~FIXED_TAIL();
52 
53  struct FIX_POINT
54  {
55  int layer;
59  };
60 
61  struct STAGE
62  {
64  std::vector<FIX_POINT> pts;
65  };
66 
67  void Clear();
68  void AddStage( const VECTOR2I& aStart, int aLayer, bool placingVias, DIRECTION_45 direction,
69  NODE* aNode );
70  bool PopStage( STAGE& aStage );
71  int StageCount() const;
72 
73 private:
74  std::vector<STAGE> m_stages;
75 };
76 
77 
78 
85 {
86 public:
87  LINE_PLACER( ROUTER* aRouter );
88  ~LINE_PLACER();
89 
93  bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
94 
99  bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
100 
109  bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
110 
111  bool UnfixRoute() override;
112 
113  bool CommitPlacement() override;
114 
115  bool AbortPlacement() override;
116 
117  bool HasPlacedAnything() const override;
118 
122  bool ToggleVia( bool aEnabled ) override;
123 
127  bool SetLayer( int aLayer ) override;
128 
133  const LINE& Head() const { return m_head; }
134 
139  const LINE& Tail() const { return m_tail; }
140 
144  const LINE Trace() const;
145 
149  const ITEM_SET Traces() override;
150 
155  const VECTOR2I& CurrentEnd() const override
156  {
157  return m_currentEnd;
158  }
159 
163  const std::vector<int> CurrentNets() const override
164  {
165  return std::vector<int>( 1, m_currentNet );
166  }
167 
171  int CurrentLayer() const override
172  {
173  return m_currentLayer;
174  }
175 
179  NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
180 
184  void FlipPosture() override;
185 
192  void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
193 
194  void SetOrthoMode( bool aOrthoMode ) override;
195 
196  bool IsPlacingVia() const override { return m_placingVia; }
197 
198  void GetModifiedNets( std::vector<int>& aNets ) const override;
199 
204  bool SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
205 
206 private:
215  bool route( const VECTOR2I& aP );
216 
221  void updateLeadingRatLine();
222 
226  void setWorld( NODE* aWorld );
227 
231  void initPlacement();
232 
237  void setInitialDirection( const DIRECTION_45& aDirection );
238 
243  void removeLoops( NODE* aNode, LINE& aLatest );
244 
250  void simplifyNewLine( NODE* aNode, LINKED_ITEM* aLatest );
251 
260 
267  bool handlePullback();
268 
274  bool mergeHead();
275 
284  bool reduceTail( const VECTOR2I& aEnd );
285 
293 
300  bool routeHead( const VECTOR2I& aP, LINE& aNewHead );
301 
308  void routeStep( const VECTOR2I& aP );
309 
311  bool rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead );
312 
314  bool rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead );
315 
317  bool rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead );
318 
319  const VIA makeVia( const VECTOR2I& aP );
320 
321  bool buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aForceNoVia = false );
322 
323 
326 
328 
331 
333 
337 
338  std::unique_ptr<SHOVE> m_shove;
339 
342 
345 
347 
350 
354 
356 
357  bool m_idle;
361 
364 };
365 
366 }
367 
368 #endif // __PNS_LINE_PLACER_H
Base class for PNS router board items.
Definition: pns_item.h:55
const ITEM_SET Traces() override
Return the complete routed line, as a single-member ITEM_SET.
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL).
LINE m_last_head
Most recent successful (non-colliding) head.
Keep the router "world" - i.e.
Definition: pns_node.h:144
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)
void routeStep(const VECTOR2I &aP)
Perform a single routing algorithm step, for the end point aP.
std::vector< STAGE > m_stages
NODE * m_world
pointer to world to search colliding items
void removeLoops(NODE *aNode, LINE &aLatest)
Searches aNode for traces concurrent to aLatest and removes them.
const std::vector< int > CurrentNets() const override
Return the net code of currently routed track.
void simplifyNewLine(NODE *aNode, LINKED_ITEM *aLatest)
Assemble a line starting from segment or arc aLatest, removes collinear segments and redundant vertic...
Single track placement algorithm.
LINE m_head
the volatile part of the track from the previously analyzed point to the current routing destination
bool rhWalkOnly(const VECTOR2I &aP, LINE &aNewHead)
Route step shove mode.
SIZES_SETTINGS m_sizes
std::vector< FIX_POINT > pts
bool PopStage(STAGE &aStage)
FIXED_TAIL(int aLineCount=1)
const LINE Trace() const
Return the complete routed line.
bool reduceTail(const VECTOR2I &aEnd)
Attempt to reduce the number of segments in the tail by trying to replace a certain number of latest ...
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:60
bool FixRoute(const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
Commit the currently routed track to the parent node taking aP as the final end point and aEndItem as...
const LINE & Tail() const
Return the "tail" of the line being placed, the part which has already wrapped around and shoved some...
bool handlePullback()
Deal with pull-back: reduces the tail if head trace is moved backwards wrs to the current tail direct...
LINE_PLACER(ROUTER *aRouter)
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Perform on-the-fly update of the width, via diameter & drill size from a settings class.
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)
Set preferred direction of the very first track segment to be laid.
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:36
bool SplitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
Check if point aP lies on segment aSeg.
std::unique_ptr< SHOVE > m_shove
The shove engine.
DIRECTION_45 m_direction
current routing direction
void initPlacement()
Initialize placement of a new line with given parameters.
void updateLeadingRatLine()
Draw the "leading" rats nest line, which connects the end of currently routed track and the nearest y...
bool routeHead(const VECTOR2I &aP, LINE &aNewHead)
Compute the head trace between the current start point (m_p_start) and point aP, starting with direct...
bool HasPlacedAnything() const override
MOUSE_TRAIL_TRACER m_mouseTrailTracer
bool handleSelfIntersections()
Check if the head of the track intersects its tail.
bool route(const VECTOR2I &aP)
Re-route the current track to point aP.
void GetModifiedNets(std::vector< int > &aNets) const override
Function GetModifiedNets.
FIXED_TAIL m_fixedTail
bool CommitPlacement() override
bool rhMarkObstacles(const VECTOR2I &aP, LINE &aNewHead)
void AddStage(const VECTOR2I &aStart, int aLayer, bool placingVias, DIRECTION_45 direction, NODE *aNode)
bool rhShoveOnly(const VECTOR2I &aP, LINE &aNewHead)
Route step mark obstacles mode.
NODE * m_currentNode
Current world state.
void setWorld(NODE *aWorld)
Set the board to route.
bool optimizeTailHeadTransition()
Try to reduce the corner count of the most recent part of tail/head by merging obtuse/collinear segme...
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Return the most recent world state.
bool ToggleVia(bool aEnabled) override
Enable/disable a via at the end of currently routed trace.
void FlipPosture() override
Toggle the current posture (straight/diagonal) of the trace head.
const VECTOR2I & CurrentEnd() const override
Return the current end of the line being placed.
bool SetLayer(int aLayer) override
Set the current routing layer.
VECTOR2I m_p_start
current routing start (end of tail, beginning of head)
bool IsPlacingVia() const override
Function IsPlacingVia()
bool mergeHead()
Moves "established" segments from the head to the tail if certain conditions are met.
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL).
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
Return the "head" of the line being placed, that is the volatile part that has not been "fixed" yet.
bool buildInitialLine(const VECTOR2I &aP, LINE &aHead, bool aForceNoVia=false)
int CurrentLayer() const override
Return the layer of currently routed track.