KiCad PCB EDA Suite
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 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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"
31 #include "pns_routing_settings.h"
32 #include "pns_algo_base.h"
33 #include "pns_logger.h"
34 #include "range.h"
35 
36 namespace PNS {
37 
38 class LINE;
39 class NODE;
40 class ROUTER;
41 
48 class SHOVE : public ALGO_BASE
49 {
50 public:
51 
53  {
54  SH_OK = 0,
59  };
60 
61  SHOVE( NODE* aWorld, ROUTER* aRouter );
62  ~SHOVE();
63 
64  virtual LOGGER* Logger() override
65  {
66  return &m_logger;
67  }
68 
69  SHOVE_STATUS ShoveLines( const LINE& aCurrentHead );
70  SHOVE_STATUS ShoveMultiLines( const ITEM_SET& aHeadSet );
71 
72  SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere, VIA_HANDLE& aNewVia );
73  SHOVE_STATUS ProcessSingleLine( LINE& aCurrent, LINE& aObstacle, LINE& aShoved );
74 
75  void ForceClearance ( bool aEnabled, int aClearance )
76  {
77  if( aEnabled )
78  m_forceClearance = aClearance;
79  else
80  m_forceClearance = -1;
81  }
82 
83  NODE* CurrentNode();
84 
85  const LINE NewHead() const;
86 
87  void SetInitialLine( LINE& aInitial );
88 
89  bool AddLockedSpringbackNode( NODE* aNode );
90  void UnlockSpringbackNode( NODE* aNode );
91  bool RewindSpringbackTo( NODE* aNode );
92 
93 private:
94  typedef std::vector<SHAPE_LINE_CHAIN> HULL_SET;
96  typedef std::pair<LINE, LINE> LINE_PAIR;
97  typedef std::vector<LINE_PAIR> LINE_PAIR_VEC;
98 
100  {
102  m_length( 0 ),
103  m_node( nullptr ),
104  m_seq( 0 ),
105  m_locked( false )
106  {}
107 
108  int64_t m_length;
113  int m_seq;
114  bool m_locked;
115  };
116 
117  SHOVE_STATUS processHullSet( LINE& aCurrent, LINE& aObstacle,
118  LINE& aShoved, const HULL_SET& hulls );
119 
120  NODE* reduceSpringback( const ITEM_SET& aHeadSet, VIA_HANDLE& aDraggedVia );
121 
122  bool pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea, VIA* aDraggedVia );
123 
124  SHOVE_STATUS walkaroundLoneVia( LINE& aCurrent, LINE& aObstacle, LINE& aShoved );
125  bool checkBumpDirection( const LINE& aCurrent, const LINE& aObstacle, const LINE& aShoved ) 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 );
131  SHOVE_STATUS onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia );
132  SHOVE_STATUS onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia );
133  SHOVE_STATUS pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, int aCurrentRank );
134 
136 
137  void unwindLineStack( LINKED_ITEM* aSeg );
138  void unwindLineStack( 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 = NULL );
146 
147  void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
148  void replaceLine( LINE& aOld, LINE& aNew );
149 
151 
152  SHOVE_STATUS shoveIteration( int aIter );
154 
155  int getClearance( const ITEM* aA, const ITEM* aB ) const;
156 
157  std::vector<SPRINGBACK_TAG> m_nodeStack;
158  std::vector<LINE> m_lineStack;
159  std::vector<LINE> m_optimizerQueue;
160 
164 
166 
169 
170  int m_iter;
173  void sanityCheck( LINE* aOld, LINE* aNew );
174 };
175 
176 }
177 
178 #endif // __PNS_SHOVE_H
bool pushLineStack(const LINE &aL, bool aKeepCurrentOnTop=false)
Definition: pns_shove.cpp:1007
ITEM.
Definition: pns_item.h:53
LINE assembleLine(const LINKED_ITEM *aSeg, int *aIndex=NULL)
Definition: pns_shove.cpp:103
void popLineStack()
Definition: pns_shove.cpp:1026
int m_restrictSpringbackTagId
Definition: pns_shove.h:163
NODE.
Definition: pns_node.h:145
SHOVE_STATUS onCollidingSolid(LINE &aCurrent, ITEM *aObstacle)
Definition: pns_shove.cpp:490
void unwindLineStack(LINKED_ITEM *aSeg)
Definition: pns_shove.cpp:973
OPT< LINE > OPT_LINE
Definition: pns_shove.h:95
SHOVE.
Definition: pns_shove.h:48
const LINE NewHead() const
Definition: pns_shove.cpp:1600
SHOVE_STATUS onCollidingArc(LINE &aCurrent, ARC *aObstacleArc)
Definition: pns_shove.cpp:386
ALGO_BASE.
Definition: pns_algo_base.h:39
SHOVE_STATUS ProcessSingleLine(LINE &aCurrent, LINE &aObstacle, LINE &aShoved)
Definition: pns_shove.cpp:267
std::vector< LINE > m_optimizerQueue
Definition: pns_shove.h:159
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
bool RewindSpringbackTo(NODE *aNode)
Definition: pns_shove.cpp:1626
SHOVE_STATUS processHullSet(LINE &aCurrent, LINE &aObstacle, LINE &aShoved, const HULL_SET &hulls)
Definition: pns_shove.cpp:164
bool checkBumpDirection(const LINE &aCurrent, const LINE &aObstacle, const LINE &aShoved) const
Definition: pns_shove.cpp:116
NODE * m_root
Definition: pns_shove.h:161
std::pair< LINE, LINE > LINE_PAIR
Definition: pns_shove.h:96
SHOVE_STATUS pushOrShoveVia(VIA *aVia, const VECTOR2I &aForce, int aCurrentRank)
Definition: pns_shove.cpp:688
std::vector< LINE_PAIR > LINE_PAIR_VEC
Definition: pns_shove.h:97
SHOVE_STATUS onCollidingLine(LINE &aCurrent, LINE &aObstacle)
Definition: pns_shove.cpp:447
SHOVE_STATUS onReverseCollidingVia(LINE &aCurrent, VIA *aObstacleVia)
Definition: pns_shove.cpp:890
std::vector< SHAPE_LINE_CHAIN > HULL_SET
Definition: pns_shove.h:94
OPT_BOX2I totalAffectedArea() const
Definition: pns_shove.cpp:1229
NODE * reduceSpringback(const ITEM_SET &aHeadSet, VIA_HANDLE &aDraggedVia)
Definition: pns_shove.cpp:623
SHOVE_STATUS ShoveLines(const LINE &aCurrentHead)
Definition: pns_shove.cpp:1245
bool AddLockedSpringbackNode(NODE *aNode)
Definition: pns_shove.cpp:1615
#define NULL
SHOVE_STATUS onCollidingVia(ITEM *aCurrent, VIA *aObstacleVia)
Definition: pns_shove.cpp:815
void runOptimizer(NODE *aNode)
Definition: pns_shove.cpp:1523
void sanityCheck(LINE *aOld, LINE *aNew)
Definition: pns_shove.cpp:75
SHOVE_STATUS shoveIteration(int aIter)
Definition: pns_shove.cpp:1055
SHOVE(NODE *aWorld, ROUTER *aRouter)
Definition: pns_shove.cpp:82
bool pushSpringback(NODE *aNode, const OPT_BOX2I &aAffectedArea, VIA *aDraggedVia)
Definition: pns_shove.cpp:651
SHOVE_STATUS onCollidingSegment(LINE &aCurrent, SEGMENT *aObstacleSeg)
Definition: pns_shove.cpp:325
void UnlockSpringbackNode(NODE *aNode)
Definition: pns_shove.cpp:1654
SHOVE_STATUS ShoveDraggingVia(const VIA_HANDLE aOldVia, const VECTOR2I &aWhere, VIA_HANDLE &aNewVia)
Definition: pns_shove.cpp:1451
std::vector< SPRINGBACK_TAG > m_nodeStack
Definition: pns_shove.h:157
VIA * m_draggedVia
Definition: pns_shove.h:168
OPT_BOX2I m_affectedArea
Definition: pns_shove.h:150
void ForceClearance(bool aEnabled, int aClearance)
Definition: pns_shove.h:75
virtual LOGGER * Logger() override
Returns the logger object, allowing to dump geometry to a file.
Definition: pns_shove.h:64
void replaceLine(LINE &aOld, LINE &aNew)
Definition: pns_shove.cpp:56
SHOVE_STATUS shoveMainLoop()
Definition: pns_shove.cpp:1189
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:524
void SetInitialLine(LINE &aInitial)
Definition: pns_shove.cpp:1608
boost::optional< T > OPT
Definition: optional.h:7
int getClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_shove.cpp:66
void replaceItems(ITEM *aOld, std::unique_ptr< ITEM > aNew)
Definition: pns_shove.cpp:46
bool m_multiLineMode
Definition: pns_shove.h:172
OPT_LINE m_newHead
Definition: pns_shove.h:165
std::vector< LINE > m_lineStack
Definition: pns_shove.h:158
SHOVE_STATUS ShoveMultiLines(const ITEM_SET &aHeadSet)
Definition: pns_shove.cpp:1350
NODE * m_currentNode
Definition: pns_shove.h:162
Push and Shove diff pair dimensions (gap) settings dialog.
SHOVE_STATUS walkaroundLoneVia(LINE &aCurrent, LINE &aObstacle, LINE &aShoved)
Definition: pns_shove.cpp:128
LOGGER m_logger
Definition: pns_shove.h:167
int m_iter
Definition: pns_shove.h:170
NODE * CurrentNode()
Definition: pns_shove.cpp:1594
int m_forceClearance
Definition: pns_shove.h:171