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 <[email protected]>
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"
33#include "pns_node.h"
34#include "pns_placement_algo.h"
35#include "pns_sizes_settings.h"
36#include "pns_via.h"
37
38namespace PNS {
39
40class ROUTER;
41class SHOVE;
42class OPTIMIZER;
43class VIA;
44class SIZES_SETTINGS;
45class NODE;
46
48{
49public:
50 FIXED_TAIL( int aLineCount = 1);
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
73private:
74 std::vector<STAGE> m_stages;
75};
76
77
78
85{
86public:
87 LINE_PLACER( ROUTER* aRouter );
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
206private:
215 bool route( const VECTOR2I& aP );
216
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
329
331
334
337
338 std::unique_ptr<SHOVE> m_shove;
339
343
345
347
350
354
357
358 bool m_idle;
362
365};
366
367}
368
369#endif // __PNS_LINE_PLACER_H
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:37
FIXED_TAIL(int aLineCount=1)
int StageCount() const
bool PopStage(STAGE &aStage)
void AddStage(const VECTOR2I &aStart, int aLayer, bool placingVias, DIRECTION_45 direction, NODE *aNode)
std::vector< STAGE > m_stages
Base class for PNS router board items.
Definition: pns_item.h:56
Single track placement algorithm.
bool mergeHead()
Moves "established" segments from the head to the tail if certain conditions are met.
bool handleSelfIntersections()
Check if the head of the track intersects its tail.
LINE_PLACER(ROUTER *aRouter)
bool SetLayer(int aLayer) override
Set the current routing layer.
NODE * m_lastNode
Postprocessed world state (including marked collisions & removed loops)
bool route(const VECTOR2I &aP)
Re-route the current track to point aP.
bool AbortPlacement() override
std::unique_ptr< SHOVE > m_shove
The shove engine.
const LINE Trace() const
Return the complete routed line.
bool handlePullback()
Deal with pull-back: reduces the tail if head trace is moved backwards wrs to the current tail direct...
const std::vector< int > CurrentNets() const override
Return the net code of currently routed track.
void setWorld(NODE *aWorld)
Set the board to route.
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Perform on-the-fly update of the width, via diameter & drill size from a settings class.
bool reduceTail(const VECTOR2I &aEnd)
Attempt to reduce the number of segments in the tail by trying to replace a certain number of latest ...
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
LINE m_tail
routing "tail": part of the track that has been already fixed due to collisions with obstacles
MOUSE_TRAIL_TRACER m_mouseTrailTracer
LINE m_last_head
Most recent successful (non-colliding) head.
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL).
bool optimizeTailHeadTransition()
Try to reduce the corner count of the most recent part of tail/head by merging obtuse/collinear segme...
bool HasPlacedAnything() const override
bool rhMarkObstacles(const VECTOR2I &aP, LINE &aNewHead)
void routeStep(const VECTOR2I &aP)
Perform a single routing algorithm step, for the end point aP.
bool buildInitialLine(const VECTOR2I &aP, LINE &aHead, bool aForceNoVia=false)
NODE * m_currentNode
Current world state.
LINE m_head
the volatile part of the track from the previously analyzed point to the current routing destination
void removeLoops(NODE *aNode, LINE &aLatest)
Searches aNode for traces concurrent to aLatest and removes them.
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...
const LINE & Tail() const
Return the "tail" of the line being placed, the part which has already wrapped around and shoved some...
NODE * m_world
pointer to world to search colliding items
bool rhWalkOnly(const VECTOR2I &aP, LINE &aNewHead)
Route step shove mode.
DIRECTION_45 m_initial_direction
routing direction for new traces
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Return the most recent world state.
SIZES_SETTINGS m_sizes
bool SplitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
Check if point aP lies on segment aSeg.
void setInitialDirection(const DIRECTION_45 &aDirection)
Set preferred direction of the very first track segment to be laid.
void updateLeadingRatLine()
Draw the "leading" rats nest line, which connects the end of currently routed track and the nearest y...
int CurrentLayer() const override
Return the layer of currently routed track.
bool UnfixRoute() override
void FlipPosture() override
Toggle the current posture (straight/diagonal) of the trace head.
const VIA makeVia(const VECTOR2I &aP)
void GetModifiedNets(std::vector< int > &aNets) const override
Function GetModifiedNets.
bool CommitPlacement() override
VECTOR2I m_p_start
current routing start (end of tail, beginning of head)
bool IsPlacingVia() const override
Function IsPlacingVia()
const LINE & Head() const
Return the "head" of the line being placed, that is the volatile part that has not been "fixed" yet.
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).
const VECTOR2I & CurrentEnd() const override
Return the current end of the line being placed.
void simplifyNewLine(NODE *aNode, LINKED_ITEM *aLatest)
Assemble a line starting from segment or arc aLatest, removes collinear segments and redundant vertic...
DIRECTION_45 m_direction
current routing direction
void initPlacement()
Initialize placement of a new line with given parameters.
FIXED_TAIL m_fixedTail
const ITEM_SET Traces() override
Return the complete routed line, as a single-member ITEM_SET.
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...
bool rhShoveOnly(const VECTOR2I &aP, LINE &aNewHead)
Route step mark obstacles mode.
bool ToggleVia(bool aEnabled) override
Enable/disable a via at the end of currently routed trace.
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
Keep the router "world" - i.e.
Definition: pns_node.h:150
Push and Shove diff pair dimensions (gap) settings dialog.
std::vector< FIX_POINT > pts