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 <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  * Copyright (C) 2017 KiCad Developers, see CHANGELOG.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 <limits>
28 
29 #include <functional>
30 using namespace std::placeholders;
31 
32 #include <board.h>
33 #include <board_item.h>
34 #include <track.h>
35 #include <footprint.h>
36 #include <pcb_edit_frame.h>
37 #include <class_draw_panel_gal.h>
38 #include <view/view_controls.h>
39 #include <view/view_group.h>
40 #include <painter.h>
41 #include <bitmaps.h>
42 #include <tool/tool_event.h>
43 #include <tool/tool_manager.h>
44 #include <tools/pcb_selection.h>
46 #include "pcb_selection_tool.h"
47 #include "pcb_actions.h"
48 
50 
51 
52 
53 EDA_ITEM* PCB_SELECTION::GetTopLeftItem( bool aFootprintsOnly ) const
54 {
55  EDA_ITEM* topLeftItem = nullptr;
56 
57  wxPoint pnt;
58 
59  // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
60  for( EDA_ITEM* item : m_items )
61  {
62  pnt = item->GetPosition();
63 
64  if( ( item->Type() != PCB_FOOTPRINT_T ) && aFootprintsOnly )
65  {
66  continue;
67  }
68  else
69  {
70  if( topLeftItem == nullptr )
71  {
72  topLeftItem = item;
73  }
74  else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
75  ( ( topLeftItem->GetPosition().x == pnt.x ) &&
76  ( pnt.y < topLeftItem->GetPosition().y ) ) )
77  {
78  topLeftItem = item;
79  }
80  }
81  }
82 
83  return topLeftItem;
84 }
85 
86 
88 {
89  std::vector<VIEW_ITEM*> items;
90 
91  std::function<void ( EDA_ITEM* )> addItem;
92  addItem = [&]( EDA_ITEM* item )
93  {
94  items.push_back( item );
95 
96  if( item->Type() == PCB_FOOTPRINT_T )
97  {
98  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
99  footprint->RunOnChildren( [&]( BOARD_ITEM* bitem )
100  {
101  addItem( bitem );
102  } );
103  }
104  else if( item->Type() == PCB_GROUP_T )
105  {
106  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
107  group->RunOnChildren( [&]( BOARD_ITEM* bitem )
108  {
109  addItem( bitem );
110  } );
111  }
112  };
113 
114  for( EDA_ITEM* item : m_items )
115  addItem( item );
116 
117  return items;
118 }
119 
120 
122 {
123  LSET retval;
124 
125  for( EDA_ITEM* item : m_items )
126  {
127  if( BOARD_ITEM* board_item = dynamic_cast<BOARD_ITEM*>( item ) )
128  retval |= board_item->GetLayerSet();
129  }
130 
131  return retval;
132 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
const KIGFX::VIEW_GROUP::ITEMS updateDrawList() const override
Layer on which the group is drawn.
virtual wxPoint GetPosition() const
Definition: eda_item.h:301
LSET is a set of PCB_LAYER_IDs.
EDA_ITEM * GetTopLeftItem(bool aFootprintsOnly=false) const override
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
std::vector< VIEW_ITEM * > ITEMS
Definition: view_group.h:119
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all members of the group.
Definition: pcb_group.cpp:310
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:1174
const LSET GetSelectionLayers()