~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to include/core/typeinfo.h

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2013 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
#include <cstdio>
 
30
 
 
31
class EDA_ITEM;
 
32
 
 
33
/**
 
34
 * Enum KICAD_T
 
35
 * is the set of class identification values, stored in EDA_ITEM::m_StructType
 
36
 */
 
37
enum KICAD_T
 
38
{
 
39
    NOT_USED = -1,          ///< the 3d code uses this value
 
40
 
 
41
    EOT = 0,                ///< search types array terminator (End Of Types)
 
42
 
 
43
    TYPE_NOT_INIT = 0,
 
44
    PCB_T,
 
45
    SCREEN_T,               ///< not really an item, used to identify a screen
 
46
 
 
47
    // Items in pcb
 
48
    PCB_MODULE_T,           ///< class MODULE, a footprint
 
49
    PCB_PAD_T,              ///< class D_PAD, a pad in a footprint
 
50
    PCB_LINE_T,             ///< class DRAWSEGMENT, a segment not on copper layers
 
51
    PCB_TEXT_T,             ///< class TEXTE_PCB, text on a layer
 
52
    PCB_MODULE_TEXT_T,      ///< class TEXTE_MODULE, text in a footprint
 
53
    PCB_MODULE_EDGE_T,      ///< class EDGE_MODULE, a footprint edge
 
54
    PCB_TRACE_T,            ///< class TRACK, a track segment (segment on a copper layer)
 
55
    PCB_VIA_T,              ///< class VIA, a via (like a track segment on a copper layer)
 
56
    PCB_ZONE_T,             ///< class SEGZONE, a segment used to fill a zone area (segment on a
 
57
                            ///< copper layer)
 
58
    PCB_MARKER_T,           ///< class MARKER_PCB, a marker used to show something
 
59
    PCB_DIMENSION_T,        ///< class DIMENSION, a dimension (graphic item)
 
60
    PCB_TARGET_T,           ///< class PCB_TARGET, a target (graphic item)
 
61
    PCB_ZONE_AREA_T,        ///< class ZONE_CONTAINER, a zone area
 
62
    PCB_ITEM_LIST_T,        ///< class BOARD_ITEM_LIST, a list of board items
 
63
 
 
64
    // Schematic draw Items.  The order of these items effects the sort order.
 
65
    // It is currently ordered to mimic the old Eeschema locate behavior where
 
66
    // the smallest item is the selected item.
 
67
    SCH_MARKER_T,
 
68
    SCH_JUNCTION_T,
 
69
    SCH_NO_CONNECT_T,
 
70
    SCH_BUS_WIRE_ENTRY_T,
 
71
    SCH_BUS_BUS_ENTRY_T,
 
72
    SCH_LINE_T,
 
73
    SCH_BITMAP_T,
 
74
    SCH_TEXT_T,
 
75
    SCH_LABEL_T,
 
76
    SCH_GLOBAL_LABEL_T,
 
77
    SCH_HIERARCHICAL_LABEL_T,
 
78
    SCH_FIELD_T,
 
79
    SCH_COMPONENT_T,
 
80
    SCH_SHEET_PIN_T,
 
81
    SCH_SHEET_T,
 
82
 
 
83
    // Be prudent with these 3 types:
 
84
    // they should be used only to locate a specific field type
 
85
    // among SCH_FIELD_T items types
 
86
    SCH_FIELD_LOCATE_REFERENCE_T,
 
87
    SCH_FIELD_LOCATE_VALUE_T,
 
88
    SCH_FIELD_LOCATE_FOOTPRINT_T,
 
89
 
 
90
    // General
 
91
    SCH_SCREEN_T,
 
92
 
 
93
    /*
 
94
     * Draw items in library component.
 
95
     *
 
96
     * The order of these items effects the sort order for items inside the
 
97
     * "DRAW/ENDDRAW" section of the component definition in a library file.
 
98
     * If you add a new draw item, type, please make sure you add it so the
 
99
     * sort order is logical.
 
100
     */
 
101
    LIB_COMPONENT_T,
 
102
    LIB_ALIAS_T,
 
103
    LIB_ARC_T,
 
104
    LIB_CIRCLE_T,
 
105
    LIB_TEXT_T,
 
106
    LIB_RECTANGLE_T,
 
107
    LIB_POLYLINE_T,
 
108
    LIB_BEZIER_T,
 
109
    LIB_PIN_T,
 
110
 
 
111
    /*
 
112
     * Fields are not saved inside the "DRAW/ENDDRAW".  Add new draw item
 
113
     * types before this line.
 
114
     */
 
115
    LIB_FIELD_T,
 
116
 
 
117
    /*
 
118
     * For GerbView: items type:
 
119
     */
 
120
    TYPE_GERBER_DRAW_ITEM,
 
121
 
 
122
    /*
 
123
     * for Pl_Editor, in undo/redo commands
 
124
     */
 
125
    TYPE_PL_EDITOR_LAYOUT,
 
126
 
 
127
    // End value
 
128
    MAX_STRUCT_TYPE_ID
 
129
};
 
130
 
 
131
template<typename T>
 
132
struct remove_pointer
 
133
{
 
134
    typedef T type;
 
135
};
 
136
 
 
137
template<typename T>
 
138
struct remove_pointer<T*>
 
139
{
 
140
    typedef typename remove_pointer<T>::type type;
 
141
};
 
142
 
 
143
/**
 
144
 * Function IsA()
 
145
 *
 
146
 * Checks if the type of aObject is T.
 
147
 * @param aObject object for type check
 
148
 * @return true, if aObject type equals T.
 
149
 */
 
150
template <class T, class I>
 
151
bool IsA(const I *aObject)
 
152
{
 
153
    return aObject && remove_pointer<T>::type::ClassOf(aObject);
 
154
}
 
155
 
 
156
template <class T, class I>
 
157
bool IsA(const I& aObject)
 
158
{
 
159
    return remove_pointer<T>::type::ClassOf(&aObject);
 
160
}
 
161
 
 
162
/**
 
163
 * Function dyn_cast()
 
164
 *
 
165
 * A lightweight dynamic downcast. Casts aObject to type Casted*.
 
166
 * Uses EDA_ITEM::Type() and EDA_ITEM::ClassOf() to check if type matches.
 
167
 * @param aObject object to be casted
 
168
 * @return down-casted object or NULL if type doesn't match Casted.
 
169
 */
 
170
template<class Casted, class From>
 
171
Casted dyn_cast(From aObject)
 
172
{
 
173
    if( remove_pointer<Casted>::type::ClassOf ( aObject ) )
 
174
        return static_cast<Casted>( aObject );
 
175
 
 
176
    return NULL;
 
177
}
 
178
 
 
179
#endif // __KICAD_TYPEINFO_H
 
180