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-2022 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;
133
134 BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
135 const STRING_UTF8_MAP* 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 STRING_UTF8_MAP* aProperties = nullptr) override;
144
145 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
146 bool aKeepUUID = false,
147 const STRING_UTF8_MAP* 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( STRING_UTF8_MAP* 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 STRING_UTF8_MAP* 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 VECTOR2I kicad_fontsize( const ECOORD& d, int aTextThickness ) const;
193
205 void mapEagleLayersToKicad( bool aIsLibraryCache = false );
206
208 PCB_LAYER_ID kicad_layer( int aLayer ) const;
209
227 std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer,
228 bool aIsLibraryCache = false ) const;
229
231 const wxString& eagle_layer_name( int aLayer ) const;
232
234 int eagle_layer_id( const wxString& aLayerName ) const;
235
236 void setKeepoutSettingsToZone( ZONE* aZone, int aLayer ) const;
237
239 void cacheLib( const wxString& aLibraryPath );
240
242 static wxDateTime getModificationTime( const wxString& aPath );
243
245 int getMinimumCopperLayerCount() const;
246
247 // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
248
249 void loadAllSections( wxXmlNode* aDocument );
250 void loadDesignRules( wxXmlNode* aDesignRules );
251 void loadLayerDefs( wxXmlNode* aLayers );
252 void loadPlain( wxXmlNode* aPlain );
253 void loadClasses( wxXmlNode* aClasses );
254 void loadSignals( wxXmlNode* aSignals );
255
266 void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
267
268 void loadLibraries( wxXmlNode* aLibs );
269 void loadElements( wxXmlNode* aElements );
270
276 ZONE* loadPolygon( wxXmlNode* aPolyNode );
277
278 void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
279 const EATTR* aValueAttr );
280
281 void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, PCB_TEXT* aFPText,
282 const EATTR* aAttr );
283
284
286 void centerBoard();
287
291 FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
292
293 void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
294 void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
295 void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
296 void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
297 void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
298 void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
299
305 void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
306 void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
307
309 void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
310
312 void deleteTemplates();
313
314 typedef std::vector<ELAYER> ELAYERS;
315 typedef ELAYERS::const_iterator EITER;
316
317 int m_cu_map[17];
318 std::map<int, ELAYER> m_eagleLayers;
319 std::map<wxString, int> m_eagleLayersIds;
320 std::map<wxString, PCB_LAYER_ID> m_layer_map;
321
323 std::map<wxString, std::shared_ptr<NETCLASS>> m_classMap;
324
326
330
332
334
335 std::map<wxString, FOOTPRINT*> m_templates;
340
343
345 unsigned m_doneCount;
347 unsigned m_totalCount;
348
353
354 wxString m_lib_path;
355 wxDateTime m_mod_time;
356};
357
358#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:270
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:331
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:328
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()
std::map< wxString, FOOTPRINT * > m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:335
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
wxString m_lib_path
Definition: eagle_plugin.h:354
unsigned m_totalCount
for progress reporting
Definition: eagle_plugin.h:347
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:327
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void setKeepoutSettingsToZone(ZONE *aZone, int aLayer) const
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:352
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:345
wxDateTime m_mod_time
Definition: eagle_plugin.h:355
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:314
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:325
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: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:333
void loadLibraries(wxXmlNode *aLibs)
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
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:349
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:317
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:351
unsigned m_lastProgressCount
Definition: eagle_plugin.h:346
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 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:320
VECTOR2I kicad_fontsize(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
void loadSignals(wxXmlNode *aSignals)
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:341
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:344
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:318
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:315
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:319
std::map< wxString, std::shared_ptr< NETCLASS > > m_classMap
Definition: eagle_plugin.h:323
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 * Load(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 ...
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:342
void loadElements(wxXmlNode *aElements)
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:350
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:64
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:116
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
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:598
int ToPcbUnits() const
Definition: eagle_parser.h:435
Eagle element element.
Definition: eagle_parser.h:814
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:697
Eagle thru hole pad.
Definition: eagle_parser.h:710
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