KiCad PCB EDA Suite
Go to the documentation of this file.
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
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 *
20 * or you may search the 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 */
25#ifndef EAGLE_PLUGIN_H
26#define EAGLE_PLUGIN_H
28#include <eda_units.h>
29#include <io_mgr.h>
30#include <layer_ids.h>
31#include <netclass.h>
35#include <map>
36#include <tuple>
37#include <wx/xml/xml.h>
39class PAD;
40class FP_TEXT;
41class ZONE;
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;
50struct ERULES
53 psElongationLong ( 100 ),
56 mvStopFrame ( 1.0 ),
57 mvCreamFrame ( 0.0 ),
63 psTop ( EPAD::UNDEF ),
64 psBottom ( EPAD::UNDEF ),
65 psFirst ( EPAD::UNDEF ),
67 srRoundness ( 0.0 ),
71 rvPadTop ( 0.25 ),
72 // rvPadBottom ( 0.25 ),
76 rvViaOuter ( 0.25 ),
79 mdWireWire ( 0 )
80 {}
82 void parse( wxXmlNode* aRules, std::function<void()> aCheckpoint );
100 int psTop;
104 double srRoundness;
112 double rvPadTop;
113 // double rvPadBottom; ///< bottom pad size as percent of drill size
115 double rlMinPadTop;
116 double rlMaxPadTop;
118 double rvViaOuter;
121 double mdWireWire;
132 const wxString PluginName() const override;
134 BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
135 const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr,
136 PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
138 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
140 const wxString GetFileExtension() const override;
142 void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
143 bool aBestEfforts, const STRING_UTF8_MAP* aProperties = nullptr) override;
145 FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
146 bool aKeepUUID = false,
147 const STRING_UTF8_MAP* aProperties = nullptr ) override;
149 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
150 {
151 return getModificationTime( aLibraryPath ).GetValue().GetValue();
152 }
154 bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
155 {
156 return false; // until someone writes others like FootprintSave(), etc.
157 }
159 void FootprintLibOptions( STRING_UTF8_MAP* aProperties ) const override;
161 typedef int BIU;
176 std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
177 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
181 void init( const STRING_UTF8_MAP* aProperties );
183 void checkpoint();
185 void clear_cu_map();
188 int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
189 int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
192 wxSize kicad_fontz( const ECOORD& d, int aTextThickness ) const;
205 void mapEagleLayersToKicad( bool aIsLibraryCache = false );
208 PCB_LAYER_ID kicad_layer( int aLayer ) const;
227 std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer,
228 bool aIsLibraryCache = false ) const;
231 const wxString& eagle_layer_name( int aLayer ) const;
234 int eagle_layer_id( const wxString& aLayerName ) const;
237 void cacheLib( const wxString& aLibraryPath );
240 static wxDateTime getModificationTime( const wxString& aPath );
242 // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
244 void loadAllSections( wxXmlNode* aDocument );
245 void loadDesignRules( wxXmlNode* aDesignRules );
246 void loadLayerDefs( wxXmlNode* aLayers );
247 void loadPlain( wxXmlNode* aPlain );
248 void loadClasses( wxXmlNode* aClasses );
249 void loadSignals( wxXmlNode* aSignals );
261 void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
263 void loadLibraries( wxXmlNode* aLibs );
264 void loadElements( wxXmlNode* aElements );
271 ZONE* loadPolygon( wxXmlNode* aPolyNode );
273 void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
274 const EATTR* aValueAttr );
276 void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText,
277 const EATTR* aAttr );
281 void centerBoard();
286 FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
288 void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
289 void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
290 void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
291 void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
292 void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
293 void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
300 void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
301 void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
304 void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
307 void deleteTemplates();
309 typedef std::vector<ELAYER> ELAYERS;
310 typedef ELAYERS::const_iterator EITER;
312 int m_cu_map[17];
313 std::map<int, ELAYER> m_eagleLayers;
314 std::map<wxString, int> m_eagleLayersIds;
315 std::map<wxString, PCB_LAYER_ID> m_layer_map;
318 std::map<wxString, std::shared_ptr<NETCLASS>> m_classMap;
339 unsigned m_doneCount;
341 unsigned m_totalCount;
348 wxString m_lib_path;
349 wxDateTime m_mod_time;
352#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:265
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:326
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:323
void loadPlain(wxXmlNode *aPlain)
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:348
unsigned m_totalCount
for progress reporting
Definition: eagle_plugin.h:341
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:322
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:330
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:346
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:339
wxDateTime m_mod_time
Definition: eagle_plugin.h:349
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:309
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:320
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 *....
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
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:328
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:343
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:312
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:345
unsigned m_lastProgressCount
Definition: eagle_plugin.h:340
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:315
void loadSignals(wxXmlNode *aSignals)
const STRING_UTF8_MAP * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:335
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
Definition: eagle_plugin.h:338
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:313
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:310
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:314
std::map< wxString, std::shared_ptr< NETCLASS > > m_classMap
Definition: eagle_plugin.h:318
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:336
void loadElements(wxXmlNode *aElements)
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:344
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.
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:57
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
A quick note on layer IDs:
Definition: layer_ids.h:59
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
Definition: eda_units.h:123
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