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 <assert.h> // for assert
29 #include <sstream>
30 #include <stddef.h> // for NULL
31 
32 #include <geometry/seg.h>
33 
34 #include <math/vector2d.h>
35 #include <math/box2.h>
36 
37 
44 {
45  SH_RECT = 0,
53 };
54 
60 class SHAPE
61 {
62 protected:
64 
65 public:
72  SHAPE( SHAPE_TYPE aType ) : m_type( aType )
73  {}
74 
75  // Destructor
76  virtual ~SHAPE()
77  {}
78 
85  SHAPE_TYPE Type() const
86  {
87  return m_type;
88  }
89 
96  virtual SHAPE* Clone() const
97  {
98  assert( false );
99  return NULL;
100  };
101 
109  virtual bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const
110  {
111  return Collide( SEG( aP, aP ), aClearance );
112  }
113 
124  virtual bool Collide( const SHAPE* aShape, int aClearance, VECTOR2I& aMTV ) const;
125  virtual bool Collide( const SHAPE* aShape, int aClearance = 0 ) const;
126 
134  virtual bool Collide( const SEG& aSeg, int aClearance = 0 ) const = 0;
135 
145  virtual const BOX2I BBox( int aClearance = 0 ) const = 0;
146 
153  virtual VECTOR2I Centre() const
154  {
155  return BBox( 0 ).Centre(); // if nothing better is available....
156  }
157 
158  virtual void Move ( const VECTOR2I& aVector ) = 0;
159 
160  virtual bool IsSolid() const = 0;
161 
162  virtual bool Parse( std::stringstream& aStream );
163 
164  virtual const std::string Format( ) const;
165 
166 protected:
169 };
170 
171 bool CollideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance,
172  bool aNeedMTV, VECTOR2I& aMTV );
173 
174 #endif // __SHAPE_H
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
set of polygons (with holes, etc.)
Definition: shape.h:51
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:72
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:85
virtual const std::string Format() const
Definition: shape.cpp:35
virtual VECTOR2I Centre() const
Function Centre()
Definition: shape.h:153
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:109
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
virtual ~SHAPE()
Definition: shape.h:76
#define NULL
virtual SHAPE * Clone() const
Function Clone()
Definition: shape.h:96
compound shape, consisting of multiple simple shapes
Definition: shape.h:52
SHAPE.
Definition: shape.h:60
virtual bool Parse(std::stringstream &aStream)
Definition: shape.cpp:28
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:168
line chain (polyline)
Definition: shape.h:48
Definition: seg.h:39
simple polygon
Definition: shape.h:50
virtual bool IsSolid() const =0
Vec Centre() const
Definition: box2.h:78
VECTOR2I::extended_type ecoord
Definition: shape.h:63
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
line segment
Definition: shape.h:47
Definition: shape.h:45
virtual void Move(const VECTOR2I &aVector)=0
SHAPE_TYPE
Enum SHAPE_TYPE Lists all supported shapes.
Definition: shape.h:43
circle
Definition: shape.h:49
axis-aligned rectangle
Definition: shape.h:46