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 std::vector< int > CurrentNets () const override
 Function CurrentNets() More...
 
int CurrentLayer () const override
 Function CurrentLayer() More...
 
const ITEM_SET Traces () override
 Function Traces() More...
 
void SetMode (int aDragMode) override
 
virtual void SetWorld (NODE *aWorld)
 Function SetWorld() More...
 
ROUTERRouter () const
 Return current router settings. More...
 
ROUTING_SETTINGSSettings () const
 Return the logger object, allowing to dump geometry to a file. More...
 
virtual LOGGERLogger ()
 
void SetLogger (LOGGER *aLogger)
 
void SetDebugDecorator (DEBUG_DECORATOR *aDecorator)
 Assign a debug decorator allowing this algo to draw extra graphics for visual debugging. More...
 
DEBUG_DECORATORDbg () const
 
const BOX2IVisibleViewArea () 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)
 
bool dragViaMarkObstacles (const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
 
bool dragViaWalkaround (const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
 
void optimizeAndUpdateDraggedLine (LINE &aDragged, const LINE &aOrig, const VECTOR2I &aP)
 
bool propagateViaForces (NODE *node, std::set< VIA * > &vias)
 
bool tryWalkaround (NODE *aNode, LINE &aOrig, LINE &aWalk)
 
VVIAcheckVirtualVia (const VECTOR2D &aP, SEGMENT *aSeg)
 

Private Attributes

VIA_HANDLE m_initialVia
 
VIA_HANDLE m_draggedVia
 
NODEm_lastNode
 
int m_mode
 
LINE m_draggedLine
 
LINE m_lastDragSolution
 
std::unique_ptr< SHOVEm_shove
 
int m_draggedSegmentIndex
 
bool m_dragStatus
 
PNS_MODE m_currentMode
 
ITEM_SET m_origViaConnections
 
VECTOR2D m_lastValidPoint
 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 degrees corners. More...
 
bool m_freeAngleMode
 
MOUSE_TRAIL_TRACER m_mouseTrailTracer
 

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 m_initialVia( {} ),
35 m_draggedVia( {} )
36{
37 m_world = nullptr;
38 m_lastNode = nullptr;
41 m_dragStatus = false;
43 m_freeAngleMode = false;
44}
bool m_dragStatus
Definition: pns_dragger.h:141
int m_draggedSegmentIndex
Definition: pns_dragger.h:140
NODE * m_lastNode
Definition: pns_dragger.h:135
VIA_HANDLE m_draggedVia
Definition: pns_dragger.h:133
bool m_freeAngleMode
Definition: pns_dragger.h:150
PNS_MODE m_currentMode
Definition: pns_dragger.h:142
VIA_HANDLE m_initialVia
Definition: pns_dragger.h:132
DRAG_ALGO(ROUTER *aRouter)
Definition: pns_drag_algo.h:45
@ RM_MarkObstacles
Ignore collisions, mark obstacles.
@ DM_SEGMENT
Definition: pns_router.h:73

◆ ~DRAGGER()

PNS::DRAGGER::~DRAGGER ( )

Definition at line 47 of file pns_dragger.cpp.

48{
49}

Member Function Documentation

◆ checkVirtualVia()

VVIA * PNS::DRAGGER::checkVirtualVia ( const VECTOR2D aP,
SEGMENT aSeg 
)
private

Definition at line 71 of file pns_dragger.cpp.

72{
73 int w2 = aSeg->Width() / 2;
74
75 auto distA = ( aP - aSeg->Seg().A ).EuclideanNorm();
76 auto distB = ( aP - aSeg->Seg().B ).EuclideanNorm();
77
78 VECTOR2I psnap;
79
80 if( distA <= w2 )
81 {
82 psnap = aSeg->Seg().A;
83 }
84 else if( distB <= w2 )
85 {
86 psnap = aSeg->Seg().B;
87 }
88 else
89 {
90 return nullptr;
91 }
92
93 JOINT *jt = m_world->FindJoint( psnap, aSeg );
94
95 if ( !jt )
96 {
97 return nullptr;
98 }
99
100 for( auto lnk : jt->LinkList() )
101 {
102 if( lnk.item->IsVirtual() && lnk.item->OfKind( ITEM::VIA_T ))
103 {
104 return static_cast<VVIA*>( lnk.item );
105 }
106 }
107
108 return nullptr;
109}
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Search for a joint at a given position, layer and belonging to given net.
Definition: pns_node.cpp:1181
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129

References SEG::A, SEG::B, EuclideanNorm(), PNS::NODE::FindJoint(), PNS::JOINT::LinkList(), PNS::DRAG_ALGO::m_world, PNS::SEGMENT::Seg(), PNS::ITEM::VIA_T, and PNS::SEGMENT::Width().

Referenced by Start().

◆ CurrentLayer()

int PNS::DRAGGER::CurrentLayer ( ) const
inlineoverridevirtual

Function CurrentLayer()

Returns the layer of currently routed track.

Implements PNS::DRAG_ALGO.

Definition at line 101 of file pns_dragger.h.

102 {
103 return m_draggedLine.Layer();
104 }
LINE m_draggedLine
Definition: pns_dragger.h:137
virtual int Layer() const
Definition: pns_item.h:158

References PNS::ITEM::Layer(), and m_draggedLine.

◆ CurrentNets()

const std::vector< int > PNS::DRAGGER::CurrentNets ( ) const
inlineoverridevirtual

Function CurrentNets()

Returns the net code(s) of currently routed track(s).

Implements PNS::DRAG_ALGO.

Definition at line 91 of file pns_dragger.h.

92 {
93 return std::vector<int>( 1, m_draggedLine.Net() );
94 }
int Net() const
Definition: pns_item.h:152

References m_draggedLine, and PNS::ITEM::Net().

◆ 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 745 of file pns_dragger.cpp.

746{
747 return m_lastNode ? m_lastNode : m_world;
748}

References m_lastNode, and PNS::DRAG_ALGO::m_world.

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 717 of file pns_dragger.cpp.

718{
720
721 bool ret = false;
722
723 if( m_freeAngleMode )
724 {
725 ret = dragMarkObstacles( aP );
726 }
727 else
728 {
729 switch( m_currentMode )
730 {
731 case RM_MarkObstacles: ret = dragMarkObstacles( aP ); break;
732 case RM_Shove: ret = dragShove( aP ); break;
733 case RM_Walkaround: ret = dragWalkaround( aP ); break;
734 default: break;
735 }
736 }
737
738 if( ret )
739 m_lastValidPoint = aP;
740
741 return ret;
742}
VECTOR2D m_lastValidPoint
Contains the list of items that are currently modified by the dragger.
Definition: pns_dragger.h:144
bool dragShove(const VECTOR2I &aP)
bool dragMarkObstacles(const VECTOR2I &aP)
bool dragWalkaround(const VECTOR2I &aP)
MOUSE_TRAIL_TRACER m_mouseTrailTracer
Definition: pns_dragger.h:151
void AddTrailPoint(const VECTOR2I &aP)
@ RM_Walkaround
Only walk around.
@ RM_Shove
Only shove.

References PNS::MOUSE_TRAIL_TRACER::AddTrailPoint(), dragMarkObstacles(), dragShove(), dragWalkaround(), m_currentMode, m_freeAngleMode, m_lastValidPoint, m_mouseTrailTracer, PNS::RM_MarkObstacles, PNS::RM_Shove, and PNS::RM_Walkaround.

Referenced by FixRoute().

◆ dragMarkObstacles()

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

Definition at line 269 of file pns_dragger.cpp.

270{
271 // fixme: rewrite using shared_ptr...
272 if( m_lastNode )
273 {
274 delete m_lastNode;
275 m_lastNode = nullptr;
276 }
277
279
280 switch( m_mode )
281 {
282 case DM_SEGMENT:
283 case DM_CORNER:
284 {
285 //TODO: Make threshold configurable
286 int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 4 : 0;
287 LINE origLine( m_draggedLine );
288 LINE dragged( m_draggedLine );
289 dragged.SetSnapThreshhold( thresh );
290 dragged.ClearLinks();
291
292 if( m_mode == DM_SEGMENT )
293 dragged.DragSegment( aP, m_draggedSegmentIndex );
294 else
295 dragged.DragCorner( aP, m_draggedSegmentIndex, m_freeAngleMode );
296
297 m_lastNode->Remove( origLine );
298 m_lastNode->Add( dragged );
299
301 m_draggedItems.Add( dragged );
302
303 break;
304 }
305
306 case DM_VIA: // fixme...
307 {
309
310 break;
311 }
312 }
313
314 if( Settings().AllowDRCViolations() )
315 m_dragStatus = true;
316 else
318
319 return true;
320}
ROUTING_SETTINGS & Settings() const
Return the logger object, allowing to dump geometry to a file.
ITEM_SET m_draggedItems
If true, moves the connection lines without maintaining 45 degrees corners.
Definition: pns_dragger.h:147
bool dragViaMarkObstacles(const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:156
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:139
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition: pns_node.cpp:468
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition: pns_node.cpp:656
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:873
bool SmoothDraggedSegments() const
Enable/disable smoothing segments during dragging.
@ DM_CORNER
Definition: pns_router.h:72
@ DM_VIA
Definition: pns_router.h:74

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 602 of file pns_dragger.cpp.

603{
604 bool ok = false;
605
606 if( m_lastNode )
607 {
608 delete m_lastNode;
609 m_lastNode = nullptr;
610 }
611
612 switch( m_mode )
613 {
614 case DM_SEGMENT:
615 case DM_CORNER:
616 {
617 //TODO: Make threshold configurable
618 int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 2 : 0;
619 LINE dragged( m_draggedLine );
620 dragged.SetSnapThreshhold( thresh );
621
622 if( m_mode == DM_SEGMENT )
623 dragged.DragSegment( aP, m_draggedSegmentIndex );
624 else
625 dragged.DragCorner( aP, m_draggedSegmentIndex );
626
627 PNS_DBG( Dbg(), AddShape, &dragged.CLine(), BLUE, 5000, wxT( "drag-shove-line" ) );
628
629 SHOVE::SHOVE_STATUS st = m_shove->ShoveLines( dragged );
630
631 if( st == SHOVE::SH_OK )
632 {
633 ok = true;
634 }
635 else if( st == SHOVE::SH_HEAD_MODIFIED )
636 {
637 dragged = m_shove->NewHead();
638 ok = true;
639 }
640
641 m_lastNode = m_shove->CurrentNode()->Branch();
642
643 if( ok )
644 {
645 VECTOR2D lockV;
646 dragged.ClearLinks();
647 dragged.Unmark();
649 m_lastDragSolution = dragged;
650 }
651 else
652 {
655 }
656
657 break;
658 }
659
660 case DM_VIA:
661 {
662 VIA_HANDLE newVia;
663
664 // corner count limiter intended to avoid excessive optimization produces mediocre results for via shoving.
665 // this is a hack that disables it, before I figure out a more reliable solution
666 m_shove->DisablePostShoveOptimizations( OPTIMIZER::LIMIT_CORNER_COUNT );
667 SHOVE::SHOVE_STATUS st = m_shove->ShoveDraggingVia( m_draggedVia, aP, newVia );
668
669 if( st == SHOVE::SH_OK || st == SHOVE::SH_HEAD_MODIFIED )
670 ok = true;
671
672 m_lastNode = m_shove->CurrentNode()->Branch();
673
674 if( newVia.valid )
675 m_draggedVia = newVia;
676
678 break;
679 }
680 }
681
682 m_dragStatus = ok;
683
684 return ok;
685}
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
void optimizeAndUpdateDraggedLine(LINE &aDragged, const LINE &aOrig, const VECTOR2I &aP)
LINE m_lastDragSolution
Definition: pns_dragger.h:138
std::unique_ptr< SHOVE > m_shove
Definition: pns_dragger.h:139
@ LIMIT_CORNER_COUNT
Do not attempt to optimize if the resulting line's corner count is outside the predefined range.
@ SH_HEAD_MODIFIED
Definition: pns_shove.h:54
@ BLUE
Definition: color4d.h:56
#define PNS_DBG(dbg, method,...)

References PNS::NODE::Add(), BLUE, PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), PNS::DM_CORNER, PNS::DM_SEGMENT, PNS::DM_VIA, PNS::LINE::DragCorner(), PNS::LINE::DragSegment(), PNS::OPTIMIZER::LIMIT_CORNER_COUNT, m_draggedItems, m_draggedLine, m_draggedSegmentIndex, m_draggedVia, m_dragStatus, m_lastDragSolution, m_lastNode, m_mode, m_shove, optimizeAndUpdateDraggedLine(), PNS_DBG, 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()

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

Definition at line 323 of file pns_dragger.cpp.

324{
326
327 ITEM_SET fanout = findViaFanoutByHandle( aNode, aHandle );
328
329 if( fanout.Empty() )
330 {
331 return true;
332 }
333
334 for( ITEM* item : fanout.Items() )
335 {
336 if( const LINE* l = dyn_cast<const LINE*>( item ) )
337 {
338 LINE origLine( *l );
339 LINE draggedLine( *l );
340
341 draggedLine.DragCorner( aP, origLine.CLine().Find( aHandle.pos ), m_freeAngleMode );
342 draggedLine.ClearLinks();
343
344 m_draggedItems.Add( draggedLine );
345
346 m_lastNode->Remove( origLine );
347 m_lastNode->Add( draggedLine );
348 }
349 else if ( VIA *via = dyn_cast<VIA*>( item ) )
350 {
351 auto nvia = Clone( *via );
352
353 nvia->SetPos( aP );
354 m_draggedItems.Add( nvia.get() );
355
356 m_lastNode->Remove( via );
357 m_lastNode->Add( std::move( nvia ) );
358 }
359 }
360
361 return true;
362}
const ITEM_SET findViaFanoutByHandle(NODE *aNode, const VIA_HANDLE &handle)
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271

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, PNS::NODE::Remove(), and via.

Referenced by dragMarkObstacles().

◆ dragViaWalkaround()

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

Definition at line 365 of file pns_dragger.cpp.

366{
368
369 ITEM_SET fanout = findViaFanoutByHandle( aNode, aHandle );
370
371 if( fanout.Empty() )
372 {
373 return true;
374 }
375
376 bool viaPropOk = false;
377 VECTOR2I viaTargetPos;
378
379 for( ITEM* item : fanout.Items() )
380 {
381 if ( VIA *via = dyn_cast<VIA*>( item ) )
382 {
383 auto draggedVia = Clone( *via );
384
385 draggedVia->SetPos( aP );
386 m_draggedItems.Add( draggedVia.get() );
387
388 std::set<VIA*> vias;
389
390 vias.insert( draggedVia.get() );
391
392 bool ok = propagateViaForces( m_lastNode, vias );
393
394 if( ok )
395 {
396 viaTargetPos = draggedVia->Pos();
397 viaPropOk = true;
398 m_lastNode->Remove( via );
399 m_lastNode->Add( std::move(draggedVia) );
400 }
401 }
402 }
403
404 if( !viaPropOk ) // can't force-propagate the via? bummer...
405 return false;
406
407 for( ITEM* item : fanout.Items() )
408 {
409 if( const LINE* l = dyn_cast<const LINE*>( item ) )
410 {
411 LINE origLine( *l );
412 LINE draggedLine( *l );
413 LINE walkLine( *l );
414
415 draggedLine.DragCorner( viaTargetPos, origLine.CLine().Find( aHandle.pos ),
417 draggedLine.ClearLinks();
418
419 if ( m_world->CheckColliding( &draggedLine ) )
420 {
421 bool ok = tryWalkaround( m_lastNode, draggedLine, walkLine );
422
423 if( !ok )
424 return false;
425
426 m_lastNode->Remove( origLine );
427 optimizeAndUpdateDraggedLine( walkLine, origLine, aP );
428 }
429 else
430 {
431 m_draggedItems.Add( draggedLine );
432
433 m_lastNode->Remove( origLine );
434 m_lastNode->Add( draggedLine );
435 }
436 }
437 }
438
439 return true;
440}
bool tryWalkaround(NODE *aNode, LINE &aOrig, LINE &aWalk)
bool propagateViaForces(NODE *node, std::set< VIA * > &vias)
Definition: pns_dragger.cpp:52

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::NODE::CheckColliding(), 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::DRAG_ALGO::m_world, optimizeAndUpdateDraggedLine(), PNS::VIA_HANDLE::pos, propagateViaForces(), PNS::NODE::Remove(), tryWalkaround(), and via.

Referenced by dragWalkaround().

◆ dragWalkaround()

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

Definition at line 536 of file pns_dragger.cpp.

537{
538 bool ok = false;
539
540 // fixme: rewrite using shared_ptr...
541 if( m_lastNode )
542 {
543 delete m_lastNode;
544 m_lastNode = nullptr;
545 }
546
548
549 switch( m_mode )
550 {
551 case DM_SEGMENT:
552 case DM_CORNER:
553 {
554 int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 4 : 0;
555 LINE dragged( m_draggedLine );
556 LINE draggedWalk( m_draggedLine );
557 LINE origLine( m_draggedLine );
558
559 dragged.SetSnapThreshhold( thresh );
560
561 if( m_mode == DM_SEGMENT )
562 dragged.DragSegment( aP, m_draggedSegmentIndex );
563 else
564 dragged.DragCorner( aP, m_draggedSegmentIndex );
565
566 if ( m_world->CheckColliding( &dragged ) )
567 {
568 ok = tryWalkaround( m_lastNode, dragged, draggedWalk );
569 }
570 else
571 {
572 draggedWalk = dragged;
573 ok = true;
574 }
575
576 if( draggedWalk.CLine().PointCount() < 2 )
577 ok = false;
578
579 if( ok )
580 {
581 PNS_DBG( Dbg(), AddShape, &origLine.CLine(), BLUE, 50000, wxT( "drag-orig-line" ) );
582 PNS_DBG( Dbg(), AddShape, &draggedWalk.CLine(), CYAN, 75000, wxT( "drag-walk" ) );
583 m_lastNode->Remove( origLine );
584 optimizeAndUpdateDraggedLine( draggedWalk, origLine, aP );
585 }
586
587 break;
588 }
589 case DM_VIA: // fixme...
590 {
592 break;
593 }
594 }
595
596 m_dragStatus = ok;
597
598 return true;
599}
bool dragViaWalkaround(const VIA_HANDLE &aHandle, NODE *aNode, const VECTOR2I &aP)
@ CYAN
Definition: color4d.h:58

References BLUE, PNS::NODE::Branch(), PNS::NODE::CheckColliding(), PNS::LINE::CLine(), CYAN, PNS::ALGO_BASE::Dbg(), PNS::DM_CORNER, PNS::DM_SEGMENT, PNS::DM_VIA, PNS::LINE::DragCorner(), PNS::LINE::DragSegment(), dragViaWalkaround(), m_draggedLine, m_draggedSegmentIndex, m_dragStatus, m_initialVia, m_lastNode, m_mode, PNS::DRAG_ALGO::m_world, optimizeAndUpdateDraggedLine(), PNS_DBG, SHAPE_LINE_CHAIN::PointCount(), PNS::NODE::Remove(), PNS::LINE::SetSnapThreshhold(), PNS::ALGO_BASE::Settings(), PNS::ROUTING_SETTINGS::SmoothDraggedSegments(), tryWalkaround(), and PNS::LINE::Width().

Referenced by Drag().

◆ findViaFanoutByHandle()

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

Definition at line 176 of file pns_dragger.cpp.

177{
178 ITEM_SET rv;
179
180 JOINT* jt = aNode->FindJoint( handle.pos, handle.layers.Start(), handle.net );
181
182 if( !jt )
183 return rv;
184
185 for( ITEM* item : jt->LinkList() )
186 {
187 if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
188 {
189 int segIndex;
190 LINKED_ITEM* seg = ( LINKED_ITEM*) item;
191 LINE l = aNode->AssembleLine( seg, &segIndex );
192
193 if( segIndex != 0 )
194 l.Reverse();
195
196 rv.Add( l );
197 }
198 else if( item->OfKind( ITEM::VIA_T ) )
199 {
200 rv.Add( item );
201 }
202 }
203
204 return rv;
205}
@ SEGMENT_T
Definition: pns_item.h:66

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 688 of file pns_dragger.cpp.

689{
690 NODE* node = CurrentNode();
691
692 if( node )
693 {
694 // If collisions exist, we can fix in shove/smart mode because all tracks to be committed
695 // will be in valid positions (even if the current routing solution to the mouse cursor is
696 // invalid). In other modes, we can only commit if "Allow DRC violations" is enabled.
697 if( !m_dragStatus )
698 {
700 node = CurrentNode();
701
702 if( !node )
703 return false;
704 }
705
706 if( !m_dragStatus && !Settings().AllowDRCViolations() )
707 return false;
708
709 Router()->CommitRouting( node );
710 return true;
711 }
712
713 return false;
714}
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
NODE * CurrentNode() const override
Function CurrentNode()
bool Drag(const VECTOR2I &aP) override
Function Drag()
void CommitRouting()
Definition: pns_router.cpp:728

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

◆ Logger()

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

Reimplemented in PNS::SHOVE.

Definition at line 34 of file pns_algo_base.cpp.

35{
36 return nullptr;
37}

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

◆ optimizeAndUpdateDraggedLine()

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

Definition at line 443 of file pns_dragger.cpp.

444{
445 VECTOR2D lockV;
446 aDragged.ClearLinks();
447 aDragged.Unmark();
448
449 lockV = aDragged.CLine().NearestPoint( aP );
450
451 OPTIMIZER optimizer( m_lastNode );
452
454
455 if( Settings().SmoothDraggedSegments() )
457
458 optimizer.SetEffortLevel( effort );
459
460 OPT_BOX2I affectedArea = aDragged.ChangedArea( &aOrig );
461 VECTOR2I anchor( aP );
462
463 if( aDragged.CLine().Find( aP ) < 0 )
464 {
465 anchor = aDragged.CLine().NearestPoint( aP );
466 }
467
468 optimizer.SetPreserveVertex( anchor );
469
470 // People almost never want KiCad to reroute tracks in areas they can't even see, so restrict
471 // the area to what is visible even if we are optimizing the "entire" track.
472 if( Settings().GetOptimizeEntireDraggedTrack() )
473 affectedArea = VisibleViewArea();
474 else if( !affectedArea )
475 affectedArea = BOX2I( aP ); // No valid area yet? set to minimum to disable optimization
476
477 PNS_DBG( Dbg(), AddPoint, anchor, YELLOW, 100000, wxT( "drag-anchor" ) );
478 PNS_DBG( Dbg(), AddShape, *affectedArea, RED, 0, wxT( "drag-affected-area" ) );
479
480 optimizer.SetRestrictArea( *affectedArea );
481 optimizer.Optimize( &aDragged );
482
483 OPT_BOX2I optArea = aDragged.ChangedArea( &aOrig );
484
485 if( optArea )
486 PNS_DBG( Dbg(), AddShape, *optArea, BLUE, 0, wxT( "drag-opt-area" ) );
487
488 m_lastNode->Add( aDragged );
490 m_draggedItems.Add( aDragged );
491}
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:509
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
const BOX2I & VisibleViewArea() const
@ MERGE_SEGMENTS
Reduce corner cost iteratively.
Definition: pns_optimizer.h:99
@ MERGE_COLINEAR
Merge co-linear segments.
@ YELLOW
Definition: color4d.h:67
@ RED
Definition: color4d.h:59

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), anchor, BLUE, PNS::LINE::ChangedArea(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), SHAPE_LINE_CHAIN::Find(), PNS::OPTIMIZER::KEEP_TOPOLOGY, m_draggedItems, m_lastNode, PNS::OPTIMIZER::MERGE_COLINEAR, PNS::OPTIMIZER::MERGE_SEGMENTS, SHAPE_LINE_CHAIN::NearestPoint(), PNS::OPTIMIZER::Optimize(), PNS_DBG, RED, PNS::OPTIMIZER::RESTRICT_AREA, PNS::OPTIMIZER::SetEffortLevel(), PNS::OPTIMIZER::SetPreserveVertex(), PNS::OPTIMIZER::SetRestrictArea(), PNS::ALGO_BASE::Settings(), PNS::LINE::Unmark(), PNS::ALGO_BASE::VisibleViewArea(), and YELLOW.

Referenced by dragShove(), dragViaWalkaround(), and dragWalkaround().

◆ propagateViaForces()

bool PNS::DRAGGER::propagateViaForces ( NODE node,
std::set< VIA * > &  vias 
)
private

Definition at line 52 of file pns_dragger.cpp.

53{
54 VIA* via = *vias.begin();
55
56 VECTOR2I force;
58
59 bool solidsOnly = false;// ( m_currentMode != RM_Walkaround );
60
61 if( via->PushoutForce( node, lead, force, solidsOnly, 40 ) )
62 {
63 via->SetPos( via->Pos() + force );
64 return true;
65 }
66
67 return false;
68}
@ VIA
Normal via.
Definition: router_tool.cpp:76

References PNS::MOUSE_TRAIL_TRACER::GetTrailLeadVector(), m_mouseTrailTracer, and via.

Referenced by dragViaWalkaround().

◆ Router()

◆ SetDebugDecorator()

void PNS::ALGO_BASE::SetDebugDecorator ( DEBUG_DECORATOR aDecorator)
inlineinherited

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

Definition at line 73 of file pns_algo_base.h.

74 {
75 m_debugDecorator = aDecorator;
76 }

References PNS::ALGO_BASE::m_debugDecorator.

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

◆ SetLogger()

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

Definition at line 65 of file pns_algo_base.h.

66 {
67 m_logger = aLogger;
68 }
LOGGER * m_logger
Definition: pns_algo_base.h:88

References PNS::ALGO_BASE::m_logger.

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

◆ SetMode()

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

Reimplemented from PNS::DRAG_ALGO.

Definition at line 263 of file pns_dragger.cpp.

264{
265 m_mode = aMode;
266}

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 60 of file pns_drag_algo.h.

61 {
62 m_world = aWorld;
63 }

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 207 of file pns_dragger.cpp.

208{
209 if( aPrimitives.Empty() )
210 return false;
211
212 ITEM* startItem = aPrimitives[0];
213
214 m_lastNode = nullptr;
218 m_lastValidPoint = aP;
219
222
224 {
225 m_shove = std::make_unique<SHOVE>( m_world, Router() );
226 m_shove->SetLogger( Logger() );
227 m_shove->SetDebugDecorator( Dbg() );
228 }
229
230 startItem->Unmark( MK_LOCKED );
231
232 PNS_DBG( Dbg(), Message, wxString::Format( "StartDragging: item %p [kind %d]",
233 startItem, (int) startItem->Kind() ) );
234
235 switch( startItem->Kind() )
236 {
237 case ITEM::SEGMENT_T:
238 {
239 SEGMENT* seg = static_cast<SEGMENT*>( startItem );
240 VVIA* vvia = checkVirtualVia( aP, seg );
241
242 if( vvia )
243 {
244 return startDragVia( vvia );
245 }
246 else
247 {
248 return startDragSegment( aP, seg );
249 }
250 }
251 case ITEM::VIA_T:
252 return startDragVia( static_cast<VIA*>( startItem ) );
253
254 case ITEM::ARC_T:
255 return startDragArc( aP, static_cast<ARC*>( startItem ) );
256
257 default:
258 return false;
259 }
260}
virtual LOGGER * Logger()
bool startDragSegment(const VECTOR2D &aP, SEGMENT *aSeg)
bool startDragVia(VIA *aVia)
VVIA * checkVirtualVia(const VECTOR2D &aP, SEGMENT *aSeg)
Definition: pns_dragger.cpp:71
bool startDragArc(const VECTOR2D &aP, ARC *aArc)
PNS_MODE Mode() const
Set the routing mode.
@ DM_FREE_ANGLE
Definition: pns_router.h:75
@ MK_LOCKED
Definition: pns_item.h:43
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References PNS::MOUSE_TRAIL_TRACER::AddTrailPoint(), PNS::ITEM::ARC_T, checkVirtualVia(), PNS::ITEM_SET::Clear(), PNS::MOUSE_TRAIL_TRACER::Clear(), PNS::ALGO_BASE::Dbg(), PNS::DM_FREE_ANGLE, PNS::ITEM_SET::Empty(), Format(), PNS::ITEM::Kind(), PNS::ALGO_BASE::Logger(), m_currentMode, m_draggedItems, m_freeAngleMode, m_lastNode, m_lastValidPoint, m_mode, m_mouseTrailTracer, m_shove, PNS::DRAG_ALGO::m_world, PNS::MK_LOCKED, PNS::ROUTING_SETTINGS::Mode(), PNS_DBG, 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 156 of file pns_dragger.cpp.

157{
159 m_shove->SetInitialLine( m_draggedLine );
160 m_mode = DM_ARC;
161
162 return true;
163}
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=nullptr, bool aStopAtLockedJoints=false, bool aFollowLockedSegments=false)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
Definition: pns_node.cpp:983
@ DM_ARC
Definition: pns_router.h:76

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 112 of file pns_dragger.cpp.

113{
114 int w2 = aSeg->Width() / 2;
115
118
119 if( m_shove )
120 {
121 m_shove->SetInitialLine( m_draggedLine );
122 }
123
124 auto distA = ( aP - aSeg->Seg().A ).EuclideanNorm();
125 auto distB = ( aP - aSeg->Seg().B ).EuclideanNorm();
126
127 if( distA <= w2 )
128 {
130 }
131 else if( distB <= w2 )
132 {
135 }
136 else if( m_freeAngleMode )
137 {
138 if( distB < distA &&
140 ( !m_draggedLine.CLine().IsPtOnArc( static_cast<size_t>(m_draggedSegmentIndex) + 1 ) ) )
141 {
143 }
144
146 }
147 else
148 {
150 }
151
152 return true;
153}
const SHAPE_LINE_CHAIN & CLine() const
Definition: pns_line.h:137
int PointCount() const
Definition: pns_line.h:140
bool IsPtOnArc(size_t aPtIndex) const

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

Referenced by Start().

◆ startDragVia()

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

Definition at line 166 of file pns_dragger.cpp.

167{
168 m_initialVia = aVia->MakeHandle();
170
171 m_mode = DM_VIA;
172
173 return true;
174}

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 751 of file pns_dragger.cpp.

752{
753 return m_draggedItems;
754}

References m_draggedItems.

◆ tryWalkaround()

bool PNS::DRAGGER::tryWalkaround ( NODE aNode,
LINE aOrig,
LINE aWalk 
)
private

Definition at line 494 of file pns_dragger.cpp.

495{
496 WALKAROUND walkaround( aNode, Router() );
497 bool ok = false;
498 walkaround.SetSolidsOnly( false );
499 walkaround.SetDebugDecorator( Dbg() );
500 walkaround.SetLogger( Logger() );
501 walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
502
503 aWalk = aOrig;
504
505 WALKAROUND::RESULT wr = walkaround.Route( aWalk );
506
507 if( wr.statusCcw == WALKAROUND::DONE && wr.statusCw == WALKAROUND::DONE )
508 {
509 if( wr.lineCw.CLine().PointCount() > 1
510 && wr.lineCw.CLine().Length() < wr.lineCcw.CLine().Length() )
511 {
512 aWalk = wr.lineCw;
513 ok = true;
514 }
515 else if( wr.lineCcw.CLine().PointCount() > 1 )
516 {
517 aWalk = wr.lineCcw;
518 ok = true;
519 }
520 }
521 else if( wr.statusCw == WALKAROUND::DONE && wr.lineCw.CLine().PointCount() > 1 )
522 {
523 aWalk = wr.lineCw;
524 ok = true;
525 }
526 else if( wr.statusCcw == WALKAROUND::DONE && wr.lineCcw.CLine().PointCount() > 1 )
527 {
528 aWalk = wr.lineCcw;
529 ok = true;
530 }
531
532 return ok;
533}

References PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), PNS::WALKAROUND::DONE, SHAPE_LINE_CHAIN::Length(), PNS::WALKAROUND::RESULT::lineCcw, PNS::WALKAROUND::RESULT::lineCw, PNS::ALGO_BASE::Logger(), SHAPE_LINE_CHAIN::PointCount(), 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::WALKAROUND::RESULT::statusCcw, and PNS::WALKAROUND::RESULT::statusCw.

Referenced by dragViaWalkaround(), and dragWalkaround().

◆ VisibleViewArea()

const BOX2I & PNS::ALGO_BASE::VisibleViewArea ( ) const
inherited

Definition at line 40 of file pns_algo_base.cpp.

41{
42 return m_router->VisibleViewArea();
43}
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:211

References PNS::ALGO_BASE::m_router, and PNS::ROUTER::VisibleViewArea().

Referenced by optimizeAndUpdateDraggedLine(), and PNS::SHOVE::runOptimizer().

Member Data Documentation

◆ m_currentMode

PNS_MODE PNS::DRAGGER::m_currentMode
private

Definition at line 142 of file pns_dragger.h.

Referenced by Drag(), and Start().

◆ m_debugDecorator

DEBUG_DECORATOR* PNS::ALGO_BASE::m_debugDecorator
protectedinherited

Definition at line 86 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 degrees corners.

Definition at line 147 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 133 of file pns_dragger.h.

Referenced by dragShove(), and startDragVia().

◆ m_dragStatus

bool PNS::DRAGGER::m_dragStatus
private

Definition at line 141 of file pns_dragger.h.

Referenced by 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 132 of file pns_dragger.h.

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

◆ m_lastDragSolution

LINE PNS::DRAGGER::m_lastDragSolution
private

Definition at line 138 of file pns_dragger.h.

Referenced by dragShove(), and startDragSegment().

◆ m_lastNode

◆ m_lastValidPoint

VECTOR2D PNS::DRAGGER::m_lastValidPoint
private

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

Definition at line 144 of file pns_dragger.h.

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

◆ m_logger

LOGGER* PNS::ALGO_BASE::m_logger
protectedinherited

Definition at line 88 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::SetLogger().

◆ m_mode

int PNS::DRAGGER::m_mode
private

◆ m_mouseTrailTracer

MOUSE_TRAIL_TRACER PNS::DRAGGER::m_mouseTrailTracer
private

Definition at line 151 of file pns_dragger.h.

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

◆ m_origViaConnections

ITEM_SET PNS::DRAGGER::m_origViaConnections
private

Definition at line 143 of file pns_dragger.h.

◆ m_router

◆ m_shove

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

Definition at line 139 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: