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-2017 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>
36 typedef std::map<wxString, MODULE*> MODULE_MAP;
37 typedef std::map<wxString, ENET> NET_MAP;
38 typedef NET_MAP::const_iterator NET_MAP_CITER;
42 struct ERULES
43 {
49  double rvPadTop;
50  // double rvPadBottom; ///< bottom pad size as percent of drill size
52  double rlMinPadTop;
53  double rlMaxPadTop;
55  double rvViaOuter;
56  double rlMinViaOuter;
57  double rlMaxViaOuter;
58  double mdWireWire;
61  ERULES() :
62  psElongationLong ( 100 ),
63  psElongationOffset ( 0 ),
64  rvPadTop ( 0.25 ),
65  // rvPadBottom ( 0.25 ),
66  rlMinPadTop ( Mils2iu( 10 ) ),
67  rlMaxPadTop ( Mils2iu( 20 ) ),
69  rvViaOuter ( 0.25 ),
70  rlMinViaOuter ( Mils2iu( 10 ) ),
71  rlMaxViaOuter ( Mils2iu( 20 ) ),
72  mdWireWire ( 0 )
73  {}
75  void parse( wxXmlNode* aRules );
76 };
83 class EAGLE_PLUGIN : public PLUGIN
84 {
85 public:
87  //-----<PUBLIC PLUGIN API>--------------------------------------------------
88  const wxString PluginName() const override;
90  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
91  const PROPERTIES* aProperties = NULL ) override;
93  const wxString GetFileExtension() const override;
95  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
96  const PROPERTIES* aProperties = NULL) override;
98  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
99  const PROPERTIES* aProperties = NULL ) override;
101  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
102  {
103  return false; // until someone writes others like FootprintSave(), etc.
104  }
106  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
108 /*
109  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
111  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
113  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
115  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
117  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
118 */
120  //-----</PUBLIC PLUGIN API>-------------------------------------------------
122  typedef int BIU;
127 private:
128  typedef std::vector<ELAYER> ELAYERS;
129  typedef ELAYERS::const_iterator EITER;
131  int m_cu_map[17];
132  std::map<int, ELAYER> m_eagleLayers;
151  int m_min_via;
154  wxString m_lib_path;
155  wxDateTime m_mod_time;
158  void init( const PROPERTIES* aProperties );
160  void clear_cu_map();
163  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
164  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
167  wxSize kicad_fontz( const ECOORD& d ) const;
170  PCB_LAYER_ID kicad_layer( int aLayer ) const;
173  const wxString& eagle_layer_name( int aLayer ) const;
176  void cacheLib( const wxString& aLibraryPath );
179  static wxDateTime getModificationTime( const wxString& aPath );
181  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
183  void loadAllSections( wxXmlNode* aDocument );
184  void loadDesignRules( wxXmlNode* aDesignRules );
185  void loadLayerDefs( wxXmlNode* aLayers );
186  void loadPlain( wxXmlNode* aPlain );
187  void loadSignals( wxXmlNode* aSignals );
200  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
202  void loadLibraries( wxXmlNode* aLibs );
203  void loadElements( wxXmlNode* aElements );
205  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
206  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
210  void centerBoard();
218  wxString fmtDEG( double aAngle ) const;
224  MODULE* makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const;
226  void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
227  void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;
228  void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
229  void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
230  void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
231  void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
232  void packageHole( MODULE* aModule, wxXmlNode* aTree ) const;
233  void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
236  void deleteTemplates();
237 };
239 #endif // EAGLE_PLUGIN_H_
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:57
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:37
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:148
void FootprintLibOptions(PROPERTIES *aProperties) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
void packageHole(MODULE *aModule, wxXmlNode *aTree) const
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:134
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Eagle element element.
Definition: eagle_parser.h:788
Class XPATH keeps track of what we are working on within a PTREE.
Definition: eagle_parser.h:109
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
wxString fmtDEG(double aAngle) const
Function fmtDEG formats an angle in a way particular to a board file format.
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:53
void packageText(MODULE *aModule, wxXmlNode *aTree) const
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:38
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:164
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:151
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:55
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
void loadLayerDefs(wxXmlNode *aLayers)
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:135
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:131
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
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:152
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:147
Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN...
Definition: eagle_plugin.h:83
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:132
wxString m_lib_path
Definition: eagle_plugin.h:154
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:47
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:163
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:42
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.
int ToPcbUnits() const
Definition: eagle_parser.h:424
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:58
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:150
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:138
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:44
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:596
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:128
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
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:101
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:142
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:129
wxDateTime m_mod_time
Definition: eagle_plugin.h:155
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:140
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:49
void deleteTemplates()
Deletes the footprint templates list
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
void loadDesignRules(wxXmlNode *aDesignRules)
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:52
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:56
MODULE * makeModule(wxXmlNode *aPackage, const wxString &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
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...
void loadSignals(wxXmlNode *aSignals)
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)