2016-09-02 10:08:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2021-09-22 11:19:29 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-09-02 10:08:40 +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
|
|
|
|
*/
|
|
|
|
|
2019-04-15 17:09:27 +00:00
|
|
|
#include "kicadpad.h"
|
|
|
|
|
|
|
|
#include <sexpr/sexpr.h>
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <wx/log.h>
|
2019-04-15 17:09:27 +00:00
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
|
|
static const char bad_pad[] = "* corrupt module in PCB file; bad pad";
|
|
|
|
|
|
|
|
|
|
|
|
KICADPAD::KICADPAD()
|
|
|
|
{
|
|
|
|
m_rotation = 0.0;
|
|
|
|
m_thruhole = false;
|
|
|
|
m_drill.oval = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KICADPAD::~KICADPAD()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
bool KICADPAD::Read( const SEXPR::SEXPR* aEntry )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
|
|
|
// form: ( pad N thru_hole shape (at x y {r}) (size x y) (drill {oval} x {y}) (layers X X X) )
|
|
|
|
int nchild = aEntry->GetNumberOfChildren();
|
|
|
|
|
|
|
|
if( nchild < 2 )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
2017-02-01 03:49:48 +00:00
|
|
|
ostr << bad_pad << " (line " << aEntry->GetLineNumber() << ")";
|
2022-02-08 21:47:43 +00:00
|
|
|
wxLogMessage( wxT( "%s\n" ), ostr.str().c_str() );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SEXPR::SEXPR* child;
|
|
|
|
|
|
|
|
for( int i = 1; i < nchild; ++i )
|
|
|
|
{
|
|
|
|
child = aEntry->GetChild( i );
|
|
|
|
|
|
|
|
if( child->IsSymbol() &&
|
|
|
|
( child->GetSymbol() == "thru_hole" || child->GetSymbol() == "np_thru_hole" ) )
|
|
|
|
{
|
|
|
|
m_thruhole = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( child->IsList() )
|
|
|
|
{
|
|
|
|
std::string name = child->GetChild( 0 )->GetSymbol();
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if( name == "drill" )
|
2016-09-14 08:37:11 +00:00
|
|
|
{
|
|
|
|
// ignore any drill info for SMD pads
|
|
|
|
if( m_thruhole )
|
|
|
|
ret = parseDrill( child );
|
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
else if( name == "at" )
|
2016-09-14 08:37:11 +00:00
|
|
|
{
|
2016-09-02 10:08:40 +00:00
|
|
|
ret = Get2DPositionAndRotation( child, m_position, m_rotation );
|
2016-09-14 08:37:11 +00:00
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
if( !ret )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
bool KICADPAD::parseDrill( const SEXPR::SEXPR* aDrill )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
|
|
|
// form: (drill {oval} X {Y})
|
2021-10-17 16:30:03 +00:00
|
|
|
const char bad_drill[] = "* corrupt pad in PCB file; bad drill";
|
2016-09-02 10:08:40 +00:00
|
|
|
int nchild = aDrill->GetNumberOfChildren();
|
|
|
|
|
|
|
|
if( nchild < 2 )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
2017-02-01 03:49:48 +00:00
|
|
|
ostr << bad_drill << " (line " << aDrill->GetLineNumber() << ")";
|
2022-02-08 21:47:43 +00:00
|
|
|
wxLogMessage( wxT( "%s\n" ), ostr.str().c_str() );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SEXPR::SEXPR* child = aDrill->GetChild( 1 );
|
|
|
|
int idx = 1;
|
|
|
|
m_drill.oval = false;
|
|
|
|
|
|
|
|
if( child->IsSymbol() )
|
|
|
|
{
|
2021-09-19 19:44:54 +00:00
|
|
|
if( child->GetSymbol() == "oval" )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2021-10-17 16:30:03 +00:00
|
|
|
m_drill.oval = true;
|
2016-09-02 10:08:40 +00:00
|
|
|
child = aDrill->GetChild( ++idx );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
2017-02-01 03:49:48 +00:00
|
|
|
ostr << bad_drill << " (line " << child->GetLineNumber();
|
|
|
|
ostr << ") (unexpected symbol: ";
|
2016-09-02 10:08:40 +00:00
|
|
|
ostr << child->GetSymbol() << "), nchild = " << nchild;
|
2022-02-08 21:47:43 +00:00
|
|
|
wxLogMessage( wxT( "%s\n" ), ostr.str().c_str() );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double x;
|
|
|
|
|
|
|
|
if( child->IsDouble() )
|
|
|
|
x = child->GetDouble();
|
|
|
|
else if( child->IsInteger() )
|
|
|
|
x = (double) child->GetInteger();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
2017-02-01 03:49:48 +00:00
|
|
|
ostr << bad_drill << " (line " << child->GetLineNumber();
|
|
|
|
ostr << ") (did not find X size)";
|
2022-02-08 21:47:43 +00:00
|
|
|
wxLogMessage( wxT( "%s\n" ), ostr.str().c_str() );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_drill.size.x = x;
|
|
|
|
m_drill.size.y = x;
|
|
|
|
|
|
|
|
if( ++idx == nchild || !m_drill.oval )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( int i = idx; i < nchild; ++i )
|
|
|
|
{
|
|
|
|
child = aDrill->GetChild( i );
|
|
|
|
|
2021-09-22 11:19:29 +00:00
|
|
|
// NOTE: the Offset of the copper pad is stored in the drill string but since the copper
|
|
|
|
// is not needed in the MCAD model the offset is simply ignored.
|
2016-09-02 10:08:40 +00:00
|
|
|
if( !child->IsList() )
|
|
|
|
{
|
|
|
|
double y;
|
|
|
|
|
|
|
|
if( child->IsDouble() )
|
|
|
|
y = child->GetDouble();
|
|
|
|
else if( child->IsInteger() )
|
|
|
|
y = (double) child->GetInteger();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
2017-02-01 03:49:48 +00:00
|
|
|
ostr << bad_drill << " (line " << child->GetLineNumber();
|
|
|
|
ostr << ") (did not find Y size)";
|
2022-02-08 21:47:43 +00:00
|
|
|
wxLogMessage( wxT( "%s\n" ), ostr.str().c_str() );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_drill.size.y = y;
|
2021-09-19 19:44:54 +00:00
|
|
|
|
|
|
|
if( m_drill.size.y != m_drill.size.x )
|
|
|
|
m_drill.oval = true;
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|