KiCad PCB EDA Suite
PNS::COMPONENT_DRAGGER Class Reference

COMPONENT_DRAGGER. More...

#include <pns_component_dragger.h>

Inheritance diagram for PNS::COMPONENT_DRAGGER:
PNS::DRAG_ALGO PNS::ALGO_BASE

Classes

struct  DRAGGED_CONNECTION
 

Public Member Functions

 COMPONENT_DRAGGER (ROUTER *aRouter)
 
 ~COMPONENT_DRAGGER ()
 
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...
 
virtual int CurrentLayer () const override
 Function CurrentLayer() More...
 
const ITEM_SET Traces () override
 Function Traces() More...
 
virtual void SetWorld (NODE *aWorld)
 Function SetWorld() More...
 
virtual void SetMode (int aDragMode)
 
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 Attributes

std::set< SOLID * > m_solids
 
std::vector< DRAGGED_CONNECTIONm_conns
 
bool m_dragStatus
 
ITEM_SET m_draggedItems
 
ITEM_SET m_initialDraggedItems
 
NODEm_currentNode
 
VECTOR2I m_p0
 

Detailed Description

COMPONENT_DRAGGER.

Implements component dragging algorithm.

Definition at line 38 of file pns_component_dragger.h.

Constructor & Destructor Documentation

◆ COMPONENT_DRAGGER()

PNS::COMPONENT_DRAGGER::COMPONENT_DRAGGER ( ROUTER aRouter)

Definition at line 33 of file pns_component_dragger.cpp.

33  : DRAG_ALGO( aRouter )
34 {
35  // ensure all variables are initialized
36  m_dragStatus = false;
37  m_currentNode = nullptr;
38 }
DRAG_ALGO(ROUTER *aRouter)
Definition: pns_drag_algo.h:45

References m_currentNode, and m_dragStatus.

◆ ~COMPONENT_DRAGGER()

PNS::COMPONENT_DRAGGER::~COMPONENT_DRAGGER ( )

Definition at line 41 of file pns_component_dragger.cpp.

42 {
43 }

Member Function Documentation

◆ CurrentLayer()

virtual int PNS::COMPONENT_DRAGGER::CurrentLayer ( ) const
inlineoverridevirtual

Function CurrentLayer()

Returns the layer of currently dragged item(s). Currently unused for component dragging.

Implements PNS::DRAG_ALGO.

Definition at line 95 of file pns_component_dragger.h.

References UNDEFINED_LAYER.

◆ CurrentNets()

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

Function CurrentNets()

Returns the net code(s) of currently dragged item(s). Currently unused for component dragging.

Implements PNS::DRAG_ALGO.

Definition at line 84 of file pns_component_dragger.h.

85  {
86  return std::vector<int>();
87  }

◆ CurrentNode()

NODE * PNS::COMPONENT_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 182 of file pns_component_dragger.cpp.

183 {
185 }

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

Referenced by FixRoute().

◆ Dbg()

◆ Drag()

bool PNS::COMPONENT_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 111 of file pns_component_dragger.cpp.

112 {
115 
116  for( auto item : m_initialDraggedItems.Items() )
117  m_currentNode->Remove( item );
118 
120 
121  for( auto item : m_solids )
122  {
123  SOLID* s = static_cast<SOLID*>( item );
124  auto p_next = aP - m_p0 + s->Pos();
125  std::unique_ptr<SOLID> snew( static_cast<SOLID*>( s->Clone() ) );
126  snew->SetPos( p_next );
127 
128  m_draggedItems.Add( snew.get() );
129  m_currentNode->Add( std::move( snew ) );
130 
131  for( auto& l : m_conns )
132  {
133  if( l.attachedPad == s )
134  {
135  l.p_orig = s->Pos() + l.offset;
136  l.p_next = p_next + l.offset;
137  }
138  }
139  }
140 
141  for( auto& cn : m_conns )
142  {
143  auto l_new( cn.origLine );
144  l_new.Unmark();
145  l_new.ClearLinks();
146  l_new.DragCorner( cn.p_next, cn.origLine.CLine().Find( cn.p_orig ) );
147 
148  PNS_DBG( Dbg(), AddLine, l_new.CLine(), BLUE, 100000, "cdrag-new-fanout" );
149  m_draggedItems.Add( l_new );
150 
151  auto l_orig( cn.origLine );
152  m_currentNode->Remove( l_orig );
153  m_currentNode->Add( l_new );
154  }
155 
156  return true;
157 }
ENTRIES & Items()
Definition: pns_itemset.h:138
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:127
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:810
std::set< SOLID * > m_solids
void KillChildren()
Definition: pns_node.cpp:1369
std::vector< DRAGGED_CONNECTION > m_conns
#define PNS_DBG(dbg, method,...)
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
Definition: color4d.h:56
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition: pns_node.cpp:621

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), BLUE, PNS::NODE::Branch(), PNS::ITEM_SET::Clear(), PNS::SOLID::Clone(), PNS::ALGO_BASE::Dbg(), PNS::ITEM_SET::Items(), PNS::NODE::KillChildren(), m_conns, m_currentNode, m_draggedItems, m_initialDraggedItems, m_p0, m_solids, PNS::DRAG_ALGO::m_world, PNS_DBG, PNS::SOLID::Pos(), and PNS::NODE::Remove().

◆ FixRoute()

bool PNS::COMPONENT_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 159 of file pns_component_dragger.cpp.

160 {
161  NODE* node = CurrentNode();
162 
163  if( node )
164  {
165  bool ok;
166 
167  if( Settings().AllowDRCViolations() )
168  ok = true;
169  else
170  ok = !node->CheckColliding( m_draggedItems );
171 
172  if( !ok )
173  return false;
174 
175  Router()->CommitRouting( node );
176  return true;
177  }
178 
179  return false;
180 }
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
NODE * CurrentNode() const override
Function CurrentNode()
void CommitRouting()
Definition: pns_router.cpp:694
ROUTING_SETTINGS & Settings() const
Return the logger object, allowing to dump geometry to a file.

References PNS::NODE::CheckColliding(), PNS::ROUTER::CommitRouting(), CurrentNode(), m_draggedItems, 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 NULL;
37 }
#define NULL

References NULL.

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

◆ 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  }
DEBUG_DECORATOR * m_debugDecorator
Definition: pns_algo_base.h:86

References PNS::ALGO_BASE::m_debugDecorator.

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

◆ SetMode()

virtual void PNS::DRAG_ALGO::SetMode ( int  aDragMode)
inlinevirtualinherited

Reimplemented in PNS::DRAGGER.

Definition at line 118 of file pns_drag_algo.h.

118 {};

◆ 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::COMPONENT_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 46 of file pns_component_dragger.cpp.

47 {
48  m_currentNode = nullptr;
49  m_initialDraggedItems = aPrimitives;
50  m_p0 = aP;
51 
52  std::unordered_set<LINKED_ITEM*> seenItems;
53 
54  auto addLinked =
55  [&]( SOLID* aSolid, LINKED_ITEM* aItem, VECTOR2I aOffset = {} )
56  {
57  if( seenItems.count( aItem ) )
58  return;
59 
60  seenItems.insert( aItem );
61 
62  int segIndex;
63  DRAGGED_CONNECTION cn;
64 
65  cn.origLine = m_world->AssembleLine( aItem, &segIndex );
66  cn.attachedPad = aSolid;
67  cn.offset = aOffset;
68 
69  m_conns.push_back( cn );
70  };
71 
72  for( auto item : aPrimitives.Items() )
73  {
74  if( item.item->Kind() != ITEM::SOLID_T )
75  continue;
76 
77  if( ! item.item->IsRoutable() )
78  continue;
79 
80  auto solid = static_cast<SOLID*>( item.item );
81  auto jt = m_world->FindJoint( solid->Pos(), solid );
82 
83  m_solids.insert( solid );
84 
85  for( auto link : jt->LinkList() )
86  {
87  if( link.item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
88  addLinked( solid, static_cast<LINKED_ITEM*>( link.item ) );
89  }
90 
91  std::vector<JOINT*> extraJoints;
92 
93  m_world->QueryJoints( solid->Hull().BBox(), extraJoints, solid->Layers(),
95 
96  for( JOINT* extraJoint : extraJoints )
97  {
98  if( extraJoint->Net() == jt->Net() && extraJoint->LinkCount() == 1 )
99  {
100  LINKED_ITEM* li = static_cast<LINKED_ITEM*>( extraJoint->LinkList()[0].item );
101 
102  if( li->Collide( solid, nullptr, m_world ) )
103  addLinked( solid, li, extraJoint->Pos() - solid->Pos() );
104  }
105  }
106  }
107 
108  return true;
109 }
std::set< SOLID * > m_solids
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
Definition: pns_node.cpp:920
std::vector< DRAGGED_CONNECTION > m_conns
int QueryJoints(const BOX2I &aBox, std::vector< JOINT * > &aJoints, LAYER_RANGE aLayerMask=LAYER_RANGE::All(), int aKindMask=ITEM::ANY_T)
Definition: pns_node.cpp:1499
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:1104

References PNS::ITEM::ARC_T, PNS::NODE::AssembleLine(), PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::attachedPad, PNS::ITEM::Collide(), PNS::NODE::FindJoint(), PNS::ITEM_SET::Items(), m_conns, m_currentNode, m_initialDraggedItems, m_p0, m_solids, PNS::DRAG_ALGO::m_world, PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::offset, PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::origLine, PNS::NODE::QueryJoints(), PNS::ITEM::SEGMENT_T, and PNS::ITEM::SOLID_T.

◆ Traces()

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

Function Traces()

Returns the set of dragged items.

Implements PNS::DRAG_ALGO.

Definition at line 187 of file pns_component_dragger.cpp.

188 {
189  return m_draggedItems;
190 }

References m_draggedItems.

◆ VisibleViewArea()

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

Definition at line 39 of file pns_algo_base.cpp.

40 {
41  return m_router->VisibleViewArea();
42 }
ROUTER * m_router
Definition: pns_algo_base.h:87
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:220

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

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

Member Data Documentation

◆ m_conns

std::vector<DRAGGED_CONNECTION> PNS::COMPONENT_DRAGGER::m_conns
private

Definition at line 117 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_currentNode

NODE* PNS::COMPONENT_DRAGGER::m_currentNode
private

Definition at line 122 of file pns_component_dragger.h.

Referenced by COMPONENT_DRAGGER(), CurrentNode(), 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::COMPONENT_DRAGGER::m_draggedItems
private

Definition at line 120 of file pns_component_dragger.h.

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

◆ m_dragStatus

bool PNS::COMPONENT_DRAGGER::m_dragStatus
private

Definition at line 119 of file pns_component_dragger.h.

Referenced by COMPONENT_DRAGGER().

◆ m_initialDraggedItems

ITEM_SET PNS::COMPONENT_DRAGGER::m_initialDraggedItems
private

Definition at line 121 of file pns_component_dragger.h.

Referenced by Drag(), 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_p0

VECTOR2I PNS::COMPONENT_DRAGGER::m_p0
private

Definition at line 123 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_router

◆ m_solids

std::set<SOLID*> PNS::COMPONENT_DRAGGER::m_solids
private

Definition at line 116 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_world


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