KiCad PCB EDA Suite
RN_NET Class Reference

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

#include <ratsnest_data.h>

Classes

class  TRIANGULATOR_STATE
 

Public Member Functions

 RN_NET ()
 

Default constructor.

More...
 
void SetVisible (bool aEnabled)
 Function SetVisible() Sets state of the visibility flag. 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< CN_EDGEGetUnconnected () 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...
 
void Clear ()
 
void AddCluster (std::shared_ptr< CN_CLUSTER > aCluster)
 
unsigned int GetNodeCount () const
 
std::list< CN_ANCHOR_PTRGetNodes (const BOARD_CONNECTED_ITEM *aItem) const
 Function GetNodes() Returns list of nodes that are associated with a given item. More...
 
const std::vector< CN_EDGE > & GetEdges () const
 
void GetAllItems (std::list< BOARD_CONNECTED_ITEM * > &aOutput, const KICAD_T aTypes[]) const
 Function GetAllItems() Adds all stored items to a list. More...
 
const CN_ANCHOR_PTR GetClosestNode (const CN_ANCHOR_PTR &aNode) const
 Function GetClosestNode() Returns a single node that lies in the shortest distance from a specific node. More...
 
bool NearestBicoloredPair (const RN_NET &aOtherNet, CN_ANCHOR_PTR &aNode1, CN_ANCHOR_PTR &aNode2) const
 

Protected Member Functions

void compute ()
 

Recomputes ratsnest from scratch.

More...
 

Protected Attributes

std::vector< CN_ANCHOR_PTRm_nodes
 

Vector of nodes

More...
 
std::vector< CN_EDGEm_boardEdges
 

Vector of edges that make pre-defined connections

More...
 
std::vector< CN_EDGEm_rnEdges
 

Vector of edges that makes ratsnest for a given net.

More...
 
bool m_dirty
 

Flag indicating necessity of recalculation of ratsnest for a net.

More...
 
std::shared_ptr< TRIANGULATOR_STATEm_triangulator
 

Detailed Description

RN_NET Describes ratsnest for a single net.

Definition at line 59 of file ratsnest_data.h.

Constructor & Destructor Documentation

◆ RN_NET()

RN_NET::RN_NET ( )

Default constructor.

Definition at line 317 of file ratsnest_data.cpp.

317  : m_dirty( true )
318 {
319  m_triangulator.reset( new TRIANGULATOR_STATE );
320 }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
std::shared_ptr< TRIANGULATOR_STATE > m_triangulator

References m_triangulator.

Member Function Documentation

◆ AddCluster()

void RN_NET::AddCluster ( std::shared_ptr< CN_CLUSTER aCluster)

Definition at line 402 of file ratsnest_data.cpp.

403 {
404  CN_ANCHOR_PTR firstAnchor;
405 
406  for( auto item : *aCluster )
407  {
408  bool isZone = dynamic_cast<CN_ZONE*>(item) != nullptr;
409  auto& anchors = item->Anchors();
410  unsigned int nAnchors = isZone ? 1 : anchors.size();
411 
412  if( nAnchors > anchors.size() )
413  nAnchors = anchors.size();
414 
415  for( unsigned int i = 0; i < nAnchors; i++ )
416  {
417  anchors[i]->SetCluster( aCluster );
418  m_nodes.push_back(anchors[i]);
419 
420  if( firstAnchor )
421  {
422  if( firstAnchor != anchors[i] )
423  {
424  m_boardEdges.emplace_back( firstAnchor, anchors[i], 0 );
425  }
426  }
427  else
428  {
429  firstAnchor = anchors[i];
430  }
431  }
432  }
433 }
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes
std::vector< CN_EDGE > m_boardEdges
Vector of edges that make pre-defined connections
std::shared_ptr< CN_ANCHOR > CN_ANCHOR_PTR

References m_boardEdges, and m_nodes.

◆ Clear()

void RN_NET::Clear ( )

Definition at line 392 of file ratsnest_data.cpp.

393 {
394  m_rnEdges.clear();
395  m_boardEdges.clear();
396  m_nodes.clear();
397 
398  m_dirty = true;
399 }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes
std::vector< CN_EDGE > m_boardEdges
Vector of edges that make pre-defined connections

References m_boardEdges, m_dirty, m_nodes, and m_rnEdges.

◆ compute()

void RN_NET::compute ( )
protected

Recomputes ratsnest from scratch.

Definition at line 323 of file ratsnest_data.cpp.

324 {
325  // Special cases do not need complicated algorithms (actually, it does not work well with
326  // the Delaunay triangulator)
327  if( m_nodes.size() <= 2 )
328  {
329  m_rnEdges.clear();
330 
331  // Check if the only possible connection exists
332  if( m_boardEdges.size() == 0 && m_nodes.size() == 2 )
333  {
334  auto last = ++m_nodes.begin();
335 
336  // There can be only one possible connection, but it is missing
337  CN_EDGE edge (*m_nodes.begin(), *last );
338  edge.GetSourceNode()->SetTag( 0 );
339  edge.GetTargetNode()->SetTag( 1 );
340 
341  m_rnEdges.push_back( edge );
342  }
343  else
344  {
345  // Set tags to m_nodes as connected
346  for( const auto& node : m_nodes )
347  node->SetTag( 0 );
348  }
349 
350  return;
351  }
352 
353 
354  m_triangulator->Clear();
355 
356  for( const auto& n : m_nodes )
357  {
358  m_triangulator->AddNode( n );
359  }
360 
361  #ifdef PROFILE
362  PROF_COUNTER cnt("triangulate");
363  #endif
364  auto triangEdges = m_triangulator->Triangulate();
365  #ifdef PROFILE
366  cnt.Show();
367  #endif
368 
369  for( const auto& e : m_boardEdges )
370  triangEdges.push_back( e );
371 
372 // Get the minimal spanning tree
373 #ifdef PROFILE
374  PROF_COUNTER cnt2("mst");
375 #endif
376  m_rnEdges = kruskalMST( triangEdges, m_nodes );
377 #ifdef PROFILE
378  cnt2.Show();
379 #endif
380 }
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:44
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes
static const std::vector< CN_EDGE > kruskalMST(std::list< CN_EDGE > &aEdges, std::vector< CN_ANCHOR_PTR > &aNodes)
std::shared_ptr< TRIANGULATOR_STATE > m_triangulator
std::vector< CN_EDGE > m_boardEdges
Vector of edges that make pre-defined connections
CN_ANCHOR_PTR GetSourceNode() const

References CN_EDGE::GetSourceNode(), kruskalMST(), m_boardEdges, m_nodes, m_rnEdges, m_triangulator, and PROF_COUNTER::Show().

Referenced by Update().

◆ GetAllItems()

void RN_NET::GetAllItems ( std::list< BOARD_CONNECTED_ITEM * > &  aOutput,
const KICAD_T  aTypes[] 
) const

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

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

◆ GetClosestNode()

const CN_ANCHOR_PTR RN_NET::GetClosestNode ( const CN_ANCHOR_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.

◆ GetEdges()

const std::vector<CN_EDGE>& RN_NET::GetEdges ( ) const
inline

Definition at line 125 of file ratsnest_data.h.

126  {
127  return m_rnEdges;
128  }
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.

References m_rnEdges.

◆ GetNodeCount()

unsigned int RN_NET::GetNodeCount ( ) const
inline

Definition at line 112 of file ratsnest_data.h.

113  {
114  return m_nodes.size();
115  }
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes

References m_nodes.

◆ GetNodes()

std::list<CN_ANCHOR_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.

◆ GetUnconnected()

const std::vector<CN_EDGE> 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 98 of file ratsnest_data.h.

99  {
100  return m_rnEdges;
101  }
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.

References m_rnEdges.

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

◆ IsDirty()

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

89  {
90  return m_dirty;
91  }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.

References m_dirty.

◆ MarkDirty()

void RN_NET::MarkDirty ( )
inline

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

requiring recomputation.

Definition at line 77 of file ratsnest_data.h.

78  {
79  m_dirty = true;
80  }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.

References m_dirty.

◆ NearestBicoloredPair()

bool RN_NET::NearestBicoloredPair ( const RN_NET aOtherNet,
CN_ANCHOR_PTR aNode1,
CN_ANCHOR_PTR aNode2 
) const

Definition at line 436 of file ratsnest_data.cpp.

438 {
439  bool rv = false;
440 
442 
443  for( const auto& nodeA : m_nodes )
444  {
445  for( const auto& nodeB : aOtherNet.m_nodes )
446  {
447  if( !nodeA->GetNoLine() )
448  {
449  auto squaredDist = (nodeA->Pos() - nodeB->Pos() ).SquaredEuclideanNorm();
450 
451  if( squaredDist < distMax )
452  {
453  rv = true;
454  distMax = squaredDist;
455  aNode1 = nodeA;
456  aNode2 = nodeB;
457  }
458  }
459  }
460  }
461 
462  return rv;
463 }
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80

References VECTOR2< T >::ECOORD_MAX, and m_nodes.

◆ SetVisible()

void RN_NET::SetVisible ( bool  aEnabled)

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 466 of file ratsnest_data.cpp.

467 {
468  for( auto& edge : m_rnEdges )
469  edge.SetVisible( aEnabled );
470 }
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.

References m_rnEdges.

◆ Update()

void RN_NET::Update ( )

Function Update() Recomputes ratsnest for a net.

Definition at line 384 of file ratsnest_data.cpp.

385 {
386  compute();
387 
388  m_dirty = false;
389 }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
void compute()
Recomputes ratsnest from scratch.

References compute(), and m_dirty.

Member Data Documentation

◆ m_boardEdges

std::vector<CN_EDGE> RN_NET::m_boardEdges
protected

Vector of edges that make pre-defined connections

Definition at line 155 of file ratsnest_data.h.

Referenced by AddCluster(), Clear(), and compute().

◆ m_dirty

bool RN_NET::m_dirty
protected

Flag indicating necessity of recalculation of ratsnest for a net.

Definition at line 161 of file ratsnest_data.h.

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

◆ m_nodes

std::vector<CN_ANCHOR_PTR> RN_NET::m_nodes
protected

Vector of nodes

Definition at line 152 of file ratsnest_data.h.

Referenced by AddCluster(), Clear(), compute(), GetNodeCount(), and NearestBicoloredPair().

◆ m_rnEdges

std::vector<CN_EDGE> RN_NET::m_rnEdges
protected

Vector of edges that makes ratsnest for a given net.

Definition at line 158 of file ratsnest_data.h.

Referenced by Clear(), compute(), GetEdges(), GetUnconnected(), and SetVisible().

◆ m_triangulator

std::shared_ptr<TRIANGULATOR_STATE> RN_NET::m_triangulator
protected

Definition at line 163 of file ratsnest_data.h.

Referenced by compute(), and RN_NET().


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