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-2022 KiCad Developers, see change_log.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
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
39template <class T, class I>
40bool IsA( const I* aObject )
41{
42 return aObject && std::remove_pointer<T>::type::ClassOf( aObject );
43}
44
45template <class T, class I>
46bool IsA( const I& aObject )
47{
48 return std::remove_pointer<T>::type::ClassOf( &aObject );
49}
50
60template<class Casted, class From>
61Casted 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
69class EDA_ITEM;
70
71#endif // SWIG
72
73
78{
79 NOT_USED = -1,
80
84
85 // Items in pcb
116
117 // Be prudent with these types:
118 // they should be used only to locate specific item sub-types
119 // N.B. If you add a type here, be sure to add it below to the BaseType()
129
130 // Same for locating shapes types from PCB_SHAPE_T and PCB_FP_SHAPE_T items
136
137 // Schematic draw Items. The order of these items effects the sort order.
138 // It is currently ordered to mimic the old Eeschema locate behavior where
139 // the smallest item is the selected item.
159
160 // Be prudent with these types:
161 // they should be used only to locate a specific field type among SCH_FIELD_Ts
162 // N.B. If you add a type here, be sure to add it below to the BaseType()
167
168 // Same for picking wires, buses and graphics from SCH_ITEM_T items
172
173 // Same for picking labels, or labels attached to wires and/or buses
177
178 // Same for picking symbols which are power symbols
180
181 // matches any type
183
184 // General
186
188
189 /*
190 * Draw items in library symbol.
191 *
192 * The order of these items effects the sort order for items inside the
193 * "DRAW/ENDDRAW" section of the symbol definition in a library file.
194 * If you add a new draw item, type, please make sure you add it so the
195 * sort order is logical.
196 */
203
204 /*
205 * Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
206 * types before this line.
207 */
209
210 /*
211 * For GerbView: item types:
212 */
216
217 /*
218 * For Pl_Editor: item types:
219 */
226
227 // serialized layout used in undo/redo commands
228 WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands
229 WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings
230
231 /*
232 * FOR PROJECT::_ELEMs
233 */
239
240 // End value
243
253constexpr KICAD_T BaseType( const KICAD_T aType )
254{
255 switch( aType )
256 {
261 return SCH_FIELD_T;
262
266 return SCH_LINE_T;
267
271 return SCH_LABEL_T;
272
274 return SCH_SYMBOL_T;
275
277 case PCB_LOCATE_PTH_T:
279 return PCB_LOCATE_HOLE_T;
280
286 return PCB_SHAPE_T;
287
289 case PCB_DIM_CENTER_T:
290 case PCB_DIM_RADIAL_T:
292 case PCB_DIM_LEADER_T:
298 return PCB_DIMENSION_T;
299
300 default:
301 return aType;
302 }
303}
304
305constexpr bool IsNullType( const KICAD_T aType )
306{
307 return aType <= 0;
308}
309
310constexpr bool IsInstantiableType( const KICAD_T aType )
311{
312 if( IsNullType( aType ) )
313 return false;
314
315 switch( aType )
316 {
317 case SCH_LOCATE_ANY_T:
318
323
327
331
333
340 case PCB_LOCATE_PTH_T:
343
349
350 case PCB_DIMENSION_T:
351
352 case SCH_SCREEN_T:
353 case PCB_ITEM_LIST_T:
354 return false;
355
356 default:
357 break;
358 }
359
360 return true;
361
362}
363
364constexpr bool IsEeschemaType( const KICAD_T aType )
365{
366 switch( aType )
367 {
368 case SCH_MARKER_T:
369 case SCH_JUNCTION_T:
370 case SCH_NO_CONNECT_T:
373 case SCH_LINE_T:
374 case SCH_SHAPE_T:
375 case SCH_BITMAP_T:
376 case SCH_TEXT_T:
377 case SCH_TEXTBOX_T:
378 case SCH_LABEL_T:
381 case SCH_HIER_LABEL_T:
382 case SCH_FIELD_T:
383 case SCH_SYMBOL_T:
384 case SCH_SHEET_PIN_T:
385 case SCH_SHEET_T:
386 case SCH_PIN_T:
387
392
396
400
402 case SCH_LOCATE_ANY_T:
403
404 case SCH_SCREEN_T:
405 case SCHEMATIC_T:
406
407 case LIB_SYMBOL_T:
408 case LIB_ALIAS_T:
409 case LIB_SHAPE_T:
410 case LIB_TEXT_T:
411 case LIB_TEXTBOX_T:
412 case LIB_PIN_T:
413
414 case LIB_FIELD_T:
415 return true;
416
417 default:
418 return false;
419 }
420}
421
422constexpr bool IsPcbnewType( const KICAD_T aType )
423{
424 switch( aType )
425 {
426 case PCB_T:
427
428 case PCB_FOOTPRINT_T:
429 case PCB_PAD_T:
430 case PCB_SHAPE_T:
431 case PCB_BITMAP_T:
432 case PCB_TEXT_T:
433 case PCB_TEXTBOX_T:
434 case PCB_FP_TEXT_T:
435 case PCB_FP_TEXTBOX_T:
436 case PCB_FP_SHAPE_T:
442 case PCB_FP_ZONE_T:
443 case PCB_TRACE_T:
444 case PCB_VIA_T:
445 case PCB_ARC_T:
446 case PCB_MARKER_T:
447 case PCB_DIMENSION_T:
449 case PCB_DIM_LEADER_T:
450 case PCB_DIM_CENTER_T:
451 case PCB_DIM_RADIAL_T:
453 case PCB_TARGET_T:
454 case PCB_ZONE_T:
455 case PCB_ITEM_LIST_T:
456 case PCB_NETINFO_T:
457 case PCB_GROUP_T:
458
465 case PCB_LOCATE_PTH_T:
473 return true;
474
475 default:
476 return false;
477 }
478}
479
480constexpr bool IsGerbviewType( const KICAD_T aType )
481{
482 switch( aType )
483 {
484 case GERBER_LAYOUT_T:
486 case GERBER_IMAGE_T:
487 return true;
488
489 default:
490 return false;
491 }
492}
493
494constexpr bool IsPageLayoutEditorType( const KICAD_T aType )
495{
496 switch( aType )
497 {
498 case WSG_LINE_T:
499 case WSG_RECT_T:
500 case WSG_POLY_T:
501 case WSG_TEXT_T:
502 case WSG_BITMAP_T:
503 case WSG_PAGE_T:
504
507 return true;
508
509 default:
510 return false;
511 }
512}
513
514constexpr bool IsMiscType( const KICAD_T aType )
515{
516 switch( aType )
517 {
518 case SCREEN_T:
519
521 case FP_LIB_TABLE_T:
522 case SYMBOL_LIBS_T:
523 case SEARCH_STACK_T:
524 case S3D_CACHE_T:
525 return true;
526
527 default:
528 return false;
529 }
530}
531
532constexpr bool IsTypeCorrect( KICAD_T aType )
533{
534 return IsNullType( aType )
535 || IsEeschemaType( aType )
536 || IsPcbnewType( aType )
537 || IsGerbviewType( aType )
538 || IsPageLayoutEditorType( aType )
539 || IsMiscType( aType );
540}
541
542constexpr bool IsTypeAvailable( KICAD_T aType )
543{
544 if( !IsInstantiableType( aType ) )
545 return false;
546
547 if( IsEeschemaType( aType ) )
548 {
549#ifdef EESCHEMA
550 return true;
551#endif // EESCHEMA
552 }
553
554 if( IsPcbnewType( aType ) )
555 {
556#ifdef PCBNEW
557 return true;
558#endif // PCBNEW
559 }
560
561 if( IsGerbviewType( aType ) )
562 {
563#ifdef GERBVIEW
564 return true;
565#endif // GERBVIEW
566 }
567
568 if( IsPageLayoutEditorType( aType ) )
569 {
570#ifdef PL_EDITOR
571 return true;
572#endif // PL_EDITOR
573 }
574
575 return false;
576}
577
578#endif // __KICAD_TYPEINFO_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
#define I(x, y, z)
Definition: md5_hash.cpp:18
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition: typeinfo.h:253
constexpr bool IsTypeAvailable(KICAD_T aType)
Definition: typeinfo.h:542
constexpr bool IsGerbviewType(const KICAD_T aType)
Definition: typeinfo.h:480
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ FP_LIB_TABLE_T
Definition: typeinfo.h:235
@ PCB_FP_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:95
@ PCB_T
Definition: typeinfo.h:82
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:110
@ SCH_LINE_T
Definition: typeinfo.h:145
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ LIB_SYMBOL_T
Definition: typeinfo.h:197
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:142
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:107
@ SCH_FIELD_LOCATE_REFERENCE_T
Definition: typeinfo.h:163
@ LIB_TEXT_T
Definition: typeinfo.h:200
@ PCB_LOCATE_BOARD_EDGE_T
Definition: typeinfo.h:128
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:165
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ LIB_ALIAS_T
Definition: typeinfo.h:198
@ MAX_STRUCT_TYPE_ID
Definition: typeinfo.h:241
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ SCH_SYMBOL_T
Definition: typeinfo.h:155
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:108
@ PCB_LOCATE_BBVIA_T
Definition: typeinfo.h:122
@ PCB_LOCATE_NPTH_T
Definition: typeinfo.h:127
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:115
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ LIB_TEXTBOX_T
Definition: typeinfo.h:201
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:169
@ SCH_FIELD_T
Definition: typeinfo.h:154
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_LOCATE_TEXT_T
Definition: typeinfo.h:123
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:153
@ SCH_LABEL_T
Definition: typeinfo.h:150
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:182
@ SCH_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:164
@ S3D_CACHE_T
Definition: typeinfo.h:238
@ PCB_FP_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:97
@ SCH_SHEET_T
Definition: typeinfo.h:157
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:170
@ LIB_SHAPE_T
Definition: typeinfo.h:199
@ SCH_MARKER_T
Definition: typeinfo.h:140
@ PCB_ITEM_LIST_T
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:113
@ SCH_SHAPE_T
Definition: typeinfo.h:146
@ WSG_POLY_T
Definition: typeinfo.h:222
@ PCB_LOCATE_STDVIA_T
Definition: typeinfo.h:120
@ PCB_LOCATE_GRAPHIC_T
Definition: typeinfo.h:124
@ GERBER_DRAW_ITEM_T
Definition: typeinfo.h:214
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:152
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:104
@ WSG_LINE_T
Definition: typeinfo.h:220
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:144
@ LIB_PIN_T
Definition: typeinfo.h:202
@ SCH_SCREEN_T
Definition: typeinfo.h:185
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:111
@ SCH_LABEL_LOCATE_ANY_T
Definition: typeinfo.h:174
@ PCB_FP_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:99
@ PCB_SHAPE_LOCATE_CIRCLE_T
Definition: typeinfo.h:133
@ PCB_SHAPE_LOCATE_SEGMENT_T
Definition: typeinfo.h:131
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:166
@ PCB_SHAPE_LOCATE_RECT_T
Definition: typeinfo.h:132
@ SYMBOL_LIB_TABLE_T
Definition: typeinfo.h:234
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:171
@ SCHEMATIC_T
Definition: typeinfo.h:187
@ SCH_LABEL_LOCATE_WIRE_T
Definition: typeinfo.h:175
@ PCB_FP_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:96
@ WSG_TEXT_T
Definition: typeinfo.h:223
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:156
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:106
@ SCH_TEXT_T
Definition: typeinfo.h:149
@ WSG_PAGE_T
Definition: typeinfo.h:225
@ WS_PROXY_UNDO_ITEM_T
Definition: typeinfo.h:228
@ SEARCH_STACK_T
Definition: typeinfo.h:237
@ SYMBOL_LIBS_T
Definition: typeinfo.h:236
@ LIB_FIELD_T
Definition: typeinfo.h:208
@ PCB_FP_ZONE_T
class ZONE, managed by a footprint
Definition: typeinfo.h:100
@ SCH_LABEL_LOCATE_BUS_T
Definition: typeinfo.h:176
@ PCB_BITMAP_T
class PCB_BITMAP, bitmap on a layer
Definition: typeinfo.h:89
@ PCB_FP_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:98
@ PCB_LOCATE_PTH_T
Definition: typeinfo.h:126
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ WSG_RECT_T
Definition: typeinfo.h:221
@ PCB_SHAPE_LOCATE_POLY_T
Definition: typeinfo.h:135
@ PCB_SHAPE_LOCATE_ARC_T
Definition: typeinfo.h:134
@ SCH_SYMBOL_LOCATE_POWER_T
Definition: typeinfo.h:179
@ GERBER_IMAGE_T
Definition: typeinfo.h:215
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:143
@ GERBER_LAYOUT_T
Definition: typeinfo.h:213
@ SCREEN_T
not really an item, used to identify a screen
Definition: typeinfo.h:83
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
@ SCH_BITMAP_T
Definition: typeinfo.h:147
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition: typeinfo.h:229
@ PCB_LOCATE_UVIA_T
Definition: typeinfo.h:121
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:105
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:114
@ SCH_TEXTBOX_T
Definition: typeinfo.h:148
@ WSG_BITMAP_T
Definition: typeinfo.h:224
@ PCB_LOCATE_HOLE_T
Definition: typeinfo.h:125
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:109
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:151
@ SCH_JUNCTION_T
Definition: typeinfo.h:141
@ SCH_PIN_T
Definition: typeinfo.h:158
constexpr bool IsTypeCorrect(KICAD_T aType)
Definition: typeinfo.h:532
constexpr bool IsPcbnewType(const KICAD_T aType)
Definition: typeinfo.h:422
constexpr bool IsMiscType(const KICAD_T aType)
Definition: typeinfo.h:514
constexpr bool IsInstantiableType(const KICAD_T aType)
Definition: typeinfo.h:310
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition: typeinfo.h:61
constexpr bool IsNullType(const KICAD_T aType)
Definition: typeinfo.h:305
bool IsA(const I *aObject)
Check if the type of aObject is T.
Definition: typeinfo.h:40
constexpr bool IsEeschemaType(const KICAD_T aType)
Definition: typeinfo.h:364
constexpr bool IsPageLayoutEditorType(const KICAD_T aType)
Definition: typeinfo.h:494