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 The 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
57
69
70
71 void SetDefaultShovePolicy( int aPolicy );
72
73 void SetShovePolicy( const LINKED_ITEM* aItem, int aPolicy );
74 void SetShovePolicy( const LINE& aLine, int aPolicy );
75
76 SHOVE( NODE* aWorld, ROUTER* aRouter );
77 ~SHOVE();
78
79 void ClearHeads();
80 void AddHeads( const LINE& aHead, int aPolicy = SHP_DEFAULT );
81 void AddHeads( VIA_HANDLE aHead, VECTOR2I aNewPos, int aPolicy = SHP_DEFAULT );
82
84
85 SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere,
86 VIA_HANDLE& aNewVia );
87 bool ShoveObstacleLine( const LINE& aCurLine, const LINE& aObstacleLine,
88 LINE& aResultLine );
89
90 void ForceClearance ( bool aEnabled, int aClearance )
91 {
92 if( aEnabled )
93 m_forceClearance = aClearance;
94 else
96 }
97
99
100 bool HeadsModified( int aIndex = -1 ) const;
101 const PNS::LINE GetModifiedHead( int aIndex ) const;
102 const VIA_HANDLE GetModifiedHeadVia( int aIndex ) const;
103
104 bool AddLockedSpringbackNode( NODE* aNode );
105 void UnlockSpringbackNode( NODE* aNode );
106 bool RewindSpringbackTo( NODE* aNode );
108 void DisablePostShoveOptimizations( int aMask );
109 void SetSpringbackDoNotTouchNode( const NODE *aNode );
110
111private:
112 typedef std::vector<SHAPE_LINE_CHAIN> HULL_SET;
113 typedef std::optional<LINE> OPT_LINE;
114 typedef std::pair<LINE, LINE> LINE_PAIR;
115 typedef std::vector<LINE_PAIR> LINE_PAIR_VEC;
116
118 {
119 ROOT_LINE_ENTRY( LINE* aLine = nullptr, int aPolicy = SHP_DEFAULT ) :
120 rootLine( aLine ),
121 policy( aPolicy )
122 {}
123
124 LINE *rootLine = nullptr;
125 VIA* oldVia = nullptr;
126 VIA* newVia = nullptr;
127 std::optional<LINE> newLine;
129 bool isHead = false;
130 };
131
133 {
134 HEAD_LINE_ENTRY( const LINE& aOrig, int aPolicy = SHP_DEFAULT ) :
135 origHead( aOrig ),
136 policy( aPolicy )
137 {
138 origHead->ClearLinks();
139 };
140
141 HEAD_LINE_ENTRY( VIA_HANDLE aVia, int aPolicy = SHP_DEFAULT ) :
142 theVia( aVia ),
143 policy( aPolicy )
144 {};
145
147 {
148 *this = aOther;
149 }
150
151 // Copy operator
152 HEAD_LINE_ENTRY& operator=( const HEAD_LINE_ENTRY& aOther ) noexcept
153 {
154 geometryModified = aOther.geometryModified;
155 prevVia = aOther.prevVia;
156 theVia = aOther.theVia;
157 draggedVia = aOther.draggedVia;
158 viaNewPos = aOther.viaNewPos;
159 origHead = aOther.origHead;
160 newHead = aOther.newHead;
161 policy = aOther.policy;
162 return *this;
163 }
164
165 // Move assignment operator
167 {
168 if (this != &aOther)
169 {
170 geometryModified = aOther.geometryModified;
171 prevVia = aOther.prevVia;
172 theVia = aOther.theVia;
173 draggedVia = aOther.draggedVia;
174 viaNewPos = aOther.viaNewPos;
175 origHead = std::move( aOther.origHead );
176 newHead = std::move( aOther.newHead );
177 policy = aOther.policy;
178 }
179
180 return *this;
181 }
182
183 bool geometryModified = false;
184 std::optional<VIA_HANDLE> prevVia;
185 std::optional<VIA_HANDLE> theVia;
186 VIA* draggedVia = nullptr;
188 std::optional<LINE> origHead;
189 std::optional<LINE> newHead;
191 };
192
194 {
196 m_length( 0 ),
197 m_node( nullptr ),
198 m_seq( 0 ),
199 m_locked( false )
200 {}
201
202 int64_t m_length;
203 std::vector<VIA_HANDLE> m_draggedVias;
207 int m_seq;
209 };
210
211 bool pruneLineFromOptimizerQueue( const LINE& aLine );
212
213 bool shoveLineToHullSet( const LINE& aCurLine, const LINE& aObstacleLine, LINE& aResultLine,
214 const HULL_SET& aHulls, bool aPermitAdjustingStart = false,
215 bool aPermitAdjustingEnd = false );
216
217 NODE* reduceSpringback( const ITEM_SET& aHeadSet );
218
219 bool patchTadpoleVia( ITEM* nearest, LINE& current );
220
221 bool pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea );
222
223 bool shoveLineFromLoneVia( const LINE& aCurLine, const LINE& aObstacleLine,
224 LINE& aResultLine );
225 bool checkShoveDirection( const LINE& aCurLine, const LINE& aObstacleLine,
226 const LINE& aShovedLine ) const;
227
228 SHOVE_STATUS onCollidingArc( LINE& aCurrent, ARC* aObstacleArc );
229 SHOVE_STATUS onCollidingLine( LINE& aCurrent, LINE& aObstacle, int aNextRank );
230 SHOVE_STATUS onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacleSeg );
231 SHOVE_STATUS onCollidingSolid( LINE& aCurrent, ITEM* aObstacle, OBSTACLE& aObstacleInfo );
232 SHOVE_STATUS onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia, OBSTACLE& aObstacleInfo, int aNextRank );
233 SHOVE_STATUS onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia, OBSTACLE& aObstacleInfo );
234 SHOVE_STATUS pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, int aNextRank, bool aDontUnwindStack = false );
235
237
238 void unwindLineStack( const LINKED_ITEM* aSeg );
239 void unwindLineStack( const ITEM* aItem );
240
241 void runOptimizer( NODE* aNode );
242
243 bool pushLineStack( const LINE& aL, bool aKeepCurrentOnTop = false );
244 void popLineStack();
245
246 LINE assembleLine( const LINKED_ITEM* aSeg, int* aIndex = nullptr, bool aPreCleanup = false );
247
248 void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
249 ROOT_LINE_ENTRY* replaceLine( LINE& aOld, LINE& aNew,
250 bool aIncludeInChangedArea = true,
251 bool aAllowRedundantSegments = true,
252 NODE *aNode = nullptr );
253
254 ROOT_LINE_ENTRY* findRootLine( const LINE& aLine ) const;
255 ROOT_LINE_ENTRY* findRootLine( const LINKED_ITEM *aItem ) const;
256 ROOT_LINE_ENTRY* touchRootLine( const LINE& aLine );
258 void pruneRootLines( NODE *aRemovedNode );
259
260
261 SHOVE_STATUS shoveIteration( int aIter );
263
264 int getClearance( const ITEM* aA, const ITEM* aB ) const;
265 bool fixupViaCollisions( const LINE* aCurrent, OBSTACLE& obs );
266 void sanityCheck( LINE* aOld, LINE* aNew );
267 void reconstructHeads( bool aShoveFailed );
268 void removeHeads();
269 bool preShoveCleanup( LINE* aOld, LINE* aNew );
270 const wxString formatPolicy( int aPolicy );
271
272 std::vector<SPRINGBACK_TAG> m_nodeStack;
273 std::vector<LINE> m_lineStack;
274 std::vector<LINE> m_optimizerQueue;
275 std::deque<HEAD_LINE_ENTRY> m_headLines;
276
277 std::unordered_map<LINKED_ITEM::UNIQ_ID, ROOT_LINE_ENTRY*> m_rootLineHistory;
278
288
290
293
294};
295
296}
297
298#endif // __PNS_SHOVE_H
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:926
ALGO_BASE(ROUTER *aRouter)
Base class for PNS router board items.
Definition pns_item.h:98
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:240
void SetSpringbackDoNotTouchNode(const NODE *aNode)
SHOVE_STATUS shoveIteration(int aIter)
SHOVE_STATUS shoveMainLoop()
std::vector< SHAPE_LINE_CHAIN > HULL_SET
Definition pns_shove.h:112
void reconstructHeads(bool aShoveFailed)
std::pair< LINE, LINE > LINE_PAIR
Definition pns_shove.h:114
SHOVE_STATUS pushOrShoveVia(VIA *aVia, const VECTOR2I &aForce, int aNextRank, bool aDontUnwindStack=false)
SHOVE_STATUS onReverseCollidingVia(LINE &aCurrent, VIA *aObstacleVia, OBSTACLE &aObstacleInfo)
OPT_BOX2I m_affectedArea
Definition pns_shove.h:292
std::vector< LINE > m_lineStack
Definition pns_shove.h:273
void popLineStack()
std::vector< SPRINGBACK_TAG > m_nodeStack
Definition pns_shove.h:272
@ SHP_DONT_OPTIMIZE
Definition pns_shove.h:65
@ SHP_WALK_BACK
Definition pns_shove.h:63
@ SHP_DONT_LOCK_ENDPOINTS
Definition pns_shove.h:66
@ SHP_WALK_FORWARD
Definition pns_shove.h:62
bool patchTadpoleVia(ITEM *nearest, LINE &current)
SHOVE_STATUS onCollidingArc(LINE &aCurrent, ARC *aObstacleArc)
bool shoveLineToHullSet(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine, const HULL_SET &aHulls, bool aPermitAdjustingStart=false, bool aPermitAdjustingEnd=false)
std::optional< LINE > OPT_LINE
Definition pns_shove.h:113
NODE * m_currentNode
Definition pns_shove.h:280
SHOVE_STATUS Run()
LINE assembleLine(const LINKED_ITEM *aSeg, int *aIndex=nullptr, bool aPreCleanup=false)
void ForceClearance(bool aEnabled, int aClearance)
Definition pns_shove.h:90
bool checkShoveDirection(const LINE &aCurLine, const LINE &aObstacleLine, const LINE &aShovedLine) const
int m_forceClearance
Definition pns_shove.h:286
SHOVE_STATUS onCollidingSegment(LINE &aCurrent, SEGMENT *aObstacleSeg)
SHOVE(NODE *aWorld, ROUTER *aRouter)
void DisablePostShoveOptimizations(int aMask)
bool RewindSpringbackTo(NODE *aNode)
bool pushLineStack(const LINE &aL, bool aKeepCurrentOnTop=false)
@ SH_INCOMPLETE
Definition pns_shove.h:53
@ SH_HEAD_MODIFIED
Definition pns_shove.h:54
OPT_BOX2I totalAffectedArea() const
bool RewindToLastLockedNode()
SHOVE_STATUS ShoveDraggingVia(const VIA_HANDLE aOldVia, const VECTOR2I &aWhere, VIA_HANDLE &aNewVia)
std::deque< HEAD_LINE_ENTRY > m_headLines
Definition pns_shove.h:275
int m_defaultPolicy
Definition pns_shove.h:291
const wxString formatPolicy(int aPolicy)
bool ShoveObstacleLine(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
SHOVE_STATUS onCollidingVia(ITEM *aCurrent, VIA *aObstacleVia, OBSTACLE &aObstacleInfo, int aNextRank)
void sanityCheck(LINE *aOld, LINE *aNew)
int m_restrictSpringbackTagId
Definition pns_shove.h:282
void runOptimizer(NODE *aNode)
ROOT_LINE_ENTRY * touchRootLine(const LINE &aLine)
const PNS::LINE GetModifiedHead(int aIndex) const
bool HeadsModified(int aIndex=-1) const
void UnlockSpringbackNode(NODE *aNode)
NODE * m_root
Definition pns_shove.h:279
NODE * reduceSpringback(const ITEM_SET &aHeadSet)
bool AddLockedSpringbackNode(NODE *aNode)
ROOT_LINE_ENTRY * findRootLine(const LINE &aLine) const
void SetDefaultShovePolicy(int aPolicy)
void AddHeads(const LINE &aHead, int aPolicy=SHP_DEFAULT)
void SetShovePolicy(const LINKED_ITEM *aItem, int aPolicy)
void unwindLineStack(const LINKED_ITEM *aSeg)
bool preShoveCleanup(LINE *aOld, LINE *aNew)
NODE * CurrentNode()
int getClearance(const ITEM *aA, const ITEM *aB) const
bool m_multiLineMode
Definition pns_shove.h:287
std::vector< LINE > m_optimizerQueue
Definition pns_shove.h:274
SHOVE_STATUS onCollidingSolid(LINE &aCurrent, ITEM *aObstacle, OBSTACLE &aObstacleInfo)
bool pushSpringback(NODE *aNode, const OPT_BOX2I &aAffectedArea)
int m_optFlagDisableMask
Definition pns_shove.h:289
SHOVE_STATUS onCollidingLine(LINE &aCurrent, LINE &aObstacle, int aNextRank)
bool fixupViaCollisions(const LINE *aCurrent, OBSTACLE &obs)
bool pruneLineFromOptimizerQueue(const LINE &aLine)
void replaceItems(ITEM *aOld, std::unique_ptr< ITEM > aNew)
Definition pns_shove.cpp:52
bool shoveLineFromLoneVia(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
VIA * m_draggedVia
Definition pns_shove.h:283
bool m_headsModified
Definition pns_shove.h:285
const NODE * m_springbackDoNotTouchNode
Definition pns_shove.h:281
void ClearHeads()
std::unordered_map< LINKED_ITEM::UNIQ_ID, ROOT_LINE_ENTRY * > m_rootLineHistory
Definition pns_shove.h:277
void pruneRootLines(NODE *aRemovedNode)
const VIA_HANDLE GetModifiedHeadVia(int aIndex) const
ROOT_LINE_ENTRY * replaceLine(LINE &aOld, LINE &aNew, bool aIncludeInChangedArea=true, bool aAllowRedundantSegments=true, NODE *aNode=nullptr)
Definition pns_shove.cpp:83
std::vector< LINE_PAIR > LINE_PAIR_VEC
Definition pns_shove.h:115
void removeHeads()
Push and Shove diff pair dimensions (gap) settings dialog.
@ SHP_DEFAULT
Hold an object colliding with another object, along with some useful data about the collision.
Definition pns_node.h:88
HEAD_LINE_ENTRY & operator=(const HEAD_LINE_ENTRY &aOther) noexcept
Definition pns_shove.h:152
std::optional< VIA_HANDLE > theVia
Definition pns_shove.h:185
HEAD_LINE_ENTRY(const HEAD_LINE_ENTRY &aOther)
Definition pns_shove.h:146
HEAD_LINE_ENTRY(const LINE &aOrig, int aPolicy=SHP_DEFAULT)
Definition pns_shove.h:134
int policy
Definition pns_shove.h:190
HEAD_LINE_ENTRY & operator=(HEAD_LINE_ENTRY &&aOther) noexcept
Definition pns_shove.h:166
VIA * draggedVia
Definition pns_shove.h:186
std::optional< VIA_HANDLE > prevVia
Definition pns_shove.h:184
bool geometryModified
Definition pns_shove.h:183
std::optional< LINE > newHead
Definition pns_shove.h:189
HEAD_LINE_ENTRY(VIA_HANDLE aVia, int aPolicy=SHP_DEFAULT)
Definition pns_shove.h:141
std::optional< LINE > origHead
Definition pns_shove.h:188
VECTOR2I viaNewPos
Definition pns_shove.h:187
Definition pns_shove.h:118
int policy
Definition pns_shove.h:128
bool isHead
Definition pns_shove.h:129
std::optional< LINE > newLine
Definition pns_shove.h:127
VIA * oldVia
Definition pns_shove.h:125
VIA * newVia
Definition pns_shove.h:126
ROOT_LINE_ENTRY(LINE *aLine=nullptr, int aPolicy=SHP_DEFAULT)
Definition pns_shove.h:119
LINE * rootLine
Definition pns_shove.h:124
std::vector< VIA_HANDLE > m_draggedVias
Definition pns_shove.h:203
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695