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 <pcbnew_settings.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"

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, SELECTION_TOOL *sTool)
 
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 2156 of file selection_tool.cpp.

2157 {
2158  if( aItem->Type() == PCB_TRACE_T )
2159  {
2160  const TRACK* t = static_cast<const TRACK*>( aItem );
2161  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
2162  }
2163 
2164  return getRect( aItem ).GetArea();
2165 }
static EDA_RECT getRect(const BOARD_ITEM *aItem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
double GetArea() const
Function GetArea returns the area of the rectangle.
int GetWidth() const
Definition: class_track.h:110
virtual double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:151
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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

2202 {
2203  if( !aItem || !aOther )
2204  return 0;
2205 
2206  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
2207 }
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 2186 of file selection_tool.cpp.

2187 {
2188  double best = 0.0;
2189 
2190  for( int i = 0; i < aCollector.GetCount(); i++ )
2191  {
2192  BOARD_ITEM* item = aCollector[i];
2193  if( item->Type() == aType )
2194  best = std::max( best, calcArea( item ) );
2195  }
2196 
2197  return best;
2198 }
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:101
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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

Referenced by SELECTION_TOOL::GuessSelectionCandidates().

◆ calcRatio()

double calcRatio ( double  a,
double  b 
)

Definition at line 2210 of file selection_tool.cpp.

2211 {
2212  if( a == 0.0 && b == 0.0 )
2213  return 1.0;
2214 
2215  if( b == 0.0 )
2216  return std::numeric_limits<double>::max();
2217 
2218  return a / b;
2219 }

Referenced by SELECTION_TOOL::GuessSelectionCandidates().

◆ connectedItemFilter()

void connectedItemFilter ( const VECTOR2I ,
GENERAL_COLLECTOR aCollector,
SELECTION_TOOL sTool 
)

Definition at line 910 of file selection_tool.cpp.

911 {
912  // Narrow the collection down to a single BOARD_CONNECTED_ITEM for each represented net.
913  // All other items types are removed.
914  std::set<int> representedNets;
915 
916  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
917  {
918  BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( aCollector[i] );
919  if( !item )
920  aCollector.Remove( i );
921  else if ( representedNets.count( item->GetNetCode() ) )
922  aCollector.Remove( i );
923  else
924  representedNets.insert( item->GetNetCode() );
925  }
926 }
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:130
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101

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

2148 {
2149  if( aItem->Type() == PCB_MODULE_T )
2150  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
2151 
2152  return aItem->GetBoundingBox();
2153 }
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.
Definition: base_struct.cpp:97
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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

1360 {
1361  bool include = true;
1362  const PCB_LAYER_ID layer = aItem.GetLayer();
1363 
1364  // if the item needs to be checked against the options
1365  if( include )
1366  {
1367  switch( aItem.Type() )
1368  {
1369  case PCB_MODULE_T:
1370  {
1371  const auto& module = static_cast<const MODULE&>( aItem );
1372 
1373  include = aFilterOptions.includeModules;
1374 
1375  if( include && !aFilterOptions.includeLockedModules )
1376  {
1377  include = !module.IsLocked();
1378  }
1379 
1380  break;
1381  }
1382  case PCB_TRACE_T:
1383  case PCB_ARC_T:
1384  {
1385  include = aFilterOptions.includeTracks;
1386  break;
1387  }
1388  case PCB_VIA_T:
1389  {
1390  include = aFilterOptions.includeVias;
1391  break;
1392  }
1393  case PCB_ZONE_AREA_T:
1394  {
1395  include = aFilterOptions.includeZones;
1396  break;
1397  }
1398  case PCB_LINE_T:
1399  case PCB_TARGET_T:
1400  case PCB_DIM_ALIGNED_T:
1401  case PCB_DIM_CENTER_T:
1402  case PCB_DIM_ORTHOGONAL_T:
1403  case PCB_DIM_LEADER_T:
1404  {
1405  if( layer == Edge_Cuts )
1406  include = aFilterOptions.includeBoardOutlineLayer;
1407  else
1408  include = aFilterOptions.includeItemsOnTechLayers;
1409  break;
1410  }
1411  case PCB_TEXT_T:
1412  {
1413  include = aFilterOptions.includePcbTexts;
1414  break;
1415  }
1416  default:
1417  {
1418  // no filtering, just select it
1419  break;
1420  }
1421  }
1422  }
1423 
1424  return include;
1425 }
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
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 PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
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:193

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_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_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().