KiCad PCB EDA Suite
pcbnew/tools/selection_tool.cpp File Reference
#include <limits>
#include <functional>
#include <class_board.h>
#include <class_board_item.h>
#include <class_track.h>
#include <class_module.h>
#include <class_pcb_text.h>
#include <class_drawsegment.h>
#include <class_zone.h>
#include <pcb_edit_frame.h>
#include <collectors.h>
#include <confirm.h>
#include <dialog_find.h>
#include <dialog_block_options.h>
#include <class_draw_panel_gal.h>
#include <view/view_controls.h>
#include <view/view_group.h>
#include <preview_items/selection_area.h>
#include <painter.h>
#include <bitmaps.h>
#include <hotkeys.h>
#include <tool/tool_event.h>
#include <tool/tool_manager.h>
#include <router/router_tool.h>
#include <connectivity/connectivity_data.h>
#include <footprint_viewer_frame.h>
#include "tool_event_utils.h"
#include "selection_tool.h"
#include "pcb_bright_box.h"
#include "pcb_actions.h"
#include "kicad_plugin.h"

Go to the source code of this file.

Classes

class  SELECT_MENU
 
class  SELECTION_TOOL::PRIV
 Private implementation of firewalled private data. More...
 

Functions

static EDA_RECT getRect (const BOARD_ITEM *aItem)
 
void connectedTrackFilter (const VECTOR2I &aPt, GENERAL_COLLECTOR &aCollector)
 
void connectedItemFilter (const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
 
static bool itemIsIncludedByFilter (const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_BLOCK_OPTIONS::OPTIONS &aBlockOpts)
 Function itemIsIncludedByFilter() More...
 
static double calcArea (const BOARD_ITEM *aItem)
 
static double calcMaxArea (GENERAL_COLLECTOR &aCollector, KICAD_T aType)
 
static double calcCommonArea (const BOARD_ITEM *aItem, const BOARD_ITEM *aOther)
 
double calcRatio (double a, double b)
 

Function Documentation

◆ calcArea()

static double calcArea ( const BOARD_ITEM aItem)
static

Definition at line 1921 of file pcbnew/tools/selection_tool.cpp.

1922 {
1923  if( aItem->Type() == PCB_TRACE_T )
1924  {
1925  const TRACK* t = static_cast<const TRACK*>( aItem );
1926  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1927  }
1928 
1929  return getRect( aItem ).GetArea();
1930 }
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:186
double GetArea() const
Function GetArea returns the area of the rectangle.
int GetWidth() const
Definition: class_track.h:127
static EDA_RECT getRect(const BOARD_ITEM *aItem)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References EDA_RECT::GetArea(), TRACK::GetLength(), getRect(), TRACK::GetWidth(), PCB_TRACE_T, and EDA_ITEM::Type().

Referenced by calcMaxArea(), and SELECTION_TOOL::guessSelectionCandidates().

◆ calcCommonArea()

static double calcCommonArea ( const BOARD_ITEM aItem,
const BOARD_ITEM aOther 
)
inlinestatic

Definition at line 1966 of file pcbnew/tools/selection_tool.cpp.

1967 {
1968  if( !aItem || !aOther )
1969  return 0;
1970 
1971  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1972 }
EDA_RECT Common(const EDA_RECT &aRect) const
Function Common returns the area that is common with another rectangle.
double GetArea() const
Function GetArea returns the area of the rectangle.
static EDA_RECT getRect(const BOARD_ITEM *aItem)

References EDA_RECT::Common(), EDA_RECT::GetArea(), and getRect().

Referenced by SELECTION_TOOL::guessSelectionCandidates().

◆ calcMaxArea()

static double calcMaxArea ( GENERAL_COLLECTOR aCollector,
KICAD_T  aType 
)
static

Definition at line 1951 of file pcbnew/tools/selection_tool.cpp.

1952 {
1953  double best = 0.0;
1954 
1955  for( int i = 0; i < aCollector.GetCount(); i++ )
1956  {
1957  BOARD_ITEM* item = aCollector[i];
1958  if( item->Type() == aType )
1959  best = std::max( best, calcArea( item ) );
1960  }
1961 
1962  return best;
1963 }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
static double calcArea(const BOARD_ITEM *aItem)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References calcArea(), COLLECTOR::GetCount(), i, max, and EDA_ITEM::Type().

Referenced by SELECTION_TOOL::guessSelectionCandidates().

◆ calcRatio()

double calcRatio ( double  a,
double  b 
)

Definition at line 1975 of file pcbnew/tools/selection_tool.cpp.

1976 {
1977  if( a == 0.0 && b == 0.0 )
1978  return 1.0;
1979 
1980  if( b == 0.0 )
1982 
1983  return a / b;
1984 }
#define max(a, b)
Definition: auxiliary.h:86

References max.

Referenced by SELECTION_TOOL::guessSelectionCandidates().

◆ connectedItemFilter()

void connectedItemFilter ( const VECTOR2I ,
GENERAL_COLLECTOR aCollector 
)

Definition at line 928 of file pcbnew/tools/selection_tool.cpp.

929 {
930  /* Narrow the collection down to a single BOARD_CONNECTED_ITEM for each
931  * represented net. All other items types are removed.
932  */
933  std::set<int> representedNets;
934 
935  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
936  {
937  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( aCollector[i] );
938  if( !item )
939  aCollector.Remove( i );
940  else if ( representedNets.count( item->GetNetCode() ) )
941  aCollector.Remove( i );
942  else
943  representedNets.insert( item->GetNetCode() );
944  }
945 }
int GetNetCode() const
Function GetNetCode.
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:143
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
size_t i
Definition: json11.cpp:597

References COLLECTOR::GetCount(), BOARD_CONNECTED_ITEM::GetNetCode(), i, and COLLECTOR::Remove().

Referenced by SELECTION_TOOL::selectCopper().

◆ connectedTrackFilter()

void connectedTrackFilter ( const VECTOR2I aPt,
GENERAL_COLLECTOR aCollector 
)

Definition at line 874 of file pcbnew/tools/selection_tool.cpp.

875 {
876  /* Narrow the collection down to a single TRACK item for a trivial
877  * connection, or multiple TRACK items for non-trivial connections.
878  */
879  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
880  {
881  if( !dynamic_cast<TRACK*>( aCollector[i] ) )
882  aCollector.Remove( i );
883  }
884 
885  ROUTER_TOOL::NeighboringSegmentFilter( aPt, aCollector );
886 }
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:143
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
size_t i
Definition: json11.cpp:597
static void NeighboringSegmentFilter(const VECTOR2I &aPt, GENERAL_COLLECTOR &aCollector)

References COLLECTOR::GetCount(), i, ROUTER_TOOL::NeighboringSegmentFilter(), and COLLECTOR::Remove().

Referenced by SELECTION_TOOL::selectConnection().

◆ getRect()

static EDA_RECT getRect ( const BOARD_ITEM aItem)
static

Definition at line 392 of file pcbnew/tools/selection_tool.cpp.

393 {
394  if( aItem->Type() == PCB_MODULE_T )
395  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
396 
397  return aItem->GetBoundingBox();
398 }
class MODULE, a footprint
Definition: typeinfo.h:89
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References EDA_ITEM::GetBoundingBox(), PCB_MODULE_T, and EDA_ITEM::Type().

Referenced by calcArea(), calcCommonArea(), and SELECTION_TOOL::selectMultiple().

◆ itemIsIncludedByFilter()

static bool itemIsIncludedByFilter ( const BOARD_ITEM aItem,
const BOARD aBoard,
const DIALOG_BLOCK_OPTIONS::OPTIONS aBlockOpts 
)
static

Function itemIsIncludedByFilter()

Determine if an item is included by the filter specified

Returns
true if the parameter indicate the items should be selected by this filter (i..e not filtered out)

Definition at line 1294 of file pcbnew/tools/selection_tool.cpp.

1297 {
1298  bool include = true;
1299  const PCB_LAYER_ID layer = aItem.GetLayer();
1300 
1301  // can skip without even checking item type
1302  // fixme: selecting items on invisible layers does not work in GAL
1303  if( !aBlockOpts.includeItemsOnInvisibleLayers
1304  && !aBoard.IsLayerVisible( layer ) )
1305  {
1306  include = false;
1307  }
1308 
1309  // if the item needs to be checked against the options
1310  if( include )
1311  {
1312  switch( aItem.Type() )
1313  {
1314  case PCB_MODULE_T:
1315  {
1316  const auto& module = static_cast<const MODULE&>( aItem );
1317 
1318  include = aBlockOpts.includeModules;
1319 
1320  if( include && !aBlockOpts.includeLockedModules )
1321  {
1322  include = !module.IsLocked();
1323  }
1324 
1325  break;
1326  }
1327  case PCB_TRACE_T:
1328  {
1329  include = aBlockOpts.includeTracks;
1330  break;
1331  }
1332  case PCB_VIA_T:
1333  {
1334  include = aBlockOpts.includeVias;
1335  break;
1336  }
1337  case PCB_ZONE_AREA_T:
1338  {
1339  include = aBlockOpts.includeZones;
1340  break;
1341  }
1342  case PCB_LINE_T:
1343  case PCB_TARGET_T:
1344  case PCB_DIMENSION_T:
1345  {
1346  if( layer == Edge_Cuts )
1347  include = aBlockOpts.includeBoardOutlineLayer;
1348  else
1349  include = aBlockOpts.includeItemsOnTechLayers;
1350  break;
1351  }
1352  case PCB_TEXT_T:
1353  {
1354  include = aBlockOpts.includePcbTexts;
1355  break;
1356  }
1357  default:
1358  {
1359  // no filtering, just select it
1360  break;
1361  }
1362  }
1363  }
1364 
1365  return include;
1366 }
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
class MODULE, a footprint
Definition: typeinfo.h:89
PCB_LAYER_ID
A quick note on layer IDs:
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:98
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:99
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:454
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

References Edge_Cuts, BOARD_ITEM::GetLayer(), DIALOG_BLOCK_OPTIONS::OPTIONS::includeBoardOutlineLayer, DIALOG_BLOCK_OPTIONS::OPTIONS::includeItemsOnInvisibleLayers, DIALOG_BLOCK_OPTIONS::OPTIONS::includeItemsOnTechLayers, DIALOG_BLOCK_OPTIONS::OPTIONS::includeLockedModules, DIALOG_BLOCK_OPTIONS::OPTIONS::includeModules, DIALOG_BLOCK_OPTIONS::OPTIONS::includePcbTexts, DIALOG_BLOCK_OPTIONS::OPTIONS::includeTracks, DIALOG_BLOCK_OPTIONS::OPTIONS::includeVias, DIALOG_BLOCK_OPTIONS::OPTIONS::includeZones, BOARD::IsLayerVisible(), PCB_DIMENSION_T, PCB_LINE_T, PCB_MODULE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, and EDA_ITEM::Type().

Referenced by SELECTION_TOOL::filterSelection().