Horizon
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 }
57
58 ~WALKAROUND() {};
59
60 enum WALKAROUND_STATUS
61 {
62 IN_PROGRESS = 0,
63 DONE,
64 STUCK
65 };
66
67 void SetWorld( NODE* aNode )
68 {
69 m_world = aNode;
70 }
71
72 void SetIterationLimit( const int aIterLimit )
73 {
74 m_iterationLimit = aIterLimit;
75 }
76
77 void SetSolidsOnly( bool aSolidsOnly )
78 {
79 if( aSolidsOnly )
80 m_itemMask = ITEM::SOLID_T;
81 else
82 m_itemMask = ITEM::ANY_T;
83 }
84
85 void SetItemMask( int aMask )
86 {
87 m_itemMask = aMask;
88 }
89
90 void SetSingleDirection( bool aForceSingleDirection )
91 {
92 m_forceSingleDirection = aForceSingleDirection;
93 m_forceLongerPath = aForceSingleDirection;
94 }
95
96 void SetSingleDirection2( bool aForceSingleDirection )
97 {
98 m_forceSingleDirection = aForceSingleDirection;
99 }
100
101 void SetApproachCursor( bool aEnabled, const VECTOR2I& aPos )
102 {
103 m_cursorPos = aPos;
104 m_cursorApproachMode = aEnabled;
105 }
106
107 void SetForceWinding ( bool aEnabled, bool aCw )
108 {
109 m_forceCw = aCw;
110 m_forceWinding = aEnabled;
111 }
112
113 void RestrictToSet( bool aEnabled, const std::set<ITEM*>& aSet )
114 {
115 if( aEnabled )
116 m_restrictedSet = aSet;
117 else
118 m_restrictedSet.clear();
119 }
120
121 WALKAROUND_STATUS Route( const LINE& aInitialPath, LINE& aWalkPath,
122 bool aOptimize = true );
123
124 virtual LOGGER* Logger() override
125 {
126 return &m_logger;
127 }
128
129private:
130 void start( const LINE& aInitialPath );
131
132 WALKAROUND_STATUS singleStep( LINE& aPath, bool aWindingDirection );
133 NODE::OPT_OBSTACLE nearestObstacle( const LINE& aPath );
134
135 NODE* m_world;
136
137 int m_recursiveBlockageCount;
138 int m_iteration;
139 int m_iterationLimit;
140 int m_itemMask;
141 bool m_forceSingleDirection, m_forceLongerPath;
142 bool m_cursorApproachMode;
143 bool m_forceWinding;
144 bool m_forceCw;
145 VECTOR2I m_cursorPos;
146 NODE::OPT_OBSTACLE m_currentObstacle[2];
147 bool m_recursiveCollision[2];
148 LOGGER m_logger;
149 std::set<ITEM*> m_restrictedSet;
150};
151
152}
153
154#endif // __PNS_WALKAROUND_H
Class ALGO_BASE.
Definition: pns_algo_base.h:40
Definition: pns_line.h:61
Definition: pns_logger.h:40
Class NODE.
Definition: pns_node.h:138
Definition: pns_router.h:113
Definition: pns_walkaround.h:36
virtual LOGGER * Logger() override
‍Returns the logger object, allowing to dump geometry to a file.
Definition: pns_walkaround.h:124