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-2016 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 
31 
32 // forward declaration on ptree template so we can confine use of big boost
33 // headers to only the implementation *.cpp file.
34 
35 #include <boost/property_tree/ptree_fwd.hpp>
36 #include <boost/ptr_container/ptr_map.hpp>
37 #include <map>
38 
39 
40 class MODULE;
41 typedef boost::ptr_map< std::string, MODULE > MODULE_MAP;
42 
43 
44 struct ENET
45 {
46  int netcode;
47  std::string netname;
48 
49  ENET( int aNetCode, const std::string& aNetName ) :
50  netcode( aNetCode ),
51  netname( aNetName )
52  {}
53 
54  ENET() :
55  netcode( 0 )
56  {}
57 };
58 
59 typedef std::map< std::string, ENET > NET_MAP;
60 typedef NET_MAP::const_iterator NET_MAP_CITER;
61 
62 typedef boost::property_tree::ptree PTREE;
63 typedef const PTREE CPTREE;
64 
65 struct EELEMENT;
66 class XPATH;
67 struct ERULES;
68 struct EATTR;
69 class TEXTE_MODULE;
70 
71 
77 class EAGLE_PLUGIN : public PLUGIN
78 {
79 public:
80 
81  //-----<PUBLIC PLUGIN API>--------------------------------------------------
82  const wxString PluginName() const override;
83 
84  BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ) override;
85 
86  const wxString GetFileExtension() const override;
87 
88  wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL) override;
89 
90  MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
91  const PROPERTIES* aProperties = NULL ) override;
92 
93  bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
94  {
95  return false; // until someone writes others like FootprintSave(), etc.
96  }
97 
98  void FootprintLibOptions( PROPERTIES* aProperties ) const override;
99 
100 /*
101  void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
102 
103  void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
104 
105  void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
106 
107  void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
108 
109  bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
110 */
111 
112  //-----</PUBLIC PLUGIN API>-------------------------------------------------
113 
114  typedef int BIU;
115 
116  EAGLE_PLUGIN();
117  ~EAGLE_PLUGIN();
118 
119 private:
120 
121  int m_cu_map[17];
122 
125 
128 
130 
132 
138 
140  int m_min_via;
142 
143  double mm_per_biu;
144  double biu_per_mm;
145 
146  wxString m_lib_path;
147  wxDateTime m_mod_time;
148 
150  void init( const PROPERTIES* aProperties );
151 
152  void clear_cu_map();
153 
155  int kicad( double d ) const;
156  int kicad_y( double y ) const { return -kicad( y ); }
157  int kicad_x( double x ) const { return kicad( x ); }
158 
160  wxSize kicad_fontz( double d ) const;
161 
163  LAYER_ID kicad_layer( int aLayer ) const;
164 
166  double eagle( BIU d ) const { return mm_per_biu * d; }
167  double eagle_x( BIU x ) const { return eagle( x ); }
168  double eagle_y( BIU y ) const { return eagle( y ); }
169 
171  void cacheLib( const wxString& aLibraryPath );
172 
174  static wxDateTime getModificationTime( const wxString& aPath );
175 
176  // all these loadXXX() throw IO_ERROR or ptree_error exceptions:
177 
178  void loadAllSections( CPTREE& aDocument );
179  void loadDesignRules( CPTREE& aDesignRules );
180  void loadLayerDefs( CPTREE& aLayers );
181  void loadPlain( CPTREE& aPlain );
182  void loadSignals( CPTREE& aSignals );
183 
195  void loadLibrary( CPTREE& aLib, const std::string* aLibName );
196 
197  void loadLibraries( CPTREE& aLibs );
198  void loadElements( CPTREE& aElements );
199 
200  void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
201  void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
202 
203 
205  void centerBoard();
206 
213  std::string fmtDEG( double aAngle ) const;
214 
219  MODULE* makeModule( CPTREE& aPackage, const std::string& aPkgName ) const;
220 
221  void packageWire( MODULE* aModule, CPTREE& aTree ) const;
222  void packagePad( MODULE* aModule, CPTREE& aTree ) const;
223  void packageText( MODULE* aModule, CPTREE& aTree ) const;
224  void packageRectangle( MODULE* aModule, CPTREE& aTree ) const;
225  void packagePolygon( MODULE* aModule, CPTREE& aTree ) const;
226  void packageCircle( MODULE* aModule, CPTREE& aTree ) const;
227  void packageHole( MODULE* aModule, CPTREE& aTree ) const;
228  void packageSMD( MODULE* aModule, CPTREE& aTree ) const;
229 };
230 
231 #endif // EAGLE_PLUGIN_H_
void packageCircle(MODULE *aModule, CPTREE &aTree) const
MODULE * makeModule(CPTREE &aPackage, const std::string &aPkgName) const
Function makeModule creates a MODULE from an Eagle package.
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:137
std::string fmtDEG(double aAngle) const
Function fmtDEG formats an angle in a way particular to a board file format.
void FootprintLibOptions(PROPERTIES *aProperties) const override
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
void packagePolygon(MODULE *aModule, CPTREE &aTree) const
void loadAllSections(CPTREE &aDocument)
ERULES * m_rules
Eagle design rules.
Definition: eagle_plugin.h:123
void packageText(MODULE *aModule, CPTREE &aTree) const
const PTREE CPTREE
Definition: eagle_plugin.h:63
std::string netname
Definition: eagle_plugin.h:47
Eagle element element.
Class XPATH keeps track of what we are working on within a PTREE.
ENET()
Definition: eagle_plugin.h:54
std::map< std::string, ENET > NET_MAP
Definition: eagle_plugin.h:59
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...
wxArrayString FootprintEnumerate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
Function FootprintEnumerate returns a list of footprint names contained within the library at aLibrar...
NET_MAP::const_iterator NET_MAP_CITER
Definition: eagle_plugin.h:60
void init(const PROPERTIES *aProperties)
initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
double eagle_x(BIU x) const
Definition: eagle_plugin.h:167
wxSize kicad_fontz(double d) const
create a font size (fontz) from an eagle font size scalar
void loadLibrary(CPTREE &aLib, const std::string *aLibName)
Function loadLibrary loads the Eagle "library" XML element, which can occur either under a "libraries...
int m_min_via
smallest via we find on Load(), in BIU.
Definition: eagle_plugin.h:140
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:124
int m_cu_map[17]
map eagle to kicad, cu layers only.
Definition: eagle_plugin.h:121
int kicad_y(double y) const
Definition: eagle_plugin.h:156
void loadDesignRules(CPTREE &aDesignRules)
int m_min_via_hole
smallest via diameter hole we find on Load(), in BIU.
Definition: eagle_plugin.h:141
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:136
Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN...
Definition: eagle_plugin.h:77
void packagePad(MODULE *aModule, CPTREE &aTree) const
double eagle_y(BIU y) const
Definition: eagle_plugin.h:168
wxString m_lib_path
Definition: eagle_plugin.h:146
void packageRectangle(MODULE *aModule, CPTREE &aTree) const
subset of eagle.drawing.board.designrules in the XML document
void packageSMD(MODULE *aModule, CPTREE &aTree) const
int kicad_x(double x) const
Definition: eagle_plugin.h:157
void loadSignals(CPTREE &aSignals)
static wxDateTime getModificationTime(const wxString &aPath)
get a file's or dir's modification time.
int m_min_trace
smallest trace we find on Load(), in BIU.
Definition: eagle_plugin.h:139
double mm_per_biu
how many mm in each BIU
Definition: eagle_plugin.h:143
int m_hole_count
generates unique module names from eagle "hole"s.
Definition: eagle_plugin.h:127
void packageHole(MODULE *aModule, CPTREE &aTree) const
void orientModuleAndText(MODULE *m, const EELEMENT &e, const EATTR *nameAttr, const EATTR *valueAttr)
Eagle "attribute" XML element, no foolin'.
void loadLibraries(CPTREE &aLibs)
void packageWire(MODULE *aModule, CPTREE &aTree) const
boost::property_tree::ptree PTREE
Definition: eagle_plugin.h:62
int netcode
Definition: eagle_plugin.h:46
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:93
LAYER_ID kicad_layer(int aLayer) const
Convert an Eagle layer to a KiCad layer.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
void loadPlain(CPTREE &aPlain)
boost::ptr_map< std::string, MODULE > MODULE_MAP
Definition: eagle_plugin.h:40
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
MODULE_MAP m_templates
is part of a MODULE factory that operates using copy construction.
Definition: eagle_plugin.h:131
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:193
wxDateTime m_mod_time
Definition: eagle_plugin.h:147
NET_MAP m_pads_to_nets
net list
Definition: eagle_plugin.h:129
double eagle(BIU d) const
Convert a KiCad distance to an Eagle distance.
Definition: eagle_plugin.h:166
double biu_per_mm
how many bius in a mm
Definition: eagle_plugin.h:144
const wxString PluginName() const override
Function PluginName returns a brief hard coded name for this PLUGIN.
void loadElements(CPTREE &aElements)
ENET(int aNetCode, const std::string &aNetName)
Definition: eagle_plugin.h:49
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...
const wxString GetFileExtension() const override
Function GetFileExtension returns the file extension for the PLUGIN.
void loadLayerDefs(CPTREE &aLayers)
void orientModuleText(MODULE *m, const EELEMENT &e, TEXTE_MODULE *txt, const EATTR *a)
int kicad(double d) const
Convert an Eagle distance to a KiCad distance.