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) 2020-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 "kicadpcb.h"
|
|
|
|
|
|
|
|
#include "kicadcurve.h"
|
2020-11-14 19:16:42 +00:00
|
|
|
#include "kicadfootprint.h"
|
2019-04-15 17:09:27 +00:00
|
|
|
#include "oce_utils.h"
|
|
|
|
|
|
|
|
#include <sexpr/sexpr.h>
|
|
|
|
#include <sexpr/sexpr_parser.h>
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <wx/filename.h>
|
2021-06-14 15:53:54 +00:00
|
|
|
#include <wx/wxcrtvararg.h>
|
2019-04-15 17:09:27 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2016-09-02 10:08:40 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-12 21:41:18 +00:00
|
|
|
KICADPCB::KICADPCB( const wxString& aPcbName )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2022-02-09 18:33:52 +00:00
|
|
|
m_resolver.Set3DConfigDir( wxEmptyString );
|
2016-09-02 10:08:40 +00:00
|
|
|
m_thickness = 1.6;
|
2018-10-02 06:34:07 +00:00
|
|
|
m_pcb_model = nullptr;
|
2018-06-19 08:14:10 +00:00
|
|
|
m_minDistance = MIN_DISTANCE;
|
2016-09-04 07:08:56 +00:00
|
|
|
m_useGridOrigin = false;
|
|
|
|
m_useDrillOrigin = false;
|
|
|
|
m_hasGridOrigin = false;
|
|
|
|
m_hasDrillOrigin = false;
|
2021-09-12 21:41:18 +00:00
|
|
|
m_pcbName = aPcbName;
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KICADPCB::~KICADPCB()
|
|
|
|
{
|
2021-09-22 10:27:44 +00:00
|
|
|
for( KICADFOOTPRINT* i : m_footprints )
|
2016-09-02 10:08:40 +00:00
|
|
|
delete i;
|
|
|
|
|
2021-09-22 10:27:44 +00:00
|
|
|
for( KICADCURVE* i : m_curves )
|
2016-09-02 10:08:40 +00:00
|
|
|
delete i;
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
delete m_pcb_model;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KICADPCB::ReadFile( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
wxFileName fname( aFileName );
|
|
|
|
|
|
|
|
if( fname.GetExt() != "kicad_pcb" )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "expecting extension kicad_pcb, got %s\n" ),
|
2020-11-17 13:49:24 +00:00
|
|
|
fname.GetExt() ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !fname.FileExists() )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "No such file: %s\n" ), aFileName ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fname.Normalize();
|
2018-09-20 09:05:52 +00:00
|
|
|
m_filename = fname.GetFullPath();
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SEXPR::PARSER parser;
|
|
|
|
std::string infile( fname.GetFullPath().ToUTF8() );
|
2018-03-19 09:02:05 +00:00
|
|
|
std::unique_ptr<SEXPR::SEXPR> data( parser.ParseFromFile( infile ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-03-19 09:02:05 +00:00
|
|
|
if( !data )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "No data in file: %s\n" ), aFileName ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-19 09:02:05 +00:00
|
|
|
if( !parsePCB( data.get() ) )
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch( std::exception& e )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "error reading file: %s\n%s\n" ),
|
|
|
|
aFileName,
|
|
|
|
e.what() ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "unexpected exception while reading file: %s\n" ),
|
2020-11-17 13:49:24 +00:00
|
|
|
aFileName ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-11 07:23:11 +00:00
|
|
|
bool KICADPCB::WriteSTEP( const wxString& aFileName )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
if( m_pcb_model )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
return m_pcb_model->WriteSTEP( aFileName );
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SUPPORTS_IGES
|
2018-09-11 07:23:11 +00:00
|
|
|
bool KICADPCB::WriteIGES( const wxString& aFileName )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
if( m_pcb_model )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
return m_pcb_model->WriteIGES( aFileName );
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
bool KICADPCB::parsePCB( SEXPR::SEXPR* data )
|
|
|
|
{
|
|
|
|
if( NULL == data )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( data->IsList() )
|
|
|
|
{
|
|
|
|
size_t nc = data->GetNumberOfChildren();
|
|
|
|
SEXPR::SEXPR* child = data->GetChild( 0 );
|
|
|
|
std::string name = child->GetSymbol();
|
|
|
|
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
for( size_t i = 1; i < nc && result; ++i )
|
|
|
|
{
|
|
|
|
child = data->GetChild( i );
|
|
|
|
|
|
|
|
if( !child->IsList() )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d)\n" ),
|
2020-11-17 13:49:24 +00:00
|
|
|
child->GetLineNumber() ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string symname( child->GetChild( 0 )->GetSymbol() );
|
|
|
|
|
|
|
|
if( symname == "general" )
|
|
|
|
result = result && parseGeneral( child );
|
2016-09-04 07:08:56 +00:00
|
|
|
else if( symname == "setup" )
|
|
|
|
result = result && parseSetup( child );
|
2017-06-08 06:33:14 +00:00
|
|
|
else if( symname == "layers" )
|
|
|
|
result = result && parseLayers( child );
|
2016-09-02 10:08:40 +00:00
|
|
|
else if( symname == "module" )
|
|
|
|
result = result && parseModule( child );
|
2020-11-17 13:49:24 +00:00
|
|
|
else if( symname == "footprint" )
|
|
|
|
result = result && parseModule( child );
|
2016-09-02 10:08:40 +00:00
|
|
|
else if( symname == "gr_arc" )
|
|
|
|
result = result && parseCurve( child, CURVE_ARC );
|
|
|
|
else if( symname == "gr_line" )
|
|
|
|
result = result && parseCurve( child, CURVE_LINE );
|
2020-08-17 17:30:35 +00:00
|
|
|
else if( symname == "gr_rect" )
|
|
|
|
result = result && parseRect( child );
|
2021-02-25 17:49:32 +00:00
|
|
|
else if( symname == "gr_poly" )
|
|
|
|
result = result && parsePolygon( child );
|
2016-09-02 10:08:40 +00:00
|
|
|
else if( symname == "gr_circle" )
|
|
|
|
result = result && parseCurve( child, CURVE_CIRCLE );
|
2020-10-20 12:28:43 +00:00
|
|
|
else if( symname == "gr_curve" )
|
|
|
|
result = result && parseCurve( child, CURVE_BEZIER );
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "data is not a valid PCB file: %s\n" ), m_filename ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KICADPCB::parseGeneral( SEXPR::SEXPR* data )
|
|
|
|
{
|
|
|
|
size_t nc = data->GetNumberOfChildren();
|
|
|
|
SEXPR::SEXPR* child = NULL;
|
|
|
|
|
|
|
|
for( size_t i = 1; i < nc; ++i )
|
|
|
|
{
|
|
|
|
child = data->GetChild( i );
|
|
|
|
|
|
|
|
if( !child->IsList() )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d)\n" ),
|
2020-11-17 13:49:24 +00:00
|
|
|
child->GetLineNumber() ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-22 11:19:29 +00:00
|
|
|
// at the moment only the thickness is of interest in the general section
|
2016-09-02 10:08:40 +00:00
|
|
|
if( child->GetChild( 0 )->GetSymbol() != "thickness" )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_thickness = child->GetChild( 1 )->GetDouble();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d)\n"
|
|
|
|
"no PCB thickness specified in general section\n" ),
|
2020-11-17 13:49:24 +00:00
|
|
|
child->GetLineNumber() ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 06:33:14 +00:00
|
|
|
bool KICADPCB::parseLayers( SEXPR::SEXPR* data )
|
|
|
|
{
|
|
|
|
size_t nc = data->GetNumberOfChildren();
|
|
|
|
SEXPR::SEXPR* child = NULL;
|
|
|
|
|
2020-11-17 13:49:24 +00:00
|
|
|
// Read the layername and the corresponding layer id list:
|
2017-06-08 06:33:14 +00:00
|
|
|
for( size_t i = 1; i < nc; ++i )
|
|
|
|
{
|
|
|
|
child = data->GetChild( i );
|
|
|
|
|
|
|
|
if( !child->IsList() )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d)\n" ),
|
2020-11-17 13:49:24 +00:00
|
|
|
child->GetLineNumber() ) );
|
2017-06-08 06:33:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-12-18 14:11:32 +00:00
|
|
|
std::string ref;
|
2017-06-08 06:33:14 +00:00
|
|
|
|
2018-12-18 14:11:32 +00:00
|
|
|
if( child->GetChild( 1 )->IsSymbol() )
|
|
|
|
ref = child->GetChild( 1 )->GetSymbol();
|
|
|
|
else
|
|
|
|
ref = child->GetChild( 1 )->GetString();
|
|
|
|
|
|
|
|
m_layersNames[ref] = child->GetChild( 0 )->GetInteger();
|
2017-06-08 06:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:49:24 +00:00
|
|
|
|
2017-06-08 06:33:14 +00:00
|
|
|
int KICADPCB::GetLayerId( std::string& aLayerName )
|
|
|
|
{
|
|
|
|
int lid = -1;
|
|
|
|
auto item = m_layersNames.find( aLayerName );
|
|
|
|
|
|
|
|
if( item != m_layersNames.end() )
|
|
|
|
lid = item->second;
|
|
|
|
|
|
|
|
return lid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-04 07:08:56 +00:00
|
|
|
bool KICADPCB::parseSetup( SEXPR::SEXPR* data )
|
|
|
|
{
|
|
|
|
size_t nc = data->GetNumberOfChildren();
|
|
|
|
SEXPR::SEXPR* child = NULL;
|
|
|
|
|
|
|
|
for( size_t i = 1; i < nc; ++i )
|
|
|
|
{
|
|
|
|
child = data->GetChild( i );
|
|
|
|
|
|
|
|
if( !child->IsList() )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d)\n" ),
|
2021-09-22 11:19:29 +00:00
|
|
|
child->GetLineNumber() ) );
|
2016-09-04 07:08:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-22 11:19:29 +00:00
|
|
|
// at the moment only the Grid and Drill origins are of interest in the setup section
|
2016-09-04 07:08:56 +00:00
|
|
|
if( child->GetChild( 0 )->GetSymbol() == "grid_origin" )
|
|
|
|
{
|
|
|
|
if( child->GetNumberOfChildren() != 3 )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d): grid_origin has "
|
|
|
|
"%d children (expected: 3)\n" ),
|
2021-09-22 11:19:29 +00:00
|
|
|
child->GetLineNumber(),
|
|
|
|
child->GetNumberOfChildren() ) );
|
2016-09-04 07:08:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_gridOrigin.x = child->GetChild( 1 )->GetDouble();
|
|
|
|
m_gridOrigin.y = child->GetChild( 2 )->GetDouble();
|
|
|
|
m_hasGridOrigin = true;
|
|
|
|
}
|
|
|
|
else if( child->GetChild( 0 )->GetSymbol() == "aux_axis_origin" )
|
|
|
|
{
|
|
|
|
if( child->GetNumberOfChildren() != 3 )
|
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxString::Format( wxT( "corrupt PCB file (line %d): aux_axis_origin "
|
|
|
|
"has %d children (expected: 3)\n" ),
|
2021-09-22 11:19:29 +00:00
|
|
|
child->GetLineNumber(),
|
|
|
|
child->GetNumberOfChildren() ) );
|
2016-09-04 07:08:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_drillOrigin.x = child->GetChild( 1 )->GetDouble();
|
|
|
|
m_drillOrigin.y = child->GetChild( 2 )->GetDouble();
|
|
|
|
m_hasDrillOrigin = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
bool KICADPCB::parseModule( SEXPR::SEXPR* data )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
KICADFOOTPRINT* footprint = new KICADFOOTPRINT( this );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( !footprint->Read( data ) )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete footprint;
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_footprints.push_back( footprint );
|
2016-09-02 10:08:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-17 17:30:35 +00:00
|
|
|
bool KICADPCB::parseRect( SEXPR::SEXPR* data )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
KICADCURVE* rect = new KICADCURVE();
|
2020-08-17 17:30:35 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( !rect->Read( data, CURVE_LINE ) )
|
2020-08-17 17:30:35 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete rect;
|
2020-08-17 17:30:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reject any curves not on the Edge.Cuts layer
|
2020-11-14 21:21:54 +00:00
|
|
|
if( rect->GetLayer() != LAYER_EDGE )
|
2020-08-17 17:30:35 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete rect;
|
2020-08-17 17:30:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
KICADCURVE* top = new KICADCURVE( *rect );
|
|
|
|
KICADCURVE* right = new KICADCURVE( *rect );
|
|
|
|
KICADCURVE* bottom = new KICADCURVE( *rect );
|
|
|
|
KICADCURVE* left = new KICADCURVE( *rect );
|
|
|
|
delete rect;
|
2020-08-17 17:30:35 +00:00
|
|
|
|
2020-08-18 11:06:26 +00:00
|
|
|
top->m_end.y = right->m_start.y;
|
2020-08-17 17:30:35 +00:00
|
|
|
m_curves.push_back( top );
|
|
|
|
|
2020-08-18 11:06:26 +00:00
|
|
|
right->m_start.x = bottom->m_end.x;
|
2020-08-17 17:30:35 +00:00
|
|
|
m_curves.push_back( right );
|
|
|
|
|
2020-08-18 11:06:26 +00:00
|
|
|
bottom->m_start.y = left->m_end.y;
|
2020-08-17 17:30:35 +00:00
|
|
|
m_curves.push_back( bottom );
|
|
|
|
|
2020-08-18 11:06:26 +00:00
|
|
|
left->m_end.x = top->m_start.x;
|
2020-08-17 17:30:35 +00:00
|
|
|
m_curves.push_back( left );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-25 17:49:32 +00:00
|
|
|
bool KICADPCB::parsePolygon( SEXPR::SEXPR* data )
|
|
|
|
{
|
2022-02-05 16:15:10 +00:00
|
|
|
std::unique_ptr<KICADCURVE> poly = std::make_unique<KICADCURVE>();
|
2021-02-25 17:49:32 +00:00
|
|
|
|
|
|
|
if( !poly->Read( data, CURVE_POLYGON ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reject any curves not on the Edge.Cuts layer
|
|
|
|
if( poly->GetLayer() != LAYER_EDGE )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pts = poly->m_poly;
|
|
|
|
|
|
|
|
for( std::size_t ii = 1; ii < pts.size(); ++ii )
|
|
|
|
{
|
|
|
|
KICADCURVE* seg = new KICADCURVE();
|
|
|
|
seg->m_form = CURVE_LINE;
|
|
|
|
seg->m_layer = poly->GetLayer();
|
|
|
|
seg->m_start = pts[ii - 1];
|
|
|
|
seg->m_end = pts[ii];
|
|
|
|
m_curves.push_back( seg );
|
|
|
|
}
|
|
|
|
|
|
|
|
KICADCURVE* seg = new KICADCURVE();
|
|
|
|
seg->m_form = CURVE_LINE;
|
|
|
|
seg->m_layer = poly->GetLayer();
|
|
|
|
seg->m_start = pts.back();
|
|
|
|
seg->m_end = pts.front();
|
|
|
|
m_curves.push_back( seg );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-02 10:08:40 +00:00
|
|
|
bool KICADPCB::parseCurve( SEXPR::SEXPR* data, CURVE_TYPE aCurveType )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
KICADCURVE* curve = new KICADCURVE();
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( !curve->Read( data, aCurveType ) )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete curve;
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reject any curves not on the Edge.Cuts layer
|
2020-11-14 21:21:54 +00:00
|
|
|
if( curve->GetLayer() != LAYER_EDGE )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete curve;
|
2016-09-02 10:08:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_curves.push_back( curve );
|
2016-09-02 10:08:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 22:46:37 +00:00
|
|
|
bool KICADPCB::ComposePCB( bool aComposeVirtual, bool aSubstituteModels )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2018-10-02 06:34:07 +00:00
|
|
|
if( m_pcb_model )
|
2016-09-02 10:08:40 +00:00
|
|
|
return true;
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_footprints.empty() && m_curves.empty() )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxT( "Error: no PCB data (no footprint, no outline) to render\n" ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-04 07:08:56 +00:00
|
|
|
DOUBLET origin;
|
|
|
|
|
|
|
|
// Determine the coordinate system reference:
|
|
|
|
// Precedence of reference point is Drill Origin > Grid Origin > User Offset
|
|
|
|
if( m_useDrillOrigin && m_hasDrillOrigin )
|
|
|
|
{
|
|
|
|
origin = m_drillOrigin;
|
|
|
|
}
|
|
|
|
else if( m_useGridOrigin && m_hasDrillOrigin )
|
|
|
|
{
|
|
|
|
origin = m_gridOrigin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
origin = m_origin;
|
|
|
|
}
|
|
|
|
|
2021-09-12 21:41:18 +00:00
|
|
|
m_pcb_model = new PCBMODEL( m_pcbName );
|
2018-10-02 06:34:07 +00:00
|
|
|
m_pcb_model->SetPCBThickness( m_thickness );
|
|
|
|
m_pcb_model->SetMinDistance( m_minDistance );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
for( auto i : m_curves )
|
|
|
|
{
|
|
|
|
if( CURVE_NONE == i->m_form || LAYER_EDGE != i->m_layer )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// adjust the coordinate system
|
2020-10-21 08:18:03 +00:00
|
|
|
// Note: we negate the Y coordinates due to the fact in Pcbnew the Y axis
|
|
|
|
// is from top to bottom.
|
2016-09-02 10:08:40 +00:00
|
|
|
KICADCURVE lcurve = *i;
|
2016-09-04 07:08:56 +00:00
|
|
|
lcurve.m_start.y = -( lcurve.m_start.y - origin.y );
|
|
|
|
lcurve.m_end.y = -( lcurve.m_end.y - origin.y );
|
|
|
|
lcurve.m_start.x -= origin.x;
|
|
|
|
lcurve.m_end.x -= origin.x;
|
2020-10-21 08:18:03 +00:00
|
|
|
// used in bezier curves:
|
|
|
|
lcurve.m_bezierctrl1.y = -( lcurve.m_bezierctrl1.y - origin.y );
|
|
|
|
lcurve.m_bezierctrl1.x -= origin.x;
|
|
|
|
lcurve.m_bezierctrl2.y = -( lcurve.m_bezierctrl2.y - origin.y );
|
|
|
|
lcurve.m_bezierctrl2.x -= origin.x;
|
2016-09-02 10:08:40 +00:00
|
|
|
|
|
|
|
if( CURVE_ARC == lcurve.m_form )
|
|
|
|
lcurve.m_angle = -lcurve.m_angle;
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
m_pcb_model->AddOutlineSegment( &lcurve );
|
2016-09-02 10:08:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( auto i : m_footprints )
|
2021-06-08 22:46:37 +00:00
|
|
|
i->ComposePCB( m_pcb_model, &m_resolver, origin, aComposeVirtual, aSubstituteModels );
|
2018-10-02 06:34:07 +00:00
|
|
|
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxT( "Create PCB solid model\n" ) );
|
2016-09-02 10:08:40 +00:00
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
if( !m_pcb_model->CreatePCB() )
|
2016-09-02 10:08:40 +00:00
|
|
|
{
|
2022-02-08 21:47:43 +00:00
|
|
|
ReportMessage( wxT( "could not create PCB solid model\n" ) );
|
2018-10-02 06:34:07 +00:00
|
|
|
delete m_pcb_model;
|
|
|
|
m_pcb_model = NULL;
|
2016-09-02 10:08:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|