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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <functional>
24using namespace std::placeholders;
25
26#include <board.h>
27#include <board_item.h>
28#include <footprint.h>
29#include <pcb_edit_frame.h>
30#include <pcb_group.h>
32#include <view/view_controls.h>
33#include <view/view_group.h>
34#include <gal/painter.h>
35#include <bitmaps.h>
36#include <tool/tool_event.h>
37#include <tool/tool_manager.h>
38#include <tools/pcb_selection.h>
40#include "pcb_selection_tool.h"
41#include "pcb_actions.h"
42
44
45
46
47EDA_ITEM* PCB_SELECTION::GetTopLeftItem( bool aFootprintsOnly ) const
48{
49 EDA_ITEM* topLeftItem = nullptr;
50
51 VECTOR2I pnt;
52
53 // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
54 for( EDA_ITEM* item : m_items )
55 {
56 pnt = item->GetPosition();
57
58 if( ( item->Type() != PCB_FOOTPRINT_T ) && aFootprintsOnly )
59 {
60 continue;
61 }
62 else
63 {
64 if( topLeftItem == nullptr )
65 {
66 topLeftItem = item;
67 }
68 else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
69 ( ( topLeftItem->GetPosition().x == pnt.x ) &&
70 ( pnt.y < topLeftItem->GetPosition().y ) ) )
71 {
72 topLeftItem = item;
73 }
74 }
75 }
76
77 return topLeftItem;
78}
79
80
81const std::vector<KIGFX::VIEW_ITEM*> PCB_SELECTION::updateDrawList() const
82{
83 std::vector<VIEW_ITEM*> items;
84
85 std::function<void ( EDA_ITEM* )> addItem =
86 [&]( EDA_ITEM* item )
87 {
88 items.push_back( item );
89
90 if( item->IsBOARD_ITEM() )
91 {
92 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
93
94 boardItem->RunOnChildren( [&]( BOARD_ITEM* childItem )
95 {
96 addItem( childItem );
97 },
99 }
100 };
101
102 for( EDA_ITEM* item : m_items )
103 addItem( item );
104
105 return items;
106}
107
108
110{
111 BOX2I bbox;
112
113 for( EDA_ITEM* item : m_items )
114 {
115 if( item->Type() == PCB_FOOTPRINT_T )
116 {
117 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
118
119 bbox.Merge( footprint->GetBoundingBox( true ) );
120 }
121 else
122 {
123 bbox.Merge( item->GetBoundingBox() );
124 }
125 }
126
127 return bbox;
128}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition board_item.h:229
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:654
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
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:236
@ NO_RECURSE
Definition eda_item.h:50
Class to handle a set of BOARD_ITEMs.
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683