KiCad PCB EDA Suite
gerbview_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) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <base_struct.h>
22 #include <view/view_group.h>
23 #include <gerber_draw_item.h>
25 
27 {
28  VECTOR2I centre;
29 
30  if( Size() == 1 )
31  {
32  centre = static_cast<GERBER_DRAW_ITEM*>( Front() )->GetPosition();
33  }
34  else
35  {
36  EDA_RECT bbox = Front()->GetBoundingBox();
37  auto i = m_items.begin();
38  ++i;
39 
40  for( ; i != m_items.end(); ++i )
41  bbox.Merge( (*i)->GetBoundingBox() );
42 
43  centre = bbox.Centre();
44  }
45 
46  return centre;
47 }
48 
49 
51 {
52  EDA_RECT eda_bbox;
53 
54  if( Size() == 1 )
55  {
56  eda_bbox = Front()->GetBoundingBox();
57  }
58  else if( Size() > 1 )
59  {
60  eda_bbox = Front()->GetBoundingBox();
61  auto i = m_items.begin();
62  ++i;
63 
64  for( ; i != m_items.end(); ++i )
65  eda_bbox.Merge( (*i)->GetBoundingBox() );
66  }
67 
68  return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() );
69 }
70 
71 
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
VECTOR2I GetCenter() const override
Returns the center point of the selection area bounding box.
const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers.
std::deque< EDA_ITEM * > m_items
Definition: selection.h:255
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
size_t i
Definition: json11.cpp:649
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
wxPoint Centre() const
Definition: eda_rect.h:62
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
EDA_ITEM * Front() const
Definition: selection.h:182
const wxSize GetSize() const
Definition: eda_rect.h:103