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 41 of file pns_walkaround.cpp.

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

Referenced by Route(), and singleStep().

42 {
44 
45  if( m_restrictedSet.empty() )
46  return obs;
47 
48  else if( obs && m_restrictedSet.find ( obs->m_item ) != m_restrictedSet.end() )
49  return obs;
50 
51  return NODE::OPT_OBSTACLE();
52 }
OPT_OBSTACLE NearestObstacle(const LINE *aItem, int aKindMask=ITEM::ANY_T, const std::set< ITEM * > *aRestrictedSet=NULL)
Function NearestObstacle()
Definition: pns_node.cpp:304
std::set< ITEM * > m_restrictedSet
boost::optional< 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 145 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().

147 {
148  LINE path_cw( aInitialPath ), path_ccw( aInitialPath );
149  WALKAROUND_STATUS s_cw = IN_PROGRESS, s_ccw = IN_PROGRESS;
150  SHAPE_LINE_CHAIN best_path;
151 
152  // special case for via-in-the-middle-of-track placement
153  if( aInitialPath.PointCount() <= 1 )
154  {
155  if( aInitialPath.EndsWithVia() && m_world->CheckColliding( &aInitialPath.Via(), m_itemMask ) )
156  return STUCK;
157 
158  aWalkPath = aInitialPath;
159  return DONE;
160  }
161 
162  start( aInitialPath );
163 
164  m_currentObstacle[0] = m_currentObstacle[1] = nearestObstacle( aInitialPath );
166 
167  aWalkPath = aInitialPath;
168 
169  if( m_forceWinding )
170  {
171  s_cw = m_forceCw ? IN_PROGRESS : STUCK;
172  s_ccw = m_forceCw ? STUCK : IN_PROGRESS;
173  m_forceSingleDirection = true;
174  } else {
175  m_forceSingleDirection = false;
176  }
177 
178  while( m_iteration < m_iterationLimit )
179  {
180  if( s_cw != STUCK )
181  s_cw = singleStep( path_cw, true );
182 
183  if( s_ccw != STUCK )
184  s_ccw = singleStep( path_ccw, false );
185 
186  if( ( s_cw == DONE && s_ccw == DONE ) || ( s_cw == STUCK && s_ccw == STUCK ) )
187  {
188  int len_cw = path_cw.CLine().Length();
189  int len_ccw = path_ccw.CLine().Length();
190 
191  if( m_forceLongerPath )
192  aWalkPath = ( len_cw > len_ccw ? path_cw : path_ccw );
193  else
194  aWalkPath = ( len_cw < len_ccw ? path_cw : path_ccw );
195 
196  break;
197  }
198  else if( s_cw == DONE && !m_forceLongerPath )
199  {
200  aWalkPath = path_cw;
201  break;
202  }
203  else if( s_ccw == DONE && !m_forceLongerPath )
204  {
205  aWalkPath = path_ccw;
206  break;
207  }
208 
209  m_iteration++;
210  }
211 
213  {
214  int len_cw = path_cw.CLine().Length();
215  int len_ccw = path_ccw.CLine().Length();
216 
217  if( m_forceLongerPath )
218  aWalkPath = ( len_cw > len_ccw ? path_cw : path_ccw );
219  else
220  aWalkPath = ( len_cw < len_ccw ? path_cw : path_ccw );
221  }
222 
224  {
225  // int len_cw = path_cw.GetCLine().Length();
226  // int len_ccw = path_ccw.GetCLine().Length();
227  bool found = false;
228 
229  SHAPE_LINE_CHAIN l = aWalkPath.CLine();
230 
231  for( int i = 0; i < l.SegmentCount(); i++ )
232  {
233  const SEG s = l.Segment( i );
234 
235  VECTOR2I nearest = s.NearestPoint( m_cursorPos );
236  VECTOR2I::extended_type dist_a = ( s.A - m_cursorPos ).SquaredEuclideanNorm();
237  VECTOR2I::extended_type dist_b = ( s.B - m_cursorPos ).SquaredEuclideanNorm();
238  VECTOR2I::extended_type dist_n = ( nearest - m_cursorPos ).SquaredEuclideanNorm();
239 
240  if( dist_n <= dist_a && dist_n < dist_b )
241  {
242  l.Remove( i + 1, -1 );
243  l.Append( nearest );
244  l.Simplify();
245  found = true;
246  break;
247  }
248  }
249 
250  if( found )
251  {
252  aWalkPath = aInitialPath;
253  aWalkPath.SetShape( l );
254  }
255  }
256 
257  aWalkPath.Line().Simplify();
258 
259  if( aWalkPath.SegmentCount() < 1 )
260  return STUCK;
261  if( aWalkPath.CPoint( -1 ) != aInitialPath.CPoint( -1 ) )
262  return STUCK;
263  if( aWalkPath.CPoint( 0 ) != aInitialPath.CPoint( 0 ) )
264  return STUCK;
265 
266  WALKAROUND_STATUS st = s_ccw == DONE || s_cw == DONE ? DONE : STUCK;
267 
268  if( st == DONE )
269  {
270  if( aOptimize )
272  }
273 
274  return st;
275 }
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:81
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:355
Definition: seg.h:37
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:427
VECTOR2I A
Definition: seg.h:47
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:48
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 55 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().

57 {
58  optional<OBSTACLE>& current_obs =
59  aWindingDirection ? m_currentObstacle[0] : m_currentObstacle[1];
60 
61  bool& prev_recursive = aWindingDirection ? m_recursiveCollision[0] : m_recursiveCollision[1];
62 
63  if( !current_obs )
64  return DONE;
65 
66  SHAPE_LINE_CHAIN path_pre[2], path_walk[2], path_post[2];
67 
68  VECTOR2I last = aPath.CPoint( -1 );
69 
70  if( ( current_obs->m_hull ).PointInside( last ) || ( current_obs->m_hull ).PointOnEdge( last ) )
71  {
73 
74  if( m_recursiveBlockageCount < 3 )
75  aPath.Line().Append( current_obs->m_hull.NearestPoint( last ) );
76  else
77  {
78  aPath = aPath.ClipToNearestObstacle( m_world );
79  return DONE;
80  }
81  }
82 
83  aPath.Walkaround( current_obs->m_hull, path_pre[0], path_walk[0],
84  path_post[0], aWindingDirection );
85  aPath.Walkaround( current_obs->m_hull, path_pre[1], path_walk[1],
86  path_post[1], !aWindingDirection );
87 
88 #ifdef DEBUG
89  m_logger.NewGroup( aWindingDirection ? "walk-cw" : "walk-ccw", m_iteration );
90  m_logger.Log( &path_walk[0], 0, "path-walk" );
91  m_logger.Log( &path_pre[0], 1, "path-pre" );
92  m_logger.Log( &path_post[0], 4, "path-post" );
93  m_logger.Log( &current_obs->m_hull, 2, "hull" );
94  m_logger.Log( current_obs->m_item, 3, "item" );
95 #endif
96 
97  int len_pre = path_walk[0].Length();
98  int len_alt = path_walk[1].Length();
99 
100  LINE walk_path( aPath, path_walk[1] );
101 
102  bool alt_collides = static_cast<bool>( m_world->CheckColliding( &walk_path, m_itemMask ) );
103 
104  SHAPE_LINE_CHAIN pnew;
105 
106  if( !m_forceLongerPath && len_alt < len_pre && !alt_collides && !prev_recursive )
107  {
108  pnew = path_pre[1];
109  pnew.Append( path_walk[1] );
110  pnew.Append( path_post[1] );
111 
112  if( !path_post[1].PointCount() || !path_walk[1].PointCount() )
113  current_obs = nearestObstacle( LINE( aPath, path_pre[1] ) );
114  else
115  current_obs = nearestObstacle( LINE( aPath, path_post[1] ) );
116  prev_recursive = false;
117  }
118  else
119  {
120  pnew = path_pre[0];
121  pnew.Append( path_walk[0] );
122  pnew.Append( path_post[0] );
123 
124  if( !path_post[0].PointCount() || !path_walk[0].PointCount() )
125  current_obs = nearestObstacle( LINE( aPath, path_pre[0] ) );
126  else
127  current_obs = nearestObstacle( LINE( aPath, path_walk[0] ) );
128 
129  if( !current_obs )
130  {
131  prev_recursive = false;
132  current_obs = nearestObstacle( LINE( aPath, path_post[0] ) );
133  }
134  else
135  prev_recursive = true;
136  }
137 
138  pnew.Simplify();
139  aPath.SetShape( pnew );
140 
141  return IN_PROGRESS;
142 }
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:427
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 34 of file pns_walkaround.cpp.

References m_iteration, and m_iterationLimit.

Referenced by Route().

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

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: