KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_pcb_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) 2023 Jon Evans <[email protected]>
5 * Copyright The 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 <api/api_pcb_utils.h>
22#include <api/api_enums.h>
23#include <board.h>
25#include <footprint.h>
26#include <lset.h>
27#include <pad.h>
28#include <pcb_group.h>
29#include <pcb_barcode.h>
30#include <pcb_reference_image.h>
31#include <pcb_shape.h>
32#include <pcb_track.h>
33#include <pcb_text.h>
34#include <pcb_textbox.h>
35#include <zone.h>
36
37
38std::unique_ptr<BOARD_ITEM> CreateItemForType( KICAD_T aType, BOARD_ITEM_CONTAINER* aContainer )
39{
40 switch( aType )
41 {
42 case PCB_TRACE_T: return std::make_unique<PCB_TRACK>( aContainer );
43 case PCB_ARC_T: return std::make_unique<PCB_ARC>( aContainer );
44 case PCB_VIA_T: return std::make_unique<PCB_VIA>( aContainer );
45 case PCB_TEXT_T: return std::make_unique<PCB_TEXT>( aContainer );
46 case PCB_TEXTBOX_T: return std::make_unique<PCB_TEXTBOX>( aContainer );
47 case PCB_SHAPE_T: return std::make_unique<PCB_SHAPE>( aContainer );
48 case PCB_BARCODE_T: return std::make_unique<PCB_BARCODE>( aContainer );
49 case PCB_ZONE_T: return std::make_unique<ZONE>( aContainer );
50 case PCB_GROUP_T: return std::make_unique<PCB_GROUP>( aContainer );
51 case PCB_REFERENCE_IMAGE_T: return std::make_unique<PCB_REFERENCE_IMAGE>( aContainer );
52
53 case PCB_PAD_T:
54 {
55 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aContainer );
56
57 if( !footprint )
58 return nullptr;
59
60 return std::make_unique<PAD>( footprint );
61 }
62
63 case PCB_FOOTPRINT_T:
64 {
65 BOARD* board = dynamic_cast<BOARD*>( aContainer );
66
67 if( !board )
68 return nullptr;
69
70 return std::make_unique<FOOTPRINT>( board );
71 }
72
73 default:
74 return nullptr;
75 }
76}
77
78namespace kiapi::board
79{
80
81void PackLayerSet( google::protobuf::RepeatedField<int>& aOutput, const LSET& aLayerSet )
82{
83 for( const PCB_LAYER_ID& layer : aLayerSet.Seq() )
85}
86
87
88LSET UnpackLayerSet( const google::protobuf::RepeatedField<int>& aProtoLayerSet )
89{
90 LSET set;
91
92 for( int layer : aProtoLayerSet )
93 {
94 wxCHECK2( layer >= F_Cu && layer < PCB_LAYER_ID_COUNT, continue );
95 PCB_LAYER_ID boardLayer =
96 FromProtoEnum<PCB_LAYER_ID>( static_cast<types::BoardLayer>( layer ) );
97 set.set( boardLayer );
98 }
99
100 return set;
101}
102
103} // namespace kiapi::board
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
Definition api_enums.cpp:96
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:35
std::unique_ptr< BOARD_ITEM > CreateItemForType(KICAD_T aType, BOARD_ITEM_CONTAINER *aContainer)
BASE_SET & set(size_t pos)
Definition base_set.h:116
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:296
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171
@ F_Cu
Definition layer_ids.h:64
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
LSET UnpackLayerSet(const google::protobuf::RepeatedField< int > &aProtoLayerSet)
BARCODE class definition.
Class to handle a set of BOARD_ITEMs.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:111
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:93
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:108
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:92
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:89
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:101
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:98
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:96