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>
|
|
|
|
* Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
|
|
// forward declaration on ptree template so we can confine use of big boost
|
|
|
|
// headers to only the implementation *.cpp file.
|
|
|
|
|
|
|
|
#include <boost/property_tree/ptree_fwd.hpp>
|
|
|
|
#include <boost/ptr_container/ptr_map.hpp>
|
2012-05-24 15:00:59 +00:00
|
|
|
#include <map>
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
class MODULE;
|
|
|
|
typedef boost::ptr_map< std::string, MODULE > MODULE_MAP;
|
|
|
|
|
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
struct ENET
|
|
|
|
{
|
|
|
|
int netcode;
|
|
|
|
std::string netname;
|
|
|
|
|
|
|
|
ENET( int aNetCode, const std::string& aNetName ) :
|
|
|
|
netcode( aNetCode ),
|
|
|
|
netname( aNetName )
|
|
|
|
{}
|
|
|
|
|
|
|
|
ENET() :
|
|
|
|
netcode( 0 )
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
typedef std::map< std::string, ENET > NET_MAP;
|
|
|
|
typedef NET_MAP::const_iterator NET_MAP_CITER;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
typedef boost::property_tree::ptree PTREE;
|
|
|
|
typedef const PTREE CPTREE;
|
|
|
|
|
2012-09-20 13:38:50 +00:00
|
|
|
struct EELEMENT;
|
2012-06-02 17:07:30 +00:00
|
|
|
class XPATH;
|
2012-06-05 04:39:37 +00:00
|
|
|
struct ERULES;
|
2012-06-07 01:49:43 +00:00
|
|
|
struct EATTR;
|
|
|
|
class TEXTE_MODULE;
|
2012-06-05 04:39:37 +00:00
|
|
|
|
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>--------------------------------------------------
|
|
|
|
const wxString& PluginName() const;
|
|
|
|
|
|
|
|
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties = NULL );
|
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
const wxString& GetFileExtension() const;
|
|
|
|
|
|
|
|
/*
|
2012-05-20 13:14:46 +00:00
|
|
|
void Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProperties = NULL );
|
|
|
|
|
|
|
|
wxArrayString FootprintEnumerate( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL);
|
|
|
|
|
|
|
|
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, PROPERTIES* aProperties = NULL );
|
|
|
|
|
|
|
|
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, PROPERTIES* aProperties = NULL );
|
|
|
|
|
|
|
|
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName );
|
|
|
|
|
|
|
|
void FootprintLibCreate( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL );
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
bool FootprintLibDelete( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
bool IsFootprintLibWritable( const wxString& aLibraryPath );
|
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:
|
|
|
|
|
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
|
|
|
std::string m_err_path; ///< snapshot m_xpath contentx into here on exception
|
2012-05-24 15:00:59 +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.
|
|
|
|
///< lookup key is libname.packagename
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
|
|
|
|
BOARD* m_board; ///< which BOARD is being worked on, no ownership here
|
|
|
|
double mm_per_biu; ///< how many mm in each BIU
|
|
|
|
double biu_per_mm; ///< how many bius in a mm
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
|
|
|
|
void init( PROPERTIES* aProperties );
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Convert an Eagle distance to a KiCad distance.
|
2012-05-20 13:14:46 +00:00
|
|
|
int kicad( double d ) const;
|
2012-05-22 17:51:18 +00:00
|
|
|
int kicad_y( double y ) const { return -kicad( y ); }
|
2012-05-20 13:14:46 +00:00
|
|
|
int kicad_x( double x ) const { return kicad( x ); }
|
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
|
|
|
|
wxSize kicad_fontz( double 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.
|
2012-05-22 17:51:18 +00:00
|
|
|
static int kicad_layer( int aLayer );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Convert a KiCad distance to an Eagle distance.
|
2012-05-20 13:14:46 +00:00
|
|
|
double eagle( BIU d ) const { return mm_per_biu * d; }
|
|
|
|
double eagle_x( BIU x ) const { return eagle( x ); }
|
|
|
|
double eagle_y( BIU y ) const { return eagle( y ); }
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/// encapsulate the BIU formatting tricks in one place.
|
|
|
|
int biuSprintf( char* buf, BIU aValue ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function fmtBIU
|
|
|
|
* converts a BIU to engineering units by scaling and formatting to ASCII.
|
|
|
|
* This function is the complement of biuParse(). One has to know what the
|
|
|
|
* other is doing.
|
|
|
|
*/
|
|
|
|
std::string fmtBIU( BIU aValue ) const;
|
|
|
|
|
|
|
|
std::string fmtBIUPair( BIU first, BIU second ) const;
|
|
|
|
|
|
|
|
std::string fmtBIUPoint( const wxPoint& aPoint ) const
|
|
|
|
{
|
|
|
|
return fmtBIUPair( aPoint.x, aPoint.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fmtBIUSize( const wxSize& aSize ) const
|
|
|
|
{
|
|
|
|
return fmtBIUPair( aSize.x, aSize.y );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// all these loadXXX() throw IO_ERROR or ptree_error exceptions:
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
void loadAllSections( CPTREE& aDocument );
|
2012-06-05 04:39:37 +00:00
|
|
|
void loadDesignRules( CPTREE& aDesignRules );
|
2012-06-01 07:39:32 +00:00
|
|
|
void loadLayerDefs( CPTREE& aLayers );
|
|
|
|
void loadPlain( CPTREE& aPlain );
|
|
|
|
void loadSignals( CPTREE& aSignals );
|
|
|
|
void loadLibraries( CPTREE& aLibs );
|
|
|
|
void loadElements( CPTREE& 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.
|
|
|
|
*/
|
|
|
|
std::string fmtDEG( double aAngle ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function makeModule
|
|
|
|
* creates a MODULE from an Eagle package.
|
|
|
|
*/
|
|
|
|
MODULE* makeModule( CPTREE& aPackage, const std::string& aPkgName ) const;
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void packageWire( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packagePad( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packageText( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packageRectangle( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packagePolygon( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packageCircle( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packageHole( MODULE* aModule, CPTREE& aTree ) const;
|
|
|
|
void packageSMD( MODULE* aModule, CPTREE& aTree ) const;
|
2012-05-20 13:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EAGLE_PLUGIN_H_
|