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