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  BOARD_ITEM* topLeftItem = nullptr;
61  BOARD_ITEM* currentItem;
62 
63  wxPoint pnt;
64 
65  // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
66  for( auto item : m_items )
67  {
68  currentItem = static_cast<BOARD_ITEM*>( item );
69  pnt = currentItem->GetPosition();
70 
71  if( ( currentItem->Type() != PCB_MODULE_T ) && onlyModules )
72  {
73  continue;
74  }
75  else
76  {
77  if( topLeftItem == nullptr )
78  {
79  topLeftItem = currentItem;
80  }
81  else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
82  ( ( topLeftItem->GetPosition().x == pnt.x ) &&
83  ( pnt.y < topLeftItem->GetPosition().y ) ) )
84  {
85  topLeftItem = currentItem;
86  }
87  }
88  }
89 
90  return static_cast<EDA_ITEM*>( topLeftItem );
91 }
92 
93 
95 {
96  std::vector<VIEW_ITEM*> items;
97 
98  for( auto item : m_items )
99  {
100  items.push_back( item );
101 
102  if( item->Type() == PCB_MODULE_T )
103  {
104  MODULE* module = static_cast<MODULE*>( item );
105  module->RunOnChildren( [&] ( BOARD_ITEM* bitem ) { items.push_back( bitem ); } );
106  }
107  }
108 
109  return items;
110 }
111 
112 
114 {
115  LSET retval;
116 
117  for( auto item : m_items )
118  {
119  auto board_item = dynamic_cast<BOARD_ITEM*>( item );
120 
121  if( board_item )
122  retval |= board_item->GetLayerSet();
123  }
124 
125  return retval;
126 }
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
TEXTE_PCB class definition.
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
Class 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.
Definitions for tracks, vias and zones.
const KIGFX::VIEW_GROUP::ITEMS updateDrawList() const override
const LSET GetSelectionLayers()
class MODULE, a footprint
Definition: typeinfo.h:89
Class LSET is a set of PCB_LAYER_IDs.
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
virtual const wxPoint GetPosition() const =0
std::vector< VIEW_ITEM * > ITEMS
Definition: view_group.h:45
Class to handle a graphic segment.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
Module description (excepted pads)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210