KiCad PCB EDA Suite
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-2021 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 <convert_to_biu.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 FP_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 ( Mils2iu( 4.0 ) ),
59 mlMaxStopFrame ( Mils2iu( 4.0 ) ),
60 mlMinCreamFrame ( Mils2iu( 0.0 ) ),
61 mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
62
63 psTop ( EPAD::UNDEF ),
64 psBottom ( EPAD::UNDEF ),
65 psFirst ( EPAD::UNDEF ),
66
67 srRoundness ( 0.0 ),
68 srMinRoundness ( Mils2iu( 0.0 ) ),
69 srMaxRoundness ( Mils2iu( 0.0 ) ),
70
71 rvPadTop ( 0.25 ),
72 // rvPadBottom ( 0.25 ),
73 rlMinPadTop ( Mils2iu( 10 ) ),
74 rlMaxPadTop ( Mils2iu( 20 ) ),
75
76 rvViaOuter ( 0.25 ),
77 rlMinViaOuter ( Mils2iu( 10 ) ),
78 rlMaxViaOuter ( Mils2iu( 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;
133
134 BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
135 const PROPERTIES* aProperties = nullptr, PROJECT* aProject = nullptr,
136 PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
137
138 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
139
140 const wxString GetFileExtension() const override;
141
142 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
143 bool aBestEfforts, const PROPERTIES* aProperties = nullptr) override;
144
145 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
146 bool aKeepUUID = false,
147 const PROPERTIES* aProperties = nullptr ) override;
148
149 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
150 {
151 return getModificationTime( aLibraryPath ).GetValue().GetValue();
152 }
153
154 bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
155 {
156 return false; // until someone writes others like FootprintSave(), etc.
157 }
158
159 void FootprintLibOptions( PROPERTIES* aProperties ) const override;
160
161 typedef int BIU;
162
163 EAGLE_PLUGIN();
165
176 std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
177 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
178
179private:
181 void init( const PROPERTIES* aProperties );
182
183 void checkpoint();
184
185 void clear_cu_map();
186
188 int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
189 int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
190
192 wxSize kicad_fontz( const ECOORD& d, int aTextThickness ) const;
193
196
198 PCB_LAYER_ID kicad_layer( int aLayer ) const;
199
202 std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer ) const;
203
205 const wxString& eagle_layer_name( int aLayer ) const;
206
208 int eagle_layer_id( const wxString& aLayerName ) const;
209
211 void cacheLib( const wxString& aLibraryPath );
212
214 static wxDateTime getModificationTime( const wxString& aPath );
215
216 // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
217
218 void loadAllSections( wxXmlNode* aDocument );
219 void loadDesignRules( wxXmlNode* aDesignRules );
220 void loadLayerDefs( wxXmlNode* aLayers );
221 void loadPlain( wxXmlNode* aPlain );
222 void loadClasses( wxXmlNode* aClasses );
223 void loadSignals( wxXmlNode* aSignals );
224
235 void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
236
237 void loadLibraries( wxXmlNode* aLibs );
238 void loadElements( wxXmlNode* aElements );
239
245 ZONE* loadPolygon( wxXmlNode* aPolyNode );
246
247 void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
248 const EATTR* aValueAttr );
249
250 void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText,
251 const EATTR* aAttr );
252
253
255 void centerBoard();
256
260 FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
261
262 void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
263 void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
264 void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
265 void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
266 void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
267 void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
268
274 void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
275 void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
276
278 void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
279
281 void deleteTemplates();
282
283 typedef std::vector<ELAYER> ELAYERS;
284 typedef ELAYERS::const_iterator EITER;
285
286 int m_cu_map[17];
287 std::map<int, ELAYER> m_eagleLayers;
288 std::map<wxString, int> m_eagleLayersIds;
289 std::map<wxString, PCB_LAYER_ID> m_layer_map;
290
291 std::map<wxString, NETCLASSPTR> m_classMap;
293
297
299
301
306
309
311 unsigned m_doneCount;
313 unsigned m_totalCount;
314
319
320 wxString m_lib_path;
321 wxDateTime m_mod_time;
322};
323
324#endif // EAGLE_PLUGIN_H
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:240
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(PROPERTIES *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:298
void mapEagleLayersToKicad()
Generate mapping between Eagle na KiCad layers.
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:295
void loadPlain(wxXmlNode *aPlain)
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
void packageCircle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, FP_TEXT *aFPText, const EATTR *aAttr)
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()
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
wxString m_lib_path
Definition: eagle_plugin.h:320
unsigned m_totalCount
for progress reporting
Definition: eagle_plugin.h:313
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:294
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:302
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *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 ...
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:318
void loadAllSections(wxXmlNode *aDocument)
void deleteTemplates()
void orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
unsigned m_doneCount
Definition: eagle_plugin.h:311
wxDateTime m_mod_time
Definition: eagle_plugin.h:321
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:283
std::tuple< PCB_LAYER_ID, LSET, bool > defaultKicadLayer(int aEagleLayer) const
Get default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer mapping...
wxString m_customRules
Definition: eagle_plugin.h:292
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:307
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
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:149
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:189
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:300
void loadLibraries(wxXmlNode *aLibs)
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
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:315
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:188
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:286
std::map< wxString, NETCLASSPTR > m_classMap
Eagle class number to KiCad netclass.
Definition: eagle_plugin.h:291
void loadLayerDefs(wxXmlNode *aLayers)
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:317
unsigned m_lastProgressCount
Definition: eagle_plugin.h:312
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:154
void loadDesignRules(wxXmlNode *aDesignRules)
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:289
void loadSignals(wxXmlNode *aSignals)
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
Definition: eagle_plugin.h:310
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:287
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:284
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:288
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:308
void loadElements(wxXmlNode *aElements)
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:316
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:270
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition: project.h:63
A name/value tuple with unique names and optional values.
Definition: properties.h:34
Keep track of what we are working on within a PTREE.
Definition: eagle_parser.h:111
Handle a list of polygons defining a copper zone.
Definition: zone.h:58
std::unordered_map< NET_NAME_CODE_CACHE_KEY, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associates a NET_CODE_NAME with all the subgraphs in that net.
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:50
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:59
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:593
int ToPcbUnits() const
Definition: eagle_parser.h:430
Eagle element element.
Definition: eagle_parser.h:809
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:692
Eagle thru hole pad.
Definition: eagle_parser.h:705
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