KiCad PCB EDA Suite
PNS::WALKAROUND Class Reference

#include <pns_walkaround.h>

Inheritance diagram for PNS::WALKAROUND:
PNS::ALGO_BASE

Public Types

enum  WALKAROUND_STATUS { IN_PROGRESS = 0, DONE, STUCK }
 

Public Member Functions

 WALKAROUND (NODE *aWorld, ROUTER *aRouter)
 
 ~WALKAROUND ()
 
void SetWorld (NODE *aNode)
 
void SetIterationLimit (const int aIterLimit)
 
void SetSolidsOnly (bool aSolidsOnly)
 
void SetItemMask (int aMask)
 
void SetSingleDirection (bool aForceSingleDirection)
 
void SetSingleDirection2 (bool aForceSingleDirection)
 
void SetApproachCursor (bool aEnabled, const VECTOR2I &aPos)
 
void SetForceWinding (bool aEnabled, bool aCw)
 
void RestrictToSet (bool aEnabled, const std::set< ITEM * > &aSet)
 
WALKAROUND_STATUS Route (const LINE &aInitialPath, LINE &aWalkPath, bool aOptimize=true)
 
virtual LOGGERLogger () override
 

Returns the logger object, allowing to dump geometry to a file.

More...
 
ROUTERRouter () const
 

Returns the instance of our router

More...
 
ROUTING_SETTINGSSettings () const
 

Returns current router settings

More...
 
void SetDebugDecorator (DEBUG_DECORATOR *aDecorator)
 Function SetDebugDecorator. More...
 
DEBUG_DECORATORDbg () const
 

Private Member Functions

void start (const LINE &aInitialPath)
 
WALKAROUND_STATUS singleStep (LINE &aPath, bool aWindingDirection)
 
NODE::OPT_OBSTACLE nearestObstacle (const LINE &aPath)
 

Private Attributes

NODEm_world
 
int m_recursiveBlockageCount
 
int m_iteration
 
int m_iterationLimit
 
int m_itemMask
 
bool m_forceSingleDirection
 
bool m_forceLongerPath
 
bool m_cursorApproachMode
 
bool m_forceWinding
 
bool m_forceCw
 
VECTOR2I m_cursorPos
 
NODE::OPT_OBSTACLE m_currentObstacle [2]
 
bool m_recursiveCollision [2]
 
LOGGER m_logger
 
std::set< ITEM * > m_restrictedSet
 

Static Private Attributes

static const int DefaultIterationLimit = 50
 

Detailed Description

Definition at line 35 of file pns_walkaround.h.

Member Enumeration Documentation

Enumerator
IN_PROGRESS 
DONE 
STUCK 

Definition at line 60 of file pns_walkaround.h.

Constructor & Destructor Documentation

PNS::WALKAROUND::WALKAROUND ( NODE aWorld,
ROUTER aRouter 
)
inline

Definition at line 40 of file pns_walkaround.h.

References PNS::ITEM::ANY_T, m_cursorApproachMode, m_forceCw, m_forceLongerPath, m_forceSingleDirection, m_forceWinding, m_itemMask, m_iteration, m_recursiveBlockageCount, and m_recursiveCollision.

40  :
41  ALGO_BASE ( aRouter ),
42  m_world( aWorld ),
44  {
45  m_forceSingleDirection = false;
46  m_forceLongerPath = false;
47  m_forceWinding = false;
48  m_cursorApproachMode = false;
50 
51  // Initialize other members, to avoid uninitialized variables.
54  m_iteration = 0;
55  m_forceCw = false;
56  }
static const int DefaultIterationLimit
ALGO_BASE(ROUTER *aRouter)
Definition: pns_algo_base.h:42
bool m_recursiveCollision[2]
PNS::WALKAROUND::~WALKAROUND ( )
inline

Definition at line 58 of file pns_walkaround.h.

58 {};

Member Function Documentation

virtual LOGGER* PNS::WALKAROUND::Logger ( )
inlineoverridevirtual

Returns the logger object, allowing to dump geometry to a file.

Reimplemented from PNS::ALGO_BASE.

Definition at line 124 of file pns_walkaround.h.

References m_logger.

125  {
126  return &m_logger;
127  }
NODE::OPT_OBSTACLE PNS::WALKAROUND::nearestObstacle ( const LINE aPath)
private

Definition at line 40 of file pns_walkaround.cpp.

References m_itemMask, m_restrictedSet, m_world, and PNS::NODE::NearestObstacle().

Referenced by Route(), and singleStep().

41 {
43 
44  if( m_restrictedSet.empty() )
45  return obs;
46 
47  else if( obs && m_restrictedSet.find ( obs->m_item ) != m_restrictedSet.end() )
48  return obs;
49 
50  return NODE::OPT_OBSTACLE();
51 }
OPT_OBSTACLE NearestObstacle(const LINE *aItem, int aKindMask=ITEM::ANY_T, const std::set< ITEM * > *aRestrictedSet=NULL)
Function NearestObstacle()
Definition: pns_node.cpp:302
std::set< ITEM * > m_restrictedSet
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:140
void PNS::WALKAROUND::RestrictToSet ( bool  aEnabled,
const std::set< ITEM * > &  aSet 
)
inline

Definition at line 113 of file pns_walkaround.h.

References m_restrictedSet.

Referenced by PNS::SHOVE::onCollidingSolid().

114  {
115  if( aEnabled )
116  m_restrictedSet = aSet;
117  else
118  m_restrictedSet.clear();
119  }
std::set< ITEM * > m_restrictedSet
WALKAROUND::WALKAROUND_STATUS PNS::WALKAROUND::Route ( const LINE aInitialPath,
LINE aWalkPath,
bool  aOptimize = true 
)

Definition at line 144 of file pns_walkaround.cpp.

References SEG::A, SHAPE_LINE_CHAIN::Append(), SEG::B, PNS::NODE::CheckColliding(), PNS::LINE::CLine(), PNS::LINE::CPoint(), DONE, PNS::LINE::EndsWithVia(), IN_PROGRESS, SHAPE_LINE_CHAIN::Length(), PNS::LINE::Line(), m_currentObstacle, m_cursorApproachMode, m_cursorPos, m_forceCw, m_forceLongerPath, m_forceSingleDirection, m_forceWinding, m_itemMask, m_iteration, m_iterationLimit, m_recursiveBlockageCount, m_world, PNS::OPTIMIZER::MERGE_OBTUSE, nearestObstacle(), SEG::NearestPoint(), PNS::OPTIMIZER::Optimize(), PNS::LINE::PointCount(), SHAPE_LINE_CHAIN::Remove(), SHAPE_LINE_CHAIN::Segment(), PNS::LINE::SegmentCount(), SHAPE_LINE_CHAIN::SegmentCount(), PNS::LINE::SetShape(), SHAPE_LINE_CHAIN::Simplify(), singleStep(), start(), STUCK, and PNS::LINE::Via().

Referenced by PNS::DIFF_PAIR_PLACER::attemptWalk(), PNS::SHOVE::onCollidingSolid(), PNS::LINE_PLACER::rhShoveOnly(), and PNS::LINE_PLACER::rhWalkOnly().

146 {
147  LINE path_cw( aInitialPath ), path_ccw( aInitialPath );
148  WALKAROUND_STATUS s_cw = IN_PROGRESS, s_ccw = IN_PROGRESS;
149  SHAPE_LINE_CHAIN best_path;
150 
151  // special case for via-in-the-middle-of-track placement
152  if( aInitialPath.PointCount() <= 1 )
153  {
154  if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(), m_itemMask ) )
155  return STUCK;
156 
157  aWalkPath = aInitialPath;
158  return DONE;
159  }
160 
161  start( aInitialPath );
162 
163  m_currentObstacle[0] = m_currentObstacle[1] = nearestObstacle( aInitialPath );
165 
166  aWalkPath = aInitialPath;
167 
168  if( m_forceWinding )
169  {
170  s_cw = m_forceCw ? IN_PROGRESS : STUCK;
171  s_ccw = m_forceCw ? STUCK : IN_PROGRESS;
172  m_forceSingleDirection = true;
173  } else {
174  m_forceSingleDirection = false;
175  }
176 
177  while( m_iteration < m_iterationLimit )
178  {
179  if( s_cw != STUCK )
180  s_cw = singleStep( path_cw, true );
181 
182  if( s_ccw != STUCK )
183  s_ccw = singleStep( path_ccw, false );
184 
185  if( ( s_cw == DONE && s_ccw == DONE ) || ( s_cw == STUCK && s_ccw == STUCK ) )
186  {
187  int len_cw = path_cw.CLine().Length();
188  int len_ccw = path_ccw.CLine().Length();
189 
190  if( m_forceLongerPath )
191  aWalkPath = ( len_cw > len_ccw ? path_cw : path_ccw );
192  else
193  aWalkPath = ( len_cw < len_ccw ? path_cw : path_ccw );
194 
195  break;
196  }
197  else if( s_cw == DONE && !m_forceLongerPath )
198  {
199  aWalkPath = path_cw;
200  break;
201  }
202  else if( s_ccw == DONE && !m_forceLongerPath )
203  {
204  aWalkPath = path_ccw;
205  break;
206  }
207 
208  m_iteration++;
209  }
210 
212  {
213  int len_cw = path_cw.CLine().Length();
214  int len_ccw = path_ccw.CLine().Length();
215 
216  if( m_forceLongerPath )
217  aWalkPath = ( len_cw > len_ccw ? path_cw : path_ccw );
218  else
219  aWalkPath = ( len_cw < len_ccw ? path_cw : path_ccw );
220  }
221 
223  {
224  // int len_cw = path_cw.GetCLine().Length();
225  // int len_ccw = path_ccw.GetCLine().Length();
226  bool found = false;
227 
228  SHAPE_LINE_CHAIN l = aWalkPath.CLine();
229 
230  for( int i = 0; i < l.SegmentCount(); i++ )
231  {
232  const SEG s = l.Segment( i );
233 
234  VECTOR2I nearest = s.NearestPoint( m_cursorPos );
235  VECTOR2I::extended_type dist_a = ( s.A - m_cursorPos ).SquaredEuclideanNorm();
236  VECTOR2I::extended_type dist_b = ( s.B - m_cursorPos ).SquaredEuclideanNorm();
237  VECTOR2I::extended_type dist_n = ( nearest - m_cursorPos ).SquaredEuclideanNorm();
238 
239  if( dist_n <= dist_a && dist_n < dist_b )
240  {
241  l.Remove( i + 1, -1 );
242  l.Append( nearest );
243  l.Simplify();
244  found = true;
245  break;
246  }
247  }
248 
249  if( found )
250  {
251  aWalkPath = aInitialPath;
252  aWalkPath.SetShape( l );
253  }
254  }
255 
256  aWalkPath.Line().Simplify();
257 
258  if( aWalkPath.SegmentCount() < 1 )
259  return STUCK;
260  if( aWalkPath.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
261  return STUCK;
262  if( aWalkPath.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
263  return STUCK;
264 
265  WALKAROUND_STATUS st = s_ccw == DONE || s_cw == DONE ? DONE : STUCK;
266 
267  if( st == DONE )
268  {
269  if( aOptimize )
271  }
272 
273  return st;
274 }
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
VECTOR2I m_cursorPos
WALKAROUND_STATUS singleStep(LINE &aPath, bool aWindingDirection)
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
NODE::OPT_OBSTACLE m_currentObstacle[2]
void start(const LINE &aInitialPath)
void Remove(int aStartIndex, int aEndIndex)
Function Remove()
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:364
Definition: seg.h:36
SEG Segment(int aIndex)
Function Segment()
NODE::OPT_OBSTACLE nearestObstacle(const LINE &aPath)
Class SHAPE_LINE_CHAIN.
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:425
VECTOR2I A
Definition: seg.h:46
static bool Optimize(LINE *aLine, int aEffortLevel, NODE *aWorld)
a quick shortcut to optmize a line without creating and setting up an optimizer
int SegmentCount() const
Function SegmentCount()
VECTOR2I B
Definition: seg.h:47
void PNS::WALKAROUND::SetApproachCursor ( bool  aEnabled,
const VECTOR2I aPos 
)
inline

Definition at line 101 of file pns_walkaround.h.

References m_cursorApproachMode, and m_cursorPos.

Referenced by PNS::LINE_PLACER::rhShoveOnly().

102  {
103  m_cursorPos = aPos;
104  m_cursorApproachMode = aEnabled;
105  }
VECTOR2I m_cursorPos
void PNS::ALGO_BASE::SetDebugDecorator ( DEBUG_DECORATOR aDecorator)
inlineinherited

Function SetDebugDecorator.

Assign a debug decorator allowing this algo to draw extra graphics for visual debugging

Definition at line 65 of file pns_algo_base.h.

References PNS::ALGO_BASE::m_debugDecorator.

66  {
67  m_debugDecorator = aDecorator;
68  }
DEBUG_DECORATOR * m_debugDecorator
Definition: pns_algo_base.h:76
void PNS::WALKAROUND::SetForceWinding ( bool  aEnabled,
bool  aCw 
)
inline

Definition at line 107 of file pns_walkaround.h.

References m_forceCw, and m_forceWinding.

108  {
109  m_forceCw = aCw;
110  m_forceWinding = aEnabled;
111  }
void PNS::WALKAROUND::SetItemMask ( int  aMask)
inline

Definition at line 85 of file pns_walkaround.h.

References m_itemMask.

86  {
87  m_itemMask = aMask;
88  }
void PNS::WALKAROUND::SetIterationLimit ( const int  aIterLimit)
inline
void PNS::WALKAROUND::SetSingleDirection ( bool  aForceSingleDirection)
inline

Definition at line 90 of file pns_walkaround.h.

References m_forceLongerPath, and m_forceSingleDirection.

Referenced by PNS::SHOVE::onCollidingSolid().

91  {
92  m_forceSingleDirection = aForceSingleDirection;
93  m_forceLongerPath = aForceSingleDirection;
94  }
void PNS::WALKAROUND::SetSingleDirection2 ( bool  aForceSingleDirection)
inline

Definition at line 96 of file pns_walkaround.h.

References m_forceSingleDirection.

97  {
98  m_forceSingleDirection = aForceSingleDirection;
99  }
void PNS::WALKAROUND::SetSolidsOnly ( bool  aSolidsOnly)
inline
void PNS::WALKAROUND::SetWorld ( NODE aNode)
inline

Definition at line 67 of file pns_walkaround.h.

References m_world.

Referenced by PNS::LINE_PLACER::rhShoveOnly().

68  {
69  m_world = aNode;
70  }
WALKAROUND::WALKAROUND_STATUS PNS::WALKAROUND::singleStep ( LINE aPath,
bool  aWindingDirection 
)
private

Definition at line 54 of file pns_walkaround.cpp.

References SHAPE_LINE_CHAIN::Append(), PNS::NODE::CheckColliding(), PNS::LINE::ClipToNearestObstacle(), PNS::LINE::CPoint(), DONE, IN_PROGRESS, SHAPE_LINE_CHAIN::Length(), PNS::LINE::Line(), PNS::LOGGER::Log(), m_currentObstacle, m_forceLongerPath, m_itemMask, m_iteration, m_logger, m_recursiveBlockageCount, m_recursiveCollision, m_world, nearestObstacle(), PNS::LOGGER::NewGroup(), PNS::LINE::SetShape(), SHAPE_LINE_CHAIN::Simplify(), and PNS::LINE::Walkaround().

Referenced by Route().

56 {
57  OPT<OBSTACLE>& current_obs =
58  aWindingDirection ? m_currentObstacle[0] : m_currentObstacle[1];
59 
60  bool& prev_recursive = aWindingDirection ? m_recursiveCollision[0] : m_recursiveCollision[1];
61 
62  if( !current_obs )
63  return DONE;
64 
65  SHAPE_LINE_CHAIN path_pre[2], path_walk[2], path_post[2];
66 
67  VECTOR2I last = aPath.CPoint( -1 );
68 
69  if( ( current_obs->m_hull ).PointInside( last ) || ( current_obs->m_hull ).PointOnEdge( last ) )
70  {
72 
73  if( m_recursiveBlockageCount < 3 )
74  aPath.Line().Append( current_obs->m_hull.NearestPoint( last ) );
75  else
76  {
77  aPath = aPath.ClipToNearestObstacle( m_world );
78  return DONE;
79  }
80  }
81 
82  aPath.Walkaround( current_obs->m_hull, path_pre[0], path_walk[0],
83  path_post[0], aWindingDirection );
84  aPath.Walkaround( current_obs->m_hull, path_pre[1], path_walk[1],
85  path_post[1], !aWindingDirection );
86 
87 #ifdef DEBUG
88  m_logger.NewGroup( aWindingDirection ? "walk-cw" : "walk-ccw", m_iteration );
89  m_logger.Log( &path_walk[0], 0, "path-walk" );
90  m_logger.Log( &path_pre[0], 1, "path-pre" );
91  m_logger.Log( &path_post[0], 4, "path-post" );
92  m_logger.Log( &current_obs->m_hull, 2, "hull" );
93  m_logger.Log( current_obs->m_item, 3, "item" );
94 #endif
95 
96  int len_pre = path_walk[0].Length();
97  int len_alt = path_walk[1].Length();
98 
99  LINE walk_path( aPath, path_walk[1] );
100 
101  bool alt_collides = static_cast<bool>( m_world->CheckColliding( &walk_path, m_itemMask ) );
102 
103  SHAPE_LINE_CHAIN pnew;
104 
105  if( !m_forceLongerPath && len_alt < len_pre && !alt_collides && !prev_recursive )
106  {
107  pnew = path_pre[1];
108  pnew.Append( path_walk[1] );
109  pnew.Append( path_post[1] );
110 
111  if( !path_post[1].PointCount() || !path_walk[1].PointCount() )
112  current_obs = nearestObstacle( LINE( aPath, path_pre[1] ) );
113  else
114  current_obs = nearestObstacle( LINE( aPath, path_post[1] ) );
115  prev_recursive = false;
116  }
117  else
118  {
119  pnew = path_pre[0];
120  pnew.Append( path_walk[0] );
121  pnew.Append( path_post[0] );
122 
123  if( !path_post[0].PointCount() || !path_walk[0].PointCount() )
124  current_obs = nearestObstacle( LINE( aPath, path_pre[0] ) );
125  else
126  current_obs = nearestObstacle( LINE( aPath, path_walk[0] ) );
127 
128  if( !current_obs )
129  {
130  prev_recursive = false;
131  current_obs = nearestObstacle( LINE( aPath, path_post[0] ) );
132  }
133  else
134  prev_recursive = true;
135  }
136 
137  pnew.Simplify();
138  aPath.SetShape( pnew );
139 
140  return IN_PROGRESS;
141 }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
NODE::OPT_OBSTACLE m_currentObstacle[2]
void NewGroup(const std::string &aName, int aIter=0)
Definition: pns_logger.cpp:55
bool m_recursiveCollision[2]
NODE::OPT_OBSTACLE nearestObstacle(const LINE &aPath)
Class SHAPE_LINE_CHAIN.
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:425
boost::optional< T > OPT
Definition: optional.h:7
void Log(const ITEM *aItem, int aKind=0, const std::string aName=std::string())
Definition: pns_logger.cpp:75
int Length() const
Function Length()
void PNS::WALKAROUND::start ( const LINE aInitialPath)
private

Definition at line 33 of file pns_walkaround.cpp.

References m_iteration, and m_iterationLimit.

Referenced by Route().

34 {
35  m_iteration = 0;
36  m_iterationLimit = 50;
37 }

Member Data Documentation

const int PNS::WALKAROUND::DefaultIterationLimit = 50
staticprivate

Definition at line 37 of file pns_walkaround.h.

NODE::OPT_OBSTACLE PNS::WALKAROUND::m_currentObstacle[2]
private

Definition at line 146 of file pns_walkaround.h.

Referenced by Route(), and singleStep().

bool PNS::WALKAROUND::m_cursorApproachMode
private

Definition at line 142 of file pns_walkaround.h.

Referenced by Route(), SetApproachCursor(), and WALKAROUND().

VECTOR2I PNS::WALKAROUND::m_cursorPos
private

Definition at line 145 of file pns_walkaround.h.

Referenced by Route(), and SetApproachCursor().

bool PNS::WALKAROUND::m_forceCw
private

Definition at line 144 of file pns_walkaround.h.

Referenced by Route(), SetForceWinding(), and WALKAROUND().

bool PNS::WALKAROUND::m_forceLongerPath
private

Definition at line 141 of file pns_walkaround.h.

Referenced by Route(), SetSingleDirection(), singleStep(), and WALKAROUND().

bool PNS::WALKAROUND::m_forceSingleDirection
private

Definition at line 141 of file pns_walkaround.h.

Referenced by Route(), SetSingleDirection(), SetSingleDirection2(), and WALKAROUND().

bool PNS::WALKAROUND::m_forceWinding
private

Definition at line 143 of file pns_walkaround.h.

Referenced by Route(), SetForceWinding(), and WALKAROUND().

int PNS::WALKAROUND::m_itemMask
private
int PNS::WALKAROUND::m_iteration
private

Definition at line 138 of file pns_walkaround.h.

Referenced by Route(), singleStep(), start(), and WALKAROUND().

int PNS::WALKAROUND::m_iterationLimit
private

Definition at line 139 of file pns_walkaround.h.

Referenced by Route(), SetIterationLimit(), and start().

LOGGER PNS::WALKAROUND::m_logger
private

Definition at line 148 of file pns_walkaround.h.

Referenced by Logger(), and singleStep().

int PNS::WALKAROUND::m_recursiveBlockageCount
private

Definition at line 137 of file pns_walkaround.h.

Referenced by Route(), singleStep(), and WALKAROUND().

bool PNS::WALKAROUND::m_recursiveCollision[2]
private

Definition at line 147 of file pns_walkaround.h.

Referenced by singleStep(), and WALKAROUND().

std::set<ITEM*> PNS::WALKAROUND::m_restrictedSet
private

Definition at line 149 of file pns_walkaround.h.

Referenced by nearestObstacle(), and RestrictToSet().

NODE* PNS::WALKAROUND::m_world
private

Definition at line 135 of file pns_walkaround.h.

Referenced by nearestObstacle(), Route(), SetWorld(), and singleStep().


The documentation for this class was generated from the following files: