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-2020 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>
30 #include <eagle_parser.h>
32 #include <map>
33 #include <wx/xml/xml.h>
35 class D_PAD;
38 typedef std::map<wxString, MODULE*> MODULE_MAP;
39 typedef std::vector<ZONE_CONTAINER*> ZONES;
40 typedef std::map<wxString, ENET> NET_MAP;
41 typedef NET_MAP::const_iterator NET_MAP_CITER;
45 struct ERULES
46 {
52  double mvStopFrame;
53  double mvCreamFrame;
59  int psTop;
60  int psBottom;
61  int psFirst;
63  double srRoundness;
67  double rvPadTop;
68  // double rvPadBottom; ///< bottom pad size as percent of drill size
70  double rlMinPadTop;
71  double rlMaxPadTop;
73  double rvViaOuter;
74  double rlMinViaOuter;
75  double rlMaxViaOuter;
76  double mdWireWire;
79  ERULES() :
80  psElongationLong ( 100 ),
81  psElongationOffset ( 0 ),
83  mvStopFrame ( 1.0 ),
84  mvCreamFrame ( 0.0 ),
85  mlMinStopFrame ( Mils2iu( 4.0 ) ),
86  mlMaxStopFrame ( Mils2iu( 4.0 ) ),
87  mlMinCreamFrame ( Mils2iu( 0.0 ) ),
88  mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
90  psTop ( EPAD::UNDEF ),
91  psBottom ( EPAD::UNDEF ),
92  psFirst ( EPAD::UNDEF ),
94  srRoundness ( 0.0 ),
95  srMinRoundness ( Mils2iu( 0.0 ) ),
96  srMaxRoundness ( Mils2iu( 0.0 ) ),
98  rvPadTop ( 0.25 ),
99  // rvPadBottom ( 0.25 ),
100  rlMinPadTop ( Mils2iu( 10 ) ),
101  rlMaxPadTop ( Mils2iu( 20 ) ),
103  rvViaOuter ( 0.25 ),
104  rlMinViaOuter ( Mils2iu( 10 ) ),
105  rlMaxViaOuter ( Mils2iu( 20 ) ),
106  mdWireWire ( 0 )
107  {}
109  void parse( wxXmlNode* aRules );
110 };
117 class EAGLE_PLUGIN : public PLUGIN
118 {
119 public:
121  //-----<PUBLIC PLUGIN API>--------------------------------------------------
122  const wxString PluginName() const override;
124  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
125  const PROPERTIES* aProperties = NULL ) override;
127  const wxString GetFileExtension() const override;
129  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
130  bool aBestEfforts, const PROPERTIES* aProperties = NULL) override;
132  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
133  const PROPERTIES* aProperties = NULL ) override;
135  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
136  {
137  return getModificationTime( aLibraryPath ).GetValue().GetValue();
138  }
140  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
141  {
142  return false; // until someone writes others like FootprintSave(), etc.
143  }
145  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
147 /*
148  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
150  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
152  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
154  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
156  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
157 */
159  //-----</PUBLIC PLUGIN API>-------------------------------------------------
161  typedef int BIU;
166 private:
167  typedef std::vector<ELAYER> ELAYERS;
168  typedef ELAYERS::const_iterator EITER;
170  int m_cu_map[17];
171  std::map<int, ELAYER> m_eagleLayers;
190  int m_min_via;
193  wxString m_lib_path;
194  wxDateTime m_mod_time;
197  void init( const PROPERTIES* aProperties );
199  void clear_cu_map();
202  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
203  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
206  wxSize kicad_fontz( const ECOORD& d ) const;
209  PCB_LAYER_ID kicad_layer( int aLayer ) const;
212  const wxString& eagle_layer_name( int aLayer ) const;
215  void cacheLib( const wxString& aLibraryPath );
218  static wxDateTime getModificationTime( const wxString& aPath );
220  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
222  void loadAllSections( wxXmlNode* aDocument );
223  void loadDesignRules( wxXmlNode* aDesignRules );
224  void loadLayerDefs( wxXmlNode* aLayers );
225  void loadPlain( wxXmlNode* aPlain );
226  void loadSignals( wxXmlNode* aSignals );
239  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
241  void loadLibraries( wxXmlNode* aLibs );
242  void loadElements( wxXmlNode* aElements );
248  ZONE_CONTAINER* loadPolygon( wxXmlNode* aPolyNode );
250  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
251  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
255  void centerBoard();
263  wxString fmtDEG( double aAngle ) const;
269  MODULE* makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const;
271  void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
272  void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;
273  void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
274  void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
275  void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
276  void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
285  void packageHole( MODULE* aModule, wxXmlNode* aTree, bool aCenter ) const;
286  void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
289  void transferPad( const EPAD_COMMON& aEaglePad, D_PAD* aPad ) const;
292  void deleteTemplates();
293 };
295 #endif // EAGLE_PLUGIN_H_
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:75
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:203
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:40
void clear_cu_map()
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:187
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void FootprintLibOptions(PROPERTIES *aProperties) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:59
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:173
void packageText(MODULE *aModule, wxXmlNode *aTree) const
Eagle element element.
Definition: eagle_parser.h:797
XPATH keeps 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:71
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:54
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:64
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL) override
Function Load loads information from some input file format that this PLUGIN implementation knows abo...
void parse(wxXmlNode *aRules)
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:41
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:190
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:73
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
void loadLayerDefs(wxXmlNode *aLayers)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:174
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:170
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:135
void packageHole(MODULE *aModule, wxXmlNode *aTree, bool aCenter) const
Function packageHole @parameter aModule - The KiCad module to which to assign the hole @parameter aTr...
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
A quick note on layer IDs:
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:191
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:186
EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API,...
Definition: eagle_plugin.h:117
#define NULL
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:171
Eagle thru hole pad.
Definition: eagle_parser.h:693
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
wxString m_lib_path
Definition: eagle_plugin.h:193
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:50
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:45
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
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:76
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:189
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:177
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:63
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:47
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:61
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:602
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:167
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:56
void loadElements(wxXmlNode *aElements)
Board layer functions and definitions.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: eagle_plugin.h:140
std::map< NET_NAME_CODE, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associates a NET_CODE_NAME with all the subgraphs in that net.
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:680
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:181
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:271
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:168
wxDateTime m_mod_time
Definition: eagle_plugin.h:194
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:52
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:179
wxString fmtDEG(double aAngle) const
Function fmtDEG formats an angle in a way particular to a board file format.
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:67
void deleteTemplates()
Deletes the footprint templates list
std::vector< ZONE_CONTAINER * > ZONES
Definition: eagle_plugin.h:39
void loadDesignRules(wxXmlNode *aDesignRules)
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:60
ZONE_CONTAINER * loadPolygon(wxXmlNode *aPolyNode)
Loads a copper or keepout polygon and adds it to the board.
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:70
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:74
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:57
MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL) override
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:65
void loadSignals(wxXmlNode *aSignals)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:202
MODULE * makeModule(wxXmlNode *aPackage, const wxString &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
int ToPcbUnits() const
Definition: eagle_parser.h:438
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:53
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)