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 The 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
61
62 struct STAGE
63 {
65 commit( nullptr )
66 {}
67
68 STAGE( const STAGE& aOther )
69 {
70 *this = aOther;
71 }
72
73 // Copy operator
74 STAGE& operator=( const STAGE& aOther )
75 {
76 commit = aOther.commit;
77 pts = aOther.pts;
78 return *this;
79 }
80
81 // Move assignment operator
82 STAGE& operator=( STAGE&& aOther ) noexcept
83 {
84 if (this != &aOther)
85 {
86 commit = aOther.commit;
87 pts = std::move( aOther.pts );
88 }
89
90 return *this;
91 }
92
94 std::vector<FIX_POINT> pts;
95 };
96
97 void Clear();
98 void AddStage( const VECTOR2I& aStart, int aLayer, bool placingVias, DIRECTION_45 direction,
99 NODE* aNode );
100 bool PopStage( STAGE& aStage );
101 int StageCount() const;
102
103private:
104 std::vector<STAGE> m_stages;
105};
106
107
112
114{
115public:
116 LINE_PLACER( ROUTER* aRouter );
117 ~LINE_PLACER();
118
122 bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
123
128 bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
129
138 bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
139
140 std::optional<VECTOR2I> UnfixRoute() override;
141
142 bool CommitPlacement() override;
143
144 bool AbortPlacement() override;
145
146 bool HasPlacedAnything() const override;
147
151 bool ToggleVia( bool aEnabled ) override;
152
156 bool SetLayer( int aLayer ) override;
157
162 const LINE& Head() const { return m_head; }
163
168 const LINE& Tail() const { return m_tail; }
169
173 const LINE Trace() const;
174
178 const ITEM_SET Traces() override;
179
183 const VECTOR2I& CurrentStart() const override
184 {
185 return m_currentStart;
186 }
187
192 const VECTOR2I& CurrentEnd() const override
193 {
194 return m_currentEnd;
195 }
196
200 const std::vector<NET_HANDLE> CurrentNets() const override
201 {
202 return std::vector<NET_HANDLE>( 1, m_currentNet );
203 }
204
208 int CurrentLayer() const override
209 {
210 return m_currentLayer;
211 }
212
216 NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
217
221 void FlipPosture() override;
222
229 void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
230
231 void SetOrthoMode( bool aOrthoMode ) override;
232
233 bool IsPlacingVia() const override { return m_placingVia; }
234
235 void GetModifiedNets( std::vector<NET_HANDLE>& aNets ) const override;
236
241 bool SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
242
247 bool SplitAdjacentArcs( NODE* aNode, ITEM* aArc, const VECTOR2I& aP );
248
249private:
258 bool route( const VECTOR2I& aP );
259
265
269 void setWorld( NODE* aWorld );
270
274 void initPlacement();
275
280 void setInitialDirection( const DIRECTION_45& aDirection );
281
286 void removeLoops( NODE* aNode, LINE& aLatest );
287
293 void simplifyNewLine( NODE* aNode, LINKED_ITEM* aLatest );
294
303
310 bool handlePullback();
311
317 bool mergeHead();
318
327 bool reduceTail( const VECTOR2I& aEnd );
328
336
343 bool routeHead( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
344
351 void routeStep( const VECTOR2I& aP );
352
354 bool rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
355 bool rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisionMask, PNS::PNS_MODE aMode, bool& aViaOk );
356 bool splitHeadTail( const LINE& aNewLine, const LINE& aOldTail, LINE& aNewHead, LINE& aNewTail );
357 bool cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCursor, double lengthThreshold, SHAPE_LINE_CHAIN& aOut );
358 bool clipAndCheckCollisions( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aL, SHAPE_LINE_CHAIN& aOut, int &thresholdDist );
359
360 void updatePStart( const LINE& tail );
361
362 //bool rhPostSplitHeadTail( )
363
365 bool rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
366
368 bool rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail );
369
370 const VIA makeVia( const VECTOR2I& aP );
371
372 bool buildInitialLine( const VECTOR2I& aP, LINE& aHead, PNS::PNS_MODE aMode, bool aForceNoVia = false );
373
374
377
380
383
387
388 std::optional<VECTOR2I> m_last_p_end;
389
390 std::unique_ptr<SHOVE> m_shove;
391
395
397
399
402
406
409
410 bool m_idle;
414
417};
418
419}
420
421#endif // __PNS_LINE_PLACER_H
Represent route directions & corner angles in a 45-degree metric.
Definition direction45.h:37
FIXED_TAIL(int aLineCount=1)
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:98
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.
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.
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.
NODE * m_currentNode
Current world state.
bool buildInitialLine(const VECTOR2I &aP, LINE &aHead, PNS::PNS_MODE aMode, bool aForceNoVia=false)
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.
bool rhWalkBase(const VECTOR2I &aP, LINE &aWalkLine, int aCollisionMask, PNS::PNS_MODE aMode, bool &aViaOk)
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 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.
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:62
Keep the router "world" - i.e.
Definition pns_node.h:232
Perform various optimizations of the lines being routed, attempting to make the lines shorter and les...
PLACEMENT_ALGO(ROUTER *aRouter)
The actual Push and Shove algorithm.
Definition pns_shove.h:46
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.
PNS_MODE
< Routing modes
void * NET_HANDLE
Definition pns_item.h:55
std::vector< FIX_POINT > pts
STAGE & operator=(const STAGE &aOther)
STAGE(const STAGE &aOther)
STAGE & operator=(STAGE &&aOther) noexcept
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695