KiCad PCB EDA Suite
Go to the documentation of this file.
1 #ifndef EAGLE_PLUGIN_H_
2 #define EAGLE_PLUGIN_H_
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <>
8  * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  *
23  * or you may search the website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
28 #include <io_mgr.h>
33 #include <map>
34 #include <tuple>
35 #include <wx/xml/xml.h>
37 class PAD;
38 class FP_TEXT;
39 class ZONE;
41 typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP;
42 typedef std::vector<ZONE*> ZONES;
43 typedef std::map<wxString, ENET> NET_MAP;
44 typedef NET_MAP::const_iterator NET_MAP_CITER;
48 struct ERULES
49 {
50  ERULES() :
51  psElongationLong ( 100 ),
52  psElongationOffset ( 0 ),
54  mvStopFrame ( 1.0 ),
55  mvCreamFrame ( 0.0 ),
56  mlMinStopFrame ( Mils2iu( 4.0 ) ),
57  mlMaxStopFrame ( Mils2iu( 4.0 ) ),
58  mlMinCreamFrame ( Mils2iu( 0.0 ) ),
59  mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
61  psTop ( EPAD::UNDEF ),
62  psBottom ( EPAD::UNDEF ),
63  psFirst ( EPAD::UNDEF ),
65  srRoundness ( 0.0 ),
66  srMinRoundness ( Mils2iu( 0.0 ) ),
67  srMaxRoundness ( Mils2iu( 0.0 ) ),
69  rvPadTop ( 0.25 ),
70  // rvPadBottom ( 0.25 ),
71  rlMinPadTop ( Mils2iu( 10 ) ),
72  rlMaxPadTop ( Mils2iu( 20 ) ),
74  rvViaOuter ( 0.25 ),
75  rlMinViaOuter ( Mils2iu( 10 ) ),
76  rlMaxViaOuter ( Mils2iu( 20 ) ),
77  mdWireWire ( 0 )
78  {}
80  void parse( wxXmlNode* aRules );
89  double mvStopFrame;
92  double mvCreamFrame;
98  int psTop;
99  int psBottom;
100  int psFirst;
102  double srRoundness;
110  double rvPadTop;
111  // double rvPadBottom; ///< bottom pad size as percent of drill size
113  double rlMinPadTop;
114  double rlMaxPadTop;
116  double rvViaOuter;
117  double rlMinViaOuter;
118  double rlMaxViaOuter;
119  double mdWireWire;
120 };
128 {
129 public:
130  const wxString PluginName() const override;
132  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
133  const PROPERTIES* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
135  std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
137  const wxString GetFileExtension() const override;
139  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
140  bool aBestEfforts, const PROPERTIES* aProperties = nullptr) override;
142  FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
143  const PROPERTIES* aProperties = nullptr ) override;
145  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
146  {
147  return getModificationTime( aLibraryPath ).GetValue().GetValue();
148  }
150  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
151  {
152  return false; // until someone writes others like FootprintSave(), etc.
153  }
155  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
157  typedef int BIU;
172  std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
173  const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
175 private:
177  void init( const PROPERTIES* aProperties );
179  void clear_cu_map();
182  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
183  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
186  wxSize kicad_fontz( const ECOORD& d, int aTextThickness ) const;
189  void mapEagleLayersToKicad();
192  PCB_LAYER_ID kicad_layer( int aLayer ) const;
196  std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer ) const;
199  const wxString& eagle_layer_name( int aLayer ) const;
202  int eagle_layer_id( const wxString& aLayerName ) const;
205  void cacheLib( const wxString& aLibraryPath );
208  static wxDateTime getModificationTime( const wxString& aPath );
210  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
212  void loadAllSections( wxXmlNode* aDocument );
213  void loadDesignRules( wxXmlNode* aDesignRules );
214  void loadLayerDefs( wxXmlNode* aLayers );
215  void loadPlain( wxXmlNode* aPlain );
216  void loadSignals( wxXmlNode* aSignals );
228  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
230  void loadLibraries( wxXmlNode* aLibs );
231  void loadElements( wxXmlNode* aElements );
238  ZONE* loadPolygon( wxXmlNode* aPolyNode );
240  void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
241  const EATTR* aValueAttr );
243  void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText,
244  const EATTR* aAttr );
248  void centerBoard();
253  FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
255  void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
256  void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
257  void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
258  void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
259  void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
260  void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
267  void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
268  void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
271  void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
274  void deleteTemplates();
276  typedef std::vector<ELAYER> ELAYERS;
277  typedef ELAYERS::const_iterator EITER;
279  int m_cu_map[17];
280  std::map<int, ELAYER> m_eagleLayers;
281  std::map<wxString, int> m_eagleLayersIds;
282  std::map<wxString, PCB_LAYER_ID> m_layer_map;
302  int m_min_via;
305  wxString m_lib_path;
306  wxDateTime m_mod_time;
307 };
309 #endif // EAGLE_PLUGIN_H_
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:42
Plugin class for import plugins that support remappable layers.
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:118
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:183
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:43
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
void clear_cu_map()
Container for project specific data.
Definition: project.h:62
void centerBoard()
move the BOARD into the center of the page
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:298
int eagle_layer_id(const wxString &aLayerName) const
Get Eagle layer number by its name.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void FootprintLibOptions(PROPERTIES *aProperties) const override
Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions.
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:98
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:284
Eagle element element.
Definition: eagle_parser.h:812
Keep track of what we are working on within a PTREE.
Definition: eagle_parser.h:112
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:114
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:93
int srMinRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:105
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:281
void parse(wxXmlNode *aRules)
percent over 100%.
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:44
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:302
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:116
A name/value tuple with unique names and optional values.
Definition: properties.h:33
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:292
void loadLayerDefs(wxXmlNode *aLayers)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:285
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:279
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:145
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
A quick note on layer IDs:
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:297
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API or a portion o...
Definition: eagle_plugin.h:127
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:280
Eagle thru hole pad.
Definition: eagle_parser.h:708
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packagePad(FOOTPRINT *aFootprint, wxXmlNode *aTree)
wxString m_lib_path
Definition: eagle_plugin.h:305
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:86
FOOTPRINT * makeFootprint(wxXmlNode *aPackage, const wxString &aPkgName)
Create a FOOTPRINT from an Eagle package.
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:48
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
void orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_plugin.h:39
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:119
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:300
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: eagle_plugin.h:288
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:102
int psElongationLong
Definition: eagle_plugin.h:84
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:100
void loadLibraries(wxXmlNode *aLibs)
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
void loadPlain(wxXmlNode *aPlain)
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...
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:596
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:276
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:95
void loadElements(wxXmlNode *aElements)
Board layer functions and definitions.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: eagle_plugin.h:150
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:282
void packageCircle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
std::map< NET_NAME_CODE, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associates a NET_CODE_NAME with all the subgraphs in that net.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packageText(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:695
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:52
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:267
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:277
wxDateTime m_mod_time
Definition: eagle_plugin.h:306
void packageSMD(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Handles common pad properties.
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
double mvStopFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:89
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:303
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:290
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, FP_TEXT *aFPText, const EATTR *aAttr)
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:301
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:110
void deleteTemplates()
void loadDesignRules(wxXmlNode *aDesignRules)
Definition: pad.h:60
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:99
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:113
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:117
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:96
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
int srMaxRoundness
Definition: eagle_plugin.h:108
void mapEagleLayersToKicad()
Generate mapping between Eagle na KiCad layers.
void loadSignals(wxXmlNode *aSignals)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:182
int ToPcbUnits() const
Definition: eagle_parser.h:432
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
ZONE * loadPolygon(wxXmlNode *aPolyNode)
Load a copper or keepout polygon and adds it to the board.
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 mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:94
double mvCreamFrame
Definition: eagle_plugin.h:92