KiCad PCB EDA Suite
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_drawsegment.h>
#include <class_zone.h>
#include <collectors.h>
#include <confirm.h>
#include <dialog_find.h>
#include <dialog_filter_selection.h>
#include <class_draw_panel_gal.h>
#include <view/view_controls.h>
#include <preview_items/selection_area.h>
#include <painter.h>
#include <bitmaps.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 <id.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

void connectedItemFilter (const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
 
static bool itemIsIncludedByFilter (const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
 Function itemIsIncludedByFilter() More...
 
static EDA_RECT getRect (const BOARD_ITEM *aItem)
 
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 1843 of file selection_tool.cpp.

1844 {
1845  if( aItem->Type() == PCB_TRACE_T )
1846  {
1847  const TRACK* t = static_cast<const TRACK*>( aItem );
1848  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1849  }
1850 
1851  return getRect( aItem ).GetArea();
1852 }
static EDA_RECT getRect(const BOARD_ITEM *aItem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:139
double GetArea() const
Function GetArea returns the area of the rectangle.
int GetWidth() const
Definition: class_track.h:103
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

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 1888 of file selection_tool.cpp.

1889 {
1890  if( !aItem || !aOther )
1891  return 0;
1892 
1893  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1894 }
static EDA_RECT getRect(const BOARD_ITEM *aItem)
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.

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 1873 of file selection_tool.cpp.

1874 {
1875  double best = 0.0;
1876 
1877  for( int i = 0; i < aCollector.GetCount(); i++ )
1878  {
1879  BOARD_ITEM* item = aCollector[i];
1880  if( item->Type() == aType )
1881  best = std::max( best, calcArea( item ) );
1882  }
1883 
1884  return best;
1885 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
static double calcArea(const BOARD_ITEM *aItem)
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:116
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

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

Referenced by SELECTION_TOOL::GuessSelectionCandidates().

◆ calcRatio()

double calcRatio ( double  a,
double  b 
)

Definition at line 1897 of file selection_tool.cpp.

1898 {
1899  if( a == 0.0 && b == 0.0 )
1900  return 1.0;
1901 
1902  if( b == 0.0 )
1903  return std::numeric_limits<double>::max();
1904 
1905  return a / b;
1906 }

Referenced by SELECTION_TOOL::GuessSelectionCandidates().

◆ connectedItemFilter()

void connectedItemFilter ( const VECTOR2I ,
GENERAL_COLLECTOR aCollector 
)

Definition at line 762 of file selection_tool.cpp.

763 {
764  // Narrow the collection down to a single BOARD_CONNECTED_ITEM for each represented net.
765  // All other items types are removed.
766  std::set<int> representedNets;
767 
768  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
769  {
770  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( aCollector[i] );
771  if( !item )
772  aCollector.Remove( i );
773  else if ( representedNets.count( item->GetNetCode() ) )
774  aCollector.Remove( i );
775  else
776  representedNets.insert( item->GetNetCode() );
777  }
778 }
int GetNetCode() const
Function GetNetCode.
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:145
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:116

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

Referenced by SELECTION_TOOL::expandConnection().

◆ getRect()

static EDA_RECT getRect ( const BOARD_ITEM aItem)
static

Definition at line 1834 of file selection_tool.cpp.

1835 {
1836  if( aItem->Type() == PCB_MODULE_T )
1837  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
1838 
1839  return aItem->GetBoundingBox();
1840 }
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:207

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

Referenced by calcArea(), and calcCommonArea().

◆ itemIsIncludedByFilter()

static bool itemIsIncludedByFilter ( const BOARD_ITEM aItem,
const BOARD aBoard,
const DIALOG_FILTER_SELECTION::OPTIONS aFilterOptions 
)
static

Function itemIsIncludedByFilter()

Determine if an item is included by the filter specified

Returns
true if aItem should be selected by this filter (i..e not filtered out)

Definition at line 1179 of file selection_tool.cpp.

1181 {
1182  bool include = true;
1183  const PCB_LAYER_ID layer = aItem.GetLayer();
1184 
1185  // if the item needs to be checked against the options
1186  if( include )
1187  {
1188  switch( aItem.Type() )
1189  {
1190  case PCB_MODULE_T:
1191  {
1192  const auto& module = static_cast<const MODULE&>( aItem );
1193 
1194  include = aFilterOptions.includeModules;
1195 
1196  if( include && !aFilterOptions.includeLockedModules )
1197  {
1198  include = !module.IsLocked();
1199  }
1200 
1201  break;
1202  }
1203  case PCB_TRACE_T:
1204  {
1205  include = aFilterOptions.includeTracks;
1206  break;
1207  }
1208  case PCB_VIA_T:
1209  {
1210  include = aFilterOptions.includeVias;
1211  break;
1212  }
1213  case PCB_ZONE_AREA_T:
1214  {
1215  include = aFilterOptions.includeZones;
1216  break;
1217  }
1218  case PCB_LINE_T:
1219  case PCB_TARGET_T:
1220  case PCB_DIMENSION_T:
1221  {
1222  if( layer == Edge_Cuts )
1223  include = aFilterOptions.includeBoardOutlineLayer;
1224  else
1225  include = aFilterOptions.includeItemsOnTechLayers;
1226  break;
1227  }
1228  case PCB_TEXT_T:
1229  {
1230  include = aFilterOptions.includePcbTexts;
1231  break;
1232  }
1233  default:
1234  {
1235  // no filtering, just select it
1236  break;
1237  }
1238  }
1239  }
1240 
1241  return include;
1242 }
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:101
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
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:99
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:100
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
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:207

References Edge_Cuts, BOARD_ITEM::GetLayer(), DIALOG_FILTER_SELECTION::OPTIONS::includeBoardOutlineLayer, DIALOG_FILTER_SELECTION::OPTIONS::includeItemsOnTechLayers, DIALOG_FILTER_SELECTION::OPTIONS::includeLockedModules, DIALOG_FILTER_SELECTION::OPTIONS::includeModules, DIALOG_FILTER_SELECTION::OPTIONS::includePcbTexts, DIALOG_FILTER_SELECTION::OPTIONS::includeTracks, DIALOG_FILTER_SELECTION::OPTIONS::includeVias, DIALOG_FILTER_SELECTION::OPTIONS::includeZones, 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().