KiCad PCB EDA Suite
cobject2d.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) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 
30 #ifndef _COBJECT2D_H_
31 #define _COBJECT2D_H_
32 
33 #include "cbbox2d.h"
34 #include <string.h>
35 
36 #include <class_board_item.h>
37 
39 {
43 };
44 
45 
47 {
59 };
60 
61 
62 class COBJECT2D
63 {
64 protected:
68 
70 public:
71 
72  COBJECT2D( OBJECT2D_TYPE aObjType, const BOARD_ITEM &aBoardItem );
73  virtual ~COBJECT2D() {}
74 
75  const BOARD_ITEM &GetBoardItem() const { return m_boardItem; }
76 
90  virtual bool Overlaps( const CBBOX2D &aBBox ) const = 0;
91 
98  virtual bool Intersects( const CBBOX2D &aBBox ) const = 0;
99 
108  virtual bool Intersect( const RAYSEG2D &aSegRay,
109  float *aOutT,
110  SFVEC2F *aNormalOut ) const = 0;
111 
117  virtual INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const = 0;
118 
119  virtual bool IsPointInside( const SFVEC2F &aPoint ) const = 0;
120 
121  const CBBOX2D &GetBBox() const { return m_bbox; }
122 
123  const SFVEC2F &GetCentroid() const { return m_centroid; }
124 
126 };
127 
128 
129 
133 {
134 public:
135  void ResetStats() { memset( m_counter, 0, sizeof( unsigned int ) * OBJ2D_MAX ); }
136 
137  unsigned int GetCountOf( OBJECT2D_TYPE aObjType ) const
138  {
139  return m_counter[aObjType];
140  }
141 
142  void AddOne( OBJECT2D_TYPE aObjType ) { m_counter[aObjType]++; }
143 
144  void PrintStats();
145 
147  {
148  if( !s_instance )
150 
151  return *s_instance;
152  }
153 
154 private:
156  COBJECT2D_STATS( const COBJECT2D_STATS &old );
157  const COBJECT2D_STATS &operator=( const COBJECT2D_STATS &old );
159 
160 private:
161  unsigned int m_counter[OBJ2D_MAX];
162 
164 };
165 
166 #endif // _COBJECT2D_H_
INTERSECTION_RESULT
Definition: cobject2d.h:38
virtual bool Overlaps(const CBBOX2D &aBBox) const =0
Function Overlaps.
void PrintStats()
Definition: cobject2d.cpp:60
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
const BOARD_ITEM & m_boardItem
Definition: cobject2d.h:69
Class CBBOX manages a bounding box defined by two SFVEC2F min max points.
Definition: cbbox2d.h:40
const BOARD_ITEM & GetBoardItem() const
Definition: cobject2d.h:75
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
Function Intersect.
unsigned int m_counter[OBJ2D_MAX]
Definition: cobject2d.h:161
const COBJECT2D_STATS & operator=(const COBJECT2D_STATS &old)
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
virtual INTERSECTION_RESULT IsBBoxInside(const CBBOX2D &aBBox) const =0
Function IsBBoxInside.
void AddOne(OBJECT2D_TYPE aObjType)
Definition: cobject2d.h:142
COBJECT2D(OBJECT2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition: cobject2d.cpp:37
OBJECT2D_TYPE GetObjectType() const
Definition: cobject2d.h:125
static COBJECT2D_STATS & Instance()
Definition: cobject2d.h:146
CBBOX2D m_bbox
Definition: cobject2d.h:65
2D Bounding Box class definition
const SFVEC2F & GetCentroid() const
Definition: cobject2d.h:123
OBJECT2D_TYPE m_obj_type
Definition: cobject2d.h:67
SFVEC2F m_centroid
Definition: cobject2d.h:66
OBJECT2D_TYPE
Definition: cobject2d.h:46
void ResetStats()
Definition: cobject2d.h:135
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
static COBJECT2D_STATS * s_instance
Definition: cobject2d.h:163
Implements a class for object statistics using Singleton pattern.
Definition: cobject2d.h:132
virtual bool Intersects(const CBBOX2D &aBBox) const =0
Function Intersects.
virtual ~COBJECT2D()
Definition: cobject2d.h:73
unsigned int GetCountOf(OBJECT2D_TYPE aObjType) const
Definition: cobject2d.h:137
Definition: ray.h:86