KiCad PCB EDA Suite
PNS::SHOVE Class Reference

The actual Push and Shove algorithm. More...

#include <pns_shove.h>

Inheritance diagram for PNS::SHOVE:
PNS::ALGO_BASE

Classes

struct  SPRINGBACK_TAG
 

Public Types

enum  SHOVE_STATUS {
  SH_OK = 0 , SH_NULL , SH_INCOMPLETE , SH_HEAD_MODIFIED ,
  SH_TRY_WALK
}
 

Public Member Functions

 SHOVE (NODE *aWorld, ROUTER *aRouter)
 
 ~SHOVE ()
 
virtual LOGGERLogger () override
 
SHOVE_STATUS ShoveLines (const LINE &aCurrentHead)
 
SHOVE_STATUS ShoveMultiLines (const ITEM_SET &aHeadSet)
 
SHOVE_STATUS ShoveDraggingVia (const VIA_HANDLE aOldVia, const VECTOR2I &aWhere, VIA_HANDLE &aNewVia)
 
SHOVE_STATUS ShoveObstacleLine (const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
 
void ForceClearance (bool aEnabled, int aClearance)
 
NODECurrentNode ()
 
const LINE NewHead () const
 
void SetInitialLine (LINE &aInitial)
 
bool AddLockedSpringbackNode (NODE *aNode)
 
void UnlockSpringbackNode (NODE *aNode)
 
bool RewindSpringbackTo (NODE *aNode)
 
bool RewindToLastLockedNode ()
 
void DisablePostShoveOptimizations (int aMask)
 
void SetSpringbackDoNotTouchNode (NODE *aNode)
 
ROUTERRouter () const
 Return current router settings. More...
 
ROUTING_SETTINGSSettings () const
 Return the logger object, allowing to dump geometry to a file. More...
 
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

DEBUG_DECORATORm_debugDecorator
 
ROUTERm_router
 

Private Types

typedef std::vector< SHAPE_LINE_CHAINHULL_SET
 
typedef OPT< LINEOPT_LINE
 
typedef std::pair< LINE, LINELINE_PAIR
 
typedef std::vector< LINE_PAIRLINE_PAIR_VEC
 

Private Member Functions

SHOVE_STATUS shoveLineToHullSet (const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine, const HULL_SET &aHulls)
 
NODEreduceSpringback (const ITEM_SET &aHeadSet, VIA_HANDLE &aDraggedVia)
 
bool pushSpringback (NODE *aNode, const OPT_BOX2I &aAffectedArea, VIA *aDraggedVia)
 
SHOVE_STATUS shoveLineFromLoneVia (const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
 
bool checkShoveDirection (const LINE &aCurLine, const LINE &aObstacleLine, const LINE &aShovedLine) const
 
SHOVE_STATUS onCollidingArc (LINE &aCurrent, ARC *aObstacleArc)
 
SHOVE_STATUS onCollidingLine (LINE &aCurrent, LINE &aObstacle)
 
SHOVE_STATUS onCollidingSegment (LINE &aCurrent, SEGMENT *aObstacleSeg)
 
SHOVE_STATUS onCollidingSolid (LINE &aCurrent, ITEM *aObstacle, OBSTACLE &aObstacleInfo)
 
SHOVE_STATUS onCollidingVia (ITEM *aCurrent, VIA *aObstacleVia, OBSTACLE &aObstacleInfo)
 
SHOVE_STATUS onReverseCollidingVia (LINE &aCurrent, VIA *aObstacleVia)
 
SHOVE_STATUS pushOrShoveVia (VIA *aVia, const VECTOR2I &aForce, int aCurrentRank)
 
OPT_BOX2I totalAffectedArea () const
 
void unwindLineStack (LINKED_ITEM *aSeg)
 
void unwindLineStack (ITEM *aItem)
 
void runOptimizer (NODE *aNode)
 
bool pushLineStack (const LINE &aL, bool aKeepCurrentOnTop=false)
 
void popLineStack ()
 
LINE assembleLine (const LINKED_ITEM *aSeg, int *aIndex=nullptr)
 
void replaceItems (ITEM *aOld, std::unique_ptr< ITEM > aNew)
 
void replaceLine (LINE &aOld, LINE &aNew, bool aIncludeInChangedArea=true, NODE *aNode=nullptr)
 
LINEfindRootLine (LINE *aLine)
 
SHOVE_STATUS shoveIteration (int aIter)
 
SHOVE_STATUS shoveMainLoop ()
 
int getClearance (const ITEM *aA, const ITEM *aB) const
 
int getHoleClearance (const ITEM *aA, const ITEM *aB) const
 
bool fixupViaCollisions (const LINE *aCurrent, OBSTACLE &obs)
 
void sanityCheck (LINE *aOld, LINE *aNew)
 

Private Attributes

OPT_BOX2I m_affectedArea
 
std::vector< SPRINGBACK_TAGm_nodeStack
 
std::vector< LINEm_lineStack
 
std::vector< LINEm_optimizerQueue
 
std::unordered_map< const LINKED_ITEM *, LINE * > m_rootLineHistory
 
NODEm_root
 
NODEm_currentNode
 
NODEm_springbackDoNotTouchNode
 
int m_restrictSpringbackTagId
 
OPT_LINE m_newHead
 
LOGGER m_logger
 
VIAm_draggedVia
 
int m_iter
 
int m_forceClearance
 
bool m_multiLineMode
 
int m_optFlagDisableMask
 

Detailed Description

The actual Push and Shove algorithm.

Definition at line 45 of file pns_shove.h.

Member Typedef Documentation

◆ HULL_SET

typedef std::vector<SHAPE_LINE_CHAIN> PNS::SHOVE::HULL_SET
private

Definition at line 96 of file pns_shove.h.

◆ LINE_PAIR

typedef std::pair<LINE, LINE> PNS::SHOVE::LINE_PAIR
private

Definition at line 98 of file pns_shove.h.

◆ LINE_PAIR_VEC

typedef std::vector<LINE_PAIR> PNS::SHOVE::LINE_PAIR_VEC
private

Definition at line 99 of file pns_shove.h.

◆ OPT_LINE

typedef OPT<LINE> PNS::SHOVE::OPT_LINE
private

Definition at line 97 of file pns_shove.h.

Member Enumeration Documentation

◆ SHOVE_STATUS

Enumerator
SH_OK 
SH_NULL 
SH_INCOMPLETE 
SH_HEAD_MODIFIED 
SH_TRY_WALK 

Definition at line 49 of file pns_shove.h.

50 {
51 SH_OK = 0,
52 SH_NULL,
56 };
@ SH_INCOMPLETE
Definition: pns_shove.h:53
@ SH_HEAD_MODIFIED
Definition: pns_shove.h:54
@ SH_TRY_WALK
Definition: pns_shove.h:55

Constructor & Destructor Documentation

◆ SHOVE()

PNS::SHOVE::SHOVE ( NODE aWorld,
ROUTER aRouter 
)

Definition at line 157 of file pns_shove.cpp.

157 :
158 ALGO_BASE( aRouter )
159{
161 m_forceClearance = -1;
162 m_root = aWorld;
163 m_currentNode = aWorld;
164 SetDebugDecorator( aRouter->GetInterface()->GetDebugDecorator() );
165
166 // Initialize other temporary variables:
167 m_draggedVia = nullptr;
168 m_iter = 0;
169 m_multiLineMode = false;
172}
void SetDebugDecorator(DEBUG_DECORATOR *aDecorator)
Assign a debug decorator allowing this algo to draw extra graphics for visual debugging.
Definition: pns_algo_base.h:73
ALGO_BASE(ROUTER *aRouter)
Definition: pns_algo_base.h:45
int m_iter
Definition: pns_shove.h:183
NODE * m_currentNode
Definition: pns_shove.h:174
int m_forceClearance
Definition: pns_shove.h:184
int m_restrictSpringbackTagId
Definition: pns_shove.h:176
NODE * m_root
Definition: pns_shove.h:173
NODE * m_springbackDoNotTouchNode
Definition: pns_shove.h:175
bool m_multiLineMode
Definition: pns_shove.h:185
int m_optFlagDisableMask
Definition: pns_shove.h:187
VIA * m_draggedVia
Definition: pns_shove.h:181

References PNS::ROUTER_IFACE::GetDebugDecorator(), PNS::ROUTER::GetInterface(), m_currentNode, m_draggedVia, m_forceClearance, m_iter, m_multiLineMode, m_optFlagDisableMask, m_restrictSpringbackTagId, m_root, m_springbackDoNotTouchNode, and PNS::ALGO_BASE::SetDebugDecorator().

◆ ~SHOVE()

PNS::SHOVE::~SHOVE ( )

Definition at line 175 of file pns_shove.cpp.

176{
177 std::unordered_set<LINE*> alreadyDeleted;
178
179 for( auto it : m_rootLineHistory )
180 {
181 auto it2 = alreadyDeleted.find( it.second );
182
183 if( it2 == alreadyDeleted.end() )
184 {
185 alreadyDeleted.insert( it.second );
186 delete it.second;
187 }
188 }
189}
std::unordered_map< const LINKED_ITEM *, LINE * > m_rootLineHistory
Definition: pns_shove.h:171

References m_rootLineHistory.

Member Function Documentation

◆ AddLockedSpringbackNode()

bool PNS::SHOVE::AddLockedSpringbackNode ( NODE aNode)

Definition at line 1960 of file pns_shove.cpp.

1961{
1962 SPRINGBACK_TAG sp;
1963 sp.m_node = aNode;
1964 sp.m_locked = true;
1965
1966 m_nodeStack.push_back(sp);
1967 return true;
1968}
std::vector< SPRINGBACK_TAG > m_nodeStack
Definition: pns_shove.h:168

References PNS::SHOVE::SPRINGBACK_TAG::m_locked, PNS::SHOVE::SPRINGBACK_TAG::m_node, and m_nodeStack.

◆ assembleLine()

LINE PNS::SHOVE::assembleLine ( const LINKED_ITEM aSeg,
int *  aIndex = nullptr 
)
private

Definition at line 192 of file pns_shove.cpp.

193{
194 return m_currentNode->AssembleLine( const_cast<LINKED_ITEM*>( aSeg ), aIndex, true );
195}
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

References PNS::NODE::AssembleLine(), and m_currentNode.

Referenced by onCollidingArc(), onCollidingSegment(), onReverseCollidingVia(), pushOrShoveVia(), and shoveIteration().

◆ checkShoveDirection()

bool PNS::SHOVE::checkShoveDirection ( const LINE aCurLine,
const LINE aObstacleLine,
const LINE aShovedLine 
) const
private

Definition at line 206 of file pns_shove.cpp.

208{
209 SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER checker( aCurLine.CPoint( 0) );
210 checker.AddPolyline( aObstacleLine.CLine() );
211 checker.AddPolyline( aShovedLine.CLine().Reverse() );
212
213 bool inside = checker.IsInside();
214
215 return !inside;
216}
A dynamic state checking if a point lies within polygon with a dynamically built outline ( with each ...

References SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::AddPolyline(), PNS::LINE::CLine(), PNS::LINE::CPoint(), SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER::IsInside(), and SHAPE_LINE_CHAIN::Reverse().

Referenced by shoveLineToHullSet().

◆ CurrentNode()

NODE * PNS::SHOVE::CurrentNode ( )

Definition at line 1939 of file pns_shove.cpp.

1940{
1941 return m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
1942}

References m_nodeStack, and m_root.

◆ Dbg()

◆ DisablePostShoveOptimizations()

void PNS::SHOVE::DisablePostShoveOptimizations ( int  aMask)

Definition at line 2029 of file pns_shove.cpp.

2030{
2031 m_optFlagDisableMask = aMask;
2032}

References m_optFlagDisableMask.

◆ findRootLine()

LINE * PNS::SHOVE::findRootLine ( LINE aLine)
private

Definition at line 1838 of file pns_shove.cpp.

1839{
1840 for( auto link : aLine->Links() )
1841 {
1842 if( auto seg = dyn_cast<SEGMENT*>( link ) )
1843 {
1844 auto it = m_rootLineHistory.find( seg );
1845
1846 if( it != m_rootLineHistory.end() )
1847 return it->second;
1848 }
1849 }
1850
1851 return nullptr;
1852}

References PNS::LINK_HOLDER::Links(), and m_rootLineHistory.

Referenced by runOptimizer().

◆ fixupViaCollisions()

bool PNS::SHOVE::fixupViaCollisions ( const LINE aCurrent,
OBSTACLE obs 
)
private

Definition at line 1242 of file pns_shove.cpp.

1243{
1244 // if the current obstacle is a via, consider also the lines connected to it
1245 // if their widths are larger or equal than the via diameter, the shove algorithm
1246 // will very likely fail in the subsequent iterations (as our base assumption is track
1247 // ends can never move on their own, only dragged by force-propagated vias
1248
1249 // our colliding item is a via: just find the max width of the traces connected to it
1250 if( obs.m_item->OfKind( ITEM::VIA_T ) )
1251 {
1252 VIA* v = static_cast<VIA*>( obs.m_item );
1253 int maxw = 0;
1254 JOINT* jv = m_currentNode->FindJoint( v->Pos(), v );
1255
1256 for( auto link : jv->Links() )
1257 {
1258 if( link.item->OfKind( ITEM::SEGMENT_T ) ) // consider segments ...
1259 {
1260 auto seg = static_cast<SEGMENT*>( link.item );
1261 maxw = std::max( seg->Width(), maxw );
1262 }
1263 else if( link.item->OfKind( ITEM::ARC_T ) ) // ... or arcs
1264 {
1265 auto arc = static_cast<ARC*>( link.item );
1266 maxw = std::max( arc->Width(), maxw );
1267 }
1268 }
1269
1270 obs.m_maxFanoutWidth = 0;
1271
1272 if( maxw > 0 && maxw >= v->Diameter() )
1273 {
1274 obs.m_maxFanoutWidth = maxw + 1;
1275 PNS_DBG( Dbg(), Message,
1276 wxString::Format( "Fixup via: new-w %d via-w %d", maxw, v->Diameter() ) );
1277
1278 return true;
1279 }
1280 return false;
1281 }
1282
1283
1284 // our colliding item is a segment. check if it has a via on either of the ends.
1285 if( !obs.m_item->OfKind( ITEM::SEGMENT_T ) )
1286 return false;
1287
1288 auto s = static_cast<SEGMENT*>( obs.m_item );
1289
1290 JOINT* ja = m_currentNode->FindJoint( s->Seg().A, s );
1291 JOINT* jb = m_currentNode->FindJoint( s->Seg().B, s );
1292
1293 VIA* vias[] = { ja->Via(), jb->Via() };
1294
1295 for( int i = 0; i < 2; i++ )
1296 {
1297 VIA* v = vias[i];
1298
1299 // via diameter is larger than the segment width - cool, the force propagation algo
1300 // will be able to deal with it, no need to intervene
1301 if( !v || v->Diameter() > s->Width() )
1302 continue;
1303
1304 VIA vtest( *v );
1305 vtest.SetDiameter( s->Width() );
1306
1307 // enlarge the via to the width of the segment
1308 if( vtest.Collide( aCurrent, m_currentNode ) )
1309 {
1310 // if colliding, drop the segment in the shove iteration loop and force-propagate the via instead
1311 obs.m_item = v;
1312 obs.m_maxFanoutWidth = s->Width() + 1;
1313 return true;
1314 }
1315 }
1316 return false;
1317}
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
@ SEGMENT_T
Definition: pns_item.h:66
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
#define PNS_DBG(dbg, method,...)
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
@ VIA
Normal via.
Definition: router_tool.cpp:76

References PNS::ITEM::ARC_T, PNS::ITEM::Collide(), PNS::ALGO_BASE::Dbg(), PNS::VIA::Diameter(), PNS::NODE::FindJoint(), Format(), PNS::JOINT::Links(), m_currentNode, PNS::OBSTACLE::m_item, PNS::OBSTACLE::m_maxFanoutWidth, PNS::ITEM::OfKind(), PNS_DBG, PNS::VIA::Pos(), PNS::ITEM::SEGMENT_T, PNS::VIA::SetDiameter(), PNS::JOINT::Via(), and PNS::ITEM::VIA_T.

Referenced by shoveIteration().

◆ ForceClearance()

void PNS::SHOVE::ForceClearance ( bool  aEnabled,
int  aClearance 
)
inline

Definition at line 74 of file pns_shove.h.

75 {
76 if( aEnabled )
77 m_forceClearance = aClearance;
78 else
80 }

References m_forceClearance.

Referenced by PNS::DIFF_PAIR_PLACER::attemptWalk().

◆ getClearance()

int PNS::SHOVE::getClearance ( const ITEM aA,
const ITEM aB 
) const
private

Definition at line 132 of file pns_shove.cpp.

133{
134 if( m_forceClearance >= 0 )
135 return m_forceClearance;
136
137 return m_currentNode->GetClearance( aA, aB );
138}
int GetClearance(const ITEM *aA, const ITEM *aB, bool aUseClearanceEpsilon=true) const
Definition: pns_node.cpp:103

References PNS::NODE::GetClearance(), m_currentNode, and m_forceClearance.

Referenced by onCollidingVia(), shoveLineFromLoneVia(), and ShoveObstacleLine().

◆ getHoleClearance()

int PNS::SHOVE::getHoleClearance ( const ITEM aA,
const ITEM aB 
) const
private

Definition at line 141 of file pns_shove.cpp.

142{
143 if( m_forceClearance >= 0 )
144 return m_forceClearance;
145
146 return m_currentNode->GetHoleClearance( aA, aB );
147}
int GetHoleClearance(const ITEM *aA, const ITEM *aB, bool aUseClearanceEpsilon=true) const
Definition: pns_node.cpp:115

References PNS::NODE::GetHoleClearance(), m_currentNode, and m_forceClearance.

◆ Logger()

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

Reimplemented from PNS::ALGO_BASE.

Definition at line 61 of file pns_shove.h.

62 {
63 return &m_logger;
64 }
LOGGER m_logger
Definition: pns_shove.h:180

References m_logger.

◆ NewHead()

const LINE PNS::SHOVE::NewHead ( ) const

Definition at line 1945 of file pns_shove.cpp.

1946{
1947 assert( m_newHead );
1948
1949 return *m_newHead;
1950}
OPT_LINE m_newHead
Definition: pns_shove.h:178

References m_newHead.

◆ onCollidingArc()

SHOVE::SHOVE_STATUS PNS::SHOVE::onCollidingArc ( LINE aCurrent,
ARC aObstacleArc 
)
private

Definition at line 556 of file pns_shove.cpp.

557{
558 int segIndex;
559 LINE obstacleLine = assembleLine( aObstacleArc, &segIndex );
560 LINE shovedLine( obstacleLine );
561 ARC tmp( *aObstacleArc );
562
563 if( obstacleLine.HasLockedSegments() )
564 return SH_TRY_WALK;
565
566 SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, obstacleLine, shovedLine );
567
568 const double extensionWalkThreshold = 1.0;
569
570 double obsLen = obstacleLine.CLine().Length();
571 double shovedLen = shovedLine.CLine().Length();
572 double extensionFactor = 0.0;
573
574 if( obsLen != 0.0f )
575 extensionFactor = shovedLen / obsLen - 1.0;
576
577 if( extensionFactor > extensionWalkThreshold )
578 return SH_TRY_WALK;
579
580 assert( obstacleLine.LayersOverlap( &shovedLine ) );
581
582 PNS_DBG( Dbg(), AddItem, &tmp, WHITE, 10000, wxT( "obstacle-arc" ) );
583 PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) );
584 PNS_DBG( Dbg(), AddItem, &obstacleLine, GREEN, 10000, wxT( "obstacle-line" ) );
585 PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 10000, wxT( "shoved-line" ) );
586
587 if( rv == SH_OK )
588 {
589 if( shovedLine.Marker() & MK_HEAD )
590 {
591 if( m_multiLineMode )
592 return SH_INCOMPLETE;
593
594 m_newHead = shovedLine;
595 }
596
597 int rank = aCurrent.Rank();
598 shovedLine.SetRank( rank - 1 );
599
600 sanityCheck( &obstacleLine, &shovedLine );
601 replaceLine( obstacleLine, shovedLine );
602
603 if( !pushLineStack( shovedLine ) )
604 rv = SH_INCOMPLETE;
605 }
606
607 return rv;
608}
SHOVE_STATUS ShoveObstacleLine(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
Definition: pns_shove.cpp:405
LINE assembleLine(const LINKED_ITEM *aSeg, int *aIndex=nullptr)
Definition: pns_shove.cpp:192
bool pushLineStack(const LINE &aL, bool aKeepCurrentOnTop=false)
Definition: pns_shove.cpp:1192
void replaceLine(LINE &aOld, LINE &aNew, bool aIncludeInChangedArea=true, NODE *aNode=nullptr)
Definition: pns_shove.cpp:62
void sanityCheck(LINE *aOld, LINE *aNew)
Definition: pns_shove.cpp:150
@ WHITE
Definition: color4d.h:48
@ BLUE
Definition: color4d.h:56
@ GREEN
Definition: color4d.h:57
@ RED
Definition: color4d.h:59
@ MK_HEAD
Definition: pns_item.h:41

References assembleLine(), BLUE, PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), GREEN, PNS::LINE::HasLockedSegments(), PNS::ITEM::LayersOverlap(), SHAPE_LINE_CHAIN::Length(), m_multiLineMode, m_newHead, PNS::LINE::Marker(), PNS::MK_HEAD, PNS_DBG, pushLineStack(), PNS::LINE::Rank(), RED, replaceLine(), sanityCheck(), PNS::LINE::SetRank(), SH_INCOMPLETE, SH_OK, SH_TRY_WALK, ShoveObstacleLine(), and WHITE.

Referenced by shoveIteration().

◆ onCollidingLine()

SHOVE::SHOVE_STATUS PNS::SHOVE::onCollidingLine ( LINE aCurrent,
LINE aObstacle 
)
private

Definition at line 614 of file pns_shove.cpp.

615{
616 LINE shovedLine( aObstacle );
617
618 SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, aObstacle, shovedLine );
619
620 PNS_DBG( Dbg(), AddItem, &aObstacle, RED, 100000, wxT( "obstacle-line" ) );
621 PNS_DBG( Dbg(), AddItem, &aCurrent, GREEN, 150000, wxT( "current-line" ) );
622 PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 200000, wxT( "shoved-line" ) );
623
624 if( rv == SH_OK )
625 {
626 if( shovedLine.Marker() & MK_HEAD )
627 {
628 if( m_multiLineMode )
629 return SH_INCOMPLETE;
630
631 m_newHead = shovedLine;
632 }
633
634 sanityCheck( &aObstacle, &shovedLine );
635 replaceLine( aObstacle, shovedLine );
636
637 int rank = aObstacle.Rank();
638 shovedLine.SetRank( rank - 1 );
639
640
641 if( !pushLineStack( shovedLine ) )
642 {
643 rv = SH_INCOMPLETE;
644 }
645 }
646
647 return rv;
648}

References BLUE, PNS::ALGO_BASE::Dbg(), GREEN, m_multiLineMode, m_newHead, PNS::LINE::Marker(), PNS::MK_HEAD, PNS_DBG, pushLineStack(), PNS::LINE::Rank(), RED, replaceLine(), sanityCheck(), PNS::LINE::SetRank(), SH_INCOMPLETE, SH_OK, and ShoveObstacleLine().

Referenced by shoveIteration().

◆ onCollidingSegment()

SHOVE::SHOVE_STATUS PNS::SHOVE::onCollidingSegment ( LINE aCurrent,
SEGMENT aObstacleSeg 
)
private

Definition at line 492 of file pns_shove.cpp.

493{
494 int segIndex;
495 LINE obstacleLine = assembleLine( aObstacleSeg, &segIndex );
496 LINE shovedLine( obstacleLine );
497 SEGMENT tmp( *aObstacleSeg );
498
499 if( obstacleLine.HasLockedSegments() )
500 {
501 PNS_DBG(Dbg(), Message, "try walk (locked segments)");
502 return SH_TRY_WALK;
503 }
504
505 SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, obstacleLine, shovedLine );
506
507 const double extensionWalkThreshold = 1.0;
508
509 double obsLen = obstacleLine.CLine().Length();
510 double shovedLen = shovedLine.CLine().Length();
511 double extensionFactor = 0.0;
512
513 if( obsLen != 0.0f )
514 extensionFactor = shovedLen / obsLen - 1.0;
515
516 if( extensionFactor > extensionWalkThreshold )
517 return SH_TRY_WALK;
518
519 assert( obstacleLine.LayersOverlap( &shovedLine ) );
520
521 if( Dbg() )
522 {
523 PNS_DBG( Dbg(), AddItem, aObstacleSeg, BLUE, 0, wxT( "shove-changed-area" ) );
524 PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) );
525 PNS_DBG( Dbg(), AddItem, &obstacleLine, GREEN, 10000, wxT( "obstacle-line" ) );
526 PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 10000, wxT( "shoved-line" ) );
527 }
528
529 if( rv == SH_OK )
530 {
531 if( shovedLine.Marker() & MK_HEAD )
532 {
533 if( m_multiLineMode )
534 return SH_INCOMPLETE;
535
536 m_newHead = shovedLine;
537 }
538
539 int rank = aCurrent.Rank();
540 shovedLine.SetRank( rank - 1 );
541
542 sanityCheck( &obstacleLine, &shovedLine );
543 replaceLine( obstacleLine, shovedLine );
544
545 if( !pushLineStack( shovedLine ) )
546 rv = SH_INCOMPLETE;
547 }
548
549 return rv;
550}

References assembleLine(), BLUE, PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), GREEN, PNS::LINE::HasLockedSegments(), PNS::ITEM::LayersOverlap(), SHAPE_LINE_CHAIN::Length(), m_multiLineMode, m_newHead, PNS::LINE::Marker(), PNS::MK_HEAD, PNS_DBG, pushLineStack(), PNS::LINE::Rank(), RED, replaceLine(), sanityCheck(), PNS::LINE::SetRank(), SH_INCOMPLETE, SH_OK, SH_TRY_WALK, and ShoveObstacleLine().

Referenced by shoveIteration().

◆ onCollidingSolid()

SHOVE::SHOVE_STATUS PNS::SHOVE::onCollidingSolid ( LINE aCurrent,
ITEM aObstacle,
OBSTACLE aObstacleInfo 
)
private

Definition at line 654 of file pns_shove.cpp.

655{
656 WALKAROUND walkaround( m_currentNode, Router() );
657 LINE walkaroundLine( aCurrent );
658
659 if( aCurrent.EndsWithVia() )
660 {
661 VIA vh = aCurrent.Via();
662 VIA* via = nullptr;
663 JOINT* jtStart = m_currentNode->FindJoint( vh.Pos(), &aCurrent );
664
665 if( !jtStart )
666 return SH_INCOMPLETE;
667
668 for( ITEM* item : jtStart->LinkList() )
669 {
670 if( item->OfKind( ITEM::VIA_T ) )
671 {
672 via = (VIA*) item;
673 break;
674 }
675 }
676
677 if( via && via->Collide( aObstacle, m_currentNode ) )
678 return onCollidingVia( aObstacle, via, aObstacleInfo );
679 }
680
681 TOPOLOGY topo( m_currentNode );
682
683 std::set<ITEM*> cluster = topo.AssembleCluster( aObstacle, aCurrent.Layers().Start() );
684
685
686
687 PNS_DBG( Dbg(), BeginGroup, "walk-cluster", 1 );
688
689 for( auto item : cluster )
690 {
691 PNS_DBG( Dbg(), AddItem, item, RED, 10000, wxT( "cl-item" ) );
692 }
693
694 PNS_DBGN( Dbg(), EndGroup );
695
696
697 walkaround.SetDebugDecorator( Dbg() );
698 walkaround.SetSolidsOnly( false );
699 walkaround.RestrictToSet( true, cluster );
700 walkaround.SetIterationLimit( 16 ); // fixme: make configurable
701
702 int currentRank = aCurrent.Rank();
703 int nextRank;
704
705 bool success = false;
706
707 for( int attempt = 0; attempt < 2; attempt++ )
708 {
709 if( attempt == 1 || Settings().JumpOverObstacles() )
710 {
711
712 nextRank = currentRank - 1;
713 }
714 else
715 {
716 nextRank = currentRank + 10000;
717 }
718
719
720 WALKAROUND::WALKAROUND_STATUS status = walkaround.Route( aCurrent, walkaroundLine, false );
721
722 if( status != WALKAROUND::DONE )
723 continue;
724
725 walkaroundLine.ClearLinks();
726 walkaroundLine.Unmark();
727 walkaroundLine.Line().Simplify();
728
729 if( walkaroundLine.HasLoops() )
730 continue;
731
732 if( aCurrent.Marker() & MK_HEAD )
733 {
734 walkaroundLine.Mark( MK_HEAD );
735
736 if( m_multiLineMode )
737 continue;
738
739 m_newHead = walkaroundLine;
740 }
741
742 sanityCheck( &aCurrent, &walkaroundLine );
743
744 if( !m_lineStack.empty() )
745 {
746 LINE lastLine = m_lineStack.front();
747
748 if( lastLine.Collide( &walkaroundLine, m_currentNode ) )
749 {
750 LINE dummy( lastLine );
751
752 if( ShoveObstacleLine( walkaroundLine, lastLine, dummy ) == SH_OK )
753 {
754 success = true;
755 break;
756 }
757 }
758 else
759 {
760 success = true;
761 break;
762 }
763 }
764 }
765
766 if(!success)
767 return SH_INCOMPLETE;
768
769 replaceLine( aCurrent, walkaroundLine );
770 walkaroundLine.SetRank( nextRank );
771
772 PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) );
773 PNS_DBG( Dbg(), AddItem, &walkaroundLine, BLUE, 10000, wxT( "walk-line" ) );
774
775 popLineStack();
776
777 if( !pushLineStack( walkaroundLine ) )
778 return SH_INCOMPLETE;
779
780 return SH_OK;
781}
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
ROUTING_SETTINGS & Settings() const
Return the logger object, allowing to dump geometry to a file.
std::vector< LINE > m_lineStack
Definition: pns_shove.h:169
void popLineStack()
Definition: pns_shove.cpp:1216
SHOVE_STATUS onCollidingVia(ITEM *aCurrent, VIA *aObstacleVia, OBSTACLE &aObstacleInfo)
Definition: pns_shove.cpp:990
#define PNS_DBGN(dbg, method)
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:73

References PNS::TOPOLOGY::AssembleCluster(), BLUE, PNS::LINK_HOLDER::ClearLinks(), PNS::ITEM::Collide(), PNS::ALGO_BASE::Dbg(), PNS::WALKAROUND::DONE, dummy(), PNS::LINE::EndsWithVia(), PNS::NODE::FindJoint(), PNS::LINE::HasLoops(), PNS::ITEM::Layers(), PNS::LINE::Line(), PNS::JOINT::LinkList(), m_currentNode, m_lineStack, m_multiLineMode, m_newHead, PNS::LINE::Mark(), PNS::LINE::Marker(), PNS::MK_HEAD, onCollidingVia(), PNS_DBG, PNS_DBGN, popLineStack(), PNS::VIA::Pos(), pushLineStack(), PNS::LINE::Rank(), RED, replaceLine(), PNS::WALKAROUND::RestrictToSet(), PNS::WALKAROUND::Route(), PNS::ALGO_BASE::Router(), sanityCheck(), PNS::ALGO_BASE::SetDebugDecorator(), PNS::WALKAROUND::SetIterationLimit(), PNS::LINE::SetRank(), PNS::WALKAROUND::SetSolidsOnly(), PNS::ALGO_BASE::Settings(), SH_INCOMPLETE, SH_OK, ShoveObstacleLine(), SHAPE_LINE_CHAIN::Simplify(), LAYER_RANGE::Start(), PNS::LINE::Unmark(), via, PNS::LINE::Via(), and PNS::ITEM::VIA_T.

Referenced by shoveIteration().

◆ onCollidingVia()

SHOVE::SHOVE_STATUS PNS::SHOVE::onCollidingVia ( ITEM aCurrent,
VIA aObstacleVia,
OBSTACLE aObstacleInfo 
)
private

Definition at line 990 of file pns_shove.cpp.

991{
992 assert( aObstacleVia );
993
994 int clearance = getClearance( aCurrent, aObstacleVia );
995 VECTOR2I mtv;
996 int rank = -1;
997
998 bool lineCollision = false;
999 bool viaCollision = false;
1000 VECTOR2I mtvLine, mtvVia;
1001
1002 PNS_DBG( Dbg(), BeginGroup, "push-via-by-line", 1 );
1003
1004 if( aCurrent->OfKind( ITEM::LINE_T ) )
1005 {
1006 VIA vtmp ( *aObstacleVia );
1007
1008 if( aObstacleInfo.m_maxFanoutWidth > 0 && aObstacleInfo.m_maxFanoutWidth > aObstacleVia->Diameter() )
1009 {
1010 vtmp.SetDiameter( aObstacleInfo.m_maxFanoutWidth );
1011 }
1012
1013 LINE* currentLine = (LINE*) aCurrent;
1014
1015 PNS_DBG( Dbg(), AddItem, currentLine, LIGHTRED, 10000, wxT( "current-line" ) );
1016
1017 if( currentLine->EndsWithVia() )
1018 {
1019 PNS_DBG( Dbg(), AddItem, &currentLine->Via(), LIGHTRED, 10000, wxT( "current-line-via" ) );
1020 }
1021
1022 PNS_DBG( Dbg(), AddItem, &vtmp, LIGHTRED, 100000, wxT( "orig-via" ) );
1023
1024 lineCollision = vtmp.Shape()->Collide( currentLine->Shape(),
1025 clearance + currentLine->Width() / 2,
1026 &mtvLine );
1027
1028 // Check the via if present. Via takes priority.
1029 if( currentLine->EndsWithVia() )
1030 {
1031 const VIA& currentVia = currentLine->Via();
1032 int viaClearance = getClearance( &currentVia, &vtmp );
1033
1034 viaCollision = currentVia.Shape()->Collide( vtmp.Shape(), viaClearance, &mtvVia );
1035 }
1036 }
1037 else if( aCurrent->OfKind( ITEM::SOLID_T ) )
1038 {
1039 // TODO: is this possible at all? We don't shove solids.
1040 return SH_INCOMPLETE;
1041 }
1042
1043 // fixme: we may have a sign issue in Collide(CIRCLE, LINE_CHAIN)
1044 if( viaCollision )
1045 mtv = -mtvVia;
1046 else if ( lineCollision )
1047 mtv = -mtvLine;
1048 else
1049 mtv = VECTOR2I(0, 0);
1050
1051 SHOVE::SHOVE_STATUS st = pushOrShoveVia( aObstacleVia, -mtv, aCurrent->Rank() );
1052 PNS_DBG(Dbg(), Message, wxString::Format("push-or-shove-via st %d", st ) );
1053
1054 PNS_DBGN( Dbg(), EndGroup );
1055
1056 return st;
1057}
@ SOLID_T
Definition: pns_item.h:63
@ LINE_T
Definition: pns_item.h:64
SHOVE_STATUS pushOrShoveVia(VIA *aVia, const VECTOR2I &aForce, int aCurrentRank)
Definition: pns_shove.cpp:863
int getClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_shove.cpp:132
@ LIGHTRED
Definition: color4d.h:65
VECTOR2< int > VECTOR2I
Definition: vector2d.h:607

References SHAPE::Collide(), PNS::ALGO_BASE::Dbg(), PNS::VIA::Diameter(), PNS::LINE::EndsWithVia(), Format(), getClearance(), LIGHTRED, PNS::ITEM::LINE_T, PNS::OBSTACLE::m_maxFanoutWidth, PNS::ITEM::OfKind(), PNS_DBG, PNS_DBGN, pushOrShoveVia(), PNS::ITEM::Rank(), PNS::VIA::SetDiameter(), SH_INCOMPLETE, PNS::LINE::Shape(), PNS::VIA::Shape(), PNS::ITEM::SOLID_T, PNS::LINE::Via(), and PNS::LINE::Width().

Referenced by onCollidingSolid(), and shoveIteration().

◆ onReverseCollidingVia()

SHOVE::SHOVE_STATUS PNS::SHOVE::onReverseCollidingVia ( LINE aCurrent,
VIA aObstacleVia 
)
private

Definition at line 1063 of file pns_shove.cpp.

1064{
1065 int n = 0;
1066 LINE cur( aCurrent );
1067 cur.ClearLinks();
1068
1069 JOINT* jt = m_currentNode->FindJoint( aObstacleVia->Pos(), aObstacleVia );
1070 LINE shoved( aCurrent );
1071 shoved.ClearLinks();
1072
1073 cur.RemoveVia();
1074 unwindLineStack( &aCurrent );
1075
1076 for( ITEM* item : jt->LinkList() )
1077 {
1078 if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) && item->LayersOverlap( &aCurrent ) )
1079 {
1080 LINKED_ITEM* li = static_cast<LINKED_ITEM*>( item );
1081 LINE head = assembleLine( li );
1082
1083 head.AppendVia( *aObstacleVia );
1084
1085 SHOVE_STATUS st = ShoveObstacleLine( head, cur, shoved );
1086
1087 if( st != SH_OK )
1088 {
1089#if 0
1090 m_logger.NewGroup( "on-reverse-via-fail-shove", m_iter );
1091 m_logger.Log( aObstacleVia, 0, "the-via" );
1092 m_logger.Log( &aCurrent, 1, "current-line" );
1093 m_logger.Log( &shoved, 3, "shoved-line" );
1094#endif
1095
1096 return st;
1097 }
1098
1099 cur.SetShape( shoved.CLine() );
1100 n++;
1101 }
1102 }
1103
1104 if( !n )
1105 {
1106#if 0
1107 m_logger.NewGroup( "on-reverse-via-fail-lonevia", m_iter );
1108 m_logger.Log( aObstacleVia, 0, "the-via" );
1109 m_logger.Log( &aCurrent, 1, "current-line" );
1110#endif
1111
1112 LINE head( aCurrent );
1113 head.Line().Clear();
1114 head.AppendVia( *aObstacleVia );
1115 head.ClearLinks();
1116
1117 SHOVE_STATUS st = ShoveObstacleLine( head, aCurrent, shoved );
1118
1119 if( st != SH_OK )
1120 return st;
1121
1122 cur.SetShape( shoved.CLine() );
1123 }
1124
1125 if( aCurrent.EndsWithVia() )
1126 shoved.AppendVia( aCurrent.Via() );
1127
1128#if 0
1129 m_logger.NewGroup( "on-reverse-via", m_iter );
1130 m_logger.Log( aObstacleVia, 0, "the-via" );
1131 m_logger.Log( &aCurrent, 1, "current-line" );
1132 m_logger.Log( &shoved, 3, "shoved-line" );
1133#endif
1134
1135 PNS_DBG( Dbg(), AddItem, aObstacleVia, YELLOW, 0, wxT( "rr-the-via" ) );
1136 PNS_DBG( Dbg(), AddItem, &aCurrent, BLUE, 0, wxT( "rr-current-line" ) );
1137 PNS_DBG( Dbg(), AddItem, &shoved, GREEN, 0, wxT( "rr-shoved-line" ) );
1138
1139 int currentRank = aCurrent.Rank();
1140 replaceLine( aCurrent, shoved );
1141
1142 if( !pushLineStack( shoved ) )
1143 return SH_INCOMPLETE;
1144
1145 shoved.SetRank( currentRank );
1146
1147 return SH_OK;
1148}
void Log(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), const ITEM *item=nullptr)
Definition: pns_logger.cpp:64
void unwindLineStack(LINKED_ITEM *aSeg)
Definition: pns_shove.cpp:1151
@ YELLOW
Definition: color4d.h:67

References PNS::LINE::AppendVia(), PNS::ITEM::ARC_T, assembleLine(), BLUE, SHAPE_LINE_CHAIN::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::ALGO_BASE::Dbg(), PNS::LINE::EndsWithVia(), PNS::NODE::FindJoint(), GREEN, PNS::LINE::Line(), PNS::JOINT::LinkList(), PNS::LOGGER::Log(), m_currentNode, m_iter, m_logger, PNS_DBG, PNS::VIA::Pos(), pushLineStack(), PNS::LINE::Rank(), PNS::LINE::RemoveVia(), replaceLine(), PNS::ITEM::SEGMENT_T, PNS::LINE::SetRank(), PNS::LINE::SetShape(), SH_INCOMPLETE, SH_OK, ShoveObstacleLine(), unwindLineStack(), PNS::LINE::Via(), and YELLOW.

Referenced by shoveIteration().

◆ popLineStack()

void PNS::SHOVE::popLineStack ( )
private

Definition at line 1216 of file pns_shove.cpp.

1217{
1218 LINE& l = m_lineStack.back();
1219
1220 for( std::vector<LINE>::iterator i = m_optimizerQueue.begin(); i != m_optimizerQueue.end(); )
1221 {
1222 bool found = false;
1223
1224 for( LINKED_ITEM* s : l.Links() )
1225 {
1226 if( i->ContainsLink( s ) )
1227 {
1228 i = m_optimizerQueue.erase( i );
1229 found = true;
1230 break;
1231 }
1232 }
1233
1234 if( !found )
1235 i++;
1236 }
1237
1238 m_lineStack.pop_back();
1239}
std::vector< LINE > m_optimizerQueue
Definition: pns_shove.h:170

References PNS::LINK_HOLDER::Links(), m_lineStack, and m_optimizerQueue.

Referenced by onCollidingSolid(), and shoveIteration().

◆ pushLineStack()

bool PNS::SHOVE::pushLineStack ( const LINE aL,
bool  aKeepCurrentOnTop = false 
)
private

Definition at line 1192 of file pns_shove.cpp.

1193{
1194 if( !aL.IsLinkedChecked() && aL.SegmentCount() != 0 )
1195 {
1196 PNS_DBG( Dbg(), AddItem, &aL, BLUE, 10000, wxT( "push line stack failed" ) );
1197
1198 return false;
1199 }
1200
1201 if( aKeepCurrentOnTop && m_lineStack.size() > 0)
1202 {
1203 m_lineStack.insert( m_lineStack.begin() + m_lineStack.size() - 1, aL );
1204 }
1205 else
1206 {
1207 m_lineStack.push_back( aL );
1208 }
1209
1210 m_optimizerQueue.push_back( aL );
1211
1212 return true;
1213}

References BLUE, PNS::ALGO_BASE::Dbg(), PNS::LINE::IsLinkedChecked(), m_lineStack, m_optimizerQueue, PNS_DBG, and PNS::LINE::SegmentCount().

Referenced by onCollidingArc(), onCollidingLine(), onCollidingSegment(), onCollidingSolid(), onReverseCollidingVia(), pushOrShoveVia(), shoveIteration(), ShoveLines(), shoveMainLoop(), and ShoveMultiLines().

◆ pushOrShoveVia()

SHOVE::SHOVE_STATUS PNS::SHOVE::pushOrShoveVia ( VIA aVia,
const VECTOR2I aForce,
int  aCurrentRank 
)
private

Definition at line 863 of file pns_shove.cpp.

864{
865 LINE_PAIR_VEC draggedLines;
866 VECTOR2I p0( aVia->Pos() );
867 JOINT* jt = m_currentNode->FindJoint( p0, aVia );
868 VECTOR2I p0_pushed( p0 + aForce );
869
870 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "via force [%d %d]\n" ), aForce.x, aForce.y ) );
871
872 // nothing to do...
873 if ( aForce.x == 0 && aForce.y == 0 )
874 return SH_OK;
875
876 if( !jt )
877 {
878 PNS_DBG( Dbg(), Message,
879 wxString::Format( wxT( "weird, can't find the center-of-via joint\n" ) ) );
880 return SH_INCOMPLETE;
881 }
882
883 if( aVia->IsLocked() )
884 return SH_TRY_WALK;
885
886 if( jt->IsLocked() )
887 return SH_INCOMPLETE;
888
889 // make sure pushed via does not overlap with any existing joint
890 while( true )
891 {
892 JOINT* jt_next = m_currentNode->FindJoint( p0_pushed, aVia );
893
894 if( !jt_next )
895 break;
896
897 p0_pushed += aForce.Resize( 2 );
898 }
899
900 std::unique_ptr<VIA> pushedVia = Clone( *aVia );
901 pushedVia->SetPos( p0_pushed );
902 pushedVia->Mark( aVia->Marker() );
903
904 for( ITEM* item : jt->LinkList() )
905 {
906 if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
907 {
908 LINKED_ITEM* li = static_cast<LINKED_ITEM*>( item );
909 LINE_PAIR lp;
910 int segIndex;
911
912 lp.first = assembleLine( li, &segIndex );
913
914 if( lp.first.HasLockedSegments() )
915 return SH_TRY_WALK;
916
917 assert( segIndex == 0 || ( segIndex == ( lp.first.SegmentCount() - 1 ) ) );
918
919 if( segIndex == 0 )
920 lp.first.Reverse();
921
922 lp.second = lp.first;
923 lp.second.ClearLinks();
924 lp.second.DragCorner( p0_pushed, lp.second.CLine().Find( p0 ) );
925 lp.second.AppendVia( *pushedVia );
926 draggedLines.push_back( lp );
927 }
928 }
929
930 pushedVia->SetRank( aCurrentRank - 1 );
931 PNS_DBG( Dbg(), Message, wxString::Format("PushViaRank %d\n", pushedVia->Rank() ) );
932
933 if( aVia->Marker() & MK_HEAD ) // push
934 {
935 m_draggedVia = pushedVia.get();
936 }
937 else
938 { // shove
939 if( jt->IsStitchingVia() )
940 pushLineStack( LINE( *pushedVia ) );
941 }
942
943 PNS_DBG( Dbg(), AddPoint, aVia->Pos(), LIGHTGREEN, 100000, "via-pre" );
944 PNS_DBG( Dbg(), AddPoint, pushedVia->Pos(), LIGHTRED, 100000, "via-post" );
945
946 replaceItems( aVia, std::move( pushedVia ) );
947
948 for( LINE_PAIR lp : draggedLines )
949 {
950 if( lp.first.Marker() & MK_HEAD )
951 {
952 lp.second.Mark( MK_HEAD );
953
954 if( m_multiLineMode )
955 return SH_INCOMPLETE;
956
957 m_newHead = lp.second;
958 }
959
960 unwindLineStack( &lp.first );
961
962 if( lp.second.SegmentCount() )
963 {
964 replaceLine( lp.first, lp.second );
965 lp.second.SetRank( aCurrentRank - 1 );
966
967
968 PNS_DBG( Dbg(), Message, wxString::Format("PushViaF %p %d\n", &lp.second, lp.second.SegmentCount() ) );
969
970 if( !pushLineStack( lp.second, true ) )
971 return SH_INCOMPLETE;
972 }
973 else
974 {
975 m_currentNode->Remove( lp.first );
976 }
977
978 PNS_DBG( Dbg(), AddItem, &lp.first, LIGHTGREEN, 10000, wxT( "fan-pre" ) );
979 PNS_DBG( Dbg(), AddItem, &lp.second, LIGHTRED, 10000, wxT( "fan-post" ) );
980 }
981
982 return SH_OK;
983}
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:873
std::pair< LINE, LINE > LINE_PAIR
Definition: pns_shove.h:98
void replaceItems(ITEM *aOld, std::unique_ptr< ITEM > aNew)
Definition: pns_shove.cpp:51
std::vector< LINE_PAIR > LINE_PAIR_VEC
Definition: pns_shove.h:99
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:367
@ LIGHTGREEN
Definition: color4d.h:63
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271

References PNS::ITEM::ARC_T, assembleLine(), PNS::Clone(), PNS::ALGO_BASE::Dbg(), PNS::NODE::FindJoint(), Format(), PNS::ITEM::IsLocked(), PNS::JOINT::IsLocked(), PNS::JOINT::IsStitchingVia(), LIGHTGREEN, LIGHTRED, PNS::JOINT::LinkList(), m_currentNode, m_draggedVia, m_multiLineMode, m_newHead, PNS::ITEM::Marker(), PNS::MK_HEAD, PNS_DBG, PNS::VIA::Pos(), pushLineStack(), PNS::NODE::Remove(), replaceItems(), replaceLine(), VECTOR2< T >::Resize(), PNS::ITEM::SEGMENT_T, SH_INCOMPLETE, SH_OK, SH_TRY_WALK, unwindLineStack(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by onCollidingVia(), and ShoveDraggingVia().

◆ pushSpringback()

bool PNS::SHOVE::pushSpringback ( NODE aNode,
const OPT_BOX2I aAffectedArea,
VIA aDraggedVia 
)
private

Definition at line 823 of file pns_shove.cpp.

824{
825 SPRINGBACK_TAG st;
826 OPT_BOX2I prev_area;
827
828 if( !m_nodeStack.empty() )
829 prev_area = m_nodeStack.back().m_affectedArea;
830
831 if( aDraggedVia )
832 {
833 st.m_draggedVia = aDraggedVia->MakeHandle();
834 }
835
836 st.m_node = aNode;
837
838 if( aAffectedArea )
839 {
840 if( prev_area )
841 st.m_affectedArea = prev_area->Merge( *aAffectedArea );
842 else
843 st.m_affectedArea = aAffectedArea;
844 }
845 else
846 {
847 st.m_affectedArea = prev_area;
848 }
849
850 st.m_seq = ( m_nodeStack.empty() ? 1 : m_nodeStack.back().m_seq + 1 );
851 st.m_locked = false;
852
853 m_nodeStack.push_back( st );
854
855 return true;
856}
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:509

References PNS::SHOVE::SPRINGBACK_TAG::m_affectedArea, PNS::SHOVE::SPRINGBACK_TAG::m_draggedVia, PNS::SHOVE::SPRINGBACK_TAG::m_locked, PNS::SHOVE::SPRINGBACK_TAG::m_node, m_nodeStack, PNS::SHOVE::SPRINGBACK_TAG::m_seq, and PNS::VIA::MakeHandle().

Referenced by ShoveDraggingVia(), ShoveLines(), and ShoveMultiLines().

◆ reduceSpringback()

NODE * PNS::SHOVE::reduceSpringback ( const ITEM_SET aHeadSet,
VIA_HANDLE aDraggedVia 
)
private

Definition at line 788 of file pns_shove.cpp.

789{
790 while( !m_nodeStack.empty() )
791 {
792 SPRINGBACK_TAG& spTag = m_nodeStack.back();
793
794 // Prevent the springback algo from erasing NODEs that might contain items used by the ROUTER_TOOL/LINE_PLACER.
795 // I noticed this can happen for the endItem provided to LINE_PLACER::Move() and cause a nasty crash.
796 if( spTag.m_node == m_springbackDoNotTouchNode )
797 break;
798
799 OPT<OBSTACLE> obs = spTag.m_node->CheckColliding( aHeadSet );
800
801 if( !obs && !spTag.m_locked )
802 {
803 aDraggedVia = spTag.m_draggedVia;
804 aDraggedVia.valid = true;
805
806 delete spTag.m_node;
807 m_nodeStack.pop_back();
808 }
809 else
810 {
811 break;
812 }
813 }
814
815 return m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
816}
boost::optional< T > OPT
Definition: optional.h:7

References PNS::NODE::CheckColliding(), PNS::SHOVE::SPRINGBACK_TAG::m_draggedVia, PNS::SHOVE::SPRINGBACK_TAG::m_locked, PNS::SHOVE::SPRINGBACK_TAG::m_node, m_nodeStack, m_root, m_springbackDoNotTouchNode, and PNS::VIA_HANDLE::valid.

Referenced by ShoveDraggingVia(), ShoveLines(), and ShoveMultiLines().

◆ replaceItems()

void PNS::SHOVE::replaceItems ( ITEM aOld,
std::unique_ptr< ITEM aNew 
)
private

Definition at line 51 of file pns_shove.cpp.

52{
53 OPT_BOX2I changed_area = ChangedArea( aOld, aNew.get() );
54
55 if( changed_area )
56 m_affectedArea = m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
57
58 m_currentNode->Replace( aOld, std::move( aNew ) );
59}
void Replace(ITEM *aOldItem, std::unique_ptr< ITEM > aNewItem)
Replace an item with another one.
Definition: pns_node.cpp:838
OPT_BOX2I m_affectedArea
Definition: pns_shove.h:158
OPT_BOX2I ChangedArea(const ITEM *aItemA, const ITEM *aItemB)
Definition: pns_utils.cpp:353

References PNS::ChangedArea(), m_affectedArea, m_currentNode, and PNS::NODE::Replace().

Referenced by pushOrShoveVia().

◆ replaceLine()

void PNS::SHOVE::replaceLine ( LINE aOld,
LINE aNew,
bool  aIncludeInChangedArea = true,
NODE aNode = nullptr 
)
private

Definition at line 62 of file pns_shove.cpp.

63{
64 if( aIncludeInChangedArea )
65 {
66 OPT_BOX2I changed_area = ChangedArea( aOld, aNew );
67
68 if( changed_area )
69 {
70 SHAPE_RECT r( *changed_area );
71 PNS_DBG(Dbg(), AddShape, &r, BLUE, 0, wxT( "shove-changed-area" ) );
72
74 m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
75 }
76 }
77
78 bool foundPredecessor = false;
79 LINE* rootLine = nullptr;
80
81 // Keep track of the 'root lines', i.e. the unmodified (pre-shove) versions
82 // of the affected tracks in a map. The optimizer can then query the pre-shove shape
83 // for each shoved line and perform additional constraint checks (i.e. prevent overzealous
84 // optimizations)
85
86 // Check if the shoved line already has an ancestor (e.g. line from a previous shove
87 // iteration/cursor movement)
88 for( auto link : aOld.Links() )
89 {
90 auto oldLineIter = m_rootLineHistory.find( link );
91
92 if( oldLineIter != m_rootLineHistory.end() )
93 {
94 rootLine = oldLineIter->second;
95 foundPredecessor = true;
96 break;
97 }
98 }
99
100 // If found, use it, otherwise, create new entry in the map (we have a genuine new 'root' line)
101 if( !foundPredecessor )
102 {
103 for( auto link : aOld.Links() )
104 {
105 if( ! rootLine )
106 {
107 rootLine = aOld.Clone();
108 }
109
110 m_rootLineHistory[link] = rootLine;
111 }
112 }
113
114 // Now update the NODE (calling Replace invalidates the Links() in a LINE)
115 if( aNode )
116 {
117 aNode->Replace( aOld, aNew );
118 }
119 else
120 {
121 m_currentNode->Replace( aOld, aNew );
122 }
123
124 // point the Links() of the new line to its oldest ancestor
125 for( auto link : aNew.Links() )
126 {
127 m_rootLineHistory[ link ] = rootLine;
128 }
129}
E_SERIE r
Definition: eserie.cpp:41

References BLUE, PNS::ChangedArea(), PNS::LINE::Clone(), PNS::ALGO_BASE::Dbg(), PNS::LINK_HOLDER::Links(), m_affectedArea, m_currentNode, m_rootLineHistory, PNS_DBG, r, and PNS::NODE::Replace().

Referenced by onCollidingArc(), onCollidingLine(), onCollidingSegment(), onCollidingSolid(), onReverseCollidingVia(), pushOrShoveVia(), and runOptimizer().

◆ RewindSpringbackTo()

bool PNS::SHOVE::RewindSpringbackTo ( NODE aNode)

Definition at line 1971 of file pns_shove.cpp.

1972{
1973 bool found = false;
1974
1975 auto iter = m_nodeStack.begin();
1976
1977 while( iter != m_nodeStack.end() )
1978 {
1979 if ( iter->m_node == aNode )
1980 {
1981 found = true;
1982 break;
1983 }
1984
1985 iter++;
1986 }
1987
1988 if( !found )
1989 return false;
1990
1991 auto start = iter;
1992
1993 aNode->KillChildren();
1994 m_nodeStack.erase( start, m_nodeStack.end() );
1995
1996 return true;
1997}

References PNS::NODE::KillChildren(), and m_nodeStack.

◆ RewindToLastLockedNode()

bool PNS::SHOVE::RewindToLastLockedNode ( )

Definition at line 2000 of file pns_shove.cpp.

2001{
2002 if( m_nodeStack.empty() )
2003 return false;
2004
2005 while( !m_nodeStack.back().m_locked && m_nodeStack.size() > 1 )
2006 m_nodeStack.pop_back();
2007
2008 return m_nodeStack.back().m_locked;
2009}

References m_nodeStack.

◆ Router()

◆ runOptimizer()

void PNS::SHOVE::runOptimizer ( NODE aNode)
private

Definition at line 1855 of file pns_shove.cpp.

1856{
1857 OPTIMIZER optimizer( aNode );
1858 int optFlags = 0;
1859 int n_passes = 0;
1860
1862
1864
1865 int maxWidth = 0;
1866
1867 for( LINE& line : m_optimizerQueue )
1868 maxWidth = std::max( line.Width(), maxWidth );
1869
1870 if( area )
1871 {
1872 area->Inflate( maxWidth );
1873 area = area->Intersect( VisibleViewArea() );
1874 }
1875
1876 switch( effort )
1877 {
1878 case OE_LOW:
1879 optFlags |= OPTIMIZER::MERGE_OBTUSE;
1880 n_passes = 1;
1881 break;
1882
1883 case OE_MEDIUM:
1884 optFlags |= OPTIMIZER::MERGE_SEGMENTS;
1885
1886 n_passes = 2;
1887 break;
1888
1889 case OE_FULL:
1890 optFlags = OPTIMIZER::MERGE_SEGMENTS;
1891 n_passes = 2;
1892 break;
1893
1894 default:
1895 break;
1896 }
1897
1899
1900 if( area )
1901 {
1902 SHAPE_RECT r( *area );
1903
1904 PNS_DBG( Dbg(), AddShape, &r, BLUE, 0, wxT( "opt-area" ) );
1905
1906 optFlags |= OPTIMIZER::RESTRICT_AREA;
1907 optimizer.SetRestrictArea( *area, false );
1908 }
1909
1910 if( Settings().SmartPads() )
1911 optFlags |= OPTIMIZER::SMART_PADS;
1912
1913
1914 optimizer.SetEffortLevel( optFlags & ~m_optFlagDisableMask );
1915 optimizer.SetCollisionMask( ITEM::ANY_T );
1916
1917 for( int pass = 0; pass < n_passes; pass++ )
1918 {
1919 std::reverse( m_optimizerQueue.begin(), m_optimizerQueue.end() );
1920
1921 for( LINE& line : m_optimizerQueue)
1922 {
1923 if( !( line.Marker() & MK_HEAD ) )
1924 {
1925 LINE optimized;
1926 LINE* root = findRootLine( &line );
1927
1928 if( optimizer.Optimize( &line, &optimized, root ) )
1929 {
1930 replaceLine( line, optimized, false, aNode );
1931 line = optimized; // keep links in the lines in the queue up to date
1932 }
1933 }
1934 }
1935 }
1936}
const BOX2I & VisibleViewArea() const
@ LIMIT_CORNER_COUNT
Do not attempt to optimize if the resulting line's corner count is outside the predefined range.
@ SMART_PADS
Reroute pad exits.
@ MERGE_SEGMENTS
Reduce corner cost iteratively.
Definition: pns_optimizer.h:99
@ MERGE_OBTUSE
Reduce corner cost by merging obtuse segments.
PNS_OPTIMIZATION_EFFORT OptimizerEffort() const
Set the optimizer effort. Bigger means cleaner traces, but slower routing.
LINE * findRootLine(LINE *aLine)
Definition: pns_shove.cpp:1838
OPT_BOX2I totalAffectedArea() const
Definition: pns_shove.cpp:1545

References PNS::ITEM::ANY_T, BLUE, PNS::ALGO_BASE::Dbg(), findRootLine(), PNS::OPTIMIZER::LIMIT_CORNER_COUNT, m_optFlagDisableMask, m_optimizerQueue, PNS::OPTIMIZER::MERGE_OBTUSE, PNS::OPTIMIZER::MERGE_SEGMENTS, PNS::MK_HEAD, PNS::OE_FULL, PNS::OE_LOW, PNS::OE_MEDIUM, PNS::OPTIMIZER::Optimize(), PNS::ROUTING_SETTINGS::OptimizerEffort(), PNS_DBG, r, replaceLine(), PNS::OPTIMIZER::RESTRICT_AREA, PNS::OPTIMIZER::SetCollisionMask(), PNS::OPTIMIZER::SetEffortLevel(), PNS::OPTIMIZER::SetRestrictArea(), PNS::ALGO_BASE::Settings(), PNS::OPTIMIZER::SMART_PADS, totalAffectedArea(), and PNS::ALGO_BASE::VisibleViewArea().

Referenced by ShoveDraggingVia(), ShoveLines(), and ShoveMultiLines().

◆ sanityCheck()

void PNS::SHOVE::sanityCheck ( LINE aOld,
LINE aNew 
)
private

Definition at line 150 of file pns_shove.cpp.

151{
152 assert( aOld->CPoint( 0 ) == aNew->CPoint( 0 ) );
153 assert( aOld->CPoint( -1 ) == aNew->CPoint( -1 ) );
154}

References PNS::LINE::CPoint().

Referenced by onCollidingArc(), onCollidingLine(), onCollidingSegment(), and onCollidingSolid().

◆ 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 onCollidingSolid(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), SHOVE(), and PNS::DRAGGER::tryWalkaround().

◆ SetInitialLine()

void PNS::SHOVE::SetInitialLine ( LINE aInitial)

Definition at line 1953 of file pns_shove.cpp.

1954{
1955 m_root = m_root->Branch();
1956 m_root->Remove( aInitial );
1957}
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:139

References PNS::NODE::Branch(), m_root, and PNS::NODE::Remove().

◆ 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 PNS::DRAGGER::tryWalkaround().

◆ SetSpringbackDoNotTouchNode()

void PNS::SHOVE::SetSpringbackDoNotTouchNode ( NODE aNode)

Definition at line 2035 of file pns_shove.cpp.

2036{
2038}

References m_springbackDoNotTouchNode.

◆ Settings()

◆ ShoveDraggingVia()

SHOVE::SHOVE_STATUS PNS::SHOVE::ShoveDraggingVia ( const VIA_HANDLE  aOldVia,
const VECTOR2I aWhere,
VIA_HANDLE aNewVia 
)

Definition at line 1770 of file pns_shove.cpp.

1772{
1773 SHOVE_STATUS st = SH_OK;
1774
1775 m_lineStack.clear();
1776 m_optimizerQueue.clear();
1777 m_newHead = OPT_LINE();
1778 m_draggedVia = nullptr;
1779
1780 VIA* viaToDrag = findViaByHandle( m_currentNode, aOldVia );
1781
1782 if( !viaToDrag )
1783 return SH_INCOMPLETE;
1784
1785 // Pop NODEs containing previous shoves which are no longer necessary
1786 ITEM_SET headSet;
1787
1788 VIA headVia ( *viaToDrag );
1789 headVia.SetPos( aWhere );
1790 headSet.Add( headVia );
1791 VIA_HANDLE prevViaHandle;
1792 NODE* parent = reduceSpringback( headSet, prevViaHandle );
1793
1794 if( prevViaHandle.valid )
1795 {
1796 aNewVia = prevViaHandle;
1797 viaToDrag = findViaByHandle( parent, prevViaHandle );
1798 }
1799
1800 // Create a new NODE to store this version of the world
1801 m_currentNode = parent->Branch();
1803
1804 viaToDrag->Mark( MK_HEAD );
1805 viaToDrag->SetRank( 100000 );
1806
1807 // Push the via to its new location
1808 st = pushOrShoveVia( viaToDrag, ( aWhere - viaToDrag->Pos() ), 0 );
1809
1810 // Shove any colliding objects out of the way
1811 if( st == SH_OK )
1812 st = shoveMainLoop();
1813
1814 if( st == SH_OK )
1816
1817 if( st == SH_OK || st == SH_HEAD_MODIFIED )
1818 {
1819 wxLogTrace( "PNS","setNewV %p", m_draggedVia );
1820
1821 if (!m_draggedVia)
1822 m_draggedVia = viaToDrag;
1823
1824 aNewVia = m_draggedVia->MakeHandle();
1825
1827 }
1828 else
1829 {
1830 delete m_currentNode;
1831 m_currentNode = parent;
1832 }
1833
1834 return st;
1835}
void ClearRanks(int aMarkerMask=MK_HEAD|MK_VIOLATION|MK_HOLE)
Definition: pns_node.cpp:1486
SHOVE_STATUS shoveMainLoop()
Definition: pns_shove.cpp:1499
NODE * reduceSpringback(const ITEM_SET &aHeadSet, VIA_HANDLE &aDraggedVia)
Definition: pns_shove.cpp:788
void runOptimizer(NODE *aNode)
Definition: pns_shove.cpp:1855
bool pushSpringback(NODE *aNode, const OPT_BOX2I &aAffectedArea, VIA *aDraggedVia)
Definition: pns_shove.cpp:823
OPT< LINE > OPT_LINE
Definition: pns_shove.h:97
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:169
static VIA * findViaByHandle(NODE *aNode, const VIA_HANDLE &handle)
Definition: pns_shove.cpp:1750

References PNS::ITEM_SET::Add(), PNS::NODE::Branch(), PNS::NODE::ClearRanks(), PNS::findViaByHandle(), m_affectedArea, m_currentNode, m_draggedVia, m_lineStack, m_newHead, m_optimizerQueue, PNS::VIA::MakeHandle(), PNS::ITEM::Mark(), PNS::MK_HEAD, PNS::VIA::Pos(), pushOrShoveVia(), pushSpringback(), reduceSpringback(), runOptimizer(), PNS::VIA::SetPos(), PNS::ITEM::SetRank(), SH_HEAD_MODIFIED, SH_INCOMPLETE, SH_OK, shoveMainLoop(), and PNS::VIA_HANDLE::valid.

◆ shoveIteration()

SHOVE::SHOVE_STATUS PNS::SHOVE::shoveIteration ( int  aIter)
private

Definition at line 1322 of file pns_shove.cpp.

1323{
1324 LINE currentLine = m_lineStack.back();
1325 NODE::OPT_OBSTACLE nearest;
1326 SHOVE_STATUS st = SH_NULL;
1327
1328 if( Dbg() )
1329 {
1330 Dbg()->SetIteration( aIter );
1331 }
1332
1333 PNS_DBG( Dbg(), AddItem, &currentLine, RED, currentLine.Width(), wxString::Format( "current-coll-chk rank %d", currentLine.Rank() ) );
1334
1335 for( ITEM::PnsKind search_order : { ITEM::SOLID_T, ITEM::VIA_T, ITEM::SEGMENT_T } )
1336 {
1337 nearest = m_currentNode->NearestObstacle( &currentLine, search_order );
1338
1339 if( nearest )
1340 {
1341 PNS_DBG( Dbg(), Message,
1342 wxString::Format( wxT( "nearest %p %s rank %d" ), nearest->m_item,
1343 nearest->m_item->KindStr(), nearest->m_item->Rank() ) );
1344
1345 PNS_DBG( Dbg(), AddShape, nearest->m_item->Shape(), YELLOW, 10000, wxT("nearest") );
1346 }
1347
1348 if( nearest )
1349 break;
1350 }
1351
1352 if( !nearest )
1353 {
1354 m_lineStack.pop_back();
1355 PNS_DBG( Dbg(), Message, "no-nearest-item ");
1356 return SH_OK;
1357 }
1358
1359 bool viaFixup = fixupViaCollisions( &currentLine, nearest.get() );
1360
1361 PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: VF %d", aIter, viaFixup?1:0 ) );
1362
1363
1364 ITEM* ni = nearest->m_item;
1365
1366 unwindLineStack( ni );
1367
1368 if( !ni->OfKind( ITEM::SOLID_T ) && ni->Rank() >= 0 && ni->Rank() > currentLine.Rank() )
1369 {
1370 // Collision with a higher-ranking object (ie: one that we've already shoved)
1371 //
1372 switch( ni->Kind() )
1373 {
1374 case ITEM::VIA_T:
1375 {
1376 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-via", aIter ).ToStdString(), 0 );
1377
1378 if( currentLine.EndsWithVia() )
1379 {
1380 st = SH_INCOMPLETE;
1381 }
1382 else
1383 {
1384 st = onReverseCollidingVia( currentLine, (VIA*) ni );
1385 }
1386
1387 PNS_DBGN( Dbg(), EndGroup );
1388
1389 break;
1390 }
1391
1392 case ITEM::SEGMENT_T:
1393 {
1394 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-segment ",
1395 aIter ).ToStdString(), 0 );
1396 LINE revLine = assembleLine( static_cast<SEGMENT*>( ni ) );
1397
1398 popLineStack();
1399 st = onCollidingLine( revLine, currentLine );
1400
1401
1402 if( !pushLineStack( revLine ) )
1403 {
1404 return SH_INCOMPLETE;
1405 }
1406
1407
1408 PNS_DBGN( Dbg(), EndGroup );
1409
1410 break;
1411 }
1412
1413 case ITEM::ARC_T:
1414 {
1415 //TODO(snh): Handle Arc shove separate from track
1416 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-arc ", aIter ).ToStdString(), 0 );
1417 LINE revLine = assembleLine( static_cast<ARC*>( ni ) );
1418
1419 popLineStack();
1420 st = onCollidingLine( revLine, currentLine );
1421
1422 PNS_DBGN( Dbg(), EndGroup );
1423
1424 if( !pushLineStack( revLine ) )
1425 return SH_INCOMPLETE;
1426
1427 break;
1428 }
1429
1430 default:
1431 assert( false );
1432 }
1433 }
1434 else
1435 {
1436 // Collision with a lower-ranking object or a solid
1437 //
1438 switch( ni->Kind() )
1439 {
1440 case ITEM::SEGMENT_T:
1441 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-segment ", aIter ), 0 );
1442
1443 st = onCollidingSegment( currentLine, (SEGMENT*) ni );
1444
1445 if( st == SH_TRY_WALK )
1446 st = onCollidingSolid( currentLine, ni, nearest.get() );
1447
1448 PNS_DBGN( Dbg(), EndGroup );
1449
1450 break;
1451
1452 //TODO(snh): Customize Arc collide
1453 case ITEM::ARC_T:
1454 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-arc ", aIter ), 0 );
1455
1456 st = onCollidingArc( currentLine, static_cast<ARC*>( ni ) );
1457
1458 if( st == SH_TRY_WALK )
1459 st = onCollidingSolid( currentLine, ni, nearest.get() );
1460
1461 PNS_DBGN( Dbg(), EndGroup );
1462
1463 break;
1464
1465 case ITEM::VIA_T:
1466 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-via (fixup: %d)", aIter, 0 ), 0 );
1467 st = onCollidingVia( &currentLine, (VIA*) ni, nearest.get() );
1468
1469 if( st == SH_TRY_WALK )
1470 st = onCollidingSolid( currentLine, ni, nearest.get() );
1471
1472 PNS_DBGN( Dbg(), EndGroup );
1473
1474 break;
1475
1476 case ITEM::SOLID_T:
1477 PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: walk-solid ", aIter ), 0);
1478 st = onCollidingSolid( currentLine, (SOLID*) ni, nearest.get() );
1479
1480 PNS_DBGN( Dbg(), EndGroup );
1481
1482 break;
1483
1484 default:
1485 break;
1486 }
1487 }
1488
1489 return st;
1490}
virtual void SetIteration(int iter)
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:160
OPT_OBSTACLE NearestObstacle(const LINE *aLine, int aKindMask=ITEM::ANY_T, const std::set< ITEM * > *aRestrictedSet=nullptr, bool aUseClearanceEpsilon=true)
Follow the line in search of an obstacle that is nearest to the starting to the line's starting point...
Definition: pns_node.cpp:301
SHOVE_STATUS onCollidingArc(LINE &aCurrent, ARC *aObstacleArc)
Definition: pns_shove.cpp:556
SHOVE_STATUS onCollidingSegment(LINE &aCurrent, SEGMENT *aObstacleSeg)
Definition: pns_shove.cpp:492
SHOVE_STATUS onCollidingLine(LINE &aCurrent, LINE &aObstacle)
Definition: pns_shove.cpp:614
SHOVE_STATUS onReverseCollidingVia(LINE &aCurrent, VIA *aObstacleVia)
Definition: pns_shove.cpp:1063
SHOVE_STATUS onCollidingSolid(LINE &aCurrent, ITEM *aObstacle, OBSTACLE &aObstacleInfo)
Definition: pns_shove.cpp:654
bool fixupViaCollisions(const LINE *aCurrent, OBSTACLE &obs)
Definition: pns_shove.cpp:1242

References PNS::ITEM::ARC_T, assembleLine(), PNS::ALGO_BASE::Dbg(), PNS::LINE::EndsWithVia(), fixupViaCollisions(), Format(), PNS::ITEM::Kind(), m_currentNode, m_lineStack, PNS::NODE::NearestObstacle(), PNS::ITEM::OfKind(), onCollidingArc(), onCollidingLine(), onCollidingSegment(), onCollidingSolid(), onCollidingVia(), onReverseCollidingVia(), PNS_DBG, PNS_DBGN, popLineStack(), pushLineStack(), PNS::ITEM::Rank(), PNS::LINE::Rank(), RED, PNS::ITEM::SEGMENT_T, PNS::DEBUG_DECORATOR::SetIteration(), SH_INCOMPLETE, SH_NULL, SH_OK, SH_TRY_WALK, PNS::ITEM::SOLID_T, unwindLineStack(), PNS::ITEM::VIA_T, PNS::LINE::Width(), and YELLOW.

Referenced by shoveMainLoop().

◆ shoveLineFromLoneVia()

SHOVE::SHOVE_STATUS PNS::SHOVE::shoveLineFromLoneVia ( const LINE aCurLine,
const LINE aObstacleLine,
LINE aResultLine 
)
private

Definition at line 226 of file pns_shove.cpp.

228{
229 // Build a hull for aCurLine's via and re-walk aObstacleLine around it.
230
231 int obstacleLineWidth = aObstacleLine.Width();
232 int clearance = getClearance( &aCurLine, &aObstacleLine );
233
234/* int holeClearance = getHoleClearance( &aCurLine.Via(), &aObstacleLine );
235
236 if( holeClearance + aCurLine.Via().Drill() / 2 > clearance + aCurLine.Via().Diameter() / 2 )
237 clearance = holeClearance + aCurLine.Via().Drill() / 2 - aCurLine.Via().Diameter() / 2;
238*/
239
240 SHAPE_LINE_CHAIN hull = aCurLine.Via().Hull( clearance, obstacleLineWidth, aCurLine.Layer() );
241 SHAPE_LINE_CHAIN path_cw;
242 SHAPE_LINE_CHAIN path_ccw;
243
244 if( ! aObstacleLine.Walkaround( hull, path_cw, true ) )
245 return SH_INCOMPLETE;
246
247 if( ! aObstacleLine.Walkaround( hull, path_ccw, false ) )
248 return SH_INCOMPLETE;
249
250 const SHAPE_LINE_CHAIN& shortest = path_ccw.Length() < path_cw.Length() ? path_ccw : path_cw;
251
252 if( shortest.PointCount() < 2 )
253 return SH_INCOMPLETE;
254
255 if( aObstacleLine.CPoint( -1 ) != shortest.CPoint( -1 ) )
256 return SH_INCOMPLETE;
257
258 if( aObstacleLine.CPoint( 0 ) != shortest.CPoint( 0 ) )
259 return SH_INCOMPLETE;
260
261 aResultLine.SetShape( shortest );
262
263 if( aResultLine.Collide( &aCurLine, m_currentNode ) )
264 return SH_INCOMPLETE;
265
266 return SH_OK;
267}
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
long long int Length() const
Return length of the line chain in Euclidean metric.

References PNS::ITEM::Collide(), PNS::LINE::CPoint(), SHAPE_LINE_CHAIN::CPoint(), getClearance(), PNS::VIA::Hull(), PNS::ITEM::Layer(), SHAPE_LINE_CHAIN::Length(), m_currentNode, SHAPE_LINE_CHAIN::PointCount(), PNS::LINE::SetShape(), SH_INCOMPLETE, SH_OK, PNS::LINE::Via(), PNS::LINE::Walkaround(), and PNS::LINE::Width().

Referenced by ShoveObstacleLine().

◆ ShoveLines()

SHOVE::SHOVE_STATUS PNS::SHOVE::ShoveLines ( const LINE aCurrentHead)

Definition at line 1561 of file pns_shove.cpp.

1562{
1563 SHOVE_STATUS st = SH_OK;
1564
1565 m_multiLineMode = false;
1566
1567 PNS_DBG( Dbg(), Message,
1568 wxString::Format( "Shove start, lc = %d", aCurrentHead.SegmentCount() ) )
1569
1570 // empty head? nothing to shove...
1571 if( !aCurrentHead.SegmentCount() && !aCurrentHead.EndsWithVia() )
1572 return SH_INCOMPLETE;
1573
1574 LINE head( aCurrentHead );
1575 head.ClearLinks();
1576
1577 m_lineStack.clear();
1578 m_optimizerQueue.clear();
1579 m_newHead = OPT_LINE();
1580
1581#if 0
1582 m_logger.Clear();
1583#endif
1584
1585 // Pop NODEs containing previous shoves which are no longer necessary
1586 //
1587 ITEM_SET headSet;
1588 headSet.Add( aCurrentHead );
1589
1590 VIA_HANDLE dummyVia;
1591
1592 NODE* parent = reduceSpringback( headSet, dummyVia );
1593
1594 // Create a new NODE to store this version of the world
1595 m_currentNode = parent->Branch();
1597 m_currentNode->Add( head );
1598
1599 m_currentNode->LockJoint( head.CPoint(0), &head, true );
1600
1601 if( !head.EndsWithVia() )
1602 m_currentNode->LockJoint( head.CPoint( -1 ), &head, true );
1603
1604 head.Mark( MK_HEAD );
1605 head.SetRank( 100000 );
1606
1607 PNS_DBG( Dbg(), AddItem, &head, CYAN, 0, wxT( "head, after shove" ) );
1608
1609 if( head.EndsWithVia() )
1610 {
1611 std::unique_ptr< VIA >headVia = Clone( head.Via() );
1612 headVia->Mark( MK_HEAD );
1613 headVia->SetRank( 100000 );
1614 m_currentNode->Add( std::move( headVia ) );
1615 }
1616
1617 if( !pushLineStack( head ) )
1618 {
1619 delete m_currentNode;
1620 m_currentNode = parent;
1621
1622 return SH_INCOMPLETE;
1623 }
1624
1625 st = shoveMainLoop();
1626
1627 if( st == SH_OK )
1628 {
1630
1631 if( m_newHead )
1633 else
1635 }
1636
1638
1639 PNS_DBG( Dbg(), Message, wxString::Format( "Shove status : %s after %d iterations",
1640 ( ( st == SH_OK || st == SH_HEAD_MODIFIED ) ? "OK" : "FAILURE"), m_iter ) );
1641
1642 if( st == SH_OK || st == SH_HEAD_MODIFIED )
1643 {
1645 }
1646 else
1647 {
1648 delete m_currentNode;
1649
1650 m_currentNode = parent;
1651 m_newHead = OPT_LINE();
1652 }
1653
1654 if(m_newHead)
1655 m_newHead->Unmark();
1656
1657 if( m_newHead && head.EndsWithVia() )
1658 {
1659 VIA v = head.Via();
1660 v.SetPos( m_newHead->CPoint( -1 ) );
1661 m_newHead->AppendVia(v);
1662 }
1663
1664 return st;
1665}
void Clear()
Definition: pns_logger.cpp:40
void RemoveByMarker(int aMarker)
Definition: pns_node.cpp:1496
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 LockJoint(const VECTOR2I &aPos, const ITEM *aItem, bool aLock)
Definition: pns_node.cpp:1211
@ CYAN
Definition: color4d.h:58

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::NODE::Branch(), PNS::NODE::CheckColliding(), PNS::LOGGER::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::NODE::ClearRanks(), PNS::Clone(), PNS::LINE::CPoint(), CYAN, PNS::ALGO_BASE::Dbg(), PNS::LINE::EndsWithVia(), Format(), PNS::NODE::LockJoint(), m_affectedArea, m_currentNode, m_iter, m_lineStack, m_logger, m_multiLineMode, m_newHead, m_optimizerQueue, PNS::LINE::Mark(), PNS::MK_HEAD, PNS_DBG, pushLineStack(), pushSpringback(), reduceSpringback(), PNS::NODE::RemoveByMarker(), runOptimizer(), PNS::LINE::SegmentCount(), PNS::VIA::SetPos(), PNS::LINE::SetRank(), SH_HEAD_MODIFIED, SH_INCOMPLETE, SH_OK, shoveMainLoop(), and PNS::LINE::Via().

◆ shoveLineToHullSet()

SHOVE::SHOVE_STATUS PNS::SHOVE::shoveLineToHullSet ( const LINE aCurLine,
const LINE aObstacleLine,
LINE aResultLine,
const HULL_SET aHulls 
)
private

Definition at line 273 of file pns_shove.cpp.

275{
276 const SHAPE_LINE_CHAIN& obs = aObstacleLine.CLine();
277
278 int attempt;
279
280 PNS_DBG( Dbg(), BeginGroup, "shove-details", 1 );
281
282 for( attempt = 0; attempt < 4; attempt++ )
283 {
284 bool invertTraversal = ( attempt >= 2 );
285 bool clockwise = attempt % 2;
286 int vFirst = -1, vLast = -1;
287
288 LINE l( aObstacleLine );
289 SHAPE_LINE_CHAIN path( l.CLine() );
290
291 for( int i = 0; i < (int) aHulls.size(); i++ )
292 {
293 const SHAPE_LINE_CHAIN& hull = aHulls[invertTraversal ? aHulls.size() - 1 - i : i];
294
295 PNS_DBG( Dbg(), AddShape, &hull, YELLOW, 10000, wxString::Format( "hull[%d]", i ) );
296 PNS_DBG( Dbg(), AddShape, &path, WHITE, l.Width(), wxString::Format( "path[%d]", i ) );
297 PNS_DBG( Dbg(), AddShape, &obs, LIGHTGRAY, aObstacleLine.Width(), wxString::Format( "obs[%d]", i ) );
298
299 if( !l.Walkaround( hull, path, clockwise ) )
300 {
301 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "Fail-Walk %s %s %d\n" ),
302 hull.Format().c_str(),
303 l.CLine().Format().c_str(),
304 clockwise? 1 : 0) );
305
306 PNS_DBGN( Dbg(), EndGroup );
307 return SH_INCOMPLETE;
308 }
309
310 PNS_DBG( Dbg(), AddShape, &path, WHITE, l.Width(), wxString::Format( "path-presimp[%d]", i ) );
311
312 path.Simplify();
313
314 PNS_DBG( Dbg(), AddShape, &path, WHITE, l.Width(), wxString::Format( "path-postsimp[%d]", i ) );
315
316 l.SetShape( path );
317 }
318
319 for( int i = 0; i < std::min( path.PointCount(), obs.PointCount() ); i++ )
320 {
321 if( path.CPoint( i ) != obs.CPoint( i ) )
322 {
323 vFirst = i;
324 break;
325 }
326 }
327
328 int k = obs.PointCount() - 1;
329
330 for( int i = path.PointCount() - 1; i >= 0 && k >= 0; i--, k-- )
331 {
332 if( path.CPoint( i ) != obs.CPoint( k ) )
333 {
334 vLast = i;
335 break;
336 }
337 }
338
339 if( ( vFirst < 0 || vLast < 0 ) && !path.CompareGeometry( aObstacleLine.CLine() ) )
340 {
341 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail vfirst-last" ),
342 attempt ) );
343 continue;
344 }
345
346 if( path.CPoint( -1 ) != obs.CPoint( -1 ) || path.CPoint( 0 ) != obs.CPoint( 0 ) )
347 {
348 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail vend-start\n" ),
349 attempt ) );
350 continue;
351 }
352
353 if( !checkShoveDirection( aCurLine, aObstacleLine, l ) )
354 {
355 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail direction-check" ),
356 attempt ) );
357 aResultLine.SetShape( l.CLine() );
358 continue;
359 }
360
361 if( path.SelfIntersecting() )
362 {
363 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail self-intersect" ),
364 attempt ) );
365 continue;
366 }
367
368 bool colliding = l.Collide( &aCurLine, m_currentNode );
369
370 if(( aCurLine.Marker() & MK_HEAD ) && !colliding )
371 {
372 JOINT* jtStart = m_currentNode->FindJoint( aCurLine.CPoint( 0 ), &aCurLine );
373
374 for( ITEM* item : jtStart->LinkList() )
375 {
376 if( item->Collide( &l, m_currentNode ) )
377 colliding = true;
378 }
379 }
380
381 if( colliding )
382 {
383 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail coll-check" ),
384 attempt ) );
385 continue;
386 }
387
388 aResultLine.SetShape( l.CLine() );
389
390 PNS_DBGN( Dbg(), EndGroup );
391
392 return SH_OK;
393 }
394
395 PNS_DBGN( Dbg(), EndGroup );
396
397 return SH_INCOMPLETE;
398}
bool checkShoveDirection(const LINE &aCurLine, const LINE &aObstacleLine, const LINE &aShovedLine) const
Definition: pns_shove.cpp:206
const std::string Format() const override
@ LIGHTGRAY
Definition: color4d.h:47

References checkShoveDirection(), PNS::LINE::CLine(), PNS::ITEM::Collide(), PNS::LINE::CPoint(), SHAPE_LINE_CHAIN::CPoint(), PNS::ALGO_BASE::Dbg(), PNS::NODE::FindJoint(), SHAPE_LINE_CHAIN::Format(), Format(), LIGHTGRAY, PNS::JOINT::LinkList(), m_currentNode, PNS::LINE::Marker(), PNS::MK_HEAD, path, PNS_DBG, PNS_DBGN, SHAPE_LINE_CHAIN::PointCount(), PNS::LINE::SetShape(), SH_INCOMPLETE, SH_OK, PNS::LINE::Walkaround(), WHITE, PNS::LINE::Width(), and YELLOW.

Referenced by ShoveObstacleLine().

◆ shoveMainLoop()

SHOVE::SHOVE_STATUS PNS::SHOVE::shoveMainLoop ( )
private

Definition at line 1499 of file pns_shove.cpp.

1500{
1501 SHOVE_STATUS st = SH_OK;
1502
1504
1505 PNS_DBG( Dbg(), Message, wxString::Format( "ShoveStart [root: %d jts, current: %d jts]",
1506 m_root->JointCount(),
1508
1509 int iterLimit = Settings().ShoveIterationLimit();
1510 TIME_LIMIT timeLimit = Settings().ShoveTimeLimit();
1511
1512 m_iter = 0;
1513
1514 timeLimit.Restart();
1515
1516 if( m_lineStack.empty() && m_draggedVia )
1517 {
1518 // If we're shoving a free via then push a proxy LINE (with the via on the end) onto
1519 // the stack.
1521 }
1522
1523 while( !m_lineStack.empty() )
1524 {
1525 PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: node %p stack %d ", m_iter,
1526 m_currentNode, (int) m_lineStack.size() ) );
1527
1528 st = shoveIteration( m_iter );
1529
1530 m_iter++;
1531
1532 if( st == SH_INCOMPLETE || timeLimit.Expired() || m_iter >= iterLimit )
1533 {
1534 PNS_DBG( Dbg(), Message, wxString::Format( "Fail [time limit expired: %d iter %d iter limit %d",
1535 timeLimit.Expired()?1:0, m_iter, iterLimit ) );
1536 st = SH_INCOMPLETE;
1537 break;
1538 }
1539 }
1540
1541 return st;
1542}
int JointCount() const
Return the number of nodes in the inheritance chain (wrs to the root node).
Definition: pns_node.h:197
TIME_LIMIT ShoveTimeLimit() const
SHOVE_STATUS shoveIteration(int aIter)
Definition: pns_shove.cpp:1322

References PNS::ALGO_BASE::Dbg(), PNS::TIME_LIMIT::Expired(), Format(), PNS::NODE::JointCount(), m_affectedArea, m_currentNode, m_draggedVia, m_iter, m_lineStack, m_root, PNS_DBG, pushLineStack(), PNS::TIME_LIMIT::Restart(), PNS::ALGO_BASE::Settings(), SH_INCOMPLETE, SH_OK, shoveIteration(), PNS::ROUTING_SETTINGS::ShoveIterationLimit(), and PNS::ROUTING_SETTINGS::ShoveTimeLimit().

Referenced by ShoveDraggingVia(), ShoveLines(), and ShoveMultiLines().

◆ ShoveMultiLines()

SHOVE::SHOVE_STATUS PNS::SHOVE::ShoveMultiLines ( const ITEM_SET aHeadSet)

Definition at line 1668 of file pns_shove.cpp.

1669{
1670 SHOVE_STATUS st = SH_OK;
1671
1672 m_multiLineMode = true;
1673
1674 ITEM_SET headSet;
1675
1676 for( const ITEM* item : aHeadSet.CItems() )
1677 {
1678 const LINE* headOrig = static_cast<const LINE*>( item );
1679
1680 // empty head? nothing to shove...
1681 if( !headOrig->SegmentCount() )
1682 return SH_INCOMPLETE;
1683
1684 headSet.Add( *headOrig );
1685 }
1686
1687 m_lineStack.clear();
1688 m_optimizerQueue.clear();
1689
1690#if 0
1691 m_logger.Clear();
1692#endif
1693
1694 VIA_HANDLE dummyVia;
1695
1696 NODE* parent = reduceSpringback( headSet, dummyVia );
1697
1698 m_currentNode = parent->Branch();
1700 int n = 0;
1701
1702 for( const ITEM* item : aHeadSet.CItems() )
1703 {
1704 const LINE* headOrig = static_cast<const LINE*>( item );
1705 LINE head( *headOrig );
1706 head.ClearLinks();
1707
1708 m_currentNode->Add( head );
1709
1710 head.Mark( MK_HEAD );
1711 head.SetRank( 100000 );
1712 n++;
1713
1714 if( !pushLineStack( head ) )
1715 return SH_INCOMPLETE;
1716
1717 if( head.EndsWithVia() )
1718 {
1719 std::unique_ptr< VIA > headVia = Clone( head.Via() );
1720 headVia->Mark( MK_HEAD );
1721 headVia->SetRank( 100000 );
1722 m_currentNode->Add( std::move( headVia ) );
1723 }
1724 }
1725
1726 st = shoveMainLoop();
1727
1728 if( st == SH_OK )
1730
1732
1733 PNS_DBG( Dbg(), Message, wxString::Format( "Shove status : %s after %d iterations",
1734 ( st == SH_OK ? "OK" : "FAILURE"), m_iter ) );
1735
1736 if( st == SH_OK )
1737 {
1739 }
1740 else
1741 {
1742 delete m_currentNode;
1743 m_currentNode = parent;
1744 }
1745
1746 return st;
1747}

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::NODE::Branch(), PNS::ITEM_SET::CItems(), PNS::LOGGER::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::NODE::ClearRanks(), PNS::Clone(), PNS::ALGO_BASE::Dbg(), PNS::LINE::EndsWithVia(), Format(), m_affectedArea, m_currentNode, m_iter, m_lineStack, m_logger, m_multiLineMode, m_optimizerQueue, PNS::LINE::Mark(), PNS::MK_HEAD, PNS_DBG, pushLineStack(), pushSpringback(), reduceSpringback(), PNS::NODE::RemoveByMarker(), runOptimizer(), PNS::LINE::SegmentCount(), PNS::LINE::SetRank(), SH_INCOMPLETE, SH_OK, shoveMainLoop(), and PNS::LINE::Via().

◆ ShoveObstacleLine()

SHOVE::SHOVE_STATUS PNS::SHOVE::ShoveObstacleLine ( const LINE aCurLine,
const LINE aObstacleLine,
LINE aResultLine 
)

Definition at line 405 of file pns_shove.cpp.

407{
408 aResultLine.ClearLinks();
409
410 bool obstacleIsHead = false;
411
412 for( LINKED_ITEM* s : aObstacleLine.Links() )
413 {
414 if( s->Marker() & MK_HEAD )
415 {
416 obstacleIsHead = true;
417 break;
418 }
419 }
420
421 SHOVE_STATUS rv;
422 bool viaOnEnd = aCurLine.EndsWithVia();
423
424 if( viaOnEnd && ( !aCurLine.Via().LayersOverlap( &aObstacleLine ) || aCurLine.SegmentCount() == 0 ) )
425 {
426 // Shove aObstacleLine to the hull of aCurLine's via.
427
428 rv = shoveLineFromLoneVia( aCurLine, aObstacleLine, aResultLine );
429 }
430 else
431 {
432 // Build a set of hulls around the segments of aCurLine. Hulls are at the clearance
433 // distance + aObstacleLine's linewidth so that when re-walking aObstacleLine along the
434 // hull it will be at the appropriate clearance.
435
436 int obstacleLineWidth = aObstacleLine.Width();
437 int clearance = getClearance( &aCurLine, &aObstacleLine ) + 1;
438 int currentLineSegmentCount = aCurLine.SegmentCount();
439 HULL_SET hulls;
440
441 hulls.reserve( currentLineSegmentCount + 1 );
442
443 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "shove process-single: cur net %d obs %d cl %d" ),
444 aCurLine.Net(), aObstacleLine.Net(), clearance ) );
445
446 for( int i = 0; i < currentLineSegmentCount; i++ )
447 {
448 SEGMENT seg( aCurLine, aCurLine.CSegment( i ) );
449 int extra = 0;
450
451 // Arcs need additional clearance to ensure the hulls are always bigger than the arc
452 if( aCurLine.CLine().IsArcSegment( i ) )
454
455 if( extra > 0 )
456 {
457 PNS_DBG( Dbg(), Message, wxString::Format( wxT( "shove add-extra-clearance %d" ),
458 extra ) );
459 }
460
461 SHAPE_LINE_CHAIN hull =
462 seg.Hull( clearance + extra, obstacleLineWidth, aObstacleLine.Layer() );
463
464 hulls.push_back( hull );
465 }
466
467 if( viaOnEnd )
468 {
469 const VIA& via = aCurLine.Via();
470 int viaClearance = getClearance( &via, &aObstacleLine );
471 /*int holeClearance = getHoleClearance( &via, &aObstacleLine );
472
473 if( holeClearance + via.Drill() / 2 > viaClearance + via.Diameter() / 2 )
474 viaClearance = holeClearance + via.Drill() / 2 - via.Diameter() / 2;*/
475
476 hulls.push_back( aCurLine.Via().Hull( viaClearance, obstacleLineWidth ) );
477 }
478
479 rv = shoveLineToHullSet( aCurLine, aObstacleLine, aResultLine, hulls );
480 }
481
482 if( obstacleIsHead )
483 aResultLine.Mark( aResultLine.Marker() | MK_HEAD );
484
485 return rv;
486}
std::vector< SHAPE_LINE_CHAIN > HULL_SET
Definition: pns_shove.h:96
SHOVE_STATUS shoveLineToHullSet(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine, const HULL_SET &aHulls)
Definition: pns_shove.cpp:273
SHOVE_STATUS shoveLineFromLoneVia(const LINE &aCurLine, const LINE &aObstacleLine, LINE &aResultLine)
Definition: pns_shove.cpp:226
static double DefaultAccuracyForPCB()
Definition: shape_arc.h:221

References PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::LINE::CSegment(), PNS::ALGO_BASE::Dbg(), SHAPE_ARC::DefaultAccuracyForPCB(), PNS::LINE::EndsWithVia(), Format(), getClearance(), PNS::SEGMENT::Hull(), PNS::VIA::Hull(), SHAPE_LINE_CHAIN::IsArcSegment(), PNS::ITEM::Layer(), PNS::ITEM::LayersOverlap(), PNS::LINK_HOLDER::Links(), PNS::LINE::Mark(), PNS::LINE::Marker(), PNS::MK_HEAD, PNS::ITEM::Net(), PNS_DBG, PNS::LINE::SegmentCount(), shoveLineFromLoneVia(), shoveLineToHullSet(), via, PNS::LINE::Via(), and PNS::LINE::Width().

Referenced by PNS::DIFF_PAIR_PLACER::attemptWalk(), onCollidingArc(), onCollidingLine(), onCollidingSegment(), onCollidingSolid(), and onReverseCollidingVia().

◆ totalAffectedArea()

OPT_BOX2I PNS::SHOVE::totalAffectedArea ( ) const
private

Definition at line 1545 of file pns_shove.cpp.

1546{
1547 OPT_BOX2I area;
1548
1549 if( !m_nodeStack.empty() )
1550 area = m_nodeStack.back().m_affectedArea;
1551
1552 if( area && m_affectedArea)
1553 area->Merge( *m_affectedArea );
1554 else if( !area )
1555 area = m_affectedArea;
1556
1557 return area;
1558}

References m_affectedArea, and m_nodeStack.

Referenced by runOptimizer().

◆ UnlockSpringbackNode()

void PNS::SHOVE::UnlockSpringbackNode ( NODE aNode)

Definition at line 2012 of file pns_shove.cpp.

2013{
2014 auto iter = m_nodeStack.begin();
2015
2016 while( iter != m_nodeStack.end() )
2017 {
2018 if ( iter->m_node == aNode )
2019 {
2020 iter->m_locked = false;
2021 break;
2022 }
2023
2024 iter++;
2025 }
2026}

References m_nodeStack.

◆ unwindLineStack() [1/2]

void PNS::SHOVE::unwindLineStack ( ITEM aItem)
private

Definition at line 1178 of file pns_shove.cpp.

1179{
1180 if( aItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
1181 unwindLineStack( static_cast<LINKED_ITEM*>( aItem ) );
1182 else if( aItem->OfKind( ITEM::LINE_T ) )
1183 {
1184 LINE* l = static_cast<LINE*>( aItem );
1185
1186 for( LINKED_ITEM* seg : l->Links() )
1187 unwindLineStack( seg );
1188 }
1189}

References PNS::ITEM::ARC_T, PNS::ITEM::LINE_T, PNS::LINK_HOLDER::Links(), PNS::ITEM::OfKind(), PNS::ITEM::SEGMENT_T, and unwindLineStack().

◆ unwindLineStack() [2/2]

void PNS::SHOVE::unwindLineStack ( LINKED_ITEM aSeg)
private

Definition at line 1151 of file pns_shove.cpp.

1152{
1153 int d = 0;
1154
1155 for( std::vector<LINE>::iterator i = m_lineStack.begin(); i != m_lineStack.end() ; )
1156 {
1157 if( i->ContainsLink( aSeg ) )
1158 {
1159 PNS_DBG(Dbg(), Message, wxString::Format("Unwind lc %d (depth %d/%d)", i->SegmentCount(), d, (int)m_lineStack.size() ) );
1160 i = m_lineStack.erase( i );
1161 }
1162 else
1163 i++;
1164
1165 d++;
1166 }
1167
1168 for( std::vector<LINE>::iterator i = m_optimizerQueue.begin(); i != m_optimizerQueue.end() ; )
1169 {
1170 if( i->ContainsLink( aSeg ) )
1171 i = m_optimizerQueue.erase( i );
1172 else
1173 i++;
1174 }
1175}

References PNS::ALGO_BASE::Dbg(), Format(), m_lineStack, m_optimizerQueue, and PNS_DBG.

Referenced by onReverseCollidingVia(), pushOrShoveVia(), shoveIteration(), and unwindLineStack().

◆ 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 PNS::DRAGGER::optimizeAndUpdateDraggedLine(), and runOptimizer().

Member Data Documentation

◆ m_affectedArea

OPT_BOX2I PNS::SHOVE::m_affectedArea
private

◆ m_currentNode

◆ 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_draggedVia

VIA* PNS::SHOVE::m_draggedVia
private

Definition at line 181 of file pns_shove.h.

Referenced by pushOrShoveVia(), SHOVE(), ShoveDraggingVia(), and shoveMainLoop().

◆ m_forceClearance

int PNS::SHOVE::m_forceClearance
private

Definition at line 184 of file pns_shove.h.

Referenced by ForceClearance(), getClearance(), getHoleClearance(), and SHOVE().

◆ m_iter

int PNS::SHOVE::m_iter
private

Definition at line 183 of file pns_shove.h.

Referenced by onReverseCollidingVia(), SHOVE(), ShoveLines(), shoveMainLoop(), and ShoveMultiLines().

◆ m_lineStack

std::vector<LINE> PNS::SHOVE::m_lineStack
private

◆ m_logger

LOGGER PNS::SHOVE::m_logger
private

Definition at line 180 of file pns_shove.h.

Referenced by Logger(), onReverseCollidingVia(), ShoveLines(), and ShoveMultiLines().

◆ m_multiLineMode

bool PNS::SHOVE::m_multiLineMode
private

◆ m_newHead

◆ m_nodeStack

◆ m_optFlagDisableMask

int PNS::SHOVE::m_optFlagDisableMask
private

Definition at line 187 of file pns_shove.h.

Referenced by DisablePostShoveOptimizations(), runOptimizer(), and SHOVE().

◆ m_optimizerQueue

std::vector<LINE> PNS::SHOVE::m_optimizerQueue
private

◆ m_restrictSpringbackTagId

int PNS::SHOVE::m_restrictSpringbackTagId
private

Definition at line 176 of file pns_shove.h.

Referenced by SHOVE().

◆ m_root

NODE* PNS::SHOVE::m_root
private

Definition at line 173 of file pns_shove.h.

Referenced by CurrentNode(), reduceSpringback(), SetInitialLine(), SHOVE(), and shoveMainLoop().

◆ m_rootLineHistory

std::unordered_map<const LINKED_ITEM*, LINE*> PNS::SHOVE::m_rootLineHistory
private

Definition at line 171 of file pns_shove.h.

Referenced by findRootLine(), replaceLine(), and ~SHOVE().

◆ m_router

◆ m_springbackDoNotTouchNode

NODE* PNS::SHOVE::m_springbackDoNotTouchNode
private

Definition at line 175 of file pns_shove.h.

Referenced by reduceSpringback(), SetSpringbackDoNotTouchNode(), and SHOVE().


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