KiCad PCB EDA Suite
RN_NET Class Reference

Class 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

Class RN_NET Describes ratsnest for a single net.

Definition at line 59 of file ratsnest_data.h.

Constructor & Destructor Documentation

RN_NET::RN_NET ( )

Default constructor.

Definition at line 334 of file ratsnest_data.cpp.

References m_triangulator.

334  : m_dirty( true )
335 {
336  m_triangulator.reset( new TRIANGULATOR_STATE );
337 }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
std::shared_ptr< TRIANGULATOR_STATE > m_triangulator

Member Function Documentation

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

Definition at line 420 of file ratsnest_data.cpp.

References CN_ITEM::Anchors(), i, m_boardEdges, and m_nodes.

Referenced by GetUnconnected().

421 {
422  CN_ANCHOR_PTR firstAnchor;
423 
424  for( auto item : *aCluster )
425  {
426  bool isZone = dynamic_cast<CN_ZONE*>(item) != nullptr;
427  auto& anchors = item->Anchors();
428  unsigned int nAnchors = isZone ? 1 : anchors.size();
429 
430  if( nAnchors > anchors.size() )
431  nAnchors = anchors.size();
432 
433  //printf("item %p anchors : %d\n", item, anchors.size() );
434  //printf("add item %p anchors : %d net : %d\n", item, item->Anchors().size(), item->Parent()->GetNetCode() );
435 
436  for( unsigned int i = 0; i < nAnchors; i++ )
437  {
438  // printf("add anchor %p\n", anchors[i].get() );
439 
440  anchors[i]->SetCluster( aCluster );
441  m_nodes.push_back(anchors[i]);
442 
443  if( firstAnchor )
444  {
445  if( firstAnchor != anchors[i] )
446  {
447  m_boardEdges.emplace_back( firstAnchor, anchors[i], 0 );
448  }
449  }
450  else
451  {
452  firstAnchor = anchors[i];
453  }
454  }
455  }
456 }
CN_ANCHORS & Anchors()
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes
std::vector< CN_EDGE > m_boardEdges
Vector of edges that make pre-defined connections
size_t i
Definition: json11.cpp:597
std::shared_ptr< CN_ANCHOR > CN_ANCHOR_PTR
void RN_NET::Clear ( )

Definition at line 410 of file ratsnest_data.cpp.

References m_boardEdges, m_dirty, m_nodes, and m_rnEdges.

Referenced by GetUnconnected().

411 {
412  m_rnEdges.clear();
413  m_boardEdges.clear();
414  m_nodes.clear();
415 
416  m_dirty = true;
417 }
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
void RN_NET::compute ( )
protected

Recomputes ratsnest from scratch.

Definition at line 340 of file ratsnest_data.cpp.

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

Referenced by GetEdges(), and Update().

341 {
342  // Special cases do not need complicated algorithms (actually, it does not work well with
343  // the Delaunay triangulator)
344  //printf("compute nodes : %d\n", m_nodes.size() );
345  if( m_nodes.size() <= 2 )
346  {
347  m_rnEdges.clear();
348 
349  // Check if the only possible connection exists
350  if( m_boardEdges.size() == 0 && m_nodes.size() == 2 )
351  {
352  auto last = ++m_nodes.begin();
353 
354  // There can be only one possible connection, but it is missing
355  CN_EDGE edge (*m_nodes.begin(), *last );
356  edge.GetSourceNode()->SetTag( 0 );
357  edge.GetTargetNode()->SetTag( 1 );
358 
359  m_rnEdges.push_back( edge );
360  }
361  else
362  {
363  // Set tags to m_nodes as connected
364  for( auto node : m_nodes )
365  node->SetTag( 0 );
366  }
367 
368  return;
369  }
370 
371 
372  m_triangulator->Clear();
373 
374  for( auto n : m_nodes )
375  {
376  m_triangulator->AddNode( n );
377  }
378 
379  #ifdef PROFILE
380  PROF_COUNTER cnt("triangulate");
381  #endif
382  auto triangEdges = m_triangulator->Triangulate();
383  #ifdef PROFILE
384  cnt.Show();
385  #endif
386 
387  for( const auto& e : m_boardEdges )
388  triangEdges.push_back( e );
389 
390 // Get the minimal spanning tree
391 #ifdef PROFILE
392  PROF_COUNTER cnt2("mst");
393 #endif
394  m_rnEdges = kruskalMST( triangEdges, m_nodes );
395 #ifdef PROFILE
396  cnt2.Show();
397 #endif
398 }
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:45
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
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.

Referenced by GetEdges().

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.

Referenced by GetEdges().

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

Definition at line 125 of file ratsnest_data.h.

References compute(), GetAllItems(), GetClosestNode(), m_rnEdges, and NearestBicoloredPair().

Referenced by PCB_BASE_FRAME::DrawGeneralRatsnest().

126  {
127  return m_rnEdges;
128  }
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.
unsigned int RN_NET::GetNodeCount ( ) const
inline

Definition at line 112 of file ratsnest_data.h.

References GetNodes(), and m_nodes.

113  {
114  return m_nodes.size();
115  }
std::vector< CN_ANCHOR_PTR > m_nodes
Vector of nodes
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.

Referenced by GetNodeCount().

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.

References AddCluster(), Clear(), m_rnEdges, and Update().

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

99  {
100  return m_rnEdges;
101  }
std::vector< CN_EDGE > 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 88 of file ratsnest_data.h.

References m_dirty.

89  {
90  return m_dirty;
91  }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
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.

References m_dirty.

78  {
79  m_dirty = true;
80  }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
bool RN_NET::NearestBicoloredPair ( const RN_NET aOtherNet,
CN_ANCHOR_PTR aNode1,
CN_ANCHOR_PTR aNode2 
) const

Definition at line 459 of file ratsnest_data.cpp.

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

Referenced by GetEdges().

461 {
462  bool rv = false;
463 
465 
466  for( auto nodeA : m_nodes )
467  {
468  for( auto nodeB : aOtherNet.m_nodes )
469  {
470  if( !nodeA->GetNoLine() )
471  {
472  auto squaredDist = (nodeA->Pos() - nodeB->Pos() ).SquaredEuclideanNorm();
473 
474  if( squaredDist < distMax )
475  {
476  rv = true;
477  distMax = squaredDist;
478  aNode1 = nodeA;
479  aNode2 = nodeB;
480  }
481  }
482  }
483  }
484 
485  return rv;
486 }
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
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 489 of file ratsnest_data.cpp.

References m_rnEdges.

490 {
491  for( auto& edge : m_rnEdges )
492  edge.SetVisible( aEnabled );
493 }
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.
void RN_NET::Update ( )

Function Update() Recomputes ratsnest for a net.

Definition at line 402 of file ratsnest_data.cpp.

References compute(), and m_dirty.

Referenced by GetUnconnected().

403 {
404  compute();
405 
406  m_dirty = false;
407 }
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
void compute()
Recomputes ratsnest from scratch.

Member Data Documentation

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().

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().

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().

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().

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: