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 ITEM_SET Traces () override
 Function Traces() More...
 
virtual void SetWorld (NODE *aWorld)
 Function SetWorld() More...
 
virtual void SetMode (int aDragMode)
 
ROUTERRouter () const
 

Returns the instance of our router

More...
 
ROUTING_SETTINGSSettings () const
 

Returns current router settings

More...
 
virtual LOGGERLogger ()
 

Returns the logger object, allowing to dump geometry to a file.

More...
 
void SetLogger (LOGGER *aLogger)
 
void SetDebugDecorator (DEBUG_DECORATOR *aDecorator)
 Function SetDebugDecorator. More...
 
DEBUG_DECORATORDbg () 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

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

160 {
162 }

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

90 {
93 
94  for( auto item : m_initialDraggedItems.Items() )
95  m_currentNode->Remove( item );
96 
98 
99  for( auto item : m_solids )
100  {
101  SOLID* s = static_cast<SOLID*>( item );
102  auto p_next = aP - m_p0 + s->Pos();
103  std::unique_ptr<SOLID> snew( static_cast<SOLID*>( s->Clone() ) );
104  snew->SetPos( p_next );
105 
106  m_draggedItems.Add( snew.get() );
107  m_currentNode->Add( std::move( snew ) );
108 
109  for( auto& l : m_conns )
110  {
111  if( l.attachedPad == s )
112  {
113  l.p_orig = s->Pos();
114  l.p_next = p_next;
115  }
116  }
117  }
118 
119  for( auto& cn : m_conns )
120  {
121  auto l_new( cn.origLine );
122  l_new.Unmark();
123  l_new.ClearSegmentLinks();
124  l_new.DragCorner( cn.p_next, cn.origLine.CLine().Find( cn.p_orig ) );
125 
126  Dbg()->AddLine( l_new.CLine(), 4, 100000 );
127  m_draggedItems.Add( l_new );
128 
129  auto l_orig( cn.origLine );
130  m_currentNode->Remove( l_orig );
131  m_currentNode->Add( l_new );
132  }
133 
134  return true;
135 }
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, int aType=0, int aWidth=0, const std::string aName="")
ENTRIES & Items()
Definition: pns_itemset.h:140
void Add(const LINE &aLine)
Definition: pns_itemset.cpp:32
NODE * Branch()
Function Branch()
Definition: pns_node.cpp:106
void Remove(ARC *aArc)
Function Remove()
Definition: pns_node.cpp:796
std::set< SOLID * > m_solids
void KillChildren()
Destroys all child nodes. Applicable only to the root node.
Definition: pns_node.cpp:1288
std::vector< DRAGGED_CONNECTION > m_conns
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:77
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620

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

138 {
139  NODE* node = CurrentNode();
140 
141  if( node )
142  {
143  bool ok;
144  if( Settings().CanViolateDRC() )
145  ok = true;
146  else
147  ok = !node->CheckColliding( m_draggedItems );
148 
149  if( !ok )
150  return false;
151 
152  Router()->CommitRouting( node );
153  return true;
154  }
155 
156  return false;
157 }
ROUTER * Router() const
Returns the instance of our router
Definition: pns_algo_base.h:51
NODE * CurrentNode() const override
Function CurrentNode()
void CommitRouting()
Definition: pns_router.cpp:422
ROUTING_SETTINGS & Settings() const
Returns current router settings

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

Returns the logger object, allowing to dump geometry to a file.

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::DRAGGER::dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::DRAGGER::Start().

◆ Router()

◆ SetDebugDecorator()

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

Function SetDebugDecorator.

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

Definition at line 72 of file pns_algo_base.h.

73  {
74  m_debugDecorator = aDecorator;
75  }
DEBUG_DECORATOR * m_debugDecorator
Definition: pns_algo_base.h:83

References PNS::ALGO_BASE::m_debugDecorator.

Referenced by PNS::DRAGGER::dragWalkaround(), PNS::LINE_PLACER::rhShoveOnly(), PNS::LINE_PLACER::rhWalkOnly(), and PNS::SHOVE::SHOVE().

◆ SetLogger()

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

Definition at line 62 of file pns_algo_base.h.

63  {
64  m_logger = aLogger;
65  }
LOGGER * m_logger
Definition: pns_algo_base.h:85

References PNS::ALGO_BASE::m_logger.

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

◆ SetMode()

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

Reimplemented in PNS::DRAGGER.

Definition at line 105 of file pns_drag_algo.h.

105 {};

◆ Settings()

◆ SetWorld()

virtual void PNS::DRAG_ALGO::SetWorld ( NODE aWorld)
inlinevirtualinherited

Function SetWorld()

Sets the board to work on.

Definition at line 59 of file pns_drag_algo.h.

60  {
61  m_world = aWorld;
62  }

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.

l0.SegmentCount() );

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  for( auto item : aPrimitives.Items() )
54  {
55  if( item.item->Kind() != ITEM::SOLID_T )
56  continue;
57 
58  auto solid = static_cast<SOLID*>( item.item );
59  auto jt = m_world->FindJoint( solid->Pos(), solid );
60 
61  m_solids.insert( solid );
62 
63  for( auto link : jt->LinkList() )
64  {
65  if( link.item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
66  {
67  LINKED_ITEM* li = static_cast<LINKED_ITEM*>( link.item );
68  int segIndex;
69 
70  auto l0 = m_world->AssembleLine( li, &segIndex );
71 
72 // printf( "solid %p jt %p fanout %d segs %d\n", solid, jt, jt->LinkCount(),
74 
75  DRAGGED_CONNECTION cn;
76 
77  cn.origLine = l0;
78  cn.attachedPad = solid;
79  m_conns.push_back( cn );
80  }
81  }
82  }
83 
84 // printf( "Total: %d conns to drag\n", m_conns.size() );
85 
86  return true;
87 }
std::set< SOLID * > m_solids
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Function AssembleLine()
Definition: pns_node.cpp:893
std::vector< DRAGGED_CONNECTION > m_conns
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Function FindJoint()
Definition: pns_node.cpp:1027

References PNS::ITEM::ARC_T, PNS::NODE::AssembleLine(), PNS::COMPONENT_DRAGGER::DRAGGED_CONNECTION::attachedPad, 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::origLine, 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 164 of file pns_component_dragger.cpp.

165 {
166  return m_draggedItems;
167 }

References m_draggedItems.

Member Data Documentation

◆ m_conns

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

Definition at line 98 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_currentNode

NODE* PNS::COMPONENT_DRAGGER::m_currentNode
private

Definition at line 103 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 83 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 101 of file pns_component_dragger.h.

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

◆ m_dragStatus

bool PNS::COMPONENT_DRAGGER::m_dragStatus
private

Definition at line 100 of file pns_component_dragger.h.

Referenced by COMPONENT_DRAGGER().

◆ m_initialDraggedItems

ITEM_SET PNS::COMPONENT_DRAGGER::m_initialDraggedItems
private

Definition at line 102 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_logger

LOGGER* PNS::ALGO_BASE::m_logger
protectedinherited

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

Referenced by Drag(), and Start().

◆ m_router

ROUTER* PNS::ALGO_BASE::m_router
protectedinherited

Definition at line 84 of file pns_algo_base.h.

Referenced by PNS::ALGO_BASE::Router(), and PNS::ALGO_BASE::Settings().

◆ m_solids

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

Definition at line 97 of file pns_component_dragger.h.

Referenced by Drag(), and Start().

◆ m_world


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