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>
|
2023-01-15 22:26:36 +00:00
|
|
|
* Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-05-16 02:27:27 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cerrno>
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
#include <wx/string.h>
|
2017-04-07 11:40:34 +00:00
|
|
|
#include <wx/xml/xml.h>
|
2020-10-02 11:18:16 +00:00
|
|
|
#include <wx/filename.h>
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
2021-05-03 23:39:56 +00:00
|
|
|
#include <wx/wfstream.h>
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <wx/txtstrm.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <wx/window.h>
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2019-05-15 06:11:30 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2022-11-06 16:51:52 +00:00
|
|
|
#include <string_utf8_map.h>
|
2019-05-15 06:11:30 +00:00
|
|
|
#include <trigo.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2021-09-20 11:36:57 +00:00
|
|
|
#include <project.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad_shapes.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2020-10-03 20:48:58 +00:00
|
|
|
#include <plugins/eagle/eagle_plugin.h>
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
using namespace std;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
|
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.
|
2017-10-17 08:18:54 +00:00
|
|
|
static int parseEagle( const wxString& aDistance )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
2017-10-23 13:37:24 +00:00
|
|
|
ECOORD::EAGLE_UNIT unit = ( aDistance.npos != aDistance.find( "mil" ) )
|
2022-04-10 11:23:41 +00:00
|
|
|
? ECOORD::EAGLE_UNIT::EU_MIL
|
|
|
|
: ECOORD::EAGLE_UNIT::EU_MM;
|
2017-10-17 08:18:54 +00:00
|
|
|
|
|
|
|
ECOORD coord( aDistance, unit );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
return coord.ToPcbUnits();
|
2012-06-05 04:39:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
|
2018-06-29 17:52:56 +00:00
|
|
|
// In Eagle one can specify DRC rules where min value > max value,
|
|
|
|
// in such case the max value has the priority
|
|
|
|
template<typename T>
|
|
|
|
static T eagleClamp( T aMin, T aValue, T aMax )
|
|
|
|
{
|
|
|
|
T ret = std::max( aMin, aValue );
|
|
|
|
return std::min( aMax, ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
/// Assemble a two part key as a simple concatenation of aFirst and aSecond parts,
|
|
|
|
/// using a separator.
|
2017-12-14 09:37:32 +00:00
|
|
|
static wxString makeKey( const wxString& aFirst, const wxString& aSecond )
|
2017-10-03 10:30:23 +00:00
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString key = aFirst + '\x02' + aSecond;
|
2017-10-03 10:30:23 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2023-01-13 14:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::setKeepoutSettingsToZone( ZONE* aZone, int aLayer ) const
|
2020-04-23 14:21:29 +00:00
|
|
|
{
|
|
|
|
if( aLayer == EAGLE_LAYER::TRESTRICT || aLayer == EAGLE_LAYER::BRESTRICT )
|
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
aZone->SetIsRuleArea( true );
|
2020-04-23 14:21:29 +00:00
|
|
|
aZone->SetDoNotAllowVias( true );
|
|
|
|
aZone->SetDoNotAllowTracks( true );
|
|
|
|
aZone->SetDoNotAllowCopperPour( true );
|
|
|
|
aZone->SetDoNotAllowPads( true );
|
|
|
|
aZone->SetDoNotAllowFootprints( false );
|
|
|
|
|
|
|
|
if( aLayer == EAGLE_LAYER::TRESTRICT ) // front layer keepout
|
|
|
|
aZone->SetLayer( F_Cu );
|
|
|
|
else // bottom layer keepout
|
|
|
|
aZone->SetLayer( B_Cu );
|
|
|
|
}
|
|
|
|
else if( aLayer == EAGLE_LAYER::VRESTRICT )
|
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
aZone->SetIsRuleArea( true );
|
2020-04-23 14:21:29 +00:00
|
|
|
aZone->SetDoNotAllowVias( true );
|
|
|
|
aZone->SetDoNotAllowTracks( false );
|
|
|
|
aZone->SetDoNotAllowCopperPour( false );
|
|
|
|
aZone->SetDoNotAllowPads( false );
|
|
|
|
aZone->SetDoNotAllowFootprints( false );
|
|
|
|
|
|
|
|
aZone->SetLayerSet( LSET::AllCuMask() );
|
|
|
|
}
|
2023-01-13 14:40:34 +00:00
|
|
|
else // copper pour cutout
|
|
|
|
{
|
|
|
|
aZone->SetIsRuleArea( true );
|
|
|
|
aZone->SetDoNotAllowVias( false );
|
|
|
|
aZone->SetDoNotAllowTracks( false );
|
|
|
|
aZone->SetDoNotAllowCopperPour( true );
|
|
|
|
aZone->SetDoNotAllowPads( false );
|
|
|
|
aZone->SetDoNotAllowFootprints( false );
|
|
|
|
|
|
|
|
aZone->SetLayerSet( kicad_layer( aLayer ) );
|
|
|
|
}
|
2020-04-23 14:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
void ERULES::parse( wxXmlNode* aRules, std::function<void()> aCheckpoint )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlNode* child = aRules->GetChildren();
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
while( child )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
aCheckpoint();
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( child->GetName() == wxT( "param" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
const wxString& name = child->GetAttribute( wxT( "name" ) );
|
|
|
|
const wxString& value = child->GetAttribute( wxT( "value" ) );
|
2017-04-07 11:40:34 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( name == wxT( "psElongationLong" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
psElongationLong = wxAtoi( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "psElongationOffset" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
psElongationOffset = wxAtoi( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mvStopFrame" ) )
|
2020-07-12 13:26:36 +00:00
|
|
|
value.ToCDouble( &mvStopFrame );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mvCreamFrame" ) )
|
2020-07-12 13:26:36 +00:00
|
|
|
value.ToCDouble( &mvCreamFrame );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mlMinStopFrame" ) )
|
2018-03-13 13:42:01 +00:00
|
|
|
mlMinStopFrame = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mlMaxStopFrame" ) )
|
2018-03-13 13:42:01 +00:00
|
|
|
mlMaxStopFrame = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mlMinCreamFrame" ) )
|
2018-03-13 13:42:01 +00:00
|
|
|
mlMinCreamFrame = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mlMaxCreamFrame" ) )
|
2018-03-13 13:42:01 +00:00
|
|
|
mlMaxCreamFrame = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "srRoundness" ) )
|
2020-07-12 13:26:36 +00:00
|
|
|
value.ToCDouble( &srRoundness );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "srMinRoundness" ) )
|
2018-03-14 09:06:40 +00:00
|
|
|
srMinRoundness = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "srMaxRoundness" ) )
|
2018-03-14 09:06:40 +00:00
|
|
|
srMaxRoundness = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "psTop" ) )
|
2019-02-04 01:46:10 +00:00
|
|
|
psTop = wxAtoi( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "psBottom" ) )
|
2019-02-04 01:46:10 +00:00
|
|
|
psBottom = wxAtoi( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "psFirst" ) )
|
2019-02-04 01:46:10 +00:00
|
|
|
psFirst = wxAtoi( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "rvPadTop" ) )
|
2020-07-12 13:26:36 +00:00
|
|
|
value.ToCDouble( &rvPadTop );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "rlMinPadTop" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
rlMinPadTop = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "rlMaxPadTop" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
rlMaxPadTop = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "rvViaOuter" ) )
|
2020-07-12 13:26:36 +00:00
|
|
|
value.ToCDouble( &rvViaOuter );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "rlMinViaOuter" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
rlMinViaOuter = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "rlMaxViaOuter" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
rlMaxViaOuter = parseEagle( value );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( name == wxT( "mdWireWire" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
mdWireWire = parseEagle( value );
|
|
|
|
}
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
child = child->GetNext();
|
2012-06-05 04:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
EAGLE_PLUGIN::EAGLE_PLUGIN() :
|
2021-06-23 22:53:08 +00:00
|
|
|
m_rules( new ERULES() ),
|
|
|
|
m_xpath( new XPATH() ),
|
|
|
|
m_progressReporter( nullptr ),
|
|
|
|
m_doneCount( 0 ),
|
|
|
|
m_lastProgressCount( 0 ),
|
|
|
|
m_totalCount( 0 ),
|
|
|
|
m_mod_time( wxDateTime::Now() )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2020-10-09 16:58:21 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
init( nullptr );
|
2013-03-13 16:38:54 +00:00
|
|
|
clear_cu_map();
|
2021-07-19 23:56:05 +00:00
|
|
|
RegisterLayerMappingCallback( std::bind( &EAGLE_PLUGIN::DefaultLayerMappingCallback,
|
|
|
|
this, _1 ) );
|
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()
|
|
|
|
{
|
2017-07-10 09:44:56 +00:00
|
|
|
deleteTemplates();
|
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
|
|
|
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
bool EAGLE_PLUGIN::CanReadBoard( const wxString& aFileName ) const
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2023-08-13 02:26:06 +00:00
|
|
|
if( !PLUGIN::CanReadBoard( aFileName ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return checkHeader( aFileName );
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
bool EAGLE_PLUGIN::CanReadFootprintLib( const wxString& aFileName ) const
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2023-08-13 02:26:06 +00:00
|
|
|
if( !PLUGIN::CanReadFootprintLib( aFileName ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return checkHeader( aFileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EAGLE_PLUGIN::CanReadFootprint( const wxString& aFileName ) const
|
|
|
|
{
|
|
|
|
return CanReadFootprintLib( aFileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EAGLE_PLUGIN::checkHeader(const wxString& aFileName) const
|
|
|
|
{
|
|
|
|
wxFileInputStream input( aFileName );
|
|
|
|
|
|
|
|
if( !input.IsOk() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxTextInputStream text( input );
|
|
|
|
|
|
|
|
for( int i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
if( input.Eof() )
|
|
|
|
return false;
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( text.ReadLine().Contains( wxS( "<!DOCTYPE eagle" ) ) )
|
2023-08-13 02:26:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
void EAGLE_PLUGIN::checkpoint()
|
|
|
|
{
|
|
|
|
const unsigned PROGRESS_DELTA = 50;
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA )
|
|
|
|
{
|
2021-06-24 10:09:03 +00:00
|
|
|
m_progressReporter->SetCurrentProgress( ( (double) m_doneCount )
|
2021-07-19 23:56:05 +00:00
|
|
|
/ std::max( 1U, m_totalCount ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( _( "Open cancelled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
m_lastProgressCount = m_doneCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I inline EAGLE_PLUGIN::kicad_fontsize( const ECOORD& d, int aTextThickness ) const
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2020-06-09 07:32:52 +00:00
|
|
|
// Eagle includes stroke thickness in the text size, KiCAD does not
|
|
|
|
int kz = d.ToPcbUnits();
|
2023-02-19 03:40:07 +00:00
|
|
|
return VECTOR2I( kz - aTextThickness, kz - aTextThickness );
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-13 02:11:58 +00:00
|
|
|
BOARD* EAGLE_PLUGIN::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
|
|
|
const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
|
|
|
|
PROGRESS_REPORTER* aProgressReporter )
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
wxXmlNode* doc;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
m_board = aAppendToMe ? aAppendToMe : new BOARD();
|
2021-06-23 22:53:08 +00:00
|
|
|
m_progressReporter = aProgressReporter;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
// Give the filename to the board if it's new
|
|
|
|
if( !aAppendToMe )
|
|
|
|
m_board->SetFileName( aFileName );
|
|
|
|
|
2016-05-29 15:02:34 +00:00
|
|
|
// delete on exception, if I own m_board, according to aAppendToMe
|
2021-07-19 23:56:05 +00:00
|
|
|
unique_ptr<BOARD> deleter( aAppendToMe ? nullptr : m_board );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
|
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( _( "Open cancelled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 23:39:56 +00:00
|
|
|
wxFileName fn = aFileName;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Load the document
|
2021-05-03 23:39:56 +00:00
|
|
|
wxFFileInputStream stream( fn.GetFullPath() );
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlDocument xmlDocument;
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2021-05-03 23:39:56 +00:00
|
|
|
if( !stream.IsOk() || !xmlDocument.Load( stream ) )
|
2020-10-13 15:53:07 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ),
|
2017-04-07 11:40:34 +00:00
|
|
|
fn.GetFullPath() ) );
|
2020-10-13 15:53:07 +00:00
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
doc = xmlDocument.GetRoot();
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
m_min_trace = INT_MAX;
|
2020-05-04 19:08:42 +00:00
|
|
|
m_min_hole = INT_MAX;
|
2013-03-14 22:54:47 +00:00
|
|
|
m_min_via = INT_MAX;
|
2020-05-11 19:39:30 +00:00
|
|
|
m_min_annulus = INT_MAX;
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
loadAllSections( doc );
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_min_trace < bds.m_TrackMinWidth )
|
|
|
|
bds.m_TrackMinWidth = m_min_trace;
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_min_via < bds.m_ViasMinSize )
|
|
|
|
bds.m_ViasMinSize = m_min_via;
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_min_hole < bds.m_MinThroughDrill )
|
|
|
|
bds.m_MinThroughDrill = m_min_hole;
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_min_annulus < bds.m_ViasMinAnnularWidth )
|
|
|
|
bds.m_ViasMinAnnularWidth = m_min_annulus;
|
2020-05-11 19:39:30 +00:00
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
if( m_rules->mdWireWire )
|
2022-08-14 11:03:18 +00:00
|
|
|
bds.m_MinClearance = KiROUND( m_rules->mdWireWire );
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
NETCLASS defaults( wxT( "dummy" ) );
|
2021-09-20 11:36:57 +00:00
|
|
|
|
|
|
|
auto finishNetclass =
|
2022-08-14 11:03:18 +00:00
|
|
|
[&]( std::shared_ptr<NETCLASS> netclass )
|
2021-09-20 11:36:57 +00:00
|
|
|
{
|
2021-09-20 20:18:06 +00:00
|
|
|
// If Eagle has a clearance matrix then we'll build custom rules from that.
|
|
|
|
// Netclasses should just be the board minimum clearance.
|
2022-08-14 11:03:18 +00:00
|
|
|
netclass->SetClearance( KiROUND( bds.m_MinClearance ) );
|
2021-09-20 20:18:06 +00:00
|
|
|
|
2021-09-20 11:36:57 +00:00
|
|
|
if( netclass->GetTrackWidth() == INT_MAX )
|
|
|
|
netclass->SetTrackWidth( defaults.GetTrackWidth() );
|
|
|
|
|
|
|
|
if( netclass->GetViaDiameter() == INT_MAX )
|
|
|
|
netclass->SetViaDiameter( defaults.GetViaDiameter() );
|
|
|
|
|
|
|
|
if( netclass->GetViaDrill() == INT_MAX )
|
|
|
|
netclass->SetViaDrill( defaults.GetViaDrill() );
|
|
|
|
};
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = bds.m_NetSettings;
|
2021-09-20 11:36:57 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
finishNetclass( netSettings->m_DefaultNetClass );
|
|
|
|
|
|
|
|
for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
|
|
|
|
finishNetclass( netclass );
|
2021-09-20 11:36:57 +00:00
|
|
|
|
|
|
|
m_board->m_LegacyNetclassesLoaded = true;
|
|
|
|
m_board->m_LegacyDesignSettingsLoaded = true;
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
fn.SetExt( wxT( "kicad_dru" ) );
|
2021-09-20 11:36:57 +00:00
|
|
|
wxFile rulesFile( fn.GetFullPath(), wxFile::write );
|
|
|
|
rulesFile.Write( m_customRules );
|
2013-03-14 22:54:47 +00:00
|
|
|
|
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
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
catch( const XML_PARSER_ERROR &exc )
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString errmsg = exc.what();
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
errmsg += wxT( "\n@ " );
|
2012-06-02 17:07:30 +00:00
|
|
|
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.
|
|
|
|
|
2023-01-29 19:09:12 +00:00
|
|
|
m_board->SetCopperLayerCount( getMinimumCopperLayerCount() );
|
2012-06-02 17:07:30 +00:00
|
|
|
centerBoard();
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2018-10-14 13:51:09 +00:00
|
|
|
deleter.release();
|
2012-05-20 13:14:46 +00:00
|
|
|
return m_board;
|
2012-05-16 02:27:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-31 21:55:51 +00:00
|
|
|
std::vector<FOOTPRINT*> EAGLE_PLUGIN::GetImportedCachedLibraryFootprints()
|
|
|
|
{
|
|
|
|
std::vector<FOOTPRINT*> retval;
|
|
|
|
|
2023-04-04 13:18:13 +00:00
|
|
|
for( const auto& [ name, footprint ] : m_templates )
|
|
|
|
retval.push_back( static_cast<FOOTPRINT*>( footprint->Clone() ) );
|
2021-01-31 21:55:51 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void EAGLE_PLUGIN::init( const STRING_UTF8_MAP* aProperties )
|
2012-05-16 02:27:27 +00:00
|
|
|
{
|
2020-05-11 19:39:30 +00:00
|
|
|
m_hole_count = 0;
|
|
|
|
m_min_trace = 0;
|
|
|
|
m_min_hole = 0;
|
|
|
|
m_min_via = 0;
|
|
|
|
m_min_annulus = 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();
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_board = nullptr;
|
2012-05-20 13:14:46 +00:00
|
|
|
m_props = aProperties;
|
2012-05-16 02:27:27 +00:00
|
|
|
|
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().
|
2019-01-06 16:43:12 +00:00
|
|
|
for( unsigned i = 0; i < arrayDim(m_cu_map); ++i )
|
2013-03-13 16:38:54 +00:00
|
|
|
m_cu_map[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadAllSections( wxXmlNode* aDoc )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlNode* drawing = MapChildren( aDoc )["drawing"];
|
|
|
|
NODE_MAP drawingChildren = MapChildren( drawing );
|
|
|
|
|
|
|
|
wxXmlNode* board = drawingChildren["board"];
|
|
|
|
NODE_MAP boardChildren = MapChildren( board );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
auto count_children = [this]( wxXmlNode* aNode )
|
|
|
|
{
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
wxXmlNode* child = aNode->GetChildren();
|
|
|
|
|
|
|
|
while( child )
|
|
|
|
{
|
|
|
|
m_totalCount++;
|
|
|
|
child = child->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wxXmlNode* designrules = boardChildren["designrules"];
|
|
|
|
wxXmlNode* layers = drawingChildren["layers"];
|
|
|
|
wxXmlNode* plain = boardChildren["plain"];
|
2021-09-20 11:36:57 +00:00
|
|
|
wxXmlNode* classes = boardChildren["classes"];
|
2021-06-23 22:53:08 +00:00
|
|
|
wxXmlNode* signals = boardChildren["signals"];
|
|
|
|
wxXmlNode* libs = boardChildren["libraries"];
|
|
|
|
wxXmlNode* elems = boardChildren["elements"];
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_totalCount = 0;
|
|
|
|
m_doneCount = 0;
|
|
|
|
|
|
|
|
count_children( designrules );
|
|
|
|
count_children( layers );
|
|
|
|
count_children( plain );
|
|
|
|
count_children( signals );
|
|
|
|
count_children( elems );
|
|
|
|
|
|
|
|
while( libs )
|
|
|
|
{
|
|
|
|
count_children( MapChildren( libs )["packages"] );
|
|
|
|
libs = libs->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewind
|
|
|
|
libs = boardChildren["libraries"];
|
|
|
|
}
|
|
|
|
|
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" );
|
|
|
|
|
|
|
|
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
|
|
|
loadLayerDefs( layers );
|
2020-10-09 16:58:21 +00:00
|
|
|
mapEagleLayersToKicad();
|
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
|
|
|
loadPlain( plain );
|
2021-09-20 11:36:57 +00:00
|
|
|
loadClasses( classes );
|
2012-06-01 07:39:32 +00:00
|
|
|
loadSignals( signals );
|
|
|
|
loadLibraries( libs );
|
|
|
|
loadElements( elems );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
m_xpath->pop();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadDesignRules( wxXmlNode* aDesignRules )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
2018-08-09 17:53:48 +00:00
|
|
|
if( aDesignRules )
|
|
|
|
{
|
|
|
|
m_xpath->push( "designrules" );
|
2021-06-23 22:53:08 +00:00
|
|
|
m_rules->parse( aDesignRules, [this](){ checkpoint(); } );
|
2018-08-09 17:53:48 +00:00
|
|
|
m_xpath->pop(); // "designrules"
|
|
|
|
}
|
2012-06-05 04:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadLayerDefs( wxXmlNode* aLayers )
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
2018-08-09 17:53:48 +00:00
|
|
|
if( !aLayers )
|
|
|
|
return;
|
|
|
|
|
2017-10-18 07:53:07 +00:00
|
|
|
ELAYERS cu; // copper layers
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first layer and iterate
|
|
|
|
wxXmlNode* layerNode = aLayers->GetChildren();
|
|
|
|
|
2017-10-18 16:02:36 +00:00
|
|
|
m_eagleLayers.clear();
|
2020-10-09 16:58:21 +00:00
|
|
|
m_eagleLayersIds.clear();
|
2017-10-18 16:02:36 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
while( layerNode )
|
2012-06-01 07:39:32 +00:00
|
|
|
{
|
2017-10-18 07:53:07 +00:00
|
|
|
ELAYER elayer( layerNode );
|
2017-10-18 16:02:36 +00:00
|
|
|
m_eagleLayers.insert( std::make_pair( elayer.number, elayer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
m_eagleLayersIds.insert( std::make_pair( elayer.name, elayer.number ) );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2017-10-18 16:02:36 +00:00
|
|
|
// find the subset of layers that are copper and active
|
2012-06-01 07:39:32 +00:00
|
|
|
if( elayer.number >= 1 && elayer.number <= 16 && ( !elayer.active || *elayer.active ) )
|
|
|
|
cu.push_back( elayer );
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
layerNode = layerNode->GetNext();
|
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 )
|
2021-06-23 22:53:08 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_map[it->number] = F_Cu;
|
2021-06-23 22:53:08 +00:00
|
|
|
}
|
2013-03-13 16:17:16 +00:00
|
|
|
else if( ki_layer_count == int( cu.size()-1 ) )
|
2021-06-23 22:53:08 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_map[it->number] = B_Cu;
|
2021-06-23 22:53:08 +00:00
|
|
|
}
|
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
|
|
|
m_cu_map[it->number] = ki_layer_count;
|
|
|
|
}
|
2013-03-13 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 12:38:03 +00:00
|
|
|
// Set the layer names and cu count if we're loading a board.
|
2013-11-20 16:35:03 +00:00
|
|
|
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 )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = kicad_layer( it->number );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2020-11-17 09:23:44 +00:00
|
|
|
// these function provide their own protection against non enabled layers:
|
|
|
|
if( layer >= 0 && layer < PCB_LAYER_ID_COUNT ) // layer should be valid
|
|
|
|
{
|
2022-04-09 13:33:01 +00:00
|
|
|
m_board->SetLayerName( layer, it->name );
|
2020-11-17 09:23:44 +00:00
|
|
|
m_board->SetLayerType( layer, LT_SIGNAL );
|
|
|
|
}
|
2021-07-19 23:56:05 +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
|
|
|
|
|
|
|
|
2023-03-05 13:27:22 +00:00
|
|
|
#define DIMENSION_PRECISION DIM_PRECISION::X_XX // 0.01 mm
|
2019-10-31 23:25:50 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2018-08-09 17:53:48 +00:00
|
|
|
if( !aGraphics )
|
|
|
|
return;
|
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "plain" );
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first graphic and iterate
|
|
|
|
wxXmlNode* gr = aGraphics->GetChildren();
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
// (polygon | wire | text | circle | rectangle | frame | hole)*
|
2017-04-07 11:40:34 +00:00
|
|
|
while( gr )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
wxString grName = gr->GetName();
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( grName == wxT( "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
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
EWIRE w( gr );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = kicad_layer( w.layer );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2022-01-11 00:49:49 +00:00
|
|
|
VECTOR2I start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
|
|
|
|
VECTOR2I end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
|
2014-12-19 22:02:02 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layer != UNDEFINED_LAYER )
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board );
|
|
|
|
int width = w.width.ToPcbUnits();
|
2019-05-20 02:33:27 +00:00
|
|
|
|
|
|
|
// KiCad cannot handle zero or negative line widths
|
|
|
|
if( width <= 0 )
|
|
|
|
width = m_board->GetDesignSettings().GetLineThickness( layer );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
2012-08-11 05:50:17 +00:00
|
|
|
|
2014-12-19 22:02:02 +00:00
|
|
|
if( !w.curve )
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetShape( SHAPE_T::SEGMENT );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetStart( start );
|
|
|
|
shape->SetEnd( end );
|
2014-12-19 22:02:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center = ConvertArcCenter( start, end, *w.curve );
|
2014-12-19 22:02:02 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
shape->SetShape( SHAPE_T::ARC );
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetCenter( center );
|
|
|
|
shape->SetStart( start );
|
2022-01-16 16:15:07 +00:00
|
|
|
shape->SetArcAngleAndEnd( -EDA_ANGLE( *w.curve, DEGREES_T ), true ); // KiCad rotates the other way
|
2014-12-19 22:02:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( layer );
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
2019-05-20 02:33:27 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "text" ) )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "text" );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
ETEXT t( gr );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_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
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* pcbtxt = new PCB_TEXT( m_board );
|
2019-12-28 00:55:11 +00:00
|
|
|
m_board->Add( pcbtxt, ADD_MODE::APPEND );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
pcbtxt->SetLayer( layer );
|
2023-01-18 12:33:36 +00:00
|
|
|
wxString kicadText = interpretText( t.text );
|
2022-04-09 13:33:01 +00:00
|
|
|
pcbtxt->SetText( kicadText );
|
2022-01-11 00:49:49 +00:00
|
|
|
pcbtxt->SetTextPos( VECTOR2I( kicad_x( t.x ), kicad_y( t.y ) ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
|
2020-06-09 07:32:52 +00:00
|
|
|
int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
|
|
|
|
pcbtxt->SetTextThickness( textThickness );
|
2023-02-19 03:40:07 +00:00
|
|
|
pcbtxt->SetTextSize( kicad_fontsize( t.size, textThickness ) );
|
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 )
|
2021-10-27 12:54:28 +00:00
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
pcbtxt->SetTextAngle( EDA_ANGLE( sign * t.rot->degrees, DEGREES_T ) );
|
2021-10-27 12:54:28 +00:00
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( degrees == 180 )
|
2021-10-27 12:54:28 +00:00
|
|
|
{
|
|
|
|
align = -align;
|
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else if( degrees == 270 )
|
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
pcbtxt->SetTextAngle( EDA_ANGLE( sign * 90, DEGREES_T ) );
|
2021-10-27 12:54:28 +00:00
|
|
|
align = -align;
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else
|
2017-04-14 12:30:57 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
// Ok so text is not at 90,180 or 270 so do some funny stuff to get
|
|
|
|
// placement right.
|
2017-04-14 12:30:57 +00:00
|
|
|
if( ( degrees > 0 ) && ( degrees < 90 ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
pcbtxt->SetTextAngle( EDA_ANGLE( sign * t.rot->degrees, DEGREES_T ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2017-04-14 12:30:57 +00:00
|
|
|
else if( ( degrees > 90 ) && ( degrees < 180 ) )
|
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
pcbtxt->SetTextAngle( EDA_ANGLE( sign * ( t.rot->degrees + 180 ), DEGREES_T ) );
|
2017-04-14 12:30:57 +00:00
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
}
|
|
|
|
else if( ( degrees > 180 ) && ( degrees < 270 ) )
|
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
pcbtxt->SetTextAngle( EDA_ANGLE( sign * ( t.rot->degrees - 180 ), DEGREES_T ) );
|
2017-04-14 12:30:57 +00:00
|
|
|
align = ETEXT::TOP_RIGHT;
|
|
|
|
}
|
|
|
|
else if( ( degrees > 270 ) && ( degrees < 360 ) )
|
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
pcbtxt->SetTextAngle( EDA_ANGLE( sign * t.rot->degrees, DEGREES_T ) );
|
2017-04-14 12:30:57 +00:00
|
|
|
align = ETEXT::BOTTOM_LEFT;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
switch( align )
|
|
|
|
{
|
|
|
|
case ETEXT::CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
pcbtxt->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
pcbtxt->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-08-11 05:50:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "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
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
ECIRCLE c( gr );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2020-04-01 09:22:32 +00:00
|
|
|
int width = c.width.ToPcbUnits();
|
|
|
|
int radius = c.radius.ToPcbUnits();
|
|
|
|
|
|
|
|
if( c.layer == EAGLE_LAYER::TRESTRICT || c.layer == EAGLE_LAYER::BRESTRICT
|
|
|
|
|| c.layer == EAGLE_LAYER::VRESTRICT )
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2020-04-01 09:22:32 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2012-08-11 05:50:17 +00:00
|
|
|
|
2020-04-23 14:21:29 +00:00
|
|
|
setKeepoutSettingsToZone( zone, c.layer );
|
2019-07-12 19:18:42 +00:00
|
|
|
|
2022-01-18 02:20:36 +00:00
|
|
|
// approximate circle as polygon
|
|
|
|
VECTOR2I center( kicad_x( c.x ), kicad_y( c.y ) );
|
|
|
|
int outlineRadius = radius + ( width / 2 );
|
|
|
|
int segsInCircle = GetArcToSegmentCount( outlineRadius, ARC_HIGH_DEF, FULL_CIRCLE );
|
|
|
|
EDA_ANGLE delta = ANGLE_360 / segsInCircle;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-01-18 02:20:36 +00:00
|
|
|
for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
|
2020-04-01 09:22:32 +00:00
|
|
|
{
|
2022-01-05 02:23:11 +00:00
|
|
|
VECTOR2I rotatedPoint( outlineRadius, 0 );
|
2022-01-18 02:20:36 +00:00
|
|
|
RotatePoint( rotatedPoint, angle );
|
2020-04-01 09:22:32 +00:00
|
|
|
zone->AppendCorner( center + rotatedPoint, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( width > 0 )
|
|
|
|
{
|
|
|
|
zone->NewHole();
|
|
|
|
int innerRadius = radius - ( width / 2 );
|
2022-01-18 02:20:36 +00:00
|
|
|
segsInCircle = GetArcToSegmentCount( innerRadius, ARC_HIGH_DEF, FULL_CIRCLE );
|
|
|
|
delta = ANGLE_360 / segsInCircle;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-01-18 02:20:36 +00:00
|
|
|
for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
|
2020-04-01 09:22:32 +00:00
|
|
|
{
|
2022-01-05 02:23:11 +00:00
|
|
|
VECTOR2I rotatedPoint( innerRadius, 0 );
|
2022-01-18 02:20:36 +00:00
|
|
|
RotatePoint( rotatedPoint, angle );
|
2020-04-01 09:22:32 +00:00
|
|
|
zone->AppendCorner( center + rotatedPoint, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2020-04-01 09:22:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = kicad_layer( c.layer );
|
|
|
|
|
|
|
|
if( layer != UNDEFINED_LAYER ) // unsupported layer
|
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( m_board, SHAPE_T::CIRCLE );
|
2020-10-04 23:34:59 +00:00
|
|
|
m_board->Add( shape, ADD_MODE::APPEND );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( false );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( layer );
|
2022-01-11 00:49:49 +00:00
|
|
|
shape->SetStart( VECTOR2I( kicad_x( c.x ), kicad_y( c.y ) ) );
|
|
|
|
shape->SetEnd( VECTOR2I( kicad_x( c.x ) + radius, kicad_y( c.y ) ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
|
2020-04-01 09:22:32 +00:00
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "rectangle" ) )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2015-10-04 16:56:59 +00:00
|
|
|
// This seems to be a simplified rectangular [copper] zone, cannot find any
|
|
|
|
// net related info on it from the DTD.
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "rectangle" );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
ERECT r( gr );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_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:
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = new ZONE( m_board );
|
2019-12-28 00:55:11 +00:00
|
|
|
m_board->Add( zone, ADD_MODE::APPEND );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
zone->SetLayer( layer );
|
2014-02-25 10:40:34 +00:00
|
|
|
zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
ZONE_BORDER_DISPLAY_STYLE outline_hatch = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2017-06-19 11:29:57 +00:00
|
|
|
const int outlineIdx = -1; // this is the id of the copper zone main outline
|
2022-01-11 00:49:49 +00:00
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
|
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
|
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
|
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2018-04-02 11:49:11 +00:00
|
|
|
if( r.rot )
|
2022-01-13 19:32:00 +00:00
|
|
|
zone->Rotate( zone->GetPosition(), EDA_ANGLE( r.rot->degrees, DEGREES_T ) );
|
2020-08-07 14:04:34 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
// this is not my fault:
|
2020-11-11 23:05:59 +00:00
|
|
|
zone->SetBorderDisplayStyle( outline_hatch, ZONE::GetDefaultHatchPitch(),
|
2020-08-07 14:04:34 +00:00
|
|
|
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
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "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
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
// Fabricate a FOOTPRINT with a single PAD_ATTRIB::NPTH pad.
|
2012-05-31 15:18:55 +00:00
|
|
|
// Use m_hole_count to gen up a unique name.
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( m_board );
|
2020-11-13 11:17:15 +00:00
|
|
|
m_board->Add( footprint, ADD_MODE::APPEND );
|
2022-02-05 02:06:25 +00:00
|
|
|
footprint->SetReference( wxString::Format( wxT( "@HOLE%d" ), m_hole_count++ ) );
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Reference().SetVisible( false );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
packageHole( footprint, gr, true );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "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
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "polygon" ) )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2018-05-18 16:14:54 +00:00
|
|
|
m_xpath->push( "polygon" );
|
|
|
|
loadPolygon( gr );
|
|
|
|
m_xpath->pop(); // "polygon"
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( grName == wxT( "dimension" ) )
|
2015-12-02 08:47:02 +00:00
|
|
|
{
|
2022-04-12 12:21:27 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
|
|
|
|
|
|
|
|
EDIMENSION d( gr );
|
2017-05-08 09:03:07 +00:00
|
|
|
PCB_LAYER_ID layer = kicad_layer( d.layer );
|
2022-04-12 12:21:27 +00:00
|
|
|
VECTOR2I pt1( kicad_x( d.x1 ), kicad_y( d.y1 ) );
|
|
|
|
VECTOR2I pt2( kicad_x( d.x2 ), kicad_y( d.y2 ) );
|
|
|
|
VECTOR2I pt3( kicad_x( d.x3 ), kicad_y( d.y3 ) );
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I textSize = designSettings.GetTextSize( layer );
|
2022-04-12 12:21:27 +00:00
|
|
|
int textThickness = designSettings.GetLineThickness( layer );
|
2015-12-02 08:47:02 +00:00
|
|
|
|
2022-04-12 12:21:27 +00:00
|
|
|
if( d.textsize )
|
2017-05-08 09:03:07 +00:00
|
|
|
{
|
2022-04-12 12:21:27 +00:00
|
|
|
double ratio = 8; // DTD says 8 is default
|
|
|
|
textThickness = KiROUND( d.textsize->ToPcbUnits() * ratio / 100 );
|
2023-02-19 03:40:07 +00:00
|
|
|
textSize = kicad_fontsize( *d.textsize, textThickness );
|
2022-04-12 12:21:27 +00:00
|
|
|
}
|
2017-05-08 09:03:07 +00:00
|
|
|
|
2022-04-12 12:21:27 +00:00
|
|
|
if( layer != UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
if( d.dimensionType == wxT( "angle" ) )
|
|
|
|
{
|
|
|
|
// Kicad doesn't (at present) support angle dimensions
|
|
|
|
}
|
|
|
|
else if( d.dimensionType == wxT( "radius" ) )
|
2017-10-18 07:21:32 +00:00
|
|
|
{
|
2022-04-12 14:19:18 +00:00
|
|
|
PCB_DIM_RADIAL* dimension = new PCB_DIM_RADIAL( m_board );
|
|
|
|
m_board->Add( dimension, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
dimension->SetLayer( layer );
|
|
|
|
dimension->SetPrecision( DIMENSION_PRECISION );
|
|
|
|
|
2022-08-30 14:13:51 +00:00
|
|
|
dimension->SetStart( pt1 );
|
|
|
|
dimension->SetEnd( pt2 );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( pt3 );
|
|
|
|
dimension->SetTextSize( textSize );
|
|
|
|
dimension->SetTextThickness( textThickness );
|
2022-04-12 14:19:18 +00:00
|
|
|
dimension->SetLineThickness( designSettings.GetLineThickness( layer ) );
|
|
|
|
dimension->SetUnits( EDA_UNITS::MILLIMETRES );
|
2022-04-12 12:21:27 +00:00
|
|
|
}
|
|
|
|
else if( d.dimensionType == wxT( "leader" ) )
|
|
|
|
{
|
|
|
|
PCB_DIM_LEADER* leader = new PCB_DIM_LEADER( m_board );
|
|
|
|
m_board->Add( leader, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
leader->SetLayer( layer );
|
|
|
|
leader->SetPrecision( DIMENSION_PRECISION );
|
|
|
|
|
2022-08-30 14:13:51 +00:00
|
|
|
leader->SetStart( pt1 );
|
|
|
|
leader->SetEnd( pt2 );
|
2023-03-04 23:15:43 +00:00
|
|
|
leader->SetTextPos( pt3 );
|
|
|
|
leader->SetTextSize( textSize );
|
|
|
|
leader->SetTextThickness( textThickness );
|
|
|
|
leader->SetOverrideText( wxEmptyString );
|
2022-04-12 12:21:27 +00:00
|
|
|
leader->SetLineThickness( designSettings.GetLineThickness( layer ) );
|
|
|
|
}
|
|
|
|
else // horizontal, vertical, <default>, diameter
|
|
|
|
{
|
|
|
|
PCB_DIM_ALIGNED* dimension = new PCB_DIM_ALIGNED( m_board, PCB_DIM_ALIGNED_T );
|
|
|
|
m_board->Add( dimension, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
if( d.dimensionType )
|
2017-10-18 07:21:32 +00:00
|
|
|
{
|
2022-04-12 12:21:27 +00:00
|
|
|
// Eagle dimension graphic arms may have different lengths, but they look
|
|
|
|
// incorrect in KiCad (the graphic is tilted). Make them even length in
|
|
|
|
// such case.
|
|
|
|
if( *d.dimensionType == wxT( "horizontal" ) )
|
|
|
|
{
|
|
|
|
int newY = ( pt1.y + pt2.y ) / 2;
|
|
|
|
pt1.y = newY;
|
|
|
|
pt2.y = newY;
|
|
|
|
}
|
|
|
|
else if( *d.dimensionType == wxT( "vertical" ) )
|
|
|
|
{
|
|
|
|
int newX = ( pt1.x + pt2.x ) / 2;
|
|
|
|
pt1.x = newX;
|
|
|
|
pt2.x = newX;
|
|
|
|
}
|
2017-10-18 07:21:32 +00:00
|
|
|
}
|
2022-04-12 12:21:27 +00:00
|
|
|
|
|
|
|
dimension->SetLayer( layer );
|
|
|
|
dimension->SetPrecision( DIMENSION_PRECISION );
|
|
|
|
|
|
|
|
// The origin and end are assumed to always be in this order from eagle
|
|
|
|
dimension->SetStart( pt1 );
|
|
|
|
dimension->SetEnd( pt2 );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextSize( textSize );
|
|
|
|
dimension->SetTextThickness( textThickness );
|
2022-04-12 12:21:27 +00:00
|
|
|
dimension->SetLineThickness( designSettings.GetLineThickness( layer ) );
|
|
|
|
dimension->SetUnits( EDA_UNITS::MILLIMETRES );
|
|
|
|
|
|
|
|
// check which axis the dimension runs in
|
|
|
|
// because the "height" of the dimension is perpendicular to that axis
|
|
|
|
// Note the check is just if two axes are close enough to each other
|
|
|
|
// Eagle appears to have some rounding errors
|
|
|
|
if( abs( pt1.x - pt2.x ) < 50000 ) // 50000 nm = 0.05 mm
|
2017-10-18 07:21:32 +00:00
|
|
|
{
|
2022-04-12 12:21:27 +00:00
|
|
|
int offset = pt3.x - pt1.x;
|
|
|
|
|
|
|
|
if( pt1.y > pt2.y )
|
|
|
|
dimension->SetHeight( offset );
|
|
|
|
else
|
|
|
|
dimension->SetHeight( -offset );
|
2017-10-18 07:21:32 +00:00
|
|
|
}
|
2022-04-12 12:21:27 +00:00
|
|
|
else if( abs( pt1.y - pt2.y ) < 50000 )
|
|
|
|
{
|
|
|
|
int offset = pt3.y - pt1.y;
|
2017-10-18 07:21:32 +00:00
|
|
|
|
2022-04-12 12:21:27 +00:00
|
|
|
if( pt1.x > pt2.x )
|
|
|
|
dimension->SetHeight( -offset );
|
|
|
|
else
|
|
|
|
dimension->SetHeight( offset );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-30 14:13:51 +00:00
|
|
|
int offset = GetLineLength( pt3, pt1 );
|
2022-04-12 12:21:27 +00:00
|
|
|
|
|
|
|
if( pt1.y > pt2.y )
|
|
|
|
dimension->SetHeight( offset );
|
|
|
|
else
|
|
|
|
dimension->SetHeight( -offset );
|
|
|
|
}
|
|
|
|
}
|
2017-05-08 09:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
// Get next graphic
|
|
|
|
gr = gr->GetNext();
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +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
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
void EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLib, const wxString* aLibName )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2018-12-11 15:06:11 +00:00
|
|
|
if( !aLib )
|
2018-08-09 17:53:48 +00:00
|
|
|
return;
|
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
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlNode* packages = MapChildren( aLib )["packages"];
|
|
|
|
|
2018-08-09 17:53:48 +00:00
|
|
|
if( !packages )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_xpath->push( "packages" );
|
2012-05-16 02:27:27 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
// Create a FOOTPRINT for all the eagle packages, for use later via a copy constructor
|
|
|
|
// to instantiate needed footprints in our BOARD. Save the FOOTPRINT templates in
|
2020-11-14 19:16:42 +00:00
|
|
|
// a FOOTPRINT_MAP using a single lookup key consisting of libname+pkgname.
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first package and iterate
|
|
|
|
wxXmlNode* package = packages->GetChildren();
|
|
|
|
|
|
|
|
while( package )
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->push( "package", "name" );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2018-08-30 20:05:54 +00:00
|
|
|
wxString pack_ref = package->GetAttribute( "name" );
|
|
|
|
ReplaceIllegalFileNameChars( pack_ref, '_' );
|
|
|
|
|
2018-08-30 20:25:18 +00:00
|
|
|
m_xpath->Value( pack_ref.ToUTF8() );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2018-08-30 20:05:54 +00:00
|
|
|
wxString key = aLibName ? makeKey( *aLibName, pack_ref ) : pack_ref;
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2022-04-10 15:48:24 +00:00
|
|
|
FOOTPRINT* footprint = makeFootprint( package, pack_ref );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
// add the templating FOOTPRINT to the FOOTPRINT template factory "m_templates"
|
2023-04-04 13:18:13 +00:00
|
|
|
auto r = m_templates.insert( { key, footprint } );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2020-08-04 14:57:57 +00:00
|
|
|
if( !r.second /* && !( m_props && m_props->Value( "ignore_duplicates" ) ) */ )
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
2018-08-30 20:25:18 +00:00
|
|
|
wxString lib = aLibName ? *aLibName : m_lib_path;
|
2019-12-05 15:40:22 +00:00
|
|
|
const wxString& pkg = pack_ref;
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString emsg = wxString::Format( _( "<package> '%s' duplicated in <library> '%s'" ),
|
|
|
|
pkg,
|
|
|
|
lib );
|
2013-01-02 04:05:48 +00:00
|
|
|
THROW_IO_ERROR( emsg );
|
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->pop();
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
package = package->GetNext();
|
2013-01-02 04:05:48 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadLibraries( wxXmlNode* aLibs )
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
2018-08-09 17:53:48 +00:00
|
|
|
if( !aLibs )
|
|
|
|
return;
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->push( "libraries.library", "name" );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first library and iterate
|
|
|
|
wxXmlNode* library = aLibs->GetChildren();
|
|
|
|
|
|
|
|
while( library )
|
2013-01-02 04:05:48 +00:00
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
const wxString& lib_name = library->GetAttribute( "name" );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->Value( lib_name.c_str() );
|
2017-04-07 11:40:34 +00:00
|
|
|
loadLibrary( library, &lib_name );
|
|
|
|
library = library->GetNext();
|
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
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2018-08-09 17:53:48 +00:00
|
|
|
if( !aElements )
|
|
|
|
return;
|
|
|
|
|
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;
|
2015-12-02 08:18:32 +00:00
|
|
|
bool refanceNamePresetInPackageLayout;
|
2015-12-02 11:46:55 +00:00
|
|
|
bool valueNamePresetInPackageLayout;
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first element and iterate
|
|
|
|
wxXmlNode* element = aElements->GetChildren();
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
while( element )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( element->GetName() != wxT( "element" ) )
|
2017-07-01 14:59:07 +00:00
|
|
|
{
|
|
|
|
// Get next item
|
|
|
|
element = element->GetNext();
|
2012-05-30 21:40:32 +00:00
|
|
|
continue;
|
2017-07-01 14:59:07 +00:00
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
EELEMENT e( element );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
// use "NULL-ness" as an indication of presence of the attribute:
|
2020-02-20 12:11:04 +00:00
|
|
|
EATTR* nameAttr = nullptr;
|
|
|
|
EATTR* valueAttr = nullptr;
|
2012-06-07 01:49:43 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->Value( e.name.c_str() );
|
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
wxString pkg_key = makeKey( e.library, e.package );
|
2023-04-04 13:18:13 +00:00
|
|
|
auto it = m_templates.find( pkg_key );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( it == m_templates.end() )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
wxString emsg = wxString::Format( _( "No '%s' package in library '%s'." ),
|
2022-04-09 13:33:01 +00:00
|
|
|
e.package, e.library );
|
2012-05-30 21:40:32 +00:00
|
|
|
THROW_IO_ERROR( emsg );
|
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( it->second->Duplicate() );
|
2020-08-10 13:22:02 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_board->Add( footprint, ADD_MODE::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
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
wxString pn_key = makeKey( e.name, pad->GetNumber() );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2016-05-29 15:02:34 +00:00
|
|
|
NET_MAP_CITER ni = m_pads_to_nets.find( pn_key );
|
2012-05-30 21:40:32 +00:00
|
|
|
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
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
refanceNamePresetInPackageLayout = true;
|
2015-12-02 11:46:55 +00:00
|
|
|
valueNamePresetInPackageLayout = true;
|
2022-01-11 00:49:49 +00:00
|
|
|
footprint->SetPosition( VECTOR2I( kicad_x( e.x ), kicad_y( e.y ) ) );
|
2017-07-17 12:09:01 +00:00
|
|
|
|
2015-12-02 11:46:55 +00:00
|
|
|
// Is >NAME field set in package layout ?
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->GetReference().size() == 0 )
|
2015-12-02 08:18:32 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Reference().SetVisible( false ); // No so no show
|
2015-12-02 08:18:32 +00:00
|
|
|
refanceNamePresetInPackageLayout = false;
|
|
|
|
}
|
2017-07-17 12:09:01 +00:00
|
|
|
|
2015-12-02 11:46:55 +00:00
|
|
|
// Is >VALUE field set in package layout
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->GetValue().size() == 0 )
|
2015-12-02 08:18:32 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( false ); // No so no show
|
2015-12-02 11:46:55 +00:00
|
|
|
valueNamePresetInPackageLayout = false;
|
2015-12-02 08:18:32 +00:00
|
|
|
}
|
2017-07-17 12:09:01 +00:00
|
|
|
|
2022-02-25 23:42:47 +00:00
|
|
|
wxString reference = e.name;
|
|
|
|
|
|
|
|
// EAGLE allows references to be single digits. This breaks KiCad
|
|
|
|
// netlisting, which requires parts to have non-digit + digit
|
|
|
|
// annotation. If the reference begins with a number, we prepend
|
|
|
|
// 'UNK' (unknown) for the symbol designator.
|
|
|
|
if( reference.find_first_not_of( "0123456789" ) != 0 )
|
|
|
|
reference.Prepend( "UNK" );
|
|
|
|
|
|
|
|
// EAGLE allows designator to start with # but that is used in KiCad
|
|
|
|
// for symbols which do not have a footprint
|
|
|
|
if( reference.find_first_not_of( "#" ) != 0 )
|
|
|
|
reference.Prepend( "UNK" );
|
|
|
|
|
|
|
|
// reference must end with a number but EAGLE does not enforce this
|
|
|
|
if( reference.find_last_not_of( "0123456789" ) == (reference.Length()-1) )
|
|
|
|
reference.Append( "0" );
|
|
|
|
|
|
|
|
footprint->SetReference( reference );
|
2022-04-09 13:33:01 +00:00
|
|
|
footprint->SetValue( e.value );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
if( !e.smashed )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
|
|
|
// Not smashed so show NAME & VALUE
|
2015-12-02 11:46:55 +00:00
|
|
|
if( valueNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( true ); // Only if place holder in package layout
|
2017-07-17 12:09:01 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
if( refanceNamePresetInPackageLayout )
|
2021-07-19 23:56:05 +00:00
|
|
|
footprint->Reference().SetVisible( true ); // Only if place holder in package layout
|
2015-12-02 08:18:32 +00:00
|
|
|
}
|
|
|
|
else if( *e.smashed == true )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
|
|
|
// Smashed so set default to no show for NAME and VALUE
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( false );
|
|
|
|
footprint->Reference().SetVisible( false );
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2019-05-17 12:38:03 +00:00
|
|
|
// initialize these to default values in case the <attribute> elements are not present.
|
2015-12-02 08:18:32 +00:00
|
|
|
m_xpath->push( "attribute", "name" );
|
|
|
|
|
|
|
|
// VALUE and NAME can have something like our text "effects" overrides
|
|
|
|
// in SWEET and new schematic. Eagle calls these XML elements "attribute".
|
|
|
|
// 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
|
|
|
|
// 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.
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first attribute and iterate
|
|
|
|
wxXmlNode* attribute = element->GetChildren();
|
|
|
|
|
|
|
|
while( attribute )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
if( attribute->GetName() != wxT( "attribute" ) )
|
2017-07-01 14:59:07 +00:00
|
|
|
{
|
|
|
|
attribute = attribute->GetNext();
|
2015-12-02 08:18:32 +00:00
|
|
|
continue;
|
2017-07-01 14:59:07 +00:00
|
|
|
}
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
EATTR a( attribute );
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( a.name == wxT( "NAME" ) )
|
2015-12-02 08:18:32 +00:00
|
|
|
{
|
|
|
|
name = a;
|
|
|
|
nameAttr = &name;
|
|
|
|
|
|
|
|
// do we have a display attribute ?
|
|
|
|
if( a.display )
|
|
|
|
{
|
|
|
|
// Yes!
|
|
|
|
switch( *a.display )
|
|
|
|
{
|
|
|
|
case EATTR::VALUE :
|
2019-05-21 02:47:32 +00:00
|
|
|
{
|
|
|
|
nameAttr->name = reference;
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
if( refanceNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Reference().SetVisible( true );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
2019-05-21 02:47:32 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
case EATTR::NAME :
|
|
|
|
if( refanceNamePresetInPackageLayout )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->SetReference( "NAME" );
|
|
|
|
footprint->Reference().SetVisible( true );
|
2015-12-02 08:18:32 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EATTR::BOTH :
|
|
|
|
if( refanceNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Reference().SetVisible( true );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
nameAttr->name = nameAttr->name + wxT( " = " ) + e.name;
|
|
|
|
footprint->SetReference( wxT( "NAME = " ) + e.name );
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EATTR::Off :
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Reference().SetVisible( false );
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
nameAttr->name = e.name;
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
if( refanceNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Reference().SetVisible( true );
|
2015-12-02 08:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2019-05-17 12:38:03 +00:00
|
|
|
// No display, so default is visible, and show value of NAME
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Reference().SetVisible( true );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2015-12-02 08:18:32 +00:00
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( a.name == wxT( "VALUE" ) )
|
2015-12-02 08:18:32 +00:00
|
|
|
{
|
|
|
|
value = a;
|
|
|
|
valueAttr = &value;
|
|
|
|
|
|
|
|
if( a.display )
|
|
|
|
{
|
|
|
|
// Yes!
|
|
|
|
switch( *a.display )
|
|
|
|
{
|
|
|
|
case EATTR::VALUE :
|
2017-12-14 09:37:32 +00:00
|
|
|
valueAttr->value = opt_wxString( e.value );
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->SetValue( e.value );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2015-12-02 11:46:55 +00:00
|
|
|
if( valueNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( true );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EATTR::NAME :
|
2015-12-02 11:46:55 +00:00
|
|
|
if( valueNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( true );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
footprint->SetValue( wxT( "VALUE" ) );
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EATTR::BOTH :
|
2015-12-02 11:46:55 +00:00
|
|
|
if( valueNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( true );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
valueAttr->value = opt_wxString( wxT( "VALUE = " ) + e.value );
|
|
|
|
footprint->SetValue( wxT( "VALUE = " ) + e.value );
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EATTR::Off :
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( false );
|
2015-12-02 08:18:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-12-14 09:37:32 +00:00
|
|
|
valueAttr->value = opt_wxString( e.value );
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2015-12-02 11:46:55 +00:00
|
|
|
if( valueNamePresetInPackageLayout )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( true );
|
2015-12-02 08:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-10-13 15:53:07 +00:00
|
|
|
{
|
2015-12-02 08:18:32 +00:00
|
|
|
// No display, so default is visible, and show value of NAME
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Value().SetVisible( true );
|
2020-10-13 15:53:07 +00:00
|
|
|
}
|
2015-12-02 08:18:32 +00:00
|
|
|
|
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
attribute = attribute->GetNext();
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2015-12-02 08:18:32 +00:00
|
|
|
m_xpath->pop(); // "attribute"
|
|
|
|
}
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
orientFootprintAndText( footprint, e, nameAttr, valueAttr );
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
// Get next element
|
|
|
|
element = element->GetNext();
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_xpath->pop(); // "elements.element"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* EAGLE_PLUGIN::loadPolygon( wxXmlNode* aPolyNode )
|
2018-05-18 16:14:54 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
EPOLYGON p( aPolyNode );
|
2018-05-18 16:14:54 +00:00
|
|
|
PCB_LAYER_ID layer = kicad_layer( p.layer );
|
2020-11-11 23:05:59 +00:00
|
|
|
bool keepout = ( p.layer == EAGLE_LAYER::TRESTRICT
|
|
|
|
|| p.layer == EAGLE_LAYER::BRESTRICT
|
|
|
|
|| p.layer == EAGLE_LAYER::VRESTRICT );
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
|
|
|
|
"was not mapped" ),
|
|
|
|
eagle_layer_name( p.layer ), p.layer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
if( !IsCopperLayer( layer ) && !keepout )
|
|
|
|
return nullptr;
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
// use a "netcode = 0" type ZONE:
|
2023-08-25 19:54:23 +00:00
|
|
|
std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( m_board );
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2020-04-23 14:21:29 +00:00
|
|
|
if( !keepout )
|
2018-05-23 15:44:45 +00:00
|
|
|
zone->SetLayer( layer );
|
2020-04-23 14:21:29 +00:00
|
|
|
else
|
2023-08-25 19:54:23 +00:00
|
|
|
setKeepoutSettingsToZone( zone.get(), p.layer );
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
// Get the first vertex and iterate
|
|
|
|
wxXmlNode* vertex = aPolyNode->GetChildren();
|
|
|
|
std::vector<EVERTEX> vertices;
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
// Create a circular vector of vertices
|
|
|
|
// The "curve" parameter indicates a curve from the current
|
|
|
|
// to the next vertex, so we keep the first at the end as well
|
|
|
|
// to allow the curve to link back
|
|
|
|
while( vertex )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
if( vertex->GetName() == wxT( "vertex" ) )
|
2019-12-05 15:41:21 +00:00
|
|
|
vertices.emplace_back( vertex );
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
vertex = vertex->GetNext();
|
|
|
|
}
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2023-01-17 20:49:24 +00:00
|
|
|
// According to Eagle's doc, by default, the orphans (islands in KiCad parlance)
|
|
|
|
// are always removed
|
|
|
|
if( !p.orphans || !p.orphans.Get() )
|
|
|
|
zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::ALWAYS );
|
|
|
|
else
|
|
|
|
zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::NEVER );
|
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
vertices.push_back( vertices[0] );
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2019-05-21 02:36:12 +00:00
|
|
|
SHAPE_POLY_SET polygon;
|
|
|
|
polygon.NewOutline();
|
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
for( size_t i = 0; i < vertices.size() - 1; i++ )
|
|
|
|
{
|
|
|
|
EVERTEX v1 = vertices[i];
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
// Append the corner
|
2019-05-21 02:36:12 +00:00
|
|
|
polygon.Append( kicad_x( v1.x ), kicad_y( v1.y ) );
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
if( v1.curve )
|
2018-05-18 16:14:54 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
EVERTEX v2 = vertices[i + 1];
|
|
|
|
VECTOR2I center =
|
|
|
|
ConvertArcCenter( VECTOR2I( kicad_x( v1.x ), kicad_y( v1.y ) ),
|
|
|
|
VECTOR2I( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
|
2018-05-23 15:44:45 +00:00
|
|
|
double angle = DEG2RAD( *v1.curve );
|
2021-07-19 23:56:05 +00:00
|
|
|
double end_angle = atan2( kicad_y( v2.y ) - center.y, kicad_x( v2.x ) - center.x );
|
|
|
|
double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
|
|
|
|
+ pow( center.y - kicad_y( v1.y ), 2 ) );
|
2018-05-23 15:44:45 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
|
|
|
|
EDA_ANGLE( *v1.curve, DEGREES_T ) );
|
2020-09-10 23:05:20 +00:00
|
|
|
double delta_angle = angle / segCount;
|
2018-05-23 15:44:45 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
for( double a = end_angle + angle; fabs( a - end_angle ) > fabs( delta_angle );
|
|
|
|
a -= delta_angle )
|
2018-05-23 15:44:45 +00:00
|
|
|
{
|
2019-05-21 02:36:12 +00:00
|
|
|
polygon.Append( KiROUND( radius * cos( a ) ) + center.x,
|
2020-10-13 15:53:07 +00:00
|
|
|
KiROUND( radius * sin( a ) ) + center.y );
|
2018-05-23 15:44:45 +00:00
|
|
|
}
|
2018-05-18 16:14:54 +00:00
|
|
|
}
|
2018-05-23 15:44:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 02:36:12 +00:00
|
|
|
// Eagle traces the zone such that half of the pen width is outside the polygon.
|
|
|
|
// We trace the zone such that the copper is completely inside.
|
|
|
|
if( p.width.ToPcbUnits() > 0 )
|
|
|
|
{
|
2023-10-05 07:34:24 +00:00
|
|
|
polygon.Inflate( p.width.ToPcbUnits() / 2, CORNER_STRATEGY::ALLOW_ACUTE_CORNERS,
|
2023-08-25 19:54:23 +00:00
|
|
|
ARC_HIGH_DEF, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( polygon.OutlineCount() != 1 )
|
|
|
|
{
|
|
|
|
wxLogMessage( wxString::Format(
|
|
|
|
_( "Skipping a polygon on layer '%s' (%d): outline count is not 1" ),
|
|
|
|
eagle_layer_name( p.layer ), p.layer ) );
|
|
|
|
|
|
|
|
return nullptr;
|
2019-05-21 02:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zone->AddPolygon( polygon.COutline( 0 ) );
|
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
// If the pour is a cutout it needs to be set to a keepout
|
|
|
|
if( p.pour == EPOLYGON::CUTOUT )
|
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
zone->SetIsRuleArea( true );
|
2020-06-07 19:24:29 +00:00
|
|
|
zone->SetDoNotAllowVias( false );
|
|
|
|
zone->SetDoNotAllowTracks( false );
|
|
|
|
zone->SetDoNotAllowPads( false );
|
|
|
|
zone->SetDoNotAllowFootprints( false );
|
2018-05-23 15:44:45 +00:00
|
|
|
zone->SetDoNotAllowCopperPour( true );
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
|
2018-05-23 15:44:45 +00:00
|
|
|
}
|
2019-07-12 18:11:21 +00:00
|
|
|
else if( p.pour == EPOLYGON::HATCH )
|
|
|
|
{
|
2022-09-16 23:25:07 +00:00
|
|
|
int spacing = p.spacing ? p.spacing->ToPcbUnits() : 50 * pcbIUScale.IU_PER_MILS;
|
2018-05-18 16:14:54 +00:00
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetHatchThickness( p.width.ToPcbUnits() );
|
|
|
|
zone->SetHatchGap( spacing - p.width.ToPcbUnits() );
|
2022-01-19 00:22:40 +00:00
|
|
|
zone->SetHatchOrientation( ANGLE_0 );
|
2019-07-12 18:11:21 +00:00
|
|
|
}
|
2018-05-23 15:44:45 +00:00
|
|
|
|
2019-05-21 02:36:12 +00:00
|
|
|
// We divide the thickness by half because we are tracing _inside_ the zone outline
|
|
|
|
// This means the radius of curvature will be twice the size for an equivalent EAGLE zone
|
2023-02-11 02:54:40 +00:00
|
|
|
zone->SetMinThickness( std::max<int>( ZONE_THICKNESS_MIN_VALUE_MM * pcbIUScale.IU_PER_MM,
|
2020-10-13 15:53:07 +00:00
|
|
|
p.width.ToPcbUnits() / 2 ) );
|
2018-05-23 15:44:45 +00:00
|
|
|
|
|
|
|
if( p.isolate )
|
2020-09-05 16:00:29 +00:00
|
|
|
zone->SetLocalClearance( p.isolate->ToPcbUnits() );
|
2018-05-23 15:44:45 +00:00
|
|
|
else
|
2020-09-05 16:00:29 +00:00
|
|
|
zone->SetLocalClearance( 1 ); // @todo: set minimum clearance value based on board settings
|
2018-05-23 15:44:45 +00:00
|
|
|
|
|
|
|
// missing == yes per DTD.
|
|
|
|
bool thermals = !p.thermals || *p.thermals;
|
2019-12-28 00:55:11 +00:00
|
|
|
zone->SetPadConnection( thermals ? ZONE_CONNECTION::THERMAL : ZONE_CONNECTION::FULL );
|
2018-05-23 15:44:45 +00:00
|
|
|
|
|
|
|
if( thermals )
|
|
|
|
{
|
|
|
|
// FIXME: eagle calculates dimensions for thermal spokes
|
|
|
|
// based on what the zone is connecting to.
|
|
|
|
// (i.e. width of spoke is half of the smaller side of an smd pad)
|
|
|
|
// This is a basic workaround
|
|
|
|
zone->SetThermalReliefGap( p.width.ToPcbUnits() + 50000 ); // 50000nm == 0.05mm
|
2020-09-17 13:14:45 +00:00
|
|
|
zone->SetThermalReliefSpokeWidth( p.width.ToPcbUnits() + 50000 );
|
2018-05-18 16:14:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 15:44:45 +00:00
|
|
|
int rank = p.rank ? (p.max_priority - *p.rank) : p.max_priority;
|
2022-03-01 14:53:35 +00:00
|
|
|
zone->SetAssignedPriority( rank );
|
2018-05-23 15:44:45 +00:00
|
|
|
|
2023-10-05 22:13:58 +00:00
|
|
|
ZONE* zonePtr = zone.release();
|
|
|
|
m_board->Add( zonePtr, ADD_MODE::APPEND );
|
|
|
|
|
|
|
|
return zonePtr;
|
2018-05-18 16:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::orientFootprintAndText( FOOTPRINT* aFootprint, const EELEMENT& e,
|
|
|
|
const EATTR* aNameAttr, const EATTR* aValueAttr )
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
|
|
|
if( e.rot )
|
|
|
|
{
|
|
|
|
if( e.rot->mirror )
|
2012-06-05 04:39:37 +00:00
|
|
|
{
|
2022-01-13 17:27:36 +00:00
|
|
|
aFootprint->SetOrientation( EDA_ANGLE( e.rot->degrees + 180.0, DEGREES_T ) );
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Flip( aFootprint->GetPosition(), false );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else
|
2020-11-13 01:12:36 +00:00
|
|
|
{
|
2022-01-13 17:27:36 +00:00
|
|
|
aFootprint->SetOrientation( EDA_ANGLE( e.rot->degrees, DEGREES_T ) );
|
2020-11-13 01:12:36 +00:00
|
|
|
}
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
orientFPText( aFootprint, e, &aFootprint->Reference(), aNameAttr );
|
|
|
|
orientFPText( aFootprint, e, &aFootprint->Value(), aValueAttr );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void EAGLE_PLUGIN::orientFPText( FOOTPRINT* aFootprint, const EELEMENT& e, PCB_TEXT* aFPText,
|
2020-11-13 15:15:52 +00:00
|
|
|
const EATTR* aAttr )
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
2015-12-02 08:18:32 +00:00
|
|
|
// Smashed part ?
|
2012-06-07 01:49:43 +00:00
|
|
|
if( aAttr )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
|
|
|
// Yes
|
2012-06-07 01:49:43 +00:00
|
|
|
const EATTR& a = *aAttr;
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
if( a.value )
|
|
|
|
{
|
2022-04-09 13:33:01 +00:00
|
|
|
aFPText->SetText( *a.value );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
if( a.x && a.y ) // std::optional
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
2022-01-11 00:49:49 +00:00
|
|
|
VECTOR2I pos( kicad_x( *a.x ), kicad_y( *a.y ) );
|
2020-11-13 01:12:36 +00:00
|
|
|
aFPText->SetTextPos( 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;
|
2022-02-01 17:58:09 +00:00
|
|
|
|
|
|
|
if( a.ratio )
|
|
|
|
ratio = *a.ratio;
|
|
|
|
|
2022-05-14 12:12:03 +00:00
|
|
|
VECTOR2I fontz = aFPText->GetTextSize();
|
|
|
|
int textThickness = KiROUND( fontz.y * ratio / 100 );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFPText->SetTextThickness( textThickness );
|
2012-06-07 01:49:43 +00:00
|
|
|
if( a.size )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
fontz = kicad_fontsize( *a.size, textThickness );
|
2020-11-13 01:12:36 +00:00
|
|
|
aFPText->SetTextSize( fontz );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2020-06-09 07:32:52 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
|
|
|
|
|
2019-05-21 03:03:43 +00:00
|
|
|
if( a.align )
|
2023-07-04 23:40:18 +00:00
|
|
|
align = *a.align;
|
2019-05-21 03:03:43 +00:00
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
// 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.
|
2022-01-13 17:27:36 +00:00
|
|
|
double degrees = a.rot ? a.rot->degrees : 0.0;
|
2012-06-07 01:49:43 +00:00
|
|
|
|
|
|
|
int sign = 1;
|
|
|
|
bool spin = false;
|
|
|
|
|
|
|
|
if( a.rot )
|
|
|
|
{
|
|
|
|
spin = a.rot->spin;
|
|
|
|
sign = a.rot->mirror ? -1 : 1;
|
2020-11-13 01:12:36 +00:00
|
|
|
aFPText->SetMirrored( a.rot->mirror );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( degrees == 90 || degrees == 0 || spin )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
aFPText->SetTextAngle( EDA_ANGLE( sign * degrees, DEGREES_T ) );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
else if( degrees == 180 )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
aFPText->SetTextAngle( EDA_ANGLE( sign * 0, DEGREES_T ) );
|
2019-05-21 03:03:43 +00:00
|
|
|
align = -align;
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
else if( degrees == 270 )
|
|
|
|
{
|
2019-05-21 03:03:43 +00:00
|
|
|
align = -align;
|
2023-03-30 11:49:23 +00:00
|
|
|
aFPText->SetTextAngle( EDA_ANGLE( sign * 90, DEGREES_T ) );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
2012-08-11 05:50:17 +00:00
|
|
|
else
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
aFPText->SetTextAngle( EDA_ANGLE( sign * 90 - degrees, DEGREES_T ) );
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
switch( align )
|
|
|
|
{
|
|
|
|
case ETEXT::TOP_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-06-07 01:49:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-06-07 01:49:43 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-21 03:03:43 +00:00
|
|
|
case ETEXT::TOP_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2019-05-21 03:03:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2019-05-21 03:03:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2019-05-21 03:03:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2019-05-21 03:03:43 +00:00
|
|
|
break;
|
|
|
|
|
2021-10-27 12:54:28 +00:00
|
|
|
case ETEXT::CENTER:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2021-10-27 12:54:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2021-10-27 12:54:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2021-10-27 12:54:28 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-07 01:49:43 +00:00
|
|
|
default:
|
|
|
|
;
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
2022-01-13 17:27:36 +00:00
|
|
|
// Part is not smash so use Lib default for NAME/VALUE
|
|
|
|
// the text is per the original package, sans <attribute>.
|
|
|
|
double degrees = aFPText->GetTextAngle().AsDegrees()
|
|
|
|
+ aFootprint->GetOrientation().AsDegrees();
|
2012-06-07 01:49:43 +00:00
|
|
|
|
2012-08-11 05:50:17 +00:00
|
|
|
// @todo there are a few more cases than these to contend with:
|
2020-11-24 22:16:41 +00:00
|
|
|
if( ( !aFPText->IsMirrored() && ( abs( degrees ) == 180 || abs( degrees ) == 270 ) )
|
2020-11-13 01:12:36 +00:00
|
|
|
|| ( aFPText->IsMirrored() && ( degrees == 360 ) ) )
|
2012-06-07 01:49:43 +00:00
|
|
|
{
|
|
|
|
// ETEXT::TOP_RIGHT:
|
2021-12-28 22:13:54 +00:00
|
|
|
aFPText->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
aFPText->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-30 21:40:32 +00:00
|
|
|
}
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* EAGLE_PLUGIN::makeFootprint( wxXmlNode* aPackage, const wxString& aPkgName )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> m = std::make_unique<FOOTPRINT>( m_board );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID fpID;
|
2020-12-17 23:32:23 +00:00
|
|
|
fpID.Parse( aPkgName, true );
|
2018-07-26 14:38:30 +00:00
|
|
|
m->SetFPID( fpID );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first package item and iterate
|
|
|
|
wxXmlNode* packageItem = aPackage->GetChildren();
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2022-01-08 20:14:53 +00:00
|
|
|
// layer 27 is default layer for tValues
|
|
|
|
// set default layer for created footprint
|
|
|
|
PCB_LAYER_ID layer = kicad_layer( 27 );
|
|
|
|
m.get()->Value().SetLayer( layer );
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
while( packageItem )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
const wxString& itemName = packageItem->GetName();
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( itemName == wxT( "description" ) )
|
2023-06-19 17:08:18 +00:00
|
|
|
m->SetLibDescription( packageItem->GetNodeContent() );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "wire" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packageWire( m.get(), packageItem );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "pad" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packagePad( m.get(), packageItem );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "text" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packageText( m.get(), packageItem );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "rectangle" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packageRectangle( m.get(), packageItem );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "polygon" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packagePolygon( m.get(), packageItem );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "circle" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packageCircle( m.get(), packageItem );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "hole" ) )
|
2018-09-09 03:40:24 +00:00
|
|
|
packageHole( m.get(), packageItem, false );
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "smd" ) )
|
2017-04-07 11:40:34 +00:00
|
|
|
packageSMD( m.get(), packageItem );
|
|
|
|
|
|
|
|
packageItem = packageItem->GetNext();
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packageWire( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
EWIRE w( aTree );
|
|
|
|
PCB_LAYER_ID layer = kicad_layer( w.layer );
|
2022-01-11 00:49:49 +00:00
|
|
|
VECTOR2I start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
|
|
|
|
VECTOR2I end( kicad_x( w.x2 ), kicad_y( w.y2 ) );
|
2018-09-19 20:23:25 +00:00
|
|
|
int width = w.width.ToPcbUnits();
|
2014-12-07 17:07:05 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
wxLogMessage( wxString::Format( _( "Ignoring a wire since Eagle layer '%s' (%d) "
|
|
|
|
"was not mapped" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
eagle_layer_name( w.layer ), w.layer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-17 12:38:03 +00:00
|
|
|
// KiCad cannot handle zero or negative line widths which apparently have meaning in Eagle.
|
2019-01-05 22:12:48 +00:00
|
|
|
if( width <= 0 )
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
BOARD* board = aFootprint->GetBoard();
|
2019-05-17 12:38:03 +00:00
|
|
|
|
|
|
|
if( board )
|
|
|
|
{
|
|
|
|
width = board->GetDesignSettings().GetLineThickness( layer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// When loading footprint libraries, there is no board so use the default KiCad
|
|
|
|
// line widths.
|
|
|
|
switch( layer )
|
|
|
|
{
|
2022-09-16 11:33:56 +00:00
|
|
|
case Edge_Cuts: width = pcbIUScale.mmToIU( DEFAULT_EDGE_WIDTH ); break;
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2019-05-17 12:38:03 +00:00
|
|
|
case F_SilkS:
|
2022-09-16 11:33:56 +00:00
|
|
|
case B_SilkS: width = pcbIUScale.mmToIU( DEFAULT_SILK_LINE_WIDTH ); break;
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2019-05-17 12:38:03 +00:00
|
|
|
case F_CrtYd:
|
2022-09-16 11:33:56 +00:00
|
|
|
case B_CrtYd: width = pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ); break;
|
2020-10-13 15:53:07 +00:00
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
default: width = pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ); break;
|
2019-05-17 12:38:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-05 22:12:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 09:42:29 +00:00
|
|
|
// FIXME: the cap attribute is ignored because KiCad can't create lines with flat ends.
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* dwg;
|
2017-10-17 08:19:43 +00:00
|
|
|
|
2017-10-11 12:24:14 +00:00
|
|
|
if( !w.curve )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dwg = new PCB_SHAPE( aFootprint, SHAPE_T::SEGMENT );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
dwg->SetStart( start );
|
|
|
|
dwg->SetEnd( end );
|
2017-10-11 12:24:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
dwg = new PCB_SHAPE( aFootprint, SHAPE_T::ARC );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center = ConvertArcCenter( start, end, *w.curve );
|
2014-12-07 17:07:05 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
dwg->SetCenter( center );
|
|
|
|
dwg->SetStart( start );
|
|
|
|
dwg->SetArcAngleAndEnd( -EDA_ANGLE( *w.curve, DEGREES_T ), true ); // KiCad rotates the other way
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
2017-10-11 12:24:14 +00:00
|
|
|
|
|
|
|
dwg->SetLayer( layer );
|
2021-07-17 19:56:18 +00:00
|
|
|
dwg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
|
|
|
|
dwg->Move( aFootprint->GetPosition() );
|
2017-10-11 12:24:14 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( dwg );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packagePad( FOOTPRINT* aFootprint, wxXmlNode* aTree )
|
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 );
|
2019-02-04 01:46:10 +00:00
|
|
|
int shape = EPAD::UNDEF;
|
2020-05-06 00:46:09 +00:00
|
|
|
int eagleDrillz = e.drill.ToPcbUnits();
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
|
|
|
|
transferPad( e, pad.get() );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2019-05-20 13:00:58 +00:00
|
|
|
if( e.first && *e.first && m_rules->psFirst != EPAD::UNDEF )
|
2019-02-04 01:46:10 +00:00
|
|
|
shape = m_rules->psFirst;
|
2020-11-13 01:12:36 +00:00
|
|
|
else if( aFootprint->GetLayer() == F_Cu && m_rules->psTop != EPAD::UNDEF )
|
2019-02-04 01:46:10 +00:00
|
|
|
shape = m_rules->psTop;
|
2020-11-13 01:12:36 +00:00
|
|
|
else if( aFootprint->GetLayer() == B_Cu && m_rules->psBottom != EPAD::UNDEF )
|
2019-02-04 01:46:10 +00:00
|
|
|
shape = m_rules->psBottom;
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( eagleDrillz, eagleDrillz ) );
|
2019-07-17 00:02:53 +00:00
|
|
|
pad->SetLayerSet( LSET::AllCuMask() );
|
|
|
|
|
2020-05-06 00:46:09 +00:00
|
|
|
if( eagleDrillz < m_min_hole )
|
|
|
|
m_min_hole = eagleDrillz;
|
2020-05-04 19:08:42 +00:00
|
|
|
|
2019-07-17 00:02:53 +00:00
|
|
|
// Solder mask
|
|
|
|
if( !e.stop || *e.stop == true ) // enabled by default
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().set( B_Mask ).set( F_Mask ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2019-05-15 06:11:30 +00:00
|
|
|
if( shape == EPAD::ROUND || shape == EPAD::SQUARE || shape == EPAD::OCTAGON )
|
2019-02-04 01:46:10 +00:00
|
|
|
e.shape = shape;
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( e.shape )
|
|
|
|
{
|
|
|
|
switch( *e.shape )
|
|
|
|
{
|
|
|
|
case EPAD::ROUND:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2012-05-31 15:18:55 +00:00
|
|
|
break;
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
case EPAD::OCTAGON:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CHAMFERED_RECT );
|
2019-05-15 06:11:30 +00:00
|
|
|
pad->SetChamferPositions( RECT_CHAMFER_ALL );
|
2022-05-23 09:42:29 +00:00
|
|
|
pad->SetChamferRectRatio( 1 - M_SQRT1_2 ); // Regular polygon
|
2012-05-31 15:18:55 +00:00
|
|
|
break;
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
case EPAD::LONG:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::OVAL );
|
2012-05-31 15:18:55 +00:00
|
|
|
break;
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
case EPAD::SQUARE:
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECTANGLE );
|
2012-05-31 15:18:55 +00:00
|
|
|
break;
|
2015-12-02 08:18:32 +00:00
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
case EPAD::OFFSET:
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::OVAL );
|
2019-05-15 06:11:30 +00:00
|
|
|
break;
|
2012-05-31 15:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if shape is not present, our default is circle and that matches their default "round"
|
|
|
|
}
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( e.diameter && e.diameter->value > 0 )
|
2012-05-29 18:10:56 +00:00
|
|
|
{
|
2017-10-17 08:18:54 +00:00
|
|
|
int diameter = e.diameter->ToPcbUnits();
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( diameter, diameter ) );
|
2012-05-29 18:10:56 +00:00
|
|
|
}
|
|
|
|
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"
|
2018-06-29 17:52:56 +00:00
|
|
|
annulus = eagleClamp( m_rules->rlMinPadTop, annulus, m_rules->rlMaxPadTop );
|
2012-06-05 04:39:37 +00:00
|
|
|
int diameter = KiROUND( drillz + 2 * annulus );
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( KiROUND( diameter ), KiROUND( diameter ) ) );
|
2012-05-31 15:18:55 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE::OVAL )
|
2012-05-31 15:18:55 +00:00
|
|
|
{
|
2022-05-23 09:42:29 +00:00
|
|
|
// The Eagle "long" pad is wider than it is tall; m_elongation is percent elongation
|
2022-01-05 01:42:27 +00:00
|
|
|
VECTOR2I 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 );
|
2019-05-15 06:11:30 +00:00
|
|
|
|
|
|
|
if( e.shape && *e.shape == EPAD::OFFSET )
|
|
|
|
{
|
|
|
|
int offset = KiROUND( ( sz.x - sz.y ) / 2.0 );
|
2022-01-11 00:49:49 +00:00
|
|
|
pad->SetOffset( VECTOR2I( offset, 0 ) );
|
2019-05-15 06:11:30 +00:00
|
|
|
}
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( e.rot )
|
2022-01-13 13:45:48 +00:00
|
|
|
pad->SetOrientation( EDA_ANGLE( e.rot->degrees, DEGREES_T ) );
|
2022-08-14 01:51:14 +00:00
|
|
|
|
2023-08-16 16:29:40 +00:00
|
|
|
// Eagle spokes are always '+'
|
|
|
|
pad->SetThermalSpokeAngle( ANGLE_0 );
|
2023-08-16 16:02:35 +00:00
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
if( pad->GetSizeX() > 0 && pad->GetSizeY() > 0 )
|
|
|
|
{
|
|
|
|
aFootprint->Add( pad.release() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogError( _( "Invalid zero-sized pad ignored in\nfile: %s" ), m_board->GetFileName() );
|
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packageText( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
ETEXT t( aTree );
|
|
|
|
PCB_LAYER_ID layer = kicad_layer( t.layer );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
wxLogMessage( wxString::Format( _( "Ignoring a text since Eagle layer '%s' (%d) "
|
|
|
|
"was not mapped" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
eagle_layer_name( t.layer ), t.layer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT* textItem;
|
2022-04-10 15:48:24 +00:00
|
|
|
|
|
|
|
if( t.text.Upper() == wxT( ">NAME" ) && aFootprint->GetReference().IsEmpty() )
|
|
|
|
{
|
|
|
|
textItem = &aFootprint->Reference();
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetText( wxT( "REF**" ) );
|
|
|
|
}
|
|
|
|
else if( t.text.Upper() == wxT( ">VALUE" ) && aFootprint->GetValue().IsEmpty() )
|
|
|
|
{
|
|
|
|
textItem = &aFootprint->Value();
|
|
|
|
|
|
|
|
textItem->SetText( aFootprint->GetFPID().GetLibItemName() );
|
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
else
|
2012-05-30 21:40:32 +00:00
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
textItem = new PCB_TEXT( aFootprint );
|
2022-04-10 15:48:24 +00:00
|
|
|
aFootprint->Add( textItem );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2023-01-18 12:33:36 +00:00
|
|
|
textItem->SetText( interpretText( t.text ) );
|
2022-04-10 15:48:24 +00:00
|
|
|
}
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos( kicad_x( t.x ), kicad_y( t.y ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
textItem->SetPosition( pos );
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetLayer( layer );
|
2020-06-09 07:32:52 +00:00
|
|
|
|
2012-06-01 07:39:32 +00:00
|
|
|
double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
|
2022-04-10 15:48:24 +00:00
|
|
|
int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetTextThickness( textThickness );
|
2023-02-19 03:40:07 +00:00
|
|
|
textItem->SetTextSize( kicad_fontsize( t.size, textThickness ) );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
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.
|
2020-11-13 01:12:36 +00:00
|
|
|
// angle -= aFootprint->GetOrienation();
|
2012-06-01 07:39:32 +00:00
|
|
|
|
|
|
|
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;
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->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 )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetTextAngle( EDA_ANGLE( sign * degrees, DEGREES_T ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-06-07 01:49:43 +00:00
|
|
|
else if( degrees == 180 )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-06-07 01:49:43 +00:00
|
|
|
align = ETEXT::TOP_RIGHT;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-06-07 01:49:43 +00:00
|
|
|
else if( degrees == 270 )
|
|
|
|
{
|
|
|
|
align = ETEXT::TOP_RIGHT;
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetTextAngle( EDA_ANGLE( sign * 90, DEGREES_T ) );
|
2012-06-07 01:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
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:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_LEFT:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::CENTER_RIGHT:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_CENTER:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_LEFT:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::TOP_RIGHT:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_CENTER:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_LEFT:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ETEXT::BOTTOM_RIGHT:
|
2022-04-10 15:48:24 +00:00
|
|
|
textItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
|
|
|
|
textItem->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
|
2012-05-24 01:18:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packageRectangle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2020-04-01 08:28:48 +00:00
|
|
|
ERECT r( aTree );
|
2018-09-19 20:23:25 +00:00
|
|
|
|
2020-04-01 08:28:48 +00:00
|
|
|
if( r.layer == EAGLE_LAYER::TRESTRICT || r.layer == EAGLE_LAYER::BRESTRICT
|
|
|
|
|| r.layer == EAGLE_LAYER::VRESTRICT )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
ZONE* zone = new ZONE( aFootprint );
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( zone, ADD_MODE::APPEND );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2020-04-23 14:21:29 +00:00
|
|
|
setKeepoutSettingsToZone( zone, r.layer );
|
2020-04-01 08:28:48 +00:00
|
|
|
|
|
|
|
const int outlineIdx = -1; // this is the id of the copper zone main outline
|
2022-01-11 00:49:49 +00:00
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y1 ) ), outlineIdx );
|
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y1 ) ), outlineIdx );
|
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x2 ), kicad_y( r.y2 ) ), outlineIdx );
|
|
|
|
zone->AppendCorner( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y2 ) ), outlineIdx );
|
2020-04-01 08:28:48 +00:00
|
|
|
|
|
|
|
if( r.rot )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center( ( kicad_x( r.x1 ) + kicad_x( r.x2 ) ) / 2,
|
|
|
|
( kicad_y( r.y1 ) + kicad_y( r.y2 ) ) / 2 );
|
2022-01-13 19:32:00 +00:00
|
|
|
zone->Rotate( center, EDA_ANGLE( r.rot->degrees, DEGREES_T ) );
|
2020-04-01 08:28:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2020-04-01 08:28:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = kicad_layer( r.layer );
|
2020-11-13 01:12:36 +00:00
|
|
|
|
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
2021-04-03 09:11:32 +00:00
|
|
|
wxLogMessage( wxString::Format( _( "Ignoring a rectangle since Eagle layer '%s' (%d) "
|
2020-11-13 01:12:36 +00:00
|
|
|
"was not mapped" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
eagle_layer_name( r.layer ), r.layer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* dwg = new PCB_SHAPE( aFootprint, SHAPE_T::POLY );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( dwg );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2020-04-01 08:28:48 +00:00
|
|
|
dwg->SetLayer( layer );
|
2021-07-17 19:56:18 +00:00
|
|
|
dwg->SetStroke( STROKE_PARAMS( 0 ) );
|
2021-11-14 23:41:22 +00:00
|
|
|
dwg->SetFilled( true );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts;
|
2017-10-11 12:24:14 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y1 ) ) );
|
|
|
|
VECTOR2I end( VECTOR2I( kicad_x( r.x1 ), kicad_y( r.y2 ) ) );
|
2017-10-11 12:24:14 +00:00
|
|
|
|
2020-04-01 08:28:48 +00:00
|
|
|
pts.push_back( start );
|
|
|
|
pts.emplace_back( kicad_x( r.x2 ), kicad_y( r.y1 ) );
|
|
|
|
pts.emplace_back( kicad_x( r.x2 ), kicad_y( r.y2 ) );
|
|
|
|
pts.push_back( end );
|
2018-04-02 11:49:11 +00:00
|
|
|
|
2020-04-01 08:28:48 +00:00
|
|
|
dwg->SetPolyPoints( pts );
|
|
|
|
|
|
|
|
if( r.rot )
|
2022-01-13 19:32:00 +00:00
|
|
|
dwg->Rotate( dwg->GetCenter(), EDA_ANGLE( r.rot->degrees, DEGREES_T ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
|
|
|
|
dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
|
|
|
|
dwg->Move( aFootprint->GetPosition() );
|
2020-04-01 08:28:48 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packagePolygon( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2018-09-19 20:23:25 +00:00
|
|
|
EPOLYGON p( aTree );
|
2017-10-03 10:30:23 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2017-10-11 12:24:14 +00:00
|
|
|
// Get the first vertex and iterate
|
|
|
|
wxXmlNode* vertex = aTree->GetChildren();
|
2018-04-02 17:49:43 +00:00
|
|
|
std::vector<EVERTEX> vertices;
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2018-04-02 17:49:43 +00:00
|
|
|
// Create a circular vector of vertices
|
|
|
|
// The "curve" parameter indicates a curve from the current
|
|
|
|
// to the next vertex, so we keep the first at the end as well
|
|
|
|
// to allow the curve to link back
|
2017-10-11 12:24:14 +00:00
|
|
|
while( vertex )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
if( vertex->GetName() == wxT( "vertex" ) )
|
2019-12-05 15:41:21 +00:00
|
|
|
vertices.emplace_back( vertex );
|
2018-04-02 17:49:43 +00:00
|
|
|
|
|
|
|
vertex = vertex->GetNext();
|
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
2018-04-02 17:49:43 +00:00
|
|
|
vertices.push_back( vertices[0] );
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2018-04-02 17:49:43 +00:00
|
|
|
for( size_t i = 0; i < vertices.size() - 1; i++ )
|
|
|
|
{
|
|
|
|
EVERTEX v1 = vertices[i];
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2018-04-02 17:49:43 +00:00
|
|
|
// Append the corner
|
2019-12-05 15:41:21 +00:00
|
|
|
pts.emplace_back( kicad_x( v1.x ), kicad_y( v1.y ) );
|
2018-04-02 17:49:43 +00:00
|
|
|
|
|
|
|
if( v1.curve )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
EVERTEX v2 = vertices[i + 1];
|
|
|
|
VECTOR2I center =
|
|
|
|
ConvertArcCenter( VECTOR2I( kicad_x( v1.x ), kicad_y( v1.y ) ),
|
|
|
|
VECTOR2I( kicad_x( v2.x ), kicad_y( v2.y ) ), *v1.curve );
|
2018-04-02 17:49:43 +00:00
|
|
|
double angle = DEG2RAD( *v1.curve );
|
2021-07-19 23:56:05 +00:00
|
|
|
double end_angle = atan2( kicad_y( v2.y ) - center.y, kicad_x( v2.x ) - center.x );
|
2018-04-02 17:49:43 +00:00
|
|
|
double radius = sqrt( pow( center.x - kicad_x( v1.x ), 2 )
|
2021-07-19 23:56:05 +00:00
|
|
|
+ pow( center.y - kicad_y( v1.y ), 2 ) );
|
2018-04-02 17:49:43 +00:00
|
|
|
|
2020-01-11 16:41:24 +00:00
|
|
|
// Don't allow a zero-radius curve
|
|
|
|
if( KiROUND( radius ) == 0 )
|
|
|
|
radius = 1.0;
|
2018-04-02 17:49:43 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
int segCount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
|
|
|
|
EDA_ANGLE( *v1.curve, DEGREES_T ) );
|
2020-01-11 16:41:24 +00:00
|
|
|
double delta = angle / segCount;
|
|
|
|
|
|
|
|
for( double a = end_angle + angle; fabs( a - end_angle ) > fabs( delta ); a -= delta )
|
2018-04-02 17:49:43 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
pts.push_back(
|
|
|
|
VECTOR2I( KiROUND( radius * cos( a ) ), KiROUND( radius * sin( a ) ) )
|
|
|
|
+ center );
|
2018-04-02 17:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-11 12:24:14 +00:00
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
2023-03-25 21:12:13 +00:00
|
|
|
PCB_LAYER_ID layer = kicad_layer( p.layer );
|
|
|
|
|
|
|
|
if( ( p.pour == EPOLYGON::CUTOUT && layer != UNDEFINED_LAYER )
|
2023-01-13 14:40:34 +00:00
|
|
|
|| p.layer == EAGLE_LAYER::TRESTRICT
|
|
|
|
|| p.layer == EAGLE_LAYER::BRESTRICT
|
|
|
|
|| p.layer == EAGLE_LAYER::VRESTRICT )
|
2020-04-01 08:48:23 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
ZONE* zone = new ZONE( aFootprint );
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( zone, ADD_MODE::APPEND );
|
2020-04-01 08:48:23 +00:00
|
|
|
|
2020-04-23 14:21:29 +00:00
|
|
|
setKeepoutSettingsToZone( zone, p.layer );
|
2020-04-01 08:48:23 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN outline( pts );
|
|
|
|
outline.SetClosed( true );
|
|
|
|
zone->Outline()->AddOutline( outline );
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2020-04-01 08:48:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
wxLogMessage( wxString::Format( _( "Ignoring a polygon since Eagle layer '%s' (%d) "
|
|
|
|
"was not mapped" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
eagle_layer_name( p.layer ), p.layer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* dwg = new PCB_SHAPE( aFootprint, SHAPE_T::POLY );
|
2020-04-01 08:48:23 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( dwg );
|
2020-04-01 08:48:23 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
dwg->SetStroke( STROKE_PARAMS( 0 ) );
|
2021-11-14 23:41:22 +00:00
|
|
|
dwg->SetFilled( true );
|
2020-04-01 08:48:23 +00:00
|
|
|
dwg->SetLayer( layer );
|
|
|
|
|
|
|
|
dwg->SetPolyPoints( pts );
|
2023-03-30 11:49:23 +00:00
|
|
|
dwg->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
|
|
|
|
dwg->Move( aFootprint->GetPosition() );
|
2023-05-29 14:28:48 +00:00
|
|
|
dwg->GetPolyShape().Inflate( p.width.ToPcbUnits() / 2,
|
2023-10-05 07:34:24 +00:00
|
|
|
CORNER_STRATEGY::ALLOW_ACUTE_CORNERS, ARC_HIGH_DEF );
|
2020-04-01 08:48:23 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packageCircle( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2020-08-04 14:57:57 +00:00
|
|
|
ECIRCLE e( aTree );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2020-04-01 09:22:32 +00:00
|
|
|
int width = e.width.ToPcbUnits();
|
|
|
|
int radius = e.radius.ToPcbUnits();
|
|
|
|
|
2020-08-04 14:57:57 +00:00
|
|
|
if( e.layer == EAGLE_LAYER::TRESTRICT
|
|
|
|
|| e.layer == EAGLE_LAYER::BRESTRICT
|
|
|
|
|| e.layer == EAGLE_LAYER::VRESTRICT )
|
2019-01-05 22:12:48 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
ZONE* zone = new ZONE( aFootprint );
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( zone, ADD_MODE::APPEND );
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2020-04-23 14:21:29 +00:00
|
|
|
setKeepoutSettingsToZone( zone, e.layer );
|
2020-04-01 09:22:32 +00:00
|
|
|
|
2022-01-18 02:20:36 +00:00
|
|
|
// approximate circle as polygon
|
|
|
|
VECTOR2I center( kicad_x( e.x ), kicad_y( e.y ) );
|
|
|
|
int outlineRadius = radius + ( width / 2 );
|
|
|
|
int segsInCircle = GetArcToSegmentCount( outlineRadius, ARC_HIGH_DEF, FULL_CIRCLE );
|
|
|
|
EDA_ANGLE delta = ANGLE_360 / segsInCircle;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-01-18 02:20:36 +00:00
|
|
|
for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
|
2020-04-01 09:22:32 +00:00
|
|
|
{
|
2022-01-05 02:23:11 +00:00
|
|
|
VECTOR2I rotatedPoint( outlineRadius, 0 );
|
2022-01-18 02:20:36 +00:00
|
|
|
RotatePoint( rotatedPoint, angle );
|
2020-04-01 09:22:32 +00:00
|
|
|
zone->AppendCorner( center + rotatedPoint, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( width > 0 )
|
|
|
|
{
|
|
|
|
zone->NewHole();
|
|
|
|
int innerRadius = radius - ( width / 2 );
|
2022-01-18 02:20:36 +00:00
|
|
|
segsInCircle = GetArcToSegmentCount( innerRadius, ARC_HIGH_DEF, FULL_CIRCLE );
|
|
|
|
delta = ANGLE_360 / segsInCircle;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-01-18 02:20:36 +00:00
|
|
|
for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += delta )
|
2020-04-01 09:22:32 +00:00
|
|
|
{
|
2022-01-05 02:23:11 +00:00
|
|
|
VECTOR2I rotatedPoint( innerRadius, 0 );
|
2022-01-18 02:20:36 +00:00
|
|
|
RotatePoint( rotatedPoint, angle );
|
2020-04-01 09:22:32 +00:00
|
|
|
zone->AppendCorner( center + rotatedPoint, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE,
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE::GetDefaultHatchPitch(), true );
|
2013-11-04 02:09:28 +00:00
|
|
|
}
|
2020-04-01 09:22:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = kicad_layer( e.layer );
|
2020-11-13 01:12:36 +00:00
|
|
|
|
|
|
|
if( layer == UNDEFINED_LAYER )
|
|
|
|
{
|
2020-11-14 08:02:03 +00:00
|
|
|
wxLogMessage( wxString::Format( _( "Ignoring a circle since Eagle layer '%s' (%d) "
|
2020-11-13 01:12:36 +00:00
|
|
|
"was not mapped" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
eagle_layer_name( e.layer ), e.layer ) );
|
2020-10-09 16:58:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* gr = new PCB_SHAPE( aFootprint, SHAPE_T::CIRCLE );
|
2020-04-01 09:22:32 +00:00
|
|
|
|
2021-11-14 23:41:22 +00:00
|
|
|
// width == 0 means filled circle
|
2020-04-01 09:22:32 +00:00
|
|
|
if( width <= 0 )
|
|
|
|
{
|
|
|
|
width = radius;
|
|
|
|
radius = radius / 2;
|
2021-11-14 23:41:22 +00:00
|
|
|
gr->SetFilled( true );
|
2020-04-01 09:22:32 +00:00
|
|
|
}
|
2012-05-30 21:40:32 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->Add( gr );
|
2021-07-17 19:56:18 +00:00
|
|
|
gr->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
|
2020-04-01 09:22:32 +00:00
|
|
|
|
|
|
|
switch( (int) layer )
|
|
|
|
{
|
|
|
|
case UNDEFINED_LAYER:
|
|
|
|
layer = Cmts_User;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gr->SetLayer( layer );
|
2023-03-30 11:49:23 +00:00
|
|
|
gr->SetStart( VECTOR2I( kicad_x( e.x ), kicad_y( e.y ) ) );
|
|
|
|
gr->SetEnd( VECTOR2I( kicad_x( e.x ) + radius, kicad_y( e.y ) ) );
|
|
|
|
gr->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
|
|
|
|
gr->Move( aFootprint->GetPosition() );
|
2020-04-01 09:22:32 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packageHole( FOOTPRINT* aFootprint, wxXmlNode* aTree, bool aCenter ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2012-05-31 15:18:55 +00:00
|
|
|
EHOLE e( aTree );
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( e.drill.value == 0 )
|
|
|
|
return;
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
// we add a PAD_ATTRIB::NPTH pad to this footprint.
|
2020-11-13 01:12:36 +00:00
|
|
|
PAD* pad = new PAD( aFootprint );
|
|
|
|
aFootprint->Add( pad );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2022-04-02 18:07:16 +00:00
|
|
|
pad->SetKeepTopBottom( false ); // TODO: correct? This seems to be KiCad default on import
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::NPTH );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
|
|
|
// Mechanical purpose only:
|
|
|
|
// no offset, no net name, no pad name allowed
|
2022-01-11 00:49:49 +00:00
|
|
|
// pad->SetOffset( VECTOR2I( 0, 0 ) );
|
2021-08-23 23:10:21 +00:00
|
|
|
// pad->SetNumber( wxEmptyString );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I padpos( kicad_x( e.x ), kicad_y( e.y ) );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2018-09-09 03:40:24 +00:00
|
|
|
if( aCenter )
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->SetPosition( padpos );
|
2018-09-09 03:40:24 +00:00
|
|
|
pad->SetPosition( padpos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
pad->SetPosition( padpos + aFootprint->GetPosition() );
|
2018-09-09 03:40:24 +00:00
|
|
|
}
|
2012-05-31 15:18:55 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I sz( e.drill.ToPcbUnits(), e.drill.ToPcbUnits() );
|
2012-05-31 15:18:55 +00:00
|
|
|
|
|
|
|
pad->SetDrillSize( sz );
|
|
|
|
pad->SetSize( sz );
|
|
|
|
|
2018-09-06 05:52:21 +00:00
|
|
|
pad->SetLayerSet( LSET::AllCuMask().set( B_Mask ).set( F_Mask ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void EAGLE_PLUGIN::packageSMD( FOOTPRINT* aFootprint, wxXmlNode* aTree ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2018-03-13 12:37:30 +00:00
|
|
|
ESMD e( aTree );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = kicad_layer( e.layer );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( !IsCopperLayer( layer ) || e.dx.value == 0 || e.dy.value == 0 )
|
2012-05-24 15:00:59 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
PAD* pad = new PAD( aFootprint );
|
|
|
|
aFootprint->Add( pad );
|
2018-03-13 13:34:53 +00:00
|
|
|
transferPad( e, pad );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2022-04-02 18:07:16 +00:00
|
|
|
pad->SetKeepTopBottom( false ); // TODO: correct? This seems to be KiCad default on import
|
|
|
|
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECTANGLE );
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I padSize( e.dx.ToPcbUnits(), e.dy.ToPcbUnits() );
|
2018-03-13 13:42:01 +00:00
|
|
|
pad->SetSize( padSize );
|
2012-05-29 18:10:56 +00:00
|
|
|
pad->SetLayer( layer );
|
2012-06-05 04:39:37 +00:00
|
|
|
|
2018-03-13 12:37:30 +00:00
|
|
|
const LSET front( 3, F_Cu, F_Paste, F_Mask );
|
|
|
|
const LSET back( 3, B_Cu, B_Paste, B_Mask );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
if( layer == F_Cu )
|
|
|
|
pad->SetLayerSet( front );
|
|
|
|
else if( layer == B_Cu )
|
|
|
|
pad->SetLayerSet( back );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2018-03-14 09:06:40 +00:00
|
|
|
int minPadSize = std::min( padSize.x, padSize.y );
|
|
|
|
|
2018-03-13 10:57:43 +00:00
|
|
|
// Rounded rectangle pads
|
2021-07-19 23:56:05 +00:00
|
|
|
int roundRadius =
|
|
|
|
eagleClamp( m_rules->srMinRoundness * 2, (int) ( minPadSize * m_rules->srRoundness ),
|
|
|
|
m_rules->srMaxRoundness * 2 );
|
2018-03-14 09:06:40 +00:00
|
|
|
|
2020-01-24 17:28:09 +00:00
|
|
|
if( e.roundness || roundRadius > 0 )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2018-03-14 09:06:40 +00:00
|
|
|
double roundRatio = (double) roundRadius / minPadSize / 2.0;
|
|
|
|
|
2018-03-13 10:57:43 +00:00
|
|
|
// Eagle uses a different definition of roundness, hence division by 200
|
2018-03-14 09:06:40 +00:00
|
|
|
if( e.roundness )
|
|
|
|
roundRatio = std::fmax( *e.roundness / 200.0, roundRatio );
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::ROUNDRECT );
|
2018-03-14 09:06:40 +00:00
|
|
|
pad->SetRoundRectRadiusRatio( roundRatio );
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:18:55 +00:00
|
|
|
if( e.rot )
|
2022-01-13 13:45:48 +00:00
|
|
|
pad->SetOrientation( EDA_ANGLE( e.rot->degrees, DEGREES_T ) );
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2023-08-16 16:29:40 +00:00
|
|
|
// Eagle spokes are always '+'
|
|
|
|
pad->SetThermalSpokeAngle( ANGLE_0 );
|
2023-08-16 16:02:35 +00:00
|
|
|
|
2018-06-29 17:52:56 +00:00
|
|
|
pad->SetLocalSolderPasteMargin( -eagleClamp( m_rules->mlMinCreamFrame,
|
2021-07-19 23:56:05 +00:00
|
|
|
(int) ( m_rules->mvCreamFrame * minPadSize ),
|
|
|
|
m_rules->mlMaxCreamFrame ) );
|
2018-04-02 11:49:11 +00:00
|
|
|
|
2019-07-17 00:02:53 +00:00
|
|
|
// Solder mask
|
|
|
|
if( e.stop && *e.stop == false ) // enabled by default
|
|
|
|
{
|
|
|
|
if( layer == F_Cu )
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().set( F_Mask, false ) );
|
|
|
|
else if( layer == B_Cu )
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().set( B_Mask, false ) );
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:42:01 +00:00
|
|
|
// Solder paste (only for SMD pads)
|
2018-04-02 11:49:11 +00:00
|
|
|
if( e.cream && *e.cream == false ) // enabled by default
|
2018-03-14 08:55:03 +00:00
|
|
|
{
|
2018-04-02 11:49:11 +00:00
|
|
|
if( layer == F_Cu )
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().set( F_Paste, false ) );
|
|
|
|
else if( layer == B_Cu )
|
|
|
|
pad->SetLayerSet( pad->GetLayerSet().set( B_Paste, false ) );
|
2018-03-14 08:55:03 +00:00
|
|
|
}
|
2018-03-13 13:42:01 +00:00
|
|
|
}
|
2018-03-13 13:34:53 +00:00
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void EAGLE_PLUGIN::transferPad( const EPAD_COMMON& aEaglePad, PAD* aPad ) const
|
2018-03-13 13:34:53 +00:00
|
|
|
{
|
2022-04-09 13:33:01 +00:00
|
|
|
aPad->SetNumber( aEaglePad.name );
|
2018-03-13 13:34:53 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I padPos( kicad_x( aEaglePad.x ), kicad_y( aEaglePad.y ) );
|
2018-03-13 13:34:53 +00:00
|
|
|
|
2018-03-13 13:42:01 +00:00
|
|
|
// Solder mask
|
2022-01-05 01:42:27 +00:00
|
|
|
const VECTOR2I& padSize( aPad->GetSize() );
|
2018-03-14 08:55:03 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
aPad->SetLocalSolderMaskMargin(
|
|
|
|
eagleClamp( m_rules->mlMinStopFrame,
|
|
|
|
(int) ( m_rules->mvStopFrame * std::min( padSize.x, padSize.y ) ),
|
|
|
|
m_rules->mlMaxStopFrame ) );
|
2018-03-13 13:42:01 +00:00
|
|
|
|
2018-03-14 09:16:51 +00:00
|
|
|
// Solid connection to copper zones
|
|
|
|
if( aEaglePad.thermals && !*aEaglePad.thermals )
|
2019-12-28 00:55:11 +00:00
|
|
|
aPad->SetZoneConnection( ZONE_CONNECTION::FULL );
|
2018-03-14 09:16:51 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
FOOTPRINT* footprint = aPad->GetParentFootprint();
|
2020-11-13 11:17:15 +00:00
|
|
|
wxCHECK( footprint, /* void */ );
|
2022-01-01 06:04:08 +00:00
|
|
|
RotatePoint( padPos, footprint->GetOrientation() );
|
2020-11-13 11:17:15 +00:00
|
|
|
aPad->SetPosition( padPos + footprint->GetPosition() );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 09:44:56 +00:00
|
|
|
|
|
|
|
void EAGLE_PLUGIN::deleteTemplates()
|
|
|
|
{
|
2023-04-04 13:18:13 +00:00
|
|
|
for( const auto& [ name, footprint ] : m_templates )
|
|
|
|
{
|
|
|
|
footprint->SetParent( nullptr );
|
|
|
|
delete footprint;
|
|
|
|
}
|
2017-07-10 09:44:56 +00:00
|
|
|
|
|
|
|
m_templates.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-20 11:36:57 +00:00
|
|
|
void EAGLE_PLUGIN::loadClasses( wxXmlNode* aClasses )
|
|
|
|
{
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
|
|
|
m_xpath->push( "classes.class", "number" );
|
|
|
|
|
|
|
|
std::vector<ECLASS> eClasses;
|
|
|
|
wxXmlNode* classNode = aClasses->GetChildren();
|
|
|
|
|
|
|
|
while( classNode )
|
|
|
|
{
|
|
|
|
checkpoint();
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
ECLASS eClass( classNode );
|
|
|
|
std::shared_ptr<NETCLASS> netclass;
|
2021-09-20 11:36:57 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
if( eClass.name.CmpNoCase( wxT( "default" ) ) == 0 )
|
2021-09-20 11:36:57 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
netclass = bds.m_NetSettings->m_DefaultNetClass;
|
2021-09-20 11:36:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
netclass.reset( new NETCLASS( eClass.name ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
bds.m_NetSettings->m_NetClasses[ eClass.name ] = netclass;
|
2021-09-20 11:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
netclass->SetTrackWidth( INT_MAX );
|
|
|
|
netclass->SetViaDiameter( INT_MAX );
|
|
|
|
netclass->SetViaDrill( INT_MAX );
|
|
|
|
|
|
|
|
eClasses.emplace_back( eClass );
|
|
|
|
m_classMap[ eClass.number ] = netclass;
|
|
|
|
|
|
|
|
// Get next class
|
|
|
|
classNode = classNode->GetNext();
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
m_customRules = wxT( "(version 1)" );
|
2021-09-20 11:36:57 +00:00
|
|
|
|
|
|
|
for( ECLASS& eClass : eClasses )
|
|
|
|
{
|
|
|
|
for( std::pair<const wxString&, ECOORD> entry : eClass.clearanceMap )
|
|
|
|
{
|
2022-01-03 14:55:57 +00:00
|
|
|
if( m_classMap[ entry.first ] != nullptr )
|
|
|
|
{
|
|
|
|
wxString rule;
|
2022-02-05 02:06:25 +00:00
|
|
|
rule.Printf( wxT( "(rule \"class %s:%s\"\n"
|
|
|
|
" (condition \"A.NetClass == '%s' && B.NetClass == '%s'\")\n"
|
|
|
|
" (constraint clearance (min %smm)))\n" ),
|
2022-01-03 14:55:57 +00:00
|
|
|
eClass.number,
|
|
|
|
entry.first,
|
|
|
|
eClass.name,
|
|
|
|
m_classMap[ entry.first ]->GetName(),
|
2022-09-16 04:38:10 +00:00
|
|
|
EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, EDA_UNITS::MILLIMETRES, entry.second.ToPcbUnits() ) );
|
2022-01-03 14:55:57 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
m_customRules += wxT( "\n" ) + rule;
|
2022-01-03 14:55:57 +00:00
|
|
|
}
|
2021-09-20 11:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_xpath->pop(); // "classes.class"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
void EAGLE_PLUGIN::loadSignals( wxXmlNode* aSignals )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2018-05-18 16:14:54 +00:00
|
|
|
ZONES zones; // per net
|
2021-09-20 11:36:57 +00:00
|
|
|
int netCode = 1;
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "signals.signal", "name" );
|
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first signal and iterate
|
|
|
|
wxXmlNode* net = aSignals->GetChildren();
|
|
|
|
|
|
|
|
while( net )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
bool sawPad = false;
|
|
|
|
|
|
|
|
zones.clear();
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
const wxString& netName = escapeName( net->GetAttribute( "name" ) );
|
|
|
|
NETINFO_ITEM* netInfo = new NETINFO_ITEM( m_board, netName, netCode );
|
|
|
|
std::shared_ptr<NETCLASS> netclass;
|
2021-09-20 11:36:57 +00:00
|
|
|
|
|
|
|
if( net->HasAttribute( "class" ) )
|
|
|
|
{
|
2023-08-25 20:05:26 +00:00
|
|
|
auto netclassIt = m_classMap.find( net->GetAttribute( "class" ) );
|
2021-09-20 11:36:57 +00:00
|
|
|
|
2023-08-25 20:05:26 +00:00
|
|
|
if( netclassIt != m_classMap.end() )
|
|
|
|
{
|
|
|
|
m_board->GetDesignSettings().m_NetSettings->m_NetClassPatternAssignments.push_back(
|
|
|
|
{ std::make_unique<EDA_COMBINED_MATCHER>( netName, CTX_NETCLASS ),
|
|
|
|
netclassIt->second->GetName() } );
|
2022-08-14 11:03:18 +00:00
|
|
|
|
2023-08-25 20:05:26 +00:00
|
|
|
netInfo->SetNetClass( netclassIt->second );
|
2023-08-25 21:45:59 +00:00
|
|
|
netclass = netclassIt->second;
|
2023-08-25 20:05:26 +00:00
|
|
|
}
|
2021-09-20 11:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_board->Add( netInfo );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2017-12-19 12:32:07 +00:00
|
|
|
m_xpath->Value( netName.c_str() );
|
2012-06-02 17:07:30 +00:00
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Get the first net item and iterate
|
|
|
|
wxXmlNode* netItem = net->GetChildren();
|
|
|
|
|
2012-05-24 01:18:30 +00:00
|
|
|
// (contactref | polygon | wire | via)*
|
2017-04-07 11:40:34 +00:00
|
|
|
while( netItem )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
const wxString& itemName = netItem->GetName();
|
2017-12-14 09:37:32 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( itemName == wxT( "wire" ) )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "wire" );
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
EWIRE w( netItem );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_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
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start( kicad_x( w.x1 ), kicad_y( w.y1 ) );
|
2018-03-09 03:08:37 +00:00
|
|
|
double angle = 0.0;
|
2018-03-14 14:38:53 +00:00
|
|
|
double end_angle = 0.0;
|
|
|
|
double radius = 0.0;
|
2018-03-26 17:39:23 +00:00
|
|
|
double delta_angle = 0.0;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center;
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2017-10-17 08:18:54 +00:00
|
|
|
int width = w.width.ToPcbUnits();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
if( width < m_min_trace )
|
|
|
|
m_min_trace = width;
|
|
|
|
|
2021-09-20 11:36:57 +00:00
|
|
|
if( netclass && width < netclass->GetTrackWidth() )
|
|
|
|
netclass->SetTrackWidth( width );
|
|
|
|
|
2018-03-09 03:08:37 +00:00
|
|
|
if( w.curve )
|
|
|
|
{
|
2022-01-11 00:49:49 +00:00
|
|
|
center = ConvertArcCenter( VECTOR2I( kicad_x( w.x1 ), kicad_y( w.y1 ) ),
|
|
|
|
VECTOR2I( kicad_x( w.x2 ), kicad_y( w.y2 ) ),
|
2021-07-19 23:56:05 +00:00
|
|
|
*w.curve );
|
2018-03-09 03:08:37 +00:00
|
|
|
|
|
|
|
angle = DEG2RAD( *w.curve );
|
|
|
|
|
|
|
|
end_angle = atan2( kicad_y( w.y2 ) - center.y,
|
|
|
|
kicad_x( w.x2 ) - center.x );
|
|
|
|
|
|
|
|
radius = sqrt( pow( center.x - kicad_x( w.x1 ), 2 ) +
|
|
|
|
pow( center.y - kicad_y( w.y1 ), 2 ) );
|
2018-03-26 17:39:23 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
int segs = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF,
|
2022-01-14 15:34:41 +00:00
|
|
|
EDA_ANGLE( *w.curve, DEGREES_T ) );
|
2020-09-10 23:05:20 +00:00
|
|
|
delta_angle = angle / segs;
|
2018-03-09 03:08:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 17:39:23 +00:00
|
|
|
while( fabs( angle ) > fabs( delta_angle ) )
|
2018-03-09 03:08:37 +00:00
|
|
|
{
|
2018-03-14 14:38:53 +00:00
|
|
|
wxASSERT( radius > 0.0 );
|
2022-01-11 00:49:49 +00:00
|
|
|
VECTOR2I end( KiROUND( radius * cos( end_angle + angle ) + center.x ),
|
|
|
|
KiROUND( radius * sin( end_angle + angle ) + center.y ) );
|
2018-03-09 03:08:37 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* t = new PCB_TRACK( m_board );
|
2018-03-09 03:08:37 +00:00
|
|
|
|
|
|
|
t->SetPosition( start );
|
|
|
|
t->SetEnd( end );
|
|
|
|
t->SetWidth( width );
|
|
|
|
t->SetLayer( layer );
|
|
|
|
t->SetNetCode( netCode );
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
m_board->Add( t );
|
2018-03-09 03:08:37 +00:00
|
|
|
|
|
|
|
start = end;
|
2018-03-26 17:39:23 +00:00
|
|
|
angle -= delta_angle;
|
2018-03-09 03:08:37 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* t = new PCB_TRACK( m_board );
|
2018-03-09 03:08:37 +00:00
|
|
|
|
|
|
|
t->SetPosition( start );
|
2022-01-11 00:49:49 +00:00
|
|
|
t->SetEnd( VECTOR2I( kicad_x( w.x2 ), kicad_y( w.y2 ) ) );
|
2013-03-14 22:54:47 +00:00
|
|
|
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
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
m_board->Add( t );
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "via" ) )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "via" );
|
2017-04-07 11:40:34 +00:00
|
|
|
EVIA v( netItem );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2021-11-08 20:46:18 +00:00
|
|
|
if( v.layer_front_most > v.layer_back_most )
|
|
|
|
std::swap( v.layer_front_most, v.layer_back_most );
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer_front_most = kicad_layer( v.layer_front_most );
|
|
|
|
PCB_LAYER_ID layer_back_most = kicad_layer( v.layer_back_most );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2021-11-08 20:46:18 +00:00
|
|
|
if( IsCopperLayer( layer_front_most ) && IsCopperLayer( layer_back_most )
|
|
|
|
&& layer_front_most != layer_back_most )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
int kidiam;
|
|
|
|
int drillz = v.drill.ToPcbUnits();
|
|
|
|
PCB_VIA* via = new PCB_VIA( m_board );
|
2019-05-31 02:30:28 +00:00
|
|
|
m_board->Add( via );
|
2012-05-24 01:18:30 +00:00
|
|
|
|
2012-05-24 15:00:59 +00:00
|
|
|
if( v.diam )
|
|
|
|
{
|
2017-10-17 08:18:54 +00:00
|
|
|
kidiam = v.diam->ToPcbUnits();
|
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"
|
2019-05-17 12:38:03 +00:00
|
|
|
annulus = eagleClamp( 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
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
// make sure the via diameter respects the restring rules
|
2017-05-04 13:47:28 +00:00
|
|
|
|
|
|
|
if( !v.diam || via->GetWidth() <= via->GetDrill() )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
double annulus =
|
|
|
|
eagleClamp( m_rules->rlMinViaOuter,
|
|
|
|
(double) ( via->GetWidth() / 2 - via->GetDrill() ),
|
|
|
|
m_rules->rlMaxViaOuter );
|
2017-05-04 13:47:28 +00:00
|
|
|
via->SetWidth( drillz + 2 * annulus );
|
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2013-03-14 22:54:47 +00:00
|
|
|
if( kidiam < m_min_via )
|
|
|
|
m_min_via = kidiam;
|
|
|
|
|
2021-09-20 11:36:57 +00:00
|
|
|
if( netclass && kidiam < netclass->GetViaDiameter() )
|
|
|
|
netclass->SetViaDiameter( kidiam );
|
|
|
|
|
2020-05-04 19:08:42 +00:00
|
|
|
if( drillz < m_min_hole )
|
|
|
|
m_min_hole = drillz;
|
2013-03-14 22:54:47 +00:00
|
|
|
|
2021-09-20 11:36:57 +00:00
|
|
|
if( netclass && drillz < netclass->GetViaDrill() )
|
|
|
|
netclass->SetViaDrill( drillz );
|
|
|
|
|
2020-05-11 19:39:30 +00:00
|
|
|
if( ( kidiam - drillz ) / 2 < m_min_annulus )
|
|
|
|
m_min_annulus = ( kidiam - drillz ) / 2;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_front_most == F_Cu && layer_back_most == B_Cu )
|
2021-11-08 20:46:18 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::THROUGH );
|
2021-11-08 20:46:18 +00:00
|
|
|
}
|
|
|
|
/// This is, at best, a guess. Eagle doesn't seem to differentiate
|
|
|
|
/// between blind/buried vias that only go one layer and micro vias
|
|
|
|
/// so the user will need to clean up a bit
|
|
|
|
else if( v.layer_back_most - v.layer_front_most == 1 )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::MICROVIA );
|
2021-11-08 20:46:18 +00:00
|
|
|
}
|
2012-06-01 07:39:32 +00:00
|
|
|
else
|
2021-11-08 20:46:18 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
via->SetViaType( VIATYPE::BLIND_BURIED );
|
2021-11-08 20:46:18 +00:00
|
|
|
}
|
2012-06-01 07:39:32 +00:00
|
|
|
|
2022-01-11 00:49:49 +00:00
|
|
|
VECTOR2I pos( kicad_x( v.x ), kicad_y( v.y ) );
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2021-11-08 20:46:18 +00:00
|
|
|
via->SetLayerPair( layer_front_most, layer_back_most );
|
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
|
|
|
}
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->pop();
|
2012-05-24 01:18:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "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"/>
|
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
const wxString& reference = netItem->GetAttribute( "element" );
|
|
|
|
const wxString& pad = netItem->GetAttribute( "pad" );
|
|
|
|
wxString key = makeKey( reference, pad ) ;
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
m_pads_to_nets[ key ] = ENET( netCode, netName );
|
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
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
else if( itemName == wxT( "polygon" ) )
|
2012-05-24 01:18:30 +00:00
|
|
|
{
|
2012-06-02 17:07:30 +00:00
|
|
|
m_xpath->push( "polygon" );
|
2018-05-18 16:14:54 +00:00
|
|
|
auto* zone = loadPolygon( netItem );
|
2013-11-04 02:09:28 +00:00
|
|
|
|
2018-05-18 16:14:54 +00:00
|
|
|
if( zone )
|
2012-05-29 18:10:56 +00:00
|
|
|
{
|
2013-03-14 22:54:47 +00:00
|
|
|
zones.push_back( zone );
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
if( !zone->GetIsRuleArea() )
|
2018-05-18 16:14:54 +00:00
|
|
|
zone->SetNetCode( netCode );
|
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
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
netItem = netItem->GetNext();
|
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...
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : zones )
|
2020-02-20 12:11:04 +00:00
|
|
|
zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2013-03-14 22:54:47 +00:00
|
|
|
|
|
|
|
// therefore omit this signal/net.
|
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +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
|
|
|
netCode++;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
// Get next signal
|
|
|
|
net = net->GetNext();
|
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
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
std::map<wxString, PCB_LAYER_ID> EAGLE_PLUGIN::DefaultLayerMappingCallback(
|
|
|
|
const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
|
|
|
|
{
|
|
|
|
std::map<wxString, PCB_LAYER_ID> layer_map;
|
|
|
|
|
|
|
|
for ( const INPUT_LAYER_DESC& layer : aInputLayerDescriptionVector )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layerId = std::get<0>( defaultKicadLayer( eagle_layer_id( layer.Name ) ) );
|
|
|
|
layer_map.emplace( layer.Name, layerId );
|
|
|
|
}
|
|
|
|
|
|
|
|
return layer_map;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-08-21 18:56:04 +00:00
|
|
|
void EAGLE_PLUGIN::mapEagleLayersToKicad( bool aIsLibraryCache )
|
2020-10-09 16:58:21 +00:00
|
|
|
{
|
|
|
|
std::vector<INPUT_LAYER_DESC> inputDescs;
|
|
|
|
|
2020-11-15 21:41:38 +00:00
|
|
|
for ( const std::pair<const int, ELAYER>& layerPair : m_eagleLayers )
|
2020-10-09 16:58:21 +00:00
|
|
|
{
|
|
|
|
const ELAYER& eLayer = layerPair.second;
|
|
|
|
|
|
|
|
INPUT_LAYER_DESC layerDesc;
|
|
|
|
std::tie( layerDesc.AutoMapLayer, layerDesc.PermittedLayers, layerDesc.Required ) =
|
2022-08-21 18:56:04 +00:00
|
|
|
defaultKicadLayer( eLayer.number, aIsLibraryCache );
|
2020-11-15 21:41:38 +00:00
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
if( layerDesc.AutoMapLayer == UNDEFINED_LAYER )
|
|
|
|
continue; // Ignore unused copper layers
|
2020-11-15 21:41:38 +00:00
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
layerDesc.Name = eLayer.name;
|
|
|
|
|
|
|
|
inputDescs.push_back( layerDesc );
|
|
|
|
}
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( m_progressReporter && dynamic_cast<wxWindow*>( m_progressReporter ) )
|
|
|
|
dynamic_cast<wxWindow*>( m_progressReporter )->Hide();
|
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
m_layer_map = m_layer_mapping_handler( inputDescs );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
if( m_progressReporter && dynamic_cast<wxWindow*>( m_progressReporter ))
|
|
|
|
dynamic_cast<wxWindow*>( m_progressReporter )->Show();
|
2020-10-09 16:58:21 +00:00
|
|
|
}
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID EAGLE_PLUGIN::kicad_layer( int aEagleLayer ) const
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2020-10-09 16:58:21 +00:00
|
|
|
auto result = m_layer_map.find( eagle_layer_name( aEagleLayer ) );
|
|
|
|
return result == m_layer_map.end() ? UNDEFINED_LAYER : result->second;
|
|
|
|
}
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-08-21 18:56:04 +00:00
|
|
|
std::tuple<PCB_LAYER_ID, LSET, bool> EAGLE_PLUGIN::defaultKicadLayer( int aEagleLayer,
|
|
|
|
bool aIsLibraryCache ) const
|
2020-10-09 16:58:21 +00:00
|
|
|
{
|
2012-05-24 15:00:59 +00:00
|
|
|
// eagle copper layer:
|
2019-01-06 16:43:12 +00:00
|
|
|
if( aEagleLayer >= 1 && aEagleLayer < int( arrayDim( m_cu_map ) ) )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2020-10-09 16:58:21 +00:00
|
|
|
LSET copperLayers;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
for( int copperLayer : m_cu_map )
|
|
|
|
{
|
|
|
|
if( copperLayer >= 0 )
|
|
|
|
copperLayers[copperLayer] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { PCB_LAYER_ID( m_cu_map[aEagleLayer] ), copperLayers, true };
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
int kiLayer = UNSELECTED_LAYER;
|
|
|
|
bool required = false;
|
|
|
|
LSET permittedLayers;
|
|
|
|
|
|
|
|
permittedLayers.set();
|
|
|
|
|
|
|
|
// translate non-copper eagle layer to pcbnew layer
|
|
|
|
switch( aEagleLayer )
|
2012-05-22 17:51:18 +00:00
|
|
|
{
|
2020-10-09 16:58:21 +00:00
|
|
|
// Eagle says "Dimension" layer, but it's for board perimeter
|
|
|
|
case EAGLE_LAYER::DIMENSION:
|
|
|
|
kiLayer = Edge_Cuts;
|
|
|
|
required = true;
|
|
|
|
permittedLayers = LSET( 1, Edge_Cuts );
|
|
|
|
break;
|
2017-11-13 19:39:32 +00:00
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
case EAGLE_LAYER::TPLACE:
|
|
|
|
kiLayer = F_SilkS;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BPLACE:
|
|
|
|
kiLayer = B_SilkS;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::TNAMES:
|
|
|
|
kiLayer = F_SilkS;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BNAMES:
|
|
|
|
kiLayer = B_SilkS;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::TVALUES:
|
|
|
|
kiLayer = F_Fab;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BVALUES:
|
|
|
|
kiLayer = B_Fab;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::TSTOP:
|
|
|
|
kiLayer = F_Mask;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BSTOP:
|
|
|
|
kiLayer = B_Mask;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::TCREAM:
|
|
|
|
kiLayer = F_Paste;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BCREAM:
|
|
|
|
kiLayer = B_Paste;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::TFINISH:
|
|
|
|
kiLayer = F_Mask;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BFINISH:
|
|
|
|
kiLayer = B_Mask;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::TGLUE:
|
|
|
|
kiLayer = F_Adhes;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BGLUE:
|
|
|
|
kiLayer = B_Adhes;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::DOCUMENT:
|
|
|
|
kiLayer = Cmts_User;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::REFERENCELC:
|
|
|
|
kiLayer = Cmts_User;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::REFERENCELS:
|
|
|
|
kiLayer = Cmts_User;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Packages show the future chip pins on SMD parts using layer 51.
|
|
|
|
// This is an area slightly smaller than the PAD/SMD copper area.
|
2020-11-13 15:15:52 +00:00
|
|
|
// Carry those visual aids into the FOOTPRINT on the fabrication layer,
|
2020-10-09 16:58:21 +00:00
|
|
|
// not silkscreen. This is perhaps not perfect, but there is not a lot
|
|
|
|
// of other suitable paired layers
|
|
|
|
case EAGLE_LAYER::TDOCU:
|
|
|
|
kiLayer = F_Fab;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BDOCU:
|
|
|
|
kiLayer = B_Fab;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// these layers are defined as user layers. put them on ECO layers
|
|
|
|
case EAGLE_LAYER::USERLAYER1:
|
|
|
|
kiLayer = Eco1_User;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::USERLAYER2:
|
|
|
|
kiLayer = Eco2_User;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// these will also appear in the ratsnest, so there's no need for a warning
|
|
|
|
case EAGLE_LAYER::UNROUTED:
|
|
|
|
kiLayer = Dwgs_User;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EAGLE_LAYER::TKEEPOUT:
|
|
|
|
kiLayer = F_CrtYd;
|
|
|
|
break;
|
|
|
|
case EAGLE_LAYER::BKEEPOUT:
|
|
|
|
kiLayer = B_CrtYd;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EAGLE_LAYER::MILLING:
|
|
|
|
case EAGLE_LAYER::TTEST:
|
|
|
|
case EAGLE_LAYER::BTEST:
|
|
|
|
case EAGLE_LAYER::HOLES:
|
|
|
|
default:
|
2022-08-21 18:56:04 +00:00
|
|
|
if( aIsLibraryCache )
|
2022-08-22 13:11:14 +00:00
|
|
|
kiLayer = UNDEFINED_LAYER;
|
2022-08-21 18:56:04 +00:00
|
|
|
else
|
|
|
|
kiLayer = UNSELECTED_LAYER;
|
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
break;
|
2012-05-22 17:51:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
return { PCB_LAYER_ID( kiLayer ), permittedLayers, required };
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-14 09:37:32 +00:00
|
|
|
const wxString& EAGLE_PLUGIN::eagle_layer_name( int aLayer ) const
|
2017-10-18 16:02:36 +00:00
|
|
|
{
|
2017-12-14 09:37:32 +00:00
|
|
|
static const wxString unknown( "unknown" );
|
2017-10-18 16:02:36 +00:00
|
|
|
auto it = m_eagleLayers.find( aLayer );
|
|
|
|
return it == m_eagleLayers.end() ? unknown : it->second.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-09 16:58:21 +00:00
|
|
|
int EAGLE_PLUGIN::eagle_layer_id( const wxString& aLayerName ) const
|
|
|
|
{
|
|
|
|
static const int unknown = -1;
|
|
|
|
auto it = m_eagleLayersIds.find( aLayerName );
|
|
|
|
return it == m_eagleLayersIds.end() ? unknown : it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbbox = m_board->GetBoardEdgesBoundingBox();
|
2013-11-02 00:24:38 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-01-11 00:49:49 +00:00
|
|
|
m_board->Move( VECTOR2I( 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
|
|
|
{
|
2018-03-02 23:44:27 +00:00
|
|
|
// File hasn't been loaded yet.
|
|
|
|
if( aPath.IsEmpty() )
|
|
|
|
return wxDateTime::Now();
|
2013-12-24 19:09:41 +00:00
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
wxFileName fn( aPath );
|
2013-09-22 00:28:02 +00:00
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
if( fn.IsFileReadable() )
|
|
|
|
return fn.GetModificationTime();
|
|
|
|
else
|
|
|
|
return wxDateTime( 0.0 );
|
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.
|
2018-03-02 23:44:27 +00:00
|
|
|
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
|
|
|
{
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlNode* doc;
|
2013-01-02 04:05:48 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2017-07-10 09:44:56 +00:00
|
|
|
deleteTemplates();
|
2013-01-02 04:05:48 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2017-04-07 11:40:34 +00:00
|
|
|
// Load the document
|
|
|
|
wxFileName fn( filename );
|
2021-05-03 23:39:56 +00:00
|
|
|
wxFFileInputStream stream( fn.GetFullPath() );
|
|
|
|
wxXmlDocument xmlDocument;
|
2017-04-07 11:40:34 +00:00
|
|
|
|
2021-05-03 23:39:56 +00:00
|
|
|
if( !stream.IsOk() || !xmlDocument.Load( stream ) )
|
2021-06-28 23:44:07 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'." ),
|
2017-04-07 11:40:34 +00:00
|
|
|
fn.GetFullPath() ) );
|
2021-06-28 23:44:07 +00:00
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
|
|
|
|
doc = xmlDocument.GetRoot();
|
|
|
|
|
|
|
|
wxXmlNode* drawing = MapChildren( doc )["drawing"];
|
|
|
|
NODE_MAP drawingChildren = MapChildren( drawing );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
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" );
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlNode* layers = drawingChildren["layers"];
|
2013-03-13 16:38:54 +00:00
|
|
|
loadLayerDefs( layers );
|
2022-08-21 18:56:04 +00:00
|
|
|
mapEagleLayersToKicad( true );
|
2013-03-13 16:38:54 +00:00
|
|
|
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" );
|
2017-04-07 11:40:34 +00:00
|
|
|
wxXmlNode* library = drawingChildren["library"];
|
2021-07-19 23:56:05 +00:00
|
|
|
loadLibrary( library, nullptr );
|
2013-01-02 04:05:48 +00:00
|
|
|
m_xpath->pop();
|
|
|
|
|
|
|
|
m_mod_time = modtime;
|
|
|
|
}
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
2017-04-07 11:40:34 +00:00
|
|
|
catch(...){}
|
|
|
|
// TODO: Handle exceptions
|
|
|
|
// catch( file_parser_error fpe )
|
|
|
|
// {
|
|
|
|
// // 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 )
|
|
|
|
// {
|
|
|
|
// string errmsg = pte.what();
|
|
|
|
//
|
|
|
|
// errmsg += " @\n";
|
|
|
|
// errmsg += m_xpath->Contents();
|
|
|
|
//
|
|
|
|
// THROW_IO_ERROR( errmsg );
|
|
|
|
// }
|
2012-05-24 15:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
bool aBestEfforts, const STRING_UTF8_MAP* aProperties )
|
2012-05-24 15:00:59 +00:00
|
|
|
{
|
2019-08-31 14:18:27 +00:00
|
|
|
wxString errorMsg;
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
init( aProperties );
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
errorMsg = ioe.What();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some of the files may have been parsed correctly so we want to add the valid files to
|
|
|
|
// the library.
|
2012-05-24 15:00:59 +00:00
|
|
|
|
2023-04-04 13:18:13 +00:00
|
|
|
for( const auto& [ name, footprint ] : m_templates )
|
|
|
|
aFootprintNames.Add( name );
|
2019-08-31 14:18:27 +00:00
|
|
|
|
|
|
|
if( !errorMsg.IsEmpty() && !aBestEfforts )
|
|
|
|
THROW_IO_ERROR( errorMsg );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
|
2021-07-19 23:56:05 +00:00
|
|
|
const wxString& aFootprintName, bool aKeepUUID,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2012-05-20 13:14:46 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
init( aProperties );
|
|
|
|
cacheLib( aLibraryPath );
|
2023-04-04 13:18:13 +00:00
|
|
|
auto it = m_templates.find( aFootprintName );
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( it == m_templates.end() )
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2013-01-02 04:05:48 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
// Return a copy of the template
|
2020-12-04 12:14:07 +00:00
|
|
|
FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate();
|
|
|
|
copy->SetParent( nullptr );
|
|
|
|
return copy;
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void EAGLE_PLUGIN::FootprintLibOptions( STRING_UTF8_MAP* aListToAppendTo ) const
|
2013-11-20 16:35:03 +00:00
|
|
|
{
|
2013-11-26 17:06:54 +00:00
|
|
|
PLUGIN::FootprintLibOptions( aListToAppendTo );
|
2012-05-20 13:14:46 +00:00
|
|
|
}
|
2023-01-29 19:09:12 +00:00
|
|
|
|
|
|
|
int EAGLE_PLUGIN::getMinimumCopperLayerCount() const
|
|
|
|
{
|
|
|
|
int minLayerCount = 2;
|
|
|
|
|
|
|
|
std::map<wxString, PCB_LAYER_ID>::const_iterator it;
|
|
|
|
|
|
|
|
for( it = m_layer_map.begin(); it != m_layer_map.end(); ++it )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layerId = it->second;
|
|
|
|
|
|
|
|
if( IsCopperLayer( layerId ) && layerId != F_Cu && layerId != B_Cu
|
|
|
|
&& ( layerId + 2 ) > minLayerCount )
|
|
|
|
minLayerCount = layerId + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure the copper layers count is a multiple of 2
|
|
|
|
// Pcbnew does not like boards with odd layers count
|
|
|
|
// (these boards cannot exist. they actually have a even layers count)
|
|
|
|
if( ( minLayerCount % 2 ) != 0 )
|
|
|
|
minLayerCount++;
|
|
|
|
|
|
|
|
return minLayerCount;
|
2023-02-11 02:54:40 +00:00
|
|
|
}
|