KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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#include "pns_walkaround.h"
38
39namespace PNS {
40
41class ROUTER;
42class SHOVE;
43class OPTIMIZER;
44class VIA;
45class SIZES_SETTINGS;
46class NODE;
47
49{
50public:
51 FIXED_TAIL( int aLineCount = 1);
53
54 struct FIX_POINT
55 {
56 int layer;
60 };
61
62 struct STAGE
63 {
65 std::vector<FIX_POINT> pts;
66 };
67
68 void Clear();
69 void AddStage( const VECTOR2I& aStart, int aLayer, bool placingVias, DIRECTION_45 direction,
70 NODE* aNode );
71 bool PopStage( STAGE& aStage );
72 int StageCount() const;
73
74private:
75 std::vector<STAGE> m_stages;
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 std::optional<VECTOR2I> 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
154 const VECTOR2I& CurrentStart() const override
155 {
156 return m_currentStart;
157 }
158
163 const VECTOR2I& CurrentEnd() const override
164 {
165 return m_currentEnd;
166 }
167
171 const std::vector<NET_HANDLE> CurrentNets() const override
172 {
173 return std::vector<NET_HANDLE>( 1, m_currentNet );
174 }
175
179 int CurrentLayer() const override
180 {
181 return m_currentLayer;
182 }
183
187 NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
188
192 void FlipPosture() override;
193
200 void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
201
202 void SetOrthoMode( bool aOrthoMode ) override;
203
204 bool IsPlacingVia() const override { return m_placingVia; }
205
206 void GetModifiedNets( std::vector<NET_HANDLE>& aNets ) const override;
207
212 bool SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
213
218 bool SplitAdjacentArcs( NODE* aNode, ITEM* aArc, const VECTOR2I& aP );
219
220private:
229 bool route( const VECTOR2I& aP );
230
236
240 void setWorld( NODE* aWorld );
241
245 void initPlacement();
246
251 void setInitialDirection( const DIRECTION_45& aDirection );
252
257 void removeLoops( NODE* aNode, LINE& aLatest );
258
264 void simplifyNewLine( NODE* aNode, LINKED_ITEM* aLatest );
265
274
281 bool handlePullback();
282
288 bool mergeHead();
289
298 bool reduceTail( const VECTOR2I& aEnd );
299
307
314 bool routeHead( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
315
322 void routeStep( const VECTOR2I& aP );
323
325 bool rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
326 bool rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisionMask, bool& aViaOk );
327 bool splitHeadTail( const LINE& aNewLine, const LINE& aOldTail, LINE& aNewHead, LINE& aNewTail );
328 bool cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCursor, double lengthThreshold, SHAPE_LINE_CHAIN& aOut );
329 bool clipAndCheckCollisions( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aL, SHAPE_LINE_CHAIN& aOut, int &thresholdDist );
330
331 void updatePStart( const LINE& tail );
332
333 //bool rhPostSplitHeadTail( )
334
336 bool rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
337
339 bool rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
340
341 const VIA makeVia( const VECTOR2I& aP );
342
343 bool buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aForceNoVia = false );
344
345
348
351
354
358
359 std::optional<VECTOR2I> m_last_p_end;
360
361 std::unique_ptr<SHOVE> m_shove;
362
366
368
370
373
377
380
381 bool m_idle;
385
388};
389
390}
391
392#endif // __PNS_LINE_PLACER_H
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:37
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:97
Single track placement algorithm.
bool mergeHead()
Moves "established" segments from the head to the tail if certain conditions are met.
bool SplitAdjacentArcs(NODE *aNode, ITEM *aArc, const VECTOR2I &aP)
Snaps the point aP to arc aArc.
bool handleSelfIntersections()
Check if the head of the track intersects its tail.
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.
void updatePStart(const LINE &tail)
bool AbortPlacement() override
std::unique_ptr< SHOVE > m_shove
The shove engine.
const LINE Trace() const
Return the complete routed line.
bool splitHeadTail(const LINE &aNewLine, const LINE &aOldTail, LINE &aNewHead, LINE &aNewTail)
bool handlePullback()
Deal with pull-back: reduces the tail if head trace is moved backwards wrs to the current tail direct...
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
const std::vector< NET_HANDLE > CurrentNets() const override
Return the net of currently routed track.
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL).
std::optional< VECTOR2I > m_last_p_end
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
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.
bool cursorDistMinimum(const SHAPE_LINE_CHAIN &aL, const VECTOR2I &aCursor, double lengthThreshold, SHAPE_LINE_CHAIN &aOut)
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.
const LINE & Tail() const
Return the "tail" of the line being placed, the part which has already wrapped around and shoved some...
VECTOR2I m_fixStart
start point of the last 'fix'
bool rhMarkObstacles(const VECTOR2I &aP, LINE &aNewHead, LINE &aNewTail)
NODE * m_world
pointer to world to search colliding items
NET_HANDLE m_currentNet
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)
Snaps the point aP to 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...
bool routeHead(const VECTOR2I &aP, LINE &aNewHead, LINE &aNewTail)
Compute the head trace between the current start point (m_p_start) and point aP, starting with direct...
int CurrentLayer() const override
Return the layer of currently routed track.
bool rhWalkOnly(const VECTOR2I &aP, LINE &aNewHead, LINE &aNewTail)
void FlipPosture() override
Toggle the current posture (straight/diagonal) of the trace head.
const VIA makeVia(const VECTOR2I &aP)
bool rhShoveOnly(const VECTOR2I &aP, LINE &aNewHead, LINE &aNewTail)
< Route step shove mode.
bool rhWalkBase(const VECTOR2I &aP, LINE &aWalkLine, int aCollisionMask, bool &aViaOk)
bool CommitPlacement() override
VECTOR2I m_p_start
current routing start (end of tail, beginning of head)
bool IsPlacingVia() const override
Function IsPlacingVia()
void GetModifiedNets(std::vector< NET_HANDLE > &aNets) const override
Function GetModifiedNets.
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.
const VECTOR2I & CurrentStart() const override
Return the current start of the line being placed.
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...
std::optional< VECTOR2I > UnfixRoute() override
bool ToggleVia(bool aEnabled) override
Enable/disable a via at the end of currently routed trace.
bool clipAndCheckCollisions(const VECTOR2I &aP, const SHAPE_LINE_CHAIN &aL, SHAPE_LINE_CHAIN &aOut, int &thresholdDist)
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:207
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54
@ VIA
Normal via.
Definition: router_tool.cpp:93
std::vector< FIX_POINT > pts