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 <memory>
35#include <geometry/eda_angle.h>
36
37
38// FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
39// a footprint library. A few variants may have been used, and so we can only be
40// sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
41
42#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
43#define FOOTPRINT_LIBRARY_HEADER_CNT 18
44
45class PCB_TARGET;
46class FOOTPRINT;
47class NETCLASS;
48class ZONE;
50class NETINFO_ITEM;
51class PCB_TEXT;
52class PAD;
53struct LP_CACHE;
54
55
62{
63 friend struct LP_CACHE;
64
65public:
68
70 {
71 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
72 }
73
75 {
76 return IO_BASE::IO_FILE_DESC( _HKI( "Legacy footprint library files" ), { "mod", "emp" } );
77 }
78
79 bool CanReadBoard( const wxString& aFileName ) const override;
80 bool CanReadFootprint( const wxString& aFileName ) const override;
81
82 BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
83 const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
84
85 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
86 bool aBestEfforts,
87 const STRING_UTF8_MAP* aProperties = nullptr ) override;
88
89 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
90 bool aKeepUUID = false,
91 const STRING_UTF8_MAP* aProperties = nullptr ) override;
92
93 bool DeleteLibrary( const wxString& aLibraryPath,
94 const STRING_UTF8_MAP* aProperties = nullptr ) override;
95
96 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
97
98 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
99
100 typedef int BIU;
101
102 void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
103
104 // return the new .kicad_pcb layer id from the old (legacy) layer id
105 static PCB_LAYER_ID leg_layer2new( int cu_count, int aLayerNum );
106
107 static LSET leg_mask2new( int cu_count, unsigned aMask );
108
109protected:
111 void init( const STRING_UTF8_MAP* aProperties );
112
113 void checkpoint();
114
117 inline int getNetCode( int aNetCode )
118 {
119 if( (unsigned int) aNetCode < m_netCodes.size() )
120 return m_netCodes[aNetCode];
121
122 return aNetCode;
123 }
124
136 BIU biuParse( const char* aValue, const char** nptrptr = nullptr );
137
146 EDA_ANGLE degParse( const char* aValue, const char** nptrptr = nullptr );
147
148 static int getVersion( LINE_READER* aReader );
149
150 void loadAllSections( bool doAppend );
151
152
153 void loadGENERAL();
154 void loadSETUP();
155 void loadSHEET();
156
157 void load3D( FOOTPRINT* aFootprint );
158 void loadPAD( FOOTPRINT* aFootprint );
159 void loadMODULE_TEXT( PCB_TEXT* aText );
160 void loadFP_SHAPE( FOOTPRINT* aFootprint );
161
162 void loadPCB_LINE();
163 void loadNETINFO_ITEM();
164 void loadPCB_TEXT();
165 void loadNETCLASS();
166 void loadFOOTPRINT( FOOTPRINT* aFootprint );
167
174 void loadTrackList( int aStructType );
175
176 void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
177 void loadDIMENSION(); // "$COTATION"
178 void loadPCB_TARGET(); // "$PCB_TARGET"
179
181 void cacheLib( const wxString& aLibraryPath );
182
183protected:
185
186 wxString m_error;
189 unsigned m_lineCount;
190
192 FILE* m_fp;
193
194 wxString m_field;
198
199 std::vector<int> m_netCodes;
200
201 double biuToDisk;
203
204 double diskToBiu;
206};
207
208#endif // PCB_IO_KICAD_LEGACY_H_
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
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: layer_ids.h:575
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:59
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 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
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
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.
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
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)
LINE_READER * m_reader
no ownership here.
void SetReader(LINE_READER *aReader)
double diskToBiu
convert from disk engineering units to BIUs
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 FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
void checkpoint()
Converts net code using the mapping table if available, otherwise returns unchanged net code.
bool DeleteLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
void init(const STRING_UTF8_MAP *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
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)
A base class that BOARD loading and saving plugins should derive from.
Definition: pcb_io.h:72
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition: project.h:62
A name/value tuple with unique names and optional values.
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
#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:39
The footprint portion of the PLUGIN API, and only for the PCB_IO_KICAD_LEGACY, so therefore is privat...