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::set< ITEM * > m_fixedItems
 
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 35 of file pns_component_dragger.cpp.

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

44 {
45 }

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.

96  {
97  return UNDEFINED_LAYER;
98  }

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

265 {
267 }

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

157 {
158  assert( m_world );
159 
162 
163  for( const ITEM_SET::ENTRY& item : m_initialDraggedItems.Items() )
164  m_currentNode->Remove( item );
165 
167 
168  for( SOLID* s : m_solids )
169  {
170  VECTOR2I p_next = aP - m_p0 + s->Pos();
171  std::unique_ptr<SOLID> snew( static_cast<SOLID*>( s->Clone() ) );
172  snew->SetPos( p_next );
173 
174  m_draggedItems.Add( snew.get() );
175  m_currentNode->Add( std::move( snew ) );
176 
177  if( !s->IsRoutable() )
178  continue;
179 
180  for( DRAGGED_CONNECTION& l : m_conns )
181  {
182  if( l.attachedPad == s )
183  {
184  l.p_orig = s->Pos() + l.offset;
185  l.p_next = p_next + l.offset;
186  }
187  }
188  }
189 
190  for( ITEM* item : m_fixedItems )
191  {
192  m_currentNode->Remove( item );
193 
194  switch( item->Kind() )
195  {
196  case ITEM::SEGMENT_T:
197  {
198  SEGMENT* s = static_cast<SEGMENT*>( item );
199  std::unique_ptr<SEGMENT> s_new( s->Clone() );
200 
201  SEG orig = s->Seg();
202  s_new->SetEnds( aP - m_p0 + orig.A, aP - m_p0 + orig.B );
203 
204  m_draggedItems.Add( s_new.get() );
205  m_currentNode->Add( std::move( s_new ) );
206 
207  break;
208  }
209 
210  case ITEM::ARC_T:
211  {
212  ARC* a = static_cast<ARC*>( item );
213  std::unique_ptr<ARC> a_new( a->Clone() );
214 
215  SHAPE_ARC& arc = a_new->Arc();
216  arc.Move( aP - m_p0 );
217 
218  m_draggedItems.Add( a_new.get() );
219  m_currentNode->Add( std::move( a_new ) );
220  break;
221  }
222 
223  default:
224  wxFAIL_MSG( "Unexpected item type in COMPONENT_DRAGGER::m_fixedItems" );
225  }
226  }
227 
228  for( COMPONENT_DRAGGER::DRAGGED_CONNECTION& cn : m_conns )
229  {
230  LINE l_new( cn.origLine );
231  l_new.Unmark();
232  l_new.ClearLinks();
233  l_new.DragCorner( cn.p_next, cn.origLine.CLine().Find( cn.p_orig ) );
234 
235  PNS_DBG( Dbg(), AddLine, l_new.CLine(), BLUE, 100000, "cdrag-new-fanout" );
236  m_draggedItems.Add( l_new );
237 
238  LINE l_orig( cn.origLine );
239  m_currentNode->Remove( l_orig );
240  m_currentNode->Add( l_new );
241  }
242 
243  return true;
244 }
std::set< ITEM * > m_fixedItems
ENTRIES & Items()
Definition: pns_itemset.h:135
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:137
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:836
std::set< SOLID * > m_solids
void KillChildren()
Definition: pns_node.cpp:1405
std::vector< DRAGGED_CONNECTION > m_conns
#define PNS_DBG(dbg, method,...)
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
Definition: seg.h:40
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:518
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:638

References PNS::ITEM_SET::Add(), PNS::NODE::Add(), PNS::ITEM::ARC_T, BLUE, PNS::NODE::Branch(), PNS::ITEM_SET::Clear(), PNS::LINK_HOLDER::ClearLinks(), PNS::LINE::CLine(), PNS::SEGMENT::Clone(), PNS::ARC::Clone(), PNS::ALGO_BASE::Dbg(), PNS::LINE::DragCorner(), PNS::ITEM_SET::Items(), PNS::NODE::KillChildren(), m_conns, m_currentNode, m_draggedItems, m_fixedItems, m_initialDraggedItems, m_p0, m_solids, PNS::DRAG_ALGO::m_world, SHAPE_ARC::Move(), PNS_DBG, PNS::NODE::Remove(), PNS::SEGMENT::Seg(), PNS::ITEM::SEGMENT_T, and PNS::LINE::Unmark().

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

248 {
249  NODE* node = CurrentNode();
250 
251  if( node )
252  {
253  if( Settings().AllowDRCViolations() || !node->CheckColliding( m_draggedItems ) )
254  {
255  Router()->CommitRouting( node );
256  return true;
257  }
258  }
259 
260  return false;
261 }
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:707
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 nullptr;
37 }

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

49 {
50  assert( m_world );
51 
52  m_currentNode = nullptr;
53  m_initialDraggedItems = aPrimitives;
54  m_p0 = aP;
55 
56  std::unordered_set<LINKED_ITEM*> seenItems;
57 
58  auto addLinked =
59  [&]( SOLID* aSolid, JOINT* aJoint, LINKED_ITEM* aItem, VECTOR2I aOffset = {} )
60  {
61  if( seenItems.count( aItem ) )
62  return;
63 
64  seenItems.insert( aItem );
65 
66  // Segments that go directly between two linked pads are special-cased
67  VECTOR2I otherEnd = ( aJoint->Pos() == aItem->Anchor( 0 ) ) ?
68  aItem->Anchor( 1 ) : aItem->Anchor( 0 );
69  JOINT* otherJoint = m_world->FindJoint( otherEnd, aItem->Layer(), aItem->Net() );
70 
71  if( otherJoint && otherJoint->LinkCount( ITEM::SOLID_T ) )
72  {
73  for( const ITEM_SET::ENTRY& otherItem : otherJoint->LinkList() )
74  {
75  if( aPrimitives.Contains( otherItem.item ) )
76  {
77  m_fixedItems.insert( aItem );
78  return;
79  }
80  }
81  }
82 
83  int segIndex;
84  DRAGGED_CONNECTION cn;
85 
86  cn.origLine = m_world->AssembleLine( aItem, &segIndex );
87  cn.attachedPad = aSolid;
88  cn.offset = aOffset;
89 
90  // Lines that go directly between two linked pads are also special-cased
91  const SHAPE_LINE_CHAIN& line = cn.origLine.CLine();
92  JOINT* jA = m_world->FindJoint( line.CPoint( 0 ), aItem->Layer(), aItem->Net() );
93  JOINT* jB = m_world->FindJoint( line.CPoint( -1 ), aItem->Layer(), aItem->Net() );
94 
95  wxASSERT( jA == aJoint || jB == aJoint );
96  JOINT* jSearch = ( jA == aJoint ) ? jB : jA;
97 
98  if( jSearch && jSearch->LinkCount( ITEM::SOLID_T ) )
99  {
100  for( const ITEM_SET::ENTRY& otherItem : jSearch->LinkList() )
101  {
102  if( aPrimitives.Contains( otherItem.item ) )
103  {
104  for( ITEM* item : cn.origLine.Links() )
105  m_fixedItems.insert( item );
106 
107  return;
108  }
109  }
110  }
111 
112  m_conns.push_back( cn );
113  };
114 
115  for( auto item : aPrimitives.Items() )
116  {
117  if( item.item->Kind() != ITEM::SOLID_T )
118  continue;
119 
120  SOLID* solid = static_cast<SOLID*>( item.item );
121 
122  m_solids.insert( solid );
123 
124  if( !item.item->IsRoutable() )
125  continue;
126 
127  JOINT* jt = m_world->FindJoint( solid->Pos(), solid );
128 
129  for( auto link : jt->LinkList() )
130  {
131  if( link.item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
132  addLinked( solid, jt, static_cast<LINKED_ITEM*>( link.item ) );
133  }
134 
135  std::vector<JOINT*> extraJoints;
136 
137  m_world->QueryJoints( solid->Hull().BBox(), extraJoints, solid->Layers(),
139 
140  for( JOINT* extraJoint : extraJoints )
141  {
142  if( extraJoint->Net() == jt->Net() && extraJoint->LinkCount() == 1 )
143  {
144  LINKED_ITEM* li = static_cast<LINKED_ITEM*>( extraJoint->LinkList()[0].item );
145 
146  if( li->Collide( solid, nullptr, m_world ) )
147  addLinked( solid, extraJoint, li, extraJoint->Pos() - solid->Pos() );
148  }
149  }
150  }
151 
152  return true;
153 }
std::set< ITEM * > m_fixedItems
std::set< SOLID * > m_solids
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
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:1535
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:1140
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=nullptr, bool aStopAtLockedJoints=false)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
Definition: pns_node.cpp:946

References PNS::ITEM::ARC_T, PNS::NODE::AssembleLine(), PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::attachedPad, SHAPE_LINE_CHAIN::BBox(), PNS::LINE::CLine(), PNS::ITEM::Collide(), PNS::ITEM_SET::Contains(), SHAPE_LINE_CHAIN::CPoint(), PNS::NODE::FindJoint(), PNS::SOLID::Hull(), PNS::ITEM_SET::Items(), PNS::ITEM::Layers(), PNS::JOINT::LinkCount(), PNS::JOINT::LinkList(), PNS::LINK_HOLDER::Links(), m_conns, m_currentNode, m_fixedItems, m_initialDraggedItems, m_p0, m_solids, PNS::DRAG_ALGO::m_world, PNS::JOINT::Net(), PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::offset, PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::origLine, PNS::SOLID::Pos(), 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 270 of file pns_component_dragger.cpp.

271 {
272  return m_draggedItems;
273 }

References m_draggedItems.

◆ 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 }
ROUTER * m_router
Definition: pns_algo_base.h:87
const BOX2I & VisibleViewArea() const
Definition: pns_router.h:210

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

Referenced by Drag(), and Start().

◆ m_currentNode

NODE* PNS::COMPONENT_DRAGGER::m_currentNode
private

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

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

◆ m_dragStatus

bool PNS::COMPONENT_DRAGGER::m_dragStatus
private

Definition at line 120 of file pns_component_dragger.h.

Referenced by COMPONENT_DRAGGER().

◆ m_fixedItems

std::set<ITEM*> PNS::COMPONENT_DRAGGER::m_fixedItems
private

Definition at line 117 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_initialDraggedItems

ITEM_SET PNS::COMPONENT_DRAGGER::m_initialDraggedItems
private

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