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

1521 {
1522  if( aItem->Type() == PCB_TRACE_T )
1523  {
1524  const TRACK* t = static_cast<const TRACK*>( aItem );
1525  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1526  }
1527 
1528  return getRect( aItem ).GetArea();
1529 }
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 1565 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1566 {
1567  if( !aItem || !aOther )
1568  return 0;
1569 
1570  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1571 }
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 1550 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1551 {
1552  double best = 0.0;
1553 
1554  for( int i = 0; i < aCollector.GetCount(); i++ )
1555  {
1556  BOARD_ITEM* item = aCollector[i];
1557  if( item->Type() == aType )
1558  best = std::max( best, calcArea( item ) );
1559  }
1560 
1561  return best;
1562 }
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 1532 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1533 {
1534  double best = std::numeric_limits<double>::max();
1535 
1536  if( !aCollector.GetCount() )
1537  return 0.0;
1538 
1539  for( int i = 0; i < aCollector.GetCount(); i++ )
1540  {
1541  BOARD_ITEM* item = aCollector[i];
1542  if( item->Type() == aType )
1543  best = std::min( best, calcArea( item ) );
1544  }
1545 
1546  return best;
1547 }
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 1574 of file selection_tool.cpp.

References max.

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1575 {
1576  if( a == 0.0 && b == 0.0 )
1577  return 1.0;
1578 
1579  if( b == 0.0 )
1581 
1582  return a / b;
1583 }
#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 1115 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::filterSelection().

1117 {
1118  LSET layerMask( Edge_Cuts );
1119 
1120  if( blockOpts.includeItemsOnTechLayers )
1121  layerMask.set();
1122 
1123  if( !blockOpts.includeBoardOutlineLayer )
1124  layerMask.set( Edge_Cuts, false );
1125 
1126  return layerMask;
1127 }
Class LSET is a set of PCB_LAYER_IDs.
static EDA_RECT getRect ( const BOARD_ITEM aItem)
static

Definition at line 1511 of file selection_tool.cpp.

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

Referenced by calcArea(), and calcCommonArea().

1512 {
1513  if( aItem->Type() == PCB_MODULE_T )
1514  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
1515 
1516  return aItem->GetBoundingBox();
1517 }
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 1044 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().

1048 {
1049  bool include = true;
1050  const PCB_LAYER_ID layer = aItem.GetLayer();
1051 
1052  // can skip without even checking item type
1053  if( !aBlockOpts.includeItemsOnInvisibleLayers
1054  && !aBoard.IsLayerVisible( layer ) )
1055  {
1056  include = false;
1057  }
1058 
1059  // if the item needsto be checked agains the options
1060  if( include )
1061  {
1062  switch( aItem.Type() )
1063  {
1064  case PCB_MODULE_T:
1065  {
1066  const auto& module = static_cast<const MODULE&>( aItem );
1067 
1068  include = aBlockOpts.includeModules;
1069 
1070  if( include && !aBlockOpts.includeLockedModules )
1071  {
1072  include = !module.IsLocked();
1073  }
1074 
1075  break;
1076  }
1077  case PCB_TRACE_T:
1078  {
1079  include = aBlockOpts.includeTracks;
1080  break;
1081  }
1082  case PCB_ZONE_AREA_T:
1083  {
1084  include = aBlockOpts.includeZones;
1085  break;
1086  }
1087  case PCB_LINE_T:
1088  case PCB_TARGET_T:
1089  case PCB_DIMENSION_T:
1090  {
1091  include = aTechnlLayerMask[layer];
1092  break;
1093  }
1094  case PCB_TEXT_T:
1095  {
1096  include = aBlockOpts.includePcbTexts
1097  && aTechnlLayerMask[layer];
1098  break;
1099  }
1100  default:
1101  {
1102  // no filterering, just select it
1103  break;
1104  }
1105  }
1106  }
1107 
1108  return include;
1109 }
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:440