KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <gal/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 [&]( EDA_ITEM* item )
91 {
92 items.push_back( item );
93
94 if( item->IsBOARD_ITEM() )
95 {
96 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
97
98 boardItem->RunOnChildren( [&]( BOARD_ITEM* childItem )
99 {
100 addItem( childItem );
101 } );
102 }
103 };
104
105 for( EDA_ITEM* item : m_items )
106 addItem( item );
107
108 return items;
109}
110
111
113{
114 BOX2I bbox;
115
116 for( EDA_ITEM* item : m_items )
117 {
118 if( item->Type() == PCB_FOOTPRINT_T )
119 {
120 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
121
122 bbox.Merge( footprint->GetBoundingBox( true ) );
123 }
124 else
125 {
126 bbox.Merge( item->GetBoundingBox() );
127 }
128 }
129
130 return bbox;
131}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all children.
Definition: board_item.h:206
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:1252
EDA_ITEM * GetTopLeftItem(bool aFootprintsOnly=false) const override
BOX2I GetBoundingBox() const override
const std::vector< KIGFX::VIEW_ITEM * > updateDrawList() const override
std::deque< EDA_ITEM * > m_items
Definition: selection.h:235
Class to handle a set of BOARD_ITEMs.
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86