KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eagle_plugin.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 EAGLE_PLUGIN_H
26#define EAGLE_PLUGIN_H
27
28#include <eda_units.h>
29#include <io_mgr.h>
30#include <layer_ids.h>
31#include <netclass.h>
34
35#include <map>
36#include <tuple>
37#include <wx/xml/xml.h>
38
39class PAD;
40class PCB_TEXT;
41class ZONE;
42
43typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP;
44typedef std::vector<ZONE*> ZONES;
45typedef std::map<wxString, ENET> NET_MAP;
46typedef NET_MAP::const_iterator NET_MAP_CITER;
47
48
50struct ERULES
51{
53 psElongationLong ( 100 ),
55
56 mvStopFrame ( 1.0 ),
57 mvCreamFrame ( 0.0 ),
58 mlMinStopFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 4.0 ) ),
59 mlMaxStopFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 4.0 ) ),
60 mlMinCreamFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
61 mlMaxCreamFrame ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
62
63 psTop ( EPAD::UNDEF ),
64 psBottom ( EPAD::UNDEF ),
65 psFirst ( EPAD::UNDEF ),
66
67 srRoundness ( 0.0 ),
68 srMinRoundness ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
69 srMaxRoundness ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 0.0 ) ),
70
71 rvPadTop ( 0.25 ),
72 // rvPadBottom ( 0.25 ),
73 rlMinPadTop ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 10 ) ),
74 rlMaxPadTop ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 20 ) ),
75
76 rvViaOuter ( 0.25 ),
77 rlMinViaOuter ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 10 ) ),
78 rlMaxViaOuter ( EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 20 ) ),
79 mdWireWire ( 0 )
80 {}
81
82 void parse( wxXmlNode* aRules, std::function<void()> aCheckpoint );
83
87
89
92
99
100 int psTop;
103
104 double srRoundness;
105
108
111
112 double rvPadTop;
113 // double rvPadBottom; ///< bottom pad size as percent of drill size
114
115 double rlMinPadTop;
116 double rlMaxPadTop;
117
118 double rvViaOuter;
121 double mdWireWire;
122};
123
124
130{
131public:
132 const wxString PluginName() const override { return wxT( "Eagle" ); }
133
135 {
136 return PLUGIN_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
137 }
138
140 {
141 return PLUGIN_FILE_DESC( _HKI( "Eagle ver. 6.x XML library files" ), { "lbr" } );
142 }
143
145
146 bool CanReadBoard( const wxString& aFileName ) const override;
147 bool CanReadFootprintLib( const wxString& aFileName ) const override;
148 bool CanReadFootprint( const wxString& aFileName ) const override;
149
150 BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
151 const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr,
152 PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
153
154 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
155
156 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
157 bool aBestEfforts, const STRING_UTF8_MAP* aProperties = nullptr) override;
158
159 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
160 bool aKeepUUID = false,
161 const STRING_UTF8_MAP* aProperties = nullptr ) override;
162
163 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
164 {
165 return getModificationTime( aLibraryPath ).GetValue().GetValue();
166 }
167
168 bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
169 {
170 return false; // until someone writes others like FootprintSave(), etc.
171 }
172
173 void FootprintLibOptions( STRING_UTF8_MAP* aProperties ) const override;
174
175 typedef int BIU;
176
177 EAGLE_PLUGIN();
179
190 std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
191 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
192
193private:
195 void init( const STRING_UTF8_MAP* 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,
298 const EATTR* aAttr );
299
300
302 void centerBoard();
303
307 FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
308
309 void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
310 void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
311 void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
312 void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
313 void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
314 void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
315
321 void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
322 void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
323
325 void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
326
328 void deleteTemplates();
329
330 typedef std::vector<ELAYER> ELAYERS;
331 typedef ELAYERS::const_iterator EITER;
332
333 int m_cu_map[17];
334 std::map<int, ELAYER> m_eagleLayers;
335 std::map<wxString, int> m_eagleLayersIds;
336 std::map<wxString, PCB_LAYER_ID> m_layer_map;
337
339 std::map<wxString, std::shared_ptr<NETCLASS>> m_classMap;
340
342
346
348
350
351 std::map<wxString, FOOTPRINT*> m_templates;
356
359
361 unsigned m_doneCount;
363 unsigned m_totalCount;
364
369
370 wxString m_lib_path;
371 wxDateTime m_mod_time;
372};
373
374#endif // EAGLE_PLUGIN_H
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API or a portion o...
Definition: eagle_plugin.h:130
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
void FootprintLibOptions(STRING_UTF8_MAP *aProperties) const override
Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions.
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: eagle_plugin.h:347
FOOTPRINT * makeFootprint(wxXmlNode *aPackage, const wxString &aPkgName)
Create a FOOTPRINT from an Eagle package.
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:344
void loadPlain(wxXmlNode *aPlain)
void packageCircle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void packageSMD(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Handles common pad properties.
void clear_cu_map()
PLUGIN_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PLUGIN.
Definition: eagle_plugin.h:134
std::map< wxString, FOOTPRINT * > m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:351
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
wxString m_lib_path
Definition: eagle_plugin.h:370
unsigned m_totalCount
for progress reporting
Definition: eagle_plugin.h:363
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:343
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void setKeepoutSettingsToZone(ZONE *aZone, int aLayer) const
PLUGIN_FILE_DESC GetFootprintFileDesc() const override
Returns footprint file description for the PLUGIN.
Definition: eagle_plugin.h:144
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:368
void loadAllSections(wxXmlNode *aDocument)
void deleteTemplates()
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 orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
unsigned m_doneCount
Definition: eagle_plugin.h:361
wxDateTime m_mod_time
Definition: eagle_plugin.h:371
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:330
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...
wxString m_customRules
Definition: eagle_plugin.h:341
void mapEagleLayersToKicad(bool aIsLibraryCache=false)
Generate mapping between Eagle and KiCad layers.
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
Definition: eagle_plugin.h:163
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:205
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:349
void loadLibraries(wxXmlNode *aLibs)
void init(const STRING_UTF8_MAP *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
void packageText(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:365
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:204
bool CanReadFootprint(const wxString &aFileName) const override
Checks if this PLUGIN can read a footprint from specified file or directory.
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
bool CanReadFootprintLib(const wxString &aFileName) const override
Checks if this PLUGIN can read footprint library from specified file or directory.
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PLUGIN can read the specified board file.
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:333
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 loadLayerDefs(wxXmlNode *aLayers)
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...
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:367
unsigned m_lastProgressCount
Definition: eagle_plugin.h:362
void centerBoard()
move the BOARD into the center of the page
void packagePad(FOOTPRINT *aFootprint, wxXmlNode *aTree)
ZONE * loadPolygon(wxXmlNode *aPolyNode)
Load a copper or keepout polygon and adds it to the board.
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: eagle_plugin.h:168
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, PCB_TEXT *aFPText, const EATTR *aAttr)
void loadDesignRules(wxXmlNode *aDesignRules)
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:336
VECTOR2I kicad_fontsize(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
PLUGIN_FILE_DESC GetFootprintLibDesc() const override
Returns footprint library description for the PLUGIN.
Definition: eagle_plugin.h:139
void loadSignals(wxXmlNode *aSignals)
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:357
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
int getMinimumCopperLayerCount() const
Determines the minimum copper layer stackup count that includes all mapped layers.
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
Definition: eagle_plugin.h:360
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:334
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:331
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
Definition: eagle_plugin.h:132
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:335
std::map< wxString, std::shared_ptr< NETCLASS > > m_classMap
Definition: eagle_plugin.h:339
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void loadClasses(wxXmlNode *aClasses)
int eagle_layer_id(const wxString &aLayerName) const
Get Eagle layer number by its name.
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:358
void loadElements(wxXmlNode *aElements)
bool checkHeader(const wxString &aFileName) const
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:366
Plugin class for import plugins that support remappable layers.
Definition: pad.h:59
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.
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)
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:44
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:46
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_plugin.h:43
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:45
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
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: eagle_plugin.h:51
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:101
int psElongationLong
Definition: eagle_plugin.h:86
double mvStopFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:91
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:104
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:119
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:98
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:97
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:100
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:120
void parse(wxXmlNode *aRules, std::function< void()> aCheckpoint)
percent over 100%.
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:121
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:112
int srMaxRoundness
Definition: eagle_plugin.h:110
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:118
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:115
double mvCreamFrame
Definition: eagle_plugin.h:94
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:88
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:95
int srMinRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:107
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:96
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:116
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:102
Container that describes file type info.