KiCad PCB EDA Suite
shape.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) 2013 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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_H
26 #define __SHAPE_H
27 
28 #include <sstream>
29 #include <geometry/seg.h>
30 #include <math/vector2d.h>
31 #include <math/box2.h>
32 
33 
40 {
41  SH_RECT = 0,
49 };
50 
51 static inline wxString SHAPE_TYPE_asString( SHAPE_TYPE a )
52 {
53  switch( a )
54  {
55  case SH_RECT: return "SH_RECT";
56  case SH_SEGMENT: return "SH_SEGMENT";
57  case SH_LINE_CHAIN: return "SH_LINE_CHAIN";
58  case SH_CIRCLE: return "SH_CIRCLE";
59  case SH_SIMPLE: return "SH_SIMPLE";
60  case SH_POLY_SET: return "SH_POLY_SET";
61  case SH_COMPOUND: return "SH_COMPOUND";
62  case SH_ARC: return "SH_ARC";
63  }
64 
65  return wxEmptyString; // Just to quiet GCC.
66 }
67 
68 
74 class SHAPE
75 {
76 protected:
78 
79 public:
86  SHAPE( SHAPE_TYPE aType ) : m_type( aType )
87  {}
88 
89  // Destructor
90  virtual ~SHAPE()
91  {}
92 
99  SHAPE_TYPE Type() const
100  {
101  return m_type;
102  }
103 
110  virtual SHAPE* Clone() const
111  {
112  assert( false );
113  return NULL;
114  };
115 
125  virtual bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr ) const
126  {
127  return Collide( SEG( aP, aP ), aClearance );
128  }
129 
142  virtual bool Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const;
143  virtual bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr ) const;
144 
154  virtual bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr ) const = 0;
155 
165  virtual const BOX2I BBox( int aClearance = 0 ) const = 0;
166 
173  virtual VECTOR2I Centre() const
174  {
175  return BBox( 0 ).Centre(); // if nothing better is available....
176  }
177 
183  virtual void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) = 0;
184 
185  virtual void Move( const VECTOR2I& aVector ) = 0;
186 
187  virtual bool IsSolid() const = 0;
188 
189  virtual bool Parse( std::stringstream& aStream );
190 
191  virtual const std::string Format( ) const;
192 
193 protected:
196 };
197 
198 
199 #endif // __SHAPE_H
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
set of polygons (with holes, etc.)
Definition: shape.h:47
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:86
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:99
virtual const std::string Format() const
Definition: shape.cpp:35
virtual VECTOR2I Centre() const
Function Centre()
Definition: shape.h:173
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
virtual ~SHAPE()
Definition: shape.h:90
#define NULL
virtual SHAPE * Clone() const
Function Clone()
Definition: shape.h:110
static wxString SHAPE_TYPE_asString(SHAPE_TYPE a)
Definition: shape.h:51
compound shape, consisting of multiple simple shapes
Definition: shape.h:48
SHAPE.
Definition: shape.h:74
virtual bool Parse(std::stringstream &aStream)
Definition: shape.cpp:28
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:195
line chain (polyline)
Definition: shape.h:44
Definition: seg.h:39
simple polygon
Definition: shape.h:46
virtual bool IsSolid() const =0
Vec Centre() const
Definition: box2.h:79
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const
Function Collide()
Definition: shape.h:125
VECTOR2I::extended_type ecoord
Definition: shape.h:77
line segment
Definition: shape.h:43
Definition: shape.h:41
virtual void Move(const VECTOR2I &aVector)=0
SHAPE_TYPE
Enum SHAPE_TYPE Lists all supported shapes.
Definition: shape.h:39
circle
Definition: shape.h:45
axis-aligned rectangle
Definition: shape.h:42
virtual void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 })=0
Function Rotate.