KiCad PCB EDA Suite
SELECTION Class Reference

#include <selection.h>

Inheritance diagram for SELECTION:
KIGFX::VIEW_GROUP KIGFX::VIEW_ITEM

Public Types

using ITER = std::set< EDA_ITEM * >::iterator
 
using CITER = std::set< EDA_ITEM * >::const_iterator
 

Public Member Functions

 SELECTION ()
 
 SELECTION (const SELECTION &aOther)
 
const SELECTIONoperator= (const SELECTION &aOther)
 
ITER begin ()
 
ITER end ()
 
CITER begin () const
 
CITER end () const
 
void SetIsHover (bool aIsHover)
 
bool IsHover () const
 
virtual void Add (EDA_ITEM *aItem)
 
virtual void Remove (EDA_ITEM *aItem)
 
virtual void Clear () override
 Function Clear() Removes all the stored items from the group. More...
 
virtual unsigned int GetSize () const override
 Function GetSize() Returns the number of stored items. More...
 
virtual KIGFX::VIEW_ITEMGetItem (unsigned int idx) const override
 
bool Contains (EDA_ITEM *aItem) const
 
bool Empty () const
 Checks if there is anything selected. More...
 
int Size () const
 Returns the number of selected parts. More...
 
const std::set< EDA_ITEM * > GetItems () const
 
VECTOR2I GetCenter () const
 Returns the center point of the selection area bounding box. More...
 
const BOX2I ViewBBox () const override
 Function ViewBBox() Returns the bounding box for all stored items covering all its layers. More...
 
EDA_ITEMoperator[] (const int index) const
 
EDA_ITEMFront () const
 
std::set< EDA_ITEM * > & Items ()
 
template<class T >
T * FirstOfKind () const
 
virtual const VIEW_GROUP::ITEMS updateDrawList () const override
 
virtual void Add (VIEW_ITEM *aItem)
 Function Add() Adds an item to the group. More...
 
virtual void Remove (VIEW_ITEM *aItem)
 Function Remove() Removes an item from the group. More...
 
virtual void ViewDraw (int aLayer, VIEW *aView) const override
 Function ViewDraw() Draws all the stored items in the group on the given layer. More...
 
virtual void ViewGetLayers (int aLayers[], int &aCount) const override
 Function ViewGetLayers() Returns all the layers used by the stored items. More...
 
virtual void SetLayer (int aLayer)
 Function SetLayer() Sets layer used to draw the group. More...
 
void FreeItems ()
 Function FreeItems() Frees all the items that were added to the group. More...
 
virtual unsigned int ViewGetLOD (int aLayer, VIEW *aView) const
 Function ViewGetLOD() Returns the level of detail of the item. More...
 
VIEW_ITEM_DATA * viewPrivData () const
 

Protected Types

typedef std::vector< VIEW_ITEM * > ITEMS
 

Protected Attributes

int m_layer
 Layer on which the group is drawn. More...
 
ITEMS m_groupItems
 Container for storing VIEW_ITEMs. More...
 

Private Attributes

std::set< EDA_ITEM * > m_items
 Set of selected items. More...
 
bool m_isHover
 

Detailed Description

Definition at line 35 of file selection.h.

Member Typedef Documentation

using SELECTION::CITER = std::set<EDA_ITEM*>::const_iterator

Definition at line 54 of file selection.h.

typedef std::vector<VIEW_ITEM*> KIGFX::VIEW_GROUP::ITEMS
protectedinherited

Definition at line 45 of file view_group.h.

using SELECTION::ITER = std::set<EDA_ITEM*>::iterator

Definition at line 53 of file selection.h.

Constructor & Destructor Documentation

SELECTION::SELECTION ( )
inline

Definition at line 38 of file selection.h.

38 {};
SELECTION::SELECTION ( const SELECTION aOther)
inline

Definition at line 40 of file selection.h.

References m_isHover, and m_items.

41  {
42  m_items = aOther.m_items;
43  m_isHover = aOther.m_isHover;
44  }
bool m_isHover
Definition: selection.h:170
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168

Member Function Documentation

void VIEW_GROUP::Add ( VIEW_ITEM aItem)
virtualinherited

Function Add() Adds an item to the group.

Parameters
aItemis the item to be added.

Definition at line 55 of file view_group.cpp.

References KIGFX::VIEW_GROUP::m_groupItems.

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::AddLine(), PNS_KICAD_IFACE::DisplayItem(), PCB_TOOL::doInteractiveItemPlacement(), MODULE_EDITOR_TOOLS::PasteItems(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), and PCB_EDITOR_CONTROL::PlaceTarget().

56 {
57  m_groupItems.push_back( aItem );
58 }
ITEMS m_groupItems
Container for storing VIEW_ITEMs.
Definition: view_group.h:135
virtual void SELECTION::Add ( EDA_ITEM aItem)
inlinevirtual

Definition at line 71 of file selection.h.

References m_items.

Referenced by PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::PlaceDXF(), DRAWING_TOOL::PlaceText(), and SELECTION_TOOL::select().

72  {
73  m_items.insert( aItem );
74  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
ITER SELECTION::begin ( )
inline

Definition at line 56 of file selection.h.

References m_items.

56 { return m_items.begin(); }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
CITER SELECTION::begin ( ) const
inline

Definition at line 58 of file selection.h.

References m_items.

58 { return m_items.cbegin(); }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
virtual void SELECTION::Clear ( )
inlineoverridevirtual

Function Clear() Removes all the stored items from the group.

Reimplemented from KIGFX::VIEW_GROUP.

Definition at line 81 of file selection.h.

References m_items.

Referenced by PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::PlaceDXF(), DRAWING_TOOL::PlaceText(), and SELECTION_TOOL::Reset().

82  {
83  m_items.clear();
84  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
bool SELECTION::Contains ( EDA_ITEM aItem) const
inline

Definition at line 100 of file selection.h.

References m_items.

Referenced by SELECTION_TOOL::select().

101  {
102  return m_items.find( aItem ) != m_items.end();
103  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
ITER SELECTION::end ( )
inline

Definition at line 57 of file selection.h.

References m_items.

57 { return m_items.end(); }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
CITER SELECTION::end ( ) const
inline

Definition at line 59 of file selection.h.

References m_items.

59 { return m_items.cend(); }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
template<class T >
T* SELECTION::FirstOfKind ( ) const
inline

Definition at line 151 of file selection.h.

References m_items.

152  {
153  auto refType = T( nullptr ).Type();
154 
155  for( auto item : m_items )
156  {
157  if( item->Type() == refType )
158  return static_cast<T*> ( item );
159  }
160 
161  return nullptr;
162  }
T
enum T contains all this lexer's tokens.
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
void VIEW_GROUP::FreeItems ( )
inherited

Function FreeItems() Frees all the items that were added to the group.

Definition at line 139 of file view_group.cpp.

References KIGFX::VIEW_GROUP::Clear(), KIGFX::VIEW_GROUP::GetItem(), and KIGFX::VIEW_GROUP::GetSize().

Referenced by PNS_PCBNEW_DEBUG_DECORATOR::Clear(), PNS_KICAD_IFACE::EraseView(), DRAWING_TOOL::PlaceDXF(), PNS_KICAD_IFACE::SetView(), and PNS_KICAD_IFACE::~PNS_KICAD_IFACE().

140 {
141  for( unsigned int i = 0 ; i < GetSize(); i++ )
142  delete GetItem( i );
143 
144  Clear();
145 }
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
Definition: view_group.cpp:85
virtual void Clear()
Function Clear() Removes all the stored items from the group.
Definition: view_group.cpp:74
virtual unsigned int GetSize() const
Function GetSize() Returns the number of stored items.
Definition: view_group.cpp:80
EDA_ITEM* SELECTION::Front ( ) const
inline
VECTOR2I SELECTION::GetCenter ( ) const

Returns the center point of the selection area bounding box.

Definition at line 1814 of file selection_tool.cpp.

References EDA_RECT::Centre(), Front(), EDA_ITEM::GetBoundingBox(), m_items, EDA_RECT::Merge(), and Size().

Referenced by GAL_ARRAY_CREATOR::getRotationCentre().

1815 {
1816  VECTOR2I centre;
1817 
1818  if( Size() == 1 )
1819  {
1820  centre = static_cast<BOARD_ITEM*>( Front() )->GetCenter();
1821  }
1822  else
1823  {
1824  EDA_RECT bbox = Front()->GetBoundingBox();
1825  auto i = m_items.begin();
1826  ++i;
1827 
1828  for( ; i != m_items.end(); ++i )
1829  {
1830  bbox.Merge( (*i)->GetBoundingBox() );
1831  }
1832 
1833  centre = bbox.Centre();
1834  }
1835 
1836  return centre;
1837 }
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
EDA_ITEM * Front() const
Definition: selection.h:137
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:65
wxPoint Centre() const
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
Class EDA_RECT handles the component boundary box.
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
virtual KIGFX::VIEW_ITEM* SELECTION::GetItem ( unsigned int  idx) const
inlineoverridevirtual

Reimplemented from KIGFX::VIEW_GROUP.

Definition at line 91 of file selection.h.

References m_items.

92  {
93  auto iter = m_items.begin();
94 
95  std::advance( iter, idx );
96 
97  return *iter;
98  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
const std::set<EDA_ITEM*> SELECTION::GetItems ( ) const
inline

Definition at line 117 of file selection.h.

References m_items.

Referenced by SELECTION_TOOL::filterSelection(), SELECTION_TOOL::selectConnection(), SELECTION_TOOL::selectCopper(), and SELECTION_TOOL::selectNet().

118  {
119  return m_items;
120  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
virtual unsigned int SELECTION::GetSize ( ) const
inlineoverridevirtual

Function GetSize() Returns the number of stored items.

Returns
Number of stored items.

Reimplemented from KIGFX::VIEW_GROUP.

Definition at line 86 of file selection.h.

References m_items.

Referenced by SELECTION_TOOL::RequestSelection().

87  {
88  return m_items.size();
89  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
bool SELECTION::IsHover ( ) const
inline

Definition at line 66 of file selection.h.

References m_isHover.

Referenced by EDIT_TOOL::Main().

67  {
68  return m_isHover;
69  }
bool m_isHover
Definition: selection.h:170
std::set<EDA_ITEM*>& SELECTION::Items ( )
inline

Definition at line 145 of file selection.h.

References m_items.

146  {
147  return m_items;
148  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
const SELECTION& SELECTION::operator= ( const SELECTION aOther)
inline

Definition at line 46 of file selection.h.

References m_isHover, and m_items.

47  {
48  m_items = aOther.m_items;
49  m_isHover = aOther.m_isHover;
50  return *this;
51  }
bool m_isHover
Definition: selection.h:170
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
EDA_ITEM* SELECTION::operator[] ( const int  index) const
inline

Definition at line 127 of file selection.h.

References m_items.

128  {
129  if( index < 0 || (unsigned int) index >= m_items.size() )
130  return nullptr;
131 
132  auto iter = m_items.begin();
133  std::advance( iter, index );
134  return *iter;
135  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
void VIEW_GROUP::Remove ( VIEW_ITEM aItem)
virtualinherited

Function Remove() Removes an item from the group.

Parameters
aItemis the item to be removed.

Definition at line 61 of file view_group.cpp.

References KIGFX::VIEW_GROUP::m_groupItems.

Referenced by PCB_TOOL::doInteractiveItemPlacement(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), and PCB_EDITOR_CONTROL::PlaceTarget().

62 {
63  for( auto iter = m_groupItems.begin(); iter != m_groupItems.end(); ++iter)
64  {
65  if( aItem == *iter )
66  {
67  m_groupItems.erase( iter);
68  break;
69  }
70  }
71 }
ITEMS m_groupItems
Container for storing VIEW_ITEMs.
Definition: view_group.h:135
virtual void SELECTION::Remove ( EDA_ITEM aItem)
inlinevirtual

Definition at line 76 of file selection.h.

References m_items.

Referenced by PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::PlaceText(), and SELECTION_TOOL::unselect().

77  {
78  m_items.erase( aItem );
79  }
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
void SELECTION::SetIsHover ( bool  aIsHover)
inline

Definition at line 61 of file selection.h.

References m_isHover.

Referenced by SELECTION_TOOL::RequestSelection().

62  {
63  m_isHover = aIsHover;
64  }
bool m_isHover
Definition: selection.h:170
virtual void KIGFX::VIEW_GROUP::SetLayer ( int  aLayer)
inlinevirtualinherited

Function SetLayer() Sets layer used to draw the group.

Parameters
aLayeris the layer used for drawing.

Definition at line 115 of file view_group.h.

References KIGFX::VIEW_GROUP::m_layer.

Referenced by PNS_KICAD_IFACE::SetView(), and PNS_PCBNEW_DEBUG_DECORATOR::SetView().

116  {
117  m_layer = aLayer;
118  }
int m_layer
Layer on which the group is drawn.
Definition: view_group.h:131
const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList ( ) const
overridevirtual

Reimplemented from KIGFX::VIEW_GROUP.

Definition at line 1862 of file selection_tool.cpp.

References m_items, PCB_MODULE_T, and MODULE::RunOnChildren().

1863 {
1864  std::vector<VIEW_ITEM*> items;
1865 
1866  for( auto item : m_items )
1867  {
1868  items.push_back( item );
1869 
1870  if( item->Type() == PCB_MODULE_T )
1871  {
1872  MODULE* module = static_cast<MODULE*>( item );
1873  module->RunOnChildren( [&] ( BOARD_ITEM* bitem ) { items.push_back( bitem ); } );
1874  }
1875  }
1876 
1877  return items;
1878 }
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
class MODULE, a footprint
Definition: typeinfo.h:101
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
const BOX2I SELECTION::ViewBBox ( ) const
overridevirtual

Function ViewBBox() Returns the bounding box for all stored items covering all its layers.

Returns
The current bounding box

Reimplemented from KIGFX::VIEW_GROUP.

Definition at line 1839 of file selection_tool.cpp.

References Front(), EDA_ITEM::GetBoundingBox(), EDA_RECT::GetOrigin(), EDA_RECT::GetSize(), m_items, EDA_RECT::Merge(), and Size().

Referenced by SELECTION_TOOL::zoomFitSelection().

1840 {
1841  EDA_RECT eda_bbox;
1842 
1843  if( Size() == 1 )
1844  {
1845  eda_bbox = Front()->GetBoundingBox();
1846  }
1847  else if( Size() > 1 )
1848  {
1849  eda_bbox = Front()->GetBoundingBox();
1850  auto i = m_items.begin();
1851  ++i;
1852 
1853  for( ; i != m_items.end(); ++i )
1854  {
1855  eda_bbox.Merge( (*i)->GetBoundingBox() );
1856  }
1857  }
1858 
1859  return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() );
1860 }
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
BOX2< VECTOR2I > BOX2I
Definition: box2.h:468
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
EDA_ITEM * Front() const
Definition: selection.h:137
const wxPoint & GetOrigin() const
std::set< EDA_ITEM * > m_items
Set of selected items.
Definition: selection.h:168
Class EDA_RECT handles the component boundary box.
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
const wxSize & GetSize() const
void VIEW_GROUP::ViewDraw ( int  aLayer,
VIEW aView 
) const
overridevirtualinherited

Function ViewDraw() Draws all the stored items in the group on the given layer.

Parameters
aLayeris the layer which should be drawn.
aGalis the GAL that should be used for drawing.

Reimplemented from KIGFX::VIEW_ITEM.

Definition at line 99 of file view_group.cpp.

References KIGFX::PAINTER::Draw(), KIGFX::VIEW::GetGAL(), KIGFX::VIEW::GetPainter(), KIGFX::VIEW::IsLayerVisible(), KIGFX::VIEW::SortLayers(), KIGFX::VIEW_GROUP::updateDrawList(), and KIGFX::VIEW::VIEW_MAX_LAYERS.

100 {
101  auto gal = aView->GetGAL();
102  PAINTER* painter = aView->GetPainter();
103 
104  const auto drawList = updateDrawList();
105 
106  // Draw all items immediately (without caching)
107  for( auto item : drawList )
108  {
109  gal->PushDepth();
110 
111  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
112  item->ViewGetLayers( layers, layers_count );
113  aView->SortLayers( layers, layers_count );
114 
115  for( int i = 0; i < layers_count; i++ )
116  {
117  if( aView->IsLayerVisible( layers[i] ) )
118  {
119  gal->AdvanceDepth();
120 
121  if( !painter->Draw( item, layers[i] ) )
122  item->ViewDraw( layers[i], aView ); // Alternative drawing method
123  }
124  }
125 
126  gal->PopDepth();
127  }
128 }
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:404
virtual const ITEMS updateDrawList() const
Definition: view_group.cpp:148
void SortLayers(int aLayers[], int &aCount) const
Function SortLayers() Changes the order of given layer ids, so after sorting the order corresponds to...
Definition: view.cpp:602
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:277
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
static const int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:640
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer)=0
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
void VIEW_GROUP::ViewGetLayers ( int  aLayers[],
int &  aCount 
) const
overridevirtualinherited

Function ViewGetLayers() Returns all the layers used by the stored items.

Parameters
aLayers[]is the output layer index array.
aCountis the number of layer indices in aLayers[].

Implements KIGFX::VIEW_ITEM.

Definition at line 131 of file view_group.cpp.

References KIGFX::VIEW_GROUP::m_layer.

132 {
133  // Everything is displayed on a single layer
134  aLayers[0] = m_layer;
135  aCount = 1;
136 }
int m_layer
Layer on which the group is drawn.
Definition: view_group.h:131
virtual unsigned int KIGFX::VIEW_ITEM::ViewGetLOD ( int  aLayer,
VIEW aView 
) const
inlinevirtualinherited

Function ViewGetLOD() Returns the level of detail of the item.

A level of detail is the minimal VIEW scale that is sufficient for an item to be shown on a given layer.

Reimplemented in MODULE, D_PAD, TRACK, and TEXTE_MODULE.

Definition at line 133 of file view_item.h.

Referenced by KIGFX::VIEW::drawItem::operator()().

134  {
135  // By default always show the item
136  return 0;
137  }

Member Data Documentation

ITEMS KIGFX::VIEW_GROUP::m_groupItems
protectedinherited
bool SELECTION::m_isHover
private

Definition at line 170 of file selection.h.

Referenced by IsHover(), operator=(), SELECTION(), and SetIsHover().

std::set<EDA_ITEM*> SELECTION::m_items
private
int KIGFX::VIEW_GROUP::m_layer
protectedinherited

Layer on which the group is drawn.

Definition at line 131 of file view_group.h.

Referenced by KIGFX::VIEW_GROUP::SetLayer(), and KIGFX::VIEW_GROUP::ViewGetLayers().


The documentation for this class was generated from the following files: