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

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

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

1589 {
1590  if( aItem->Type() == PCB_TRACE_T )
1591  {
1592  const TRACK* t = static_cast<const TRACK*>( aItem );
1593  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1594  }
1595 
1596  return getRect( aItem ).GetArea();
1597 }
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 1633 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1634 {
1635  if( !aItem || !aOther )
1636  return 0;
1637 
1638  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1639 }
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 1618 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1619 {
1620  double best = 0.0;
1621 
1622  for( int i = 0; i < aCollector.GetCount(); i++ )
1623  {
1624  BOARD_ITEM* item = aCollector[i];
1625  if( item->Type() == aType )
1626  best = std::max( best, calcArea( item ) );
1627  }
1628 
1629  return best;
1630 }
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
double calcRatio ( double  a,
double  b 
)

Definition at line 1642 of file selection_tool.cpp.

References max.

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1643 {
1644  if( a == 0.0 && b == 0.0 )
1645  return 1.0;
1646 
1647  if( b == 0.0 )
1649 
1650  return a / b;
1651 }
#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 1181 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::filterSelection().

1183 {
1184  LSET layerMask( Edge_Cuts );
1185 
1186  if( blockOpts.includeItemsOnTechLayers )
1187  layerMask.set();
1188 
1189  if( !blockOpts.includeBoardOutlineLayer )
1190  layerMask.set( Edge_Cuts, false );
1191 
1192  return layerMask;
1193 }
Class LSET is a set of PCB_LAYER_IDs.
static EDA_RECT getRect ( const BOARD_ITEM aItem)
static

Definition at line 1579 of file selection_tool.cpp.

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

Referenced by calcArea(), and calcCommonArea().

1580 {
1581  if( aItem->Type() == PCB_MODULE_T )
1582  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
1583 
1584  return aItem->GetBoundingBox();
1585 }
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 1110 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().

1114 {
1115  bool include = true;
1116  const PCB_LAYER_ID layer = aItem.GetLayer();
1117 
1118  // can skip without even checking item type
1119  if( !aBlockOpts.includeItemsOnInvisibleLayers
1120  && !aBoard.IsLayerVisible( layer ) )
1121  {
1122  include = false;
1123  }
1124 
1125  // if the item needsto be checked agains the options
1126  if( include )
1127  {
1128  switch( aItem.Type() )
1129  {
1130  case PCB_MODULE_T:
1131  {
1132  const auto& module = static_cast<const MODULE&>( aItem );
1133 
1134  include = aBlockOpts.includeModules;
1135 
1136  if( include && !aBlockOpts.includeLockedModules )
1137  {
1138  include = !module.IsLocked();
1139  }
1140 
1141  break;
1142  }
1143  case PCB_TRACE_T:
1144  {
1145  include = aBlockOpts.includeTracks;
1146  break;
1147  }
1148  case PCB_ZONE_AREA_T:
1149  {
1150  include = aBlockOpts.includeZones;
1151  break;
1152  }
1153  case PCB_LINE_T:
1154  case PCB_TARGET_T:
1155  case PCB_DIMENSION_T:
1156  {
1157  include = aTechnlLayerMask[layer];
1158  break;
1159  }
1160  case PCB_TEXT_T:
1161  {
1162  include = aBlockOpts.includePcbTexts
1163  && aTechnlLayerMask[layer];
1164  break;
1165  }
1166  default:
1167  {
1168  // no filterering, just select it
1169  break;
1170  }
1171  }
1172  }
1173 
1174  return include;
1175 }
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