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