2012-05-16 02:27:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
/*
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
Pcbnew PLUGIN for Eagle 6.x XML *.brd and footprint format.
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
XML parsing and converting:
|
|
|
|
Getting line numbers and byte offsets from the source XML file is not
|
|
|
|
possible using currently available XML libraries within KiCad project:
|
|
|
|
wxXmlDocument and boost::property_tree.
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
property_tree will give line numbers but no byte offsets, and only during
|
|
|
|
document loading. This means that if we have a problem after the document is
|
|
|
|
successfully loaded, there is no way to correlate back to line number and byte
|
|
|
|
offset of the problem. So a different approach is taken, one which relies on the
|
|
|
|
XML elements themselves using an XPATH type of reporting mechanism. The path to
|
|
|
|
the problem is reported in the error messages. This means keeping track of that
|
|
|
|
path as we traverse the XML document for the sole purpose of accurate error
|
|
|
|
reporting.
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
User can load the source XML file into firefox or other xml browser and follow
|
|
|
|
our error message.
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
Load() TODO's
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
*) verify zone fill clearances are correct
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
*/
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/property_tree/xml_parser.hpp>
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
#include <eagle_plugin.h>
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <fctsys.h>
|
2012-05-22 17:51:18 +00:00
|
|
|
#include <trigo.h>
|
2013-11-15 09:28:31 +00:00
|
|
|
#include <macros.h>
|
2013-11-29 18:29:41 +00:00
|
|
|
#include <kicad_string.h>
|
2013-01-02 04:05:48 +00:00
|
|
|
#include <wx/filename.h>
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_edge_mod.h>
|
2012-05-24 01:18:30 +00:00
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_pcb_text.h>
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
using namespace boost::property_tree;
|
2012-08-04 09:43:27 +00:00
|
|
|
using namespace std;
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
typedef EAGLE_PLUGIN::BIU BIU;
|
|
|
|
typedef PTREE::const_assoc_iterator CA_ITER;
|
|
|
|
typedef PTREE::const_iterator CITER;
|
|
|
|
typedef std::pair<CA_ITER, CA_ITER> CA_ITER_RANGE;
|
|
|
|
|
|
|
|
typedef MODULE_MAP::iterator MODULE_ITER;
|
|
|
|
typedef MODULE_MAP::const_iterator MODULE_CITER;
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
typedef boost::optional<string> opt_string;
|
2012-06-05 04:39:37 +00:00
|
|
|
typedef boost::optional<int> opt_int;
|
|
|
|
typedef boost::optional<double> opt_double;
|
|
|
|
typedef boost::optional<bool> opt_bool;
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// segment (element) of our XPATH into the Eagle XML document tree in PTREE form.
|
|
|
|
struct TRIPLET
|
|
|
|
{
|
|
|
|
const char* element;
|
|
|
|
const char* attribute;
|
|
|
|
const char* value;
|
|
|
|
|
|
|
|
TRIPLET( const char* aElement, const char* aAttribute = "", const char* aValue = "" ) :
|
|
|
|
element( aElement ),
|
|
|
|
attribute( aAttribute ),
|
|
|
|
value( aValue )
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class XPATH
|
|
|
|
* keeps track of what we are working on within a PTREE.
|
|
|
|
* Then if an exception is thrown, the place within the tree that gave us
|
|
|
|
* grief can be reported almost accurately. To minimally impact
|
|
|
|
* speed, merely assign const char* pointers during the tree walking
|
|
|
|
* expedition. The const char* pointers must be to C strings residing either in
|
|
|
|
* the data or code segment (i.e. "compiled in") or within the XML document, but
|
|
|
|
* not on the stack, since the stack is unwound during the throwing of the
|
|
|
|
* exception. The XML document will not immediately vanish since we capture
|
|
|
|
* the xpath (using function Contents()) before the XML document tree (PTREE)
|
|
|
|
* is destroyed.
|
|
|
|
*/
|
|
|
|
class XPATH
|
|
|
|
{
|
|
|
|
std::vector<TRIPLET> p;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void push( const char* aPathSegment, const char* aAttribute="" )
|
|
|
|
{
|
|
|
|
p.push_back( TRIPLET( aPathSegment, aAttribute ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() { p.clear(); }
|
|
|
|
|
|
|
|
void pop() { p.pop_back(); }
|
|
|
|
|
|
|
|
/// modify the last path node's value
|
|
|
|
void Value( const char* aValue )
|
|
|
|
{
|
|
|
|
p.back().value = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// modify the last path node's attribute
|
|
|
|
void Attribute( const char* aAttribute )
|
|
|
|
{
|
|
|
|
p.back().attribute = aAttribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return the contents of the XPATH as a single string
|
2013-11-06 16:53:44 +00:00
|
|
|
string Contents()
|
2012-06-02 17:07:30 +00:00
|
|
|
{
|
|
|
|
typedef std::vector<TRIPLET>::const_iterator CITER;
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
string ret;
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
for( CITER it = p.begin(); it != p.end(); ++it )
|
|
|
|
{
|
|
|
|
if( it != p.begin() )
|
|
|
|
ret += '.';
|
|
|
|
|
|
|
|
ret += it->element;
|
|
|
|
|
|
|
|
if( it->attribute[0] && it->value[0] )
|
|
|
|
{
|
|
|
|
ret += '[';
|
|
|
|
ret += it->attribute;
|
|
|
|
ret += '=';
|
|
|
|
ret += it->value;
|
|
|
|
ret += ']';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/**
|
|
|
|
* Function parseOptionalBool
|
|
|
|
* returns an opt_bool and sets it true or false according to the presence
|
|
|
|
* and value of an attribute within the CPTREE element.
|
|
|
|
*/
|
2012-05-30 21:40:32 +00:00
|
|
|
static opt_bool parseOptionalBool( CPTREE& attribs, const char* aName )
|
|
|
|
{
|
|
|
|
opt_bool ret;
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string stemp = attribs.get_optional<string>( aName );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
if( stemp )
|
|
|
|
ret = !stemp->compare( "yes" );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
|
|
|
|
// All of the 'E'STRUCTS below merely hold Eagle XML information verbatim, in binary.
|
|
|
|
// For maintenance and troubleshooting purposes, it was thought that we'd need to
|
|
|
|
// separate the conversion process into distinct steps. There is no intent to have KiCad
|
|
|
|
// forms of information in these 'E'STRUCTS. They are only binary forms
|
|
|
|
// of the Eagle information in the corresponding Eagle XML nodes.
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Eagle rotation
|
|
|
|
struct EROT
|
|
|
|
{
|
|
|
|
bool mirror;
|
|
|
|
bool spin;
|
|
|
|
double degrees;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
EROT() :
|
|
|
|
mirror( false ),
|
|
|
|
spin( false ),
|
|
|
|
degrees( 0 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
EROT( double aDegrees ) :
|
|
|
|
mirror( false ),
|
|
|
|
spin( false ),
|
|
|
|
degrees( aDegrees )
|
|
|
|
{}
|
2012-05-30 21:40:32 +00:00
|
|
|
};
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
typedef boost::optional<EROT> opt_erot;
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// parse an Eagle XML "rot" field. Unfortunately the DTD seems not to explain
|
2012-06-05 04:39:37 +00:00
|
|
|
/// this format very well. [S][M]R<degrees>. Examples: "R90", "MR180", "SR180"
|
2013-11-06 16:53:44 +00:00
|
|
|
static EROT erot( const string& aRot )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
|
|
|
EROT rot;
|
|
|
|
|
|
|
|
rot.spin = aRot.find( 'S' ) != aRot.npos;
|
|
|
|
rot.mirror = aRot.find( 'M' ) != aRot.npos;
|
|
|
|
rot.degrees = strtod( aRot.c_str()
|
|
|
|
+ 1 // skip leading 'R'
|
|
|
|
+ int( rot.spin ) // skip optional leading 'S'
|
|
|
|
+ int( rot.mirror ), // skip optional leading 'M'
|
|
|
|
NULL );
|
|
|
|
return rot;
|
|
|
|
}
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Eagle "rot" fields are optional, handle that by returning opt_erot.
|
2012-05-30 21:40:32 +00:00
|
|
|
static opt_erot parseOptionalEROT( CPTREE& attribs )
|
|
|
|
{
|
|
|
|
opt_erot ret;
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string stemp = attribs.get_optional<string>( "rot" );
|
2012-05-30 21:40:32 +00:00
|
|
|
if( stemp )
|
|
|
|
ret = erot( *stemp );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
/// Eagle wire
|
|
|
|
struct EWIRE
|
|
|
|
{
|
2012-06-05 04:39:37 +00:00
|
|
|
double x1;
|
|
|
|
double y1;
|
|
|
|
double x2;
|
|
|
|
double y2;
|
|
|
|
double width;
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer;
|
2012-06-05 04:39:37 +00:00
|
|
|
|
|
|
|
// for style: (continuous | longdash | shortdash | dashdot)
|
|
|
|
enum {
|
|
|
|
CONTINUOUS,
|
|
|
|
LONGDASH,
|
|
|
|
SHORTDASH,
|
|
|
|
DASHDOT,
|
|
|
|
};
|
|
|
|
opt_int style;
|
|
|
|
opt_double curve; ///< range is -359.9..359.9
|
|
|
|
|
|
|
|
// for cap: (flat | round)
|
|
|
|
enum {
|
|
|
|
FLAT,
|
|
|
|
ROUND,
|
|
|
|
};
|
|
|
|
opt_int cap;
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
EWIRE( CPTREE& aWire );
|
2012-05-22 17:51:18 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
/**
|
|
|
|
* Constructor EWIRE
|
2012-09-12 17:28:55 +00:00
|
|
|
* converts a "wire"'s xml attributes ( <wire> )
|
|
|
|
* to binary without additional conversion.
|
|
|
|
* This result is an EWIRE with the <wire> textual data merely converted to binary.
|
2012-05-30 21:40:32 +00:00
|
|
|
*/
|
|
|
|
EWIRE::EWIRE( CPTREE& aWire )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aWire.get_child( "<xmlattr>" );
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/*
|
|
|
|
<!ELEMENT wire EMPTY>
|
|
|
|
<!ATTLIST wire
|
|
|
|
x1 %Coord; #REQUIRED
|
|
|
|
y1 %Coord; #REQUIRED
|
|
|
|
x2 %Coord; #REQUIRED
|
|
|
|
y2 %Coord; #REQUIRED
|
|
|
|
width %Dimension; #REQUIRED
|
|
|
|
layer %Layer; #REQUIRED
|
|
|
|
extent %Extent; #IMPLIED -- only applicable for airwires --
|
|
|
|
style %WireStyle; "continuous"
|
|
|
|
curve %WireCurve; "0"
|
|
|
|
cap %WireCap; "round" -- only applicable if 'curve' is not zero --
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
x1 = attribs.get<double>( "x1" );
|
|
|
|
y1 = attribs.get<double>( "y1" );
|
|
|
|
x2 = attribs.get<double>( "x2" );
|
|
|
|
y2 = attribs.get<double>( "y2" );
|
|
|
|
width = attribs.get<double>( "width" );
|
|
|
|
layer = attribs.get<int>( "layer" );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
curve = attribs.get_optional<double>( "curve" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string s = attribs.get_optional<string>( "style" );
|
2012-06-05 04:39:37 +00:00
|
|
|
if( s )
|
|
|
|
{
|
|
|
|
if( !s->compare( "continuous" ) )
|
|
|
|
style = EWIRE::CONTINUOUS;
|
|
|
|
else if( !s->compare( "longdash" ) )
|
|
|
|
style = EWIRE::LONGDASH;
|
|
|
|
else if( !s->compare( "shortdash" ) )
|
|
|
|
style = EWIRE::SHORTDASH;
|
|
|
|
else if( !s->compare( "dashdot" ) )
|
|
|
|
style = EWIRE::DASHDOT;
|
|
|
|
}
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
s = attribs.get_optional<string>( "cap" );
|
2012-06-05 04:39:37 +00:00
|
|
|
if( s )
|
|
|
|
{
|
|
|
|
if( !s->compare( "round" ) )
|
|
|
|
cap = EWIRE::ROUND;
|
|
|
|
else if( !s->compare( "flat" ) )
|
|
|
|
cap = EWIRE::FLAT;
|
|
|
|
}
|
|
|
|
// ignoring extent
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
/// Eagle via
|
|
|
|
struct EVIA
|
|
|
|
{
|
|
|
|
double x;
|
|
|
|
double y;
|
2012-06-01 07:39:32 +00:00
|
|
|
int layer_front_most; /// < extent
|
|
|
|
int layer_back_most; /// < inclusive
|
2012-05-24 01:18:30 +00:00
|
|
|
double drill;
|
|
|
|
opt_double diam;
|
|
|
|
opt_string shape;
|
2012-05-30 21:40:32 +00:00
|
|
|
EVIA( CPTREE& aVia );
|
2012-05-24 01:18:30 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
EVIA::EVIA( CPTREE& aVia )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aVia.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT via EMPTY>
|
|
|
|
<!ATTLIST via
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
extent %Extent; #REQUIRED
|
|
|
|
drill %Dimension; #REQUIRED
|
|
|
|
diameter %Dimension; "0"
|
|
|
|
shape %ViaShape; "round"
|
|
|
|
alwaysstop %Bool; "no"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
string ext = attribs.get<string>( "extent" );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
sscanf( ext.c_str(), "%u-%u", &layer_front_most, &layer_back_most );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
drill = attribs.get<double>( "drill" );
|
|
|
|
diam = attribs.get_optional<double>( "diameter" );
|
2013-11-06 16:53:44 +00:00
|
|
|
shape = attribs.get_optional<string>( "shape" );
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
/// Eagle circle
|
|
|
|
struct ECIRCLE
|
|
|
|
{
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double radius;
|
|
|
|
double width;
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
ECIRCLE( CPTREE& aCircle );
|
2012-05-22 17:51:18 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
ECIRCLE::ECIRCLE( CPTREE& aCircle )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aCircle.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT circle EMPTY>
|
|
|
|
<!ATTLIST circle
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
radius %Coord; #REQUIRED
|
|
|
|
width %Dimension; #REQUIRED
|
|
|
|
layer %Layer; #REQUIRED
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
radius = attribs.get<double>( "radius" );
|
|
|
|
width = attribs.get<double>( "width" );
|
|
|
|
layer = attribs.get<int>( "layer" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
/// Eagle XML rectangle in binary
|
|
|
|
struct ERECT
|
|
|
|
{
|
2012-05-30 21:40:32 +00:00
|
|
|
double x1;
|
|
|
|
double y1;
|
|
|
|
double x2;
|
|
|
|
double y2;
|
|
|
|
int layer;
|
2012-06-01 07:39:32 +00:00
|
|
|
opt_erot rot;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
ERECT( CPTREE& aRect );
|
2012-05-24 01:18:30 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
ERECT::ERECT( CPTREE& aRect )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-30 21:40:32 +00:00
|
|
|
CPTREE& attribs = aRect.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT rectangle EMPTY>
|
|
|
|
<!ATTLIST rectangle
|
|
|
|
x1 %Coord; #REQUIRED
|
|
|
|
y1 %Coord; #REQUIRED
|
|
|
|
x2 %Coord; #REQUIRED
|
|
|
|
y2 %Coord; #REQUIRED
|
|
|
|
layer %Layer; #REQUIRED
|
|
|
|
rot %Rotation; "R0"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
x1 = attribs.get<double>( "x1" );
|
|
|
|
y1 = attribs.get<double>( "y1" );
|
|
|
|
x2 = attribs.get<double>( "x2" );
|
|
|
|
y2 = attribs.get<double>( "y2" );
|
|
|
|
layer = attribs.get<int>( "layer" );
|
|
|
|
rot = parseOptionalEROT( attribs );
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
/// Eagle "attribute" XML element, no foolin'.
|
|
|
|
struct EATTR
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string name;
|
2012-05-22 17:51:18 +00:00
|
|
|
opt_string value;
|
|
|
|
opt_double x;
|
|
|
|
opt_double y;
|
|
|
|
opt_double size;
|
2012-05-30 21:40:32 +00:00
|
|
|
opt_int layer;
|
2012-05-22 17:51:18 +00:00
|
|
|
opt_double ratio;
|
2012-06-01 07:39:32 +00:00
|
|
|
opt_erot rot;
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
enum { // for 'display'
|
2012-05-22 17:51:18 +00:00
|
|
|
Off,
|
|
|
|
VALUE,
|
|
|
|
NAME,
|
|
|
|
BOTH,
|
|
|
|
};
|
2012-06-07 01:49:43 +00:00
|
|
|
opt_int display;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
EATTR( CPTREE& aTree );
|
2012-06-07 01:49:43 +00:00
|
|
|
EATTR() {}
|
2012-05-22 17:51:18 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
/**
|
|
|
|
* Constructor EATTR
|
|
|
|
* parses an Eagle "attribute" XML element. Note that an attribute element
|
|
|
|
* is different than an XML element attribute. The attribute element is a
|
|
|
|
* full XML node in and of itself, and has attributes of its own. Blame Eagle.
|
|
|
|
*/
|
|
|
|
EATTR::EATTR( CPTREE& aAttribute )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aAttribute.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT attribute EMPTY>
|
|
|
|
<!ATTLIST attribute
|
2012-06-02 17:07:30 +00:00
|
|
|
name %String; #REQUIRED
|
|
|
|
value %String; #IMPLIED
|
|
|
|
x %Coord; #IMPLIED
|
|
|
|
y %Coord; #IMPLIED
|
|
|
|
size %Dimension; #IMPLIED
|
|
|
|
layer %Layer; #IMPLIED
|
|
|
|
font %TextFont; #IMPLIED
|
|
|
|
ratio %Int; #IMPLIED
|
|
|
|
rot %Rotation; "R0"
|
|
|
|
display %AttributeDisplay; "value" -- only in <element> or <instance> context --
|
|
|
|
constant %Bool; "no" -- only in <device> context --
|
|
|
|
>
|
2012-05-30 21:40:32 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
name = attribs.get<string>( "name" ); // #REQUIRED
|
|
|
|
value = attribs.get_optional<string>( "value" );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
x = attribs.get_optional<double>( "x" );
|
|
|
|
y = attribs.get_optional<double>( "y" );
|
|
|
|
size = attribs.get_optional<double>( "size" );
|
|
|
|
|
|
|
|
// KiCad cannot currently put a TEXTE_MODULE on a different layer than the MODULE
|
|
|
|
// Eagle can it seems.
|
|
|
|
layer = attribs.get_optional<int>( "layer" );
|
|
|
|
|
|
|
|
ratio = attribs.get_optional<double>( "ratio" );
|
2012-06-01 07:39:32 +00:00
|
|
|
rot = parseOptionalEROT( attribs );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string stemp = attribs.get_optional<string>( "display" );
|
2012-05-30 21:40:32 +00:00
|
|
|
if( stemp )
|
|
|
|
{
|
|
|
|
// (off | value | name | both)
|
|
|
|
if( !stemp->compare( "off" ) )
|
|
|
|
display = EATTR::Off;
|
|
|
|
else if( !stemp->compare( "value" ) )
|
|
|
|
display = EATTR::VALUE;
|
|
|
|
else if( !stemp->compare( "name" ) )
|
|
|
|
display = EATTR::NAME;
|
|
|
|
else if( !stemp->compare( "both" ) )
|
|
|
|
display = EATTR::BOTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
/// Eagle text element
|
|
|
|
struct ETEXT
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string text;
|
2012-05-24 01:18:30 +00:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double size;
|
|
|
|
int layer;
|
|
|
|
opt_string font;
|
|
|
|
opt_double ratio;
|
2012-06-01 07:39:32 +00:00
|
|
|
opt_erot rot;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
enum { // for align
|
2012-05-24 01:18:30 +00:00
|
|
|
CENTER,
|
|
|
|
CENTER_LEFT,
|
|
|
|
TOP_CENTER,
|
|
|
|
TOP_LEFT,
|
|
|
|
TOP_RIGHT,
|
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
// opposites are -1 x above, used by code tricks in here
|
2012-05-24 01:18:30 +00:00
|
|
|
CENTER_RIGHT = -CENTER_LEFT,
|
|
|
|
BOTTOM_CENTER = -TOP_CENTER,
|
|
|
|
BOTTOM_LEFT = -TOP_RIGHT,
|
|
|
|
BOTTOM_RIGHT = -TOP_LEFT,
|
|
|
|
};
|
2012-05-29 18:10:56 +00:00
|
|
|
|
|
|
|
opt_int align;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
ETEXT( CPTREE& aText );
|
2012-05-29 18:10:56 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
ETEXT::ETEXT( CPTREE& aText )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aText.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT text (#PCDATA)>
|
|
|
|
<!ATTLIST text
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
size %Dimension; #REQUIRED
|
|
|
|
layer %Layer; #REQUIRED
|
|
|
|
font %TextFont; "proportional"
|
|
|
|
ratio %Int; "8"
|
|
|
|
rot %Rotation; "R0"
|
|
|
|
align %Align; "bottom-left"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
text = aText.data();
|
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
size = attribs.get<double>( "size" );
|
|
|
|
layer = attribs.get<int>( "layer" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
font = attribs.get_optional<string>( "font" );
|
2012-05-30 21:40:32 +00:00
|
|
|
ratio = attribs.get_optional<double>( "ratio" );
|
2012-06-01 07:39:32 +00:00
|
|
|
rot = parseOptionalEROT( attribs );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string stemp = attribs.get_optional<string>( "align" );
|
2012-05-30 21:40:32 +00:00
|
|
|
if( stemp )
|
|
|
|
{
|
|
|
|
// (bottom-left | bottom-center | bottom-right | center-left |
|
|
|
|
// center | center-right | top-left | top-center | top-right)
|
|
|
|
if( !stemp->compare( "center" ) )
|
|
|
|
align = ETEXT::CENTER;
|
|
|
|
else if( !stemp->compare( "center-right" ) )
|
|
|
|
align = ETEXT::CENTER_RIGHT;
|
|
|
|
else if( !stemp->compare( "top-left" ) )
|
|
|
|
align = ETEXT::TOP_LEFT;
|
|
|
|
else if( !stemp->compare( "top-center" ) )
|
|
|
|
align = ETEXT::TOP_CENTER;
|
|
|
|
else if( !stemp->compare( "top-right" ) )
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
else if( !stemp->compare( "bottom-left" ) )
|
|
|
|
align = ETEXT::BOTTOM_LEFT;
|
|
|
|
else if( !stemp->compare( "bottom-center" ) )
|
|
|
|
align = ETEXT::BOTTOM_CENTER;
|
|
|
|
else if( !stemp->compare( "bottom-right" ) )
|
|
|
|
align = ETEXT::BOTTOM_RIGHT;
|
|
|
|
else if( !stemp->compare( "center-left" ) )
|
|
|
|
align = ETEXT::CENTER_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
/// Eagle thru hol pad
|
|
|
|
struct EPAD
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string name;
|
2012-05-29 18:10:56 +00:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double drill;
|
|
|
|
opt_double diameter;
|
|
|
|
|
|
|
|
// for shape: (square | round | octagon | long | offset)
|
|
|
|
enum {
|
|
|
|
SQUARE,
|
|
|
|
ROUND,
|
|
|
|
OCTAGON,
|
|
|
|
LONG,
|
|
|
|
OFFSET,
|
|
|
|
};
|
|
|
|
opt_int shape;
|
2012-05-31 15:18:55 +00:00
|
|
|
opt_erot rot;
|
2012-05-29 18:10:56 +00:00
|
|
|
opt_bool stop;
|
|
|
|
opt_bool thermals;
|
|
|
|
opt_bool first;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
EPAD( CPTREE& aPad );
|
2012-05-29 18:10:56 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
EPAD::EPAD( CPTREE& aPad )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aPad.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT pad EMPTY>
|
|
|
|
<!ATTLIST pad
|
|
|
|
name %String; #REQUIRED
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
drill %Dimension; #REQUIRED
|
|
|
|
diameter %Dimension; "0"
|
|
|
|
shape %PadShape; "round"
|
|
|
|
rot %Rotation; "R0"
|
|
|
|
stop %Bool; "yes"
|
|
|
|
thermals %Bool; "yes"
|
|
|
|
first %Bool; "no"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
// #REQUIRED says DTD, throw exception if not found
|
2013-11-06 16:53:44 +00:00
|
|
|
name = attribs.get<string>( "name" );
|
2012-05-30 21:40:32 +00:00
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
drill = attribs.get<double>( "drill" );
|
|
|
|
|
|
|
|
diameter = attribs.get_optional<double>( "diameter" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string s = attribs.get_optional<string>( "shape" );
|
2012-05-30 21:40:32 +00:00
|
|
|
if( s )
|
|
|
|
{
|
|
|
|
// (square | round | octagon | long | offset)
|
|
|
|
if( !s->compare( "square" ) )
|
|
|
|
shape = EPAD::SQUARE;
|
|
|
|
else if( !s->compare( "round" ) )
|
|
|
|
shape = EPAD::ROUND;
|
|
|
|
else if( !s->compare( "octagon" ) )
|
|
|
|
shape = EPAD::OCTAGON;
|
|
|
|
else if( !s->compare( "long" ) )
|
|
|
|
shape = EPAD::LONG;
|
|
|
|
else if( !s->compare( "offset" ) )
|
|
|
|
shape = EPAD::OFFSET;
|
|
|
|
}
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
rot = parseOptionalEROT( attribs );
|
2012-05-30 21:40:32 +00:00
|
|
|
stop = parseOptionalBool( attribs, "stop" );
|
|
|
|
thermals = parseOptionalBool( attribs, "thermals" );
|
|
|
|
first = parseOptionalBool( attribs, "first" );
|
|
|
|
}
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
|
|
|
|
/// Eagle SMD pad
|
|
|
|
struct ESMD
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string name;
|
2012-05-29 18:10:56 +00:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double dx;
|
|
|
|
double dy;
|
|
|
|
int layer;
|
|
|
|
opt_int roundness;
|
2012-05-31 15:18:55 +00:00
|
|
|
opt_erot rot;
|
2012-05-29 18:10:56 +00:00
|
|
|
opt_bool stop;
|
|
|
|
opt_bool thermals;
|
|
|
|
opt_bool cream;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
ESMD( CPTREE& aSMD );
|
2012-05-29 18:10:56 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
ESMD::ESMD( CPTREE& aSMD )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aSMD.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ATTLIST smd
|
|
|
|
name %String; #REQUIRED
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
dx %Dimension; #REQUIRED
|
|
|
|
dy %Dimension; #REQUIRED
|
|
|
|
layer %Layer; #REQUIRED
|
|
|
|
roundness %Int; "0"
|
|
|
|
rot %Rotation; "R0"
|
|
|
|
stop %Bool; "yes"
|
|
|
|
thermals %Bool; "yes"
|
|
|
|
cream %Bool; "yes"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
// DTD #REQUIRED, throw exception if not found
|
2013-11-06 16:53:44 +00:00
|
|
|
name = attribs.get<string>( "name" );
|
2012-05-30 21:40:32 +00:00
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
dx = attribs.get<double>( "dx" );
|
|
|
|
dy = attribs.get<double>( "dy" );
|
|
|
|
layer = attribs.get<int>( "layer" );
|
2012-05-31 15:18:55 +00:00
|
|
|
rot = parseOptionalEROT( attribs );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
roundness = attribs.get_optional<int>( "roundness" );
|
|
|
|
thermals = parseOptionalBool( attribs, "thermals" );
|
|
|
|
stop = parseOptionalBool( attribs, "stop" );
|
|
|
|
thermals = parseOptionalBool( attribs, "thermals" );
|
|
|
|
cream = parseOptionalBool( attribs, "cream" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
struct EVERTEX
|
|
|
|
{
|
|
|
|
double x;
|
|
|
|
double y;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
EVERTEX( CPTREE& aVertex );
|
2012-05-29 18:10:56 +00:00
|
|
|
};
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
EVERTEX::EVERTEX( CPTREE& aVertex )
|
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
CPTREE& attribs = aVertex.get_child( "<xmlattr>" );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT vertex EMPTY>
|
|
|
|
<!ATTLIST vertex
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
curve %WireCurve; "0" -- the curvature from this vertex to the next one --
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Eagle polygon, without vertices which are parsed as needed
|
2012-05-29 18:10:56 +00:00
|
|
|
struct EPOLYGON
|
|
|
|
{
|
|
|
|
double width;
|
|
|
|
int layer;
|
|
|
|
opt_double spacing;
|
|
|
|
|
|
|
|
enum { // for pour
|
|
|
|
SOLID,
|
|
|
|
HATCH,
|
|
|
|
CUTOUT,
|
|
|
|
};
|
|
|
|
opt_int pour;
|
|
|
|
opt_double isolate;
|
|
|
|
opt_bool orphans;
|
|
|
|
opt_bool thermals;
|
|
|
|
opt_int rank;
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
EPOLYGON( CPTREE& aPolygon );
|
|
|
|
};
|
|
|
|
|
|
|
|
EPOLYGON::EPOLYGON( CPTREE& aPolygon )
|
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
CPTREE& attribs = aPolygon.get_child( "<xmlattr>" );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
<!ATTLIST polygon
|
|
|
|
width %Dimension; #REQUIRED
|
|
|
|
layer %Layer; #REQUIRED
|
|
|
|
spacing %Dimension; #IMPLIED
|
|
|
|
pour %PolygonPour; "solid"
|
|
|
|
isolate %Dimension; #IMPLIED -- only in <signal> or <package> context --
|
|
|
|
orphans %Bool; "no" -- only in <signal> context --
|
|
|
|
thermals %Bool; "yes" -- only in <signal> context --
|
|
|
|
rank %Int; "0" -- 1..6 in <signal> context, 0 or 7 in <package> context --
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
width = attribs.get<double>( "width" );
|
|
|
|
layer = attribs.get<int>( "layer" );
|
|
|
|
spacing = attribs.get_optional<double>( "spacing" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string s = attribs.get_optional<string>( "pour" );
|
2012-05-30 21:40:32 +00:00
|
|
|
if( s )
|
|
|
|
{
|
|
|
|
// (solid | hatch | cutout)
|
|
|
|
if( !s->compare( "hatch" ) )
|
|
|
|
pour = EPOLYGON::HATCH;
|
|
|
|
else if( !s->compare( "cutout" ) )
|
|
|
|
pour = EPOLYGON::CUTOUT;
|
|
|
|
else
|
|
|
|
pour = EPOLYGON::SOLID;
|
|
|
|
}
|
|
|
|
|
|
|
|
orphans = parseOptionalBool( attribs, "orphans" );
|
|
|
|
thermals = parseOptionalBool( attribs, "thermals" );
|
|
|
|
rank = attribs.get_optional<int>( "rank" );
|
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Eagle hole element
|
2012-05-31 15:18:55 +00:00
|
|
|
struct EHOLE
|
|
|
|
{
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double drill;
|
|
|
|
|
|
|
|
EHOLE( CPTREE& aHole );
|
|
|
|
};
|
|
|
|
|
|
|
|
EHOLE::EHOLE( CPTREE& aHole )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aHole.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT hole EMPTY>
|
|
|
|
<!ATTLIST hole
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
drill %Dimension; #REQUIRED
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
// #REQUIRED:
|
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
drill = attribs.get<double>( "drill" );
|
|
|
|
}
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
/// Eagle element element
|
2012-05-31 15:18:55 +00:00
|
|
|
struct EELEMENT
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string name;
|
|
|
|
string library;
|
|
|
|
string package;
|
|
|
|
string value;
|
2012-05-31 15:18:55 +00:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
opt_bool locked;
|
|
|
|
// opt_bool smashed;
|
|
|
|
opt_erot rot;
|
|
|
|
|
|
|
|
EELEMENT( CPTREE& aElement );
|
|
|
|
};
|
|
|
|
|
|
|
|
EELEMENT::EELEMENT( CPTREE& aElement )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aElement.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT element (attribute*, variant*)>
|
|
|
|
<!ATTLIST element
|
|
|
|
name %String; #REQUIRED
|
|
|
|
library %String; #REQUIRED
|
|
|
|
package %String; #REQUIRED
|
|
|
|
value %String; #REQUIRED
|
|
|
|
x %Coord; #REQUIRED
|
|
|
|
y %Coord; #REQUIRED
|
|
|
|
locked %Bool; "no"
|
|
|
|
smashed %Bool; "no"
|
|
|
|
rot %Rotation; "R0"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
// #REQUIRED
|
2013-11-06 16:53:44 +00:00
|
|
|
name = attribs.get<string>( "name" );
|
|
|
|
library = attribs.get<string>( "library" );
|
|
|
|
value = attribs.get<string>( "value" );
|
|
|
|
|
|
|
|
package = attribs.get<string>( "package" );
|
2013-11-29 18:29:41 +00:00
|
|
|
ReplaceIllegalFileNameChars( &package );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
|
|
|
x = attribs.get<double>( "x" );
|
|
|
|
y = attribs.get<double>( "y" );
|
|
|
|
|
|
|
|
// optional
|
|
|
|
locked = parseOptionalBool( attribs, "locked" );
|
|
|
|
// smashed = pasreOptionalBool( attribs, "smashed" );
|
|
|
|
rot = parseOptionalEROT( attribs );
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
struct ELAYER
|
|
|
|
{
|
|
|
|
int number;
|
2013-11-06 16:53:44 +00:00
|
|
|
string name;
|
2012-06-01 07:39:32 +00:00
|
|
|
int color;
|
|
|
|
int fill;
|
|
|
|
opt_bool visible;
|
|
|
|
opt_bool active;
|
|
|
|
|
|
|
|
ELAYER( CPTREE& aLayer );
|
|
|
|
};
|
|
|
|
|
|
|
|
ELAYER::ELAYER( CPTREE& aLayer )
|
|
|
|
{
|
|
|
|
CPTREE& attribs = aLayer.get_child( "<xmlattr>" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
<!ELEMENT layer EMPTY>
|
|
|
|
<!ATTLIST layer
|
|
|
|
number %Layer; #REQUIRED
|
|
|
|
name %String; #REQUIRED
|
|
|
|
color %Int; #REQUIRED
|
|
|
|
fill %Int; #REQUIRED
|
|
|
|
visible %Bool; "yes"
|
|
|
|
active %Bool; "yes"
|
|
|
|
>
|
|
|
|
*/
|
|
|
|
|
|
|
|
number = attribs.get<int>( "number" );
|
2013-11-06 16:53:44 +00:00
|
|
|
name = attribs.get<string>( "name" );
|
2012-06-01 07:39:32 +00:00
|
|
|
color = attribs.get<int>( "color" );
|
|
|
|
visible = parseOptionalBool( attribs, "visible" );
|
|
|
|
active = parseOptionalBool( attribs, "active" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
/// Parse an eagle distance which is either mm, or mils if there is "mil" suffix.
|
|
|
|
/// Return is in BIU.
|
2013-11-06 16:53:44 +00:00
|
|
|
static double parseEagle( const string& aDistance )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
|
|
|
double ret = strtod( aDistance.c_str(), NULL );
|
|
|
|
if( aDistance.npos != aDistance.find( "mil" ) )
|
|
|
|
ret = IU_PER_MILS * ret;
|
|
|
|
else
|
|
|
|
ret = IU_PER_MM * ret;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// subset of eagle.drawing.board.designrules in the XML document
|
|
|
|
struct ERULES
|
|
|
|
{
|
|
|
|
int psElongationLong; ///< percent over 100%. 0-> not elongated, 100->twice as wide as is tall
|
|
|
|
///< Goes into making a scaling factor for "long" pads.
|
|
|
|
|
|
|
|
int psElongationOffset; ///< the offset of the hole within the "long" pad.
|
|
|
|
|
|
|
|
double rvPadTop; ///< top pad size as percent of drill size
|
|
|
|
// double rvPadBottom; ///< bottom pad size as percent of drill size
|
|
|
|
|
|
|
|
double rlMinPadTop; ///< minimum copper annulus on through hole pads
|
|
|
|
double rlMaxPadTop; ///< maximum copper annulus on through hole pads
|
|
|
|
|
|
|
|
double rvViaOuter; ///< copper annulus is this percent of via hole
|
|
|
|
double rlMinViaOuter; ///< minimum copper annulus on via
|
|
|
|
double rlMaxViaOuter; ///< maximum copper annulus on via
|
2013-03-14 22:54:47 +00:00
|
|
|
double mdWireWire; ///< wire to wire spacing I presume.
|
2012-06-05 04:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
ERULES() :
|
|
|
|
psElongationLong ( 100 ),
|
|
|
|
rvPadTop ( 0.25 ),
|
|
|
|
// rvPadBottom ( 0.25 ),
|
|
|
|
rlMinPadTop ( Mils2iu( 10 ) ),
|
|
|
|
rlMaxPadTop ( Mils2iu( 20 ) ),
|
|
|
|
|
|
|
|
rvViaOuter ( 0.25 ),
|
|
|
|
rlMinViaOuter ( Mils2iu( 10 ) ),
|
2013-03-14 22:54:47 +00:00
|
|
|
rlMaxViaOuter ( Mils2iu( 20 ) ),
|
|
|
|
mdWireWire ( 0 )
|
2012-06-05 04:39:37 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void parse( CPTREE& aRules );
|
|
|
|
};
|
|
|
|
|
|
|
|
void ERULES::parse( CPTREE& aRules )
|
|
|
|
{
|
|
|
|
for( CITER it = aRules.begin(); it != aRules.end(); ++it )
|
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( it->first != "param" )
|
2012-06-05 04:39:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
CPTREE& attribs = it->second.get_child( "<xmlattr>" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
const string& name = attribs.get<string>( "name" );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
if( name == "psElongationLong" )
|
2012-06-05 04:39:37 +00:00
|
|
|
psElongationLong = attribs.get<int>( "value" );
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "psElongationOffset" )
|
2012-06-05 04:39:37 +00:00
|
|
|
psElongationOffset = attribs.get<int>( "value" );
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "rvPadTop" )
|
2012-06-05 04:39:37 +00:00
|
|
|
rvPadTop = attribs.get<double>( "value" );
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "rlMinPadTop" )
|
2013-11-06 16:53:44 +00:00
|
|
|
rlMinPadTop = parseEagle( attribs.get<string>( "value" ) );
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "rlMaxPadTop" )
|
2013-11-06 16:53:44 +00:00
|
|
|
rlMaxPadTop = parseEagle( attribs.get<string>( "value" ) );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "rvViaOuter" )
|
2012-06-05 04:39:37 +00:00
|
|
|
rvViaOuter = attribs.get<double>( "value" );
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "rlMinViaOuter" )
|
2013-11-06 16:53:44 +00:00
|
|
|
rlMinViaOuter = parseEagle( attribs.get<string>( "value" ) );
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( name == "rlMaxViaOuter" )
|
2013-11-06 16:53:44 +00:00
|
|
|
rlMaxViaOuter = parseEagle( attribs.get<string>( "value" ) );
|
2013-03-14 22:54:47 +00:00
|
|
|
else if( name == "mdWireWire" )
|
2013-11-06 16:53:44 +00:00
|
|
|
mdWireWire = parseEagle( attribs.get<string>( "value" ) );
|
2012-06-05 04:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
/// Assemble a two part key as a simple concatonation of aFirst and aSecond parts,
|
2012-05-31 15:18:55 +00:00
|
|
|
/// using a separator.
|
2013-11-06 16:53:44 +00:00
|
|
|
static inline string makeKey( const string& aFirst, const string& aSecond )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string key = aFirst + '\x02' + aSecond;
|
2012-05-20 13:14:46 +00:00
|
|
|
return key;
|
|
|
|
}
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
/// Make a unique time stamp
|
2012-05-24 01:18:30 +00:00
|
|
|
static inline unsigned long timeStamp( CPTREE& aTree )
|
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
// in this case from a unique tree memory location
|
2012-05-24 01:18:30 +00:00
|
|
|
return (unsigned long)(void*) &aTree;
|
|
|
|
}
|
|
|
|
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2014-12-19 22:02:02 +00:00
|
|
|
/// Convert an Eagle curve end to a KiCad center for S_ARC
|
|
|
|
wxPoint kicad_arc_center( wxPoint start, wxPoint end, double angle )
|
|
|
|
{
|
|
|
|
// Eagle give us start and end.
|
|
|
|
// S_ARC wants start to give the center, and end to give the start.
|
|
|
|
double dx = end.x - start.x, dy = end.y - start.y;
|
|
|
|
wxPoint mid = (start + end) / 2;
|
|
|
|
|
|
|
|
double dlen = sqrt( dx*dx + dy*dy );
|
|
|
|
double dist = dlen / ( 2 * tan( DEG2RAD( angle ) / 2 ) );
|
|
|
|
|
|
|
|
wxPoint center(
|
|
|
|
mid.x + dist * ( dy / dlen ),
|
|
|
|
mid.y - dist * ( dx / dlen )
|
|
|
|
);
|
|
|
|
|
|
|
|
return center;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
EAGLE_PLUGIN::EAGLE_PLUGIN() :
|
2012-06-05 04:39:37 +00:00
|
|
|
m_rules( new ERULES() ),
|
2013-09-22 00:28:02 +00:00
|
|
|
m_xpath( new XPATH() ),
|
|
|
|
m_mod_time( wxDateTime::Now() )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
|
|
|
init( NULL );
|
2013-03-13 16:38:54 +00:00
|
|
|
|
|
|
|
clear_cu_map();
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
2012-05-16 02:27:27 +00:00
|
|
|
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
EAGLE_PLUGIN::~EAGLE_PLUGIN()
|
|
|
|
{
|
2012-06-05 04:39:37 +00:00
|
|
|
delete m_rules;
|
2012-06-02 17:07:30 +00:00
|
|
|
delete m_xpath;
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
2012-05-16 02:27:27 +00:00
|
|
|
|
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
const wxString EAGLE_PLUGIN::PluginName() const
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2013-11-27 06:04:04 +00:00
|
|
|
return wxT( "Eagle" );
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
const wxString EAGLE_PLUGIN::GetFileExtension() const
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2013-11-27 06:04:04 +00:00
|
|
|
return wxT( "brd" );
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
int inline EAGLE_PLUGIN::kicad( double d ) const
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2012-05-20 13:14:46 +00:00
|
|
|
return KiROUND( biu_per_mm * d );
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
wxSize inline EAGLE_PLUGIN::kicad_fontz( double d ) const
|
|
|
|
{
|
|
|
|
// texts seem to better match eagle when scaled down by 0.95
|
|
|
|
int kz = kicad( d ) * 95 / 100;
|
|
|
|
return wxSize( kz, kz );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2012-05-20 13:14:46 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
PTREE doc;
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
m_board = aAppendToMe ? aAppendToMe : new BOARD();
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
// Give the filename to the board if it's new
|
|
|
|
if( !aAppendToMe )
|
|
|
|
m_board->SetFileName( aFileName );
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
// delete on exception, iff I own m_board, according to aAppendToMe
|
2012-11-15 16:04:10 +00:00
|
|
|
auto_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
// 8 bit "filename" should be encoded according to disk filename encoding,
|
|
|
|
// (maybe this is current locale, maybe not, its a filesystem issue),
|
|
|
|
// and is not necessarily utf8.
|
2013-11-06 16:53:44 +00:00
|
|
|
string filename = (const char*) aFileName.char_str( wxConvFile );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
read_xml( filename, doc, xml_parser::trim_whitespace | xml_parser::no_comments );
|
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
m_min_trace = INT_MAX;
|
|
|
|
m_min_via = INT_MAX;
|
|
|
|
m_min_via_hole = INT_MAX;
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
loadAllSections( doc );
|
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
|
2013-03-14 22:54:47 +00:00
|
|
|
|
|
|
|
if( m_min_trace < designSettings.m_TrackMinWidth )
|
|
|
|
designSettings.m_TrackMinWidth = m_min_trace;
|
|
|
|
|
|
|
|
if( m_min_via < designSettings.m_ViasMinSize )
|
|
|
|
designSettings.m_ViasMinSize = m_min_via;
|
|
|
|
|
|
|
|
if( m_min_via_hole < designSettings.m_ViasMinDrill )
|
|
|
|
designSettings.m_ViasMinDrill = m_min_via_hole;
|
|
|
|
|
|
|
|
if( m_rules->mdWireWire )
|
|
|
|
{
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR defaultNetclass = designSettings.GetDefault();
|
2013-03-14 22:54:47 +00:00
|
|
|
int clearance = KiROUND( m_rules->mdWireWire );
|
|
|
|
|
|
|
|
if( clearance < defaultNetclass->GetClearance() )
|
|
|
|
defaultNetclass->SetClearance( clearance );
|
|
|
|
}
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
// should be empty, else missing m_xpath->pop()
|
|
|
|
wxASSERT( m_xpath->Contents().size() == 0 );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
catch( file_parser_error fpe )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
|
|
|
// for xml_parser_error, what() has the line number in it,
|
|
|
|
// but no byte offset. That should be an adequate error message.
|
2012-06-02 17:07:30 +00:00
|
|
|
THROW_IO_ERROR( fpe.what() );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
// Class ptree_error is a base class for xml_parser_error & file_parser_error,
|
|
|
|
// so one catch should be OK for all errors.
|
|
|
|
catch( ptree_error pte )
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string errmsg = pte.what();
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
errmsg += " @\n";
|
|
|
|
errmsg += m_xpath->Contents();
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
THROW_IO_ERROR( errmsg );
|
2012-06-01 07:39:32 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
// IO_ERROR exceptions are left uncaught, they pass upwards from here.
|
|
|
|
|
|
|
|
centerBoard();
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
deleter.release();
|
|
|
|
return m_board;
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void EAGLE_PLUGIN::init( const PROPERTIES* aProperties )
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
m_hole_count = 0;
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->clear();
|
2012-05-24 15:00:59 +00:00
|
|
|
m_pads_to_nets.clear();
|
2013-01-02 04:05:48 +00:00
|
|
|
|
|
|
|
// m_templates.clear(); this is the FOOTPRINT cache too
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
m_board = NULL;
|
|
|
|
m_props = aProperties;
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
mm_per_biu = 1/IU_PER_MM;
|
|
|
|
biu_per_mm = IU_PER_MM;
|
2012-06-05 04:39:37 +00:00
|
|
|
|
|
|
|
delete m_rules;
|
|
|
|
m_rules = new ERULES();
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2013-03-13 16:38:54 +00:00
|
|
|
void EAGLE_PLUGIN::clear_cu_map()
|
|
|
|
{
|
|
|
|
// All cu layers are invalid until we see them in the <layers> section while
|
|
|
|
// loading either a board or library. See loadLayerDefs().
|
|
|
|
for( unsigned i = 0; i < DIM(m_cu_map); ++i )
|
|
|
|
m_cu_map[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
void EAGLE_PLUGIN::loadAllSections( CPTREE& aDoc )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-06-01 07:39:32 +00:00
|
|
|
CPTREE& drawing = aDoc.get_child( "eagle.drawing" );
|
2012-06-05 04:39:37 +00:00
|
|
|
CPTREE& board = drawing.get_child( "board" );
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "eagle.drawing" );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
|
|
|
m_xpath->push( "board" );
|
|
|
|
|
|
|
|
CPTREE& designrules = board.get_child( "designrules" );
|
|
|
|
loadDesignRules( designrules );
|
|
|
|
|
|
|
|
m_xpath->pop();
|
|
|
|
}
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
2013-03-13 16:38:54 +00:00
|
|
|
m_xpath->push( "layers" );
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
CPTREE& layers = drawing.get_child( "layers" );
|
|
|
|
loadLayerDefs( layers );
|
2013-03-13 16:38:54 +00:00
|
|
|
|
|
|
|
m_xpath->pop();
|
2012-06-01 07:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "board" );
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
CPTREE& plain = board.get_child( "plain" );
|
|
|
|
loadPlain( plain );
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
CPTREE& signals = board.get_child( "signals" );
|
|
|
|
loadSignals( signals );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
CPTREE& libs = board.get_child( "libraries" );
|
|
|
|
loadLibraries( libs );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
CPTREE& elems = board.get_child( "elements" );
|
|
|
|
loadElements( elems );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop(); // "board"
|
2012-06-01 07:39:32 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop(); // "eagle.drawing"
|
2012-06-01 07:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
void EAGLE_PLUGIN::loadDesignRules( CPTREE& aDesignRules )
|
|
|
|
{
|
|
|
|
m_xpath->push( "designrules" );
|
|
|
|
m_rules->parse( aDesignRules );
|
|
|
|
m_xpath->pop(); // "designrules"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
void EAGLE_PLUGIN::loadLayerDefs( CPTREE& aLayers )
|
|
|
|
{
|
|
|
|
typedef std::vector<ELAYER> ELAYERS;
|
|
|
|
typedef ELAYERS::const_iterator EITER;
|
|
|
|
|
|
|
|
ELAYERS cu; // copper layers
|
|
|
|
|
|
|
|
// find the subset of layers that are copper, and active
|
|
|
|
for( CITER layer = aLayers.begin(); layer != aLayers.end(); ++layer )
|
|
|
|
{
|
|
|
|
ELAYER elayer( layer->second );
|
|
|
|
|
|
|
|
if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
|
|
|
|
{
|
|
|
|
cu.push_back( elayer );
|
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 16:17:16 +00:00
|
|
|
// establish cu layer map:
|
|
|
|
int ki_layer_count = 0;
|
2013-09-22 00:28:02 +00:00
|
|
|
|
2013-03-13 16:17:16 +00:00
|
|
|
for( EITER it = cu.begin(); it != cu.end(); ++it, ++ki_layer_count )
|
|
|
|
{
|
|
|
|
if( ki_layer_count == 0 )
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_map[it->number] = F_Cu;
|
2013-03-13 16:17:16 +00:00
|
|
|
else if( ki_layer_count == int( cu.size()-1 ) )
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_map[it->number] = B_Cu;
|
2013-03-13 16:17:16 +00:00
|
|
|
else
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
2013-03-13 16:17:16 +00:00
|
|
|
// some eagle boards do not have contiguous layer number sequences.
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
#if 0 // pre LAYER_ID & LSET:
|
2013-03-13 16:17:16 +00:00
|
|
|
m_cu_map[it->number] = cu.size() - 1 - ki_layer_count;
|
2014-06-24 16:17:18 +00:00
|
|
|
#else
|
|
|
|
m_cu_map[it->number] = ki_layer_count;
|
|
|
|
#endif
|
|
|
|
}
|
2013-03-13 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
|
|
|
printf( "m_cu_map:\n" );
|
|
|
|
for( unsigned i=0; i<DIM(m_cu_map); ++i )
|
|
|
|
{
|
|
|
|
printf( "\t[%d]:%d\n", i, m_cu_map[i] );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-20 16:35:03 +00:00
|
|
|
// Set the layer names and cu count iff we're loading a board.
|
|
|
|
if( m_board )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2013-11-20 16:35:03 +00:00
|
|
|
m_board->SetCopperLayerCount( cu.size() );
|
|
|
|
|
|
|
|
for( EITER it = cu.begin(); it != cu.end(); ++it )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( it->number );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2013-11-20 16:35:03 +00:00
|
|
|
// these function provide their own protection against UNDEFINED_LAYER:
|
|
|
|
m_board->SetLayerName( layer, FROM_UTF8( it->name.c_str() ) );
|
|
|
|
m_board->SetLayerType( layer, LT_SIGNAL );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2013-11-20 16:35:03 +00:00
|
|
|
// could map the colors here
|
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-16 02:27:27 +00:00
|
|
|
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
void EAGLE_PLUGIN::loadPlain( CPTREE& aGraphics )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "plain" );
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
// (polygon | wire | text | circle | rectangle | frame | hole)*
|
|
|
|
for( CITER gr = aGraphics.begin(); gr != aGraphics.end(); ++gr )
|
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( gr->first == "wire" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "wire" );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
|
|
|
EWIRE w( gr->second );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( w.layer );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2014-12-19 22:02:02 +00:00
|
|
|
wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
|
|
|
|
wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
|
|
|
|
int width = kicad( w.width );
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layer != UNDEFINED_LAYER )
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
|
|
|
DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
|
|
|
|
m_board->Add( dseg, ADD_APPEND );
|
|
|
|
|
2014-12-19 22:02:02 +00:00
|
|
|
if( !w.curve )
|
|
|
|
{
|
|
|
|
dseg->SetStart( start );
|
|
|
|
dseg->SetEnd( end );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint center = kicad_arc_center( start, end, *w.curve);
|
|
|
|
|
|
|
|
dseg->SetShape( S_ARC );
|
|
|
|
dseg->SetStart( center );
|
|
|
|
dseg->SetEnd( start );
|
|
|
|
dseg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
|
|
|
|
}
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
dseg->SetTimeStamp( timeStamp( gr->second ) );
|
|
|
|
dseg->SetLayer( layer );
|
2014-12-19 22:02:02 +00:00
|
|
|
dseg->SetWidth( width );
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( gr->first == "text" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-24 01:18:30 +00:00
|
|
|
#if defined(DEBUG)
|
2012-08-11 05:50:17 +00:00
|
|
|
if( gr->second.data() == "ATMEGA328" )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
|
|
|
int breakhere = 1;
|
|
|
|
(void) breakhere;
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "text" );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2013-11-04 02:09:28 +00:00
|
|
|
ETEXT t( gr->second );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( t.layer );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
|
|
|
if( layer != UNDEFINED_LAYER )
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
|
|
|
TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
|
|
|
|
m_board->Add( pcbtxt, ADD_APPEND );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
pcbtxt->SetLayer( layer );
|
|
|
|
pcbtxt->SetTimeStamp( timeStamp( gr->second ) );
|
|
|
|
pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
|
2013-03-18 19:36:07 +00:00
|
|
|
pcbtxt->SetTextPosition( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
pcbtxt->SetSize( kicad_fontz( t.size ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
pcbtxt->SetThickness( kicad( t.size * ratio / 100 ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
|
2012-06-07 01:49:43 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
if( t.rot )
|
|
|
|
{
|
|
|
|
int sign = t.rot->mirror ? -1 : 1;
|
|
|
|
pcbtxt->SetMirrored( t.rot->mirror );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
double degrees = t.rot->degrees;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
if( degrees == 90 || t.rot->spin )
|
|
|
|
pcbtxt->SetOrientation( sign * t.rot->degrees * 10 );
|
2012-06-07 01:49:43 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( degrees == 180 )
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( degrees == 270 )
|
|
|
|
{
|
|
|
|
pcbtxt->SetOrientation( sign * 90 * 10 );
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
}
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
switch( align )
|
|
|
|
{
|
|
|
|
case ETEXT::CENTER:
|
|
|
|
// this was the default in pcbtxt's constructor
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_LEFT:
|
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_RIGHT:
|
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( gr->first == "circle" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "circle" );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
|
|
|
ECIRCLE c( gr->second );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( c.layer );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layer != UNDEFINED_LAYER ) // unsupported layer
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
|
|
|
DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
|
|
|
|
m_board->Add( dseg, ADD_APPEND );
|
|
|
|
|
|
|
|
dseg->SetShape( S_CIRCLE );
|
|
|
|
dseg->SetTimeStamp( timeStamp( gr->second ) );
|
|
|
|
dseg->SetLayer( layer );
|
|
|
|
dseg->SetStart( wxPoint( kicad_x( c.x ), kicad_y( c.y ) ) );
|
|
|
|
dseg->SetEnd( wxPoint( kicad_x( c.x + c.radius ), kicad_y( c.y ) ) );
|
|
|
|
dseg->SetWidth( kicad( c.width ) );
|
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
|
|
|
// This seems to be a simplified rectangular [copper] zone, cannot find any
|
|
|
|
// net related info on it from the DTD.
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( gr->first == "rectangle" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "rectangle" );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
|
|
|
ERECT r( gr->second );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( r.layer );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsCopperLayer( layer ) )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-05-29 18:10:56 +00:00
|
|
|
// use a "netcode = 0" type ZONE:
|
|
|
|
ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
|
|
|
|
m_board->Add( zone, ADD_APPEND );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
zone->SetTimeStamp( timeStamp( gr->second ) );
|
|
|
|
zone->SetLayer( layer );
|
2014-02-25 10:40:34 +00:00
|
|
|
zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-07-30 07:40:25 +00:00
|
|
|
CPolyLine::HATCH_STYLE outline_hatch = CPolyLine::DIAGONAL_EDGE;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2013-03-20 14:50:12 +00:00
|
|
|
zone->Outline()->Start( layer, kicad_x( r.x1 ), kicad_y( r.y1 ), outline_hatch );
|
2012-05-29 18:10:56 +00:00
|
|
|
zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
|
|
|
|
zone->AppendCorner( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
|
|
|
|
zone->AppendCorner( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
|
2013-03-20 14:50:12 +00:00
|
|
|
zone->Outline()->CloseLastContour();
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
// this is not my fault:
|
2013-11-04 02:09:28 +00:00
|
|
|
zone->Outline()->SetHatch(
|
|
|
|
outline_hatch, Mils2iu( zone->Outline()->GetDefaultHatchPitchMils() ), true );
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( gr->first == "hole" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "hole" );
|
2012-05-31 15:18:55 +00:00
|
|
|
EHOLE e( gr->second );
|
|
|
|
|
|
|
|
// Fabricate a MODULE with a single PAD_HOLE_NOT_PLATED pad.
|
|
|
|
// Use m_hole_count to gen up a unique name.
|
|
|
|
|
|
|
|
MODULE* module = new MODULE( m_board );
|
|
|
|
m_board->Add( module, ADD_APPEND );
|
|
|
|
|
|
|
|
char temp[40];
|
|
|
|
sprintf( temp, "@HOLE%d", m_hole_count++ );
|
|
|
|
module->SetReference( FROM_UTF8( temp ) );
|
|
|
|
module->Reference().SetVisible( false );
|
|
|
|
|
|
|
|
wxPoint pos( kicad_x( e.x ), kicad_y( e.y ) );
|
|
|
|
|
|
|
|
module->SetPosition( pos );
|
|
|
|
|
|
|
|
// Add a PAD_HOLE_NOT_PLATED pad to this module.
|
|
|
|
D_PAD* pad = new D_PAD( module );
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Pads().PushBack( pad );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
|
|
|
pad->SetShape( PAD_ROUND );
|
|
|
|
pad->SetAttribute( PAD_HOLE_NOT_PLATED );
|
|
|
|
|
|
|
|
/* pad's position is already centered on module at relative (0, 0)
|
|
|
|
wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
|
|
|
|
|
|
|
|
pad->SetPos0( padpos );
|
|
|
|
pad->SetPosition( padpos + module->GetPosition() );
|
|
|
|
*/
|
|
|
|
|
|
|
|
wxSize sz( kicad( e.drill ), kicad( e.drill ) );
|
|
|
|
|
|
|
|
pad->SetDrillSize( sz );
|
|
|
|
pad->SetSize( sz );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
pad->SetLayerSet( LSET::AllCuMask() );
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( gr->first == "frame" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-24 15:00:59 +00:00
|
|
|
// picture this
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( gr->first == "polygon" )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
// could be on a copper layer, could be on another layer.
|
|
|
|
// copper layer would be done using netCode=0 type of ZONE_CONTAINER.
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
void EAGLE_PLUGIN::loadLibrary( CPTREE& aLib, const string* aLibName )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->push( "packages" );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
// library will have <xmlattr> node, skip that and get the single packages node
|
|
|
|
CPTREE& packages = aLib.get_child( "packages" );
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
// Create a MODULE for all the eagle packages, for use later via a copy constructor
|
|
|
|
// to instantiate needed MODULES in our BOARD. Save the MODULE templates in
|
|
|
|
// a MODULE_MAP using a single lookup key consisting of libname+pkgname.
|
|
|
|
|
|
|
|
for( CITER package = packages.begin(); package != packages.end(); ++package )
|
|
|
|
{
|
|
|
|
m_xpath->push( "package", "name" );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
const string& pack_ref = package->second.get<string>( "<xmlattr>.name" );
|
|
|
|
|
|
|
|
string pack_name( pack_ref );
|
|
|
|
|
2013-11-29 18:29:41 +00:00
|
|
|
ReplaceIllegalFileNameChars( &pack_name );
|
2013-11-06 16:53:44 +00:00
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
2013-01-02 04:05:48 +00:00
|
|
|
if( pack_name == "TO220H" )
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
int breakhere = 1;
|
|
|
|
(void) breakhere;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
m_xpath->Value( pack_name.c_str() );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
string key = aLibName ? makeKey( *aLibName, pack_name ) : pack_name;
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
MODULE* m = makeModule( package->second, pack_name );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
// add the templating MODULE to the MODULE template factory "m_templates"
|
|
|
|
std::pair<MODULE_ITER, bool> r = m_templates.insert( key, m );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-11-20 16:35:03 +00:00
|
|
|
if( !r.second
|
|
|
|
// && !( m_props && m_props->Value( "ignore_duplicates" ) )
|
|
|
|
)
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
|
|
|
wxString lib = aLibName ? FROM_UTF8( aLibName->c_str() ) : m_lib_path;
|
|
|
|
wxString pkg = FROM_UTF8( pack_name.c_str() );
|
|
|
|
|
|
|
|
wxString emsg = wxString::Format(
|
2013-11-20 16:35:03 +00:00
|
|
|
_( "<package> name: '%s' duplicated in eagle <library>: '%s'" ),
|
2013-01-02 04:05:48 +00:00
|
|
|
GetChars( pkg ),
|
|
|
|
GetChars( lib )
|
|
|
|
);
|
|
|
|
THROW_IO_ERROR( emsg );
|
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->pop();
|
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->pop(); // "packages"
|
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
void EAGLE_PLUGIN::loadLibraries( CPTREE& aLibs )
|
|
|
|
{
|
|
|
|
m_xpath->push( "libraries.library", "name" );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
for( CITER library = aLibs.begin(); library != aLibs.end(); ++library )
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
const string& lib_name = library->second.get<string>( "<xmlattr>.name" );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->Value( lib_name.c_str() );
|
|
|
|
|
|
|
|
loadLibrary( library->second, &lib_name );
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop();
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
void EAGLE_PLUGIN::loadElements( CPTREE& aElements )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "elements.element", "name" );
|
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
EATTR name;
|
|
|
|
EATTR value;
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
for( CITER it = aElements.begin(); it != aElements.end(); ++it )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( it->first != "element" )
|
2012-05-30 21:40:32 +00:00
|
|
|
continue;
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
EELEMENT e( it->second );
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
// use "NULL-ness" as an indication of presence of the attribute:
|
2012-06-07 01:49:43 +00:00
|
|
|
EATTR* nameAttr = 0;
|
|
|
|
EATTR* valueAttr = 0;
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->Value( e.name.c_str() );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
string key = makeKey( e.library, e.package );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
MODULE_CITER mi = m_templates.find( key );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
if( mi == m_templates.end() )
|
|
|
|
{
|
|
|
|
wxString emsg = wxString::Format( _( "No '%s' package in library '%s'" ),
|
2012-05-31 15:18:55 +00:00
|
|
|
GetChars( FROM_UTF8( e.package.c_str() ) ),
|
|
|
|
GetChars( FROM_UTF8( e.library.c_str() ) ) );
|
2012-05-30 21:40:32 +00:00
|
|
|
THROW_IO_ERROR( emsg );
|
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
#if defined(DEBUG)
|
2012-08-11 05:50:17 +00:00
|
|
|
if( e.name == "ARM_C8" )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
|
|
|
int breakhere = 1;
|
|
|
|
(void) breakhere;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// copy constructor to clone the template
|
|
|
|
MODULE* m = new MODULE( *mi->second );
|
|
|
|
m_board->Add( m, ADD_APPEND );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
// update the nets within the pads of the clone
|
2013-03-18 19:36:07 +00:00
|
|
|
for( D_PAD* pad = m->Pads(); pad; pad = pad->Next() )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string key = makeKey( e.name, TO_UTF8( pad->GetPadName() ) );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
NET_MAP_CITER ni = m_pads_to_nets.find( key );
|
|
|
|
if( ni != m_pads_to_nets.end() )
|
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
const ENET* enet = &ni->second;
|
2014-02-25 10:40:34 +00:00
|
|
|
pad->SetNetCode( enet->netcode );
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
|
|
|
|
m->SetReference( FROM_UTF8( e.name.c_str() ) );
|
|
|
|
m->SetValue( FROM_UTF8( e.value.c_str() ) );
|
2012-05-30 21:40:32 +00:00
|
|
|
// m->Value().SetVisible( false );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
// initalize these to default values incase the <attribute> elements are not present.
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "attribute", "name" );
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
// VALUE and NAME can have something like our text "effects" overrides
|
|
|
|
// in SWEET and new schematic. Eagle calls these XML elements "attribute".
|
2012-06-01 07:39:32 +00:00
|
|
|
// There can be one for NAME and/or VALUE both. Features present in the
|
|
|
|
// EATTR override the ones established in the package only if they are
|
2012-06-02 17:07:30 +00:00
|
|
|
// present here (except for rot, which if not present means angle zero).
|
|
|
|
// So the logic is a bit different than in packageText() and in plain text.
|
2012-05-30 21:40:32 +00:00
|
|
|
for( CITER ait = it->second.begin(); ait != it->second.end(); ++ait )
|
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( ait->first != "attribute" )
|
2012-05-30 21:40:32 +00:00
|
|
|
continue;
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
EATTR a( ait->second );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
if( a.name == "NAME" )
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
|
|
|
name = a;
|
|
|
|
nameAttr = &name;
|
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( a.name == "VALUE" )
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
2012-06-05 04:39:37 +00:00
|
|
|
value = a;
|
2012-06-07 01:49:43 +00:00
|
|
|
valueAttr = &value;
|
|
|
|
}
|
2012-06-05 04:39:37 +00:00
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-05 04:39:37 +00:00
|
|
|
m_xpath->pop(); // "attribute"
|
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
orientModuleAndText( m, e, nameAttr, valueAttr );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_xpath->pop(); // "elements.element"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EAGLE_PLUGIN::orientModuleAndText( MODULE* m, const EELEMENT& e,
|
|
|
|
const EATTR* nameAttr, const EATTR* valueAttr )
|
|
|
|
{
|
|
|
|
if( e.rot )
|
|
|
|
{
|
|
|
|
if( e.rot->mirror )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
double orientation = e.rot->degrees + 180.0;
|
|
|
|
m->SetOrientation( orientation * 10 );
|
2012-06-07 01:49:43 +00:00
|
|
|
m->Flip( m->GetPosition() );
|
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else
|
|
|
|
m->SetOrientation( e.rot->degrees * 10 );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
orientModuleText( m, e, &m->Reference(), nameAttr );
|
|
|
|
orientModuleText( m, e, &m->Value(), valueAttr );
|
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e,
|
|
|
|
TEXTE_MODULE* txt, const EATTR* aAttr )
|
|
|
|
{
|
|
|
|
if( aAttr )
|
|
|
|
{
|
|
|
|
const EATTR& a = *aAttr;
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
if( a.value )
|
|
|
|
{
|
|
|
|
txt->SetText( FROM_UTF8( a.value->c_str() ) );
|
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
if( a.x && a.y ) // boost::optional
|
|
|
|
{
|
|
|
|
wxPoint pos( kicad_x( *a.x ), kicad_y( *a.y ) );
|
2013-03-18 19:36:07 +00:00
|
|
|
txt->SetTextPosition( pos );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
// Even though size and ratio are both optional, I am not seeing
|
|
|
|
// a case where ratio is present but size is not.
|
|
|
|
double ratio = 8;
|
|
|
|
wxSize fontz = txt->GetSize();
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
if( a.size )
|
|
|
|
{
|
|
|
|
fontz = kicad_fontz( *a.size );
|
|
|
|
txt->SetSize( fontz );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
if( a.ratio )
|
|
|
|
ratio = *a.ratio;
|
|
|
|
}
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
int lw = int( fontz.y * ratio / 100.0 );
|
|
|
|
txt->SetThickness( lw );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
|
|
|
|
|
|
|
|
// The "rot" in a EATTR seems to be assumed to be zero if it is not
|
|
|
|
// present, and this zero rotation becomes an override to the
|
|
|
|
// package's text field. If they did not want zero, they specify
|
|
|
|
// what they want explicitly.
|
|
|
|
double degrees = a.rot ? a.rot->degrees : 0;
|
|
|
|
double orient; // relative to parent
|
|
|
|
|
|
|
|
int sign = 1;
|
|
|
|
bool spin = false;
|
|
|
|
|
|
|
|
if( a.rot )
|
|
|
|
{
|
|
|
|
spin = a.rot->spin;
|
|
|
|
sign = a.rot->mirror ? -1 : 1;
|
|
|
|
txt->SetMirrored( a.rot->mirror );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( degrees == 90 || degrees == 0 || spin )
|
|
|
|
{
|
|
|
|
orient = degrees - m->GetOrientation() / 10;
|
|
|
|
txt->SetOrientation( sign * orient * 10 );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( degrees == 180 )
|
|
|
|
{
|
|
|
|
orient = 0 - m->GetOrientation() / 10;
|
|
|
|
txt->SetOrientation( sign * orient * 10 );
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( degrees == 270 )
|
|
|
|
{
|
|
|
|
orient = 90 - m->GetOrientation() / 10;
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
txt->SetOrientation( sign * orient * 10 );
|
|
|
|
}
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
orient = 90 + degrees - m->GetOrientation() / 10;
|
|
|
|
txt->SetOrientation( sign * orient * 10 );
|
|
|
|
}
|
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
switch( align )
|
|
|
|
{
|
|
|
|
case ETEXT::TOP_RIGHT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
else // the text is per the original package, sans <attribute>
|
|
|
|
{
|
|
|
|
double degrees = ( txt->GetOrientation() + m->GetOrientation() ) / 10;
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
// @todo there are a few more cases than these to contend with:
|
2012-06-07 01:49:43 +00:00
|
|
|
if( (!txt->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ))
|
|
|
|
|| ( txt->IsMirrored() && ( degrees == 360 ) ) )
|
|
|
|
{
|
|
|
|
// ETEXT::TOP_RIGHT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
}
|
|
|
|
}
|
2012-08-11 19:14:45 +00:00
|
|
|
|
|
|
|
txt->SetLocalCoord();
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
MODULE* EAGLE_PLUGIN::makeModule( CPTREE& aPackage, const string& aPkgName ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
BOARD_CONNECTED_ITEMs do not store net code anymore (m_NetCode field), instead net info is stored using a pointer to NETINFO_ITEM.
GetNet() refers to the net code stored in the NETINFO_ITEM. SetNet() finds an appropriate NETINFO_ITEM and uses it.
Removing GetNet() & SetNet() (and the whole net code idea) requires too many changes in the code (~250 references to the mentioned functions).
BOARD_CONNECTED_ITEMs by default get a pointer to NETINFO_ITEM that stores unconnected items. This requires for all BOARD_CONNECTED_ITEMs to have a parent (so BOARD* is accessible). The only orphaned item is BOARD_DESIGN_SETTINGS::m_Pad_Master, but it does not cause any issues so far.
Items that do not have access to a BOARD (do not have set parents) and therefore cannot get net assigned, by default get const static NETINFO_LIST::ORPHANED.
Performed tests:
- loaded .kicad_pcb, KiCad legacy board, Eagle 6.0 board, P-CAD board - all ok
- load a simple project, reload netlist after changing connections in eeschema - ok
- save & reload a board - ok, but still contain empty nets
- remove everything, restore with undo - ok
- remove everything, reload netlist - ok
- changing net names (all possibilites: empty->existing, empty->not existing, existing->empty, existing->not existing) - all ok
- zones: when net is changed to a net that does not have any nodes besides the zone itself, it does not get filled
2014-01-15 17:03:06 +00:00
|
|
|
std::auto_ptr<MODULE> m( new MODULE( m_board ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
m->SetFPID( FPID( aPkgName ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
opt_string description = aPackage.get_optional<string>( "description" );
|
2012-05-20 13:14:46 +00:00
|
|
|
if( description )
|
|
|
|
m->SetDescription( FROM_UTF8( description->c_str() ) );
|
|
|
|
|
|
|
|
for( CITER it = aPackage.begin(); it != aPackage.end(); ++it )
|
|
|
|
{
|
|
|
|
CPTREE& t = it->second;
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
if( it->first == "wire" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packageWire( m.get(), t );
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "pad" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packagePad( m.get(), t );
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "text" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packageText( m.get(), t );
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "rectangle" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packageRectangle( m.get(), t );
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "polygon" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packagePolygon( m.get(), t );
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "circle" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packageCircle( m.get(), t );
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "hole" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packageHole( m.get(), t );
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "smd" )
|
2012-05-20 13:14:46 +00:00
|
|
|
packageSMD( m.get(), t );
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packageWire( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-11-04 02:09:28 +00:00
|
|
|
EWIRE w( aTree );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( w.layer );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2013-11-04 02:09:28 +00:00
|
|
|
if( IsNonCopperLayer( layer ) ) // only valid non-copper wires, skip copper package wires
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
|
|
|
wxPoint start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
|
|
|
|
wxPoint end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
|
|
|
|
int width = kicad( w.width );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2014-12-07 17:07:05 +00:00
|
|
|
EDGE_MODULE* dwg;
|
|
|
|
if( !w.curve )
|
|
|
|
{
|
|
|
|
dwg = new EDGE_MODULE( aModule, S_SEGMENT );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2014-12-07 17:07:05 +00:00
|
|
|
dwg->SetStart0( start );
|
|
|
|
dwg->SetEnd0( end );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwg = new EDGE_MODULE( aModule, S_ARC );
|
2014-12-19 22:02:02 +00:00
|
|
|
wxPoint center = kicad_arc_center( start, end, *w.curve);
|
2014-12-07 17:07:05 +00:00
|
|
|
|
2014-12-19 22:02:02 +00:00
|
|
|
dwg->SetStart0( center );
|
2014-12-07 17:07:05 +00:00
|
|
|
dwg->SetEnd0( start );
|
|
|
|
dwg->SetAngle( *w.curve * -10.0 ); // KiCad rotates the other way
|
|
|
|
}
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
dwg->SetLayer( layer );
|
|
|
|
dwg->SetWidth( width );
|
2014-12-07 17:07:05 +00:00
|
|
|
|
|
|
|
aModule->GraphicalItems().PushBack( dwg );
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packagePad( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-05-29 18:10:56 +00:00
|
|
|
// this is thru hole technology here, no SMDs
|
2012-05-30 21:40:32 +00:00
|
|
|
EPAD e( aTree );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
|
|
|
D_PAD* pad = new D_PAD( aModule );
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->Pads().PushBack( pad );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
|
|
|
// pad's "Position" is not relative to the module's,
|
|
|
|
// whereas Pos0 is relative to the module's but is the unrotated coordinate.
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
|
|
|
pad->SetPos0( padpos );
|
|
|
|
|
|
|
|
RotatePoint( &padpos, aModule->GetOrientation() );
|
|
|
|
|
|
|
|
pad->SetPosition( padpos + aModule->GetPosition() );
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
pad->SetDrillSize( wxSize( kicad( e.drill ), kicad( e.drill ) ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( e.shape )
|
|
|
|
{
|
|
|
|
switch( *e.shape )
|
|
|
|
{
|
|
|
|
case EPAD::ROUND:
|
|
|
|
wxASSERT( pad->GetShape()==PAD_CIRCLE ); // verify set in D_PAD constructor
|
|
|
|
break;
|
|
|
|
case EPAD::OCTAGON:
|
|
|
|
// no KiCad octagonal pad shape, use PAD_CIRCLE for now.
|
|
|
|
// pad->SetShape( PAD_OCTAGON );
|
|
|
|
wxASSERT( pad->GetShape()==PAD_CIRCLE ); // verify set in D_PAD constructor
|
|
|
|
break;
|
|
|
|
case EPAD::LONG:
|
|
|
|
pad->SetShape( PAD_OVAL );
|
|
|
|
break;
|
|
|
|
case EPAD::SQUARE:
|
|
|
|
pad->SetShape( PAD_RECT );
|
|
|
|
break;
|
|
|
|
case EPAD::OFFSET:
|
|
|
|
; // don't know what to do here.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if shape is not present, our default is circle and that matches their default "round"
|
|
|
|
}
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
if( e.diameter )
|
|
|
|
{
|
|
|
|
int diameter = kicad( *e.diameter );
|
|
|
|
pad->SetSize( wxSize( diameter, diameter ) );
|
|
|
|
}
|
|
|
|
else
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-05 04:39:37 +00:00
|
|
|
double drillz = pad->GetDrillSize().x;
|
|
|
|
double annulus = drillz * m_rules->rvPadTop; // copper annulus, eagle "restring"
|
|
|
|
annulus = Clamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
|
|
|
|
int diameter = KiROUND( drillz + 2 * annulus );
|
|
|
|
pad->SetSize( wxSize( KiROUND( diameter ), KiROUND( diameter ) ) );
|
2012-05-31 15:18:55 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( pad->GetShape() == PAD_OVAL )
|
|
|
|
{
|
2012-06-05 04:39:37 +00:00
|
|
|
// The Eagle "long" pad is wider than it is tall,
|
|
|
|
// m_elongation is percent elongation
|
2012-05-31 15:18:55 +00:00
|
|
|
wxSize sz = pad->GetSize();
|
2012-06-05 04:39:37 +00:00
|
|
|
sz.x = ( sz.x * ( 100 + m_rules->psElongationLong ) ) / 100;
|
2012-05-31 15:18:55 +00:00
|
|
|
pad->SetSize( sz );
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( e.rot )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
pad->SetOrientation( e.rot->degrees * 10 );
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
// @todo: handle stop and thermal
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packageText( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-11-04 02:09:28 +00:00
|
|
|
ETEXT t( aTree );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( t.layer );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
layer = Cmts_User;
|
2013-11-04 02:09:28 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
|
|
|
TEXTE_MODULE* txt;
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
if( t.text == ">NAME" || t.text == ">name" )
|
2012-05-24 01:18:30 +00:00
|
|
|
txt = &aModule->Reference();
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( t.text == ">VALUE" || t.text == ">value" )
|
2012-05-24 01:18:30 +00:00
|
|
|
txt = &aModule->Value();
|
|
|
|
else
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
|
|
|
txt = new TEXTE_MODULE( aModule );
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->GraphicalItems().PushBack( txt );
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
|
|
|
txt->SetTimeStamp( timeStamp( aTree ) );
|
|
|
|
txt->SetText( FROM_UTF8( t.text.c_str() ) );
|
|
|
|
|
|
|
|
wxPoint pos( kicad_x( t.x ), kicad_y( t.y ) );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
txt->SetTextPosition( pos );
|
2012-05-24 01:18:30 +00:00
|
|
|
txt->SetPos0( pos - aModule->GetPosition() );
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
txt->SetLayer( layer );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
|
|
|
txt->SetSize( kicad_fontz( t.size ) );
|
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
|
2012-05-24 01:18:30 +00:00
|
|
|
|
|
|
|
txt->SetThickness( kicad( t.size * ratio / 100 ) );
|
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
// An eagle package is never rotated, the DTD does not allow it.
|
|
|
|
// angle -= aModule->GetOrienation();
|
|
|
|
|
|
|
|
if( t.rot )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-07 01:49:43 +00:00
|
|
|
int sign = t.rot->mirror ? -1 : 1;
|
|
|
|
txt->SetMirrored( t.rot->mirror );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
double degrees = t.rot->degrees;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
if( degrees == 90 || t.rot->spin )
|
|
|
|
txt->SetOrientation( sign * degrees * 10 );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
else if( degrees == 180 )
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
|
|
|
|
else if( degrees == 270 )
|
|
|
|
{
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
txt->SetOrientation( sign * 90 * 10 );
|
|
|
|
}
|
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
switch( align )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
|
|
|
case ETEXT::CENTER:
|
|
|
|
// this was the default in pcbtxt's constructor
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_LEFT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_RIGHT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
|
|
|
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packageRectangle( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-11-04 02:09:28 +00:00
|
|
|
ERECT r( aTree );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( r.layer );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
|
|
|
EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->GraphicalItems().PushBack( dwg );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
dwg->SetLayer( layer );
|
|
|
|
dwg->SetWidth( 0 );
|
|
|
|
|
|
|
|
dwg->SetTimeStamp( timeStamp( aTree ) );
|
|
|
|
|
|
|
|
std::vector<wxPoint> pts;
|
|
|
|
|
|
|
|
wxPoint start( wxPoint( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
|
|
|
|
wxPoint end( wxPoint( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
|
|
|
|
|
|
|
|
pts.push_back( start );
|
|
|
|
pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y1 ) ) );
|
|
|
|
pts.push_back( wxPoint( kicad_x( r.x2 ), kicad_y( r.y2 ) ) );
|
|
|
|
pts.push_back( end );
|
|
|
|
|
|
|
|
dwg->SetPolyPoints( pts );
|
|
|
|
|
|
|
|
dwg->SetStart0( start );
|
|
|
|
dwg->SetEnd0( end );
|
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packagePolygon( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-06-01 07:39:32 +00:00
|
|
|
EPOLYGON p( aTree );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( p.layer );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsNonCopperLayer( layer ) ) // skip copper "package.rectangle"s
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
|
|
|
EDGE_MODULE* dwg = new EDGE_MODULE( aModule, S_POLYGON );
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->GraphicalItems().PushBack( dwg );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
dwg->SetWidth( 0 ); // it's filled, no need for boundary width
|
|
|
|
|
|
|
|
/*
|
|
|
|
switch( layer )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case Eco1_User: layer = F_SilkS; break;
|
|
|
|
case Eco2_User: layer = B_SilkS; break;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
// all MODULE templates (created from eagle packages) are on front layer
|
|
|
|
// until cloned.
|
2014-06-24 16:17:18 +00:00
|
|
|
case Cmts_User: layer = F_SilkS; break;
|
2012-06-01 07:39:32 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
dwg->SetLayer( layer );
|
|
|
|
|
|
|
|
dwg->SetTimeStamp( timeStamp( aTree ) );
|
|
|
|
|
|
|
|
std::vector<wxPoint> pts;
|
|
|
|
pts.reserve( aTree.size() );
|
|
|
|
|
|
|
|
for( CITER vi = aTree.begin(); vi != aTree.end(); ++vi )
|
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( vi->first != "vertex" ) // skip <xmlattr> node
|
2012-06-01 07:39:32 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
EVERTEX v( vi->second );
|
|
|
|
|
|
|
|
pts.push_back( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
dwg->SetPolyPoints( pts );
|
|
|
|
|
|
|
|
dwg->SetStart0( *pts.begin() );
|
|
|
|
dwg->SetEnd0( pts.back() );
|
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packageCircle( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-11-04 02:09:28 +00:00
|
|
|
ECIRCLE e( aTree );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( e.layer );
|
2013-11-04 02:09:28 +00:00
|
|
|
EDGE_MODULE* gr = new EDGE_MODULE( aModule, S_CIRCLE );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->GraphicalItems().PushBack( gr );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
gr->SetWidth( kicad( e.width ) );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
switch( (int) layer )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case UNDEFINED_LAYER: layer = Cmts_User; break;
|
2013-11-04 02:09:28 +00:00
|
|
|
/*
|
2014-06-24 16:17:18 +00:00
|
|
|
case Eco1_User: layer = F_SilkS; break;
|
|
|
|
case Eco2_User: layer = B_SilkS; break;
|
2012-06-01 07:39:32 +00:00
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-11-04 02:09:28 +00:00
|
|
|
}
|
2012-05-30 21:40:32 +00:00
|
|
|
|
|
|
|
gr->SetLayer( layer );
|
|
|
|
gr->SetTimeStamp( timeStamp( aTree ) );
|
|
|
|
|
|
|
|
gr->SetStart0( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
|
|
|
|
gr->SetEnd0( wxPoint( kicad_x( e.x + e.radius ), kicad_y( e.y ) ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packageHole( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
EHOLE e( aTree );
|
|
|
|
|
|
|
|
// we add a PAD_HOLE_NOT_PLATED pad to this module.
|
|
|
|
D_PAD* pad = new D_PAD( aModule );
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->Pads().PushBack( pad );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
|
|
|
pad->SetShape( PAD_ROUND );
|
|
|
|
pad->SetAttribute( PAD_HOLE_NOT_PLATED );
|
|
|
|
|
|
|
|
// Mechanical purpose only:
|
|
|
|
// no offset, no net name, no pad name allowed
|
|
|
|
// pad->SetOffset( wxPoint( 0, 0 ) );
|
|
|
|
// pad->SetPadName( wxEmptyString );
|
|
|
|
|
|
|
|
wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
|
|
|
|
|
|
|
|
pad->SetPos0( padpos );
|
|
|
|
pad->SetPosition( padpos + aModule->GetPosition() );
|
|
|
|
|
|
|
|
wxSize sz( kicad( e.drill ), kicad( e.drill ) );
|
|
|
|
|
|
|
|
pad->SetDrillSize( sz );
|
|
|
|
pad->SetSize( sz );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
pad->SetLayerSet( LSET::AllCuMask() /* | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT */ );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
void EAGLE_PLUGIN::packageSMD( MODULE* aModule, CPTREE& aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-11-04 02:09:28 +00:00
|
|
|
ESMD e( aTree );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( e.layer );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( !IsCopperLayer( layer ) )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D_PAD* pad = new D_PAD( aModule );
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->Pads().PushBack( pad );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
pad->SetPadName( FROM_UTF8( e.name.c_str() ) );
|
2012-05-24 15:00:59 +00:00
|
|
|
pad->SetShape( PAD_RECT );
|
|
|
|
pad->SetAttribute( PAD_SMD );
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
// pad's "Position" is not relative to the module's,
|
|
|
|
// whereas Pos0 is relative to the module's but is the unrotated coordinate.
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
wxPoint padpos( kicad_x( e.x ), kicad_y( e.y ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
|
|
|
pad->SetPos0( padpos );
|
|
|
|
|
|
|
|
RotatePoint( &padpos, aModule->GetOrientation() );
|
|
|
|
|
|
|
|
pad->SetPosition( padpos + aModule->GetPosition() );
|
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
pad->SetSize( wxSize( kicad( e.dx ), kicad( e.dy ) ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
pad->SetLayer( layer );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
static const LSET front( 3, F_Cu, F_Paste, F_Mask );
|
|
|
|
static const LSET back( 3, B_Cu, B_Paste, B_Mask );
|
|
|
|
|
|
|
|
if( layer == F_Cu )
|
|
|
|
pad->SetLayerSet( front );
|
|
|
|
else if( layer == B_Cu )
|
|
|
|
pad->SetLayerSet( back );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
// Optional according to DTD
|
2012-05-29 18:10:56 +00:00
|
|
|
if( e.roundness ) // set set shape to PAD_RECT above, in case roundness is not present
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-29 18:10:56 +00:00
|
|
|
if( *e.roundness >= 75 ) // roundness goes from 0-100% as integer
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-29 18:10:56 +00:00
|
|
|
if( e.dy == e.dx )
|
2012-05-22 17:51:18 +00:00
|
|
|
pad->SetShape( PAD_ROUND );
|
|
|
|
else
|
|
|
|
pad->SetShape( PAD_OVAL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( e.rot )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
pad->SetOrientation( e.rot->degrees * 10 );
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't know what stop, thermals, and cream should look like now.
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
/// non-owning container
|
|
|
|
typedef std::vector<ZONE_CONTAINER*> ZONES;
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
void EAGLE_PLUGIN::loadSignals( CPTREE& aSignals )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-03-14 22:54:47 +00:00
|
|
|
ZONES zones; // per net
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "signals.signal", "name" );
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
int netCode = 1;
|
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
for( CITER net = aSignals.begin(); net != aSignals.end(); ++net )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-03-14 22:54:47 +00:00
|
|
|
bool sawPad = false;
|
|
|
|
|
|
|
|
zones.clear();
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
const string& nname = net->second.get<string>( "<xmlattr>.name" );
|
2012-05-24 15:00:59 +00:00
|
|
|
wxString netName = FROM_UTF8( nname.c_str() );
|
BOARD_CONNECTED_ITEMs do not store net code anymore (m_NetCode field), instead net info is stored using a pointer to NETINFO_ITEM.
GetNet() refers to the net code stored in the NETINFO_ITEM. SetNet() finds an appropriate NETINFO_ITEM and uses it.
Removing GetNet() & SetNet() (and the whole net code idea) requires too many changes in the code (~250 references to the mentioned functions).
BOARD_CONNECTED_ITEMs by default get a pointer to NETINFO_ITEM that stores unconnected items. This requires for all BOARD_CONNECTED_ITEMs to have a parent (so BOARD* is accessible). The only orphaned item is BOARD_DESIGN_SETTINGS::m_Pad_Master, but it does not cause any issues so far.
Items that do not have access to a BOARD (do not have set parents) and therefore cannot get net assigned, by default get const static NETINFO_LIST::ORPHANED.
Performed tests:
- loaded .kicad_pcb, KiCad legacy board, Eagle 6.0 board, P-CAD board - all ok
- load a simple project, reload netlist after changing connections in eeschema - ok
- save & reload a board - ok, but still contain empty nets
- remove everything, restore with undo - ok
- remove everything, reload netlist - ok
- changing net names (all possibilites: empty->existing, empty->not existing, existing->empty, existing->not existing) - all ok
- zones: when net is changed to a net that does not have any nodes besides the zone itself, it does not get filled
2014-01-15 17:03:06 +00:00
|
|
|
m_board->AppendNet( new NETINFO_ITEM( m_board, netName, netCode ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->Value( nname.c_str() );
|
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
if( netName == wxT( "N$8" ) )
|
|
|
|
{
|
|
|
|
int breakhere = 1;
|
|
|
|
(void) breakhere;
|
|
|
|
}
|
|
|
|
#endif
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
// (contactref | polygon | wire | via)*
|
|
|
|
for( CITER it = net->second.begin(); it != net->second.end(); ++it )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( it->first == "wire" )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "wire" );
|
2012-05-30 21:40:32 +00:00
|
|
|
EWIRE w( it->second );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( w.layer );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsCopperLayer( layer ) )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
|
|
|
TRACK* t = new TRACK( m_board );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
t->SetTimeStamp( timeStamp( it->second ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
t->SetPosition( wxPoint( kicad_x( w.x1 ), kicad_y( w.y1 ) ) );
|
|
|
|
t->SetEnd( wxPoint( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
int width = kicad( w.width );
|
|
|
|
if( width < m_min_trace )
|
|
|
|
m_min_trace = width;
|
|
|
|
|
|
|
|
t->SetWidth( width );
|
2012-05-24 15:00:59 +00:00
|
|
|
t->SetLayer( layer );
|
2014-02-25 10:40:34 +00:00
|
|
|
t->SetNetCode( netCode );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
|
|
|
m_board->m_Track.Insert( t, NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// put non copper wires where the sun don't shine.
|
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop();
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "via" )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "via" );
|
2012-05-30 21:40:32 +00:00
|
|
|
EVIA v( it->second );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
|
|
|
|
LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsCopperLayer( layer_front_most ) &&
|
|
|
|
IsCopperLayer( layer_back_most ) )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
int kidiam;
|
|
|
|
int drillz = kicad( v.drill );
|
|
|
|
VIA* via = new VIA( m_board );
|
2012-05-30 21:40:32 +00:00
|
|
|
m_board->m_Track.Insert( via, NULL );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
via->SetLayerPair( layer_front_most, layer_back_most );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
|
|
|
if( v.diam )
|
|
|
|
{
|
2013-03-14 22:54:47 +00:00
|
|
|
kidiam = kicad( *v.diam );
|
2012-05-24 15:00:59 +00:00
|
|
|
via->SetWidth( kidiam );
|
|
|
|
}
|
|
|
|
else
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2012-06-05 04:39:37 +00:00
|
|
|
double annulus = drillz * m_rules->rvViaOuter; // eagle "restring"
|
|
|
|
annulus = Clamp( m_rules->rlMinViaOuter, annulus, m_rules->rlMaxViaOuter );
|
2013-03-14 22:54:47 +00:00
|
|
|
kidiam = KiROUND( drillz + 2 * annulus );
|
|
|
|
via->SetWidth( kidiam );
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
via->SetDrill( drillz );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
if( kidiam < m_min_via )
|
|
|
|
m_min_via = kidiam;
|
|
|
|
|
|
|
|
if( drillz < m_min_via_hole )
|
|
|
|
m_min_via_hole = drillz;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_front_most == F_Cu && layer_back_most == B_Cu )
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( VIA_THROUGH );
|
2014-06-24 16:17:18 +00:00
|
|
|
else if( layer_front_most == F_Cu || layer_back_most == B_Cu )
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( VIA_MICROVIA );
|
2012-06-01 07:39:32 +00:00
|
|
|
else
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( VIA_BLIND_BURIED );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
via->SetTimeStamp( timeStamp( it->second ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
wxPoint pos( kicad_x( v.x ), kicad_y( v.y ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
via->SetPosition( pos );
|
|
|
|
via->SetEnd( pos );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
via->SetNetCode( netCode );
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "contactref" )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "contactref" );
|
2012-05-24 15:00:59 +00:00
|
|
|
// <contactref element="RN1" pad="7"/>
|
|
|
|
CPTREE& attribs = it->second.get_child( "<xmlattr>" );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
const string& reference = attribs.get<string>( "element" );
|
|
|
|
const string& pad = attribs.get<string>( "pad" );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
string key = makeKey( reference, pad ) ;
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
// D(printf( "adding refname:'%s' pad:'%s' netcode:%d netname:'%s'\n", reference.c_str(), pad.c_str(), netCode, nname.c_str() );)
|
2012-05-24 15:00:59 +00:00
|
|
|
|
|
|
|
m_pads_to_nets[ key ] = ENET( netCode, nname );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop();
|
2013-03-14 22:54:47 +00:00
|
|
|
|
|
|
|
sawPad = true;
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( it->first == "polygon" )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "polygon" );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
|
|
|
EPOLYGON p( it->second );
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID layer = kicad_layer( p.layer );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsCopperLayer( layer ) )
|
2012-05-29 18:10:56 +00:00
|
|
|
{
|
|
|
|
// use a "netcode = 0" type ZONE:
|
|
|
|
ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
|
|
|
|
m_board->Add( zone, ADD_APPEND );
|
2013-03-14 22:54:47 +00:00
|
|
|
zones.push_back( zone );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
|
|
|
zone->SetTimeStamp( timeStamp( it->second ) );
|
|
|
|
zone->SetLayer( layer );
|
2014-02-25 10:40:34 +00:00
|
|
|
zone->SetNetCode( netCode );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-07-30 07:40:25 +00:00
|
|
|
CPolyLine::HATCH_STYLE outline_hatch = CPolyLine::DIAGONAL_EDGE;
|
2012-05-29 18:10:56 +00:00
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
for( CITER vi = it->second.begin(); vi != it->second.end(); ++vi )
|
|
|
|
{
|
2012-08-11 05:50:17 +00:00
|
|
|
if( vi->first != "vertex" ) // skip <xmlattr> node
|
2012-05-29 18:10:56 +00:00
|
|
|
continue;
|
|
|
|
|
2012-05-30 21:40:32 +00:00
|
|
|
EVERTEX v( vi->second );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
|
|
|
// the ZONE_CONTAINER API needs work, as you can see:
|
|
|
|
if( first )
|
|
|
|
{
|
2013-03-20 14:50:12 +00:00
|
|
|
zone->Outline()->Start( layer, kicad_x( v.x ), kicad_y( v.y ),
|
|
|
|
outline_hatch );
|
2012-05-29 18:10:56 +00:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
zone->AppendCorner( wxPoint( kicad_x( v.x ), kicad_y( v.y ) ) );
|
|
|
|
}
|
|
|
|
|
2013-03-20 14:50:12 +00:00
|
|
|
zone->Outline()->CloseLastContour();
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2013-03-20 14:50:12 +00:00
|
|
|
zone->Outline()->SetHatch( outline_hatch,
|
|
|
|
Mils2iu( zone->Outline()->GetDefaultHatchPitchMils() ),
|
|
|
|
true );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
// clearances, etc.
|
2013-03-18 19:36:07 +00:00
|
|
|
zone->SetArcSegmentCount( 32 ); // @todo: should be a constructor default?
|
2012-06-01 07:39:32 +00:00
|
|
|
zone->SetMinThickness( kicad( p.width ) );
|
|
|
|
|
|
|
|
if( p.spacing )
|
|
|
|
zone->SetZoneClearance( kicad( *p.spacing ) );
|
|
|
|
|
|
|
|
if( p.rank )
|
|
|
|
zone->SetPriority( *p.rank );
|
|
|
|
|
|
|
|
// missing == yes per DTD.
|
|
|
|
bool thermals = !p.thermals || *p.thermals;
|
|
|
|
zone->SetPadConnection( thermals ? THERMAL_PAD : PAD_IN_ZONE );
|
|
|
|
|
|
|
|
int rank = p.rank ? *p.rank : 0;
|
|
|
|
zone->SetPriority( rank );
|
2012-05-29 18:10:56 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop(); // "polygon"
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
2013-03-14 22:54:47 +00:00
|
|
|
|
|
|
|
if( zones.size() && !sawPad )
|
|
|
|
{
|
|
|
|
// KiCad does not support an unconnected zone with its own non-zero netcode,
|
|
|
|
// but only when assigned netcode = 0 w/o a name...
|
|
|
|
for( ZONES::iterator it = zones.begin(); it != zones.end(); ++it )
|
2014-02-25 10:40:34 +00:00
|
|
|
(*it)->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2013-03-14 22:54:47 +00:00
|
|
|
|
|
|
|
// therefore omit this signal/net.
|
|
|
|
}
|
|
|
|
else
|
BOARD_CONNECTED_ITEMs do not store net code anymore (m_NetCode field), instead net info is stored using a pointer to NETINFO_ITEM.
GetNet() refers to the net code stored in the NETINFO_ITEM. SetNet() finds an appropriate NETINFO_ITEM and uses it.
Removing GetNet() & SetNet() (and the whole net code idea) requires too many changes in the code (~250 references to the mentioned functions).
BOARD_CONNECTED_ITEMs by default get a pointer to NETINFO_ITEM that stores unconnected items. This requires for all BOARD_CONNECTED_ITEMs to have a parent (so BOARD* is accessible). The only orphaned item is BOARD_DESIGN_SETTINGS::m_Pad_Master, but it does not cause any issues so far.
Items that do not have access to a BOARD (do not have set parents) and therefore cannot get net assigned, by default get const static NETINFO_LIST::ORPHANED.
Performed tests:
- loaded .kicad_pcb, KiCad legacy board, Eagle 6.0 board, P-CAD board - all ok
- load a simple project, reload netlist after changing connections in eeschema - ok
- save & reload a board - ok, but still contain empty nets
- remove everything, restore with undo - ok
- remove everything, reload netlist - ok
- changing net names (all possibilites: empty->existing, empty->not existing, existing->empty, existing->not existing) - all ok
- zones: when net is changed to a net that does not have any nodes besides the zone itself, it does not get filled
2014-01-15 17:03:06 +00:00
|
|
|
netCode++;
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
|
|
|
m_xpath->pop(); // "signals.signal"
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-05-24 15:00:59 +00:00
|
|
|
/* will assume this is a valid mapping for all eagle boards until I get paid more:
|
|
|
|
|
|
|
|
<layers>
|
|
|
|
<layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="2" name="Route2" color="1" fill="3" visible="no" active="no"/>
|
|
|
|
<layer number="3" name="Route3" color="4" fill="3" visible="no" active="no"/>
|
|
|
|
<layer number="4" name="Route4" color="1" fill="4" visible="no" active="no"/>
|
|
|
|
<layer number="5" name="Route5" color="4" fill="4" visible="no" active="no"/>
|
|
|
|
<layer number="6" name="Route6" color="1" fill="8" visible="no" active="no"/>
|
|
|
|
<layer number="7" name="Route7" color="4" fill="8" visible="no" active="no"/>
|
|
|
|
<layer number="8" name="Route8" color="1" fill="2" visible="no" active="no"/>
|
|
|
|
<layer number="9" name="Route9" color="4" fill="2" visible="no" active="no"/>
|
|
|
|
<layer number="10" name="Route10" color="1" fill="7" visible="no" active="no"/>
|
|
|
|
<layer number="11" name="Route11" color="4" fill="7" visible="no" active="no"/>
|
|
|
|
<layer number="12" name="Route12" color="1" fill="5" visible="no" active="no"/>
|
|
|
|
<layer number="13" name="Route13" color="4" fill="5" visible="no" active="no"/>
|
|
|
|
<layer number="14" name="Route14" color="1" fill="6" visible="no" active="no"/>
|
|
|
|
<layer number="15" name="Route15" color="4" fill="6" visible="no" active="no"/>
|
|
|
|
<layer number="16" name="Bottom" color="1" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="18" name="Vias" color="14" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="21" name="tPlace" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="22" name="bPlace" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="24" name="bOrigins" color="15" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="26" name="bNames" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="27" name="tValues" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="29" name="tStop" color="2" fill="3" visible="no" active="yes"/>
|
|
|
|
<layer number="30" name="bStop" color="5" fill="6" visible="no" active="yes"/>
|
|
|
|
<layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/>
|
|
|
|
<layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
|
|
|
|
<layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
|
|
|
|
<layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
|
|
|
|
<layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
|
|
|
|
<layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
|
|
|
|
<layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="39" name="tKeepout" color="4" fill="11" visible="no" active="yes"/>
|
|
|
|
<layer number="40" name="bKeepout" color="1" fill="11" visible="no" active="yes"/>
|
|
|
|
<layer number="41" name="tRestrict" color="4" fill="10" visible="no" active="yes"/>
|
|
|
|
<layer number="42" name="bRestrict" color="1" fill="10" visible="no" active="yes"/>
|
|
|
|
<layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/>
|
|
|
|
<layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/>
|
|
|
|
<layer number="49" name="ReferenceLC" color="13" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="50" name="ReferenceLS" color="12" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="52" name="bDocu" color="7" fill="1" visible="yes" active="yes"/>
|
|
|
|
<layer number="91" name="Nets" color="2" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="92" name="Busses" color="1" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="93" name="Pins" color="2" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="94" name="Symbols" color="4" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="95" name="Names" color="7" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="96" name="Values" color="7" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="97" name="Info" color="7" fill="1" visible="no" active="no"/>
|
|
|
|
<layer number="98" name="Guide" color="6" fill="1" visible="no" active="no"/>
|
|
|
|
</layers>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int kiLayer;
|
|
|
|
|
|
|
|
// eagle copper layer:
|
2013-03-13 16:17:16 +00:00
|
|
|
if( aEagleLayer >= 1 && aEagleLayer < int( DIM( m_cu_map ) ) )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
kiLayer = m_cu_map[aEagleLayer];
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-05-24 15:00:59 +00:00
|
|
|
/*
|
2013-03-31 13:27:46 +00:00
|
|
|
#define FIRST_NON_COPPER_LAYER 16
|
2014-06-24 16:17:18 +00:00
|
|
|
#define B_Adhes 16
|
|
|
|
#define F_Adhes 17
|
|
|
|
#define B_Paste 18
|
|
|
|
#define F_Paste 19
|
|
|
|
#define B_SilkS 20
|
|
|
|
#define F_SilkS 21
|
|
|
|
#define B_Mask 22
|
|
|
|
#define F_Mask 23
|
|
|
|
#define Dwgs_User 24
|
|
|
|
#define Cmts_User 25
|
|
|
|
#define Eco1_User 26
|
|
|
|
#define Eco2_User 27
|
|
|
|
#define Edge_Cuts 28
|
2013-03-31 13:27:46 +00:00
|
|
|
#define LAST_NON_COPPER_LAYER 28
|
2012-05-24 15:00:59 +00:00
|
|
|
#define UNUSED_LAYER_29 29
|
|
|
|
#define UNUSED_LAYER_30 30
|
|
|
|
#define UNUSED_LAYER_31 31
|
|
|
|
*/
|
|
|
|
// translate non-copper eagle layer to pcbnew layer
|
|
|
|
switch( aEagleLayer )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case 20: kiLayer = Edge_Cuts; break; // eagle says "Dimension" layer, but it's for board perimeter
|
|
|
|
case 21: kiLayer = F_SilkS; break;
|
|
|
|
case 22: kiLayer = B_SilkS; break;
|
|
|
|
case 25: kiLayer = F_SilkS; break;
|
|
|
|
case 26: kiLayer = B_SilkS; break;
|
|
|
|
case 27: kiLayer = F_SilkS; break;
|
|
|
|
case 28: kiLayer = B_SilkS; break;
|
|
|
|
case 29: kiLayer = F_Mask; break;
|
|
|
|
case 30: kiLayer = B_Mask; break;
|
|
|
|
case 31: kiLayer = F_Paste; break;
|
|
|
|
case 32: kiLayer = B_Paste; break;
|
|
|
|
case 33: kiLayer = F_Mask; break;
|
|
|
|
case 34: kiLayer = B_Mask; break;
|
|
|
|
case 35: kiLayer = F_Adhes; break;
|
|
|
|
case 36: kiLayer = B_Adhes; break;
|
|
|
|
case 49: kiLayer = Cmts_User; break;
|
|
|
|
case 50: kiLayer = Cmts_User; break;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
// Packages show the future chip pins on SMD parts using layer 51.
|
|
|
|
// This is an area slightly smaller than the PAD/SMD copper area.
|
|
|
|
// Carry those visual aids into the MODULE on the drawing layer, not silkscreen.
|
2014-06-24 16:17:18 +00:00
|
|
|
case 51: kiLayer = Dwgs_User; break;
|
|
|
|
case 52: kiLayer = Dwgs_User; break;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case 95: kiLayer = Eco1_User; break;
|
|
|
|
case 96: kiLayer = Eco2_User; break;
|
2012-05-24 15:00:59 +00:00
|
|
|
default:
|
2013-11-04 02:09:28 +00:00
|
|
|
// some layers do not map to KiCad
|
|
|
|
// DBG( printf( "unsupported eagle layer: %d\n", aEagleLayer );)
|
2014-06-24 16:17:18 +00:00
|
|
|
kiLayer = UNDEFINED_LAYER; break;
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2014-07-05 20:42:59 +00:00
|
|
|
return LAYER_ID( kiLayer );
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
void EAGLE_PLUGIN::centerBoard()
|
|
|
|
{
|
|
|
|
if( m_props )
|
|
|
|
{
|
2014-01-02 02:17:07 +00:00
|
|
|
UTF8 page_width;
|
|
|
|
UTF8 page_height;
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-11-02 00:24:38 +00:00
|
|
|
if( m_props->Value( "page_width", &page_width ) &&
|
|
|
|
m_props->Value( "page_height", &page_height ) )
|
2012-06-02 17:07:30 +00:00
|
|
|
{
|
2013-11-02 00:24:38 +00:00
|
|
|
EDA_RECT bbbox = m_board->ComputeBoundingBox( true );
|
|
|
|
|
|
|
|
int w = atoi( page_width.c_str() );
|
|
|
|
int h = atoi( page_height.c_str() );
|
|
|
|
|
|
|
|
int desired_x = ( w - bbbox.GetWidth() ) / 2;
|
|
|
|
int desired_y = ( h - bbbox.GetHeight() ) / 2;
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-11-02 00:24:38 +00:00
|
|
|
DBG(printf( "bbox.width:%d bbox.height:%d w:%d h:%d desired_x:%d desired_y:%d\n",
|
|
|
|
bbbox.GetWidth(), bbbox.GetHeight(), w, h, desired_x, desired_y );)
|
|
|
|
|
|
|
|
m_board->Move( wxPoint( desired_x - bbbox.GetX(), desired_y - bbbox.GetY() ) );
|
2012-06-02 17:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
wxDateTime EAGLE_PLUGIN::getModificationTime( const wxString& aPath )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
wxFileName fn( aPath );
|
|
|
|
|
2013-12-24 19:09:41 +00:00
|
|
|
// Do not call wxFileName::GetModificationTime() on a non-existent file, because
|
|
|
|
// if it fails, wx's implementation calls the crap wxLogSysError() which
|
|
|
|
// eventually infects our UI with an unwanted popup window, so don't let it fail.
|
|
|
|
if( !fn.IsFileReadable() )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
|
|
|
_( "File '%s' is not readable." ),
|
|
|
|
GetChars( aPath ) );
|
|
|
|
|
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
/*
|
|
|
|
// update the writable flag while we have a wxFileName, in a network this
|
|
|
|
// is possibly quite dynamic anyway.
|
|
|
|
m_writable = fn.IsFileWritable();
|
|
|
|
*/
|
|
|
|
|
2013-09-22 00:28:02 +00:00
|
|
|
wxDateTime modTime = fn.GetModificationTime();
|
|
|
|
|
|
|
|
if( !modTime.IsValid() )
|
|
|
|
modTime.Now();
|
|
|
|
|
|
|
|
return modTime;
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
try
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2013-09-22 17:20:46 +00:00
|
|
|
wxDateTime modtime = getModificationTime( aLibPath );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2013-09-22 17:20:46 +00:00
|
|
|
// Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the
|
|
|
|
// cache if either of the wxDateTime objects are invalid or the last file modification
|
|
|
|
// time differs from the current file modification time.
|
|
|
|
bool load = !m_mod_time.IsValid() || !modtime.IsValid() ||
|
|
|
|
m_mod_time != modtime;
|
2013-09-22 00:28:02 +00:00
|
|
|
|
2013-09-22 17:20:46 +00:00
|
|
|
if( aLibPath != m_lib_path || load )
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
|
|
|
PTREE doc;
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_templates.clear();
|
|
|
|
|
|
|
|
// Set this before completion of loading, since we rely on it for
|
|
|
|
// text of an exception. Delay setting m_mod_time until after successful load
|
|
|
|
// however.
|
|
|
|
m_lib_path = aLibPath;
|
|
|
|
|
|
|
|
// 8 bit "filename" should be encoded according to disk filename encoding,
|
|
|
|
// (maybe this is current locale, maybe not, its a filesystem issue),
|
|
|
|
// and is not necessarily utf8.
|
2013-11-06 16:53:44 +00:00
|
|
|
string filename = (const char*) aLibPath.char_str( wxConvFile );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
|
|
|
read_xml( filename, doc, xml_parser::trim_whitespace | xml_parser::no_comments );
|
|
|
|
|
2013-03-13 16:38:54 +00:00
|
|
|
// clear the cu map and then rebuild it.
|
|
|
|
clear_cu_map();
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2013-03-13 16:38:54 +00:00
|
|
|
m_xpath->push( "eagle.drawing.layers" );
|
|
|
|
CPTREE& layers = doc.get_child( "eagle.drawing.layers" );
|
|
|
|
loadLayerDefs( layers );
|
|
|
|
m_xpath->pop();
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2013-03-13 16:38:54 +00:00
|
|
|
m_xpath->push( "eagle.drawing.library" );
|
|
|
|
CPTREE& library = doc.get_child( "eagle.drawing.library" );
|
2013-01-02 04:05:48 +00:00
|
|
|
loadLibrary( library, NULL );
|
|
|
|
m_xpath->pop();
|
|
|
|
|
|
|
|
m_mod_time = modtime;
|
|
|
|
}
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
2013-01-02 04:05:48 +00:00
|
|
|
catch( file_parser_error fpe )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
// for xml_parser_error, what() has the line number in it,
|
|
|
|
// but no byte offset. That should be an adequate error message.
|
|
|
|
THROW_IO_ERROR( fpe.what() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Class ptree_error is a base class for xml_parser_error & file_parser_error,
|
|
|
|
// so one catch should be OK for all errors.
|
|
|
|
catch( ptree_error pte )
|
|
|
|
{
|
2013-11-06 16:53:44 +00:00
|
|
|
string errmsg = pte.what();
|
2013-01-02 04:05:48 +00:00
|
|
|
|
|
|
|
errmsg += " @\n";
|
|
|
|
errmsg += m_xpath->Contents();
|
|
|
|
|
|
|
|
THROW_IO_ERROR( errmsg );
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
wxArrayString EAGLE_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
init( aProperties );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
cacheLib( aLibraryPath );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
wxArrayString ret;
|
|
|
|
|
|
|
|
for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
|
|
|
|
ret.Add( FROM_UTF8( it->first.c_str() ) );
|
|
|
|
|
|
|
|
return ret;
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
MODULE* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
2013-11-06 16:53:44 +00:00
|
|
|
string key = TO_UTF8( aFootprintName );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
|
|
|
MODULE_CITER mi = m_templates.find( key );
|
|
|
|
|
|
|
|
if( mi == m_templates.end() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// copy constructor to clone the template
|
|
|
|
MODULE* ret = new MODULE( *mi->second );
|
|
|
|
|
|
|
|
return ret;
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-20 16:35:03 +00:00
|
|
|
void EAGLE_PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
|
|
|
|
{
|
2013-11-26 17:06:54 +00:00
|
|
|
PLUGIN::FootprintLibOptions( aListToAppendTo );
|
|
|
|
|
2013-11-20 16:35:03 +00:00
|
|
|
/*
|
2014-01-02 02:17:07 +00:00
|
|
|
(*aListToAppendTo)["ignore_duplicates"] = UTF8( _(
|
2013-11-20 16:35:03 +00:00
|
|
|
"Ignore duplicately named footprints within the same Eagle library. "
|
|
|
|
"Only the first similarly named footprint will be loaded."
|
2014-01-02 02:17:07 +00:00
|
|
|
));
|
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 EAGLE_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
// Eagle lovers apply here.
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void EAGLE_PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EAGLE_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void EAGLE_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
bool EAGLE_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EAGLE_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2012-06-03 15:47:53 +00:00
|
|
|
*/
|