KiCad PCB EDA Suite
RN_NET Class Reference

Class RN_NET Describes ratsnest for a single net. More...

#include <ratsnest_data.h>

Classes

struct  RN_PAD_DATA
 

Structureo to hold ratsnest data for D_PAD objects.

More...
 
struct  RN_ZONE_DATA
 

Structure to hold ratsnest data for ZONE_CONTAINER objects.

More...
 

Public Member Functions

 RN_NET ()
 

Default constructor.

More...
 
void SetVisible (bool aEnabled)
 Function SetVisible() Sets state of the visibility flag. More...
 
bool IsVisible () const
 Function IsVisible() Returns the visibility flag state. More...
 
void MarkDirty ()
 Function MarkDirty() Marks ratsnest for given net as 'dirty', i.e. More...
 
bool IsDirty () const
 Function IsDirty() Returns state of the 'dirty' flag, indicating that ratsnest for a given net is invalid and requires an update. More...
 
const std::vector< RN_EDGE_MST_PTR > * GetUnconnected () const
 Function GetUnconnected() Returns pointer to a vector of edges that makes ratsnest for a given net. More...
 
void Update ()
 Function Update() Recomputes ratsnest for a net. More...
 
bool AddItem (const D_PAD *aPad)
 Function AddItem() Adds an appropriate node associated with selected pad, so it is taken into account during ratsnest computations. More...
 
bool AddItem (const VIA *aVia)
 Function AddItem() Adds an appropriate node associated with selected via, so it is taken into account during ratsnest computations. More...
 
bool AddItem (const TRACK *aTrack)
 Function AddItem() Adds appropriate nodes and edges associated with selected track, so they are taken into account during ratsnest computations. More...
 
bool AddItem (const ZONE_CONTAINER *aZone)
 Function AddItem() Processes zone to split it into subpolygons and adds appropriate nodes for them, so they are taken into account during ratsnest computations. More...
 
bool RemoveItem (const D_PAD *aPad)
 Function RemoveItem() Removes all nodes and edges associated with selected pad, so they are not taken into account during ratsnest computations anymore. More...
 
bool RemoveItem (const VIA *aVia)
 Function RemoveItem() Removes all nodes and edges associated with selected via, so they are not taken into account during ratsnest computations anymore. More...
 
bool RemoveItem (const TRACK *aTrack)
 Function RemoveItem() Removes all nodes and edges associated with selected track, so they are not taken into account during ratsnest computations anymore. More...
 
bool RemoveItem (const ZONE_CONTAINER *aZone)
 Function RemoveItem() Removes all nodes and edges associated with selected zone, so they are not taken into account during ratsnest computations anymore. More...
 
std::list< RN_NODE_PTRGetNodes (const BOARD_CONNECTED_ITEM *aItem) const
 Function GetNodes() Returns list of nodes that are associated with a given item. More...
 
void GetAllItems (std::list< BOARD_CONNECTED_ITEM * > &aOutput, RN_ITEM_TYPE aType=RN_ALL) const
 Function GetAllItems() Adds all stored items to a list. More...
 
const RN_NODE_PTR GetClosestNode (const RN_NODE_PTR &aNode) const
 Function GetClosestNode() Returns a single node that lies in the shortest distance from a specific node. More...
 
const RN_NODE_PTR GetClosestNode (const RN_NODE_PTR &aNode, const RN_NODE_FILTER &aFilter) const
 Function GetClosestNode() Returns a single node that lies in the shortest distance from a specific node and meets selected filter criterion. More...
 
std::list< RN_NODE_PTRGetClosestNodes (const RN_NODE_PTR &aNode, int aNumber=-1) const
 Function GetClosestNodes() Returns list of nodes sorted by the distance from a specific node. More...
 
std::list< RN_NODE_PTRGetClosestNodes (const RN_NODE_PTR &aNode, const RN_NODE_FILTER &aFilter, int aNumber=-1) const
 Function GetClosestNodes() Returns filtered list of nodes sorted by the distance from a specific node. More...
 
void AddSimple (const BOARD_CONNECTED_ITEM *aItem)
 Function AddSimple() Changes drawing mode for an item to simple (i.e. More...
 
void AddBlockedNode (RN_NODE_PTR &aNode)
 Function AddBlockedNode() Specifies a node as not suitable as a ratsnest line target (i.e. More...
 
const std::unordered_set< RN_NODE_PTR > & GetSimpleNodes () const
 Function GetSimpleNodes() Returns list of nodes for which ratsnest is drawn in simple mode (i.e. More...
 
void ClearSimple ()
 Function ClearSimple() Removes all nodes and edges that are used for displaying ratsnest in simple mode. More...
 
void GetConnectedItems (const BOARD_CONNECTED_ITEM *aItem, std::list< BOARD_CONNECTED_ITEM * > &aOutput, RN_ITEM_TYPE aTypes=RN_ALL) const
 Function GetConnectedItems() Adds items that are connected together to a list. More...
 

Protected Types

typedef std::unordered_map< const D_PAD *, RN_PAD_DATAPAD_NODE_MAP
 

Helper typedefs

More...
 
typedef std::unordered_map< const VIA *, RN_NODE_PTRVIA_NODE_MAP
 
typedef std::unordered_map< const TRACK *, RN_EDGE_MST_PTRTRACK_EDGE_MAP
 
typedef std::unordered_map< const ZONE_CONTAINER *, RN_ZONE_DATAZONE_DATA_MAP
 

Protected Member Functions

void validateEdge (RN_EDGE_MST_PTR &aEdge)
 

Validates edge, i.e.

More...
 
void removeNode (RN_NODE_PTR &aNode, const BOARD_CONNECTED_ITEM *aParent)
 

Removes a link between a node and a parent, and clears linked edges if it was the last parent.

More...
 
void removeEdge (RN_EDGE_MST_PTR &aEdge, const BOARD_CONNECTED_ITEM *aParent)
 

Removes a link between an edge and a parent, and clears its node data if it was the last parent.

More...
 
void clearNode (const RN_NODE_PTR &aNode)
 

Removes all ratsnest edges for a given node.

More...
 
void processZones ()
 

Adds appropriate edges for nodes that are connected by zones.

More...
 
void processPads ()
 

Adds additional edges to account for connections made by items located in pads areas.

More...
 
void compute ()
 

Recomputes ratsnset from scratch.

More...
 

Protected Attributes

RN_LINKS m_links
 
std::shared_ptr< std::vector< RN_EDGE_MST_PTR > > m_rnEdges
 

Vector of edges that makes ratsnest for a given net.

More...
 
std::unordered_set< RN_NODE_PTRm_blockedNodes
 

List of nodes which will not be used as ratsnest target nodes.

More...
 
std::unordered_set< RN_NODE_PTRm_simpleNodes
 

Nodes to be displayed using the simplified ratsnest algorithm.

More...
 
bool m_dirty
 

Flag indicating necessity of recalculation of ratsnest for a net.

More...
 
PAD_NODE_MAP m_pads
 

Map that associates nodes in the ratsnest model to respective nodes.

More...
 
VIA_NODE_MAP m_vias
 

Map that associates nodes in the ratsnest model to respective vias.

More...
 
TRACK_EDGE_MAP m_tracks
 

Map that associates edges in the ratsnest model to respective tracks.

More...
 
ZONE_DATA_MAP m_zones
 

Map that associates groups of subpolygons in the ratsnest model to respective zones.

More...
 
bool m_visible
 

Visibility flag.

More...
 

Detailed Description

Class RN_NET Describes ratsnest for a single net.

Definition at line 333 of file ratsnest_data.h.

Member Typedef Documentation

typedef std::unordered_map<const D_PAD*, RN_PAD_DATA> RN_NET::PAD_NODE_MAP
protected

Helper typedefs

Definition at line 624 of file ratsnest_data.h.

typedef std::unordered_map<const TRACK*, RN_EDGE_MST_PTR> RN_NET::TRACK_EDGE_MAP
protected

Definition at line 626 of file ratsnest_data.h.

typedef std::unordered_map<const VIA*, RN_NODE_PTR> RN_NET::VIA_NODE_MAP
protected

Definition at line 625 of file ratsnest_data.h.

typedef std::unordered_map<const ZONE_CONTAINER*, RN_ZONE_DATA> RN_NET::ZONE_DATA_MAP
protected

Definition at line 627 of file ratsnest_data.h.

Constructor & Destructor Documentation

RN_NET::RN_NET ( )
inline

Default constructor.

Definition at line 337 of file ratsnest_data.h.

337  : m_dirty( true ), m_visible( true )
338  {}
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
bool m_visible
Visibility flag.

Member Function Documentation

void RN_NET::AddBlockedNode ( RN_NODE_PTR aNode)
inline

Function AddBlockedNode() Specifies a node as not suitable as a ratsnest line target (i.e.

ratsnest lines will not target the node). The status is cleared after calling ClearSimple().

Parameters
aNodeis the node that is not going to be used as a ratsnest line target.

Definition at line 529 of file ratsnest_data.h.

References m_blockedNodes.

Referenced by AddSimple().

530  {
531  m_blockedNodes.insert( aNode );
532  aNode->SetNoLine( true );
533  }
std::unordered_set< RN_NODE_PTR > m_blockedNodes
List of nodes which will not be used as ratsnest target nodes.
bool RN_NET::AddItem ( const D_PAD aPad)

Function AddItem() Adds an appropriate node associated with selected pad, so it is taken into account during ratsnest computations.

Parameters
aPadis a pad for which node is added.

Definition at line 454 of file ratsnest_data.cpp.

References RN_LINKS::AddNode(), LSET::AllCuMask(), D_PAD::GetLayerSet(), D_PAD::GetPosition(), m_dirty, m_links, m_pads, wxPoint::x, and wxPoint::y.

455 {
456  // Ratsnest is not computed for non-copper pads
457  if( ( aPad->GetLayerSet() & LSET::AllCuMask() ).none() )
458  return false;
459 
460  RN_NODE_PTR node = m_links.AddNode( aPad->GetPosition().x, aPad->GetPosition().y );
461  node->AddParent( aPad );
462  m_pads[aPad].m_Node = node;
463  m_dirty = true;
464 
465  return true;
466 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
RN_LINKS m_links
PAD_NODE_MAP m_pads
Map that associates nodes in the ratsnest model to respective nodes.
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:235
bool RN_NET::AddItem ( const VIA aVia)

Function AddItem() Adds an appropriate node associated with selected via, so it is taken into account during ratsnest computations.

Parameters
aViais a via for which node is added.

Definition at line 469 of file ratsnest_data.cpp.

References RN_LINKS::AddNode(), VIA::GetPosition(), m_dirty, m_links, m_vias, wxPoint::x, and wxPoint::y.

470 {
471  RN_NODE_PTR node = m_links.AddNode( aVia->GetPosition().x, aVia->GetPosition().y );
472  node->AddParent( aVia );
473  m_vias[aVia] = node;
474  m_dirty = true;
475 
476  return true;
477 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
RN_LINKS m_links
const wxPoint & GetPosition() const override
Definition: class_track.h:415
VIA_NODE_MAP m_vias
Map that associates nodes in the ratsnest model to respective vias.
bool RN_NET::AddItem ( const TRACK aTrack)

Function AddItem() Adds appropriate nodes and edges associated with selected track, so they are taken into account during ratsnest computations.

Parameters
aTrackis a track for which nodes and edges are added.

Definition at line 480 of file ratsnest_data.cpp.

References RN_LINKS::AddConnection(), RN_LINKS::AddNode(), TRACK::GetEnd(), TRACK::GetStart(), m_dirty, m_links, m_tracks, wxPoint::x, and wxPoint::y.

481 {
482  if( aTrack->GetStart() == aTrack->GetEnd() )
483  return false;
484 
485  RN_NODE_PTR start = m_links.AddNode( aTrack->GetStart().x, aTrack->GetStart().y );
486  RN_NODE_PTR end = m_links.AddNode( aTrack->GetEnd().x, aTrack->GetEnd().y );
487 
488  start->AddParent( aTrack );
489  end->AddParent( aTrack );
490  m_tracks[aTrack] = m_links.AddConnection( start, end );
491  m_dirty = true;
492 
493  return true;
494 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
RN_LINKS m_links
const wxPoint & GetEnd() const
Definition: class_track.h:117
TRACK_EDGE_MAP m_tracks
Map that associates edges in the ratsnest model to respective tracks.
const wxPoint & GetStart() const
Definition: class_track.h:120
bool RN_NET::AddItem ( const ZONE_CONTAINER aZone)

Function AddItem() Processes zone to split it into subpolygons and adds appropriate nodes for them, so they are taken into account during ratsnest computations.

Parameters
aZoneis a zone to be processed.

Definition at line 497 of file ratsnest_data.cpp.

References SHAPE_LINE_CHAIN::BBox(), SHAPE_POLY_SET::COutline(), ZONE_CONTAINER::GetFilledPolysList(), m_dirty, m_links, m_zones, and SHAPE_POLY_SET::OutlineCount().

498 {
499  // Prepare a list of polygons (every zone can contain one or more polygons)
500  const SHAPE_POLY_SET& polySet = aZone->GetFilledPolysList();
501 
502  // This ensures that we record aZone as added even if it contains no polygons.
503  (void) m_zones[aZone];
504 
505  for( int i = 0; i < polySet.OutlineCount(); ++i )
506  {
507  const SHAPE_LINE_CHAIN& path = polySet.COutline( i );
508 
509  RN_POLY poly = RN_POLY( &polySet, i, m_links, path.BBox() );
510  m_zones[aZone].m_Polygons.push_back( poly );
511  }
512 
513  m_dirty = true;
514 
515  return true;
516 }
ZONE_DATA_MAP m_zones
Map that associates groups of subpolygons in the ratsnest model to respective zones.
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
RN_LINKS m_links
int OutlineCount() const
Returns the number of outlines in the set
Class RN_POLY Describes a single subpolygon (ZONE_CONTAINER is supposed to contain one or more of tho...
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Class SHAPE_POLY_SET.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:470
Class SHAPE_LINE_CHAIN.
void RN_NET::AddSimple ( const BOARD_CONNECTED_ITEM aItem)

Function AddSimple() Changes drawing mode for an item to simple (i.e.

one ratsnest line per node).

Parameters
aNodeis a node that changes its drawing mode.

Definition at line 699 of file ratsnest_data.cpp.

References AddBlockedNode(), GetNodes(), and m_simpleNodes.

700 {
701  for( RN_NODE_PTR node : GetNodes( aItem ) )
702  {
703  // Block all nodes, so they do not become targets for dynamic ratsnest lines
704  AddBlockedNode( node );
705 
706  // Filter out junctions
707  if( node->GetRefCount() == 1 )
708  m_simpleNodes.insert( node );
709  }
710 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
std::unordered_set< RN_NODE_PTR > m_simpleNodes
Nodes to be displayed using the simplified ratsnest algorithm.
std::list< RN_NODE_PTR > GetNodes(const BOARD_CONNECTED_ITEM *aItem) const
Function GetNodes() Returns list of nodes that are associated with a given item.
void AddBlockedNode(RN_NODE_PTR &aNode)
Function AddBlockedNode() Specifies a node as not suitable as a ratsnest line target (i...
void RN_NET::clearNode ( const RN_NODE_PTR aNode)
protected

Removes all ratsnest edges for a given node.

Definition at line 399 of file ratsnest_data.cpp.

References isEdgeConnectingNode().

400 {
401  if( !m_rnEdges )
402  return;
403 
404  std::vector<RN_EDGE_MST_PTR>::iterator newEnd;
405 
406  // Remove all ratsnest edges for associated with the node
407  newEnd = std::remove_if( m_rnEdges->begin(), m_rnEdges->end(),
408  std::bind( isEdgeConnectingNode, _1, std::cref( aNode ) ) );
409 
410  m_rnEdges->resize( std::distance( m_rnEdges->begin(), newEnd ) );
411 }
static bool isEdgeConnectingNode(const RN_EDGE_PTR &aEdge, const RN_NODE_PTR &aNode)
std::shared_ptr< std::vector< RN_EDGE_MST_PTR > > m_rnEdges
Vector of edges that makes ratsnest for a given net.
void RN_NET::ClearSimple ( )

Function ClearSimple() Removes all nodes and edges that are used for displaying ratsnest in simple mode.

Definition at line 799 of file ratsnest_data.cpp.

References m_blockedNodes, and m_simpleNodes.

800 {
801  for( const RN_NODE_PTR& node : m_blockedNodes )
802  node->SetNoLine( false );
803 
804  m_blockedNodes.clear();
805  m_simpleNodes.clear();
806 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
std::unordered_set< RN_NODE_PTR > m_simpleNodes
Nodes to be displayed using the simplified ratsnest algorithm.
std::unordered_set< RN_NODE_PTR > m_blockedNodes
List of nodes which will not be used as ratsnest target nodes.
void RN_NET::compute ( )
protected

Recomputes ratsnset from scratch.

Definition at line 345 of file ratsnest_data.cpp.

References hed::TRIANGULATION::CreateDelaunay(), getDistance(), and kruskalMST().

Referenced by Update().

346 {
347  const RN_LINKS::RN_NODE_SET& boardNodes = m_links.GetNodes();
348  const RN_LINKS::RN_EDGE_LIST& boardEdges = m_links.GetConnections();
349 
350  // Special cases do not need complicated algorithms (actually, it does not work well with
351  // the Delaunay triangulator)
352  if( boardNodes.size() <= 2 )
353  {
354  m_rnEdges.reset( new std::vector<RN_EDGE_MST_PTR>( 0 ) );
355 
356  // Check if the only possible connection exists
357  if( boardEdges.size() == 0 && boardNodes.size() == 2 )
358  {
359  RN_LINKS::RN_NODE_SET::const_iterator last = ++boardNodes.begin();
360 
361  // There can be only one possible connection, but it is missing
362  RN_EDGE_MST_PTR edge = std::make_shared<RN_EDGE_MST>( *boardNodes.begin(), *last );
363  edge->GetSourceNode()->SetTag( 0 );
364  edge->GetTargetNode()->SetTag( 1 );
365  m_rnEdges->push_back( edge );
366  }
367  else
368  {
369  // Set tags to nodes as connected
370  for( RN_NODE_PTR node : boardNodes )
371  node->SetTag( 0 );
372  }
373 
374 
375  return;
376  }
377 
378  // Move and sort (sorting speeds up) all nodes to a vector for the Delaunay triangulation
379  std::vector<RN_NODE_PTR> nodes( boardNodes.size() );
380  std::partial_sort_copy( boardNodes.begin(), boardNodes.end(), nodes.begin(), nodes.end() );
381 
382  TRIANGULATOR triangulator;
383  triangulator.CreateDelaunay( nodes.begin(), nodes.end() );
384  std::unique_ptr<RN_LINKS::RN_EDGE_LIST> triangEdges( triangulator.GetEdges() );
385 
386  // Compute weight/distance for edges resulting from triangulation
387  RN_LINKS::RN_EDGE_LIST::iterator eit, eitEnd;
388  for( eit = (*triangEdges).begin(), eitEnd = (*triangEdges).end(); eit != eitEnd; ++eit )
389  (*eit)->SetWeight( getDistance( (*eit)->GetSourceNode(), (*eit)->GetTargetNode() ) );
390 
391  // Add the currently existing connections list to the results of triangulation
392  std::copy( boardEdges.begin(), boardEdges.end(), std::front_inserter( *triangEdges ) );
393 
394  // Get the minimal spanning tree
395  m_rnEdges.reset( kruskalMST( *triangEdges, nodes ) );
396 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
RN_LINKS m_links
static std::vector< RN_EDGE_MST_PTR > * kruskalMST(RN_LINKS::RN_EDGE_LIST &aEdges, std::vector< RN_NODE_PTR > &aNodes)
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
static uint64_t getDistance(const RN_NODE_PTR &aNode1, const RN_NODE_PTR &aNode2)
std::shared_ptr< std::vector< RN_EDGE_MST_PTR > > m_rnEdges
Vector of edges that makes ratsnest for a given net.
void CreateDelaunay(NODES_CONTAINER::iterator aFirst, NODES_CONTAINER::iterator aLast)
Creates a Delaunay triangulation from a set of points.
Definition: hetriang.cpp:195
Triangulation class for the half-edge data structure with adaption to TTL.
Definition: hetriang.h:384
void RN_NET::GetAllItems ( std::list< BOARD_CONNECTED_ITEM * > &  aOutput,
RN_ITEM_TYPE  aType = RN_ALL 
) const

Function GetAllItems() Adds all stored items to a list.

Parameters
aOutputis the list that will have items added.
aTypedetermines the type of added items.

Definition at line 771 of file ratsnest_data.cpp.

References m_pads, m_tracks, m_vias, m_zones, RN_PADS, RN_TRACKS, RN_VIAS, and RN_ZONES.

772 {
773  if( aType & RN_PADS )
774  {
775  for( auto it : m_pads )
776  aOutput.push_back( const_cast<D_PAD*>( it.first ) );
777  }
778 
779  if( aType & RN_VIAS )
780  {
781  for( auto it : m_vias )
782  aOutput.push_back( const_cast<VIA*>( it.first ) );
783  }
784 
785  if( aType & RN_TRACKS )
786  {
787  for( auto it : m_tracks )
788  aOutput.push_back( const_cast<TRACK*>( it.first ) );
789  }
790 
791  if( aType & RN_ZONES )
792  {
793  for( auto it : m_zones )
794  aOutput.push_back( const_cast<ZONE_CONTAINER*>( it.first ) );
795  }
796 }
ZONE_DATA_MAP m_zones
Map that associates groups of subpolygons in the ratsnest model to respective zones.
PAD_NODE_MAP m_pads
Map that associates nodes in the ratsnest model to respective nodes.
TRACK_EDGE_MAP m_tracks
Map that associates edges in the ratsnest model to respective tracks.
VIA_NODE_MAP m_vias
Map that associates nodes in the ratsnest model to respective vias.
const RN_NODE_PTR RN_NET::GetClosestNode ( const RN_NODE_PTR aNode) const

Function GetClosestNode() Returns a single node that lies in the shortest distance from a specific node.

Parameters
aNodeis the node for which the closest node is searched.

Definition at line 594 of file ratsnest_data.cpp.

References getDistance(), RN_LINKS::GetNodes(), m_links, and max.

Referenced by KIGFX::RATSNEST_VIEWITEM::ViewDraw().

595 {
596  const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
597  RN_LINKS::RN_NODE_SET::const_iterator it, itEnd;
598 
599  unsigned int minDistance = std::numeric_limits<unsigned int>::max();
600  RN_NODE_PTR closest;
601 
602  for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it )
603  {
604  RN_NODE_PTR node = *it;
605 
606  // Obviously the distance between node and itself is the shortest,
607  // that's why we have to skip it
608  if( node != aNode )
609  {
610  unsigned int distance = getDistance( node, aNode );
611  if( distance < minDistance )
612  {
613  minDistance = distance;
614  closest = node;
615  }
616  }
617  }
618 
619  return closest;
620 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
RN_LINKS m_links
static uint64_t getDistance(const RN_NODE_PTR &aNode1, const RN_NODE_PTR &aNode2)
#define max(a, b)
Definition: auxiliary.h:86
const RN_NODE_PTR RN_NET::GetClosestNode ( const RN_NODE_PTR aNode,
const RN_NODE_FILTER aFilter 
) const

Function GetClosestNode() Returns a single node that lies in the shortest distance from a specific node and meets selected filter criterion.

Parameters
aNodeis the node for which the closest node is searched.
aFilteris a functor that filters nodes.

Definition at line 623 of file ratsnest_data.cpp.

References getDistance(), RN_LINKS::GetNodes(), m_links, and max.

625 {
626  const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
627  RN_LINKS::RN_NODE_SET::const_iterator it, itEnd;
628 
629  unsigned int minDistance = std::numeric_limits<unsigned int>::max();
630  RN_NODE_PTR closest;
631 
632  for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it )
633  {
634  RN_NODE_PTR node = *it;
635 
636  // Obviously the distance between node and itself is the shortest,
637  // that's why we have to skip it
638  if( node != aNode && aFilter( node ) )
639  {
640  unsigned int distance = getDistance( node, aNode );
641 
642  if( distance < minDistance )
643  {
644  minDistance = distance;
645  closest = node;
646  }
647  }
648  }
649 
650  return closest;
651 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
RN_LINKS m_links
static uint64_t getDistance(const RN_NODE_PTR &aNode1, const RN_NODE_PTR &aNode2)
#define max(a, b)
Definition: auxiliary.h:86
std::list< RN_NODE_PTR > RN_NET::GetClosestNodes ( const RN_NODE_PTR aNode,
int  aNumber = -1 
) const

Function GetClosestNodes() Returns list of nodes sorted by the distance from a specific node.

Parameters
aNodeis the node for which the closest nodes are searched.
aNumberis asked number of returned nodes. If it is negative then all nodes that belong to the same net are returned. If asked number is greater than number of possible nodes then the size of list is limited to number of possible nodes.

Definition at line 654 of file ratsnest_data.cpp.

References RN_LINKS::GetNodes(), m_links, min, and sortDistance().

655 {
656  std::list<RN_NODE_PTR> closest;
657  const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
658 
659  // Copy nodes
660  std::copy( nodes.begin(), nodes.end(), std::back_inserter( closest ) );
661 
662  // Sort by the distance from aNode
663  closest.sort( std::bind( sortDistance, std::cref( aNode ), _1, _2 ) );
664 
665  // aNode should not be returned in the results
666  closest.remove( aNode );
667 
668  // Trim the result to the asked size
669  if( aNumber > 0 )
670  closest.resize( std::min( (size_t)aNumber, nodes.size() ) );
671 
672  return closest;
673 }
RN_LINKS m_links
static bool sortDistance(const RN_NODE_PTR &aOrigin, const RN_NODE_PTR &aNode1, const RN_NODE_PTR &aNode2)
#define min(a, b)
Definition: auxiliary.h:85
std::list< RN_NODE_PTR > RN_NET::GetClosestNodes ( const RN_NODE_PTR aNode,
const RN_NODE_FILTER aFilter,
int  aNumber = -1 
) const

Function GetClosestNodes() Returns filtered list of nodes sorted by the distance from a specific node.

Parameters
aNodeis the node for which the closest nodes are searched.
aFilteris a functor that filters nodes.
aNumberis asked number of returned nodes. If it is negative then all nodes that belong to the same net are returned. If asked number is greater than number of possible nodes then the size of list is limited to number of possible nodes.

Definition at line 676 of file ratsnest_data.cpp.

References RN_LINKS::GetNodes(), m_links, min, and sortDistance().

678 {
679  std::list<RN_NODE_PTR> closest;
680  const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
681 
682  // Copy filtered nodes
683  std::copy_if( nodes.begin(), nodes.end(), std::back_inserter( closest ), std::cref( aFilter ) );
684 
685  // Sort by the distance from aNode
686  closest.sort( std::bind( sortDistance, std::cref( aNode ), _1, _2 ) );
687 
688  // aNode should not be returned in the results
689  closest.remove( aNode );
690 
691  // Trim the result to the asked size
692  if( aNumber > 0 )
693  closest.resize( std::min( static_cast<size_t>( aNumber ), nodes.size() ) );
694 
695  return closest;
696 }
RN_LINKS m_links
static bool sortDistance(const RN_NODE_PTR &aOrigin, const RN_NODE_PTR &aNode1, const RN_NODE_PTR &aNode2)
#define min(a, b)
Definition: auxiliary.h:85
void RN_NET::GetConnectedItems ( const BOARD_CONNECTED_ITEM aItem,
std::list< BOARD_CONNECTED_ITEM * > &  aOutput,
RN_ITEM_TYPE  aTypes = RN_ALL 
) const

Function GetConnectedItems() Adds items that are connected together to a list.

Parameters
aItemis the reference item to find other connected items.
aOutputis the list that will contain found items.
aTypesallows to filter by item types.

Definition at line 809 of file ratsnest_data.cpp.

References GetNodes(), m_pads, m_tracks, m_vias, m_zones, RN_PADS, RN_TRACKS, RN_VIAS, and RN_ZONES.

812 {
813  std::list<RN_NODE_PTR> nodes = GetNodes( aItem );
814  assert( !nodes.empty() );
815 
816  int tag = nodes.front()->GetTag();
817  assert( tag >= 0 );
818 
819  if( aTypes & RN_PADS )
820  {
821  for( PAD_NODE_MAP::const_iterator it = m_pads.begin(); it != m_pads.end(); ++it )
822  {
823  if( it->second.m_Node->GetTag() == tag )
824  aOutput.push_back( const_cast<D_PAD*>( it->first ) );
825  }
826  }
827 
828  if( aTypes & RN_VIAS )
829  {
830  for( VIA_NODE_MAP::const_iterator it = m_vias.begin(); it != m_vias.end(); ++it )
831  {
832  if( it->second->GetTag() == tag )
833  aOutput.push_back( const_cast<VIA*>( it->first ) );
834  }
835  }
836 
837  if( aTypes & RN_TRACKS )
838  {
839  for( TRACK_EDGE_MAP::const_iterator it = m_tracks.begin(); it != m_tracks.end(); ++it )
840  {
841  if( it->second->GetTag() == tag )
842  aOutput.push_back( const_cast<TRACK*>( it->first ) );
843  }
844  }
845 
846  if( aTypes & RN_ZONES )
847  {
848  for( ZONE_DATA_MAP::const_iterator it = m_zones.begin(); it != m_zones.end(); ++it )
849  {
850  for( const RN_EDGE_MST_PTR& edge : it->second.m_Edges )
851  {
852  if( edge->GetTag() == tag )
853  {
854  aOutput.push_back( const_cast<ZONE_CONTAINER*>( it->first ) );
855  break;
856  }
857  }
858  }
859  }
860 }
ZONE_DATA_MAP m_zones
Map that associates groups of subpolygons in the ratsnest model to respective zones.
PAD_NODE_MAP m_pads
Map that associates nodes in the ratsnest model to respective nodes.
TRACK_EDGE_MAP m_tracks
Map that associates edges in the ratsnest model to respective tracks.
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
std::list< RN_NODE_PTR > GetNodes(const BOARD_CONNECTED_ITEM *aItem) const
Function GetNodes() Returns list of nodes that are associated with a given item.
VIA_NODE_MAP m_vias
Map that associates nodes in the ratsnest model to respective vias.
std::list< RN_NODE_PTR > RN_NET::GetNodes ( const BOARD_CONNECTED_ITEM aItem) const

Function GetNodes() Returns list of nodes that are associated with a given item.

Parameters
aItemis an item for which the list is generated.
Returns
List of associated nodes.

Definition at line 713 of file ratsnest_data.cpp.

References m_pads, m_tracks, m_vias, m_zones, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, and EDA_ITEM::Type().

Referenced by AddSimple(), and GetConnectedItems().

714 {
715  std::list<RN_NODE_PTR> nodes;
716 
717  switch( aItem->Type() )
718  {
719  case PCB_PAD_T:
720  {
721  PAD_NODE_MAP::const_iterator it = m_pads.find( static_cast<const D_PAD*>( aItem ) );
722 
723  if( it != m_pads.end() )
724  nodes.push_back( it->second.m_Node );
725  }
726  break;
727 
728  case PCB_VIA_T:
729  {
730  VIA_NODE_MAP::const_iterator it = m_vias.find( static_cast<const VIA*>( aItem ) );
731 
732  if( it != m_vias.end() )
733  nodes.push_back( it->second );
734  }
735  break;
736 
737  case PCB_TRACE_T:
738  {
739  TRACK_EDGE_MAP::const_iterator it = m_tracks.find( static_cast<const TRACK*>( aItem ) );
740 
741  if( it != m_tracks.end() )
742  {
743  nodes.push_back( it->second->GetSourceNode() );
744  nodes.push_back( it->second->GetTargetNode() );
745  }
746  }
747  break;
748 
749  case PCB_ZONE_AREA_T:
750  {
751  ZONE_DATA_MAP::const_iterator itz = m_zones.find( static_cast<const ZONE_CONTAINER*>( aItem ) );
752 
753  if( itz != m_zones.end() )
754  {
755  const std::deque<RN_POLY>& polys = itz->second.m_Polygons;
756 
757  for( std::deque<RN_POLY>::const_iterator it = polys.begin(); it != polys.end(); ++it )
758  nodes.push_back( it->GetNode() );
759  }
760  }
761  break;
762 
763  default:
764  break;
765  }
766 
767  return nodes;
768 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
ZONE_DATA_MAP m_zones
Map that associates groups of subpolygons in the ratsnest model to respective zones.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
PAD_NODE_MAP m_pads
Map that associates nodes in the ratsnest model to respective nodes.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
TRACK_EDGE_MAP m_tracks
Map that associates edges in the ratsnest model to respective tracks.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
VIA_NODE_MAP m_vias
Map that associates nodes in the ratsnest model to respective vias.
const std::unordered_set<RN_NODE_PTR>& RN_NET::GetSimpleNodes ( ) const
inline

Function GetSimpleNodes() Returns list of nodes for which ratsnest is drawn in simple mode (i.e.

one ratsnest line per node).

Returns
list of nodes for which ratsnest is drawn in simple mode.

Definition at line 541 of file ratsnest_data.h.

References m_simpleNodes.

Referenced by KIGFX::RATSNEST_VIEWITEM::ViewDraw().

542  {
543  return m_simpleNodes;
544  }
std::unordered_set< RN_NODE_PTR > m_simpleNodes
Nodes to be displayed using the simplified ratsnest algorithm.
const std::vector<RN_EDGE_MST_PTR>* RN_NET::GetUnconnected ( ) const
inline

Function GetUnconnected() Returns pointer to a vector of edges that makes ratsnest for a given net.

Returns
Pointer to a vector of edges that makes ratsnest for a given net.

Definition at line 386 of file ratsnest_data.h.

References m_rnEdges.

Referenced by KIGFX::RATSNEST_VIEWITEM::ViewDraw().

387  {
388  return m_rnEdges.get();
389  }
std::shared_ptr< std::vector< RN_EDGE_MST_PTR > > m_rnEdges
Vector of edges that makes ratsnest for a given net.
bool RN_NET::IsDirty ( ) const
inline

Function IsDirty() Returns state of the 'dirty' flag, indicating that ratsnest for a given net is invalid and requires an update.

Returns
True if ratsnest requires recomputation, false otherwise.

Definition at line 376 of file ratsnest_data.h.

References m_dirty.

377  {
378  return m_dirty;
379  }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
bool RN_NET::IsVisible ( ) const
inline

Function IsVisible() Returns the visibility flag state.

Returns
True if ratsnest for given net is set as visible, false otherwise,

Definition at line 356 of file ratsnest_data.h.

References m_visible.

Referenced by KIGFX::RATSNEST_VIEWITEM::ViewDraw().

357  {
358  return m_visible;
359  }
bool m_visible
Visibility flag.
void RN_NET::MarkDirty ( )
inline

Function MarkDirty() Marks ratsnest for given net as 'dirty', i.e.

requiring recomputation.

Definition at line 365 of file ratsnest_data.h.

References m_dirty.

366  {
367  m_dirty = true;
368  }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
void RN_NET::processPads ( )
protected

Adds additional edges to account for connections made by items located in pads areas.

Definition at line 1028 of file ratsnest_data.cpp.

References RN_LINKS::AddConnection(), D_PAD::GetLayerSet(), RN_LINKS::GetNodes(), D_PAD::HitTest(), m_links, m_pads, and RN_LINKS::RemoveConnection().

Referenced by Update().

1029 {
1030  for( PAD_NODE_MAP::iterator it = m_pads.begin(); it != m_pads.end(); ++it )
1031  {
1032  const D_PAD* pad = it->first;
1033  RN_NODE_PTR node = it->second.m_Node;
1034  std::deque<RN_EDGE_MST_PTR>& edges = it->second.m_Edges;
1035 
1036  // Reset existing connections
1037  for( RN_EDGE_MST_PTR edge : edges )
1038  m_links.RemoveConnection( edge );
1039 
1040  LSET layers = pad->GetLayerSet();
1041  const RN_LINKS::RN_NODE_SET& candidates = m_links.GetNodes();
1042  RN_LINKS::RN_NODE_SET::const_iterator point, pointEnd;
1043 
1044  point = candidates.begin();
1045  pointEnd = candidates.end();
1046 
1047  while( point != pointEnd )
1048  {
1049  if( *point != node && ( (*point)->GetLayers() & layers ).any() &&
1050  pad->HitTest( wxPoint( (*point)->GetX(), (*point)->GetY() ) ) )
1051  {
1052  //(*point)->AddParent( pad ); // do not assign parent for helper links
1053 
1054  RN_EDGE_MST_PTR connection = m_links.AddConnection( node, *point );
1055  edges.push_back( connection );
1056  }
1057 
1058  ++point;
1059  }
1060  }
1061 }
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: class_pad.cpp:700
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
RN_LINKS m_links
PAD_NODE_MAP m_pads
Map that associates nodes in the ratsnest model to respective nodes.
Class LSET is a set of LAYER_IDs.
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:235
void RN_NET::processZones ( )
protected

Adds appropriate edges for nodes that are connected by zones.

Definition at line 974 of file ratsnest_data.cpp.

References RN_LINKS::AddConnection(), BOARD_ITEM::GetLayerSet(), RN_LINKS::GetNodes(), RN_NET::RN_ZONE_DATA::m_Edges, m_links, RN_NET::RN_ZONE_DATA::m_Polygons, m_zones, RN_LINKS::RemoveConnection(), and sortArea().

Referenced by Update().

975 {
976  for( ZONE_DATA_MAP::iterator it = m_zones.begin(); it != m_zones.end(); ++it )
977  {
978  const ZONE_CONTAINER* zone = it->first;
979  RN_ZONE_DATA& zoneData = it->second;
980 
981  // Reset existing connections
982  for( RN_EDGE_MST_PTR edge : zoneData.m_Edges )
983  m_links.RemoveConnection( edge );
984 
985  zoneData.m_Edges.clear();
986  LSET layers = zone->GetLayerSet();
987 
988  // Compute new connections
989  RN_LINKS::RN_NODE_SET candidates = m_links.GetNodes();
990  RN_LINKS::RN_NODE_SET::const_iterator point, pointEnd;
991 
992  // Sorting by area should speed up the processing, as smaller polygons are computed
993  // faster and may reduce the number of points for further checks
994  std::sort( zoneData.m_Polygons.begin(), zoneData.m_Polygons.end(), sortArea );
995 
996  for( std::deque<RN_POLY>::iterator poly = zoneData.m_Polygons.begin(),
997  polyEnd = zoneData.m_Polygons.end(); poly != polyEnd; ++poly )
998  {
999  const RN_NODE_PTR& node = poly->GetNode();
1000 
1001  point = candidates.begin();
1002  pointEnd = candidates.end();
1003 
1004  while( point != pointEnd )
1005  {
1006  if( *point != node && ( (*point)->GetLayers() & layers ).any()
1007  && poly->HitTest( *point ) )
1008  {
1009  //(*point)->AddParent( zone ); // do not assign parent for helper links
1010 
1011  RN_EDGE_MST_PTR connection = m_links.AddConnection( node, *point );
1012  zoneData.m_Edges.push_back( connection );
1013 
1014  // This point already belongs to a polygon, we do not need to check it anymore
1015  point = candidates.erase( point );
1016  pointEnd = candidates.end();
1017  }
1018  else
1019  {
1020  ++point;
1021  }
1022  }
1023  }
1024  }
1025 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
ZONE_DATA_MAP m_zones
Map that associates groups of subpolygons in the ratsnest model to respective zones.
RN_LINKS m_links
Class LSET is a set of LAYER_IDs.
bool sortArea(const RN_POLY &aP1, const RN_POLY &aP2)
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
void RN_NET::removeEdge ( RN_EDGE_MST_PTR aEdge,
const BOARD_CONNECTED_ITEM aParent 
)
protected

Removes a link between an edge and a parent, and clears its node data if it was the last parent.

Definition at line 285 of file ratsnest_data.cpp.

Referenced by RemoveItem().

286 {
287  // Save nodes, so they can be cleared later
288  RN_NODE_PTR start = aEdge->GetSourceNode();
289  RN_NODE_PTR end = aEdge->GetTargetNode();
290 
291  start->RemoveParent( aParent );
292  end->RemoveParent( aParent );
293 
294  // Connection has to be removed before running RemoveNode(),
295  // as RN_NODE influences the reference counter
296  m_links.RemoveConnection( aEdge );
297 
298  // Remove nodes associated with the edge. It is done in a safe way, there is a check
299  // if nodes are not used by other edges.
300  if( m_links.RemoveNode( start ) )
301  clearNode( start );
302 
303  if( m_links.RemoveNode( end ) )
304  clearNode( end );
305 
306  m_dirty = true;
307 }
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
RN_LINKS m_links
void clearNode(const RN_NODE_PTR &aNode)
Removes all ratsnest edges for a given node.
bool RN_NET::RemoveItem ( const D_PAD aPad)

Function RemoveItem() Removes all nodes and edges associated with selected pad, so they are not taken into account during ratsnest computations anymore.

Parameters
aPadis a pad for which nodes and edges are removed.

Definition at line 519 of file ratsnest_data.cpp.

References RN_NET::RN_PAD_DATA::m_Edges, RN_NET::RN_PAD_DATA::m_Node, m_pads, removeEdge(), and removeNode().

520 {
521  PAD_NODE_MAP::iterator it = m_pads.find( aPad );
522 
523  if( it == m_pads.end() )
524  return false;
525 
526  RN_PAD_DATA& pad_data = it->second;
527  removeNode( pad_data.m_Node, aPad );
528 
529  for( RN_EDGE_MST_PTR& edge : pad_data.m_Edges )
530  removeEdge( edge, aPad );
531 
532  m_pads.erase( aPad );
533 
534  return true;
535 }
void removeNode(RN_NODE_PTR &aNode, const BOARD_CONNECTED_ITEM *aParent)
Removes a link between a node and a parent, and clears linked edges if it was the last parent...
PAD_NODE_MAP m_pads
Map that associates nodes in the ratsnest model to respective nodes.
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
void removeEdge(RN_EDGE_MST_PTR &aEdge, const BOARD_CONNECTED_ITEM *aParent)
Removes a link between an edge and a parent, and clears its node data if it was the last parent...
bool RN_NET::RemoveItem ( const VIA aVia)

Function RemoveItem() Removes all nodes and edges associated with selected via, so they are not taken into account during ratsnest computations anymore.

Parameters
aViais a via for which nodes and edges are removed.

Definition at line 538 of file ratsnest_data.cpp.

References m_vias, and removeNode().

539 {
540  VIA_NODE_MAP::iterator it = m_vias.find( aVia );
541 
542  if( it == m_vias.end() )
543  return false;
544 
545  removeNode( it->second, aVia );
546  m_vias.erase( it );
547 
548  return true;
549 }
void removeNode(RN_NODE_PTR &aNode, const BOARD_CONNECTED_ITEM *aParent)
Removes a link between a node and a parent, and clears linked edges if it was the last parent...
VIA_NODE_MAP m_vias
Map that associates nodes in the ratsnest model to respective vias.
bool RN_NET::RemoveItem ( const TRACK aTrack)

Function RemoveItem() Removes all nodes and edges associated with selected track, so they are not taken into account during ratsnest computations anymore.

Parameters
aTrackis a track for which nodes and edges are removed.

Definition at line 552 of file ratsnest_data.cpp.

References m_tracks, and removeEdge().

553 {
554  TRACK_EDGE_MAP::iterator it = m_tracks.find( aTrack );
555 
556  if( it == m_tracks.end() )
557  return false;
558 
559  removeEdge( it->second, aTrack );
560  m_tracks.erase( it );
561 
562  return true;
563 }
TRACK_EDGE_MAP m_tracks
Map that associates edges in the ratsnest model to respective tracks.
void removeEdge(RN_EDGE_MST_PTR &aEdge, const BOARD_CONNECTED_ITEM *aParent)
Removes a link between an edge and a parent, and clears its node data if it was the last parent...
bool RN_NET::RemoveItem ( const ZONE_CONTAINER aZone)

Function RemoveItem() Removes all nodes and edges associated with selected zone, so they are not taken into account during ratsnest computations anymore.

Parameters
aZoneis a zone for which nodes and edges are removed.

Definition at line 566 of file ratsnest_data.cpp.

References RN_NET::RN_ZONE_DATA::m_Edges, RN_NET::RN_ZONE_DATA::m_Polygons, m_zones, removeEdge(), and removeNode().

567 {
568  ZONE_DATA_MAP::iterator it = m_zones.find( aZone );
569 
570  if( it == m_zones.end() )
571  return false;
572 
573  RN_ZONE_DATA& zoneData = it->second;
574 
575  // Remove all subpolygons that make the zone
576  std::deque<RN_POLY>& polygons = zoneData.m_Polygons;
577  for( RN_POLY& polygon : polygons )
578  removeNode( polygon.GetNode(), aZone );
579  polygons.clear();
580 
581  // Remove all connections added by the zone
582  std::deque<RN_EDGE_MST_PTR>& edges = zoneData.m_Edges;
583 
584  for( RN_EDGE_MST_PTR edge : edges )
585  removeEdge( edge, aZone );
586 
587  edges.clear();
588  m_zones.erase( it );
589 
590  return true;
591 }
void removeNode(RN_NODE_PTR &aNode, const BOARD_CONNECTED_ITEM *aParent)
Removes a link between a node and a parent, and clears linked edges if it was the last parent...
ZONE_DATA_MAP m_zones
Map that associates groups of subpolygons in the ratsnest model to respective zones.
Class RN_POLY Describes a single subpolygon (ZONE_CONTAINER is supposed to contain one or more of tho...
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
void removeEdge(RN_EDGE_MST_PTR &aEdge, const BOARD_CONNECTED_ITEM *aParent)
Removes a link between an edge and a parent, and clears its node data if it was the last parent...
void RN_NET::removeNode ( RN_NODE_PTR aNode,
const BOARD_CONNECTED_ITEM aParent 
)
protected

Removes a link between a node and a parent, and clears linked edges if it was the last parent.

Definition at line 273 of file ratsnest_data.cpp.

Referenced by RemoveItem().

274 {
275  aNode->RemoveParent( aParent );
276 
277  if( m_links.RemoveNode( aNode ) )
278  {
279  clearNode( aNode );
280  m_dirty = true;
281  }
282 }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
RN_LINKS m_links
void clearNode(const RN_NODE_PTR &aNode)
Removes all ratsnest edges for a given node.
void RN_NET::SetVisible ( bool  aEnabled)
inline

Function SetVisible() Sets state of the visibility flag.

Parameters
aEnabledis new state. True if ratsnest for a given net is meant to be displayed, false otherwise.

Definition at line 346 of file ratsnest_data.h.

References m_visible.

347  {
348  m_visible = aEnabled;
349  }
bool m_visible
Visibility flag.
void RN_NET::Update ( )

Function Update() Recomputes ratsnest for a net.

Definition at line 439 of file ratsnest_data.cpp.

References compute(), m_dirty, m_rnEdges, processPads(), processZones(), and validateEdge().

440 {
441  // Add edges resulting from nodes being connected by zones
442  processZones();
443  processPads();
444 
445  compute();
446 
447  for( RN_EDGE_MST_PTR& edge : *m_rnEdges )
448  validateEdge( edge );
449 
450  m_dirty = false;
451 }
void processPads()
Adds additional edges to account for connections made by items located in pads areas.
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
void compute()
Recomputes ratsnset from scratch.
void validateEdge(RN_EDGE_MST_PTR &aEdge)
Validates edge, i.e.
std::shared_ptr< hed::EDGE_MST > RN_EDGE_MST_PTR
Definition: ratsnest_data.h:69
std::shared_ptr< std::vector< RN_EDGE_MST_PTR > > m_rnEdges
Vector of edges that makes ratsnest for a given net.
void processZones()
Adds appropriate edges for nodes that are connected by zones.
void RN_NET::validateEdge ( RN_EDGE_MST_PTR aEdge)
protected

Validates edge, i.e.

modifies source and target nodes for an edge

to make sure that they are not ones with the flag set.

Definition at line 211 of file ratsnest_data.cpp.

Referenced by Update().

212 {
213  RN_NODE_PTR source = aEdge->GetSourceNode();
214  RN_NODE_PTR target = aEdge->GetTargetNode();
215  bool update = false, changed = false;
216 
217  // If any of nodes belonging to the edge has the flag set,
218  // change it to the closest node that has flag cleared
219  // note: finding the right nodes can be done iteratively to get the best results,
220  // but it is not likely to be worth the time cost
221  do
222  {
223  if( changed || source->GetNoLine() )
224  {
225  changed = false;
226  std::list<RN_NODE_PTR> closest = GetClosestNodes( target,
227  LINE_TARGET_SAME_TAG( source->GetTag() ) );
228 
229  if( !closest.empty() )
230  {
231  RN_NODE_PTR& node = closest.front();
232 
233  if( node != source )
234  {
235  changed = true;
236  update = true;
237  source = node;
238  }
239  }
240  }
241 
242  if( changed || target->GetNoLine() )
243  {
244  changed = false;
245  std::list<RN_NODE_PTR> closest = GetClosestNodes( source,
246  LINE_TARGET_SAME_TAG( target->GetTag() ) );
247 
248  if( !closest.empty() )
249  {
250  RN_NODE_PTR& node = closest.front();
251 
252  if( node != target )
253  {
254  changed = true;
255  update = true;
256  target = node;
257  }
258  }
259  }
260  }
261  while( changed );
262 
263  assert( source->GetTag() >= 0 && target->GetTag() >= 0 );
264  assert( source->GetTag() != target->GetTag() );
265  assert( source != target );
266 
267  // Replace an invalid edge with new, valid one
268  if( update )
269  aEdge.reset( new RN_EDGE_MST( source, target ) );
270 }
Leaves nodes that can be a ratsnest line target and have a specific tag
hed::NODE_PTR RN_NODE_PTR
Definition: ratsnest_data.h:64
hed::EDGE_MST RN_EDGE_MST
Definition: ratsnest_data.h:67
std::list< RN_NODE_PTR > GetClosestNodes(const RN_NODE_PTR &aNode, int aNumber=-1) const
Function GetClosestNodes() Returns list of nodes sorted by the distance from a specific node...

Member Data Documentation

std::unordered_set<RN_NODE_PTR> RN_NET::m_blockedNodes
protected

List of nodes which will not be used as ratsnest target nodes.

Definition at line 595 of file ratsnest_data.h.

Referenced by AddBlockedNode(), and ClearSimple().

bool RN_NET::m_dirty
protected

Flag indicating necessity of recalculation of ratsnest for a net.

Definition at line 601 of file ratsnest_data.h.

Referenced by AddItem(), IsDirty(), MarkDirty(), and Update().

RN_LINKS RN_NET::m_links
protected

Definition at line 589 of file ratsnest_data.h.

Referenced by AddItem(), GetClosestNode(), GetClosestNodes(), processPads(), and processZones().

PAD_NODE_MAP RN_NET::m_pads
protected

Map that associates nodes in the ratsnest model to respective nodes.

Definition at line 630 of file ratsnest_data.h.

Referenced by AddItem(), GetAllItems(), GetConnectedItems(), GetNodes(), processPads(), and RemoveItem().

std::shared_ptr< std::vector<RN_EDGE_MST_PTR> > RN_NET::m_rnEdges
protected

Vector of edges that makes ratsnest for a given net.

Definition at line 592 of file ratsnest_data.h.

Referenced by GetUnconnected(), and Update().

std::unordered_set<RN_NODE_PTR> RN_NET::m_simpleNodes
protected

Nodes to be displayed using the simplified ratsnest algorithm.

Definition at line 598 of file ratsnest_data.h.

Referenced by AddSimple(), ClearSimple(), and GetSimpleNodes().

TRACK_EDGE_MAP RN_NET::m_tracks
protected

Map that associates edges in the ratsnest model to respective tracks.

Definition at line 636 of file ratsnest_data.h.

Referenced by AddItem(), GetAllItems(), GetConnectedItems(), GetNodes(), and RemoveItem().

VIA_NODE_MAP RN_NET::m_vias
protected

Map that associates nodes in the ratsnest model to respective vias.

Definition at line 633 of file ratsnest_data.h.

Referenced by AddItem(), GetAllItems(), GetConnectedItems(), GetNodes(), and RemoveItem().

bool RN_NET::m_visible
protected

Visibility flag.

Definition at line 642 of file ratsnest_data.h.

Referenced by IsVisible(), and SetVisible().

ZONE_DATA_MAP RN_NET::m_zones
protected

Map that associates groups of subpolygons in the ratsnest model to respective zones.

Definition at line 639 of file ratsnest_data.h.

Referenced by AddItem(), GetAllItems(), GetConnectedItems(), GetNodes(), processZones(), and RemoveItem().


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