KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_eagle.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) 2012-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_EAGLE_H_
26#define PCB_IO_EAGLE_H_
27
29#include <pcb_io/pcb_io.h>
30#include <pcb_io/pcb_io_mgr.h>
32
33#include <eda_units.h>
34#include <layer_ids.h>
35#include <netclass.h>
36
37#include <map>
38#include <tuple>
39#include <wx/xml/xml.h>
40
41class PAD;
42class PCB_TEXT;
43class ZONE;
44
45typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP;
46typedef std::vector<ZONE*> ZONES;
47typedef std::map<wxString, ENET> NET_MAP;
48typedef NET_MAP::const_iterator NET_MAP_CITER;
49
50
52struct ERULES
53{
55 psElongationLong ( 100 ),
57
58 mvStopFrame ( 1.0 ),
59 mvCreamFrame ( 0.0 ),
60 mlMinStopFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 4.0 ) ),
61 mlMaxStopFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 4.0 ) ),
62 mlMinCreamFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
63 mlMaxCreamFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
64
65 psTop ( EPAD::UNDEF ),
66 psBottom ( EPAD::UNDEF ),
67 psFirst ( EPAD::UNDEF ),
68
69 srRoundness ( 0.0 ),
70 srMinRoundness ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
71 srMaxRoundness ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
72
73 rvPadTop ( 0.25 ),
74 // rvPadBottom ( 0.25 ),
75 rlMinPadTop ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 10 ) ),
76 rlMaxPadTop ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 20 ) ),
77
78 rvViaOuter ( 0.25 ),
79 rlMinViaOuter ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 10 ) ),
80 rlMaxViaOuter ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 20 ) ),
81 mdWireWire ( 0 )
82 {}
83
84 void parse( wxXmlNode* aRules, std::function<void()> aCheckpoint );
85
89
91
94
101
102 int psTop;
105
106 double srRoundness;
107
110
113
114 double rvPadTop;
115 // double rvPadBottom; ///< bottom pad size as percent of drill size
116
117 double rlMinPadTop;
118 double rlMaxPadTop;
119
120 double rvViaOuter;
123 double mdWireWire;
124};
125
126
132{
133public:
135 {
136 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
137 }
138
140 {
141 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML library files" ), { "lbr" } );
142 }
143
144 bool CanReadBoard( const wxString& aFileName ) const override;
145 bool CanReadLibrary( const wxString& aFileName ) const override;
146 bool CanReadFootprint( const wxString& aFileName ) const override;
147
148 BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
149 const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
150
151 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
152
153 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
154 bool aBestEfforts, const STRING_UTF8_MAP* aProperties = nullptr) override;
155
156 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
157 bool aKeepUUID = false,
158 const STRING_UTF8_MAP* aProperties = nullptr ) override;
159
160 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
161 {
162 return getModificationTime( aLibraryPath ).GetValue().GetValue();
163 }
164
165 bool IsLibraryWritable( const wxString& aLibraryPath ) override
166 {
167 return false; // until someone writes others like FootprintSave(), etc.
168 }
169
170 typedef int BIU;
171
172 PCB_IO_EAGLE();
174
185 std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
186 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
187
188private:
190 void init( const STRING_UTF8_MAP* aProperties );
191
192 bool checkHeader( const wxString& aFileName ) const;
193
194 void checkpoint();
195
196 void clear_cu_map();
197
199 int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
200 int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
201
203 VECTOR2I kicad_fontsize( const ECOORD& d, int aTextThickness ) const;
204
216 void mapEagleLayersToKicad( bool aIsLibraryCache = false );
217
219 PCB_LAYER_ID kicad_layer( int aLayer ) const;
220
238 std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer,
239 bool aIsLibraryCache = false ) const;
240
242 const wxString& eagle_layer_name( int aLayer ) const;
243
245 int eagle_layer_id( const wxString& aLayerName ) const;
246
247 void setKeepoutSettingsToZone( ZONE* aZone, int aLayer ) const;
248
250 void cacheLib( const wxString& aLibraryPath );
251
253 static wxDateTime getModificationTime( const wxString& aPath );
254
256 int getMinimumCopperLayerCount() const;
257
258 // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
259
260 void loadAllSections( wxXmlNode* aDocument );
261 void loadDesignRules( wxXmlNode* aDesignRules );
262 void loadLayerDefs( wxXmlNode* aLayers );
263 void loadPlain( wxXmlNode* aPlain );
264 void loadClasses( wxXmlNode* aClasses );
265 void loadSignals( wxXmlNode* aSignals );
266
277 void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
278
279 void loadLibraries( wxXmlNode* aLibs );
280 void loadElements( wxXmlNode* aElements );
281
287 ZONE* loadPolygon( wxXmlNode* aPolyNode );
288
289 void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
290 const EATTR* aValueAttr );
291
292 void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, PCB_TEXT* aFPText,
293 const EATTR* aAttr );
294
295
297 void centerBoard();
298
302 FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
303
304 void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
305 void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
306 void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
307 void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
308 void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
309 void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
310
316 void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
317 void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
318
320 void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
321
323 void deleteTemplates();
324
325 typedef std::vector<ELAYER> ELAYERS;
326 typedef ELAYERS::const_iterator EITER;
327
328 int m_cu_map[17];
329 std::map<int, ELAYER> m_eagleLayers;
330 std::map<wxString, int> m_eagleLayersIds;
331 std::map<wxString, PCB_LAYER_ID> m_layer_map;
332
334 std::map<wxString, std::shared_ptr<NETCLASS>> m_classMap;
335
337
341
343
345
346 std::map<wxString, FOOTPRINT*> m_templates;
351
353 unsigned m_doneCount;
355 unsigned m_totalCount;
356
361
362 wxString m_lib_path;
363 wxDateTime m_mod_time;
364};
365
366#endif // PCB_IO_EAGLE_H_
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
Plugin class for import plugins that support remappable layers.
Definition: pad.h:59
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew #PLUGIN API or a portion ...
Definition: pcb_io_eagle.h:132
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
Definition: pcb_io_eagle.h:139
std::vector< ELAYER > ELAYERS
Definition: pcb_io_eagle.h:325
void packageSMD(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Handles common pad properties.
void loadPlain(wxXmlNode *aPlain)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: pcb_io_eagle.h:165
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: pcb_io_eagle.h:357
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: pcb_io_eagle.h:331
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, PCB_TEXT *aFPText, const EATTR *aAttr)
VECTOR2I kicad_fontsize(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
bool checkHeader(const wxString &aFileName) const
void loadElements(wxXmlNode *aElements)
FOOTPRINT * makeFootprint(wxXmlNode *aPackage, const wxString &aPkgName)
Create a FOOTPRINT from an Eagle package.
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: pcb_io_eagle.h:358
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: pcb_io_eagle.h:339
unsigned m_totalCount
for progress reporting
Definition: pcb_io_eagle.h:355
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 cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: pcb_io_eagle.h:342
std::map< wxString, FOOTPRINT * > m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: pcb_io_eagle.h:346
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: pcb_io_eagle.h:330
void mapEagleLayersToKicad(bool aIsLibraryCache=false)
Generate mapping between Eagle and KiCad layers.
std::map< wxString, std::shared_ptr< NETCLASS > > m_classMap
Definition: pcb_io_eagle.h:334
std::tuple< PCB_LAYER_ID, LSET, bool > defaultKicadLayer(int aEagleLayer, bool aIsLibraryCache=false) const
Get the default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer map...
void loadLibraries(wxXmlNode *aLibs)
int eagle_layer_id(const wxString &aLayerName) const
Get Eagle layer number by its name.
void loadAllSections(wxXmlNode *aDocument)
bool CanReadFootprint(const wxString &aFileName) const override
Checks if this PCB_IO can read a footprint from specified file or directory.
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
ELAYERS::const_iterator EITER
Definition: pcb_io_eagle.h:326
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: pcb_io_eagle.h:199
void loadClasses(wxXmlNode *aClasses)
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: pcb_io_eagle.h:329
wxString m_customRules
Definition: pcb_io_eagle.h:336
NET_MAP m_pads_to_nets
net list
Definition: pcb_io_eagle.h:344
void packageText(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
int getMinimumCopperLayerCount() const
Determines the minimum copper layer stackup count that includes all mapped layers.
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
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...
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void centerBoard()
move the BOARD into the center of the page
unsigned m_lastProgressCount
Definition: pcb_io_eagle.h:354
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: pcb_io_eagle.h:328
ZONE * loadPolygon(wxXmlNode *aPolyNode)
Load a copper or keepout polygon and adds it to the board.
int m_min_via
smallest via we find on Load(), in BIU.
Definition: pcb_io_eagle.h:359
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
void clear_cu_map()
void packageCircle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
void packagePad(FOOTPRINT *aFootprint, wxXmlNode *aTree)
void loadSignals(wxXmlNode *aSignals)
ERULES * m_rules
Eagle design rules.
Definition: pcb_io_eagle.h:338
wxDateTime m_mod_time
Definition: pcb_io_eagle.h:363
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
Definition: pcb_io_eagle.h:160
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: pcb_io_eagle.h:360
void loadLayerDefs(wxXmlNode *aLayers)
void init(const STRING_UTF8_MAP *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
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 ...
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
Definition: pcb_io_eagle.h:134
void setKeepoutSettingsToZone(ZONE *aZone, int aLayer) const
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
void deleteTemplates()
int kicad_x(const ECOORD &x) const
Definition: pcb_io_eagle.h:200
void loadDesignRules(wxXmlNode *aDesignRules)
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
Definition: pcb_io_eagle.h:352
unsigned m_doneCount
Definition: pcb_io_eagle.h:353
wxString m_lib_path
Definition: pcb_io_eagle.h:362
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.
Keep track of what we are working on within a PTREE.
Definition: eagle_parser.h:119
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
std::vector< ZONE * > ZONES
Definition: pcb_io_eagle.h:46
NET_MAP::const_iterator NET_MAP_CITER
Definition: pcb_io_eagle.h:48
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: pcb_io_eagle.h:45
std::map< wxString, ENET > NET_MAP
Definition: pcb_io_eagle.h:47
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:601
int ToPcbUnits() const
Definition: eagle_parser.h:438
Eagle element element.
Definition: eagle_parser.h:817
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:700
Eagle thru hole pad.
Definition: eagle_parser.h:713
subset of eagle.drawing.board.designrules in the XML document
Definition: pcb_io_eagle.h:53
int psBottom
Shape of the bottom pads.
Definition: pcb_io_eagle.h:103
int psElongationLong
Definition: pcb_io_eagle.h:88
double mvStopFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: pcb_io_eagle.h:93
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: pcb_io_eagle.h:106
double rlMinViaOuter
minimum copper annulus on via
Definition: pcb_io_eagle.h:121
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: pcb_io_eagle.h:100
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: pcb_io_eagle.h:99
int psTop
Shape of the top pads.
Definition: pcb_io_eagle.h:102
double rlMaxViaOuter
maximum copper annulus on via
Definition: pcb_io_eagle.h:122
void parse(wxXmlNode *aRules, std::function< void()> aCheckpoint)
percent over 100%.
double mdWireWire
wire to wire spacing I presume.
Definition: pcb_io_eagle.h:123
double rvPadTop
top pad size as percent of drill size
Definition: pcb_io_eagle.h:114
int srMaxRoundness
Definition: pcb_io_eagle.h:112
double rvViaOuter
copper annulus is this percent of via hole
Definition: pcb_io_eagle.h:120
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: pcb_io_eagle.h:117
double mvCreamFrame
Definition: pcb_io_eagle.h:96
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: pcb_io_eagle.h:90
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: pcb_io_eagle.h:97
int srMinRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: pcb_io_eagle.h:109
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: pcb_io_eagle.h:98
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: pcb_io_eagle.h:118
int psFirst
Shape of the first pads.
Definition: pcb_io_eagle.h:104
Container that describes file type info.
Definition: io_base.h:39