2012-05-20 13:14:46 +00:00
|
|
|
#ifndef EAGLE_PLUGIN_H_
|
|
|
|
#define EAGLE_PLUGIN_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2017-06-11 20:20:44 +00:00
|
|
|
* Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-05-20 13:14:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <io_mgr.h>
|
2013-03-30 17:24:04 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2017-04-07 11:40:34 +00:00
|
|
|
#include <eagle_parser.h>
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
#include <map>
|
2017-04-07 11:40:34 +00:00
|
|
|
#include <wx/xml/xml.h>
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
typedef std::map<wxString, MODULE*> MODULE_MAP;
|
|
|
|
typedef std::map<wxString, ENET> NET_MAP;
|
|
|
|
typedef NET_MAP::const_iterator NET_MAP_CITER;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
/// subset of eagle.drawing.board.designrules in the XML document
|
|
|
|
struct ERULES
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
int psElongationLong; ///< percent over 100%. 0-> not elongated, 100->twice as wide as is tall
|
|
|
|
///< Goes into making a scaling factor for "long" pads.
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
int psElongationOffset; ///< the offset of the hole within the "long" pad.
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
double rvPadTop; ///< top pad size as percent of drill size
|
|
|
|
// double rvPadBottom; ///< bottom pad size as percent of drill size
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
double rlMinPadTop; ///< minimum copper annulus on through hole pads
|
|
|
|
double rlMaxPadTop; ///< maximum copper annulus on through hole pads
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
double rvViaOuter; ///< copper annulus is this percent of via hole
|
|
|
|
double rlMinViaOuter; ///< minimum copper annulus on via
|
|
|
|
double rlMaxViaOuter; ///< maximum copper annulus on via
|
|
|
|
double mdWireWire; ///< wire to wire spacing I presume.
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
ERULES() :
|
|
|
|
psElongationLong ( 100 ),
|
|
|
|
psElongationOffset ( 0 ),
|
|
|
|
rvPadTop ( 0.25 ),
|
|
|
|
// rvPadBottom ( 0.25 ),
|
|
|
|
rlMinPadTop ( Mils2iu( 10 ) ),
|
|
|
|
rlMaxPadTop ( Mils2iu( 20 ) ),
|
|
|
|
|
|
|
|
rvViaOuter ( 0.25 ),
|
|
|
|
rlMinViaOuter ( Mils2iu( 10 ) ),
|
|
|
|
rlMaxViaOuter ( Mils2iu( 20 ) ),
|
|
|
|
mdWireWire ( 0 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
void parse( wxXmlNode* aRules );
|
|
|
|
};
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
/**
|
|
|
|
* Class EAGLE_PLUGIN
|
2012-06-02 17:07:30 +00:00
|
|
|
* works with Eagle 6.x XML board files and footprints to implement the
|
|
|
|
* Pcbnew PLUGIN API, or a portion of it.
|
2012-05-20 13:14:46 +00:00
|
|
|
*/
|
|
|
|
class EAGLE_PLUGIN : public PLUGIN
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//-----<PUBLIC PLUGIN API>--------------------------------------------------
|
2016-09-24 18:53:15 +00:00
|
|
|
const wxString PluginName() const override;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
|
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
const wxString GetFileExtension() const override;
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties = NULL) override;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2016-09-25 17:06:49 +00:00
|
|
|
const PROPERTIES* aProperties = NULL ) override;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
bool IsFootprintLibWritable( const wxString& aLibraryPath ) override
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
|
|
|
return false; // until someone writes others like FootprintSave(), etc.
|
|
|
|
}
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void FootprintLibOptions( PROPERTIES* aProperties ) const override;
|
2013-11-20 16:35:03 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
/*
|
2013-09-25 19:17:06 +00:00
|
|
|
void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties = NULL );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
|
2012-05-24 15:00:59 +00:00
|
|
|
*/
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
//-----</PUBLIC PLUGIN API>-------------------------------------------------
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
typedef int BIU;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
EAGLE_PLUGIN();
|
|
|
|
~EAGLE_PLUGIN();
|
|
|
|
|
|
|
|
private:
|
2017-10-18 07:53:07 +00:00
|
|
|
typedef std::vector<ELAYER> ELAYERS;
|
|
|
|
typedef ELAYERS::const_iterator EITER;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-03-13 16:17:16 +00:00
|
|
|
int m_cu_map[17]; ///< map eagle to kicad, cu layers only.
|
2017-10-18 16:02:36 +00:00
|
|
|
std::map<int, ELAYER> m_eagleLayers; ///< Eagle layers data stored by the layer number
|
2013-03-13 16:17:16 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
ERULES* m_rules; ///< Eagle design rules.
|
2012-06-02 17:07:30 +00:00
|
|
|
XPATH* m_xpath; ///< keeps track of what we are working on within
|
|
|
|
///< XML document during a Load().
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
int m_hole_count; ///< generates unique module names from eagle "hole"s.
|
|
|
|
|
|
|
|
NET_MAP m_pads_to_nets; ///< net list
|
|
|
|
|
|
|
|
MODULE_MAP m_templates; ///< is part of a MODULE factory that operates
|
2012-05-22 17:51:18 +00:00
|
|
|
///< using copy construction.
|
2013-01-02 04:05:48 +00:00
|
|
|
///< lookup key is either libname.packagename or simply
|
|
|
|
///< packagename if FootprintLoad() or FootprintEnumberate()
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
const PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
|
2012-06-02 17:07:30 +00:00
|
|
|
BOARD* m_board; ///< which BOARD is being worked on, no ownership here
|
2013-03-14 22:54:47 +00:00
|
|
|
|
|
|
|
int m_min_trace; ///< smallest trace we find on Load(), in BIU.
|
|
|
|
int m_min_via; ///< smallest via we find on Load(), in BIU.
|
|
|
|
int m_min_via_hole; ///< smallest via diameter hole we find on Load(), in BIU.
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
wxString m_lib_path;
|
|
|
|
wxDateTime m_mod_time;
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
|
2013-09-25 19:17:06 +00:00
|
|
|
void init( const PROPERTIES* aProperties );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-03-13 16:38:54 +00:00
|
|
|
void clear_cu_map();
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Convert an Eagle distance to a KiCad distance.
|
2017-10-17 08:18:54 +00:00
|
|
|
int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
|
|
|
|
int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// create a font size (fontz) from an eagle font size scalar
|
2017-10-17 08:18:54 +00:00
|
|
|
wxSize kicad_fontz( const ECOORD& d ) const;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Convert an Eagle layer to a KiCad layer.
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID kicad_layer( int aLayer ) const;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2017-10-18 16:02:36 +00:00
|
|
|
/// Get Eagle layer name by its number
|
2017-12-14 09:37:32 +00:00
|
|
|
const wxString& eagle_layer_name( int aLayer ) const;
|
2017-10-18 16:02:36 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
/// This PLUGIN only caches one footprint library, this determines which one.
|
|
|
|
void cacheLib( const wxString& aLibraryPath );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
/// get a file's or dir's modification time.
|
|
|
|
static wxDateTime getModificationTime( const wxString& aPath );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
// all these loadXXX() throw IO_ERROR or ptree_error exceptions:
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void loadAllSections( wxXmlNode* aDocument );
|
|
|
|
void loadDesignRules( wxXmlNode* aDesignRules );
|
|
|
|
void loadLayerDefs( wxXmlNode* aLayers );
|
|
|
|
void loadPlain( wxXmlNode* aPlain );
|
|
|
|
void loadSignals( wxXmlNode* aSignals );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function loadLibrary
|
|
|
|
* loads the Eagle "library" XML element, which can occur either under
|
|
|
|
* a "libraries" element (if a *.brd file) or under a "drawing" element if a
|
|
|
|
* *.lbr file.
|
|
|
|
* @param aLib is the portion of the loaded XML document tree that is the "library"
|
|
|
|
* element.
|
|
|
|
* @param aLibName is a pointer to the library name or NULL. If NULL this means
|
|
|
|
* we are loading a *.lbr not a *.brd file and the key used in m_templates is to exclude
|
|
|
|
* the library name.
|
|
|
|
*/
|
2017-12-14 09:37:32 +00:00
|
|
|
void loadLibrary( wxXmlNode* aLib, const wxString* aLibName );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void loadLibraries( wxXmlNode* aLibs );
|
|
|
|
void loadElements( wxXmlNode* aElements );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
void orientModuleAndText( MODULE* m, const EELEMENT& e, const EATTR* nameAttr, const EATTR* valueAttr );
|
|
|
|
void orientModuleText( MODULE* m, const EELEMENT& e, TEXTE_MODULE* txt, const EATTR* a );
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// move the BOARD into the center of the page
|
|
|
|
void centerBoard();
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
/**
|
|
|
|
* Function fmtDEG
|
|
|
|
* formats an angle in a way particular to a board file format. This function
|
|
|
|
* is the opposite or complement of degParse(). One has to know what the
|
|
|
|
* other is doing.
|
|
|
|
*/
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString fmtDEG( double aAngle ) const;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function makeModule
|
|
|
|
* creates a MODULE from an Eagle package.
|
|
|
|
*/
|
2017-12-14 09:37:32 +00:00
|
|
|
MODULE* makeModule( wxXmlNode* aPackage, const wxString& aPkgName ) const;
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
void packageWire( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packagePad( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packageText( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packageRectangle( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packagePolygon( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packageHole( MODULE* aModule, wxXmlNode* aTree ) const;
|
|
|
|
void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
|
2017-07-10 09:44:56 +00:00
|
|
|
|
|
|
|
///> Deletes the footprint templates list
|
|
|
|
void deleteTemplates();
|
2012-05-20 13:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EAGLE_PLUGIN_H_
|