KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_odbpp.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 * Author: SYSUEric <[email protected]>.
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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#ifndef _PCB_IO_ODBPP_H_
23#define _PCB_IO_ODBPP_H_
24
25#include <pcb_io/pcb_io.h>
27
28#include <layer_ids.h> // PCB_LAYER_ID
31#include <font/font.h>
33#include <stroke_params.h>
34#include <memory>
35#include "odb_entity.h"
36
37
38class BOARD;
39class BOARD_ITEM;
40class EDA_TEXT;
41class FOOTPRINT;
43class NETINFO_ITEM;
44class PAD;
45class PCB_SHAPE;
46class PCB_TRACK;
47class PCB_VIA;
49class SHAPE_POLY_SET;
50class SHAPE_SEGMENT;
51class EDA_DATA;
52class ZONE;
53
54
55class PCB_IO_ODBPP : public PCB_IO
56{
57public:
58 PCB_IO_ODBPP() : PCB_IO( wxS( "ODBPlusPlus" ) ) { m_board = nullptr; }
59
60 ~PCB_IO_ODBPP() override;
61
62 void SaveBoard( const wxString& aFileName, BOARD& aBoard,
63 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
64
66 void Export( const wxString& aFileName, BOARD& aBoard, const ODB_EXPORT_OPTIONS& aOptions );
67
68 void ConfigureExport( BOARD& aBoard, const ODB_EXPORT_OPTIONS& aOptions );
69
71 {
72 return IO_BASE::IO_FILE_DESC( _HKI( "ODB++ Production File" ), { "ZIP" }, {}, true, false, true );
73 }
74
76 {
77 // No library description for this plugin
78 return IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
79 }
80
81
82 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
83
85 static int MinPrecision( bool aInches ) { return aInches ? 4 : 3; }
86
88 static int MaxPrecision() { return 16; }
89
90 const ODB_FORMAT& GetFormat() const { return m_format; }
91 const FAB_STACKUP& GetFabStackup() const { return *m_fabStackup; }
93
94 uint32_t NewUid() { return ++m_maxUid; }
95 uint32_t MaxUid() const { return m_maxUid; }
96
97 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override { return 0; }
98
99 // Reading currently disabled
100 bool CanReadBoard( const wxString& aFileName ) const override { return false; }
101
102 // Reading currently disabled
103 bool CanReadFootprint( const wxString& aFileName ) const override { return false; }
104
105 // Reading currently disabled
106 bool CanReadLibrary( const wxString& aFileName ) const override { return false; }
107
108public:
109 inline std::vector<ODB_LAYER_NAME>& GetLayerNameList() { return m_layer_name_list; }
110
111 inline std::vector<std::shared_ptr<FOOTPRINT>>& GetLoadedFootprintList()
112 {
113 return m_loaded_footprints;
114 }
115
116 inline std::map<DRILL_SPAN, std::vector<BOARD_ITEM*>>& GetDrillLayerItemsMap() { return m_drill_layers; }
117
118 inline std::map<ODB_AUX_LAYER_KEY, std::vector<BOARD_ITEM*>>& GetAuxilliaryLayerItemsMap()
119 {
120 return m_auxilliary_layers;
121 }
122
123 inline std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>&
125 {
126 return m_slot_holes;
127 }
128
129 inline std::map<const PAD*, EDA_DATA::SUB_NET_TOEPRINT*>& GetPadSubnetMap()
130 {
131 return m_topeprint_subnets;
132 }
133
134 inline std::map<std::pair<PCB_LAYER_ID, ZONE*>, EDA_DATA::SUB_NET_PLANE*>& GetPlaneSubnetMap()
135 {
136 return m_plane_subnets;
137 }
138
139 inline std::map<PCB_TRACK*, EDA_DATA::SUB_NET*>& GetViaTraceSubnetMap()
140 {
141 return m_via_trace_subnets;
142 }
143
144 void RecordNetTieFeature( const BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, const wxString& aLayerName,
145 size_t aIndex )
146 {
147 m_netTieFeatures.try_emplace( std::make_pair( aItem, aLayer ), aLayerName, aIndex );
148 }
149
150 const std::map<std::pair<const BOARD_ITEM*, PCB_LAYER_ID>, std::pair<wxString, size_t>>&
152 {
153 return m_netTieFeatures;
154 }
155
156 const wxString& GetLegalNetName( int aNetCode ) const
157 {
158 return m_netNames.at( aNetCode );
159 }
160
161
162 std::shared_ptr<ODB_TREE_WRITER> m_writer;
163
164 bool GenerateFiles( ODB_TREE_WRITER& writer );
165 bool ExportODB( const wxString& aFileName );
166 void CreateEntity();
167
169
170 // Frees the memory allocated for the loaded footprints in #m_loaded_footprints.
172
173private:
174 template <typename T, typename... Args>
175 void Make( Args&&... args )
176 {
177 std::shared_ptr<ODB_ENTITY_BASE> entity =
178 std::make_shared<T>( std::forward<Args>( args )... );
179
180 if( entity )
181 m_entities.push_back( entity );
182 }
183
186 uint32_t m_maxUid = 0;
187
188 std::vector<std::shared_ptr<FOOTPRINT>> m_loaded_footprints;
189
190 std::vector<ODB_LAYER_NAME> m_layer_name_list; //<! matrix row metadata in row order
191
192 std::map<DRILL_SPAN, std::vector<BOARD_ITEM*>> m_drill_layers; //<! Drill sets are output as layers, one per span
193 std::map<ODB_AUX_LAYER_KEY, std::vector<BOARD_ITEM*>>
194 m_auxilliary_layers; //<! Auxilliary layers, from/to pairs or simple (depending on type)
195
196 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>
197 m_slot_holes; //<! Storage vector of slotted holes that need to be output as cutouts
198
199 std::map<const PAD*, EDA_DATA::SUB_NET_TOEPRINT*> m_topeprint_subnets;
200
201 std::map<int, wxString> m_netNames;
202
203 std::map<std::pair<PCB_LAYER_ID, ZONE*>, EDA_DATA::SUB_NET_PLANE*> m_plane_subnets;
204
205 std::map<PCB_TRACK*, EDA_DATA::SUB_NET*> m_via_trace_subnets;
206
207 std::map<std::pair<const BOARD_ITEM*, PCB_LAYER_ID>, std::pair<wxString, size_t>> m_netTieFeatures;
208
209 // The entities hold pointers into the snapshot and must be destroyed first
210 std::unique_ptr<FAB_STACKUP> m_fabStackup;
211 std::unique_ptr<FAB_DRILL_MODEL> m_fabDrillModel;
212 std::vector<std::shared_ptr<ODB_ENTITY_BASE>> m_entities;
213};
214
215#endif // _PCB_IO_ODBPP_H_
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
Board stackup snapshot synchronized without changing the source board.
Definition fab_stackup.h:29
Handle the data for a net.
Definition netinfo.h:50
Definition pad.h:61
std::map< std::pair< PCB_LAYER_ID, ZONE * >, EDA_DATA::SUB_NET_PLANE * > & GetPlaneSubnetMap()
std::unique_ptr< FAB_STACKUP > m_fabStackup
BOARD * m_board
void ConfigureExport(BOARD &aBoard, const ODB_EXPORT_OPTIONS &aOptions)
ODB_FORMAT m_format
std::map< PCB_TRACK *, EDA_DATA::SUB_NET * > & GetViaTraceSubnetMap()
std::shared_ptr< ODB_TREE_WRITER > m_writer
~PCB_IO_ODBPP() override
bool CanReadBoard(const wxString &aFileName) const override
uint32_t NewUid()
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void ClearLoadedFootprints()
void Make(Args &&... args)
std::vector< std::shared_ptr< FOOTPRINT > > & GetLoadedFootprintList()
std::map< std::pair< PCB_LAYER_ID, ZONE * >, EDA_DATA::SUB_NET_PLANE * > m_plane_subnets
bool CanReadFootprint(const wxString &aFileName) const override
Check if this PCB_IO can read a footprint from specified file or directory.
uint32_t MaxUid() const
std::vector< ODB_LAYER_NAME > & GetLayerNameList()
void RecordNetTieFeature(const BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, const wxString &aLayerName, size_t aIndex)
std::map< std::pair< const BOARD_ITEM *, PCB_LAYER_ID >, std::pair< wxString, size_t > > m_netTieFeatures
const FAB_DRILL_MODEL & GetFabDrillModel()
void CreateEntity()
bool ExportODB(const wxString &aFileName)
std::vector< std::shared_ptr< FOOTPRINT > > m_loaded_footprints
static int MinPrecision(bool aInches)
Lowest sigfig that still resolves a 0.1 mil grid: 3 decimal places in mm, 4 in inches.
void Export(const wxString &aFileName, BOARD &aBoard, const ODB_EXPORT_OPTIONS &aOptions)
Write the product model tree at aFileName Throw IO_ERROR when the write fails.
std::map< std::pair< PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< BOARD_ITEM * > > & GetSlotHolesMap()
uint32_t m_maxUid
std::map< ODB_AUX_LAYER_KEY, std::vector< BOARD_ITEM * > > m_auxilliary_layers
const FAB_STACKUP & GetFabStackup() const
std::map< const PAD *, EDA_DATA::SUB_NET_TOEPRINT * > & GetPadSubnetMap()
static int MaxPrecision()
Highest sigfig accepted by the exporter, matching the export dialog's spin control.
void SaveBoard(const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
std::map< int, wxString > m_netNames
std::map< DRILL_SPAN, std::vector< BOARD_ITEM * > > & GetDrillLayerItemsMap()
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Return board file description for the PCB_IO.
std::map< ODB_AUX_LAYER_KEY, std::vector< BOARD_ITEM * > > & GetAuxilliaryLayerItemsMap()
std::vector< std::shared_ptr< ODB_ENTITY_BASE > > m_entities
std::map< const PAD *, EDA_DATA::SUB_NET_TOEPRINT * > m_topeprint_subnets
const ODB_FORMAT & GetFormat() const
std::map< std::pair< PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< BOARD_ITEM * > > m_slot_holes
std::map< DRILL_SPAN, std::vector< BOARD_ITEM * > > m_drill_layers
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
const wxString & GetLegalNetName(int aNetCode) const
bool GenerateFiles(ODB_TREE_WRITER &writer)
const std::map< std::pair< const BOARD_ITEM *, PCB_LAYER_ID >, std::pair< wxString, size_t > > & GetNetTieFeatures() const
std::map< PCB_TRACK *, EDA_DATA::SUB_NET * > m_via_trace_subnets
bool CreateDirectories(ODB_TREE_WRITER &writer)
std::vector< ODB_LAYER_NAME > m_layer_name_list
std::unique_ptr< FAB_DRILL_MODEL > m_fabDrillModel
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
PCB_IO(const wxString &aName)
Definition pcb_io.h:372
A progress reporter interface for use in multi-threaded environments.
Represent a set of closed polygons.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
#define _HKI(x)
Definition page_info.cpp:40
Container that describes file type info.
Definition io_base.h:43
What a caller asks of one ODB++ export.
Definition odb_util.h:50