Commit 5cda6bc1 authored by Dick Hollenbeck's avatar Dick Hollenbeck

eagle plugin first work

parent ea467e67
...@@ -117,6 +117,7 @@ set(PCB_COMMON_SRCS ...@@ -117,6 +117,7 @@ set(PCB_COMMON_SRCS
../pcbnew/sel_layer.cpp ../pcbnew/sel_layer.cpp
../pcbnew/pcb_plot_params.cpp ../pcbnew/pcb_plot_params.cpp
../pcbnew/io_mgr.cpp ../pcbnew/io_mgr.cpp
../pcbnew/eagle_plugin.cpp
../pcbnew/legacy_plugin.cpp ../pcbnew/legacy_plugin.cpp
../pcbnew/kicad_plugin.cpp ../pcbnew/kicad_plugin.cpp
pcb_plot_params_keywords.cpp pcb_plot_params_keywords.cpp
......
...@@ -110,7 +110,6 @@ set(PCBNEW_SRCS ...@@ -110,7 +110,6 @@ set(PCBNEW_SRCS
drc.cpp drc.cpp
drc_clearance_test_functions.cpp drc_clearance_test_functions.cpp
drc_marker_functions.cpp drc_marker_functions.cpp
eagle_plugin.cpp
edgemod.cpp edgemod.cpp
edit.cpp edit.cpp
editedge.cpp editedge.cpp
......
...@@ -232,7 +232,7 @@ public: ...@@ -232,7 +232,7 @@ public:
unsigned m_RatsnestEndIdx; // Ending point of ratsnests of this net unsigned m_RatsnestEndIdx; // Ending point of ratsnests of this net
// (excluded) in this buffer // (excluded) in this buffer
NETINFO_ITEM( BOARD_ITEM* aParent ); NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName = NETCLASS::Default, int aNetCode = 0 );
~NETINFO_ITEM(); ~NETINFO_ITEM();
/** /**
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
/* class NETINFO_ITEM: handle data relative to a given net */ /* class NETINFO_ITEM: handle data relative to a given net */
/*********************************************************/ /*********************************************************/
NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent ) NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int aNetCode )
{ {
SetNet( 0 ); SetNet( aNetCode );
m_NbNodes = 0; m_NbNodes = 0;
m_NbLink = 0; m_NbLink = 0;
m_NbNoconn = 0; m_NbNoconn = 0;
...@@ -33,7 +33,7 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent ) ...@@ -33,7 +33,7 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent )
// general buffer of ratsnest // general buffer of ratsnest
m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
m_NetClassName = NETCLASS::Default; m_NetClassName = aNetName;
m_NetClass = 0; m_NetClass = 0;
} }
......
...@@ -82,7 +82,7 @@ void NETINFO_LIST::buildListOfNets() ...@@ -82,7 +82,7 @@ void NETINFO_LIST::buildListOfNets()
// Create and add the "unconnected net", always existing, // Create and add the "unconnected net", always existing,
// used to handle pads and tracks that are not member of a "real" net // used to handle pads and tracks that are not member of a "real" net
net_item = new NETINFO_ITEM( (BOARD_ITEM*) m_Parent ); net_item = new NETINFO_ITEM( m_Parent );
AppendNet( net_item ); AppendNet( net_item );
// Build the PAD list, sorted by net // Build the PAD list, sorted by net
...@@ -108,15 +108,15 @@ void NETINFO_LIST::buildListOfNets() ...@@ -108,15 +108,15 @@ void NETINFO_LIST::buildListOfNets()
if( last_pad == NULL || ( pad->GetNetname() != last_pad->GetNetname() ) ) if( last_pad == NULL || ( pad->GetNetname() != last_pad->GetNetname() ) )
{ {
netcode++; netcode++;
net_item = new NETINFO_ITEM( (BOARD_ITEM*)m_Parent ); net_item = new NETINFO_ITEM( m_Parent, pad->GetNetname(), netcode );
net_item->SetNet( netcode );
net_item->SetNetname( pad->GetNetname() );
AppendNet( net_item ); AppendNet( net_item );
} }
pad->SetNet( netcode ); pad->SetNet( netcode );
net_item->m_PadInNetList.push_back( pad ); net_item->m_PadInNetList.push_back( pad );
nodes_count ++;
nodes_count++;
last_pad = pad; last_pad = pad;
} }
......
This diff is collapsed.
#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>
class MODULE;
typedef boost::ptr_map< std::string, MODULE > MODULE_MAP;
/*
#include
namespace boost {
namespace property_tree
{
template < class Key, class Data, class KeyCompare = std::less<Key> >
class basic_ptree;
typedef basic_ptree< std::string, std::string > ptree;
}
}
*/
typedef boost::property_tree::ptree PTREE;
typedef const PTREE CPTREE;
struct EWIRE ///< Eagle wire
{
double x1;
double y1;
double x2;
double y2;
double width;
int layer;
};
/**
* Class EAGLE_PLUGIN
* works with Eagle 6.x XML board files and footprints.
*/
class EAGLE_PLUGIN : public PLUGIN
{
public:
//-----<PUBLIC PLUGIN API>--------------------------------------------------
const wxString& PluginName() const;
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties = NULL );
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 );
void FootprintLibDelete( const wxString& aLibraryPath, PROPERTIES* aProperties = NULL );
bool IsFootprintLibWritable( const wxString& aLibraryPath );
const wxString& GetFileExtension() const;
//-----</PUBLIC PLUGIN API>-------------------------------------------------
typedef int BIU;
EAGLE_PLUGIN();
~EAGLE_PLUGIN();
private:
MODULE_MAP m_modules; ///< is a factory by use of MODULE copy constructor,
///< lookup is based on libname.packagename
PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
BOARD* m_board; ///< which BOARD, no ownership here
double mm_per_biu; ///< how many mm in each BIU
double biu_per_mm; ///< how many bius in a mm
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void init( PROPERTIES* aProperties );
int kicad( double d ) const;
int kicad_y( double y ) const { return kicad( y ); }
int kicad_x( double x ) const { return kicad( x ); }
int kicad_layer( int aLayer ) const;
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
/**
* Function dblParse
* parses an ASCII decimal floating point value and reports any error by throwing
* an exception using the xpath in the error message text.
*
* @param aValue is the ASCII value in C locale form with possible leading whitespace
*
* @param aXpath tells where the value is within the XML document.
*
* @return double - aValue in binary, not scaled.
*/
static double dblParse( const char* aValue, const std::string& aXpath );
/**
* Function biuParse
* parses an ASCII decimal floating point value and scales it into a BIU
* according to the current mm_per_biu. This fuction is the complement of
* fmtBIU(). One has to know what the other is doing.
*
* @param aValue is the ASCII value in C locale form with possible leading whitespace
*
* @param aXpath tells where the value is within the XML document.
*
* @return BIU - the converted Board Internal Unit.
*/
BIU biuParse( const char* aValue, const std::string& aXpath );
/**
* Function degParse
* parses an ASCII decimal floating point value which is certainly an angle. This
* is a dedicated function for encapsulating support for the migration from
* tenths of degrees to degrees in floating point. This function is the complement of
* fmtDEG(). One has to know what the other is doing.
*
* @param aValue is the ASCII value in C locale form with possible leading whitespace
*
* @param nptrptr may be NULL, but if not, then it tells where to put a
* pointer to the next unconsumed input text. See "man strtod" for more information.
*
* @return double - the string converted to a primitive double type
*/
double degParse( const char* aValue, const char** nptrptr = NULL );
/// 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:
void loadAllSections( CPTREE& aEagleBoard, const std::string& aXpath, bool aAppendToMe );
void loadNetsAndTracks( CPTREE& aSignals, const std::string& aXpath );
void loadModules( CPTREE& aLibs, const std::string& aXpath );
/**
* Function wire
* converts a <wire>'s xml attributes to binary without additional conversion.
* @return EWIRE - an Eagle <wire> object in binary.
*/
EWIRE wire( CPTREE aWire ) const;
/**
* 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;
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;
};
#endif // EAGLE_PLUGIN_H_
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <io_mgr.h> #include <io_mgr.h>
#include <legacy_plugin.h> #include <legacy_plugin.h>
#include <kicad_plugin.h> #include <kicad_plugin.h>
#include <eagle_plugin.h>
#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." ) #define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." )
...@@ -60,10 +61,8 @@ PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType ) ...@@ -60,10 +61,8 @@ PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType )
case KICAD: case KICAD:
return new PCB_IO(); return new PCB_IO();
/*
case EAGLE: case EAGLE:
return &eagle_plugin; return new EAGLE_PLUGIN();
*/
} }
return NULL; return NULL;
......
...@@ -50,10 +50,10 @@ public: ...@@ -50,10 +50,10 @@ public:
{ {
LEGACY, //< Legacy Pcbnew file formats prior to s-expression. LEGACY, //< Legacy Pcbnew file formats prior to s-expression.
KICAD, //< S-expression Pcbnew file format. KICAD, //< S-expression Pcbnew file format.
EAGLE,
// add your type here. // add your type here.
// EAGLE,
// ALTIUM, // ALTIUM,
// etc. // etc.
}; };
......
...@@ -88,11 +88,17 @@ ...@@ -88,11 +88,17 @@
#include <wx/ffile.h> #include <wx/ffile.h>
typedef LEGACY_PLUGIN::BIU BIU;
#define VERSION_ERROR_FORMAT _( "File '%s' is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file." ) #define VERSION_ERROR_FORMAT _( "File '%s' is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file." )
#define UNKNOWN_GRAPHIC_FORMAT _( "unknown graphic type: %d") #define UNKNOWN_GRAPHIC_FORMAT _( "unknown graphic type: %d")
#define UNKNOWN_PAD_FORMAT _( "unknown pad type: %d") #define UNKNOWN_PAD_FORMAT _( "unknown pad type: %d")
#define UNKNOWN_PAD_ATTRIBUTE _( "unknown pad attribute: %d" ) #define UNKNOWN_PAD_ATTRIBUTE _( "unknown pad attribute: %d" )
// Old internal units definition (UI = decimil) // Old internal units definition (UI = decimil)
#define PCB_LEGACY_INTERNAL_UNIT 10000 #define PCB_LEGACY_INTERNAL_UNIT 10000
...@@ -3729,7 +3735,7 @@ void LEGACY_PLUGIN::savePCB_TEXT( const TEXTE_PCB* me ) const ...@@ -3729,7 +3735,7 @@ void LEGACY_PLUGIN::savePCB_TEXT( const TEXTE_PCB* me ) const
#include <boost/ptr_container/ptr_map.hpp> #include <boost/ptr_container/ptr_map.hpp>
#include <wx/filename.h> #include <wx/filename.h>
typedef boost::ptr_map< wxString, MODULE > MODULE_MAP; typedef boost::ptr_map< std::string, MODULE > MODULE_MAP;
typedef MODULE_MAP::iterator MODULE_ITER; typedef MODULE_MAP::iterator MODULE_ITER;
typedef MODULE_MAP::const_iterator MODULE_CITER; typedef MODULE_MAP::const_iterator MODULE_CITER;
...@@ -3912,8 +3918,7 @@ void FPL_CACHE::LoadModules( LINE_READER* aReader ) ...@@ -3912,8 +3918,7 @@ void FPL_CACHE::LoadModules( LINE_READER* aReader )
{ {
MODULE* m = m_owner->LoadMODULE(); MODULE* m = m_owner->LoadMODULE();
// wxString footprintName = m->GetReference(); std::string footprintName = TO_UTF8( m->GetLibRef() );
wxString footprintName = m->GetLibRef();
/* /*
...@@ -3944,11 +3949,15 @@ void FPL_CACHE::LoadModules( LINE_READER* aReader ) ...@@ -3944,11 +3949,15 @@ void FPL_CACHE::LoadModules( LINE_READER* aReader )
{ {
bool nameOK = false; bool nameOK = false;
int version = 2; int version = 2;
char buf[48];
while( !nameOK ) while( !nameOK )
{ {
wxString newName = footprintName; std::string newName = footprintName;
newName << wxT( "_v" ) << version++;
newName += "_v";
sprintf( buf, "%d", version++ );
newName += buf;
it = m_modules.find( newName ); it = m_modules.find( newName );
...@@ -3956,7 +3965,7 @@ void FPL_CACHE::LoadModules( LINE_READER* aReader ) ...@@ -3956,7 +3965,7 @@ void FPL_CACHE::LoadModules( LINE_READER* aReader )
{ {
nameOK = true; nameOK = true;
m->SetLibRef( newName ); m->SetLibRef( FROM_UTF8( newName.c_str() ) );
std::pair<MODULE_ITER, bool> r = m_modules.insert( newName, m ); std::pair<MODULE_ITER, bool> r = m_modules.insert( newName, m );
wxASSERT_MSG( r.second, wxT( "error doing cache insert using guaranteed unique name" ) ); wxASSERT_MSG( r.second, wxT( "error doing cache insert using guaranteed unique name" ) );
...@@ -4035,7 +4044,7 @@ void FPL_CACHE::SaveIndex( FILE* aFile ) ...@@ -4035,7 +4044,7 @@ void FPL_CACHE::SaveIndex( FILE* aFile )
for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it ) for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it )
{ {
fprintf( aFile, "%s\n", TO_UTF8( it->first ) ); fprintf( aFile, "%s\n", it->first.c_str() );
} }
fprintf( aFile, "$EndINDEX\n" ); fprintf( aFile, "$EndINDEX\n" );
...@@ -4081,7 +4090,7 @@ wxArrayString LEGACY_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, P ...@@ -4081,7 +4090,7 @@ wxArrayString LEGACY_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, P
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{ {
ret.Add( it->first ); ret.Add( FROM_UTF8( it->first.c_str() ) );
} }
return ret; return ret;
...@@ -4099,7 +4108,7 @@ MODULE* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxStri ...@@ -4099,7 +4108,7 @@ MODULE* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxStri
const MODULE_MAP& mods = m_cache->m_modules; const MODULE_MAP& mods = m_cache->m_modules;
MODULE_CITER it = mods.find( aFootprintName ); MODULE_CITER it = mods.find( TO_UTF8( aFootprintName ) );
if( it == mods.end() ) if( it == mods.end() )
{ {
...@@ -4129,7 +4138,7 @@ void LEGACY_PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* a ...@@ -4129,7 +4138,7 @@ void LEGACY_PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* a
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) ); THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) );
} }
wxString footprintName = aFootprint->GetLibRef(); std::string footprintName = TO_UTF8( aFootprint->GetLibRef() );
MODULE_MAP& mods = m_cache->m_modules; MODULE_MAP& mods = m_cache->m_modules;
...@@ -4173,7 +4182,9 @@ void LEGACY_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxStrin ...@@ -4173,7 +4182,9 @@ void LEGACY_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxStrin
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) ); THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) );
} }
size_t erasedCount = m_cache->m_modules.erase( aFootprintName ); std::string footprintName = TO_UTF8( aFootprintName );
size_t erasedCount = m_cache->m_modules.erase( footprintName );
if( erasedCount != 1 ) if( erasedCount != 1 )
{ {
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1" #define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
#define FOOTPRINT_LIBRARY_HEADER_CNT 18 #define FOOTPRINT_LIBRARY_HEADER_CNT 18
typedef int BIU;
class PCB_TARGET; class PCB_TARGET;
class MODULE; class MODULE;
...@@ -62,6 +61,7 @@ class LEGACY_PLUGIN : public PLUGIN ...@@ -62,6 +61,7 @@ class LEGACY_PLUGIN : public PLUGIN
{ {
public: public:
//-----<PLUGIN IMPLEMENTATION>---------------------------------------------- //-----<PLUGIN IMPLEMENTATION>----------------------------------------------
const wxString& PluginName() const const wxString& PluginName() const
...@@ -98,6 +98,8 @@ public: ...@@ -98,6 +98,8 @@ public:
//-----</PLUGIN IMPLEMENTATION>--------------------------------------------- //-----</PLUGIN IMPLEMENTATION>---------------------------------------------
typedef int BIU;
LEGACY_PLUGIN(); LEGACY_PLUGIN();
~LEGACY_PLUGIN(); ~LEGACY_PLUGIN();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment