KiCad PCB EDA Suite
Loading...
Searching...
No Matches
legacy_plugin.h
Go to the documentation of this file.
1#ifndef LEGACY_PLUGIN_H_
2#define LEGACY_PLUGIN_H_
3
4/*
5 * This program source code file is part of KiCad, a free EDA CAD application.
6 *
7 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
8 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#include <io_mgr.h>
29#include <richio.h>
30#include <string>
31#include <layer_ids.h>
32#include <memory>
33#include <geometry/eda_angle.h>
34
35
36// FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
37// a footprint library. A few variants may have been used, and so we can only be
38// sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
39
40#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
41#define FOOTPRINT_LIBRARY_HEADER_CNT 18
42
43class PCB_TARGET;
44class FOOTPRINT;
45class NETCLASS;
46class ZONE;
48class NETINFO_ITEM;
49class PCB_TEXT;
50class PAD;
51struct LP_CACHE;
52
53
59class LEGACY_PLUGIN : public PLUGIN
60{
61 friend struct LP_CACHE;
62
63public:
66
67 const wxString PluginName() const override
68 {
69 return wxT( "KiCad-Legacy" );
70 }
71
73 {
74 return PLUGIN_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
75 }
76
78 {
79 return PLUGIN_FILE_DESC( _HKI( "Legacy footprint library files" ), { "mod", "emp" } );
80 }
81
83
84 bool CanReadBoard( const wxString& aFileName ) const override;
85 bool CanReadFootprint( const wxString& aFileName ) const override;
86
87 BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
88 const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr,
89 PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
90
91 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
92 bool aBestEfforts,
93 const STRING_UTF8_MAP* aProperties = nullptr ) override;
94
95 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
96 bool aKeepUUID = false,
97 const STRING_UTF8_MAP* aProperties = nullptr ) override;
98
99 bool FootprintLibDelete( const wxString& aLibraryPath,
100 const STRING_UTF8_MAP* aProperties = nullptr ) override;
101
102 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
103
104 bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;
105
106 typedef int BIU;
107
108 void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
109
110 // return the new .kicad_pcb layer id from the old (legacy) layer id
111 static PCB_LAYER_ID leg_layer2new( int cu_count, int aLayerNum );
112
113 static LSET leg_mask2new( int cu_count, unsigned aMask );
114
115protected:
117 void init( const STRING_UTF8_MAP* aProperties );
118
119 void checkpoint();
120
123 inline int getNetCode( int aNetCode )
124 {
125 if( (unsigned int) aNetCode < m_netCodes.size() )
126 return m_netCodes[aNetCode];
127
128 return aNetCode;
129 }
130
142 BIU biuParse( const char* aValue, const char** nptrptr = nullptr );
143
152 EDA_ANGLE degParse( const char* aValue, const char** nptrptr = nullptr );
153
154 static int getVersion( LINE_READER* aReader );
155
156 void loadAllSections( bool doAppend );
157
158
159 void loadGENERAL();
160 void loadSETUP();
161 void loadSHEET();
162
163 void load3D( FOOTPRINT* aFootprint );
164 void loadPAD( FOOTPRINT* aFootprint );
165 void loadMODULE_TEXT( PCB_TEXT* aText );
166 void loadFP_SHAPE( FOOTPRINT* aFootprint );
167
168 void loadPCB_LINE();
169 void loadNETINFO_ITEM();
170 void loadPCB_TEXT();
171 void loadNETCLASS();
172 void loadFOOTPRINT( FOOTPRINT* aFootprint );
173
180 void loadTrackList( int aStructType );
181
182 void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
183 void loadDIMENSION(); // "$COTATION"
184 void loadPCB_TARGET(); // "$PCB_TARGET"
185
187 void cacheLib( const wxString& aLibraryPath );
188
189protected:
191
192 wxString m_error;
198 unsigned m_lineCount;
199
201 FILE* m_fp;
202
203 wxString m_field;
207
208 std::vector<int> m_netCodes;
209
210 double biuToDisk;
212
213 double diskToBiu;
215};
216
217#endif // LEGACY_PLUGIN_H_
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
A PLUGIN derivation which could possibly be put into a DLL/DSO.
Definition: legacy_plugin.h:60
unsigned m_lastProgressLine
int m_loading_format_version
which BOARD_FORMAT_VERSION am I Load()ing?
int getNetCode(int aNetCode)
bool CanReadFootprint(const wxString &aFileName) const override
Checks if this PLUGIN can read a footprint from specified file or directory.
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...
static LSET leg_mask2new(int cu_count, unsigned aMask)
void loadFP_SHAPE(FOOTPRINT *aFootprint)
void init(const STRING_UTF8_MAP *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
double diskToBiu
convert from disk engineering units to BIUs
PLUGIN_FILE_DESC GetFootprintLibDesc() const override
Returns footprint library description for the PLUGIN.
Definition: legacy_plugin.h:77
void loadTrackList(int aStructType)
Read a list of segments (Tracks and Vias, or Segzones)
bool m_showLegacySegmentZoneWarning
wxString m_field
reused to stuff FOOTPRINT fields.
static int getVersion(LINE_READER *aReader)
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
Definition: legacy_plugin.h:67
static PCB_LAYER_ID leg_layer2new(int cu_count, int aLayerNum)
PROGRESS_REPORTER * m_progressReporter
may be NULL, no ownership
double biuToDisk
convert from BIUs to disk engineering units with this scale factor
unsigned m_lineCount
for progress reporting
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 loadFOOTPRINT(FOOTPRINT *aFootprint)
PLUGIN_FILE_DESC GetFootprintFileDesc() const override
Returns footprint file description for the PLUGIN.
Definition: legacy_plugin.h:82
void loadPAD(FOOTPRINT *aFootprint)
void checkpoint()
Converts net code using the mapping table if available, otherwise returns unchanged net code.
FILE * m_fp
no ownership here.
PLUGIN_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PLUGIN.
Definition: legacy_plugin.h:72
void loadAllSections(bool doAppend)
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
bool FootprintLibDelete(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing footprint library and returns true, or if library does not exist returns false,...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
void load3D(FOOTPRINT *aFootprint)
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.
LP_CACHE * m_cache
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
void loadZONE_CONTAINER()
wxString m_error
for throwing exceptions
std::vector< int > m_netCodes
net codes mapping for boards being loaded
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership,
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PLUGIN can read the specified board file.
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 PL...
LINE_READER * m_reader
no ownership here.
void SetReader(LINE_READER *aReader)
void loadMODULE_TEXT(PCB_TEXT *aText)
void cacheLib(const wxString &aLibraryPath)
we only cache one footprint library for now, this determines which one.
BOARD * m_board
which BOARD, no ownership here
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:556
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:47
Handle the data for a net.
Definition: netinfo.h:56
Definition: pad.h:58
Abstract dimension API.
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:272
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
LEGACY_PLUGIN::BIU BIU
The footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN, so therefore is private to t...
Container that describes file type info.