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-2021 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>
32 
33 #include <map>
34 #include <tuple>
35 #include <wx/xml/xml.h>
36 
37 class PAD;
38 class FP_TEXT;
39 class ZONE;
40 
41 typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP;
42 typedef std::vector<ZONE*> ZONES;
43 typedef std::map<wxString, ENET> NET_MAP;
44 typedef NET_MAP::const_iterator NET_MAP_CITER;
45 
46 
48 struct ERULES
49 {
50  ERULES() :
51  psElongationLong ( 100 ),
52  psElongationOffset ( 0 ),
53 
54  mvStopFrame ( 1.0 ),
55  mvCreamFrame ( 0.0 ),
56  mlMinStopFrame ( Mils2iu( 4.0 ) ),
57  mlMaxStopFrame ( Mils2iu( 4.0 ) ),
58  mlMinCreamFrame ( Mils2iu( 0.0 ) ),
59  mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
60 
61  psTop ( EPAD::UNDEF ),
62  psBottom ( EPAD::UNDEF ),
63  psFirst ( EPAD::UNDEF ),
64 
65  srRoundness ( 0.0 ),
66  srMinRoundness ( Mils2iu( 0.0 ) ),
67  srMaxRoundness ( Mils2iu( 0.0 ) ),
68 
69  rvPadTop ( 0.25 ),
70  // rvPadBottom ( 0.25 ),
71  rlMinPadTop ( Mils2iu( 10 ) ),
72  rlMaxPadTop ( Mils2iu( 20 ) ),
73 
74  rvViaOuter ( 0.25 ),
75  rlMinViaOuter ( Mils2iu( 10 ) ),
76  rlMaxViaOuter ( Mils2iu( 20 ) ),
77  mdWireWire ( 0 )
78  {}
79 
80  void parse( wxXmlNode* aRules );
81 
85 
87 
89  double mvStopFrame;
90 
92  double mvCreamFrame;
97 
98  int psTop;
99  int psBottom;
100  int psFirst;
101 
102  double srRoundness;
103 
106 
109 
110  double rvPadTop;
111  // double rvPadBottom; ///< bottom pad size as percent of drill size
112 
113  double rlMinPadTop;
114  double rlMaxPadTop;
115 
116  double rvViaOuter;
117  double rlMinViaOuter;
118  double rlMaxViaOuter;
119  double mdWireWire;
120 };
121 
122 
128 {
129 public:
130  const wxString PluginName() const override;
131 
132  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
133  const PROPERTIES* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
134 
135  const wxString GetFileExtension() const override;
136 
137  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
138  bool aBestEfforts, const PROPERTIES* aProperties = nullptr) override;
139 
140  FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
141  const PROPERTIES* aProperties = nullptr ) override;
142 
143  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
144  {
145  return getModificationTime( aLibraryPath ).GetValue().GetValue();
146  }
147 
148  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
149  {
150  return false; // until someone writes others like FootprintSave(), etc.
151  }
152 
153  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
154 
155  typedef int BIU;
156 
157  EAGLE_PLUGIN();
158  ~EAGLE_PLUGIN();
159 
170  std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
171  const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
172 
173 private:
175  void init( const PROPERTIES* aProperties );
176 
177  void clear_cu_map();
178 
180  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
181  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
182 
184  wxSize kicad_fontz( const ECOORD& d, int aTextThickness ) const;
185 
187  void mapEagleLayersToKicad();
188 
190  PCB_LAYER_ID kicad_layer( int aLayer ) const;
191 
194  std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer ) const;
195 
197  const wxString& eagle_layer_name( int aLayer ) const;
198 
200  int eagle_layer_id( const wxString& aLayerName ) const;
201 
203  void cacheLib( const wxString& aLibraryPath );
204 
206  static wxDateTime getModificationTime( const wxString& aPath );
207 
208  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
209 
210  void loadAllSections( wxXmlNode* aDocument );
211  void loadDesignRules( wxXmlNode* aDesignRules );
212  void loadLayerDefs( wxXmlNode* aLayers );
213  void loadPlain( wxXmlNode* aPlain );
214  void loadSignals( wxXmlNode* aSignals );
215 
226  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
227 
228  void loadLibraries( wxXmlNode* aLibs );
229  void loadElements( wxXmlNode* aElements );
230 
236  ZONE* loadPolygon( wxXmlNode* aPolyNode );
237 
238  void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
239  const EATTR* aValueAttr );
240 
241  void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText,
242  const EATTR* aAttr );
243 
244 
246  void centerBoard();
247 
251  FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
252 
253  void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
254  void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
255  void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
256  void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
257  void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
258  void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
259 
265  void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
266  void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
267 
269  void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
270 
272  void deleteTemplates();
273 
274  typedef std::vector<ELAYER> ELAYERS;
275  typedef ELAYERS::const_iterator EITER;
276 
277  int m_cu_map[17];
278  std::map<int, ELAYER> m_eagleLayers;
279  std::map<wxString, int> m_eagleLayersIds;
280  std::map<wxString, PCB_LAYER_ID> m_layer_map;
281 
284 
287 
289 
291 
297 
300  int m_min_via;
302 
303  wxString m_lib_path;
304  wxDateTime m_mod_time;
305 };
306 
307 #endif // EAGLE_PLUGIN_H_
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:42
Plugin class for import plugins that support remappable layers.
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:118
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:181
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:43
void packageHole(FOOTPRINT *aFootprint, wxXmlNode *aTree, bool aCenter) const
void clear_cu_map()
Container for project specific data.
Definition: project.h:62
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:296
int eagle_layer_id(const wxString &aLayerName) const
Get Eagle layer number by its name.
PCB_LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
void FootprintLibOptions(PROPERTIES *aProperties) const override
Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions.
int psTop
Shape of the top pads.
Definition: eagle_plugin.h:98
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:282
Eagle element element.
Definition: eagle_parser.h:790
Keep track of what we are working on within a PTREE.
Definition: eagle_parser.h:111
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:114
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:93
int srMinRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:105
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:279
void parse(wxXmlNode *aRules)
percent over 100%.
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:44
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:300
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:116
A name/value tuple with unique names and optional values.
Definition: properties.h:33
const wxString & eagle_layer_name(int aLayer) const
Get Eagle layer name by its number.
FOOTPRINT_MAP m_templates
is part of a FOOTPRINT factory that operates using copy construction.
Definition: eagle_plugin.h:290
void loadLayerDefs(wxXmlNode *aLayers)
XPATH * m_xpath
keeps track of what we are working on within XML document during a Load().
Definition: eagle_plugin.h:283
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:277
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:143
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
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.
const PROPERTIES * m_props
passed via Save() or Load(), no ownership, may be NULL.
Definition: eagle_plugin.h:295
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API or a portion o...
Definition: eagle_plugin.h:127
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:278
Eagle thru hole pad.
Definition: eagle_parser.h:686
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packagePad(FOOTPRINT *aFootprint, wxXmlNode *aTree)
wxString m_lib_path
Definition: eagle_plugin.h:303
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:86
FOOTPRINT * makeFootprint(wxXmlNode *aPackage, const wxString &aPkgName)
Create a FOOTPRINT from an Eagle package.
subset of eagle.drawing.board.designrules in the XML document
Definition: eagle_plugin.h:48
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
void orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_plugin.h:39
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:119
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:298
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: eagle_plugin.h:286
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:102
int psElongationLong
Definition: eagle_plugin.h:84
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:100
void loadLibraries(wxXmlNode *aLibs)
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
void loadPlain(wxXmlNode *aPlain)
std::tuple< PCB_LAYER_ID, LSET, bool > defaultKicadLayer(int aEagleLayer) const
Get default KiCad layer corresponding to an Eagle layer of the board, a set of sensible layer mapping...
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:595
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:274
wxSize kicad_fontz(const ECOORD &d, int aTextThickness) const
create a font size (fontz) from an eagle font size scalar and KiCad font thickness
int mlMinCreamFrame
solder paste mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:95
void loadElements(wxXmlNode *aElements)
Board layer functions and definitions.
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: eagle_plugin.h:148
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:280
void packageCircle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
std::map< NET_NAME_CODE, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associates a NET_CODE_NAME with all the subgraphs in that net.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:189
void packagePolygon(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packageText(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Structure holding common properties for through-hole and SMD pads.
Definition: eagle_parser.h:673
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:51
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:267
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:275
wxDateTime m_mod_time
Definition: eagle_plugin.h:304
void packageSMD(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
Handles common pad properties.
void loadLibrary(wxXmlNode *aLib, const wxString *aLibName)
Load the Eagle "library" XML element, which can occur either under a "libraries" element (if a *....
double mvStopFrame
solderpaste mask, expressed as percentage of the smaller pad/via dimension
Definition: eagle_plugin.h:89
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:301
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:288
void orientFPText(FOOTPRINT *aFootprint, const EELEMENT &e, FP_TEXT *aFPText, const EATTR *aAttr)
int m_min_hole
smallest diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:299
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:110
void deleteTemplates()
void loadDesignRules(wxXmlNode *aDesignRules)
Definition: pad.h:60
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
int psBottom
Shape of the bottom pads.
Definition: eagle_plugin.h:99
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:113
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:117
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:96
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
int srMaxRoundness
Definition: eagle_plugin.h:108
void mapEagleLayersToKicad()
Generate mapping between Eagle na KiCad layers.
void loadSignals(wxXmlNode *aSignals)
int kicad_y(const ECOORD &y) const
Convert an Eagle distance to a KiCad distance.
Definition: eagle_plugin.h:180
int ToPcbUnits() const
Definition: eagle_parser.h:431
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
ZONE * loadPolygon(wxXmlNode *aPolyNode)
Load a copper or keepout polygon and adds it to the board.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
int mlMaxStopFrame
solder mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:94
double mvCreamFrame
Definition: eagle_plugin.h:92