KiCad PCB EDA Suite
typeinfo.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) 2014 CERN
5  * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __KICAD_TYPEINFO_H
27 #define __KICAD_TYPEINFO_H
28 
29 
30 #ifndef SWIG
31 #include <type_traits>
32 
39 template <class T, class I>
40 bool IsA( const I* aObject )
41 {
42  return aObject && std::remove_pointer<T>::type::ClassOf( aObject );
43 }
44 
45 template <class T, class I>
46 bool IsA( const I& aObject )
47 {
48  return std::remove_pointer<T>::type::ClassOf( &aObject );
49 }
50 
60 template<class Casted, class From>
61 Casted dyn_cast( From aObject )
62 {
63  if( std::remove_pointer<Casted>::type::ClassOf ( aObject ) )
64  return static_cast<Casted>( aObject );
65 
66  return nullptr;
67 }
68 
69 class EDA_ITEM;
70 
71 #endif // SWIG
72 
73 
77 enum KICAD_T
78 {
79  NOT_USED = -1,
80 
81  EOT = 0,
82 
86 
87  // Items in pcb
109 
119 
120  // Schematic draw Items. The order of these items effects the sort order.
121  // It is currently ordered to mimic the old Eeschema locate behavior where
122  // the smallest item is the selected item.
139 
140  // Be prudent with these types:
141  // they should be used only to locate a specific field type among SCH_FIELD_Ts
142  // N.B. If you add a type here, be sure to add it below to the BaseType()
147 
148  // Same for picking wires and buses from SCH_LINE_T items
152 
153  // Same for picking labels attached to wires and/or buses
156 
157  // Same for picking components which are power symbols
159 
160  // matches any type
162 
163  // General
165 
167 
168  /*
169  * Draw items in library component.
170  *
171  * The order of these items effects the sort order for items inside the
172  * "DRAW/ENDDRAW" section of the component definition in a library file.
173  * If you add a new draw item, type, please make sure you add it so the
174  * sort order is logical.
175  */
185 
186  /*
187  * Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
188  * types before this line.
189  */
191 
192  /*
193  * For GerbView: item types:
194  */
198 
199  /*
200  * For Pl_Editor: item types:
201  */
208 
209  // serialized layout used in undo/redo commands
210  WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands
211  WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings
212 
213  /*
214  * FOR PROJECT::_ELEMs
215  */
221 
222  // End value
224 };
225 
235 constexpr KICAD_T BaseType( const KICAD_T aType )
236 {
237  switch( aType )
238  {
243  return SCH_FIELD_T;
244 
248  return SCH_LINE_T;
249 
252  return SCH_LABEL_T;
253 
255  return SCH_COMPONENT_T;
256 
257  case PCB_LOCATE_HOLE_T:
258  case PCB_LOCATE_PTH_T:
259  case PCB_LOCATE_NPTH_T:
260  return PCB_LOCATE_HOLE_T;
261 
262  case PCB_DIM_ALIGNED_T:
263  case PCB_DIM_CENTER_T:
265  case PCB_DIM_LEADER_T:
266  return PCB_DIMENSION_T;
267 
268  default:
269  return aType;
270  }
271 }
272 
273 #endif // __KICAD_TYPEINFO_H
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:100
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
Definition: typeinfo.h:84
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
constexpr KICAD_T BaseType(const KICAD_T aType)
Returns the underlying type of the given type.
Definition: typeinfo.h:235
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:102
the 3d code uses this value
Definition: typeinfo.h:79
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition: typeinfo.h:61
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
not really an item, used to identify a screen
Definition: typeinfo.h:85
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
#define I(x, y, z)
Definition: md5_hash.cpp:18
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:106
class ZONE, a copper pour area
Definition: typeinfo.h:105
class DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:99
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:98
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:107
class ZONE, managed by a footprint
Definition: typeinfo.h:94
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
bool IsA(const I *aObject)
Checks if the type of aObject is T.
Definition: typeinfo.h:40