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 (C) 2023 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 <pad.h>
27#include <pcb_group.h>
28#include <pcb_reference_image.h>
29#include <pcb_shape.h>
30#include <pcb_track.h>
31#include <pcb_text.h>
32#include <pcb_textbox.h>
33#include <zone.h>
34
35
36std::unique_ptr<BOARD_ITEM> CreateItemForType( KICAD_T aType, BOARD_ITEM_CONTAINER* aContainer )
37{
38 switch( aType )
39 {
40 case PCB_TRACE_T: return std::make_unique<PCB_TRACK>( aContainer );
41 case PCB_ARC_T: return std::make_unique<PCB_ARC>( aContainer );
42 case PCB_VIA_T: return std::make_unique<PCB_VIA>( aContainer );
43 case PCB_TEXT_T: return std::make_unique<PCB_TEXT>( aContainer );
44 case PCB_TEXTBOX_T: return std::make_unique<PCB_TEXTBOX>( aContainer );
45 case PCB_SHAPE_T: return std::make_unique<PCB_SHAPE>( aContainer );
46 case PCB_ZONE_T: return std::make_unique<ZONE>( aContainer );
47 case PCB_GROUP_T: return std::make_unique<PCB_GROUP>( aContainer );
48 case PCB_REFERENCE_IMAGE_T: return std::make_unique<PCB_REFERENCE_IMAGE>( aContainer );
49
50 case PCB_PAD_T:
51 {
52 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aContainer );
53
54 if( !footprint )
55 return nullptr;
56
57 return std::make_unique<PAD>( footprint );
58 }
59
60 case PCB_FOOTPRINT_T:
61 {
62 BOARD* board = dynamic_cast<BOARD*>( aContainer );
63
64 if( !board )
65 return nullptr;
66
67 return std::make_unique<FOOTPRINT>( board );
68 }
69
70 default:
71 return nullptr;
72 }
73}
74
75namespace kiapi::board
76{
77
78void PackLayerSet( google::protobuf::RepeatedField<int>& aOutput, const LSET& aLayerSet )
79{
80 for( const PCB_LAYER_ID& layer : aLayerSet.Seq() )
81 aOutput.Add( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( layer ) );
82}
83
84
85LSET UnpackLayerSet( const google::protobuf::RepeatedField<int>& aProtoLayerSet )
86{
87 LSET set;
88
89 for( int layer : aProtoLayerSet )
90 {
91 wxCHECK2( layer >= F_Cu && layer < PCB_LAYER_ID_COUNT, continue );
92 PCB_LAYER_ID boardLayer =
93 FromProtoEnum<PCB_LAYER_ID>( static_cast<types::BoardLayer>( layer ) );
94 set.set( boardLayer );
95 }
96
97 return set;
98}
99
100} // namespace kiapi::board
std::unique_ptr< BOARD_ITEM > CreateItemForType(KICAD_T aType, BOARD_ITEM_CONTAINER *aContainer)
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:418
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
@ 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)
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:110
@ 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:107
@ 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_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