KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_kicad_legacy.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 (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef PCB_IO_KICAD_LEGACY_H_
26#define PCB_IO_KICAD_LEGACY_H_
27
28#include <pcb_io/pcb_io.h>
29#include <pcb_io/pcb_io_mgr.h>
30
31#include <richio.h>
32#include <string>
33#include <layer_ids.h>
34#include <lset.h>
35#include <memory>
36#include <geometry/eda_angle.h>
37
38
39// FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
40// a footprint library. A few variants may have been used, and so we can only be
41// sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
42
43#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
44#define FOOTPRINT_LIBRARY_HEADER_CNT 18
45
46class PCB_TARGET;
47class FOOTPRINT;
48class NETCLASS;
49class ZONE;
51class NETINFO_ITEM;
52class PCB_TEXT;
53class PAD;
54struct LP_CACHE;
55
56
63{
64 friend struct LP_CACHE;
65
66public:
69
71 {
72 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
73 }
74
76 {
77 return IO_BASE::IO_FILE_DESC( _HKI( "Legacy footprint library files" ), { "mod", "emp" } );
78 }
79
80 bool CanReadBoard( const wxString& aFileName ) const override;
81 bool CanReadFootprint( const wxString& aFileName ) const override;
82
83 BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
84 const std::map<std::string, UTF8>* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
85
86 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
87 bool aBestEfforts,
88 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
89
90 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
91 bool aKeepUUID = false,
92 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
93
94 bool DeleteLibrary( const wxString& aLibraryPath,
95 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
96
97 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
98
99 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
100
101 typedef int BIU;
102
103 void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
104
105 // return the new .kicad_pcb layer id from the old (legacy) layer id
106 static PCB_LAYER_ID leg_layer2new( int cu_count, int aLayerNum );
107
108 static LSET leg_mask2new( int cu_count, unsigned aMask );
109
110protected:
112 void init( const std::map<std::string, UTF8>* aProperties );
113
114 void checkpoint();
115
118 inline int getNetCode( int aNetCode )
119 {
120 if( (unsigned int) aNetCode < m_netCodes.size() )
121 return m_netCodes[aNetCode];
122
123 return aNetCode;
124 }
125
137 BIU biuParse( const char* aValue, const char** nptrptr = nullptr );
138
147 EDA_ANGLE degParse( const char* aValue, const char** nptrptr = nullptr );
148
149 static int getVersion( LINE_READER* aReader );
150
151 void loadAllSections( bool doAppend );
152
153
154 void loadGENERAL();
155 void loadSETUP();
156 void loadSHEET();
157
158 void load3D( FOOTPRINT* aFootprint );
159 void loadPAD( FOOTPRINT* aFootprint );
160 void loadMODULE_TEXT( PCB_TEXT* aText );
161 void loadFP_SHAPE( FOOTPRINT* aFootprint );
162
163 void loadPCB_LINE();
164 void loadNETINFO_ITEM();
165 void loadPCB_TEXT();
166 void loadNETCLASS();
167 void loadFOOTPRINT( FOOTPRINT* aFootprint );
168
175 void loadTrackList( int aStructType );
176
177 void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
178 void loadDIMENSION(); // "$COTATION"
179 void loadPCB_TARGET(); // "$PCB_TARGET"
180
182 void cacheLib( const wxString& aLibraryPath );
183
184protected:
186
187 wxString m_error;
190 unsigned m_lineCount;
191
193 FILE* m_fp;
194
195 wxString m_field;
199
200 std::vector<int> m_netCodes;
201
202 double biuToDisk;
204
205 double diskToBiu;
207};
208
209#endif // PCB_IO_KICAD_LEGACY_H_
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
Handle the data for a net.
Definition: netinfo.h:56
Definition: pad.h:54
Abstract dimension API.
A #PLUGIN derivation which could possibly be put into a DLL/DSO.
wxString m_error
for throwing exceptions
EDA_ANGLE degParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value which is certainly an angle in tenths of a degree.
void init(const std::map< std::string, UTF8 > *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void loadMODULE_TEXT(PCB_TEXT *aText)
bool CanReadFootprint(const wxString &aFileName) const override
Checks if this PCB_IO can read a footprint from specified file or directory.
PROGRESS_REPORTER * m_progressReporter
may be NULL, no ownership
void loadFP_SHAPE(FOOTPRINT *aFootprint)
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
std::vector< int > m_netCodes
net codes mapping for boards being loaded
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
void loadAllSections(bool doAppend)
unsigned m_lineCount
for progress reporting
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
void loadPAD(FOOTPRINT *aFootprint)
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
static LSET leg_mask2new(int cu_count, unsigned aMask)
void loadTrackList(int aStructType)
Read a list of segments (Tracks and Vias, or Segzones)
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
LINE_READER * m_reader
no ownership here.
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
void SetReader(LINE_READER *aReader)
double diskToBiu
convert from disk engineering units to BIUs
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
BIU biuParse(const char *aValue, const char **nptrptr=nullptr)
Parse an ASCII decimal floating point value and scales it into a BIU according to the current value o...
wxString m_field
reused to stuff FOOTPRINT fields.
void checkpoint()
Converts net code using the mapping table if available, otherwise returns unchanged net code.
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
void loadFOOTPRINT(FOOTPRINT *aFootprint)
FILE * m_fp
no ownership here.
static int getVersion(LINE_READER *aReader)
void load3D(FOOTPRINT *aFootprint)
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
int getNetCode(int aNetCode)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
static PCB_LAYER_ID leg_layer2new(int cu_count, int aLayerNum)
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
A base class that BOARD loading and saving plugins should derive from.
Definition: pcb_io.h:71
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition: project.h:64
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
#define _HKI(x)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
PCB_IO_KICAD_LEGACY::BIU BIU
Container that describes file type info.
Definition: io_base.h:43
The footprint portion of the PLUGIN API, and only for the PCB_IO_KICAD_LEGACY, so therefore is privat...