KiCad PCB EDA Suite
pcbnew_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 <class_board.h>
33 #include <class_board_item.h>
34 #include <class_track.h>
35 #include <class_module.h>
36 #include <class_pcb_text.h>
37 #include <class_drawsegment.h>
38 #include <class_zone.h>
39 #include <pcb_edit_frame.h>
40 #include <class_draw_panel_gal.h>
41 #include <view/view_controls.h>
42 #include <view/view_group.h>
44 #include <painter.h>
45 #include <bitmaps.h>
46 #include <tool/tool_event.h>
47 #include <tool/tool_manager.h>
48 #include <tools/pcbnew_selection.h>
50 #include "selection_tool.h"
51 #include "pcb_bright_box.h"
52 #include "pcb_actions.h"
53 
54 #include "kicad_plugin.h"
55 
56 
57 
58 EDA_ITEM* PCBNEW_SELECTION::GetTopLeftItem( bool onlyModules ) const
59 {
60  EDA_ITEM* topLeftItem = nullptr;
61 
62  wxPoint pnt;
63 
64  // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
65  for( EDA_ITEM* item : m_items )
66  {
67  pnt = item->GetPosition();
68 
69  if( ( item->Type() != PCB_MODULE_T ) && onlyModules )
70  {
71  continue;
72  }
73  else
74  {
75  if( topLeftItem == nullptr )
76  {
77  topLeftItem = item;
78  }
79  else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
80  ( ( topLeftItem->GetPosition().x == pnt.x ) &&
81  ( pnt.y < topLeftItem->GetPosition().y ) ) )
82  {
83  topLeftItem = item;
84  }
85  }
86  }
87 
88  return topLeftItem;
89 }
90 
91 
93 {
94  std::vector<VIEW_ITEM*> items;
95 
96  for( auto item : m_items )
97  {
98  items.push_back( item );
99 
100  if( item->Type() == PCB_MODULE_T )
101  {
102  MODULE* module = static_cast<MODULE*>( item );
103  module->RunOnChildren( [&] ( BOARD_ITEM* bitem ) { items.push_back( bitem ); } );
104  }
105  }
106 
107  return items;
108 }
109 
110 
112 {
113  LSET retval;
114 
115  for( auto item : m_items )
116  {
117  if( auto board_item = dynamic_cast<BOARD_ITEM*>( item ) )
118  retval |= board_item->GetLayerSet();
119  }
120 
121  return retval;
122 }
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
TEXTE_PCB class definition.
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
VIEW_CONTROLS class definition.
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
virtual wxPoint GetPosition() const
Definition: base_struct.h:337
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
const KIGFX::VIEW_GROUP::ITEMS updateDrawList() const override
const LSET GetSelectionLayers()
class MODULE, a footprint
Definition: typeinfo.h:89
LSET is a set of PCB_LAYER_IDs.
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
std::vector< VIEW_ITEM * > ITEMS
Definition: view_group.h:45
Class to handle a graphic segment.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159