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< 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,
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:
129  int m_cu_map[17];
148  int m_min_via;
151  double mm_per_biu;
152  double biu_per_mm;
154  wxString m_lib_path;
155  wxDateTime m_mod_time;
158  void init( const PROPERTIES* aProperties );
160  void clear_cu_map();
163  int kicad( double d ) const;
164  int kicad_y( double y ) const { return -kicad( y ); }
165  int kicad_x( double x ) const { return kicad( x ); }
168  wxSize kicad_fontz( double d ) const;
171  PCB_LAYER_ID kicad_layer( int aLayer ) const;
174  double eagle( BIU d ) const { return mm_per_biu * d; }
175  double eagle_x( BIU x ) const { return eagle( x ); }
176  double eagle_y( BIU y ) const { return eagle( y ); }
179  void cacheLib( const wxString& aLibraryPath );
182  static wxDateTime getModificationTime( const wxString& aPath );
184  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
186  void loadAllSections( wxXmlNode* aDocument );
187  void loadDesignRules( wxXmlNode* aDesignRules );
188  void loadLayerDefs( wxXmlNode* aLayers );
189  void loadPlain( wxXmlNode* aPlain );
190  void loadSignals( wxXmlNode* aSignals );
203  void loadLibrary( wxXmlNode* aLib, const std::string* aLibName );
205  void loadLibraries( wxXmlNode* aLibs );
206  void loadElements( wxXmlNode* aElements );
208  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
209  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
213  void centerBoard();
221  std::string fmtDEG( double aAngle ) const;
227  MODULE* makeModule( wxXmlNode* aPackage, const std::string& aPkgName ) const;
229  void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
230  void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;
231  void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
232  void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
233  void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
234  void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
235  void packageHole( MODULE* aModule, wxXmlNode* aTree ) const;
236  void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
239  void deleteTemplates();
240 };
242 #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:145
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:131
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
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
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...
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:175
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:148
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:132
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:129
int kicad_y(double y) const
Definition: eagle_plugin.h:164
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:149
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:144
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:176
wxString m_lib_path
Definition: eagle_plugin.h:154
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:165
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:147
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:151
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:135
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: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:139
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:155
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:137
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:174
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
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:152
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...