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#pragma once
23
24
25#include <type_traits>
26
33template <class T, class I>
34bool IsA( const I* aObject )
35{
36 return aObject && std::remove_pointer<T>::type::ClassOf( aObject );
37}
38
39template <class T, class I>
40bool IsA( const I& aObject )
41{
42 return std::remove_pointer<T>::type::ClassOf( &aObject );
43}
44
54template<class Casted, class From>
55Casted dyn_cast( From aObject )
56{
57 if( std::remove_pointer<Casted>::type::ClassOf ( aObject ) )
58 return static_cast<Casted>( aObject );
59
60 return nullptr;
61}
62
63class EDA_ITEM;
64
65
70{
71 NOT_USED = -1,
72
76
77 // Items in pcb
106
107 // Be prudent with these types:
108 // they should be used only to locate a specific field type among PCB_FIELD_Ts
109 // N.B. If you add a type here, be sure to add it below to the BaseType()
114
115 // Be prudent with these types:
116 // they should be used only to locate specific item sub-types
117 // N.B. If you add a type here, be sure to add it below to the BaseType()
127
128 // Same for locating shapes types from PCB_SHAPE_T items
135
136 /*
137 * Draw items in library symbol.
138 *
139 * The order of these items effects the sort order for items inside the
140 * "DRAW/ENDDRAW" section of the symbol definition in a library file.
141 * If you add a new draw item, type, please make sure you add it so the
142 * sort order is logical.
143 */
150
151 // Schematic draw Items. The order of these items effects the sort order.
152 // It is currently ordered to mimic the old Eeschema locate behavior where
153 // the smallest item is the selected item.
172
173 // Be prudent with these types:
174 // they should be used only to locate a specific field type among SCH_FIELD_Ts
175 // N.B. If you add a type here, be sure to add it below to the BaseType()
180
181 // Same for picking wires, buses and graphics from SCH_ITEM_T items
185
186 // Same for picking labels, or labels attached to wires and/or buses
190
191 // Same for picking symbols which are power symbols
193
194 // matches any type
196
197 // General
199
201
202 /*
203 * For GerbView: item types:
204 */
208
209 /*
210 * For Pl_Editor: item types:
211 */
218
219 // serialized layout used in undo/redo commands
220 WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands
221 WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings
222
223 /*
224 * FOR PROJECT::_ELEMs
225 */
232
233 // New types appended here to preserve historical KICAD_T ordinals
234 // (IPC clients with stale protobuf-generated headers depend on stable values).
243
244 // End value
246};
247
248static_assert( S3D_CACHE_T == 104,
249 "KICAD_T ordinals are exposed via IPC; new values must be appended at the end "
250 "of the enum, not inserted into existing blocks." );
251
261constexpr KICAD_T BaseType( const KICAD_T aType )
262{
263 switch( aType )
264 {
269 return SCH_FIELD_T;
270
274 return SCH_LINE_T;
275
279 return SCH_LABEL_T;
280
282 return SCH_SYMBOL_T;
283
288 return PCB_FIELD_T;
289
291 case PCB_LOCATE_PTH_T:
293 return PCB_LOCATE_HOLE_T;
294
303
305 case PCB_DIM_CENTER_T:
306 case PCB_DIM_RADIAL_T:
308 case PCB_DIM_LEADER_T:
309 return PCB_DIMENSION_T;
310
313 return PCB_TABLE_T;
314
315 default:
316 return aType;
317 }
318}
319
320constexpr bool IsNullType( const KICAD_T aType )
321{
322 return aType <= 0;
323}
324
328constexpr bool IsGeneratedTableType( const KICAD_T aType )
329{
330 return aType == PCB_DRILL_CHART_T || aType == PCB_STACKUP_TABLE_T;
331}
332
333constexpr bool IsInstantiableType( const KICAD_T aType )
334{
335 if( IsNullType( aType ) )
336 return false;
337
338 switch( aType )
339 {
340 case SCH_LOCATE_ANY_T:
341
346
350
354
356
361
368 case PCB_LOCATE_PTH_T:
371
380 return false;
381
382 case PCB_DIMENSION_T:
383 // base class is not instantiable
384 return false;
385
386 case SCH_TABLECELL_T:
387 case PCB_TABLECELL_T:
388 // must be instantiated as part of a SCH_TABLE or PCB_TABLE
389 return false;
390
391 case SCH_SCREEN_T:
392 case PCB_ITEM_LIST_T:
393 return false;
394
395 default:
396 break;
397 }
398
399 return true;
400
401}
402
403constexpr bool IsEeschemaType( const KICAD_T aType )
404{
405 switch( aType )
406 {
407 case SCH_MARKER_T:
408 case SCH_JUNCTION_T:
409 case SCH_NO_CONNECT_T:
412 case SCH_LINE_T:
413 case SCH_SHAPE_T:
414 case SCH_RULE_AREA_T:
415 case SCH_BITMAP_T:
416 case SCH_TEXT_T:
417 case SCH_TEXTBOX_T:
418 case SCH_TABLE_T:
419 case SCH_TABLECELL_T:
420 case SCH_LABEL_T:
423 case SCH_HIER_LABEL_T:
424 case SCH_FIELD_T:
425 case SCH_SYMBOL_T:
426 case SCH_SHEET_PIN_T:
427 case SCH_GROUP_T:
428 case SCH_SHEET_T:
429 case SCH_PIN_T:
430
435
439
443
445 case SCH_LOCATE_ANY_T:
446
447 case SCH_SCREEN_T:
448 case SCHEMATIC_T:
449
450 case LIB_SYMBOL_T:
451 return true;
452
453 default:
454 return false;
455 }
456}
457
458constexpr bool IsPcbnewType( const KICAD_T aType )
459{
460 switch( aType )
461 {
462 case PCB_T:
463
464 case PCB_FOOTPRINT_T:
465 case PCB_PAD_T:
466 case PCB_SHAPE_T:
468 case PCB_FIELD_T:
469 case PCB_TEXT_T:
470 case PCB_TEXTBOX_T:
471 case PCB_BARCODE_T:
472 case PCB_TABLE_T:
473 case PCB_TABLECELL_T:
474 case PCB_TRACE_T:
475 case PCB_VIA_T:
476 case PCB_ARC_T:
477 case PCB_MARKER_T:
478 case PCB_DIMENSION_T:
480 case PCB_DIM_LEADER_T:
481 case PCB_DIM_CENTER_T:
482 case PCB_DIM_RADIAL_T:
484 case PCB_TARGET_T:
486 case PCB_DRILL_MAP_T:
487 case PCB_3D_BODY_T:
489 case PCB_POINT_T:
490 case PCB_ZONE_T:
491 case PCB_ITEM_LIST_T:
492 case PCB_NETINFO_T:
493 case PCB_GROUP_T:
494 case PCB_GENERATOR_T:
495 case PCB_GRID_ITEM_T:
496
507 case PCB_LOCATE_PTH_T:
519 case PCB_CONSTRAINT_T:
520 return true;
521
522 default:
523 return false;
524 }
525}
526
527constexpr bool IsSingleLayerType( const KICAD_T aType )
528{
529 switch( aType )
530 {
531 case PCB_SHAPE_T:
533 case PCB_FIELD_T:
534 case PCB_TEXT_T:
535 case PCB_TEXTBOX_T:
536 case PCB_BARCODE_T:
537 case PCB_TABLE_T:
539 case PCB_DRILL_MAP_T:
541 case PCB_TABLECELL_T:
542 case PCB_TRACE_T:
543 case PCB_ARC_T:
544 case PCB_MARKER_T:
545 case PCB_DIMENSION_T:
547 case PCB_DIM_LEADER_T:
548 case PCB_DIM_CENTER_T:
549 case PCB_DIM_RADIAL_T:
551 case PCB_TARGET_T:
552 case PCB_POINT_T:
553 case PCB_GENERATOR_T:
554 return true;
555
556 default:
557 return false;
558 }
559}
560
561constexpr bool IsGerbviewType( const KICAD_T aType )
562{
563 switch( aType )
564 {
565 case GERBER_LAYOUT_T:
567 case GERBER_IMAGE_T:
568 return true;
569
570 default:
571 return false;
572 }
573}
574
575constexpr bool IsPageLayoutEditorType( const KICAD_T aType )
576{
577 switch( aType )
578 {
579 case WSG_LINE_T:
580 case WSG_RECT_T:
581 case WSG_POLY_T:
582 case WSG_TEXT_T:
583 case WSG_BITMAP_T:
584 case WSG_PAGE_T:
585
588 return true;
589
590 default:
591 return false;
592 }
593}
594
595constexpr bool IsMiscType( const KICAD_T aType )
596{
597 switch( aType )
598 {
599 case SCREEN_T:
600
602 case FP_LIB_TABLE_T:
604 case SYMBOL_LIBS_T:
605 case SEARCH_STACK_T:
606 case S3D_CACHE_T:
607 return true;
608
609 default:
610 return false;
611 }
612}
613
614constexpr bool IsTypeCorrect( KICAD_T aType )
615{
616 return IsNullType( aType )
617 || IsEeschemaType( aType )
618 || IsPcbnewType( aType )
619 || IsGerbviewType( aType )
620 || IsPageLayoutEditorType( aType )
621 || IsMiscType( aType );
622}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
#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:261
constexpr bool IsSingleLayerType(const KICAD_T aType)
Definition typeinfo.h:527
constexpr bool IsGerbviewType(const KICAD_T aType)
Definition typeinfo.h:561
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ FP_LIB_TABLE_T
Definition typeinfo.h:227
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_TABLE_T
Definition typeinfo.h:161
@ PCB_SHAPE_LOCATE_ELLIPSE_ARC_T
Definition typeinfo.h:236
@ PCB_T
Definition typeinfo.h:74
@ PCB_CONSTRAINT_T
a geometric constraint between board items
Definition typeinfo.h:237
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ SCH_LINE_T
Definition typeinfo.h:159
@ PCB_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:111
@ LIB_SYMBOL_T
Definition typeinfo.h:144
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ SCH_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:176
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_LOCATE_BOARD_EDGE_T
Definition typeinfo.h:126
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition typeinfo.h:178
@ TYPE_NOT_INIT
Definition typeinfo.h:73
@ MAX_STRUCT_TYPE_ID
Definition typeinfo.h:245
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
Definition typeinfo.h:240
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_LOCATE_NPTH_T
Definition typeinfo.h:125
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_LOCATE_BLINDVIA_T
Definition typeinfo.h:120
@ SCH_ITEM_LOCATE_WIRE_T
Definition typeinfo.h:182
@ SCH_FIELD_T
Definition typeinfo.h:146
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_LOCATE_TEXT_T
Definition typeinfo.h:122
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:167
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:195
@ SCH_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:177
@ S3D_CACHE_T
Definition typeinfo.h:231
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_ITEM_LOCATE_BUS_T
Definition typeinfo.h:183
@ PCB_3D_BODY_T
class PCB_3D_BODY, a 3D body (extruded or model) on a footprint
Definition typeinfo.h:241
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ SCH_MARKER_T
Definition typeinfo.h:154
@ PCB_ITEM_LIST_T
class BOARD_ITEM_LIST, a list of board items
Definition typeinfo.h:101
@ SCH_SHAPE_T
Definition typeinfo.h:145
@ WSG_POLY_T
Definition typeinfo.h:214
@ SCH_RULE_AREA_T
Definition typeinfo.h:166
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_LOCATE_STDVIA_T
Definition typeinfo.h:118
@ GERBER_DRAW_ITEM_T
Definition typeinfo.h:206
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:71
@ PCB_LOCATE_BURIEDVIA_T
Definition typeinfo.h:121
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:91
@ WSG_LINE_T
Definition typeinfo.h:212
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:158
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ SCH_SCREEN_T
Definition typeinfo.h:198
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:99
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:187
@ PCB_SHAPE_LOCATE_CIRCLE_T
Definition typeinfo.h:131
@ PCB_SHAPE_LOCATE_SEGMENT_T
Definition typeinfo.h:129
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:179
@ PCB_SHAPE_LOCATE_RECT_T
Definition typeinfo.h:130
@ SYMBOL_LIB_TABLE_T
Definition typeinfo.h:226
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition typeinfo.h:184
@ PCB_SHAPE_LOCATE_ELLIPSE_T
Definition typeinfo.h:235
@ SCHEMATIC_T
Definition typeinfo.h:200
@ SCH_LABEL_LOCATE_WIRE_T
Definition typeinfo.h:188
@ WSG_TEXT_T
Definition typeinfo.h:215
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ SCH_SHEET_PIN_T
Definition typeinfo.h:170
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:110
@ SCH_TEXT_T
Definition typeinfo.h:147
@ PCB_SHAPE_LOCATE_BEZIER_T
Definition typeinfo.h:134
@ WSG_PAGE_T
Definition typeinfo.h:217
@ WS_PROXY_UNDO_ITEM_T
Definition typeinfo.h:220
@ SEARCH_STACK_T
Definition typeinfo.h:230
@ SYMBOL_LIBS_T
Definition typeinfo.h:229
@ SCH_LABEL_LOCATE_BUS_T
Definition typeinfo.h:189
@ PCB_LOCATE_PTH_T
Definition typeinfo.h:124
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ WSG_RECT_T
Definition typeinfo.h:213
@ PCB_SHAPE_LOCATE_POLY_T
Definition typeinfo.h:133
@ PCB_SHAPE_LOCATE_ARC_T
Definition typeinfo.h:132
@ SCH_SYMBOL_LOCATE_POWER_T
Definition typeinfo.h:192
@ DESIGN_BLOCK_LIB_TABLE_T
Definition typeinfo.h:228
@ GERBER_IMAGE_T
Definition typeinfo.h:207
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:157
@ GERBER_LAYOUT_T
Definition typeinfo.h:205
@ SCREEN_T
not really an item, used to identify a screen
Definition typeinfo.h:75
@ SCH_BITMAP_T
Definition typeinfo.h:160
@ PCB_BOARD_OUTLINE_T
class PCB_BOARD_OUTLINE_T, a pcb board outline item
Definition typeinfo.h:104
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition typeinfo.h:221
@ PCB_LOCATE_UVIA_T
Definition typeinfo.h:119
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:92
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:102
@ SCH_TEXTBOX_T
Definition typeinfo.h:148
@ PCB_STACKUP_TABLE_T
class PCB_STACKUP_TABLE, a live stackup table derived from PCB_TABLE
Definition typeinfo.h:242
@ WSG_BITMAP_T
Definition typeinfo.h:216
@ PCB_LOCATE_HOLE_T
Definition typeinfo.h:123
@ PCB_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:113
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
Definition typeinfo.h:239
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
@ PCB_FIELD_LOCATE_FOOTPRINT_T
Definition typeinfo.h:112
@ SCH_JUNCTION_T
Definition typeinfo.h:155
@ SCH_PIN_T
Definition typeinfo.h:149
constexpr bool IsTypeCorrect(KICAD_T aType)
Definition typeinfo.h:614
constexpr bool IsPcbnewType(const KICAD_T aType)
Definition typeinfo.h:458
constexpr bool IsMiscType(const KICAD_T aType)
Definition typeinfo.h:595
constexpr bool IsInstantiableType(const KICAD_T aType)
Definition typeinfo.h:333
constexpr bool IsGeneratedTableType(const KICAD_T aType)
A PCB_TABLE subclass whose cells are generated from the board rather than typed by the user.
Definition typeinfo.h:328
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:55
constexpr bool IsNullType(const KICAD_T aType)
Definition typeinfo.h:320
bool IsA(const I *aObject)
Check if the type of aObject is T.
Definition typeinfo.h:34
constexpr bool IsEeschemaType(const KICAD_T aType)
Definition typeinfo.h:403
constexpr bool IsPageLayoutEditorType(const KICAD_T aType)
Definition typeinfo.h:575