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 (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
107
108 // Be prudent with these types:
109 // they should be used only to locate specific item sub-types
110 // N.B. If you add a type here, be sure to add it below to the BaseType()
119
120 // Same for locating shapes types from PCB_SHAPE_T items
127
128 // Schematic draw Items. The order of these items effects the sort order.
129 // It is currently ordered to mimic the old Eeschema locate behavior where
130 // the smallest item is the selected item.
150
151 // Be prudent with these types:
152 // they should be used only to locate a specific field type among SCH_FIELD_Ts
153 // N.B. If you add a type here, be sure to add it below to the BaseType()
158
159 // Same for picking wires, buses and graphics from SCH_ITEM_T items
163
164 // Same for picking labels, or labels attached to wires and/or buses
168
169 // Same for picking symbols which are power symbols
171
172 // matches any type
174
175 // General
177
179
180 /*
181 * Draw items in library symbol.
182 *
183 * The order of these items effects the sort order for items inside the
184 * "DRAW/ENDDRAW" section of the symbol definition in a library file.
185 * If you add a new draw item, type, please make sure you add it so the
186 * sort order is logical.
187 */
193
194 /*
195 * Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
196 * types before this line.
197 */
199
200 /*
201 * For GerbView: item types:
202 */
206
207 /*
208 * For Pl_Editor: item types:
209 */
216
217 // serialized layout used in undo/redo commands
218 WS_PROXY_UNDO_ITEM_T, // serialized layout used in undo/redo commands
219 WS_PROXY_UNDO_ITEM_PLUS_T, // serialized layout plus page and title block settings
220
221 /*
222 * FOR PROJECT::_ELEMs
223 */
229
230 // End value
233
243constexpr KICAD_T BaseType( const KICAD_T aType )
244{
245 switch( aType )
246 {
251 return SCH_FIELD_T;
252
256 return SCH_LINE_T;
257
261 return SCH_LABEL_T;
262
264 return SCH_SYMBOL_T;
265
267 case PCB_LOCATE_PTH_T:
269 return PCB_LOCATE_HOLE_T;
270
277 return PCB_SHAPE_T;
278
280 case PCB_DIM_CENTER_T:
281 case PCB_DIM_RADIAL_T:
283 case PCB_DIM_LEADER_T:
284 return PCB_DIMENSION_T;
285
286 default:
287 return aType;
288 }
289}
290
291constexpr bool IsNullType( const KICAD_T aType )
292{
293 return aType <= 0;
294}
295
296constexpr bool IsInstantiableType( const KICAD_T aType )
297{
298 if( IsNullType( aType ) )
299 return false;
300
301 switch( aType )
302 {
303 case SCH_LOCATE_ANY_T:
304
309
313
317
319
325 case PCB_LOCATE_PTH_T:
328
335
336 case PCB_DIMENSION_T:
337
338 case SCH_SCREEN_T:
339 case PCB_ITEM_LIST_T:
340 return false;
341
342 default:
343 break;
344 }
345
346 return true;
347
348}
349
350constexpr bool IsEeschemaType( const KICAD_T aType )
351{
352 switch( aType )
353 {
354 case SCH_MARKER_T:
355 case SCH_JUNCTION_T:
356 case SCH_NO_CONNECT_T:
359 case SCH_LINE_T:
360 case SCH_SHAPE_T:
361 case SCH_BITMAP_T:
362 case SCH_TEXT_T:
363 case SCH_TEXTBOX_T:
364 case SCH_LABEL_T:
367 case SCH_HIER_LABEL_T:
368 case SCH_FIELD_T:
369 case SCH_SYMBOL_T:
370 case SCH_SHEET_PIN_T:
371 case SCH_SHEET_T:
372 case SCH_PIN_T:
373
378
382
386
388 case SCH_LOCATE_ANY_T:
389
390 case SCH_SCREEN_T:
391 case SCHEMATIC_T:
392
393 case LIB_SYMBOL_T:
394 case LIB_SHAPE_T:
395 case LIB_TEXT_T:
396 case LIB_TEXTBOX_T:
397 case LIB_PIN_T:
398
399 case LIB_FIELD_T:
400 return true;
401
402 default:
403 return false;
404 }
405}
406
407constexpr bool IsPcbnewType( const KICAD_T aType )
408{
409 switch( aType )
410 {
411 case PCB_T:
412
413 case PCB_FOOTPRINT_T:
414 case PCB_PAD_T:
415 case PCB_SHAPE_T:
416 case PCB_BITMAP_T:
417 case PCB_TEXT_T:
418 case PCB_TEXTBOX_T:
419 case PCB_TRACE_T:
420 case PCB_VIA_T:
421 case PCB_ARC_T:
422 case PCB_MARKER_T:
423 case PCB_DIMENSION_T:
425 case PCB_DIM_LEADER_T:
426 case PCB_DIM_CENTER_T:
427 case PCB_DIM_RADIAL_T:
429 case PCB_TARGET_T:
430 case PCB_ZONE_T:
431 case PCB_ITEM_LIST_T:
432 case PCB_NETINFO_T:
433 case PCB_GROUP_T:
434
440 case PCB_LOCATE_PTH_T:
449 return true;
450
451 default:
452 return false;
453 }
454}
455
456constexpr bool IsGerbviewType( const KICAD_T aType )
457{
458 switch( aType )
459 {
460 case GERBER_LAYOUT_T:
462 case GERBER_IMAGE_T:
463 return true;
464
465 default:
466 return false;
467 }
468}
469
470constexpr bool IsPageLayoutEditorType( const KICAD_T aType )
471{
472 switch( aType )
473 {
474 case WSG_LINE_T:
475 case WSG_RECT_T:
476 case WSG_POLY_T:
477 case WSG_TEXT_T:
478 case WSG_BITMAP_T:
479 case WSG_PAGE_T:
480
483 return true;
484
485 default:
486 return false;
487 }
488}
489
490constexpr bool IsMiscType( const KICAD_T aType )
491{
492 switch( aType )
493 {
494 case SCREEN_T:
495
497 case FP_LIB_TABLE_T:
498 case SYMBOL_LIBS_T:
499 case SEARCH_STACK_T:
500 case S3D_CACHE_T:
501 return true;
502
503 default:
504 return false;
505 }
506}
507
508constexpr bool IsTypeCorrect( KICAD_T aType )
509{
510 return IsNullType( aType )
511 || IsEeschemaType( aType )
512 || IsPcbnewType( aType )
513 || IsGerbviewType( aType )
514 || IsPageLayoutEditorType( aType )
515 || IsMiscType( aType );
516}
517
518constexpr bool IsTypeAvailable( KICAD_T aType )
519{
520 if( !IsInstantiableType( aType ) )
521 return false;
522
523 if( IsEeschemaType( aType ) )
524 {
525#ifdef EESCHEMA
526 return true;
527#endif // EESCHEMA
528 }
529
530 if( IsPcbnewType( aType ) )
531 {
532#ifdef PCBNEW
533 return true;
534#endif // PCBNEW
535 }
536
537 if( IsGerbviewType( aType ) )
538 {
539#ifdef GERBVIEW
540 return true;
541#endif // GERBVIEW
542 }
543
544 if( IsPageLayoutEditorType( aType ) )
545 {
546#ifdef PL_EDITOR
547 return true;
548#endif // PL_EDITOR
549 }
550
551 return false;
552}
553
554#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:243
constexpr bool IsTypeAvailable(KICAD_T aType)
Definition: typeinfo.h:518
constexpr bool IsGerbviewType(const KICAD_T aType)
Definition: typeinfo.h:456
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:225
@ 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:101
@ SCH_LINE_T
Definition: typeinfo.h:136
@ LIB_SYMBOL_T
Definition: typeinfo.h:188
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:133
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:98
@ SCH_FIELD_LOCATE_REFERENCE_T
Definition: typeinfo.h:154
@ LIB_TEXT_T
Definition: typeinfo.h:190
@ PCB_LOCATE_BOARD_EDGE_T
Definition: typeinfo.h:118
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:93
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:156
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ MAX_STRUCT_TYPE_ID
Definition: typeinfo.h:231
@ SCH_SYMBOL_T
Definition: typeinfo.h:146
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:99
@ PCB_LOCATE_BBVIA_T
Definition: typeinfo.h:113
@ PCB_LOCATE_NPTH_T
Definition: typeinfo.h:117
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:106
@ 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:103
@ LIB_TEXTBOX_T
Definition: typeinfo.h:191
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:160
@ SCH_FIELD_T
Definition: typeinfo.h:145
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_LOCATE_TEXT_T
Definition: typeinfo.h:114
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:144
@ SCH_LABEL_T
Definition: typeinfo.h:141
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:173
@ SCH_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:155
@ S3D_CACHE_T
Definition: typeinfo.h:228
@ SCH_SHEET_T
Definition: typeinfo.h:148
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:161
@ LIB_SHAPE_T
Definition: typeinfo.h:189
@ SCH_MARKER_T
Definition: typeinfo.h:131
@ PCB_ITEM_LIST_T
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:104
@ SCH_SHAPE_T
Definition: typeinfo.h:137
@ WSG_POLY_T
Definition: typeinfo.h:212
@ PCB_LOCATE_STDVIA_T
Definition: typeinfo.h:111
@ GERBER_DRAW_ITEM_T
Definition: typeinfo.h:204
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:143
@ 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:95
@ WSG_LINE_T
Definition: typeinfo.h:210
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:135
@ LIB_PIN_T
Definition: typeinfo.h:192
@ SCH_SCREEN_T
Definition: typeinfo.h:176
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:102
@ SCH_LABEL_LOCATE_ANY_T
Definition: typeinfo.h:165
@ PCB_SHAPE_LOCATE_CIRCLE_T
Definition: typeinfo.h:123
@ PCB_SHAPE_LOCATE_SEGMENT_T
Definition: typeinfo.h:121
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:157
@ PCB_SHAPE_LOCATE_RECT_T
Definition: typeinfo.h:122
@ SYMBOL_LIB_TABLE_T
Definition: typeinfo.h:224
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:162
@ SCHEMATIC_T
Definition: typeinfo.h:178
@ SCH_LABEL_LOCATE_WIRE_T
Definition: typeinfo.h:166
@ WSG_TEXT_T
Definition: typeinfo.h:213
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:147
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:97
@ SCH_TEXT_T
Definition: typeinfo.h:140
@ PCB_SHAPE_LOCATE_BEZIER_T
Definition: typeinfo.h:126
@ WSG_PAGE_T
Definition: typeinfo.h:215
@ WS_PROXY_UNDO_ITEM_T
Definition: typeinfo.h:218
@ SEARCH_STACK_T
Definition: typeinfo.h:227
@ SYMBOL_LIBS_T
Definition: typeinfo.h:226
@ LIB_FIELD_T
Definition: typeinfo.h:198
@ SCH_LABEL_LOCATE_BUS_T
Definition: typeinfo.h:167
@ PCB_BITMAP_T
class PCB_BITMAP, bitmap on a layer
Definition: typeinfo.h:89
@ PCB_LOCATE_PTH_T
Definition: typeinfo.h:116
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ WSG_RECT_T
Definition: typeinfo.h:211
@ PCB_SHAPE_LOCATE_POLY_T
Definition: typeinfo.h:125
@ PCB_SHAPE_LOCATE_ARC_T
Definition: typeinfo.h:124
@ SCH_SYMBOL_LOCATE_POWER_T
Definition: typeinfo.h:170
@ GERBER_IMAGE_T
Definition: typeinfo.h:205
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:134
@ GERBER_LAYOUT_T
Definition: typeinfo.h:203
@ SCREEN_T
not really an item, used to identify a screen
Definition: typeinfo.h:83
@ SCH_BITMAP_T
Definition: typeinfo.h:138
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:94
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition: typeinfo.h:219
@ PCB_LOCATE_UVIA_T
Definition: typeinfo.h:112
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:96
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:105
@ SCH_TEXTBOX_T
Definition: typeinfo.h:139
@ WSG_BITMAP_T
Definition: typeinfo.h:214
@ PCB_LOCATE_HOLE_T
Definition: typeinfo.h:115
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:92
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:100
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:142
@ SCH_JUNCTION_T
Definition: typeinfo.h:132
@ SCH_PIN_T
Definition: typeinfo.h:149
constexpr bool IsTypeCorrect(KICAD_T aType)
Definition: typeinfo.h:508
constexpr bool IsPcbnewType(const KICAD_T aType)
Definition: typeinfo.h:407
constexpr bool IsMiscType(const KICAD_T aType)
Definition: typeinfo.h:490
constexpr bool IsInstantiableType(const KICAD_T aType)
Definition: typeinfo.h:296
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition: typeinfo.h:61
constexpr bool IsNullType(const KICAD_T aType)
Definition: typeinfo.h:291
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:350
constexpr bool IsPageLayoutEditorType(const KICAD_T aType)
Definition: typeinfo.h:470