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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PCB_IO_KICAD_LEGACY_H_
22#define PCB_IO_KICAD_LEGACY_H_
23
24#include <pcb_io/pcb_io.h>
25#include <pcb_io/pcb_io_mgr.h>
26
27#include <richio.h>
28#include <string>
29#include <layer_ids.h>
30#include <lset.h>
31#include <memory>
32#include <geometry/eda_angle.h>
33
34
35// FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
36// a footprint library. A few variants may have been used, and so we can only be
37// sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
38
39#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
40#define FOOTPRINT_LIBRARY_HEADER_CNT 18
41
42class PCB_TARGET;
43class FOOTPRINT;
44class NETCLASS;
45class ZONE;
47class NETINFO_ITEM;
48class PCB_TEXT;
49class PAD;
50struct LP_CACHE;
51
52
59{
60 friend struct LP_CACHE;
61
62public:
65
67 {
68 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
69 }
70
72 {
73 return IO_BASE::IO_FILE_DESC( _HKI( "Legacy footprint library files" ), { "mod", "emp" } );
74 }
75
76 bool CanReadBoard( const wxString& aFileName ) const override;
77 bool CanReadFootprint( const wxString& aFileName ) const override;
78
79 BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
80 const std::map<std::string, UTF8>* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
81
82 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
83 bool aBestEfforts,
84 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
85
86 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
87 bool aKeepUUID = false,
88 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
89
90 bool DeleteLibrary( const wxString& aLibraryPath,
91 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
92
93 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
94
95 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
96
97 typedef int BIU;
98
99 void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
100
101 // return the new .kicad_pcb layer id from the old (legacy) layer id
102 static PCB_LAYER_ID leg_layer2new( int cu_count, int aLayerNum );
103
104 static LSET leg_mask2new( int cu_count, unsigned aMask );
105
106protected:
108 void init( const std::map<std::string, UTF8>* aProperties );
109
110 void checkpoint();
111
114 inline int getNetCode( int aNetCode )
115 {
116 if( (unsigned int) aNetCode < m_netCodes.size() )
117 return m_netCodes[aNetCode];
118
119 return aNetCode;
120 }
121
133 BIU biuParse( const char* aValue, const char** nptrptr = nullptr );
134
143 EDA_ANGLE degParse( const char* aValue, const char** nptrptr = nullptr );
144
145 static int getVersion( LINE_READER* aReader );
146
147 void loadAllSections( bool doAppend );
148
149
150 void loadGENERAL();
151 void loadSETUP();
152 void loadSHEET();
153
154 void load3D( FOOTPRINT* aFootprint );
155 void loadPAD( FOOTPRINT* aFootprint );
156 void loadMODULE_TEXT( PCB_TEXT* aText );
157 void loadFP_SHAPE( FOOTPRINT* aFootprint );
158
159 void loadPCB_LINE();
160 void loadNETINFO_ITEM();
161 void loadPCB_TEXT();
162 void loadNETCLASS();
163 void loadFOOTPRINT( FOOTPRINT* aFootprint );
164
171 void loadTrackList( int aStructType );
172
173 void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
174 void loadDIMENSION(); // "$COTATION"
175 void loadPCB_TARGET(); // "$PCB_TARGET"
176
178 void cacheLib( const wxString& aLibraryPath );
179
180protected:
182
183 wxString m_error;
186 unsigned m_lineCount;
187
189 FILE* m_fp;
190
191 wxString m_field;
195
196 std::vector<int> m_netCodes;
197
198 double biuToDisk;
200
201 double diskToBiu;
203};
204
205#endif // PCB_IO_KICAD_LEGACY_H_
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:62
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:38
Handle the data for a net.
Definition netinfo.h:46
Definition pad.h:61
Abstract dimension API.
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...
PCB_IO(const wxString &aName)
Definition pcb_io.h:342
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:62
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
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...