KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef __KICAD_TYPEINFO_H
23#define __KICAD_TYPEINFO_H
24
25
26#include <type_traits>
27
34template <class T, class I>
35bool IsA( const I* aObject )
36{
37 return aObject && std::remove_pointer<T>::type::ClassOf( aObject );
38}
39
40template <class T, class I>
41bool IsA( const I& aObject )
42{
43 return std::remove_pointer<T>::type::ClassOf( &aObject );
44}
45
55template<class Casted, class From>
56Casted dyn_cast( From aObject )
57{
58 if( std::remove_pointer<Casted>::type::ClassOf ( aObject ) )
59 return static_cast<Casted>( aObject );
60
61 return nullptr;
62}
63
64class EDA_ITEM;
65
66
71{
72 NOT_USED = -1,
73
77
78 // Items in pcb
107
108 // Be prudent with these types:
109 // they should be used only to locate a specific field type among PCB_FIELD_Ts
110 // N.B. If you add a type here, be sure to add it below to the BaseType()
115
116 // Be prudent with these types:
117 // they should be used only to locate specific item sub-types
118 // N.B. If you add a type here, be sure to add it below to the BaseType()
128
129 // Same for locating shapes types from PCB_SHAPE_T items
136
137 /*
138 * Draw items in library symbol.
139 *
140 * The order of these items effects the sort order for items inside the
141 * "DRAW/ENDDRAW" section of the symbol definition in a library file.
142 * If you add a new draw item, type, please make sure you add it so the
143 * sort order is logical.
144 */
151
152 // Schematic draw Items. The order of these items effects the sort order.
153 // It is currently ordered to mimic the old Eeschema locate behavior where
154 // the smallest item is the selected item.
173
174 // Be prudent with these types:
175 // they should be used only to locate a specific field type among SCH_FIELD_Ts
176 // N.B. If you add a type here, be sure to add it below to the BaseType()
181
182 // Same for picking wires, buses and graphics from SCH_ITEM_T items
186
187 // Same for picking labels, or labels attached to wires and/or buses
191
192 // Same for picking symbols which are power symbols
194
195 // matches any type
197
198 // General
200
202
203 /*
204 * For GerbView: item types:
205 */
209
210 /*
211 * For Pl_Editor: item types:
212 */
219
220 // serialized layout used in undo/redo commands
221 WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands
222 WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings
223
224 /*
225 * FOR PROJECT::_ELEMs
226 */
233
234 // New types appended here to preserve historical KICAD_T ordinals
235 // (IPC clients with stale protobuf-generated headers depend on stable values).
238
239 // End value
241};
242
243static_assert( S3D_CACHE_T == 104,
244 "KICAD_T ordinals are exposed via IPC; new values must be appended at the end "
245 "of the enum, not inserted into existing blocks." );
246
256constexpr KICAD_T BaseType( const KICAD_T aType )
257{
258 switch( aType )
259 {
264 return SCH_FIELD_T;
265
269 return SCH_LINE_T;
270
274 return SCH_LABEL_T;
275
277 return SCH_SYMBOL_T;
278
283 return PCB_FIELD_T;
284
286 case PCB_LOCATE_PTH_T:
288 return PCB_LOCATE_HOLE_T;
289
298
300 case PCB_DIM_CENTER_T:
301 case PCB_DIM_RADIAL_T:
303 case PCB_DIM_LEADER_T:
304 return PCB_DIMENSION_T;
305
306 default:
307 return aType;
308 }
309}
310
311constexpr bool IsNullType( const KICAD_T aType )
312{
313 return aType <= 0;
314}
315
316constexpr bool IsInstantiableType( const KICAD_T aType )
317{
318 if( IsNullType( aType ) )
319 return false;
320
321 switch( aType )
322 {
323 case SCH_LOCATE_ANY_T:
324
329
333
337
339
344
351 case PCB_LOCATE_PTH_T:
354
363
364 case PCB_DIMENSION_T:
365
366 case SCH_SCREEN_T:
367 case PCB_ITEM_LIST_T:
368 return false;
369
370 default:
371 break;
372 }
373
374 return true;
375
376}
377
378constexpr bool IsEeschemaType( const KICAD_T aType )
379{
380 switch( aType )
381 {
382 case SCH_MARKER_T:
383 case SCH_JUNCTION_T:
384 case SCH_NO_CONNECT_T:
387 case SCH_LINE_T:
388 case SCH_SHAPE_T:
389 case SCH_RULE_AREA_T:
390 case SCH_BITMAP_T:
391 case SCH_TEXT_T:
392 case SCH_TEXTBOX_T:
393 case SCH_TABLE_T:
394 case SCH_TABLECELL_T:
395 case SCH_LABEL_T:
398 case SCH_HIER_LABEL_T:
399 case SCH_FIELD_T:
400 case SCH_SYMBOL_T:
401 case SCH_SHEET_PIN_T:
402 case SCH_GROUP_T:
403 case SCH_SHEET_T:
404 case SCH_PIN_T:
405
410
414
418
420 case SCH_LOCATE_ANY_T:
421
422 case SCH_SCREEN_T:
423 case SCHEMATIC_T:
424
425 case LIB_SYMBOL_T:
426 return true;
427
428 default:
429 return false;
430 }
431}
432
433constexpr bool IsPcbnewType( const KICAD_T aType )
434{
435 switch( aType )
436 {
437 case PCB_T:
438
439 case PCB_FOOTPRINT_T:
440 case PCB_PAD_T:
441 case PCB_SHAPE_T:
443 case PCB_FIELD_T:
444 case PCB_TEXT_T:
445 case PCB_TEXTBOX_T:
446 case PCB_BARCODE_T:
447 case PCB_TABLE_T:
448 case PCB_TABLECELL_T:
449 case PCB_TRACE_T:
450 case PCB_VIA_T:
451 case PCB_ARC_T:
452 case PCB_MARKER_T:
453 case PCB_DIMENSION_T:
455 case PCB_DIM_LEADER_T:
456 case PCB_DIM_CENTER_T:
457 case PCB_DIM_RADIAL_T:
459 case PCB_TARGET_T:
460 case PCB_POINT_T:
461 case PCB_ZONE_T:
462 case PCB_ITEM_LIST_T:
463 case PCB_NETINFO_T:
464 case PCB_GROUP_T:
465 case PCB_GENERATOR_T:
466
477 case PCB_LOCATE_PTH_T:
489 return true;
490
491 default:
492 return false;
493 }
494}
495
496constexpr bool IsGerbviewType( const KICAD_T aType )
497{
498 switch( aType )
499 {
500 case GERBER_LAYOUT_T:
502 case GERBER_IMAGE_T:
503 return true;
504
505 default:
506 return false;
507 }
508}
509
510constexpr bool IsPageLayoutEditorType( const KICAD_T aType )
511{
512 switch( aType )
513 {
514 case WSG_LINE_T:
515 case WSG_RECT_T:
516 case WSG_POLY_T:
517 case WSG_TEXT_T:
518 case WSG_BITMAP_T:
519 case WSG_PAGE_T:
520
523 return true;
524
525 default:
526 return false;
527 }
528}
529
530constexpr bool IsMiscType( const KICAD_T aType )
531{
532 switch( aType )
533 {
534 case SCREEN_T:
535
537 case FP_LIB_TABLE_T:
539 case SYMBOL_LIBS_T:
540 case SEARCH_STACK_T:
541 case S3D_CACHE_T:
542 return true;
543
544 default:
545 return false;
546 }
547}
548
549constexpr bool IsTypeCorrect( KICAD_T aType )
550{
551 return IsNullType( aType )
552 || IsEeschemaType( aType )
553 || IsPcbnewType( aType )
554 || IsGerbviewType( aType )
555 || IsPageLayoutEditorType( aType )
556 || IsMiscType( aType );
557}
558
559#endif // __KICAD_TYPEINFO_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
#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:256
constexpr bool IsGerbviewType(const KICAD_T aType)
Definition typeinfo.h:496
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ FP_LIB_TABLE_T
Definition typeinfo.h:228
@ SCH_GROUP_T
Definition typeinfo.h:170
@ SCH_TABLE_T
Definition typeinfo.h:162
@ PCB_SHAPE_LOCATE_ELLIPSE_ARC_T
Definition typeinfo.h:237
@ PCB_T
Definition typeinfo.h:75
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:99
@ SCH_LINE_T
Definition typeinfo.h:160
@ PCB_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:112
@ LIB_SYMBOL_T
Definition typeinfo.h:145
@ SCH_NO_CONNECT_T
Definition typeinfo.h:157
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:96
@ SCH_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:177
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:84
@ PCB_LOCATE_BOARD_EDGE_T
Definition typeinfo.h:127
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition typeinfo.h:179
@ TYPE_NOT_INIT
Definition typeinfo.h:74
@ MAX_STRUCT_TYPE_ID
Definition typeinfo.h:240
@ SCH_SYMBOL_T
Definition typeinfo.h:169
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:97
@ PCB_LOCATE_NPTH_T
Definition typeinfo.h:126
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:104
@ SCH_TABLECELL_T
Definition typeinfo.h:163
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:86
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:101
@ PCB_LOCATE_BLINDVIA_T
Definition typeinfo.h:121
@ SCH_ITEM_LOCATE_WIRE_T
Definition typeinfo.h:183
@ SCH_FIELD_T
Definition typeinfo.h:147
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85
@ PCB_LOCATE_TEXT_T
Definition typeinfo.h:123
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:168
@ SCH_LABEL_T
Definition typeinfo.h:164
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:196
@ SCH_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:178
@ S3D_CACHE_T
Definition typeinfo.h:232
@ SCH_SHEET_T
Definition typeinfo.h:172
@ SCH_ITEM_LOCATE_BUS_T
Definition typeinfo.h:184
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:82
@ SCH_MARKER_T
Definition typeinfo.h:155
@ PCB_ITEM_LIST_T
class BOARD_ITEM_LIST, a list of board items
Definition typeinfo.h:102
@ SCH_SHAPE_T
Definition typeinfo.h:146
@ WSG_POLY_T
Definition typeinfo.h:215
@ SCH_RULE_AREA_T
Definition typeinfo.h:167
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
@ PCB_LOCATE_STDVIA_T
Definition typeinfo.h:119
@ GERBER_DRAW_ITEM_T
Definition typeinfo.h:207
@ SCH_HIER_LABEL_T
Definition typeinfo.h:166
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:72
@ PCB_LOCATE_BURIEDVIA_T
Definition typeinfo.h:122
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:92
@ WSG_LINE_T
Definition typeinfo.h:213
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:159
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:94
@ SCH_SCREEN_T
Definition typeinfo.h:199
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:100
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:188
@ PCB_SHAPE_LOCATE_CIRCLE_T
Definition typeinfo.h:132
@ PCB_SHAPE_LOCATE_SEGMENT_T
Definition typeinfo.h:130
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:180
@ PCB_SHAPE_LOCATE_RECT_T
Definition typeinfo.h:131
@ SYMBOL_LIB_TABLE_T
Definition typeinfo.h:227
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition typeinfo.h:185
@ PCB_SHAPE_LOCATE_ELLIPSE_T
Definition typeinfo.h:236
@ SCHEMATIC_T
Definition typeinfo.h:201
@ SCH_LABEL_LOCATE_WIRE_T
Definition typeinfo.h:189
@ WSG_TEXT_T
Definition typeinfo.h:216
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:88
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79
@ SCH_SHEET_PIN_T
Definition typeinfo.h:171
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:95
@ PCB_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:111
@ SCH_TEXT_T
Definition typeinfo.h:148
@ PCB_SHAPE_LOCATE_BEZIER_T
Definition typeinfo.h:135
@ WSG_PAGE_T
Definition typeinfo.h:218
@ WS_PROXY_UNDO_ITEM_T
Definition typeinfo.h:221
@ SEARCH_STACK_T
Definition typeinfo.h:231
@ SYMBOL_LIBS_T
Definition typeinfo.h:230
@ SCH_LABEL_LOCATE_BUS_T
Definition typeinfo.h:190
@ PCB_LOCATE_PTH_T
Definition typeinfo.h:125
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80
@ WSG_RECT_T
Definition typeinfo.h:214
@ PCB_SHAPE_LOCATE_POLY_T
Definition typeinfo.h:134
@ PCB_SHAPE_LOCATE_ARC_T
Definition typeinfo.h:133
@ SCH_SYMBOL_LOCATE_POWER_T
Definition typeinfo.h:193
@ DESIGN_BLOCK_LIB_TABLE_T
Definition typeinfo.h:229
@ GERBER_IMAGE_T
Definition typeinfo.h:208
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:158
@ GERBER_LAYOUT_T
Definition typeinfo.h:206
@ SCREEN_T
not really an item, used to identify a screen
Definition typeinfo.h:76
@ SCH_BITMAP_T
Definition typeinfo.h:161
@ PCB_BOARD_OUTLINE_T
class PCB_BOARD_OUTLINE_T, a pcb board outline item
Definition typeinfo.h:105
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition typeinfo.h:222
@ PCB_LOCATE_UVIA_T
Definition typeinfo.h:120
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:93
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:87
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:103
@ SCH_TEXTBOX_T
Definition typeinfo.h:149
@ WSG_BITMAP_T
Definition typeinfo.h:217
@ PCB_LOCATE_HOLE_T
Definition typeinfo.h:124
@ PCB_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:114
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:106
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:98
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:165
@ PCB_FIELD_LOCATE_FOOTPRINT_T
Definition typeinfo.h:113
@ SCH_JUNCTION_T
Definition typeinfo.h:156
@ SCH_PIN_T
Definition typeinfo.h:150
constexpr bool IsTypeCorrect(KICAD_T aType)
Definition typeinfo.h:549
constexpr bool IsPcbnewType(const KICAD_T aType)
Definition typeinfo.h:433
constexpr bool IsMiscType(const KICAD_T aType)
Definition typeinfo.h:530
constexpr bool IsInstantiableType(const KICAD_T aType)
Definition typeinfo.h:316
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:56
constexpr bool IsNullType(const KICAD_T aType)
Definition typeinfo.h:311
bool IsA(const I *aObject)
Check if the type of aObject is T.
Definition typeinfo.h:35
constexpr bool IsEeschemaType(const KICAD_T aType)
Definition typeinfo.h:378
constexpr bool IsPageLayoutEditorType(const KICAD_T aType)
Definition typeinfo.h:510