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-2016 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< std::string, MODULE* > MODULE_MAP;
37 typedef std::map< std::string, 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, const PROPERTIES* aProperties = NULL ) override;
92  const wxString GetFileExtension() const override;
94  wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL) override;
96  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
97  const PROPERTIES* aProperties = NULL ) override;
99  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
100  {
101  return false; // until someone writes others like FootprintSave(), etc.
102  }
104  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
106 /*
107  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
109  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
111  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
113  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
115  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
116 */
118  //-----</PUBLIC PLUGIN API>-------------------------------------------------
120  typedef int BIU;
125 private:
127  int m_cu_map[17];
146  int m_min_via;
149  double mm_per_biu;
150  double biu_per_mm;
152  wxString m_lib_path;
153  wxDateTime m_mod_time;
156  void init( const PROPERTIES* aProperties );
158  void clear_cu_map();
161  int kicad( double d ) const;
162  int kicad_y( double y ) const { return -kicad( y ); }
163  int kicad_x( double x ) const { return kicad( x ); }
166  wxSize kicad_fontz( double d ) const;
169  PCB_LAYER_ID kicad_layer( int aLayer ) const;
172  double eagle( BIU d ) const { return mm_per_biu * d; }
173  double eagle_x( BIU x ) const { return eagle( x ); }
174  double eagle_y( BIU y ) const { return eagle( y ); }
177  void cacheLib( const wxString& aLibraryPath );
180  static wxDateTime getModificationTime( const wxString& aPath );
182  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
184  void loadAllSections( wxXmlNode* aDocument );
185  void loadDesignRules( wxXmlNode* aDesignRules );
186  void loadLayerDefs( wxXmlNode* aLayers );
187  void loadPlain( wxXmlNode* aPlain );
188  void loadSignals( wxXmlNode* aSignals );
201  void loadLibrary( wxXmlNode* aLib, const std::string* aLibName );
203  void loadLibraries( wxXmlNode* aLibs );
204  void loadElements( wxXmlNode* aElements );
206  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
207  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
211  void centerBoard();
219  std::string fmtDEG( double aAngle ) const;
225  MODULE* makeModule( wxXmlNode* aPackage, const std::string& aPkgName ) const;
227  void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
228  void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;
229  void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
230  void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
231  void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
232  void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
233  void packageHole( MODULE* aModule, wxXmlNode* aTree ) const;
234  void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
235 };
237 #endif // EAGLE_PLUGIN_H_
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:57
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:143
std::string fmtDEG(double aAngle) const
Function fmtDEG formats an angle in a way particular to a board file format.
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:129
MODULE * makeModule(wxXmlNode *aPackage, const std::string &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Eagle element element.
Definition: eagle_parser.h:643
Class XPATH keeps track of what we are working on within a PTREE.
Definition: eagle_parser.h:99
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:53
std::map< std::string, ENET > NET_MAP
Definition: eagle_plugin.h:37
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...
wxArrayString FootprintEnumerate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintEnumerate returns a list of footprint names contained within the library at aLibrar...
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.
double eagle_x(BIU x) const
Definition: eagle_plugin.h:173
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:146
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:130
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:127
int kicad_y(double y) const
Definition: eagle_plugin.h:162
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:147
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:142
Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN...
Definition: eagle_plugin.h:83
double eagle_y(BIU y) const
Definition: eagle_plugin.h:174
wxString m_lib_path
Definition: eagle_plugin.h:152
std::map< std::string, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:36
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:47
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:42
int kicad_x(double x) const
Definition: eagle_plugin.h:163
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:58
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:145
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:149
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:133
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:473
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
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:99
void packagePad(MODULE *aModule, wxXmlNode *aTree) const
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:137
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:193
wxDateTime m_mod_time
Definition: eagle_plugin.h:153
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:135
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:172
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:49
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:150
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 * 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)
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.
void loadLibrary(wxXmlNode *aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...