Horizon
Loading...
Searching...
No Matches
shape_compound.h
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016-2020 CERN
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef __SHAPE_COMPOUND_H
26#define __SHAPE_COMPOUND_H
27
28#include <geometry/shape.h>
29#include <math/vector2d.h>
30#include <math/box2.h>
31#include <list>
32#include <vector>
33
34class SHAPE_SIMPLE;
35
36class SHAPE_COMPOUND : public SHAPE
37{
38public:
40 SHAPE( SH_COMPOUND ),
41 m_dirty( true )
42 {
43 }
44
45
46 SHAPE_COMPOUND( const std::vector<SHAPE*>& aShapes );
47
48 SHAPE_COMPOUND( const SHAPE_COMPOUND& aOther );
50
51 SHAPE_COMPOUND* Clone() const override;
52 const std::string Format() const override;
53
54 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
55 VECTOR2I* aLocation = nullptr ) const override;
56
57 bool Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const override
58 {
59 return SHAPE::Collide( aShape, aClearance, aMTV );
60 }
61
62 bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
63 VECTOR2I* aLocation = nullptr ) const override
64 {
65 return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
66 }
67
68 const std::vector<SHAPE*>& Shapes() const
69 {
70 return m_shapes;
71 }
72
73 const BOX2I BBox( int aClearance = 0 ) const override;
74
75 int Distance( const SEG& aSeg ) const;
76
77 void Move( const VECTOR2I& aVector ) override;
78
79 void AddShape( SHAPE* aShape )
80 {
81 // Don't make clients deal with nested SHAPE_COMPOUNDs
82 if( aShape->HasIndexableSubshapes() )
83 {
84 std::vector<SHAPE*> subshapes;
85 aShape->GetIndexableSubshapes( subshapes );
86
87 for( SHAPE* subshape : subshapes )
88 m_shapes.push_back( subshape->Clone() );
89
90 delete aShape;
91 }
92 else
93 {
94 m_shapes.push_back( aShape );
95 }
96
97 m_dirty = true;
98 }
99
100 bool Empty() const
101 {
102 return m_shapes.empty();
103 }
104
105 int Size() const
106 {
107 return m_shapes.size();
108 }
109
110 void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override;
111
112 bool IsSolid() const override;
113
114 SHAPE* UniqueSubshape() const
115 {
116 return m_shapes.size() != 1 ? nullptr : m_shapes[0];
117 }
118
119 virtual bool HasIndexableSubshapes() const override
120 {
121 return true;
122 }
123
124 virtual size_t GetIndexableSubshapeCount() const override
125 {
126 return m_shapes.size();
127 }
128
129 virtual void GetIndexableSubshapes( std::vector<SHAPE*>& aSubshapes ) override
130 {
131 aSubshapes = m_shapes;
132 }
133
134 bool ConvertToSimplePolygon( SHAPE_SIMPLE* aOut ) const;
135
136private:
137 BOX2I m_cachedBBox;
138 bool m_dirty;
139 std::vector<SHAPE*> m_shapes;
140};
141
142#endif // __SHAPE_COMPOUND_H
Definition seg.h:41
Definition shape_compound.h:37
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition shape_compound.cpp:76
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Definition shape_compound.cpp:105
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition shape_compound.h:57
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Definition shape_compound.cpp:117
SHAPE_COMPOUND * Clone() const override
Return a dynamically allocated copy of the shape.
Definition shape_compound.cpp:70
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition shape_simple.h:42
An abstract shape on 2D plane.
Definition shape.h:117
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition shape.h:165
apply< bind_back< quote< list >, Ts... >, L > push_back
Return a new meta::list by adding the element T to the back of L.
Definition meta.hpp:2173