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 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_EAGLE_H_
22#define PCB_IO_EAGLE_H_
23
25#include <pcb_io/pcb_io.h>
26#include <pcb_io/pcb_io_mgr.h>
28
29#include <eda_units.h>
30#include <layer_ids.h>
31#include <lset.h>
32#include <netclass.h>
33
34#include <map>
35#include <tuple>
36#include <wx/xml/xml.h>
37
38class PAD;
39class PCB_TEXT;
40class ZONE;
41
42typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP;
43typedef std::vector<ZONE*> ZONES;
44typedef std::map<wxString, ENET> NET_MAP;
45typedef NET_MAP::const_iterator NET_MAP_CITER;
46
47
49struct ERULES
50{
52 psElongationLong ( 100 ),
54
55 mvStopFrame ( 1.0 ),
56 mvCreamFrame ( 0.0 ),
57 mlMinStopFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 4.0 ) ),
58 mlMaxStopFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 4.0 ) ),
59 mlMinCreamFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
60 mlMaxCreamFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
61
62 psTop ( EPAD::UNDEF ),
63 psBottom ( EPAD::UNDEF ),
64 psFirst ( EPAD::UNDEF ),
65
66 srRoundness ( 0.0 ),
67 srMinRoundness ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
68 srMaxRoundness ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
69
70 rvPadTop ( 0.25 ),
71 // rvPadBottom ( 0.25 ),
72 rlMinPadTop ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 10 ) ),
73 rlMaxPadTop ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 20 ) ),
74 rlMinPadInner ( 0.0 ),
75 rlMaxPadInner ( 0.0 ),
76 rlMinPadBottom ( 0.0 ),
77 rlMaxPadBottom ( 0.0 ),
78
79 rvViaOuter ( 0.25 ),
80 rlMinViaOuter ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 10 ) ),
81 rlMaxViaOuter ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 20 ) ),
82 mdWireWire ( 0 )
83 {}
84
85 void parse( wxXmlNode* aRules, std::function<void()> aCheckpoint );
86
90
92
95
102
103 int psTop;
106
107 double srRoundness;
108
111
114
115 double rvPadTop;
116 // double rvPadBottom; ///< bottom pad size as percent of drill size
117
118 double rlMinPadTop;
119 double rlMaxPadTop;
124
125 double rvViaOuter;
128 double mdWireWire;
129};
130
131
137{
138public:
140 {
141 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle PCB files (6.x XML and pre-v6 binary)" ),
142 { "brd" } );
143 }
144
146 {
147 return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML library files" ), { "lbr" } );
148 }
149
150 bool CanReadBoard( const wxString& aFileName ) const override;
151 bool CanReadLibrary( const wxString& aFileName ) const override;
152 bool CanReadFootprint( const wxString& aFileName ) const override;
153
154 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
155 wxString GetImportedDesignRules() const override { return m_importedDesignRules; }
156
157 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
158 bool aBestEfforts, const std::map<std::string, UTF8>* aProperties = nullptr) override;
159
160 std::unique_ptr<FOOTPRINT> FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
161 bool aKeepUUID = false,
162 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
163
164 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
165
166 bool IsLibraryWritable( const wxString& aLibraryPath ) override
167 {
168 return false; // until someone writes others like FootprintSave(), etc.
169 }
170
171 typedef int BIU;
172
173 PCB_IO_EAGLE();
175
176protected:
177 void loadBoard( const wxString& aFileName, BOARD& aBoard, bool aIsNewLoad,
178 const std::map<std::string, UTF8>* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
179
190 std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
191 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
192
193private:
195 void init( const std::map<std::string, UTF8>* aProperties );
196
197 bool checkHeader( const wxString& aFileName ) const;
198
199 void checkpoint();
200
201 void clear_cu_map();
202
204 int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
205 int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
206
208 VECTOR2I kicad_fontsize( const ECOORD& d, int aTextThickness ) const;
209
221 void mapEagleLayersToKicad( bool aIsLibraryCache = false );
222
224 PCB_LAYER_ID kicad_layer( int aLayer ) const;
225
243 std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer,
244 bool aIsLibraryCache = false ) const;
245
247 const wxString& eagle_layer_name( int aLayer ) const;
248
250 int eagle_layer_id( const wxString& aLayerName ) const;
251
252 void setKeepoutSettingsToZone( ZONE* aZone, int aLayer ) const;
253
255 void cacheLib( const wxString& aLibraryPath );
256
258 static wxDateTime getModificationTime( const wxString& aPath );
259
261 int getMinimumCopperLayerCount() const;
262
263 // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
264
265 void loadAllSections( wxXmlNode* aDocument );
266 void loadDesignRules( wxXmlNode* aDesignRules );
267 void loadLayerDefs( wxXmlNode* aLayers );
268 void loadPlain( wxXmlNode* aPlain );
269 void loadClasses( wxXmlNode* aClasses );
270 void loadSignals( wxXmlNode* aSignals );
271
282 void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
283
284 void loadLibraries( wxXmlNode* aLibs );
285 void loadElements( wxXmlNode* aElements );
286
292 ZONE* loadPolygon( wxXmlNode* aPolyNode );
293
294 void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
295 const EATTR* aValueAttr );
296
297 void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, PCB_TEXT* aFPText, const EATTR* aAttr,
298 double aTextDefAngle = 0.0, bool aTextDefMirror = false, bool aTextDefSpin = false );
299
300
317 void adjustFootprintForDesignRules( FOOTPRINT* aFootprint );
318
320 void centerBoard();
321
325 FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
326
327 void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
328 void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
329 void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
330 void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
331 void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
332 void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
333
339 void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
340 void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
341
343 void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
344
346 void deleteTemplates();
347
348 typedef std::vector<ELAYER> ELAYERS;
349 typedef ELAYERS::const_iterator EITER;
350
351 int m_cu_map[17];
352 std::map<int, ELAYER> m_eagleLayers;
353 std::map<wxString, int> m_eagleLayersIds;
354 std::map<wxString, PCB_LAYER_ID> m_layer_map;
355
357 std::map<wxString, std::shared_ptr<NETCLASS>> m_classMap;
358 std::map<wxString, wxString> m_boardAttributes;
359
362
366
368
370
371 std::map<wxString, FOOTPRINT*> m_templates;
376
378 unsigned m_doneCount;
380 unsigned m_totalCount;
381
386
387 wxString m_lib_path;
388 long long m_timestamp;
389};
390
391#endif // PCB_IO_EAGLE_H_
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
Plugin class for import plugins that support remappable layers.
Definition pad.h:61
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
std::vector< ELAYER > ELAYERS
void packageSMD(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void loadPlain(wxXmlNode *aPlain)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
int m_min_trace
smallest trace we find on Load(), in BIU.
wxString m_importedDesignRules
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
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.
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().
std::map< wxString, wxString > m_boardAttributes
Board attribute values by name.
unsigned m_totalCount
for progress reporting
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.
std::map< wxString, FOOTPRINT * > m_templates
is part of a FOOTPRINT factory that operates using copy construction.
wxString GetImportedDesignRules() const override
Return custom DRC rules generated while importing the most recent board.
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
void mapEagleLayersToKicad(bool aIsLibraryCache=false)
Generate mapping between Eagle and KiCad layers.
std::map< wxString, std::shared_ptr< NETCLASS > > m_classMap
Eagle class number to KiCad netclass.
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...
std::unique_ptr< 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...
void adjustFootprintForDesignRules(FOOTPRINT *aFootprint)
Reconcile all required footprint design rule adjustments.
void loadLibraries(wxXmlNode *aLibs)
void init(const std::map< std::string, UTF8 > *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
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
Check 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
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
ELAYERS::const_iterator EITER
long long m_timestamp
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
void loadClasses(wxXmlNode *aClasses)
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
wxString m_customRules
NET_MAP m_pads_to_nets
net list
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
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void centerBoard()
move the BOARD into the center of the page
unsigned m_lastProgressCount
int m_cu_map[17]
map eagle to KiCad, cu layers only.
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.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
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.
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)
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
void loadLayerDefs(wxXmlNode *aLayers)
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.
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Return board file description for the PCB_IO.
void setKeepoutSettingsToZone(ZONE *aZone, int aLayer) const
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Handles common pad properties.
void deleteTemplates()
Deletes the footprint templates list.
int kicad_x(const ECOORD &x) const
void loadDesignRules(wxXmlNode *aDesignRules)
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, PCB_TEXT *aFPText, const EATTR *aAttr, double aTextDefAngle=0.0, bool aTextDefMirror=false, bool aTextDefSpin=false)
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
unsigned m_doneCount
wxString m_lib_path
PCB_IO(const wxString &aName)
Definition pcb_io.h:383
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:63
Keep track of what we are working on within a PTREE.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
std::unordered_map< NET_NAME_CODE_CACHE_KEY, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associate a NET_NAME_CODE_CACHE_KEY with all the subgraphs in that net.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
#define _HKI(x)
Definition page_info.cpp:40
std::vector< ZONE * > ZONES
NET_MAP::const_iterator NET_MAP_CITER
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
std::map< wxString, ENET > NET_MAP
Parse an Eagle "attribute" XML element.
int ToPcbUnits() const
Eagle element element.
Structure holding common properties for through-hole and SMD pads.
Eagle thru hole pad.
subset of eagle.drawing.board.designrules in the XML document
int psBottom
Shape of the bottom pads.
int psElongationLong
percent over 100%.
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
double srRoundness
corner rounding ratio for SMD pads (percentage)
double rlMaxPadBottom
Maximum bottom layer copper annulus on through hole pads.
double rlMinViaOuter
minimum copper annulus on via
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
int psTop
Shape of the top pads.
double rlMaxViaOuter
maximum copper annulus on via
void parse(wxXmlNode *aRules, std::function< void()> aCheckpoint)
double mdWireWire
wire to wire spacing I presume.
double rvPadTop
top pad size as percent of drill size
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
double rvViaOuter
copper annulus is this percent of via hole
double rlMinPadTop
Minimum top layer copper annulus on through hole pads.
double rlMinPadInner
Minimum inner layer copper annulus on through hole pads.
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
int psElongationOffset
the offset of the hole within the "long" pad.
double rlMaxPadInner
Maximum inner layer copper annulus on through hole pads.
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
double rlMinPadBottom
Minimum bottom layer copper annulus on through hole pads.
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
double rlMaxPadTop
Maximum top layer copper annulus on through hole pads.
int psFirst
Shape of the first pads.
Container that describes file type info.
Definition io_base.h:43
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708