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_pcb_text.h>
#include <class_drawsegment.h>
#include <wxPcbStruct.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 <connectivity.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

static bool itemIsIncludedByFilter (const BOARD_ITEM &aItem, const BOARD &aBoard, const LSET &aTechnlLayerMask, const DIALOG_BLOCK_OPTIONS::OPTIONS &aBlockOpts)
 Function itemIsIncludedByFilter() More...
 
static LSET getFilteredLayerSet (const DIALOG_BLOCK_OPTIONS::OPTIONS &blockOpts)
 Gets the technical layers that are part of the given selection opts. More...
 
static EDA_RECT getRect (const BOARD_ITEM *aItem)
 
static double calcArea (const BOARD_ITEM *aItem)
 
static double calcMinArea (GENERAL_COLLECTOR &aCollector, KICAD_T aType)
 
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

static double calcArea ( const BOARD_ITEM aItem)
static

Definition at line 1585 of file selection_tool.cpp.

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

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

1586 {
1587  if( aItem->Type() == PCB_TRACE_T )
1588  {
1589  const TRACK* t = static_cast<const TRACK*>( aItem );
1590  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1591  }
1592 
1593  return getRect( aItem ).GetArea();
1594 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
static EDA_RECT getRect(const BOARD_ITEM *aItem)
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
double GetArea() const
Function GetArea returns the area of the rectangle.
int GetWidth() const
Definition: class_track.h:115
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:171
static double calcCommonArea ( const BOARD_ITEM aItem,
const BOARD_ITEM aOther 
)
inlinestatic

Definition at line 1630 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1631 {
1632  if( !aItem || !aOther )
1633  return 0;
1634 
1635  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1636 }
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.
static double calcMaxArea ( GENERAL_COLLECTOR aCollector,
KICAD_T  aType 
)
static

Definition at line 1615 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1616 {
1617  double best = 0.0;
1618 
1619  for( int i = 0; i < aCollector.GetCount(); i++ )
1620  {
1621  BOARD_ITEM* item = aCollector[i];
1622  if( item->Type() == aType )
1623  best = std::max( best, calcArea( item ) );
1624  }
1625 
1626  return best;
1627 }
int GetCount() const
Function GetCount returns the number of objects in the list.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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)
#define max(a, b)
Definition: auxiliary.h:86
static double calcMinArea ( GENERAL_COLLECTOR aCollector,
KICAD_T  aType 
)
static

Definition at line 1597 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1598 {
1599  double best = std::numeric_limits<double>::max();
1600 
1601  if( !aCollector.GetCount() )
1602  return 0.0;
1603 
1604  for( int i = 0; i < aCollector.GetCount(); i++ )
1605  {
1606  BOARD_ITEM* item = aCollector[i];
1607  if( item->Type() == aType )
1608  best = std::min( best, calcArea( item ) );
1609  }
1610 
1611  return best;
1612 }
int GetCount() const
Function GetCount returns the number of objects in the list.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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)
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85
double calcRatio ( double  a,
double  b 
)

Definition at line 1639 of file selection_tool.cpp.

References max.

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1640 {
1641  if( a == 0.0 && b == 0.0 )
1642  return 1.0;
1643 
1644  if( b == 0.0 )
1646 
1647  return a / b;
1648 }
#define max(a, b)
Definition: auxiliary.h:86
static LSET getFilteredLayerSet ( const DIALOG_BLOCK_OPTIONS::OPTIONS blockOpts)
static

Gets the technical layers that are part of the given selection opts.

Definition at line 1175 of file selection_tool.cpp.

References Edge_Cuts, DIALOG_BLOCK_OPTIONS::OPTIONS::includeBoardOutlineLayer, and DIALOG_BLOCK_OPTIONS::OPTIONS::includeItemsOnTechLayers.

Referenced by SELECTION_TOOL::filterSelection().

1177 {
1178  LSET layerMask( Edge_Cuts );
1179 
1180  if( blockOpts.includeItemsOnTechLayers )
1181  layerMask.set();
1182 
1183  if( !blockOpts.includeBoardOutlineLayer )
1184  layerMask.set( Edge_Cuts, false );
1185 
1186  return layerMask;
1187 }
Class LSET is a set of PCB_LAYER_IDs.
static EDA_RECT getRect ( const BOARD_ITEM aItem)
static

Definition at line 1576 of file selection_tool.cpp.

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

Referenced by calcArea(), and calcCommonArea().

1577 {
1578  if( aItem->Type() == PCB_MODULE_T )
1579  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
1580 
1581  return aItem->GetBoundingBox();
1582 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
class MODULE, a footprint
Definition: typeinfo.h:101
static bool itemIsIncludedByFilter ( const BOARD_ITEM aItem,
const BOARD aBoard,
const LSET aTechnlLayerMask,
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 1104 of file selection_tool.cpp.

References BOARD_ITEM::GetLayer(), DIALOG_BLOCK_OPTIONS::OPTIONS::includeItemsOnInvisibleLayers, DIALOG_BLOCK_OPTIONS::OPTIONS::includeLockedModules, DIALOG_BLOCK_OPTIONS::OPTIONS::includeModules, DIALOG_BLOCK_OPTIONS::OPTIONS::includePcbTexts, DIALOG_BLOCK_OPTIONS::OPTIONS::includeTracks, 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_ZONE_AREA_T, and EDA_ITEM::Type().

Referenced by SELECTION_TOOL::filterSelection().

1108 {
1109  bool include = true;
1110  const PCB_LAYER_ID layer = aItem.GetLayer();
1111 
1112  // can skip without even checking item type
1113  if( !aBlockOpts.includeItemsOnInvisibleLayers
1114  && !aBoard.IsLayerVisible( layer ) )
1115  {
1116  include = false;
1117  }
1118 
1119  // if the item needsto be checked agains the options
1120  if( include )
1121  {
1122  switch( aItem.Type() )
1123  {
1124  case PCB_MODULE_T:
1125  {
1126  const auto& module = static_cast<const MODULE&>( aItem );
1127 
1128  include = aBlockOpts.includeModules;
1129 
1130  if( include && !aBlockOpts.includeLockedModules )
1131  {
1132  include = !module.IsLocked();
1133  }
1134 
1135  break;
1136  }
1137  case PCB_TRACE_T:
1138  {
1139  include = aBlockOpts.includeTracks;
1140  break;
1141  }
1142  case PCB_ZONE_AREA_T:
1143  {
1144  include = aBlockOpts.includeZones;
1145  break;
1146  }
1147  case PCB_LINE_T:
1148  case PCB_TARGET_T:
1149  case PCB_DIMENSION_T:
1150  {
1151  include = aTechnlLayerMask[layer];
1152  break;
1153  }
1154  case PCB_TEXT_T:
1155  {
1156  include = aBlockOpts.includePcbTexts
1157  && aTechnlLayerMask[layer];
1158  break;
1159  }
1160  default:
1161  {
1162  // no filterering, just select it
1163  break;
1164  }
1165  }
1166  }
1167 
1168  return include;
1169 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
class MODULE, a footprint
Definition: typeinfo.h:101
PCB_LAYER_ID
A quick note on layer IDs:
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
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:443