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-2021 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 symbols which are power symbols
159 
160  // matches any type
162 
163  // General
165 
167 
168  /*
169  * Draw items in library symbol.
170  *
171  * The order of these items effects the sort order for items inside the
172  * "DRAW/ENDDRAW" section of the symbol 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  */
181 
182  /*
183  * Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
184  * types before this line.
185  */
187 
188  /*
189  * For GerbView: item types:
190  */
194 
195  /*
196  * For Pl_Editor: item types:
197  */
204 
205  // serialized layout used in undo/redo commands
206  WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands
207  WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings
208 
209  /*
210  * FOR PROJECT::_ELEMs
211  */
217 
218  // End value
220 };
221 
231 constexpr KICAD_T BaseType( const KICAD_T aType )
232 {
233  switch( aType )
234  {
239  return SCH_FIELD_T;
240 
244  return SCH_LINE_T;
245 
248  return SCH_LABEL_T;
249 
251  return SCH_SYMBOL_T;
252 
253  case PCB_LOCATE_HOLE_T:
254  case PCB_LOCATE_PTH_T:
255  case PCB_LOCATE_NPTH_T:
256  return PCB_LOCATE_HOLE_T;
257 
258  case PCB_DIM_ALIGNED_T:
259  case PCB_DIM_CENTER_T:
261  case PCB_DIM_LEADER_T:
262  return PCB_DIMENSION_T;
263 
264  default:
265  return aType;
266  }
267 }
268 
269 #endif // __KICAD_TYPEINFO_H
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
class PCB_DIM_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)
Return the underlying type of the given type.
Definition: typeinfo.h:231
class PCB_DIM_CENTER, 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 PCB_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 PCB_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 PCB_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 PCB_MARKER, 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:100
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class PCB_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)
Check if the type of aObject is T.
Definition: typeinfo.h:40