KiCad PCB EDA Suite
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 
40 #include <pcb_edit_frame.h>
41 
42 #include <class_draw_panel_gal.h>
43 #include <view/view_controls.h>
44 #include <view/view_group.h>
46 #include <painter.h>
47 #include <bitmaps.h>
48 #include <hotkeys.h>
49 
50 #include <tool/tool_event.h>
51 #include <tool/tool_manager.h>
53 
54 #include "selection_tool.h"
55 #include "pcb_bright_box.h"
56 #include "pcb_actions.h"
57 
58 #include "kicad_plugin.h"
59 
60 // TODO(JE) Only works for BOARD_ITEM
62 {
63  return static_cast<VECTOR2I>( GetBoundingBox().GetPosition() );
64 }
65 
66 
68 {
69  return static_cast<VECTOR2I>( GetBoundingBox().Centre() );
70 }
71 
72 
74 {
75  EDA_RECT bbox;
76 
77  bbox = Front()->GetBoundingBox();
78  auto i = m_items.begin();
79  ++i;
80 
81  for( ; i != m_items.end(); ++i )
82  {
83  bbox.Merge( (*i)->GetBoundingBox() );
84  }
85 
86  return bbox;
87 }
88 
89 
90 EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const
91 {
92  BOARD_ITEM* topLeftItem = nullptr;
93  BOARD_ITEM* currentItem;
94 
95  wxPoint pnt;
96 
97  // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
98  for( auto item : m_items )
99  {
100  currentItem = static_cast<BOARD_ITEM*>( item );
101  pnt = currentItem->GetPosition();
102 
103  if( ( currentItem->Type() != PCB_MODULE_T ) && onlyModules )
104  {
105  continue;
106  }
107  else
108  {
109  if( topLeftItem == nullptr )
110  {
111  topLeftItem = currentItem;
112  }
113  else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
114  ( ( topLeftItem->GetPosition().x == pnt.x ) &&
115  ( pnt.y < topLeftItem->GetPosition().y ) ) )
116  {
117  topLeftItem = currentItem;
118  }
119  }
120  }
121 
122  return static_cast<EDA_ITEM*>( topLeftItem );
123 }
124 
125 
127 {
128  return GetTopLeftItem( true );
129 }
130 
131 
133 {
134  BOX2I r;
135  r.SetMaximum();
136  return r;
137 }
138 
139 
141 {
142  std::vector<VIEW_ITEM*> items;
143 
144  for( auto item : m_items )
145  {
146  items.push_back( item );
147 
148  if( item->Type() == PCB_MODULE_T )
149  {
150  MODULE* module = static_cast<MODULE*>( item );
151  module->RunOnChildren( [&] ( BOARD_ITEM* bitem ) { items.push_back( bitem ); } );
152  }
153  }
154 
155  return items;
156 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
TEXTE_PCB class definition.
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.
virtual const VIEW_GROUP::ITEMS updateDrawList() const override
Definition: selection.cpp:140
Class BOARD to handle a board.
VECTOR2I GetPosition() const
Returns the top left point of the selection area bounding box.
Definition: selection.cpp:61
Classes to handle copper zones.
Functions relatives to tracks, vias and segments used to fill zones.
Pcbnew hotkeys.
class MODULE, a footprint
Definition: typeinfo.h:89
const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers...
Definition: selection.cpp:132
void SetMaximum()
Definition: box2.h:71
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const
Definition: selection.cpp:90
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
EDA_RECT GetBoundingBox() const
Definition: selection.cpp:73
virtual const wxPoint GetPosition() const =0
std::vector< VIEW_ITEM * > ITEMS
Definition: view_group.h:45
Class to handle a graphic segment.
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
Module description (excepted pads)
VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:67
EDA_ITEM * GetTopLeftModule() const
Definition: selection.cpp:126