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-2020 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 class TEXTE_MODULE;
38 
39 typedef std::map<wxString, MODULE*> MODULE_MAP;
40 typedef std::vector<ZONE_CONTAINER*> ZONES;
41 typedef std::map<wxString, ENET> NET_MAP;
42 typedef NET_MAP::const_iterator NET_MAP_CITER;
43 
44 
46 struct ERULES
47 {
49 
52 
53  double mvStopFrame;
54  double mvCreamFrame;
59 
60  int psTop;
61  int psBottom;
62  int psFirst;
63 
64  double srRoundness;
67 
68  double rvPadTop;
69  // double rvPadBottom; ///< bottom pad size as percent of drill size
70 
71  double rlMinPadTop;
72  double rlMaxPadTop;
73 
74  double rvViaOuter;
75  double rlMinViaOuter;
76  double rlMaxViaOuter;
77  double mdWireWire;
78 
79 
80  ERULES() :
81  psElongationLong ( 100 ),
82  psElongationOffset ( 0 ),
83 
84  mvStopFrame ( 1.0 ),
85  mvCreamFrame ( 0.0 ),
86  mlMinStopFrame ( Mils2iu( 4.0 ) ),
87  mlMaxStopFrame ( Mils2iu( 4.0 ) ),
88  mlMinCreamFrame ( Mils2iu( 0.0 ) ),
89  mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
90 
91  psTop ( EPAD::UNDEF ),
92  psBottom ( EPAD::UNDEF ),
93  psFirst ( EPAD::UNDEF ),
94 
95  srRoundness ( 0.0 ),
96  srMinRoundness ( Mils2iu( 0.0 ) ),
97  srMaxRoundness ( Mils2iu( 0.0 ) ),
98 
99  rvPadTop ( 0.25 ),
100  // rvPadBottom ( 0.25 ),
101  rlMinPadTop ( Mils2iu( 10 ) ),
102  rlMaxPadTop ( Mils2iu( 20 ) ),
103 
104  rvViaOuter ( 0.25 ),
105  rlMinViaOuter ( Mils2iu( 10 ) ),
106  rlMaxViaOuter ( Mils2iu( 20 ) ),
107  mdWireWire ( 0 )
108  {}
109 
110  void parse( wxXmlNode* aRules );
111 };
112 
118 class EAGLE_PLUGIN : public PLUGIN
119 {
120 public:
121 
122  //-----<PUBLIC PLUGIN API>--------------------------------------------------
123  const wxString PluginName() const override;
124 
125  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
126  const PROPERTIES* aProperties = NULL ) override;
127 
128  const wxString GetFileExtension() const override;
129 
130  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
131  bool aBestEfforts, const PROPERTIES* aProperties = NULL) override;
132 
133  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
134  const PROPERTIES* aProperties = NULL ) override;
135 
136  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
137  {
138  return getModificationTime( aLibraryPath ).GetValue().GetValue();
139  }
140 
141  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
142  {
143  return false; // until someone writes others like FootprintSave(), etc.
144  }
145 
146  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
147 
148 /*
149  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
150 
151  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
152 
153  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
154 
155  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
156 
157  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
158 */
159 
160  //-----</PUBLIC PLUGIN API>-------------------------------------------------
161 
162  typedef int BIU;
163 
164  EAGLE_PLUGIN();
165  ~EAGLE_PLUGIN();
166 
167 private:
168  typedef std::vector<ELAYER> ELAYERS;
169  typedef ELAYERS::const_iterator EITER;
170 
171  int m_cu_map[17];
172  std::map<int, ELAYER> m_eagleLayers;
173 
176 
179 
181 
183 
189 
192  int m_min_via;
194 
195  wxString m_lib_path;
196  wxDateTime m_mod_time;
197 
199  void init( const PROPERTIES* aProperties );
200 
201  void clear_cu_map();
202 
204  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
205  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
206 
208  wxSize kicad_fontz( const ECOORD& d ) const;
209 
211  PCB_LAYER_ID kicad_layer( int aLayer ) const;
212 
214  const wxString& eagle_layer_name( int aLayer ) const;
215 
217  void cacheLib( const wxString& aLibraryPath );
218 
220  static wxDateTime getModificationTime( const wxString& aPath );
221 
222  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
223 
224  void loadAllSections( wxXmlNode* aDocument );
225  void loadDesignRules( wxXmlNode* aDesignRules );
226  void loadLayerDefs( wxXmlNode* aLayers );
227  void loadPlain( wxXmlNode* aPlain );
228  void loadSignals( wxXmlNode* aSignals );
229 
241  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
242 
243  void loadLibraries( wxXmlNode* aLibs );
244  void loadElements( wxXmlNode* aElements );
245 
250  ZONE_CONTAINER* loadPolygon( wxXmlNode* aPolyNode );
251 
252  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
253  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
254 
255 
257  void centerBoard();
258 
265  wxString fmtDEG( double aAngle ) const;
266 
271  MODULE* makeModule( wxXmlNode* aPackage, const wxString& aPkgName );
272 
273  void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
274  void packagePad( MODULE* aModule, wxXmlNode* aTree );
275  void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
276  void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
277  void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
278  void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
279 
287  void packageHole( MODULE* aModule, wxXmlNode* aTree, bool aCenter ) const;
288  void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
289 
291  void transferPad( const EPAD_COMMON& aEaglePad, D_PAD* aPad ) const;
292 
294  void deleteTemplates();
295 };
296 
297 #endif // EAGLE_PLUGIN_H_
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:76
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:205
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:41
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:188
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void FootprintLibOptions(PROPERTIES *aProperties) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:60
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:174
void packageText(MODULE *aModule, wxXmlNode *aTree) const
Eagle element element.
Definition: eagle_parser.h:797
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:72
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:55
int srMinRoundness
corner rounding radius, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:65
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:42
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:192
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:74
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
void loadLayerDefs(wxXmlNode *aLayers)
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_parser.h:51
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:175
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:171
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:136
void packageHole(MODULE *aModule, wxXmlNode *aTree, bool aCenter) const
Function packageHole @parameter aModule - The KiCad module to which to assign the hole @parameter aTr...
PCB_LAYER_ID
A quick note on layer IDs:
void cacheLib(const wxString &aLibraryPath)
This PLUGIN only caches one footprint library, this determines which one.
void packagePolygon(MODULE *aModule, wxXmlNode *aTree) const
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:187
EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API,...
Definition: eagle_plugin.h:118
#define NULL
std::map< int, ELAYER > m_eagleLayers
Eagle layers data stored by the layer number.
Definition: eagle_plugin.h:172
Eagle thru hole pad.
Definition: eagle_parser.h:693
void packageWire(MODULE *aModule, wxXmlNode *aTree) const
void packageRectangle(MODULE *aModule, wxXmlNode *aTree) const
wxString m_lib_path
Definition: eagle_plugin.h:195
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:51
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:46
std::map< wxString, MODULE * > MODULE_MAP
Definition: eagle_plugin.h:37
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:77
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:190
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:178
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:64
int psElongationLong
percent over 100%.
Definition: eagle_plugin.h:48
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:62
void loadLibraries(wxXmlNode *aLibs)
void loadPlain(wxXmlNode *aPlain)
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
EATTR parses an Eagle "attribute" XML element.
Definition: eagle_parser.h:602
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:168
void packagePad(MODULE *aModule, wxXmlNode *aTree)
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:57
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:141
std::map< NET_NAME_CODE, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associates a NET_CODE_NAME with all the subgraphs in that net.
void packageSMD(MODULE *aModule, wxXmlNode *aTree) const
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:181
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL) override
Return a list of footprint names contained within the library at aLibraryPath.
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:182
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:169
wxDateTime m_mod_time
Definition: eagle_plugin.h:196
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
double mvStopFrame
solder mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:53
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:193
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:180
wxString fmtDEG(double aAngle) const
Function fmtDEG formats an angle in a way particular to a board file format.
void transferPad(const EPAD_COMMON &aEaglePad, D_PAD *aPad) const
Handles common pad properties
wxSize kicad_fontz(const ECOORD &d) const
create a font size (fontz) from an eagle font size scalar
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:191
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:68
void deleteTemplates()
Deletes the footprint templates list
std::vector< ZONE_CONTAINER * > ZONES
Definition: eagle_plugin.h:40
void loadDesignRules(wxXmlNode *aDesignRules)
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
void packageCircle(MODULE *aModule, wxXmlNode *aTree) const
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:61
ZONE_CONTAINER * loadPolygon(wxXmlNode *aPolyNode)
Loads a copper or keepout polygon and adds it to the board.
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:71
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:75
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:58
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...
int srMaxRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:66
MODULE * makeModule(wxXmlNode *aPackage, const wxString &aPkgName)
Function makeModule creates a MODULE from an Eagle package.
void loadSignals(wxXmlNode *aSignals)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:204
int ToPcbUnits() const
Definition: eagle_parser.h:438
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:56
double mvCreamFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:54
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)