Horizon
Loading...
Searching...
No Matches
pns_walkaround.h
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_WALKAROUND_H
23#define __PNS_WALKAROUND_H
24
25#include <set>
26
27#include "pns_line.h"
28#include "pns_node.h"
29#include "pns_router.h"
30#include "pns_logger.h"
31#include "pns_algo_base.h"
32
33namespace PNS {
34
35class WALKAROUND : public ALGO_BASE
36{
37 static const int DefaultIterationLimit = 50;
38
39public:
40 WALKAROUND( NODE* aWorld, ROUTER* aRouter ) :
41 ALGO_BASE ( aRouter ),
42 m_world( aWorld ),
43 m_iterationLimit( DefaultIterationLimit )
44 {
45 m_forceSingleDirection = false;
46 m_forceLongerPath = false;
47 m_forceWinding = false;
48 m_cursorApproachMode = false;
49 m_itemMask = ITEM::ANY_T;
50
51 // Initialize other members, to avoid uninitialized variables.
52 m_recursiveBlockageCount = 0;
53 m_recursiveCollision[0] = m_recursiveCollision[1] = false;
54 m_iteration = 0;
55 m_forceCw = false;
56 m_forceUniqueWindingDirection = false;
57 }
58
59 ~WALKAROUND() {};
60
61 enum WALKAROUND_STATUS
62 {
63 IN_PROGRESS = 0,
64 ALMOST_DONE,
65 DONE,
66 STUCK
67 };
68
69 struct RESULT
70 {
71 RESULT( WALKAROUND_STATUS aStatusCw = STUCK, WALKAROUND_STATUS aStatusCcw = STUCK, const LINE& aLineCw = LINE(), const LINE& aLineCcw = LINE() )
72 {
73 statusCw = aStatusCw;
74 statusCcw = aStatusCcw;
75 lineCw = aLineCw;
76 lineCcw = aLineCcw;
77 }
78
79 WALKAROUND_STATUS statusCw, statusCcw;
80 LINE lineCw, lineCcw;
81 };
82
83 void SetWorld( NODE* aNode )
84 {
85 m_world = aNode;
86 }
87
88 void SetIterationLimit( const int aIterLimit )
89 {
90 m_iterationLimit = aIterLimit;
91 }
92
93 void SetSolidsOnly( bool aSolidsOnly )
94 {
95 if( aSolidsOnly )
96 m_itemMask = ITEM::SOLID_T;
97 else
98 m_itemMask = ITEM::ANY_T;
99 }
100
101 void SetItemMask( int aMask )
102 {
103 m_itemMask = aMask;
104 }
105
106 void SetSingleDirection( bool aForceSingleDirection )
107 {
108 m_forceSingleDirection = aForceSingleDirection;
109 m_forceLongerPath = aForceSingleDirection;
110 }
111
112 void SetSingleDirection2( bool aForceSingleDirection )
113 {
114 m_forceSingleDirection = aForceSingleDirection;
115 }
116
117 void SetApproachCursor( bool aEnabled, const VECTOR2I& aPos )
118 {
119 m_cursorPos = aPos;
120 m_cursorApproachMode = aEnabled;
121 }
122
123 void SetForceWinding ( bool aEnabled, bool aCw )
124 {
125 m_forceCw = aCw;
126 m_forceWinding = aEnabled;
127 }
128
129 void RestrictToSet( bool aEnabled, const std::set<ITEM*>& aSet )
130 {
131 if( aEnabled )
132 m_restrictedSet = aSet;
133 else
134 m_restrictedSet.clear();
135 }
136
137 WALKAROUND_STATUS Route( const LINE& aInitialPath, LINE& aWalkPath,
138 bool aOptimize = true );
139
140 const RESULT Route( const LINE& aInitialPath );
141
142private:
143 void start( const LINE& aInitialPath );
144
145 WALKAROUND_STATUS singleStep( LINE& aPath, bool aWindingDirection );
146 NODE::OPT_OBSTACLE nearestObstacle( const LINE& aPath );
147
148 NODE* m_world;
149
150 int m_recursiveBlockageCount;
151 int m_iteration;
152 int m_iterationLimit;
153 int m_itemMask;
154 bool m_forceSingleDirection, m_forceLongerPath;
155 bool m_cursorApproachMode;
156 bool m_forceWinding;
157 bool m_forceCw;
158 bool m_forceUniqueWindingDirection;
159 VECTOR2I m_cursorPos;
160 NODE::OPT_OBSTACLE m_currentObstacle[2];
161 bool m_recursiveCollision[2];
162 std::set<ITEM*> m_restrictedSet;
163};
164
165}
166
167#endif // __PNS_WALKAROUND_H
Base class for all P&S algorithms (shoving, walkaround, line placement, dragging, etc....
Definition pns_algo_base.h:43
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:148
Definition pns_router.h:116
Definition pns_walkaround.h:36
Definition pns_walkaround.h:70