KiCad PCB EDA Suite
PNS::DRAGGER Class Reference

DRAGGER. More...

#include <pns_dragger.h>

Inheritance diagram for PNS::DRAGGER:
PNS::DRAG_ALGO PNS::ALGO_BASE

Public Member Functions

 DRAGGER (ROUTER *aRouter)
 
 ~DRAGGER ()
 
virtual bool Start (const VECTOR2I &aP, ITEM_SET &aPrimitives) override
 Function Start() More...
 
bool Drag (const VECTOR2I &aP) override
 Function Drag() More...
 
bool FixRoute () override
 Function FixRoute() More...
 
NODECurrentNode () const override
 Function CurrentNode() More...
 
const ITEM_SET Traces () override
 Function Traces() More...
 
void SetMode (int aDragMode) override
 
virtual void SetWorld (NODE *aWorld)
 Function SetWorld() More...
 
ROUTERRouter () const
 

Returns the instance of our router

More...
 
ROUTING_SETTINGSSettings () const
 

Returns current router settings

More...
 
virtual LOGGERLogger ()
 

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

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

Protected Attributes

NODEm_world
 
DEBUG_DECORATORm_debugDecorator
 
ROUTERm_router
 
LOGGERm_logger
 

Private Member Functions

const ITEM_SET findViaFanoutByHandle (NODE *aNode, const VIA_HANDLE &handle)
 
bool dragMarkObstacles (const VECTOR2I &aP)
 
bool dragShove (const VECTOR2I &aP)
 
bool dragWalkaround (const VECTOR2I &aP)
 
bool startDragSegment (const VECTOR2D &aP, SEGMENT *aSeg)
 
bool startDragArc (const VECTOR2D &aP, ARC *aArc)
 
bool startDragVia (VIA *aVia)
 
void dragViaMarkObstacles (const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
 
void dragViaWalkaround (const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
 
void optimizeAndUpdateDraggedLine (LINE &dragged, const VECTOR2I &aP)
 

Private Attributes

VIA_HANDLE m_initialVia
 
VIA_HANDLE m_draggedVia
 
NODEm_lastNode
 
int m_mode
 
LINE m_draggedLine
 
std::unique_ptr< SHOVEm_shove
 
int m_draggedSegmentIndex
 
bool m_dragStatus
 
PNS_MODE m_currentMode
 
ITEM_SET m_origViaConnections
 Contains the list of items that are currently modified by the dragger. More...
 
ITEM_SET m_draggedItems
 If true, moves the connection lines without maintaining 45° corners. More...
 
bool m_freeAngleMode
 

Detailed Description

DRAGGER.

Via, segment and corner dragging algorithm.

Definition at line 47 of file pns_dragger.h.

Constructor & Destructor Documentation

◆ DRAGGER()

PNS::DRAGGER::DRAGGER ( ROUTER aRouter)

Definition at line 32 of file pns_dragger.cpp.

32  :
33  DRAG_ALGO( aRouter )
34 {
35  m_world = NULL;
36  m_lastNode = NULL;
39  m_dragStatus = false;
41  m_freeAngleMode = false;
42 }
bool m_dragStatus
Definition: pns_dragger.h:119
DRAG_ALGO(ROUTER *aRouter)
Definition: pns_drag_algo.h:45
#define NULL
int m_draggedSegmentIndex
Definition: pns_dragger.h:118
NODE * m_lastNode
Definition: pns_dragger.h:112
PNS_MODE m_currentMode
Definition: pns_dragger.h:120
bool m_freeAngleMode
Definition: pns_dragger.h:127

References PNS::DM_SEGMENT, m_currentMode, m_draggedSegmentIndex, m_dragStatus, m_freeAngleMode, m_lastNode, m_mode, PNS::DRAG_ALGO::m_world, NULL, and PNS::RM_MarkObstacles.

◆ ~DRAGGER()

PNS::DRAGGER::~DRAGGER ( )

Definition at line 45 of file pns_dragger.cpp.

46 {
47 }

Member Function Documentation

◆ CurrentNode()

NODE * PNS::DRAGGER::CurrentNode ( ) const
overridevirtual

Function CurrentNode()

Returns the most recent world state, including all items changed due to dragging operation.

Implements PNS::DRAG_ALGO.

Definition at line 551 of file pns_dragger.cpp.

552 {
553  return m_lastNode;
554 }
NODE * m_lastNode
Definition: pns_dragger.h:112

References m_lastNode.

Referenced by FixRoute().

◆ Dbg()

◆ Drag()

bool PNS::DRAGGER::Drag ( const VECTOR2I aP)
overridevirtual

Function Drag()

Drags the current segment/corner/via to the point aP.

Returns
true, if dragging finished with success.

Implements PNS::DRAG_ALGO.

Definition at line 528 of file pns_dragger.cpp.

529 {
530  if( m_freeAngleMode )
531  return dragMarkObstacles( aP );
532 
533  switch( m_currentMode )
534  {
535  case RM_MarkObstacles:
536  return dragMarkObstacles( aP );
537 
538  case RM_Shove:
539  case RM_Smart:
540  return dragShove( aP );
541 
542  case RM_Walkaround:
543  return dragWalkaround( aP );
544 
545  default:
546  return false;
547  }
548 }
Ignore collisions, mark obstacles
Only walkaround
bool dragWalkaround(const VECTOR2I &aP)
bool dragShove(const VECTOR2I &aP)
PNS_MODE m_currentMode
Definition: pns_dragger.h:120
bool dragMarkObstacles(const VECTOR2I &aP)
bool m_freeAngleMode
Definition: pns_dragger.h:127

References dragMarkObstacles(), dragShove(), dragWalkaround(), m_currentMode, m_freeAngleMode, PNS::RM_MarkObstacles, PNS::RM_Shove, PNS::RM_Smart, and PNS::RM_Walkaround.

◆ dragMarkObstacles()

bool PNS::DRAGGER::dragMarkObstacles ( const VECTOR2I aP)
private

Definition at line 188 of file pns_dragger.cpp.

189 {
190  // fixme: rewrite using shared_ptr...
191  if( m_lastNode )
192  {
193  delete m_lastNode;
194  m_lastNode = nullptr;
195  }
196 
198 
199  switch( m_mode )
200  {
201  case DM_SEGMENT:
202  case DM_CORNER:
203  {
204  //TODO: Make threshhold configurable
205  int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 4 : 0;
206  LINE origLine( m_draggedLine );
207  LINE dragged( m_draggedLine );
208  dragged.SetSnapThreshhold( thresh );
209  dragged.ClearLinks();
210 
211  if( m_mode == DM_SEGMENT )
212  dragged.DragSegment( aP, m_draggedSegmentIndex );
213  else
214  dragged.DragCorner( aP, m_draggedSegmentIndex, m_freeAngleMode );
215 
216  m_lastNode->Remove( origLine );
217  m_lastNode->Add( dragged );
218 
220  m_draggedItems.Add( dragged );
221 
222  break;
223  }
224 
225  case DM_VIA: // fixme...
226  {
228 
229  break;
230  }
231  }
232 
233  if( Settings().CanViolateDRC() )
234  m_dragStatus = true;
235  else
237 
238  return true;
239 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124
bool m_dragStatus
Definition: pns_dragger.h:119
LINE m_draggedLine
Definition: pns_dragger.h:114
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
NODE * Branch()
Function Branch()
Definition: pns_node.cpp:106
void Remove(ARC *aArc)
Function Remove()
Definition: pns_node.cpp:796
ROUTING_SETTINGS & Settings() const
Returns current router settings
int m_draggedSegmentIndex
Definition: pns_dragger.h:118
bool SmoothDraggedSegments() const
Returns true if smoothing segments durign dragging is enabled.
NODE * m_lastNode
Definition: pns_dragger.h:112
void dragViaMarkObstacles(const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427
VIA_HANDLE m_initialVia
Definition: pns_dragger.h:109
int Width() const
Returns line width
Definition: pns_line.h:192
bool m_freeAngleMode
Definition: pns_dragger.h:127
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::NODE::Branch(), PNS::NODE::CheckColliding(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::DM_CORNER, PNS::DM_SEGMENT, PNS::DM_VIA, PNS::LINE::DragCorner(), PNS::LINE::DragSegment(), dragViaMarkObstacles(), m_draggedItems, m_draggedLine, m_draggedSegmentIndex, m_dragStatus, m_freeAngleMode, m_initialVia, m_lastNode, m_mode, PNS::DRAG_ALGO::m_world, PNS::NODE::Remove(), PNS::LINE::SetSnapThreshhold(), PNS::ALGO_BASE::Settings(), PNS::ROUTING_SETTINGS::SmoothDraggedSegments(), and PNS::LINE::Width().

Referenced by Drag().

◆ dragShove()

bool PNS::DRAGGER::dragShove ( const VECTOR2I aP)
private

Definition at line 425 of file pns_dragger.cpp.

426 {
427  bool ok = false;
428 
429  if( m_lastNode )
430  {
431  delete m_lastNode;
432  m_lastNode = NULL;
433  }
434 
435  switch( m_mode )
436  {
437  case DM_SEGMENT:
438  case DM_CORNER:
439  {
440  //TODO: Make threshhold configurable
441  int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 2 : 0;
442  LINE dragged( m_draggedLine );
443  dragged.SetSnapThreshhold( thresh );
444 
445  if( m_mode == DM_SEGMENT )
446  dragged.DragSegment( aP, m_draggedSegmentIndex );
447  else
448  dragged.DragCorner( aP, m_draggedSegmentIndex );
449 
450  SHOVE::SHOVE_STATUS st = m_shove->ShoveLines( dragged );
451 
452  if( st == SHOVE::SH_OK )
453  ok = true;
454  else if( st == SHOVE::SH_HEAD_MODIFIED )
455  {
456  dragged = m_shove->NewHead();
457  ok = true;
458  }
459 
460  m_lastNode = m_shove->CurrentNode()->Branch();
461 
462  if( ok )
463  {
464  VECTOR2D lockV;
465  dragged.ClearLinks();
466  dragged.Unmark();
467 
468  lockV = dragged.CLine().NearestPoint( aP );
469 
470  if( Settings().GetOptimizeDraggedTrack() )
471  {
475  }
476 
477  m_lastNode->Add( dragged );
479  m_draggedItems.Add( dragged );
480  }
481 
482  break;
483  }
484 
485  case DM_VIA:
486  {
487  VIA_HANDLE newVia;
488 
489  SHOVE::SHOVE_STATUS st = m_shove->ShoveDraggingVia( m_draggedVia, aP, newVia );
490 
491  if( st == SHOVE::SH_OK || st == SHOVE::SH_HEAD_MODIFIED )
492  ok = true;
493 
494  m_lastNode = m_shove->CurrentNode()->Branch();
495 
496  if( newVia.valid )
497  m_draggedVia = newVia;
498 
500  break;
501  }
502  }
503 
504  m_dragStatus = ok;
505 
506  return ok;
507 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124
std::unique_ptr< SHOVE > m_shove
Definition: pns_dragger.h:117
bool m_dragStatus
Definition: pns_dragger.h:119
VIA_HANDLE m_draggedVia
Definition: pns_dragger.h:110
LINE m_draggedLine
Definition: pns_dragger.h:114
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
ROUTING_SETTINGS & Settings() const
Returns current router settings
#define NULL
int m_draggedSegmentIndex
Definition: pns_dragger.h:118
static bool Optimize(LINE *aLine, int aEffortLevel, NODE *aWorld, const VECTOR2I aV=VECTOR2I(0, 0))
a quick shortcut to optmize a line without creating and setting up an optimizer
bool SmoothDraggedSegments() const
Returns true if smoothing segments durign dragging is enabled.
NODE * m_lastNode
Definition: pns_dragger.h:112
int Width() const
Returns line width
Definition: pns_line.h:192
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::DM_CORNER, PNS::DM_SEGMENT, PNS::DM_VIA, PNS::LINE::DragCorner(), PNS::LINE::DragSegment(), PNS::OPTIMIZER::KEEP_TOPOLOGY, m_draggedItems, m_draggedLine, m_draggedSegmentIndex, m_draggedVia, m_dragStatus, m_lastNode, m_mode, m_shove, PNS::OPTIMIZER::MERGE_SEGMENTS, SHAPE_LINE_CHAIN::NearestPoint(), NULL, PNS::OPTIMIZER::Optimize(), PNS::OPTIMIZER::PRESERVE_VERTEX, PNS::LINE::SetSnapThreshhold(), PNS::ALGO_BASE::Settings(), PNS::SHOVE::SH_HEAD_MODIFIED, PNS::SHOVE::SH_OK, PNS::ROUTING_SETTINGS::SmoothDraggedSegments(), PNS::LINE::Unmark(), PNS::VIA_HANDLE::valid, and PNS::LINE::Width().

Referenced by Drag().

◆ dragViaMarkObstacles()

void PNS::DRAGGER::dragViaMarkObstacles ( const VIA_HANDLE aHandle,
NODE aNode,
const VECTOR2I aP 
)
private

Definition at line 242 of file pns_dragger.cpp.

243 {
245 
246  ITEM_SET fanout = findViaFanoutByHandle( aNode, aHandle );
247 
248  if( fanout.Empty() )
249  {
250  return;
251  }
252 
253  for( ITEM* item : fanout.Items() )
254  {
255  if( const LINE* l = dyn_cast<const LINE*>( item ) )
256  {
257  LINE origLine( *l );
258  LINE draggedLine( *l );
259 
260  draggedLine.DragCorner( aP, origLine.CLine().Find( aHandle.pos ), m_freeAngleMode );
261  draggedLine.ClearLinks();
262 
263  m_draggedItems.Add( draggedLine );
264 
265  m_lastNode->Remove( origLine );
266  m_lastNode->Add( draggedLine );
267  }
268  else if ( VIA *via = dyn_cast<VIA*>( item ) )
269  {
270  auto nvia = Clone( *via );
271 
272  nvia->SetPos( aP );
273  m_draggedItems.Add( nvia.get() );
274 
275  m_lastNode->Remove( via );
276  m_lastNode->Add( std::move( nvia ) );
277  }
278  }
279 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
void Remove(ARC *aArc)
Function Remove()
Definition: pns_node.cpp:796
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:147
NODE * m_lastNode
Definition: pns_dragger.h:112
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271
const ITEM_SET findViaFanoutByHandle(NODE *aNode, const VIA_HANDLE &handle)
bool m_freeAngleMode
Definition: pns_dragger.h:127
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::Clone(), PNS::LINE::DragCorner(), PNS::ITEM_SET::Empty(), SHAPE_LINE_CHAIN::Find(), findViaFanoutByHandle(), PNS::ITEM_SET::Items(), m_draggedItems, m_freeAngleMode, m_lastNode, PNS::VIA_HANDLE::pos, and PNS::NODE::Remove().

Referenced by dragMarkObstacles().

◆ dragViaWalkaround()

void PNS::DRAGGER::dragViaWalkaround ( const VIA_HANDLE aHandle,
NODE aNode,
const VECTOR2I aP 
)
private

Definition at line 282 of file pns_dragger.cpp.

283 {
285 
286  ITEM_SET fanout = findViaFanoutByHandle( aNode, aHandle );
287 
288  if( fanout.Empty() )
289  {
290  return;
291  }
292 
293  for( ITEM* item : fanout.Items() )
294  {
295  if( const LINE* l = dyn_cast<const LINE*>( item ) )
296  {
297  LINE origLine( *l );
298  LINE draggedLine( *l );
299 
300  draggedLine.DragCorner( aP, origLine.CLine().Find( aHandle.pos ), m_freeAngleMode );
301  draggedLine.ClearLinks();
302 
303  m_draggedItems.Add( draggedLine );
304 
305  m_lastNode->Remove( origLine );
306  m_lastNode->Add( draggedLine );
307  }
308  else if ( VIA *via = dyn_cast<VIA*>( item ) )
309  {
310  auto nvia = Clone( *via );
311 
312  nvia->SetPos( aP );
313  m_draggedItems.Add( nvia.get() );
314 
315  m_lastNode->Remove( via );
316  m_lastNode->Add( std::move( nvia ) );
317  }
318  }
319 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
void Remove(ARC *aArc)
Function Remove()
Definition: pns_node.cpp:796
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:147
NODE * m_lastNode
Definition: pns_dragger.h:112
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271
const ITEM_SET findViaFanoutByHandle(NODE *aNode, const VIA_HANDLE &handle)
bool m_freeAngleMode
Definition: pns_dragger.h:127
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::Clone(), PNS::LINE::DragCorner(), PNS::ITEM_SET::Empty(), SHAPE_LINE_CHAIN::Find(), findViaFanoutByHandle(), PNS::ITEM_SET::Items(), m_draggedItems, m_freeAngleMode, m_lastNode, PNS::VIA_HANDLE::pos, and PNS::NODE::Remove().

Referenced by dragWalkaround().

◆ dragWalkaround()

bool PNS::DRAGGER::dragWalkaround ( const VECTOR2I aP)
private

Definition at line 343 of file pns_dragger.cpp.

344 {
345  bool ok = false;
346 // fixme: rewrite using shared_ptr...
347  if( m_lastNode )
348  {
349  delete m_lastNode;
350  m_lastNode = nullptr;
351  }
352 
354 
355  switch( m_mode )
356  {
357  case DM_SEGMENT:
358  case DM_CORNER:
359  {
360  int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 4 : 0;
361  LINE dragged( m_draggedLine );
362  LINE origLine( m_draggedLine );
363 
364  if( m_mode == DM_SEGMENT )
365  dragged.DragSegment( aP, m_draggedSegmentIndex );
366  else
367  dragged.DragCorner( aP, m_draggedSegmentIndex );
368 
369  if ( m_world->CheckColliding( &dragged ) )
370  {
371  WALKAROUND walkaround( m_lastNode, Router() );
372 
373  walkaround.SetSolidsOnly( false );
374  walkaround.SetDebugDecorator( Dbg() );
375  walkaround.SetLogger( Logger() );
376  walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
377 
378  WALKAROUND::RESULT wr = walkaround.Route( dragged );
379 
380  //Dbg()->AddLine( wr.lineCw.CLine(), 3, 200000 );
381  //Dbg()->AddLine( wr.lineCcw.CLine(), 2, 200000 );
382 
383  if( wr.statusCcw == WALKAROUND::DONE && wr.statusCw == WALKAROUND::DONE )
384  {
385  dragged = ( wr.lineCw.CLine().Length() < wr.lineCcw.CLine().Length() ? wr.lineCw : wr.lineCcw );
386  ok = true;
387  }
388  else if ( wr.statusCw == WALKAROUND::DONE )
389  {
390  dragged = wr.lineCw;
391  ok = true;
392  }
393  else if ( wr.statusCcw == WALKAROUND::DONE )
394  {
395  dragged = wr.lineCcw;
396  ok = true;
397  }
398 
399  }
400  else
401  {
402  ok = true;
403  }
404 
405  if(ok)
406  {
407  m_lastNode->Remove( origLine );
408  optimizeAndUpdateDraggedLine( dragged, aP );
409  }
410  break;
411  }
412  case DM_VIA: // fixme...
413  {
415 
416  break;
417  }
418  }
419 
420  m_dragStatus = ok;
421 
422  return true;
423 }
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
bool m_dragStatus
Definition: pns_dragger.h:119
virtual LOGGER * Logger()
Returns the logger object, allowing to dump geometry to a file.
LINE m_draggedLine
Definition: pns_dragger.h:114
NODE * Branch()
Function Branch()
Definition: pns_node.cpp:106
void dragViaWalkaround(const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
void Remove(ARC *aArc)
Function Remove()
Definition: pns_node.cpp:796
ROUTING_SETTINGS & Settings() const
Returns current router settings
void optimizeAndUpdateDraggedLine(LINE &dragged, const VECTOR2I &aP)
int m_draggedSegmentIndex
Definition: pns_dragger.h:118
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:77
bool SmoothDraggedSegments() const
Returns true if smoothing segments durign dragging is enabled.
NODE * m_lastNode
Definition: pns_dragger.h:112
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427
VIA_HANDLE m_initialVia
Definition: pns_dragger.h:109
int Width() const
Returns line width
Definition: pns_line.h:192

References PNS::NODE::Branch(), PNS::NODE::CheckColliding(), PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), PNS::DM_CORNER, PNS::DM_SEGMENT, PNS::DM_VIA, PNS::WALKAROUND::DONE, PNS::LINE::DragCorner(), PNS::LINE::DragSegment(), dragViaWalkaround(), SHAPE_LINE_CHAIN::Length(), PNS::WALKAROUND::RESULT::lineCcw, PNS::WALKAROUND::RESULT::lineCw, PNS::ALGO_BASE::Logger(), m_draggedLine, m_draggedSegmentIndex, m_dragStatus, m_initialVia, m_lastNode, m_mode, PNS::DRAG_ALGO::m_world, optimizeAndUpdateDraggedLine(), PNS::NODE::Remove(), PNS::WALKAROUND::Route(), PNS::ALGO_BASE::Router(), PNS::ALGO_BASE::SetDebugDecorator(), PNS::WALKAROUND::SetIterationLimit(), PNS::ALGO_BASE::SetLogger(), PNS::WALKAROUND::SetSolidsOnly(), PNS::ALGO_BASE::Settings(), PNS::ROUTING_SETTINGS::SmoothDraggedSegments(), PNS::WALKAROUND::RESULT::statusCcw, PNS::WALKAROUND::RESULT::statusCw, and PNS::LINE::Width().

Referenced by Drag().

◆ findViaFanoutByHandle()

const ITEM_SET PNS::DRAGGER::findViaFanoutByHandle ( NODE aNode,
const VIA_HANDLE handle 
)
private

Definition at line 112 of file pns_dragger.cpp.

113 {
114  ITEM_SET rv;
115 
116  JOINT* jt = aNode->FindJoint( handle.pos, handle.layers.Start(), handle.net );
117 
118  if( !jt )
119  return rv;
120 
121  for( ITEM* item : jt->LinkList() )
122  {
123  if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
124  {
125  int segIndex;
126  LINKED_ITEM* seg = ( LINKED_ITEM*) item;
127  LINE l = aNode->AssembleLine( seg, &segIndex );
128 
129  if( segIndex != 0 )
130  l.Reverse();
131 
132  rv.Add( l );
133  } else if ( item->OfKind( ITEM::VIA_T ))
134  {
135  rv.Add( item );
136  }
137  }
138 
139  return rv;
140 }
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:147

References PNS::ITEM_SET::Add(), PNS::ITEM::ARC_T, PNS::NODE::AssembleLine(), PNS::NODE::FindJoint(), PNS::VIA_HANDLE::layers, PNS::JOINT::LinkList(), PNS::VIA_HANDLE::net, PNS::VIA_HANDLE::pos, PNS::LINE::Reverse(), PNS::ITEM::SEGMENT_T, LAYER_RANGE::Start(), and PNS::ITEM::VIA_T.

Referenced by dragViaMarkObstacles(), and dragViaWalkaround().

◆ FixRoute()

bool PNS::DRAGGER::FixRoute ( )
overridevirtual

Function FixRoute()

Checks if the result of current dragging operation is correct and eventually commits it to the world.

Returns
true, if dragging finished with success.

Implements PNS::DRAG_ALGO.

Definition at line 510 of file pns_dragger.cpp.

511 {
512  NODE* node = CurrentNode();
513 
514  if( node )
515  {
516  // Collisions still prevent fixing unless "Allow DRC violations" is checked
517  if( !m_dragStatus )
518  return false;
519 
520  Router()->CommitRouting( node );
521  return true;
522  }
523 
524  return false;
525 }
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
void CommitRouting()
Definition: pns_router.cpp:443
bool m_dragStatus
Definition: pns_dragger.h:119
NODE * CurrentNode() const override
Function CurrentNode()

References PNS::ROUTER::CommitRouting(), CurrentNode(), m_dragStatus, and PNS::ALGO_BASE::Router().

◆ Logger()

LOGGER * PNS::ALGO_BASE::Logger ( )
virtualinherited

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

Reimplemented in PNS::SHOVE.

Definition at line 34 of file pns_algo_base.cpp.

35 {
36  return NULL;
37 }
#define NULL

References NULL.

Referenced by dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and Start().

◆ optimizeAndUpdateDraggedLine()

void PNS::DRAGGER::optimizeAndUpdateDraggedLine ( LINE dragged,
const VECTOR2I aP 
)
private

Definition at line 322 of file pns_dragger.cpp.

323 {
324  VECTOR2D lockV;
325  dragged.ClearLinks();
326  dragged.Unmark();
327 
328  lockV = dragged.CLine().NearestPoint( aP );
329 
330  if( Settings().GetOptimizeDraggedTrack() )
331  {
332  OPTIMIZER::Optimize( &dragged,
334  m_lastNode, lockV );
335  }
336 
337  m_lastNode->Add( dragged );
339  m_draggedItems.Add( dragged );
340 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
ROUTING_SETTINGS & Settings() const
Returns current router settings
static bool Optimize(LINE *aLine, int aEffortLevel, NODE *aWorld, const VECTOR2I aV=VECTOR2I(0, 0))
a quick shortcut to optmize a line without creating and setting up an optimizer
NODE * m_lastNode
Definition: pns_dragger.h:112
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::OPTIMIZER::KEEP_TOPOLOGY, m_draggedItems, m_lastNode, PNS::OPTIMIZER::MERGE_SEGMENTS, SHAPE_LINE_CHAIN::NearestPoint(), PNS::OPTIMIZER::Optimize(), PNS::OPTIMIZER::PRESERVE_VERTEX, PNS::ALGO_BASE::Settings(), and PNS::LINE::Unmark().

Referenced by dragWalkaround().

◆ Router()

◆ SetDebugDecorator()

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 72 of file pns_algo_base.h.

73  {
74  m_debugDecorator = aDecorator;
75  }
DEBUG_DECORATOR * m_debugDecorator
Definition: pns_algo_base.h:83

References PNS::ALGO_BASE::m_debugDecorator.

Referenced by dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::SHOVE::SHOVE().

◆ SetLogger()

void PNS::ALGO_BASE::SetLogger ( LOGGER aLogger)
inlineinherited

Definition at line 62 of file pns_algo_base.h.

63  {
64  m_logger = aLogger;
65  }
LOGGER * m_logger
Definition: pns_algo_base.h:85

References PNS::ALGO_BASE::m_logger.

Referenced by dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), and PNS::LINE_PLACER::rhWalkOnly().

◆ SetMode()

void PNS::DRAGGER::SetMode ( int  aDragMode)
overridevirtual

Reimplemented from PNS::DRAG_ALGO.

Definition at line 182 of file pns_dragger.cpp.

183 {
184  m_mode = aMode;
185 }

References m_mode.

◆ Settings()

◆ SetWorld()

virtual void PNS::DRAG_ALGO::SetWorld ( NODE aWorld)
inlinevirtualinherited

Function SetWorld()

Sets the board to work on.

Definition at line 59 of file pns_drag_algo.h.

60  {
61  m_world = aWorld;
62  }

References PNS::DRAG_ALGO::m_world.

◆ Start()

bool PNS::DRAGGER::Start ( const VECTOR2I aP,
ITEM_SET aPrimitives 
)
overridevirtual

Function Start()

Starts routing a single track at point aP, taking item aStartItem as anchor (unless NULL). Returns true if a dragging operation has started.

Implements PNS::DRAG_ALGO.

Definition at line 142 of file pns_dragger.cpp.

143 {
144  if( aPrimitives.Empty() )
145  return false;
146 
147  ITEM* startItem = aPrimitives[0];
148 
149  m_lastNode = NULL;
153 
155  {
156  m_shove = std::make_unique<SHOVE>( m_world, Router() );
157  m_shove->SetLogger( Logger() );
158  m_shove->SetDebugDecorator( Dbg() );
159  }
160 
161  startItem->Unmark( MK_LOCKED );
162 
163  wxLogTrace( "PNS", "StartDragging: item %p [kind %d]", startItem, (int) startItem->Kind() );
164 
165  switch( startItem->Kind() )
166  {
167  case ITEM::SEGMENT_T:
168  return startDragSegment( aP, static_cast<SEGMENT*>( startItem ) );
169 
170  case ITEM::VIA_T:
171  return startDragVia( static_cast<VIA*>( startItem ) );
172 
173  case ITEM::ARC_T:
174  return startDragArc( aP, static_cast<ARC*>( startItem ) );
175 
176  default:
177  return false;
178  }
179 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
std::unique_ptr< SHOVE > m_shove
Definition: pns_dragger.h:117
Ignore collisions, mark obstacles
virtual LOGGER * Logger()
Returns the logger object, allowing to dump geometry to a file.
bool startDragSegment(const VECTOR2D &aP, SEGMENT *aSeg)
Definition: pns_dragger.cpp:50
bool startDragArc(const VECTOR2D &aP, ARC *aArc)
Definition: pns_dragger.cpp:92
bool startDragVia(VIA *aVia)
ROUTING_SETTINGS & Settings() const
Returns current router settings
#define NULL
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:77
PNS_MODE Mode() const
Returns the routing mode.
NODE * m_lastNode
Definition: pns_dragger.h:112
PNS_MODE m_currentMode
Definition: pns_dragger.h:120
bool m_freeAngleMode
Definition: pns_dragger.h:127

References PNS::ITEM::ARC_T, PNS::ITEM_SET::Clear(), PNS::ALGO_BASE::Dbg(), PNS::DM_FREE_ANGLE, PNS::ITEM_SET::Empty(), PNS::ITEM::Kind(), PNS::ALGO_BASE::Logger(), m_currentMode, m_draggedItems, m_freeAngleMode, m_lastNode, m_mode, m_shove, PNS::DRAG_ALGO::m_world, PNS::MK_LOCKED, PNS::ROUTING_SETTINGS::Mode(), NULL, PNS::RM_Shove, PNS::ALGO_BASE::Router(), PNS::ITEM::SEGMENT_T, PNS::ALGO_BASE::Settings(), startDragArc(), startDragSegment(), startDragVia(), PNS::ITEM::Unmark(), and PNS::ITEM::VIA_T.

◆ startDragArc()

bool PNS::DRAGGER::startDragArc ( const VECTOR2D aP,
ARC aArc 
)
private

Definition at line 92 of file pns_dragger.cpp.

93 {
95  m_shove->SetInitialLine( m_draggedLine );
96  m_mode = DM_ARC;
97 
98  return true;
99 }
std::unique_ptr< SHOVE > m_shove
Definition: pns_dragger.h:117
LINE m_draggedLine
Definition: pns_dragger.h:114
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:893
int m_draggedSegmentIndex
Definition: pns_dragger.h:118

References PNS::NODE::AssembleLine(), PNS::DM_ARC, m_draggedLine, m_draggedSegmentIndex, m_mode, m_shove, and PNS::DRAG_ALGO::m_world.

Referenced by Start().

◆ startDragSegment()

bool PNS::DRAGGER::startDragSegment ( const VECTOR2D aP,
SEGMENT aSeg 
)
private

Definition at line 50 of file pns_dragger.cpp.

51 {
52  int w2 = aSeg->Width() / 2;
53 
55 
56  if( m_shove )
57  {
58  m_shove->SetInitialLine( m_draggedLine );
59  }
60 
61  auto distA = ( aP - aSeg->Seg().A ).EuclideanNorm();
62  auto distB = ( aP - aSeg->Seg().B ).EuclideanNorm();
63 
64  if( distA <= w2 )
65  {
66  m_mode = DM_CORNER;
67  }
68  else if( distB <= w2 )
69  {
70  //todo (snh) Adjust segment for arcs
72  m_mode = DM_CORNER;
73  }
74  else if ( m_freeAngleMode )
75  {
76  if( distB < distA )
77  {
79  }
80  m_mode = DM_CORNER;
81  }
82  else
83  {
85  }
86 
87  return true;
88 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
std::unique_ptr< SHOVE > m_shove
Definition: pns_dragger.h:117
LINE m_draggedLine
Definition: pns_dragger.h:114
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:893
int m_draggedSegmentIndex
Definition: pns_dragger.h:118
bool m_freeAngleMode
Definition: pns_dragger.h:127

References SEG::A, PNS::NODE::AssembleLine(), SEG::B, PNS::DM_CORNER, PNS::DM_SEGMENT, EuclideanNorm(), m_draggedLine, m_draggedSegmentIndex, m_freeAngleMode, m_mode, m_shove, PNS::DRAG_ALGO::m_world, PNS::SEGMENT::Seg(), and PNS::SEGMENT::Width().

Referenced by Start().

◆ startDragVia()

bool PNS::DRAGGER::startDragVia ( VIA aVia)
private

Definition at line 102 of file pns_dragger.cpp.

103 {
104  m_initialVia = aVia->MakeHandle();
106 
107  m_mode = DM_VIA;
108 
109  return true;
110 }
VIA_HANDLE m_draggedVia
Definition: pns_dragger.h:110
VIA_HANDLE m_initialVia
Definition: pns_dragger.h:109

References PNS::DM_VIA, m_draggedVia, m_initialVia, m_mode, and PNS::VIA::MakeHandle().

Referenced by Start().

◆ Traces()

const ITEM_SET PNS::DRAGGER::Traces ( )
overridevirtual

Function Traces()

Returns the set of dragged items.

Implements PNS::DRAG_ALGO.

Definition at line 557 of file pns_dragger.cpp.

558 {
559  return m_draggedItems;
560 }
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45° corners.
Definition: pns_dragger.h:124

References m_draggedItems.

Member Data Documentation

◆ m_currentMode

PNS_MODE PNS::DRAGGER::m_currentMode
private

Definition at line 120 of file pns_dragger.h.

Referenced by Drag(), DRAGGER(), and Start().

◆ m_debugDecorator

DEBUG_DECORATOR* PNS::ALGO_BASE::m_debugDecorator
protectedinherited

Definition at line 83 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::Dbg(), and PNS::ALGO_BASE::SetDebugDecorator().

◆ m_draggedItems

ITEM_SET PNS::DRAGGER::m_draggedItems
private

If true, moves the connection lines without maintaining 45° corners.

Definition at line 124 of file pns_dragger.h.

Referenced by dragMarkObstacles(), dragShove(), dragViaMarkObstacles(), dragViaWalkaround(), optimizeAndUpdateDraggedLine(), Start(), and Traces().

◆ m_draggedLine

LINE PNS::DRAGGER::m_draggedLine
private

◆ m_draggedSegmentIndex

int PNS::DRAGGER::m_draggedSegmentIndex
private

◆ m_draggedVia

VIA_HANDLE PNS::DRAGGER::m_draggedVia
private

Definition at line 110 of file pns_dragger.h.

Referenced by dragShove(), and startDragVia().

◆ m_dragStatus

bool PNS::DRAGGER::m_dragStatus
private

Definition at line 119 of file pns_dragger.h.

Referenced by DRAGGER(), dragMarkObstacles(), dragShove(), dragWalkaround(), and FixRoute().

◆ m_freeAngleMode

bool PNS::DRAGGER::m_freeAngleMode
private

◆ m_initialVia

VIA_HANDLE PNS::DRAGGER::m_initialVia
private

Definition at line 109 of file pns_dragger.h.

Referenced by dragMarkObstacles(), dragWalkaround(), and startDragVia().

◆ m_lastNode

◆ m_logger

LOGGER* PNS::ALGO_BASE::m_logger
protectedinherited

Definition at line 85 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::SetLogger(), and PNS::WALKAROUND::singleStep().

◆ m_mode

int PNS::DRAGGER::m_mode
private

◆ m_origViaConnections

ITEM_SET PNS::DRAGGER::m_origViaConnections
private

Contains the list of items that are currently modified by the dragger.

Definition at line 121 of file pns_dragger.h.

◆ m_router

ROUTER* PNS::ALGO_BASE::m_router
protectedinherited

Definition at line 84 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::Router(), and PNS::ALGO_BASE::Settings().

◆ m_shove

std::unique_ptr<SHOVE> PNS::DRAGGER::m_shove
private

Definition at line 117 of file pns_dragger.h.

Referenced by dragShove(), Start(), startDragArc(), and startDragSegment().

◆ m_world


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