KiCad PCB EDA Suite
ratsnest.cpp File Reference

Ratsnets functions. More...

#include <fctsys.h>
#include <gr_basic.h>
#include <common.h>
#include <class_drawpanel.h>
#include <colors_selection.h>
#include <wxBasePcbFrame.h>
#include <macros.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <pcbnew.h>
#include <minimun_spanning_tree.h>

Go to the source code of this file.

Classes

class  MIN_SPAN_TREE_PADS
 class MIN_SPAN_TREE_PADS (derived from MIN_SPAN_TREE) specializes the base class to calculate a minimum spanning tree from a list of pads, and to add this tree as ratsnest to the main ratsnest list. More...
 

Functions

static bool sortByNetcode (const D_PAD *const &ref, const D_PAD *const &item)
 
static int tst_links_between_blocks (NETINFO_ITEM *aNetinfo, std::vector< RATSNEST_ITEM > &aRatsnestBuffer)
 Function used by TestForActiveLinksInRatsnest Function testing the ratsnest between 2 blocks ( of the same net ) The search is made between pads in block 1 and the others blocks The block n ( n > 1 ) is merged with block 1 and linked by the smallest ratsnest between block 1 and the block n (activate the logical connection) More...
 
static void tst_links_between_pads (int &aCurrSubRatsnestId, RATSNEST_ITEM *aFirstItem, RATSNEST_ITEM *aLastItem)
 Function used by TestForActiveLinksInRatsnest_general The general ratsnest list must exists because this function explores this ratsnest Activates (i.e. More...
 
static bool sort_by_distance (const wxPoint &ref, const wxPoint &compare)
 
static bool sort_by_point (const wxPoint &ref, const wxPoint &compare)
 

Variables

static std::vector< wxPoints_TargetsLocations
 
static wxPoint s_CursorPos
 

Detailed Description

Ratsnets functions.

Definition in file ratsnest.cpp.

Function Documentation

static bool sort_by_distance ( const wxPoint ref,
const wxPoint compare 
)
static

Definition at line 808 of file ratsnest.cpp.

References abs, s_CursorPos, wxPoint::x, and wxPoint::y.

Referenced by PCB_BASE_FRAME::BuildAirWiresTargetsList().

809 {
810  wxPoint deltaref = ref - s_CursorPos; // relative coordinate of ref
811  wxPoint deltacmp = compare - s_CursorPos; // relative coordinate of compare
812 
813  // rectilinear distance between ref and s_CursorPos:
814  int lengthref = abs( deltaref.x ) + abs( deltaref.y );
815 
816  // rectilinear distance between compare and s_CursorPos:
817  int lengthcmp = abs( deltacmp.x ) + abs( deltacmp.y );
818 
819  return lengthref < lengthcmp;
820 }
static wxPoint s_CursorPos
Definition: ratsnest.cpp:802
#define abs(a)
Definition: auxiliary.h:84
static bool sort_by_point ( const wxPoint ref,
const wxPoint compare 
)
static

Definition at line 822 of file ratsnest.cpp.

References wxPoint::x, and wxPoint::y.

Referenced by PCB_BASE_FRAME::BuildAirWiresTargetsList().

823 {
824  if( ref.x == compare.x )
825  return ref.y < compare.y;
826 
827  return ref.x < compare.x;
828 }
static bool sortByNetcode ( const D_PAD *const &  ref,
const D_PAD *const &  item 
)
static

Definition at line 211 of file ratsnest.cpp.

References BOARD_CONNECTED_ITEM::GetNetCode().

Referenced by PCB_BASE_FRAME::build_ratsnest_module().

212 {
213  return ref->GetNetCode() < item->GetNetCode();
214 }
int GetNetCode() const
Function GetNetCode.
static int tst_links_between_blocks ( NETINFO_ITEM aNetinfo,
std::vector< RATSNEST_ITEM > &  aRatsnestBuffer 
)
static

Function used by TestForActiveLinksInRatsnest Function testing the ratsnest between 2 blocks ( of the same net ) The search is made between pads in block 1 and the others blocks The block n ( n > 1 ) is merged with block 1 and linked by the smallest ratsnest between block 1 and the block n (activate the logical connection)

Parameters
aRatsnestBuffer= the buffer to store NETINFO_ITEM* items
aNetinfo= the current NETINFO_ITEM for the current net output: .state member, bit CH_ACTIF of the ratsnest item
Returns
last subratsnest id in use

Definition at line 339 of file ratsnest.cpp.

References CH_ACTIF, D_PAD::GetSubRatsnest(), RATSNEST_ITEM::m_Length, RATSNEST_ITEM::m_PadEnd, NETINFO_ITEM::m_PadInNetList, RATSNEST_ITEM::m_PadStart, NETINFO_ITEM::m_RatsnestStartIdx, and RATSNEST_ITEM::m_Status.

Referenced by PCB_BASE_FRAME::TestForActiveLinksInRatsnest().

341 {
342  int subratsnest_id, min_id;
343  RATSNEST_ITEM* link, * best_link;
344 
345  // Search a link from a block to an other block
346  best_link = NULL;
347 
348  for( unsigned ii = aNetinfo->m_RatsnestStartIdx; ii < aNetinfo->m_RatsnestEndIdx; ii++ )
349  {
350  link = &aRatsnestBuffer[ii];
351 
352  // If this link joints 2 pads inside the same block, do nothing
353  // (these pads are already connected)
354  if( link->m_PadStart->GetSubRatsnest() == link->m_PadEnd->GetSubRatsnest() )
355  continue;
356 
357  // This link joints 2 pads of different blocks: this is a candidate,
358  // but we want to select the shorter link, so use it only if it is shorter
359  // than the previous candidate:
360  if( best_link == NULL ) // no candidate
361  best_link = link;
362  else if( best_link->m_Length > link->m_Length ) // It is a better candidate.
363  best_link = link;
364  }
365 
366  if( best_link == NULL )
367  return 1;
368 
369  /* At this point we have found a link between 2 different blocks (subratsnest)
370  * we must set its status to ACTIVE and merge the 2 blocks
371  */
372  best_link->m_Status |= CH_ACTIF;
373  subratsnest_id = best_link->m_PadStart->GetSubRatsnest();
374  min_id = best_link->m_PadEnd->GetSubRatsnest();
375 
376  if( min_id > subratsnest_id )
377  std::swap( min_id, subratsnest_id );
378 
379  // Merge the 2 blocks in one sub ratsnest:
380  for( unsigned ii = 0; ii < aNetinfo->m_PadInNetList.size(); ii++ )
381  {
382  if( aNetinfo->m_PadInNetList[ii]->GetSubRatsnest() == subratsnest_id )
383  {
384  aNetinfo->m_PadInNetList[ii]->SetSubRatsnest( min_id );
385  }
386  }
387 
388  return subratsnest_id;
389 }
D_PADS m_PadInNetList
List of pads connected to this net.
#define CH_ACTIF
Definition: class_netinfo.h:60
D_PAD * m_PadEnd
Definition: class_netinfo.h:76
unsigned m_RatsnestStartIdx
int GetSubRatsnest() const
Function GetSubRatsnest.
Definition: class_pad.h:474
D_PAD * m_PadStart
Definition: class_netinfo.h:75
Class RATSNEST_ITEM describes a ratsnest line: a straight line connecting 2 pads. ...
Definition: class_netinfo.h:68
static void tst_links_between_pads ( int &  aCurrSubRatsnestId,
RATSNEST_ITEM aFirstItem,
RATSNEST_ITEM aLastItem 
)
static

Function used by TestForActiveLinksInRatsnest_general The general ratsnest list must exists because this function explores this ratsnest Activates (i.e.

set the CH_ACTIF flag) the ratsnest links between 2 pads when at least one pad not already connected (SubRatsnest = 0) and actives the corresponding link

Parameters
aFirstItem= starting address for the ratsnest list
aLastItem= ending address for the ratsnest list
aCurrSubRatsnestId= last sub ratsnest id in use (computed from the track analysis)
 output:
     ratsnest list (status member bit CH_ACTIF set)
     and pads linked (m_SubRatsnest value set)
Returns
new block number

Definition at line 410 of file ratsnest.cpp.

References CH_ACTIF, D_PAD::GetSubRatsnest(), and D_PAD::SetSubRatsnest().

Referenced by PCB_BASE_FRAME::TestForActiveLinksInRatsnest().

413 {
414  for( RATSNEST_ITEM* item = aFirstItem; item < aLastItem; item++ )
415  {
416  D_PAD* pad_start = item->m_PadStart;
417  D_PAD* pad_end = item->m_PadEnd;
418 
419  /* Update the current SubRatsnest if the 2 pads are not connected :
420  * a new cluster is created and the link activated
421  */
422  if( (pad_start->GetSubRatsnest() == 0) && (pad_end->GetSubRatsnest() == 0) )
423  {
424  aCurrSubRatsnestId++;
425  pad_start->SetSubRatsnest( aCurrSubRatsnestId );
426  pad_end->SetSubRatsnest( aCurrSubRatsnestId );
427  item->m_Status |= CH_ACTIF;
428  }
429 
430  /* If a pad is already connected to a subratsnest: activate the link
431  * the pad other is merged in the existing subratsnest
432  */
433  else if( pad_start->GetSubRatsnest() == 0 )
434  {
435  pad_start->SetSubRatsnest( pad_end->GetSubRatsnest() );
436  item->m_Status |= CH_ACTIF;
437  }
438  else if( pad_end->GetSubRatsnest() == 0 )
439  {
440  pad_end->SetSubRatsnest( pad_start->GetSubRatsnest() );
441  item->m_Status |= CH_ACTIF;
442  }
443  }
444 }
void SetSubRatsnest(int aSubRatsnest)
Definition: class_pad.h:475
#define CH_ACTIF
Definition: class_netinfo.h:60
int GetSubRatsnest() const
Function GetSubRatsnest.
Definition: class_pad.h:474
Class RATSNEST_ITEM describes a ratsnest line: a straight line connecting 2 pads. ...
Definition: class_netinfo.h:68

Variable Documentation

wxPoint s_CursorPos
static

Definition at line 802 of file ratsnest.cpp.

Referenced by sort_by_distance(), and PCB_BASE_FRAME::TraceAirWiresToTargets().

std::vector<wxPoint> s_TargetsLocations
static