KiCad PCB EDA Suite
pcb_selection.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013-2017 CERN
5 * @author Tomasz Wlostowski <[email protected]>
6 * @author Maciej Suminski <[email protected]>
7 * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.TXT for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <functional>
28using namespace std::placeholders;
29
30#include <board.h>
31#include <board_item.h>
32#include <footprint.h>
33#include <pcb_edit_frame.h>
34#include <pcb_group.h>
36#include <view/view_controls.h>
37#include <view/view_group.h>
38#include <painter.h>
39#include <bitmaps.h>
40#include <tool/tool_event.h>
41#include <tool/tool_manager.h>
42#include <tools/pcb_selection.h>
44#include "pcb_selection_tool.h"
45#include "pcb_actions.h"
46
48
49
50
51EDA_ITEM* PCB_SELECTION::GetTopLeftItem( bool aFootprintsOnly ) const
52{
53 EDA_ITEM* topLeftItem = nullptr;
54
55 VECTOR2I pnt;
56
57 // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
58 for( EDA_ITEM* item : m_items )
59 {
60 pnt = item->GetPosition();
61
62 if( ( item->Type() != PCB_FOOTPRINT_T ) && aFootprintsOnly )
63 {
64 continue;
65 }
66 else
67 {
68 if( topLeftItem == nullptr )
69 {
70 topLeftItem = item;
71 }
72 else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
73 ( ( topLeftItem->GetPosition().x == pnt.x ) &&
74 ( pnt.y < topLeftItem->GetPosition().y ) ) )
75 {
76 topLeftItem = item;
77 }
78 }
79 }
80
81 return topLeftItem;
82}
83
84
85const std::vector<KIGFX::VIEW_ITEM*> PCB_SELECTION::updateDrawList() const
86{
87 std::vector<VIEW_ITEM*> items;
88
89 std::function<void ( EDA_ITEM* )> addItem;
90 addItem = [&]( EDA_ITEM* item )
91 {
92 items.push_back( item );
93
94 if( item->Type() == PCB_FOOTPRINT_T )
95 {
96 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
97 footprint->RunOnChildren( [&]( BOARD_ITEM* bitem )
98 {
99 addItem( bitem );
100 } );
101 }
102 else if( item->Type() == PCB_GROUP_T )
103 {
104 PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
105 group->RunOnChildren( [&]( BOARD_ITEM* bitem )
106 {
107 addItem( bitem );
108 } );
109 }
110 };
111
112 for( EDA_ITEM* item : m_items )
113 addItem( item );
114
115 return items;
116}
117
118
120{
121 LSET retval;
122
123 for( EDA_ITEM* item : m_items )
124 {
125 if( BOARD_ITEM* board_item = dynamic_cast<BOARD_ITEM*>( item ) )
126 retval |= board_item->GetLayerSet();
127 }
128
129 return retval;
130}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:251
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all BOARD_ITEMs that belong to the footprint (pads, drawings,...
Definition: footprint.cpp:1367
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
const LSET GetSelectionLayers()
EDA_ITEM * GetTopLeftItem(bool aFootprintsOnly=false) const override
const std::vector< KIGFX::VIEW_ITEM * > updateDrawList() const override
std::deque< EDA_ITEM * > m_items
Definition: selection.h:283
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:115
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86