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>
|
2020-09-03 21:59:03 +00:00
|
|
|
* Copyright (C) 2016-2020 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 "kicadmodel.h"
|
|
|
|
|
|
|
|
#include <sexpr/sexpr.h>
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
2017-11-08 09:56:57 +00:00
|
|
|
KICADMODEL::KICADMODEL() :
|
2020-09-03 21:59:03 +00:00
|
|
|
m_hide( false ),
|
2017-11-08 09:56:57 +00:00
|
|
|
m_scale( 1.0, 1.0, 1.0 ),
|
|
|
|
m_offset( 0.0, 0.0, 0.0 ),
|
|
|
|
m_rotation( 0.0, 0.0, 0.0 )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KICADMODEL::~KICADMODEL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KICADMODEL::Read( SEXPR::SEXPR* aEntry )
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
ostr << "* invalid model entry";
|
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 = aEntry->GetChild( 1 );
|
|
|
|
|
|
|
|
if( child->IsSymbol() )
|
2020-09-03 21:59:03 +00:00
|
|
|
{
|
2016-09-02 10:08:40 +00:00
|
|
|
m_modelname = child->GetSymbol();
|
2020-09-03 21:59:03 +00:00
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
else if( child->IsString() )
|
2020-09-03 21:59:03 +00:00
|
|
|
{
|
2016-09-02 10:08:40 +00:00
|
|
|
m_modelname = child->GetString();
|
2020-09-03 21:59:03 +00:00
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << "* invalid model entry; invalid path";
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = 2; i < nchild; ++i )
|
|
|
|
{
|
|
|
|
child = aEntry->GetChild( i );
|
|
|
|
|
2020-09-03 21:59:03 +00:00
|
|
|
if( child->IsSymbol() && child->GetSymbol() == "hide" )
|
2017-11-26 21:20:02 +00:00
|
|
|
{
|
2020-09-03 21:59:03 +00:00
|
|
|
m_hide = true;
|
2017-11-26 21:20:02 +00:00
|
|
|
}
|
2020-09-03 21:59:03 +00:00
|
|
|
else if( child->IsList() )
|
2017-11-26 21:20:02 +00:00
|
|
|
{
|
2020-09-03 21:59:03 +00:00
|
|
|
std::string name = child->GetChild( 0 )->GetSymbol();
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version 4.x and prior used 'at' parameter,
|
|
|
|
* which was specified in inches.
|
|
|
|
*/
|
|
|
|
if( name == "at" )
|
|
|
|
{
|
|
|
|
ret = Get3DCoordinate( child->GetChild( 1 ), m_offset );
|
|
|
|
|
|
|
|
if( ret )
|
|
|
|
{
|
|
|
|
m_offset.x *= 25.4f;
|
|
|
|
m_offset.y *= 25.4f;
|
|
|
|
m_offset.z *= 25.4f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* From 5.x onwards, 3D model is provided in 'offset',
|
|
|
|
* which is in millimetres
|
|
|
|
*/
|
|
|
|
else if( name == "offset" )
|
|
|
|
{
|
|
|
|
ret = Get3DCoordinate( child->GetChild( 1 ), m_offset );
|
|
|
|
}
|
|
|
|
else if( name == "scale" )
|
|
|
|
{
|
|
|
|
ret = Get3DCoordinate( child->GetChild( 1 ), m_scale );
|
|
|
|
}
|
|
|
|
else if( name == "rotate" )
|
|
|
|
{
|
|
|
|
ret = GetXYZRotation( child->GetChild( 1 ), m_rotation );
|
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2020-09-03 21:59:03 +00:00
|
|
|
if( !ret )
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|