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 <eda_item.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 = 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:522
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:431
VECTOR2I GetCenter() const override
Returns the center point of the selection area bounding box.
virtual wxPoint GetPosition() const
Definition: eda_item.h:302
const BOX2I ViewBBox() const override
Return the bounding box for all stored items covering all its layers.
std::deque< EDA_ITEM * > m_items
Definition: selection.h:290
const wxPoint GetOrigin() const
Definition: eda_rect.h:106
Handle the component boundary box.
Definition: eda_rect.h:42
int Size() const
Returns the number of selected parts.
Definition: selection.h:128
wxPoint Centre() const
Definition: eda_rect.h:60
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:73
EDA_ITEM * Front() const
Definition: selection.h:203
const wxSize GetSize() const
Definition: eda_rect.h:96