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 42 of file pns_component_dragger.h.

Constructor & Destructor Documentation

◆ COMPONENT_DRAGGER()

PNS::COMPONENT_DRAGGER::COMPONENT_DRAGGER ( ROUTER aRouter)

Definition at line 34 of file pns_component_dragger.cpp.

34  : DRAG_ALGO( aRouter )
35 {
36  // ensure all variables are initialized
37  m_dragStatus = false;
38  m_currentNode = nullptr;
39 }
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 42 of file pns_component_dragger.cpp.

43 {
44 }

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 99 of file pns_component_dragger.h.

100  {
101  return UNDEFINED_LAYER;
102  }

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 88 of file pns_component_dragger.h.

89  {
90  return std::vector<int>();
91  }

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

113 {
116 
117  for( auto item : m_initialDraggedItems.Items() )
118  m_currentNode->Remove( item );
119 
121 
122  for( auto item : m_solids )
123  {
124  SOLID* s = static_cast<SOLID*>( item );
125  auto p_next = aP - m_p0 + s->Pos();
126  std::unique_ptr<SOLID> snew( static_cast<SOLID*>( s->Clone() ) );
127  snew->SetPos( p_next );
128 
129  m_draggedItems.Add( snew.get() );
130  m_currentNode->Add( std::move( snew ) );
131 
132  for( auto& l : m_conns )
133  {
134  if( l.attachedPad == s )
135  {
136  l.p_orig = s->Pos() + l.offset;
137  l.p_next = p_next + l.offset;
138  }
139  }
140  }
141 
142  for( auto& cn : m_conns )
143  {
144  auto l_new( cn.origLine );
145  l_new.Unmark();
146  l_new.ClearLinks();
147  l_new.DragCorner( cn.p_next, cn.origLine.CLine().Find( cn.p_orig ) );
148 
149  Dbg()->AddLine( l_new.CLine(), 4, 100000 );
150  m_draggedItems.Add( l_new );
151 
152  auto l_orig( cn.origLine );
153  m_currentNode->Remove( l_orig );
154  m_currentNode->Add( l_new );
155  }
156 
157  return true;
158 }
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, int aType=0, int aWidth=0, const std::string aName="")
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:124
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:804
std::set< SOLID * > m_solids
void KillChildren()
Definition: pns_node.cpp:1292
std::vector< DRAGGED_CONNECTION > m_conns
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition: pns_node.cpp:615

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::DEBUG_DECORATOR::AddLine(), 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::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 160 of file pns_component_dragger.cpp.

161 {
162  NODE* node = CurrentNode();
163 
164  if( node )
165  {
166  bool ok;
167  if( Settings().CanViolateDRC() )
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:655
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 47 of file pns_component_dragger.cpp.

48 {
49  m_currentNode = nullptr;
50  m_initialDraggedItems = aPrimitives;
51  m_p0 = aP;
52 
53  std::unordered_set<LINKED_ITEM*> seenItems;
54 
55  auto addLinked =
56  [&]( SOLID* aSolid, LINKED_ITEM* aItem, VECTOR2I aOffset = {} )
57  {
58  if( seenItems.count( aItem ) )
59  return;
60 
61  seenItems.insert( aItem );
62 
63  int segIndex;
64  DRAGGED_CONNECTION cn;
65 
66  cn.origLine = m_world->AssembleLine( aItem, &segIndex );
67  cn.attachedPad = aSolid;
68  cn.offset = aOffset;
69 
70  m_conns.push_back( cn );
71  };
72 
73  for( auto item : aPrimitives.Items() )
74  {
75  if( item.item->Kind() != ITEM::SOLID_T )
76  continue;
77 
78  if( ! item.item->IsRoutable() )
79  continue;
80 
81  auto solid = static_cast<SOLID*>( item.item );
82  auto jt = m_world->FindJoint( solid->Pos(), solid );
83 
84  m_solids.insert( solid );
85 
86  for( auto link : jt->LinkList() )
87  {
88  if( link.item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
89  addLinked( solid, static_cast<LINKED_ITEM*>( link.item ) );
90  }
91 
92  std::vector<JOINT*> extraJoints;
93 
94  m_world->QueryJoints( solid->Hull().BBox(), extraJoints, solid->Layers(),
96 
97  for( JOINT* extraJoint : extraJoints )
98  {
99  if( extraJoint->Net() == jt->Net() && extraJoint->LinkCount() == 1 )
100  {
101  LINKED_ITEM* li = static_cast<LINKED_ITEM*>( extraJoint->LinkList()[0].item );
102 
103  if( li->Collide( solid, 0, m_world ) )
104  addLinked( solid, li, extraJoint->Pos() - solid->Pos() );
105  }
106  }
107  }
108 
109  return true;
110 }
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:912
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:1422
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:1027

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  auto bb = m_router->VisibleViewArea();
42  return m_router->VisibleViewArea();
43 }
ROUTER * m_router
Definition: pns_algo_base.h:87
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:225

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

Referenced by PNS::SHOVE::runOptimizer().

Member Data Documentation

◆ m_conns

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

Definition at line 121 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_currentNode

NODE* PNS::COMPONENT_DRAGGER::m_currentNode
private

Definition at line 126 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 124 of file pns_component_dragger.h.

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

◆ m_dragStatus

bool PNS::COMPONENT_DRAGGER::m_dragStatus
private

Definition at line 123 of file pns_component_dragger.h.

Referenced by COMPONENT_DRAGGER().

◆ m_initialDraggedItems

ITEM_SET PNS::COMPONENT_DRAGGER::m_initialDraggedItems
private

Definition at line 125 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(), and PNS::WALKAROUND::singleStep().

◆ m_p0

VECTOR2I PNS::COMPONENT_DRAGGER::m_p0
private

Definition at line 127 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 120 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_world


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