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 "pns_optimizer.h"
29 #include "pns_routing_settings.h"
30 #include "pns_algo_base.h"
31 #include "pns_logger.h"
32 #include "range.h"
33 
34 namespace PNS {
35 
36 class LINE;
37 class NODE;
38 class ROUTER;
39 
46 class SHOVE : public ALGO_BASE
47 {
48 public:
49 
51  {
52  SH_OK = 0,
57  };
58 
59  SHOVE( NODE* aWorld, ROUTER* aRouter );
60  ~SHOVE();
61 
62  virtual LOGGER* Logger() override
63  {
64  return &m_logger;
65  }
66 
67  SHOVE_STATUS ShoveLines( const LINE& aCurrentHead );
68  SHOVE_STATUS ShoveMultiLines( const ITEM_SET& aHeadSet );
69 
70  SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere, VIA_HANDLE& aNewVia );
71  SHOVE_STATUS ProcessSingleLine( LINE& aCurrent, LINE& aObstacle, LINE& aShoved );
72 
73  void ForceClearance ( bool aEnabled, int aClearance )
74  {
75  if( aEnabled )
76  m_forceClearance = aClearance;
77  else
78  m_forceClearance = -1;
79  }
80 
81  NODE* CurrentNode();
82 
83  const LINE NewHead() const;
84 
85  void SetInitialLine( LINE& aInitial );
86 
87 private:
88  typedef std::vector<SHAPE_LINE_CHAIN> HULL_SET;
90  typedef std::pair<LINE, LINE> LINE_PAIR;
91  typedef std::vector<LINE_PAIR> LINE_PAIR_VEC;
92 
94  {
95  int64_t m_length;
100  };
101 
102  SHOVE_STATUS processHullSet( LINE& aCurrent, LINE& aObstacle,
103  LINE& aShoved, const HULL_SET& hulls );
104 
105  NODE* reduceSpringback( const ITEM_SET& aHeadSet, VIA_HANDLE& aDraggedVia );
106 
107  bool pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea, VIA* aDraggedVia );
108 
109  SHOVE_STATUS walkaroundLoneVia( LINE& aCurrent, LINE& aObstacle, LINE& aShoved );
110  bool checkBumpDirection( const LINE& aCurrent, const LINE& aShoved ) const;
111 
112  SHOVE_STATUS onCollidingLine( LINE& aCurrent, LINE& aObstacle );
113  SHOVE_STATUS onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacleSeg );
114  SHOVE_STATUS onCollidingSolid( LINE& aCurrent, ITEM* aObstacle );
115  SHOVE_STATUS onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia );
116  SHOVE_STATUS onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia );
117  SHOVE_STATUS pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, int aCurrentRank );
118 
120 
121  void unwindLineStack( SEGMENT* aSeg );
122  void unwindLineStack( ITEM* aItem );
123 
124  void runOptimizer( NODE* aNode );
125 
126  bool pushLineStack( const LINE& aL, bool aKeepCurrentOnTop = false );
127  void popLineStack();
128 
129  LINE assembleLine( const SEGMENT* aSeg, int* aIndex = NULL );
130 
131  void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
132  void replaceLine( LINE& aOld, LINE& aNew );
133 
135 
136  SHOVE_STATUS shoveIteration( int aIter );
138 
139  int getClearance( const ITEM* aA, const ITEM* aB ) const;
140 
141  std::vector<SPRINGBACK_TAG> m_nodeStack;
142  std::vector<LINE> m_lineStack;
143  std::vector<LINE> m_optimizerQueue;
144 
147 
149 
152 
153  int m_iter;
156  void sanityCheck( LINE* aOld, LINE* aNew );
157 };
158 
159 }
160 
161 #endif // __PNS_SHOVE_H
bool pushLineStack(const LINE &aL, bool aKeepCurrentOnTop=false)
Definition: pns_shove.cpp:940
Class ITEM.
Definition: pns_item.h:53
void popLineStack()
Definition: pns_shove.cpp:959
Class NODE.
Definition: pns_node.h:140
SHOVE_STATUS onCollidingSolid(LINE &aCurrent, ITEM *aObstacle)
Definition: pns_shove.cpp:425
LINE assembleLine(const SEGMENT *aSeg, int *aIndex=NULL)
Definition: pns_shove.cpp:100
OPT< LINE > OPT_LINE
Definition: pns_shove.h:89
Class SHOVE.
Definition: pns_shove.h:46
const LINE NewHead() const
Definition: pns_shove.cpp:1508
Class ALGO_BASE.
Definition: pns_algo_base.h:39
SHOVE_STATUS ProcessSingleLine(LINE &aCurrent, LINE &aObstacle, LINE &aShoved)
Definition: pns_shove.cpp:263
std::vector< LINE > m_optimizerQueue
Definition: pns_shove.h:143
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
SHOVE_STATUS processHullSet(LINE &aCurrent, LINE &aObstacle, LINE &aShoved, const HULL_SET &hulls)
Definition: pns_shove.cpp:160
NODE * m_root
Definition: pns_shove.h:145
std::pair< LINE, LINE > LINE_PAIR
Definition: pns_shove.h:90
SHOVE_STATUS pushOrShoveVia(VIA *aVia, const VECTOR2I &aForce, int aCurrentRank)
Definition: pns_shove.cpp:620
std::vector< LINE_PAIR > LINE_PAIR_VEC
Definition: pns_shove.h:91
SHOVE_STATUS onCollidingLine(LINE &aCurrent, LINE &aObstacle)
Definition: pns_shove.cpp:382
SHOVE_STATUS onReverseCollidingVia(LINE &aCurrent, VIA *aObstacleVia)
Definition: pns_shove.cpp:823
std::vector< SHAPE_LINE_CHAIN > HULL_SET
Definition: pns_shove.h:88
OPT_BOX2I totalAffectedArea() const
Definition: pns_shove.cpp:1137
NODE * reduceSpringback(const ITEM_SET &aHeadSet, VIA_HANDLE &aDraggedVia)
Definition: pns_shove.cpp:558
SHOVE_STATUS ShoveLines(const LINE &aCurrentHead)
Definition: pns_shove.cpp:1153
SHOVE_STATUS onCollidingVia(ITEM *aCurrent, VIA *aObstacleVia)
Definition: pns_shove.cpp:746
void runOptimizer(NODE *aNode)
Definition: pns_shove.cpp:1431
void sanityCheck(LINE *aOld, LINE *aNew)
Definition: pns_shove.cpp:73
SHOVE_STATUS shoveIteration(int aIter)
Definition: pns_shove.cpp:988
SHOVE(NODE *aWorld, ROUTER *aRouter)
Definition: pns_shove.cpp:80
bool pushSpringback(NODE *aNode, const OPT_BOX2I &aAffectedArea, VIA *aDraggedVia)
Definition: pns_shove.cpp:586
SHOVE_STATUS onCollidingSegment(LINE &aCurrent, SEGMENT *aObstacleSeg)
Definition: pns_shove.cpp:321
void unwindLineStack(SEGMENT *aSeg)
Definition: pns_shove.cpp:906
SHOVE_STATUS ShoveDraggingVia(const VIA_HANDLE aOldVia, const VECTOR2I &aWhere, VIA_HANDLE &aNewVia)
Definition: pns_shove.cpp:1359
bool checkBumpDirection(const LINE &aCurrent, const LINE &aShoved) const
Definition: pns_shove.cpp:109
std::vector< SPRINGBACK_TAG > m_nodeStack
Definition: pns_shove.h:141
VIA * m_draggedVia
Definition: pns_shove.h:151
OPT_BOX2I m_affectedArea
Definition: pns_shove.h:134
void ForceClearance(bool aEnabled, int aClearance)
Definition: pns_shove.h:73
virtual LOGGER * Logger() override
Returns the logger object, allowing to dump geometry to a file.
Definition: pns_shove.h:62
void replaceLine(LINE &aOld, LINE &aNew)
Definition: pns_shove.cpp:54
SHOVE_STATUS shoveMainLoop()
Definition: pns_shove.cpp:1097
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:523
void SetInitialLine(LINE &aInitial)
Definition: pns_shove.cpp:1516
boost::optional< T > OPT
Definition: optional.h:7
int getClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_shove.cpp:64
void replaceItems(ITEM *aOld, std::unique_ptr< ITEM > aNew)
Definition: pns_shove.cpp:44
bool m_multiLineMode
Definition: pns_shove.h:155
OPT_LINE m_newHead
Definition: pns_shove.h:148
std::vector< LINE > m_lineStack
Definition: pns_shove.h:142
SHOVE_STATUS ShoveMultiLines(const ITEM_SET &aHeadSet)
Definition: pns_shove.cpp:1258
NODE * m_currentNode
Definition: pns_shove.h:146
Push and Shove diff pair dimensions (gap) settings dialog.
SHOVE_STATUS walkaroundLoneVia(LINE &aCurrent, LINE &aObstacle, LINE &aShoved)
Definition: pns_shove.cpp:124
LOGGER m_logger
Definition: pns_shove.h:150
int m_iter
Definition: pns_shove.h:153
NODE * CurrentNode()
Definition: pns_shove.cpp:1502
int m_forceClearance
Definition: pns_shove.h:154