KiCad PCB EDA Suite
eagle_plugin.h
Go to the documentation of this file.
1 #ifndef EAGLE_PLUGIN_H_
2 #define EAGLE_PLUGIN_H_
3 
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 <dick@softplc.com>
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
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org 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  */
27 
28 #include <io_mgr.h>
30 #include <eagle_parser.h>
31 
32 #include <map>
33 #include <wx/xml/xml.h>
34 
35 
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;
39 
40 
42 struct ERULES
43 {
45 
48 
49  double rvPadTop;
50  // double rvPadBottom; ///< bottom pad size as percent of drill size
51 
52  double rlMinPadTop;
53  double rlMaxPadTop;
54 
55  double rvViaOuter;
56  double rlMinViaOuter;
57  double rlMaxViaOuter;
58  double mdWireWire;
59 
60 
61  ERULES() :
62  psElongationLong ( 100 ),
63  psElongationOffset ( 0 ),
64  rvPadTop ( 0.25 ),
65  // rvPadBottom ( 0.25 ),
66  rlMinPadTop ( Mils2iu( 10 ) ),
67  rlMaxPadTop ( Mils2iu( 20 ) ),
68 
69  rvViaOuter ( 0.25 ),
70  rlMinViaOuter ( Mils2iu( 10 ) ),
71  rlMaxViaOuter ( Mils2iu( 20 ) ),
72  mdWireWire ( 0 )
73  {}
74 
75  void parse( wxXmlNode* aRules );
76 };
77 
83 class EAGLE_PLUGIN : public PLUGIN
84 {
85 public:
86 
87  //-----<PUBLIC PLUGIN API>--------------------------------------------------
88  const wxString PluginName() const override;
89 
90  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
91  const PROPERTIES* aProperties = NULL ) override;
92 
93  const wxString GetFileExtension() const override;
94 
95  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
96  const PROPERTIES* aProperties = NULL) override;
97 
98  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
99  const PROPERTIES* aProperties = NULL ) override;
100 
101  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
102  {
103  return false; // until someone writes others like FootprintSave(), etc.
104  }
105 
106  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
107 
108 /*
109  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
110 
111  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
112 
113  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
114 
115  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
116 
117  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
118 */
119 
120  //-----</PUBLIC PLUGIN API>-------------------------------------------------
121 
122  typedef int BIU;
123 
124  EAGLE_PLUGIN();
125  ~EAGLE_PLUGIN();
126 
127 private:
128  typedef std::vector<ELAYER> ELAYERS;
129  typedef ELAYERS::const_iterator EITER;
130 
131  int m_cu_map[17];
132  std::map<int, ELAYER> m_eagleLayers;
133 
136 
139 
141 
143 
149 
151  int m_min_via;
153 
154  wxString m_lib_path;
155  wxDateTime m_mod_time;
156 
158  void init( const PROPERTIES* aProperties );
159 
160  void clear_cu_map();
161 
163  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
164  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
165 
167  wxSize kicad_fontz( const ECOORD& d ) const;
168 
170  PCB_LAYER_ID kicad_layer( int aLayer ) const;
171 
173  const std::string& eagle_layer_name( int aLayer ) const;
174 
176  void cacheLib( const wxString& aLibraryPath );
177 
179  static wxDateTime getModificationTime( const wxString& aPath );
180 
181  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
182 
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 );
188 
200  void loadLibrary( wxXmlNode* aLib, const std::string* aLibName );
201 
202  void loadLibraries( wxXmlNode* aLibs );
203  void loadElements( wxXmlNode* aElements );
204 
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 );
207 
208 
210  void centerBoard();
211 
218  std::string fmtDEG( double aAngle ) const;
219 
224  MODULE* makeModule( wxXmlNode* aPackage, const std::string& aPkgName ) const;
225 
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;
234 
236  void deleteTemplates();
237 };
238 
239 #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:148
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:134
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:785
Class XPATH keeps track of what we are working on within a PTREE.
Definition: eagle_parser.h:110
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.
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
PCB_LAYER_ID
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
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
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
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
int ToPcbUnits() const
Definition: eagle_parser.h:421
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:593
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
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
const std::string & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
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)
void loadLibrary(wxXmlNode *aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...