KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_shove.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
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_SHOVE_H
23#define __PNS_SHOVE_H
24
25#include <vector>
26#include <stack>
27
28#include <math/box2.h>
29
30#include "pns_optimizer.h"
32#include "pns_algo_base.h"
33#include "pns_logger.h"
34#include "range.h"
35
36namespace PNS {
37
38class LINE;
39class NODE;
40class ROUTER;
41
45class SHOVE : public ALGO_BASE
46{
47public:
48
50 {
51 SH_OK = 0,
56 };
57
58 SHOVE( NODE* aWorld, ROUTER* aRouter );
59 ~SHOVE();
60
61 SHOVE_STATUS ShoveLines( const LINE& aCurrentHead );
62 SHOVE_STATUS ShoveMultiLines( const ITEM_SET& aHeadSet );
63
64 SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere,
65 VIA_HANDLE& aNewVia );
66 SHOVE_STATUS ShoveObstacleLine( const LINE& aCurLine, const LINE& aObstacleLine,
67 LINE& aResultLine );
68
69 void ForceClearance ( bool aEnabled, int aClearance )
70 {
71 if( aEnabled )
72 m_forceClearance = aClearance;
73 else
75 }
76
78
79 const LINE NewHead() const;
80
81 void SetInitialLine( LINE& aInitial );
82
83 bool AddLockedSpringbackNode( NODE* aNode );
84 void UnlockSpringbackNode( NODE* aNode );
85 bool RewindSpringbackTo( NODE* aNode );
87 void DisablePostShoveOptimizations( int aMask );
88 void SetSpringbackDoNotTouchNode( const NODE *aNode );
89
90private:
91 typedef std::vector<SHAPE_LINE_CHAIN> HULL_SET;
92 typedef std::optional<LINE> OPT_LINE;
93 typedef std::pair<LINE, LINE> LINE_PAIR;
94 typedef std::vector<LINE_PAIR> LINE_PAIR_VEC;
95
97 {
99 m_length( 0 ),
100 m_draggedVia(),
101 m_node( nullptr ),
102 m_seq( 0 ),
103 m_locked( false )
104 {}
105
106 int64_t m_length;
111 int m_seq;
113 };
114
115 SHOVE_STATUS shoveLineToHullSet( const LINE& aCurLine, const LINE& aObstacleLine,
116 LINE& aResultLine, const HULL_SET& aHulls );
117
118 NODE* reduceSpringback( const ITEM_SET& aHeadSet, VIA_HANDLE& aDraggedVia );
119
120 bool pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea, VIA* aDraggedVia );
121
122 SHOVE_STATUS shoveLineFromLoneVia( const LINE& aCurLine, const LINE& aObstacleLine,
123 LINE& aResultLine );
124 bool checkShoveDirection( const LINE& aCurLine, const LINE& aObstacleLine,
125 const LINE& aShovedLine ) const;
126
127 SHOVE_STATUS onCollidingArc( LINE& aCurrent, ARC* aObstacleArc );
128 SHOVE_STATUS onCollidingLine( LINE& aCurrent, LINE& aObstacle );
129 SHOVE_STATUS onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacleSeg );
130 SHOVE_STATUS onCollidingSolid( LINE& aCurrent, ITEM* aObstacle, OBSTACLE& aObstacleInfo );
131 SHOVE_STATUS onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia, OBSTACLE& aObstacleInfo );
132 SHOVE_STATUS onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia );
133 SHOVE_STATUS pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, int aCurrentRank );
134
136
137 void unwindLineStack( const LINKED_ITEM* aSeg );
138 void unwindLineStack( const ITEM* aItem );
139
140 void runOptimizer( NODE* aNode );
141
142 bool pushLineStack( const LINE& aL, bool aKeepCurrentOnTop = false );
143 void popLineStack();
144
145 LINE assembleLine( const LINKED_ITEM* aSeg, int* aIndex = nullptr );
146
147 void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
148 void replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea = true,
149 NODE *aNode = nullptr );
150
151 LINE* findRootLine( LINE *aLine );
152
154
155 SHOVE_STATUS shoveIteration( int aIter );
157
158 int getClearance( const ITEM* aA, const ITEM* aB ) const;
159 bool fixupViaCollisions( const LINE* aCurrent, OBSTACLE& obs );
160 void sanityCheck( LINE* aOld, LINE* aNew );
161
162 std::vector<SPRINGBACK_TAG> m_nodeStack;
163 std::vector<LINE> m_lineStack;
164 std::vector<LINE> m_optimizerQueue;
165 std::unordered_map<const LINKED_ITEM*, LINE*> m_rootLineHistory;
166
171
173
175
179
181};
182
183}
184
185#endif // __PNS_SHOVE_H
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:856
Base class for all P&S algorithms (shoving, walkaround, line placement, dragging, etc....
Definition: pns_algo_base.h:43
Base class for PNS router board items.
Definition: pns_item.h:97
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
The actual Push and Shove algorithm.
Definition: pns_shove.h:46
void SetSpringbackDoNotTouchNode(const NODE *aNode)
Definition: pns_shove.cpp:2040
SHOVE_STATUS shoveIteration(int aIter)
Definition: pns_shove.cpp:1302
SHOVE_STATUS shoveMainLoop()
Definition: pns_shove.cpp:1489
std::vector< SHAPE_LINE_CHAIN > HULL_SET
Definition: pns_shove.h:91
int m_iter
Definition: pns_shove.h:176
std::pair< LINE, LINE > LINE_PAIR
Definition: pns_shove.h:93
OPT_BOX2I m_affectedArea
Definition: pns_shove.h:153
std::vector< LINE > m_lineStack
Definition: pns_shove.h:163
void popLineStack()
Definition: pns_shove.cpp:1194
LINE * findRootLine(LINE *aLine)
Definition: pns_shove.cpp:1829
std::vector< SPRINGBACK_TAG > m_nodeStack
Definition: pns_shove.h:162
SHOVE_STATUS onCollidingArc(LINE &aCurrent, ARC *aObstacleArc)
Definition: pns_shove.cpp:548
SHOVE_STATUS ShoveObstacleLine(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
Definition: pns_shove.cpp:394
LINE assembleLine(const LINKED_ITEM *aSeg, int *aIndex=nullptr)
Definition: pns_shove.cpp:181
std::optional< LINE > OPT_LINE
Definition: pns_shove.h:92
NODE * m_currentNode
Definition: pns_shove.h:168
void ForceClearance(bool aEnabled, int aClearance)
Definition: pns_shove.h:69
void SetInitialLine(LINE &aInitial)
Definition: pns_shove.cpp:1958
bool checkShoveDirection(const LINE &aCurLine, const LINE &aObstacleLine, const LINE &aShovedLine) const
Definition: pns_shove.cpp:195
int m_forceClearance
Definition: pns_shove.h:177
SHOVE_STATUS pushOrShoveVia(VIA *aVia, const VECTOR2I &aForce, int aCurrentRank)
Definition: pns_shove.cpp:846
SHOVE_STATUS onCollidingSegment(LINE &aCurrent, SEGMENT *aObstacleSeg)
Definition: pns_shove.cpp:484
void DisablePostShoveOptimizations(int aMask)
Definition: pns_shove.cpp:2034
SHOVE_STATUS ShoveLines(const LINE &aCurrentHead)
Definition: pns_shove.cpp:1551
bool RewindSpringbackTo(NODE *aNode)
Definition: pns_shove.cpp:1976
bool pushLineStack(const LINE &aL, bool aKeepCurrentOnTop=false)
Definition: pns_shove.cpp:1170
@ SH_INCOMPLETE
Definition: pns_shove.h:53
@ SH_HEAD_MODIFIED
Definition: pns_shove.h:54
@ SH_TRY_WALK
Definition: pns_shove.h:55
OPT_BOX2I totalAffectedArea() const
Definition: pns_shove.cpp:1535
bool RewindToLastLockedNode()
Definition: pns_shove.cpp:2005
void replaceLine(LINE &aOld, LINE &aNew, bool aIncludeInChangedArea=true, NODE *aNode=nullptr)
Definition: pns_shove.cpp:60
SHOVE_STATUS ShoveDraggingVia(const VIA_HANDLE aOldVia, const VECTOR2I &aWhere, VIA_HANDLE &aNewVia)
Definition: pns_shove.cpp:1752
void sanityCheck(LINE *aOld, LINE *aNew)
Definition: pns_shove.cpp:139
int m_restrictSpringbackTagId
Definition: pns_shove.h:170
NODE * reduceSpringback(const ITEM_SET &aHeadSet, VIA_HANDLE &aDraggedVia)
Definition: pns_shove.cpp:771
void runOptimizer(NODE *aNode)
Definition: pns_shove.cpp:1846
SHOVE_STATUS shoveLineToHullSet(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine, const HULL_SET &aHulls)
Definition: pns_shove.cpp:262
bool pushSpringback(NODE *aNode, const OPT_BOX2I &aAffectedArea, VIA *aDraggedVia)
Definition: pns_shove.cpp:806
SHOVE_STATUS onCollidingLine(LINE &aCurrent, LINE &aObstacle)
Definition: pns_shove.cpp:606
void UnlockSpringbackNode(NODE *aNode)
Definition: pns_shove.cpp:2017
NODE * m_root
Definition: pns_shove.h:167
bool AddLockedSpringbackNode(NODE *aNode)
Definition: pns_shove.cpp:1965
OPT_LINE m_newHead
Definition: pns_shove.h:172
void unwindLineStack(const LINKED_ITEM *aSeg)
Definition: pns_shove.cpp:1125
NODE * CurrentNode()
Definition: pns_shove.cpp:1944
SHOVE_STATUS shoveLineFromLoneVia(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
Definition: pns_shove.cpp:215
int getClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_shove.cpp:122
bool m_multiLineMode
Definition: pns_shove.h:178
SHOVE_STATUS onReverseCollidingVia(LINE &aCurrent, VIA *aObstacleVia)
Definition: pns_shove.cpp:1044
std::vector< LINE > m_optimizerQueue
Definition: pns_shove.h:164
SHOVE_STATUS onCollidingSolid(LINE &aCurrent, ITEM *aObstacle, OBSTACLE &aObstacleInfo)
Definition: pns_shove.cpp:646
int m_optFlagDisableMask
Definition: pns_shove.h:180
bool fixupViaCollisions(const LINE *aCurrent, OBSTACLE &obs)
Definition: pns_shove.cpp:1220
void replaceItems(ITEM *aOld, std::unique_ptr< ITEM > aNew)
Definition: pns_shove.cpp:49
VIA * m_draggedVia
Definition: pns_shove.h:174
const NODE * m_springbackDoNotTouchNode
Definition: pns_shove.h:169
SHOVE_STATUS ShoveMultiLines(const ITEM_SET &aHeadSet)
Definition: pns_shove.cpp:1654
std::unordered_map< const LINKED_ITEM *, LINE * > m_rootLineHistory
Definition: pns_shove.h:165
const LINE NewHead() const
Definition: pns_shove.cpp:1950
std::vector< LINE_PAIR > LINE_PAIR_VEC
Definition: pns_shove.h:94
SHOVE_STATUS onCollidingVia(ITEM *aCurrent, VIA *aObstacleVia, OBSTACLE &aObstacleInfo)
Definition: pns_shove.cpp:971
Push and Shove diff pair dimensions (gap) settings dialog.
Hold an object colliding with another object, along with some useful data about the collision.
Definition: pns_node.h:87