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 class D_PAD;
36 
37 typedef std::map<wxString, MODULE*> MODULE_MAP;
38 typedef std::map<wxString, ENET> NET_MAP;
39 typedef NET_MAP::const_iterator NET_MAP_CITER;
40 
41 
43 struct ERULES
44 {
46 
49 
50  double mvStopFrame;
51  double mvCreamFrame;
56 
57  double srRoundness;
60 
61  double rvPadTop;
62  // double rvPadBottom; ///< bottom pad size as percent of drill size
63 
64  double rlMinPadTop;
65  double rlMaxPadTop;
66 
67  double rvViaOuter;
68  double rlMinViaOuter;
69  double rlMaxViaOuter;
70  double mdWireWire;
71 
72 
73  ERULES() :
74  psElongationLong ( 100 ),
75  psElongationOffset ( 0 ),
76 
77  mvStopFrame ( 1.0 ),
78  mvCreamFrame ( 0.0 ),
79  mlMinStopFrame ( Mils2iu( 4.0 ) ),
80  mlMaxStopFrame ( Mils2iu( 4.0 ) ),
81  mlMinCreamFrame ( Mils2iu( 0.0 ) ),
82  mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
83 
84  srRoundness ( 0.0 ),
85  srMinRoundness ( Mils2iu( 0.0 ) ),
86  srMaxRoundness ( Mils2iu( 0.0 ) ),
87 
88  rvPadTop ( 0.25 ),
89  // rvPadBottom ( 0.25 ),
90  rlMinPadTop ( Mils2iu( 10 ) ),
91  rlMaxPadTop ( Mils2iu( 20 ) ),
92 
93  rvViaOuter ( 0.25 ),
94  rlMinViaOuter ( Mils2iu( 10 ) ),
95  rlMaxViaOuter ( Mils2iu( 20 ) ),
96  mdWireWire ( 0 )
97  {}
98 
99  void parse( wxXmlNode* aRules );
100 };
101 
107 class EAGLE_PLUGIN : public PLUGIN
108 {
109 public:
110 
111  //-----<PUBLIC PLUGIN API>--------------------------------------------------
112  const wxString PluginName() const override;
113 
114  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
115  const PROPERTIES* aProperties = NULL ) override;
116 
117  const wxString GetFileExtension() const override;
118 
119  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
120  const PROPERTIES* aProperties = NULL) override;
121 
122  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
123  const PROPERTIES* aProperties = NULL ) override;
124 
125  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
126  {
127  return getModificationTime( aLibraryPath ).GetValue().GetValue();
128  }
129 
130  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
131  {
132  return false; // until someone writes others like FootprintSave(), etc.
133  }
134 
135  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
136 
137 /*
138  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
139 
140  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
141 
142  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
143 
144  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
145 
146  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
147 */
148 
149  //-----</PUBLIC PLUGIN API>-------------------------------------------------
150 
151  typedef int BIU;
152 
153  EAGLE_PLUGIN();
154  ~EAGLE_PLUGIN();
155 
156 private:
157  typedef std::vector<ELAYER> ELAYERS;
158  typedef ELAYERS::const_iterator EITER;
159 
160  int m_cu_map[17];
161  std::map<int, ELAYER> m_eagleLayers;
162 
165 
168 
170 
172 
178 
180  int m_min_via;
182 
183  wxString m_lib_path;
184  wxDateTime m_mod_time;
185 
187  void init( const PROPERTIES* aProperties );
188 
189  void clear_cu_map();
190 
192  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
193  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
194 
196  wxSize kicad_fontz( const ECOORD& d ) const;
197 
199  PCB_LAYER_ID kicad_layer( int aLayer ) const;
200 
202  const wxString& eagle_layer_name( int aLayer ) const;
203 
205  void cacheLib( const wxString& aLibraryPath );
206 
208  static wxDateTime getModificationTime( const wxString& aPath );
209 
210  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
211 
212  void loadAllSections( wxXmlNode* aDocument );
213  void loadDesignRules( wxXmlNode* aDesignRules );
214  void loadLayerDefs( wxXmlNode* aLayers );
215  void loadPlain( wxXmlNode* aPlain );
216  void loadSignals( wxXmlNode* aSignals );
217 
229  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
230 
231  void loadLibraries( wxXmlNode* aLibs );
232  void loadElements( wxXmlNode* aElements );
233 
234  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
235  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
236 
237 
239  void centerBoard();
240 
247  wxString fmtDEG( double aAngle ) const;
248 
253  MODULE* makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const;
254 
255  void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
256  void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;
257  void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
258  void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
259  void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
260  void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
261  void packageHole( MODULE* aModule, wxXmlNode* aTree ) const;
262  void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
263 
265  void transferPad( const EPAD_COMMON& aEaglePad, D_PAD* aPad ) const;
266 
268  void deleteTemplates();
269 };
270 
271 #endif // EAGLE_PLUGIN_H_
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:69
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:38
BOARD * m_board
which BOARD is being worked on, no ownership here
Definition: eagle_plugin.h:177
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:163
Eagle element element.
Definition: eagle_parser.h:796
Class 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:65
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:52
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:58
void parse(wxXmlNode *aRules)
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:39
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:193
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:180
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:67
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:164
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:125
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:181
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:176
Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN...
Definition: eagle_plugin.h:107
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:161
wxString m_lib_path
Definition: eagle_plugin.h:183
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:48
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:192
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:43
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:35
int ToPcbUnits() const
Definition: eagle_parser.h:438
double mdWireWire
wire to wire spacing I presume.
Definition: eagle_plugin.h:70
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:179
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:167
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:57
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:45
Class EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:602
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:157
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:54
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:130
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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:171
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:158
wxDateTime m_mod_time
Definition: eagle_plugin.h:184
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:50
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:169
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:61
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:64
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:68
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:59
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:53
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:51