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( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
95 {
96 boardItem->RunOnChildren( [&]( BOARD_ITEM* bitem )
97 {
98 addItem( bitem );
99 } );
100 }
101 };
102
103 for( EDA_ITEM* item : m_items )
104 addItem( item );
105
106 return items;
107}
108
109
110BOX2I PCB_SELECTION::GetBoundingBox( bool aOnlyVisible ) const
111{
112 BOX2I bbox;
113
114 for( EDA_ITEM* item : m_items )
115 {
116 if( item->Type() == PCB_FOOTPRINT_T )
117 {
118 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
119
120 bbox.Merge( footprint->GetBoundingBox( true, !aOnlyVisible ) );
121 }
122 else
123 {
124 bbox.Merge( item->GetBoundingBox() );
125 }
126 }
127
128 return bbox;
129}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:623
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:242
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:1238
EDA_ITEM * GetTopLeftItem(bool aFootprintsOnly=false) const override
BOX2I GetBoundingBox(bool aOnlyVisible=false) 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