KiCad PCB EDA Suite
shape_compound.h
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) 2016-2020 CERN
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef __SHAPE_COMPOUND_H
25 #define __SHAPE_COMPOUND_H
26 
27 #include <geometry/shape.h>
28 #include <math/vector2d.h>
29 #include <math/box2.h>
30 #include <list>
31 #include <vector>
32 
33 class SHAPE_COMPOUND : public SHAPE
34 {
35  public:
37  SHAPE( SH_COMPOUND ),
38  m_dirty( true )
39  {}
40 
41 
42  SHAPE_COMPOUND( const std::vector<SHAPE*>& aShapes );
43 
44  SHAPE_COMPOUND( const SHAPE_COMPOUND& aOther );
46 
47  SHAPE_COMPOUND* Clone() const override;
48  const std::string Format() const override;
49 
50  bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr ) const override;
51 
52  bool Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const override
53  {
54  return SHAPE::Collide( aShape, aClearance, aMTV );
55  }
56 
57  bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr ) const override
58  {
59  return SHAPE::Collide( aShape, aClearance, aActual );
60  }
61 
62 
63  const std::vector<SHAPE*>& Shapes() const
64  {
65  return m_shapes;
66  }
67 
68  const BOX2I BBox( int aClearance = 0 ) const override;
69 
70  int Distance( const SEG& aSeg ) const;
71 
72  void Move ( const VECTOR2I& aVector ) override;
73 
74  void AddShape( SHAPE* aShape )
75  {
76  m_shapes.push_back( aShape );
77  m_dirty = true;
78  }
79 
80  bool Empty() const
81  {
82  return m_shapes.empty();
83  }
84 
85  int Size() const
86  {
87  return m_shapes.size();
88  }
89 
90  void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override;
91 
92  bool IsSolid() const override;
93 
95  {
96  return m_shapes.size() != 1 ? nullptr : m_shapes[0];
97  }
98 
99  private:
100 
102  bool m_dirty;
103  std::vector<SHAPE*> m_shapes;
104 };
105 
106 #endif // __SHAPE_COMPOUND_H
set of polygons (with holes, etc.)
Definition: shape.h:48
void Move(const VECTOR2I &aVector) override
int Size() const
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Function Collide()
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr) const override
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const override
Function Collide()
bool Empty() const
bool IsSolid() const override
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Function Rotate.
int Distance(const SEG &aSeg) const
SHAPE_COMPOUND * Clone() const override
Function Clone()
SHAPE.
Definition: shape.h:120
Definition: seg.h:39
const std::vector< SHAPE * > & Shapes() const
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const
Function Collide()
Definition: shape.h:172
std::vector< SHAPE * > m_shapes
SHAPE * UniqueSubshape() const
const BOX2I BBox(int aClearance=0) const override
Function BBox()
const std::string Format() const override
void AddShape(SHAPE *aShape)