KiCad PCB EDA Suite
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5  * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  *
20  * or you may search the website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
25 #ifndef EAGLE_PLUGIN_H
26 #define EAGLE_PLUGIN_H
28 #include <convert_to_biu.h>
29 #include <io_mgr.h>
30 #include <layer_ids.h>
31 #include <netclass.h>
35 #include <map>
36 #include <tuple>
37 #include <wx/xml/xml.h>
39 class PAD;
40 class FP_TEXT;
41 class ZONE;
43 typedef std::map<wxString, FOOTPRINT*> FOOTPRINT_MAP;
44 typedef std::vector<ZONE*> ZONES;
45 typedef std::map<wxString, ENET> NET_MAP;
46 typedef NET_MAP::const_iterator NET_MAP_CITER;
50 struct ERULES
51 {
52  ERULES() :
53  psElongationLong ( 100 ),
54  psElongationOffset ( 0 ),
56  mvStopFrame ( 1.0 ),
57  mvCreamFrame ( 0.0 ),
58  mlMinStopFrame ( Mils2iu( 4.0 ) ),
59  mlMaxStopFrame ( Mils2iu( 4.0 ) ),
60  mlMinCreamFrame ( Mils2iu( 0.0 ) ),
61  mlMaxCreamFrame ( Mils2iu( 0.0 ) ),
63  psTop ( EPAD::UNDEF ),
64  psBottom ( EPAD::UNDEF ),
65  psFirst ( EPAD::UNDEF ),
67  srRoundness ( 0.0 ),
68  srMinRoundness ( Mils2iu( 0.0 ) ),
69  srMaxRoundness ( Mils2iu( 0.0 ) ),
71  rvPadTop ( 0.25 ),
72  // rvPadBottom ( 0.25 ),
73  rlMinPadTop ( Mils2iu( 10 ) ),
74  rlMaxPadTop ( Mils2iu( 20 ) ),
76  rvViaOuter ( 0.25 ),
77  rlMinViaOuter ( Mils2iu( 10 ) ),
78  rlMaxViaOuter ( Mils2iu( 20 ) ),
79  mdWireWire ( 0 )
80  {}
82  void parse( wxXmlNode* aRules, std::function<void()> aCheckpoint );
91  double mvStopFrame;
94  double mvCreamFrame;
100  int psTop;
101  int psBottom;
102  int psFirst;
104  double srRoundness;
112  double rvPadTop;
113  // double rvPadBottom; ///< bottom pad size as percent of drill size
115  double rlMinPadTop;
116  double rlMaxPadTop;
118  double rvViaOuter;
119  double rlMinViaOuter;
120  double rlMaxViaOuter;
121  double mdWireWire;
122 };
130 {
131 public:
132  const wxString PluginName() const override;
134  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
135  const PROPERTIES* aProperties = nullptr, PROJECT* aProject = nullptr,
136  PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
138  std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
140  const wxString GetFileExtension() const override;
142  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
143  bool aBestEfforts, const PROPERTIES* aProperties = nullptr) override;
145  FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
146  bool aKeepUUID = false,
147  const PROPERTIES* aProperties = nullptr ) override;
149  long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
150  {
151  return getModificationTime( aLibraryPath ).GetValue().GetValue();
152  }
154  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
155  {
156  return false; // until someone writes others like FootprintSave(), etc.
157  }
159  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
161  typedef int BIU;
176  std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
177  const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
179 private:
181  void init( const PROPERTIES* aProperties );
183  void checkpoint();
185  void clear_cu_map();
188  int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
189  int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
192  wxSize kicad_fontz( const ECOORD& d, int aTextThickness ) const;
195  void mapEagleLayersToKicad();
198  PCB_LAYER_ID kicad_layer( int aLayer ) const;
202  std::tuple<PCB_LAYER_ID, LSET, bool> defaultKicadLayer( int aEagleLayer ) const;
205  const wxString& eagle_layer_name( int aLayer ) const;
208  int eagle_layer_id( const wxString& aLayerName ) const;
211  void cacheLib( const wxString& aLibraryPath );
214  static wxDateTime getModificationTime( const wxString& aPath );
216  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
218  void loadAllSections( wxXmlNode* aDocument );
219  void loadDesignRules( wxXmlNode* aDesignRules );
220  void loadLayerDefs( wxXmlNode* aLayers );
221  void loadPlain( wxXmlNode* aPlain );
222  void loadClasses( wxXmlNode* aClasses );
223  void loadSignals( wxXmlNode* aSignals );
235  void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
237  void loadLibraries( wxXmlNode* aLibs );
238  void loadElements( wxXmlNode* aElements );
245  ZONE* loadPolygon( wxXmlNode* aPolyNode );
247  void orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e, const EATTR* aNameAttr,
248  const EATTR* aValueAttr );
250  void orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, FP_TEXT* aFPText,
251  const EATTR* aAttr );
255  void centerBoard();
260  FOOTPRINT* makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName );
262  void packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
263  void packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree );
264  void packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
265  void packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
266  void packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
267  void packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
274  void packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const;
275  void packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const;
278  void transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const;
281  void deleteTemplates();
283  typedef std::vector<ELAYER> ELAYERS;
284  typedef ELAYERS::const_iterator EITER;
286  int m_cu_map[17];
287  std::map<int, ELAYER> m_eagleLayers;
288  std::map<wxString, int> m_eagleLayersIds;
289  std::map<wxString, PCB_LAYER_ID> m_layer_map;
291  std::map<wxString, NETCLASSPTR> m_classMap;
292  wxString m_customRules;
311  unsigned m_doneCount;
313  unsigned m_totalCount;
317  int m_min_via;
320  wxString m_lib_path;
321  wxDateTime m_mod_time;
322 };
324 #endif // EAGLE_PLUGIN_H
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:44
Plugin class for import plugins that support remappable layers.
void loadAllSections(wxXmlNode *aDocument)
double rlMaxViaOuter
maximum copper annulus on via
Definition: eagle_plugin.h:120
int kicad_x(const ECOORD &x) const
Definition: eagle_plugin.h:189
std::map< wxString, ENET > NET_MAP
Definition: eagle_plugin.h:45
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:308
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:100
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:294
A progress reporter interface for use in multi-threaded environments.
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
Eagle element element.
Definition: eagle_parser.h:810
unsigned m_lastProgressCount
Definition: eagle_plugin.h:312
Keep track of what we are working on within a PTREE.
Definition: eagle_parser.h:110
double rlMaxPadTop
maximum copper annulus on through hole pads
Definition: eagle_plugin.h:116
void parse(wxXmlNode *aRules, std::function< void()> aCheckpoint)
percent over 100%.
int mlMinStopFrame
solder mask, minimum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:95
int srMinRoundness
corner rounding radius, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:107
std::map< wxString, int > m_eagleLayersIds
Eagle layer ids stored by layer name.
Definition: eagle_plugin.h:288
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
Definition: eagle_plugin.h:310
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:46
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:317
double rvViaOuter
copper annulus is this percent of via hole
Definition: eagle_plugin.h:118
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:302
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:295
int m_cu_map[17]
map eagle to KiCad, cu layers only.
Definition: eagle_plugin.h:286
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:149
unsigned m_doneCount
Definition: eagle_plugin.h:311
void packageWire(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
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:307
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN API or a portion o...
Definition: eagle_plugin.h:129
std::map< int, ELAYER > m_eagleLayers
Eagle layer data stored by layer number.
Definition: eagle_plugin.h:287
Eagle thru hole pad.
Definition: eagle_parser.h:706
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void packageRectangle(FOOTPRINT *aFootprint, wxXmlNode *aTree) const
void packagePad(FOOTPRINT *aFootprint, wxXmlNode *aTree)
wxString m_lib_path
Definition: eagle_plugin.h:320
int psElongationOffset
the offset of the hole within the "long" pad.
Definition: eagle_plugin.h:88
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:50
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
void orientFootprintAndText(FOOTPRINT *aFootprint, const EELEMENT &e, const EATTR *aNameAttr, const EATTR *aValueAttr)
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_plugin.h:41
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:121
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:315
int m_hole_count
generates unique footprint names from eagle "hole"s.
Definition: eagle_plugin.h:298
double srRoundness
corner rounding ratio for SMD pads (percentage)
Definition: eagle_plugin.h:104
int psElongationLong
Definition: eagle_plugin.h:86
int psFirst
Shape of the first pads.
Definition: eagle_plugin.h:102
void loadLibraries(wxXmlNode *aLibs)
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...
wxString m_customRules
Definition: eagle_plugin.h:292
void transferPad(const EPAD_COMMON &aEaglePad, PAD *aPad) const
Deletes the footprint templates list.
Parse an Eagle "attribute" XML element.
Definition: eagle_parser.h:594
std::vector< ELAYER > ELAYERS
Definition: eagle_plugin.h:283
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:97
void loadElements(wxXmlNode *aElements)
bool IsFootprintLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition: eagle_plugin.h:154
std::map< wxString, PCB_LAYER_ID > m_layer_map
Map of Eagle layers to KiCad layers.
Definition: eagle_plugin.h:289
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:191
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:693
A quick note on layer IDs:
Definition: layer_ids.h:65
std::map< wxString, FOOTPRINT * > FOOTPRINT_MAP
Definition: eagle_parser.h:50
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:269
ELAYERS::const_iterator EITER
Definition: eagle_plugin.h:284
wxDateTime m_mod_time
Definition: eagle_plugin.h:321
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:91
int m_min_annulus
smallest via annulus we find on Load(), in BIU.
Definition: eagle_plugin.h:318
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:300
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const PROPERTIES *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
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:316
double rvPadTop
top pad size as percent of drill size
Definition: eagle_plugin.h:112
void deleteTemplates()
void loadDesignRules(wxXmlNode *aDesignRules)
Definition: pad.h:57
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:101
double rlMinPadTop
minimum copper annulus on through hole pads
Definition: eagle_plugin.h:115
double rlMinViaOuter
minimum copper annulus on via
Definition: eagle_plugin.h:119
unsigned m_totalCount
for progress reporting
Definition: eagle_plugin.h:313
int mlMaxCreamFrame
solder paste mask, maximum size (Eagle mils, here nanometers)
Definition: eagle_plugin.h:98
int srMaxRoundness
Definition: eagle_plugin.h:110
std::map< wxString, NETCLASSPTR > m_classMap
Eagle class number to KiCad netclass.
Definition: eagle_plugin.h:291
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:188
int ToPcbUnits() const
Definition: eagle_parser.h:430
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 loadClasses(wxXmlNode *aClasses)
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:96
double mvCreamFrame
Definition: eagle_plugin.h:94