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

1809 {
1810  if( aItem->Type() == PCB_TRACE_T )
1811  {
1812  const TRACK* t = static_cast<const TRACK*>( aItem );
1813  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1814  }
1815 
1816  return getRect( aItem ).GetArea();
1817 }
static EDA_RECT getRect(const BOARD_ITEM *aItem)
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:149
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:197

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

1854 {
1855  if( !aItem || !aOther )
1856  return 0;
1857 
1858  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1859 }
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 1838 of file selection_tool.cpp.

1839 {
1840  double best = 0.0;
1841 
1842  for( int i = 0; i < aCollector.GetCount(); i++ )
1843  {
1844  BOARD_ITEM* item = aCollector[i];
1845  if( item->Type() == aType )
1846  best = std::max( best, calcArea( item ) );
1847  }
1848 
1849  return best;
1850 }
Class 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:113
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

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

1863 {
1864  if( a == 0.0 && b == 0.0 )
1865  return 1.0;
1866 
1867  if( b == 0.0 )
1869 
1870  return a / b;
1871 }
#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 793 of file selection_tool.cpp.

794 {
795  /* Narrow the collection down to a single BOARD_CONNECTED_ITEM for each
796  * represented net. All other items types are removed.
797  */
798  std::set<int> representedNets;
799 
800  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
801  {
802  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( aCollector[i] );
803  if( !item )
804  aCollector.Remove( i );
805  else if ( representedNets.count( item->GetNetCode() ) )
806  aCollector.Remove( i );
807  else
808  representedNets.insert( item->GetNetCode() );
809  }
810 }
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:142
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
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 733 of file selection_tool.cpp.

734 {
735  /* Narrow the collection down to a single TRACK item for a trivial
736  * connection, or multiple TRACK items for non-trivial connections.
737  */
738  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
739  {
740  if( !dynamic_cast<TRACK*>( aCollector[i] ) )
741  aCollector.Remove( i );
742  }
743 
744  ROUTER_TOOL::NeighboringSegmentFilter( aPt, aCollector );
745 }
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:142
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
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 1799 of file selection_tool.cpp.

1800 {
1801  if( aItem->Type() == PCB_MODULE_T )
1802  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
1803 
1804  return aItem->GetBoundingBox();
1805 }
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:197

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

1153 {
1154  bool include = true;
1155  const PCB_LAYER_ID layer = aItem.GetLayer();
1156 
1157  // can skip without even checking item type
1158  // fixme: selecting items on invisible layers does not work in GAL
1159  if( !aBlockOpts.includeItemsOnInvisibleLayers
1160  && !aBoard.IsLayerVisible( layer ) )
1161  {
1162  include = false;
1163  }
1164 
1165  // if the item needs to be checked against the options
1166  if( include )
1167  {
1168  switch( aItem.Type() )
1169  {
1170  case PCB_MODULE_T:
1171  {
1172  const auto& module = static_cast<const MODULE&>( aItem );
1173 
1174  include = aBlockOpts.includeModules;
1175 
1176  if( include && !aBlockOpts.includeLockedModules )
1177  {
1178  include = !module.IsLocked();
1179  }
1180 
1181  break;
1182  }
1183  case PCB_TRACE_T:
1184  {
1185  include = aBlockOpts.includeTracks;
1186  break;
1187  }
1188  case PCB_VIA_T:
1189  {
1190  include = aBlockOpts.includeVias;
1191  break;
1192  }
1193  case PCB_ZONE_AREA_T:
1194  {
1195  include = aBlockOpts.includeZones;
1196  break;
1197  }
1198  case PCB_LINE_T:
1199  case PCB_TARGET_T:
1200  case PCB_DIMENSION_T:
1201  {
1202  if( layer == Edge_Cuts )
1203  include = aBlockOpts.includeBoardOutlineLayer;
1204  else
1205  include = aBlockOpts.includeItemsOnTechLayers;
1206  break;
1207  }
1208  case PCB_TEXT_T:
1209  {
1210  include = aBlockOpts.includePcbTexts;
1211  break;
1212  }
1213  default:
1214  {
1215  // no filtering, just select it
1216  break;
1217  }
1218  }
1219  }
1220 
1221  return include;
1222 }
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:459
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:197

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