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

1471 {
1472  if( aItem->Type() == PCB_TRACE_T )
1473  {
1474  const TRACK* t = static_cast<const TRACK*>( aItem );
1475  return ( t->GetWidth() + t->GetLength() ) * t->GetWidth();
1476  }
1477 
1478  return getRect( aItem ).GetArea();
1479 }
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:114
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:170
static double calcCommonArea ( const BOARD_ITEM aItem,
const BOARD_ITEM aOther 
)
inlinestatic

Definition at line 1515 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1516 {
1517  if( !aItem || !aOther )
1518  return 0;
1519 
1520  return getRect( aItem ).Common( getRect( aOther ) ).GetArea();
1521 }
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 1500 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1501 {
1502  double best = 0.0;
1503 
1504  for( int i = 0; i < aCollector.GetCount(); i++ )
1505  {
1506  BOARD_ITEM* item = aCollector[i];
1507  if( item->Type() == aType )
1508  best = std::max( best, calcArea( item ) );
1509  }
1510 
1511  return best;
1512 }
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 1482 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1483 {
1484  double best = std::numeric_limits<double>::max();
1485 
1486  if( !aCollector.GetCount() )
1487  return 0.0;
1488 
1489  for( int i = 0; i < aCollector.GetCount(); i++ )
1490  {
1491  BOARD_ITEM* item = aCollector[i];
1492  if( item->Type() == aType )
1493  best = std::min( best, calcArea( item ) );
1494  }
1495 
1496  return best;
1497 }
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 1524 of file selection_tool.cpp.

References max.

Referenced by SELECTION_TOOL::guessSelectionCandidates().

1525 {
1526  if( a == 0.0 && b == 0.0 )
1527  return 1.0;
1528 
1529  if( b == 0.0 )
1531 
1532  return a / b;
1533 }
#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 1073 of file selection_tool.cpp.

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

Referenced by SELECTION_TOOL::filterSelection().

1075 {
1076  LSET layerMask( Edge_Cuts );
1077 
1078  if( blockOpts.includeItemsOnTechLayers )
1079  layerMask.set();
1080 
1081  if( !blockOpts.includeBoardOutlineLayer )
1082  layerMask.set( Edge_Cuts, false );
1083 
1084  return layerMask;
1085 }
Class LSET is a set of LAYER_IDs.
static EDA_RECT getRect ( const BOARD_ITEM aItem)
static

Definition at line 1461 of file selection_tool.cpp.

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

Referenced by calcArea(), and calcCommonArea().

1462 {
1463  if( aItem->Type() == PCB_MODULE_T )
1464  return static_cast<const MODULE*>( aItem )->GetFootprintRect();
1465 
1466  return aItem->GetBoundingBox();
1467 }
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 1002 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().

1006 {
1007  bool include = true;
1008  const LAYER_ID layer = aItem.GetLayer();
1009 
1010  // can skip without even checking item type
1011  if( !aBlockOpts.includeItemsOnInvisibleLayers
1012  && !aBoard.IsLayerVisible( layer ) )
1013  {
1014  include = false;
1015  }
1016 
1017  // if the item needsto be checked agains the options
1018  if( include )
1019  {
1020  switch( aItem.Type() )
1021  {
1022  case PCB_MODULE_T:
1023  {
1024  const auto& module = static_cast<const MODULE&>( aItem );
1025 
1026  include = aBlockOpts.includeModules;
1027 
1028  if( include && !aBlockOpts.includeLockedModules )
1029  {
1030  include = !module.IsLocked();
1031  }
1032 
1033  break;
1034  }
1035  case PCB_TRACE_T:
1036  {
1037  include = aBlockOpts.includeTracks;
1038  break;
1039  }
1040  case PCB_ZONE_AREA_T:
1041  {
1042  include = aBlockOpts.includeZones;
1043  break;
1044  }
1045  case PCB_LINE_T:
1046  case PCB_TARGET_T:
1047  case PCB_DIMENSION_T:
1048  {
1049  include = aTechnlLayerMask[layer];
1050  break;
1051  }
1052  case PCB_TEXT_T:
1053  {
1054  include = aBlockOpts.includePcbTexts
1055  && aTechnlLayerMask[layer];
1056  break;
1057  }
1058  default:
1059  {
1060  // no filterering, just select it
1061  break;
1062  }
1063  }
1064  }
1065 
1066  return include;
1067 }
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
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
class MODULE, a footprint
Definition: typeinfo.h:101
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
bool IsLayerVisible(LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:440
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103