KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_sch_utils.cpp
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) 2024 Jon Evans <[email protected]>
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <sch_pin.h>
22#include <lib_symbol.h>
23#include <sch_bitmap.h>
24#include <sch_bus_entry.h>
25#include <sch_field.h>
26#include <sch_junction.h>
27#include <sch_label.h>
28#include <sch_line.h>
29#include <sch_no_connect.h>
30#include <sch_shape.h>
31#include <sch_sheet.h>
32#include <sch_sheet_pin.h>
33#include <sch_table.h>
34#include <sch_tablecell.h>
35#include <sch_text.h>
36#include <sch_textbox.h>
37
38#include "api_sch_utils.h"
39
40
41std::unique_ptr<EDA_ITEM> CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer )
42{
43 SCH_ITEM* parentSchItem = dynamic_cast<SCH_ITEM*>( aContainer );
44
45 switch( aType )
46 {
47 case SCH_JUNCTION_T: return std::make_unique<SCH_JUNCTION>();
48 case SCH_NO_CONNECT_T: return std::make_unique<SCH_NO_CONNECT>();
49 case SCH_BUS_WIRE_ENTRY_T: return std::make_unique<SCH_BUS_WIRE_ENTRY>();
50 case SCH_BUS_BUS_ENTRY_T: return std::make_unique<SCH_BUS_BUS_ENTRY>();
51 case SCH_LINE_T: return std::make_unique<SCH_LINE>();
52 case SCH_SHAPE_T: return std::make_unique<SCH_SHAPE>();
53 case SCH_BITMAP_T: return std::make_unique<SCH_BITMAP>();
54 case SCH_TEXTBOX_T: return std::make_unique<SCH_TEXTBOX>();
55 case SCH_TEXT_T: return std::make_unique<SCH_TEXT>();
56 case SCH_TABLE_T: return std::make_unique<SCH_TABLE>();
57 case SCH_TABLECELL_T: return std::make_unique<SCH_TABLECELL>();
58 case SCH_LABEL_T: return std::make_unique<SCH_LABEL>();
59 case SCH_GLOBAL_LABEL_T: return std::make_unique<SCH_GLOBALLABEL>();
60 case SCH_HIER_LABEL_T: return std::make_unique<SCH_HIERLABEL>();
61 case SCH_DIRECTIVE_LABEL_T: return std::make_unique<SCH_DIRECTIVE_LABEL>();
62 case SCH_FIELD_T: return std::make_unique<SCH_FIELD>( parentSchItem );
63
64 case SCH_SYMBOL_T:
65 {
66 // TODO: constructing currently requires more than just a "container" LIB_SYMBOL
67 return nullptr;
68 }
69
70 case SCH_SHEET_PIN_T:
71 {
72 if( aContainer && aContainer->Type() == SCH_SHEET_T )
73 return std::make_unique<SCH_SHEET_PIN>( static_cast<SCH_SHEET*>( aContainer ) );
74
75 return nullptr;
76 }
77
78 case SCH_SHEET_T: return std::make_unique<SCH_SHEET>();
79
80 case SCH_PIN_T:
81 {
82 if( aContainer && aContainer->Type() == LIB_SYMBOL_T )
83 return std::make_unique<SCH_PIN>( static_cast<LIB_SYMBOL*>( aContainer ) );
84
85 return nullptr;
86 }
87
88 case LIB_SYMBOL_T: return nullptr; // TODO: ctor currently requires non-null name
89
90 default:
91 return nullptr;
92 }
93}
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
Define a library symbol object.
Definition: lib_symbol.h:77
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_TABLE_T
Definition: typeinfo.h:165
@ SCH_LINE_T
Definition: typeinfo.h:163
@ LIB_SYMBOL_T
Definition: typeinfo.h:148
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:160
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_TABLECELL_T
Definition: typeinfo.h:166
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:171
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:162
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:173
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:161
@ SCH_BITMAP_T
Definition: typeinfo.h:164
@ SCH_TEXTBOX_T
Definition: typeinfo.h:152
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
@ SCH_JUNCTION_T
Definition: typeinfo.h:159
@ SCH_PIN_T
Definition: typeinfo.h:153