2019-11-25 07:02:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN
|
2024-01-10 11:28:29 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-11-25 07:02:16 +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
|
|
|
|
*/
|
|
|
|
|
2024-06-20 22:33:03 +00:00
|
|
|
// base64 code. Needed for PCB_REFERENCE_IMAGE
|
|
|
|
#define wxUSE_BASE64 1
|
|
|
|
#include <wx/base64.h>
|
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/ffile.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/mstream.h>
|
|
|
|
|
2020-07-25 21:53:58 +00:00
|
|
|
#include <advanced_config.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>
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <callback_gal.h>
|
2020-08-11 19:37:07 +00:00
|
|
|
#include <confirm.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h> // for enum RECT_CHAMFER_POSITIONS definition
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <fmt/core.h>
|
|
|
|
#include <font/fontconfig.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <io/kicad/kicad_io_utils.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2023-05-25 10:25:32 +00:00
|
|
|
#include <pcb_dimension.h>
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <pcb_generator.h>
|
|
|
|
#include <pcb_group.h>
|
|
|
|
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
|
|
|
|
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.h>
|
2023-10-23 17:23:24 +00:00
|
|
|
#include <pcb_reference_image.h>
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_table.h>
|
|
|
|
#include <pcb_tablecell.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <pcb_target.h>
|
|
|
|
#include <pcb_text.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include <pcb_textbox.h>
|
2023-05-25 10:25:32 +00:00
|
|
|
#include <pcb_track.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2023-03-24 23:45:56 +00:00
|
|
|
#include <pgm_base.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <reporter.h>
|
|
|
|
#include <string_utils.h>
|
|
|
|
#include <trace_helpers.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <zone.h>
|
2023-05-25 00:07:46 +00:00
|
|
|
|
2024-06-20 22:33:03 +00:00
|
|
|
#include <build_version.h>
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <filter_reader.h>
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
using namespace PCB_KEYS_T;
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FP_CACHE_ITEM::FP_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName ) :
|
2020-11-13 02:09:34 +00:00
|
|
|
m_filename( aFileName ),
|
|
|
|
m_footprint( aFootprint )
|
2019-11-25 07:02:16 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
FP_CACHE::FP_CACHE( PCB_IO_KICAD_SEXPR* aOwner, const wxString& aLibraryPath )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_owner = aOwner;
|
|
|
|
m_lib_raw_path = aLibraryPath;
|
|
|
|
m_lib_path.SetPath( aLibraryPath );
|
|
|
|
m_cache_timestamp = 0;
|
|
|
|
m_cache_dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FP_CACHE::Save( FOOTPRINT* aFootprint )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_cache_timestamp = 0;
|
|
|
|
|
|
|
|
if( !m_lib_path.DirExists() && !m_lib_path.Mkdir() )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Cannot create footprint library '%s'." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
m_lib_raw_path ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_lib_path.IsDirWritable() )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' is read only." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
m_lib_raw_path ) );
|
|
|
|
}
|
|
|
|
|
2022-11-28 02:27:34 +00:00
|
|
|
for( FP_CACHE_FOOTPRINT_MAP::iterator it = m_footprints.begin(); it != m_footprints.end(); ++it )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-11-15 12:20:59 +00:00
|
|
|
if( aFootprint && aFootprint != it->second->GetFootprint() )
|
2019-11-25 07:02:16 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
WX_FILENAME fn = it->second->GetFileName();
|
|
|
|
|
|
|
|
wxString tempFileName =
|
|
|
|
#ifdef USE_TMP_FILE
|
|
|
|
wxFileName::CreateTempFileName( fn.GetPath() );
|
|
|
|
#else
|
|
|
|
fn.GetFullPath();
|
|
|
|
#endif
|
|
|
|
// Allow file output stream to go out of scope to close the file stream before
|
|
|
|
// renaming the file.
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file '%s'." ),
|
2020-10-16 00:39:55 +00:00
|
|
|
tempFileName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-24 18:58:19 +00:00
|
|
|
PRETTIFIED_FILE_OUTPUTFORMATTER formatter( tempFileName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_owner->SetOutputFormatter( &formatter );
|
2020-11-15 12:20:59 +00:00
|
|
|
m_owner->Format( (BOARD_ITEM*) it->second->GetFootprint() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_TMP_FILE
|
|
|
|
wxRemove( fn.GetFullPath() ); // it is not an error if this does not exist
|
|
|
|
|
2020-09-22 21:50:59 +00:00
|
|
|
// Even on Linux you can see an _intermittent_ error when calling wxRename(),
|
2019-11-25 07:02:16 +00:00
|
|
|
// and it is fully inexplicable. See if this dodges the error.
|
|
|
|
wxMilliSleep( 250L );
|
|
|
|
|
2023-05-25 00:07:46 +00:00
|
|
|
// Preserve the permissions of the current file
|
|
|
|
KIPLATFORM::IO::DuplicatePermissions( fn.GetFullPath(), tempFileName );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
if( !wxRenameFile( tempFileName, fn.GetFullPath() ) )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
wxString msg = wxString::Format( _( "Cannot rename temporary file '%s' to '%s'" ),
|
|
|
|
tempFileName,
|
|
|
|
fn.GetFullPath() );
|
2019-11-25 07:02:16 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
m_cache_timestamp += fn.GetTimestamp();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cache_timestamp += m_lib_path.GetModificationTime().GetValue().GetValue();
|
|
|
|
|
|
|
|
// If we've saved the full cache, we clear the dirty flag.
|
2020-11-13 02:09:34 +00:00
|
|
|
if( !aFootprint )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_cache_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FP_CACHE::Load()
|
|
|
|
{
|
|
|
|
m_cache_dirty = false;
|
|
|
|
m_cache_timestamp = 0;
|
|
|
|
|
|
|
|
wxDir dir( m_lib_raw_path );
|
|
|
|
|
|
|
|
if( !dir.IsOpened() )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString msg = wxString::Format( _( "Footprint library '%s' not found." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
m_lib_raw_path );
|
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString fullName;
|
2024-03-21 01:52:19 +00:00
|
|
|
wxString fileSpec = wxT( "*." ) + wxString( FILEEXT::KiCadFootprintFileExtension );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
// wxFileName construction is egregiously slow. Construct it once and just swap out
|
|
|
|
// the filename thereafter.
|
|
|
|
WX_FILENAME fn( m_lib_raw_path, wxT( "dummyName" ) );
|
|
|
|
|
|
|
|
if( dir.GetFirst( &fullName, fileSpec ) )
|
|
|
|
{
|
|
|
|
wxString cacheError;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fn.SetFullName( fullName );
|
|
|
|
|
|
|
|
// Queue I/O errors so only files that fail to parse don't get loaded.
|
|
|
|
try
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
FILE_LINE_READER reader( fn.GetFullPath() );
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR_PARSER parser( &reader, nullptr, nullptr );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-01-28 15:38:56 +00:00
|
|
|
FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( parser.Parse() );
|
|
|
|
wxString fpName = fn.GetName();
|
|
|
|
|
|
|
|
if( !footprint )
|
2024-03-15 22:47:00 +00:00
|
|
|
THROW_IO_ERROR( wxEmptyString ); // caught locally, just below...
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
footprint->SetFPID( LIB_ID( wxEmptyString, fpName ) );
|
2020-11-14 21:21:54 +00:00
|
|
|
m_footprints.insert( fpName, new FP_CACHE_ITEM( footprint, fn ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
if( !cacheError.IsEmpty() )
|
2022-02-04 22:44:59 +00:00
|
|
|
cacheError += wxT( "\n\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-03-15 22:47:00 +00:00
|
|
|
cacheError += wxString::Format( _( "Unable to read file '%s'" ) + '\n',
|
|
|
|
fn.GetFullPath() );
|
2019-11-25 07:02:16 +00:00
|
|
|
cacheError += ioe.What();
|
|
|
|
}
|
|
|
|
} while( dir.GetNext( &fullName ) );
|
|
|
|
|
2021-02-25 22:35:06 +00:00
|
|
|
m_cache_timestamp = GetTimestamp( m_lib_raw_path );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
if( !cacheError.IsEmpty() )
|
|
|
|
THROW_IO_ERROR( cacheError );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FP_CACHE::Remove( const wxString& aFootprintName )
|
|
|
|
{
|
2022-11-28 02:27:34 +00:00
|
|
|
FP_CACHE_FOOTPRINT_MAP::const_iterator it = m_footprints.find( aFootprintName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( it == m_footprints.end() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library '%s' has no footprint '%s'." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
m_lib_raw_path,
|
|
|
|
aFootprintName );
|
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
|
|
|
|
2020-11-14 22:00:12 +00:00
|
|
|
// Remove the footprint from the cache and delete the footprint file from the library.
|
2019-11-25 07:02:16 +00:00
|
|
|
wxString fullPath = it->second->GetFileName().GetFullPath();
|
2020-11-14 21:21:54 +00:00
|
|
|
m_footprints.erase( aFootprintName );
|
2019-11-25 07:02:16 +00:00
|
|
|
wxRemoveFile( fullPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FP_CACHE::IsPath( const wxString& aPath ) const
|
|
|
|
{
|
|
|
|
return aPath == m_lib_raw_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-07 02:20:19 +00:00
|
|
|
void FP_CACHE::SetPath( const wxString& aPath )
|
|
|
|
{
|
|
|
|
m_lib_raw_path = aPath;
|
|
|
|
m_lib_path.SetPath( aPath );
|
|
|
|
|
|
|
|
|
2022-12-07 03:00:09 +00:00
|
|
|
for( const auto& footprint : GetFootprints() )
|
2022-12-07 02:20:19 +00:00
|
|
|
{
|
|
|
|
footprint.second->SetFilePath( aPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
bool FP_CACHE::IsModified()
|
|
|
|
{
|
|
|
|
m_cache_dirty = m_cache_dirty || GetTimestamp( m_lib_path.GetFullPath() ) != m_cache_timestamp;
|
|
|
|
|
|
|
|
return m_cache_dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long long FP_CACHE::GetTimestamp( const wxString& aLibPath )
|
|
|
|
{
|
2024-03-21 01:52:19 +00:00
|
|
|
wxString fileSpec = wxT( "*." ) + wxString( FILEEXT::KiCadFootprintFileExtension );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
return TimestampDir( aLibPath, fileSpec );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
bool PCB_IO_KICAD_SEXPR::CanReadBoard( const wxString& aFileName ) const
|
2023-08-13 02:26:06 +00:00
|
|
|
{
|
2023-12-19 17:39:26 +00:00
|
|
|
if( !PCB_IO::CanReadBoard( aFileName ) )
|
2023-08-13 02:26:06 +00:00
|
|
|
return false;
|
|
|
|
|
2023-08-29 16:13:55 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FILE_LINE_READER reader( aFileName );
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR_PARSER parser( &reader, nullptr, m_queryUserCallback );
|
2023-08-13 02:26:06 +00:00
|
|
|
|
2023-08-29 16:13:55 +00:00
|
|
|
return parser.IsValidBoardHeader();
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& )
|
|
|
|
{
|
|
|
|
}
|
2023-08-13 02:26:06 +00:00
|
|
|
|
2023-08-29 16:13:55 +00:00
|
|
|
return false;
|
2023-08-13 02:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::SaveBoard( const wxString& aFileName, BOARD* aBoard,
|
2023-12-27 17:06:23 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
wxString sanityResult = aBoard->GroupsSanityCheck();
|
|
|
|
|
2022-02-11 21:38:31 +00:00
|
|
|
if( sanityResult != wxEmptyString && m_queryUserCallback )
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2023-05-20 04:00:09 +00:00
|
|
|
if( !m_queryUserCallback(
|
2022-02-11 21:38:31 +00:00
|
|
|
_( "Internal Group Data Error" ), wxICON_ERROR,
|
|
|
|
wxString::Format( _( "Please report this bug. Error validating group "
|
|
|
|
"structure: %s\n\nSave anyway?" ), sanityResult ),
|
|
|
|
_( "Save Anyway" ) ) )
|
|
|
|
{
|
2020-08-11 19:37:07 +00:00
|
|
|
return;
|
2022-02-11 21:38:31 +00:00
|
|
|
}
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
m_board = aBoard; // after init()
|
|
|
|
|
|
|
|
// Prepare net mapping that assures that net codes saved in a file are consecutive integers
|
|
|
|
m_mapping->SetBoard( aBoard );
|
|
|
|
|
2023-09-24 18:58:19 +00:00
|
|
|
PRETTIFIED_FILE_OUTPUTFORMATTER formatter( aFileName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out = &formatter; // no ownership
|
|
|
|
|
2023-11-18 22:34:09 +00:00
|
|
|
m_out->Print( 0, "(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version \"%s\")\n",
|
|
|
|
SEXPR_BOARD_FILE_VERSION, GetMajorMinorVersion().c_str().AsChar() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
Format( aBoard, 1 );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
2023-09-24 18:58:19 +00:00
|
|
|
m_out->Finish();
|
2021-05-31 01:29:26 +00:00
|
|
|
|
|
|
|
m_out = nullptr;
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
BOARD_ITEM* PCB_IO_KICAD_SEXPR::Parse( const wxString& aClipboardSourceInput )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
std::string input = TO_UTF8( aClipboardSourceInput );
|
|
|
|
|
2021-10-31 19:57:52 +00:00
|
|
|
STRING_LINE_READER reader( input, wxT( "clipboard" ) );
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR_PARSER parser( &reader, nullptr, m_queryUserCallback );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
return parser.Parse();
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
if( parser.IsTooRecent() )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
|
2019-11-25 07:02:16 +00:00
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::Format( const BOARD_ITEM* aItem, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // public API function, perform anything convenient for caller
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const BOARD*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
2021-06-11 16:59:28 +00:00
|
|
|
format( static_cast<const PCB_DIMENSION_BASE*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const PCB_SHAPE*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-10-23 17:23:24 +00:00
|
|
|
case PCB_REFERENCE_IMAGE_T:
|
|
|
|
format( static_cast<const PCB_REFERENCE_IMAGE*>( aItem ), aNestLevel );
|
2022-02-08 19:29:54 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
case PCB_TARGET_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const PCB_TARGET*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const FOOTPRINT*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const PAD*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-06-06 15:09:34 +00:00
|
|
|
case PCB_FIELD_T:
|
2023-06-12 14:02:28 +00:00
|
|
|
// Handled in the footprint formatter when properties are formatted
|
|
|
|
break;
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
case PCB_TEXT_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const PCB_TEXT*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
|
|
|
format( static_cast<const PCB_TEXTBOX*>( aItem ), aNestLevel );
|
|
|
|
break;
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
case PCB_TABLE_T:
|
|
|
|
format( static_cast<const PCB_TABLE*>( aItem ), aNestLevel );
|
|
|
|
break;
|
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
case PCB_GROUP_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const PCB_GROUP*>( aItem ), aNestLevel );
|
2020-08-11 19:37:07 +00:00
|
|
|
break;
|
|
|
|
|
2023-10-07 01:55:45 +00:00
|
|
|
case PCB_GENERATOR_T:
|
|
|
|
format( static_cast<const PCB_GENERATOR*>( aItem ), aNestLevel );
|
|
|
|
break;
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2019-11-25 07:02:16 +00:00
|
|
|
case PCB_VIA_T:
|
2021-06-11 21:07:02 +00:00
|
|
|
format( static_cast<const PCB_TRACK*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2020-12-20 18:44:13 +00:00
|
|
|
format( static_cast<const ZONE*>( aItem ), aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
std::string formatInternalUnits( int aValue )
|
|
|
|
{
|
|
|
|
return EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string formatInternalUnits( const VECTOR2I& aCoord )
|
|
|
|
{
|
|
|
|
return EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aCoord );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string formatInternalUnits( const VECTOR2I& aCoord, const FOOTPRINT* aParentFP )
|
|
|
|
{
|
|
|
|
if( aParentFP )
|
|
|
|
{
|
|
|
|
VECTOR2I coord = aCoord - aParentFP->GetPosition();
|
|
|
|
RotatePoint( coord, -aParentFP->GetOrientation() );
|
|
|
|
return formatInternalUnits( coord );
|
|
|
|
}
|
|
|
|
|
|
|
|
return formatInternalUnits( aCoord );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatLayer( PCB_LAYER_ID aLayer, bool aIsKnockout ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2022-03-08 13:16:39 +00:00
|
|
|
m_out->Print( 0, " (layer %s%s)",
|
|
|
|
m_out->Quotew( LSET::Name( aLayer ) ).c_str(),
|
|
|
|
aIsKnockout ? " knockout" : "" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel,
|
2023-03-30 11:49:23 +00:00
|
|
|
bool aCompact, const FOOTPRINT* aParentFP ) const
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel + 1, "(pts\n" );
|
|
|
|
|
|
|
|
bool needNewline = false;
|
|
|
|
int nestLevel = aNestLevel + 2;
|
|
|
|
int shapesAdded = 0;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < outline.PointCount(); ++ii )
|
|
|
|
{
|
|
|
|
int ind = outline.ArcIndex( ii );
|
|
|
|
|
|
|
|
if( ind < 0 )
|
|
|
|
{
|
|
|
|
m_out->Print( nestLevel, "(xy %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( outline.CPoint( ii ), aParentFP ).c_str() );
|
2022-01-04 23:00:00 +00:00
|
|
|
needNewline = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const SHAPE_ARC& arc = outline.Arc( ind );
|
|
|
|
m_out->Print( nestLevel, "(arc (start %s) (mid %s) (end %s))",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( arc.GetP0(), aParentFP ).c_str(),
|
|
|
|
formatInternalUnits( arc.GetArcMid(), aParentFP ).c_str(),
|
|
|
|
formatInternalUnits( arc.GetP1(), aParentFP ).c_str() );
|
2022-01-04 23:00:00 +00:00
|
|
|
needNewline = true;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++ii;
|
|
|
|
} while( ii < outline.PointCount() && outline.ArcIndex( ii ) == ind );
|
|
|
|
|
|
|
|
--ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
++shapesAdded;
|
|
|
|
|
|
|
|
if( !( shapesAdded % 4 ) || !aCompact )
|
|
|
|
{
|
|
|
|
// newline every 4 shapes if compact save
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
needNewline = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( needNewline )
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) const
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
2023-05-24 16:21:50 +00:00
|
|
|
wxString resolvedText( aText->GetShownText( true ) );
|
2022-10-22 20:32:10 +00:00
|
|
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = aText->GetRenderCache( aText->GetFont(),
|
2023-05-24 16:21:50 +00:00
|
|
|
resolvedText );
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "(render_cache %s %s\n",
|
2023-05-24 16:21:50 +00:00
|
|
|
m_out->Quotew( resolvedText ).c_str(),
|
2022-08-29 23:30:25 +00:00
|
|
|
EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() );
|
2022-01-04 23:00:00 +00:00
|
|
|
|
2023-05-25 10:25:32 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
2023-05-24 16:21:50 +00:00
|
|
|
|
2023-05-25 10:25:32 +00:00
|
|
|
CALLBACK_GAL callback_gal( empty_opts,
|
|
|
|
// Polygon callback
|
|
|
|
[&]( const SHAPE_LINE_CHAIN& aPoly )
|
2022-01-04 23:00:00 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel + 1, "(polygon\n" );
|
2023-05-25 10:25:32 +00:00
|
|
|
formatPolyPts( aPoly, aNestLevel + 1, true );
|
2022-01-04 23:00:00 +00:00
|
|
|
m_out->Print( aNestLevel + 1, ")\n" );
|
2023-05-25 10:25:32 +00:00
|
|
|
} );
|
|
|
|
|
2023-05-26 14:39:48 +00:00
|
|
|
callback_gal.SetLineWidth( aText->GetTextThickness() );
|
2023-05-25 10:25:32 +00:00
|
|
|
callback_gal.DrawGlyphs( *cache );
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatSetup( const BOARD* aBoard, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
// Setup
|
|
|
|
m_out->Print( aNestLevel, "(setup\n" );
|
|
|
|
|
|
|
|
// Save the board physical stackup structure
|
2020-12-20 18:44:13 +00:00
|
|
|
const BOARD_STACKUP& stackup = aBoard->GetDesignSettings().GetStackupDescriptor();
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( aBoard->GetDesignSettings().m_HasStackup )
|
2020-10-13 22:05:15 +00:00
|
|
|
stackup.FormatBoardStackup( m_out, aBoard, aNestLevel+1 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-02-28 19:04:28 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( dsnSettings.m_SolderMaskExpansion ).c_str() );
|
2021-02-28 19:04:28 +00:00
|
|
|
|
|
|
|
if( dsnSettings.m_SolderMaskMinWidth )
|
2022-08-14 21:53:20 +00:00
|
|
|
{
|
2021-02-28 19:04:28 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
|
2022-08-14 21:53:20 +00:00
|
|
|
}
|
2021-02-28 19:04:28 +00:00
|
|
|
|
|
|
|
if( dsnSettings.m_SolderPasteMargin != 0 )
|
2022-08-14 21:53:20 +00:00
|
|
|
{
|
2021-02-28 19:04:28 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
|
2022-08-14 21:53:20 +00:00
|
|
|
}
|
2021-02-28 19:04:28 +00:00
|
|
|
|
|
|
|
if( dsnSettings.m_SolderPasteMarginRatio != 0 )
|
2022-08-14 21:53:20 +00:00
|
|
|
{
|
2021-02-28 19:04:28 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
|
2022-08-14 21:53:20 +00:00
|
|
|
}
|
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "allow_soldermask_bridges_in_footprints",
|
|
|
|
dsnSettings.m_AllowSoldermaskBridgesInFPs );
|
2021-02-28 19:04:28 +00:00
|
|
|
|
2024-06-09 22:28:19 +00:00
|
|
|
m_out->Print( 0, " (tenting " );
|
|
|
|
|
|
|
|
if( dsnSettings.m_TentViasFront || dsnSettings.m_TentViasBack )
|
|
|
|
{
|
|
|
|
if( dsnSettings.m_TentViasFront )
|
|
|
|
m_out->Print( 0, "front " );
|
|
|
|
if( dsnSettings.m_TentViasBack )
|
|
|
|
m_out->Print( 0, "back " );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
2024-06-09 16:44:30 +00:00
|
|
|
else
|
2024-06-09 22:28:19 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, " none)" );
|
|
|
|
}
|
2024-06-09 16:44:30 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I origin = dsnSettings.GetAuxOrigin();
|
2021-11-09 03:36:40 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
if( origin != VECTOR2I( 0, 0 ) )
|
2021-11-09 03:36:40 +00:00
|
|
|
{
|
2020-07-01 12:28:10 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( origin.x ).c_str(),
|
|
|
|
formatInternalUnits( origin.y ).c_str() );
|
2021-11-09 03:36:40 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-11-09 03:36:40 +00:00
|
|
|
origin = dsnSettings.GetGridOrigin();
|
|
|
|
|
2022-01-11 00:49:49 +00:00
|
|
|
if( origin != VECTOR2I( 0, 0 ) )
|
2021-11-09 03:36:40 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( origin.x ).c_str(),
|
|
|
|
formatInternalUnits( origin.y ).c_str() );
|
2021-11-09 03:36:40 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatGeneral( const BOARD* aBoard, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel, "(general\n" );
|
2023-05-12 21:03:54 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(thickness %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "legacy_teardrops",
|
|
|
|
aBoard->LegacyTeardrops() );
|
2023-05-12 21:03:54 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel, ")\n\n" );
|
|
|
|
|
|
|
|
aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
|
|
|
|
aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatBoardLayers( const BOARD* aBoard, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel, "(layers\n" );
|
|
|
|
|
|
|
|
// Save only the used copper layers from front to back.
|
|
|
|
|
|
|
|
for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = *cu;
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(%d %s %s", layer,
|
2020-09-22 21:50:59 +00:00
|
|
|
m_out->Quotew( LSET::Name( layer ) ).c_str(),
|
2019-11-25 07:02:16 +00:00
|
|
|
LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
|
|
|
|
|
2020-09-22 21:50:59 +00:00
|
|
|
if( LSET::Name( layer ) != m_board->GetLayerName( layer ) )
|
|
|
|
m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save used non-copper layers in the order they are defined.
|
|
|
|
// desired sequence for non Cu BOARD layers.
|
|
|
|
static const PCB_LAYER_ID non_cu[] =
|
|
|
|
{
|
|
|
|
B_Adhes, // 32
|
|
|
|
F_Adhes,
|
|
|
|
B_Paste,
|
|
|
|
F_Paste,
|
|
|
|
B_SilkS,
|
|
|
|
F_SilkS,
|
|
|
|
B_Mask,
|
|
|
|
F_Mask,
|
|
|
|
Dwgs_User,
|
|
|
|
Cmts_User,
|
|
|
|
Eco1_User,
|
|
|
|
Eco2_User,
|
|
|
|
Edge_Cuts,
|
|
|
|
Margin,
|
|
|
|
B_CrtYd,
|
|
|
|
F_CrtYd,
|
|
|
|
B_Fab,
|
2020-09-22 21:50:59 +00:00
|
|
|
F_Fab,
|
|
|
|
User_1,
|
|
|
|
User_2,
|
|
|
|
User_3,
|
|
|
|
User_4,
|
|
|
|
User_5,
|
|
|
|
User_6,
|
|
|
|
User_7,
|
|
|
|
User_8,
|
|
|
|
User_9
|
2019-11-25 07:02:16 +00:00
|
|
|
};
|
|
|
|
|
2020-12-20 18:50:45 +00:00
|
|
|
for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = *seq;
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(%d %s user", layer,
|
2020-09-22 21:50:59 +00:00
|
|
|
m_out->Quotew( LSET::Name( layer ) ).c_str() );
|
|
|
|
|
|
|
|
if( m_board->GetLayerName( layer ) != LSET::Name( layer ) )
|
|
|
|
m_out->Print( 0, " %s", m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatNetInformation( const BOARD* aBoard, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
for( NETINFO_ITEM* net : *m_mapping )
|
|
|
|
{
|
2020-08-06 14:11:55 +00:00
|
|
|
if( net == nullptr ) // Skip not actually existing nets (orphan nets)
|
|
|
|
continue;
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel, "(net %d %s)\n",
|
2020-12-08 13:02:08 +00:00
|
|
|
m_mapping->Translate( net->GetNetCode() ),
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Quotew( net->GetNetname() ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatProperties( const BOARD* aBoard, int aNestLevel ) const
|
2020-08-19 18:21:24 +00:00
|
|
|
{
|
|
|
|
for( const std::pair<const wxString, wxString>& prop : aBoard->GetProperties() )
|
|
|
|
{
|
2020-08-20 11:37:57 +00:00
|
|
|
m_out->Print( aNestLevel, "(property %s %s)\n",
|
2020-08-19 18:21:24 +00:00
|
|
|
m_out->Quotew( prop.first ).c_str(),
|
|
|
|
m_out->Quotew( prop.second ).c_str() );
|
|
|
|
}
|
|
|
|
|
2021-04-20 14:18:31 +00:00
|
|
|
if( !aBoard->GetProperties().empty() )
|
|
|
|
m_out->Print( 0, "\n" );
|
2020-08-19 18:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatHeader( const BOARD* aBoard, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
formatGeneral( aBoard, aNestLevel );
|
2021-04-20 14:18:31 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// Layers list.
|
|
|
|
formatBoardLayers( aBoard, aNestLevel );
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
formatSetup( aBoard, aNestLevel );
|
|
|
|
|
2020-08-19 18:21:24 +00:00
|
|
|
// Properties
|
|
|
|
formatProperties( aBoard, aNestLevel );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// Save net codes and names
|
|
|
|
formatNetInformation( aBoard, aNestLevel );
|
|
|
|
}
|
|
|
|
|
2020-08-19 18:21:24 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
bool isDefaultTeardropParameters( const TEARDROP_PARAMETERS& tdParams )
|
|
|
|
{
|
|
|
|
static const TEARDROP_PARAMETERS defaults;
|
|
|
|
|
|
|
|
return tdParams.m_Enabled == defaults.m_Enabled
|
|
|
|
&& tdParams.m_BestLengthRatio == defaults.m_BestLengthRatio
|
|
|
|
&& tdParams.m_TdMaxLen == defaults.m_TdMaxLen
|
|
|
|
&& tdParams.m_BestWidthRatio == defaults.m_BestWidthRatio
|
|
|
|
&& tdParams.m_TdMaxWidth == defaults.m_TdMaxWidth
|
|
|
|
&& tdParams.m_CurveSegCount == defaults.m_CurveSegCount
|
|
|
|
&& tdParams.m_WidthtoSizeFilterRatio == defaults.m_WidthtoSizeFilterRatio
|
|
|
|
&& tdParams.m_AllowUseTwoTracks == defaults.m_AllowUseTwoTracks
|
|
|
|
&& tdParams.m_TdOnPadsInZones == defaults.m_TdOnPadsInZones;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatTeardropParameters( const TEARDROP_PARAMETERS& tdParams,
|
2023-05-12 21:03:54 +00:00
|
|
|
int aNestLevel ) const
|
|
|
|
{
|
2024-01-08 23:43:57 +00:00
|
|
|
m_out->Print( aNestLevel, "(teardrops (best_length_ratio %s) (max_length %s) "
|
2023-05-12 21:03:54 +00:00
|
|
|
"(best_width_ratio %s) (max_width %s) (curve_points %d) "
|
2024-01-08 23:43:57 +00:00
|
|
|
"(filter_ratio %s)",
|
2023-05-12 21:03:54 +00:00
|
|
|
FormatDouble2Str( tdParams.m_BestLengthRatio ).c_str(),
|
|
|
|
formatInternalUnits( tdParams.m_TdMaxLen ).c_str(),
|
|
|
|
FormatDouble2Str( tdParams.m_BestWidthRatio ).c_str(),
|
|
|
|
formatInternalUnits( tdParams.m_TdMaxWidth ).c_str(),
|
|
|
|
tdParams.m_CurveSegCount,
|
|
|
|
FormatDouble2Str( tdParams.m_WidthtoSizeFilterRatio ).c_str() );
|
2024-01-08 23:43:57 +00:00
|
|
|
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel, "enabled", tdParams.m_Enabled );
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel, "allow_two_segments",
|
|
|
|
tdParams.m_AllowUseTwoTracks );
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel, "prefer_zone_connections",
|
|
|
|
!tdParams.m_TdOnPadsInZones );
|
|
|
|
m_out->Print( aNestLevel, ")" );
|
2023-05-12 21:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const BOARD* aBoard, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-11-14 22:00:12 +00:00
|
|
|
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_footprints( aBoard->Footprints().begin(),
|
|
|
|
aBoard->Footprints().end() );
|
2020-07-24 22:08:36 +00:00
|
|
|
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_drawings( aBoard->Drawings().begin(),
|
2021-04-20 14:18:31 +00:00
|
|
|
aBoard->Drawings().end() );
|
2021-06-11 21:07:02 +00:00
|
|
|
std::set<PCB_TRACK*, PCB_TRACK::cmp_tracks> sorted_tracks( aBoard->Tracks().begin(),
|
|
|
|
aBoard->Tracks().end() );
|
2020-07-24 22:08:36 +00:00
|
|
|
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aBoard->Zones().begin(),
|
2021-04-20 14:18:31 +00:00
|
|
|
aBoard->Zones().end() );
|
2020-08-11 19:37:07 +00:00
|
|
|
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->Groups().begin(),
|
2021-04-20 14:18:31 +00:00
|
|
|
aBoard->Groups().end() );
|
2023-10-07 01:55:45 +00:00
|
|
|
std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_generators( aBoard->Generators().begin(),
|
|
|
|
aBoard->Generators().end() );
|
2019-11-25 07:02:16 +00:00
|
|
|
formatHeader( aBoard, aNestLevel );
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Save the footprints.
|
2020-11-14 22:00:12 +00:00
|
|
|
for( BOARD_ITEM* footprint : sorted_footprints )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-11-14 22:00:12 +00:00
|
|
|
Format( footprint, aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
// Save the graphical items on the board (not owned by a footprint)
|
2020-10-03 11:16:29 +00:00
|
|
|
for( BOARD_ITEM* item : sorted_drawings )
|
2019-11-25 07:02:16 +00:00
|
|
|
Format( item, aNestLevel );
|
|
|
|
|
2020-07-24 22:08:36 +00:00
|
|
|
if( sorted_drawings.size() )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
// Do not save PCB_MARKERs, they can be regenerated easily.
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
// Save the tracks and vias.
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : sorted_tracks )
|
2019-11-25 07:02:16 +00:00
|
|
|
Format( track, aNestLevel );
|
|
|
|
|
2020-07-24 22:08:36 +00:00
|
|
|
if( sorted_tracks.size() )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
// Save the polygon (which are the newer technology) zones.
|
2020-07-24 22:08:36 +00:00
|
|
|
for( auto zone : sorted_zones )
|
|
|
|
Format( zone, aNestLevel );
|
2020-08-11 19:37:07 +00:00
|
|
|
|
|
|
|
// Save the groups
|
2020-10-03 11:16:29 +00:00
|
|
|
for( BOARD_ITEM* group : sorted_groups )
|
2020-08-11 19:37:07 +00:00
|
|
|
Format( group, aNestLevel );
|
2023-10-07 01:55:45 +00:00
|
|
|
|
|
|
|
// Save the generators
|
|
|
|
for( BOARD_ITEM* gen : sorted_generators )
|
|
|
|
Format( gen, aNestLevel );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_DIMENSION_BASE* aDimension, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_ALIGNED* aligned = dynamic_cast<const PCB_DIM_ALIGNED*>( aDimension );
|
|
|
|
const PCB_DIM_ORTHOGONAL* ortho = dynamic_cast<const PCB_DIM_ORTHOGONAL*>( aDimension );
|
|
|
|
const PCB_DIM_CENTER* center = dynamic_cast<const PCB_DIM_CENTER*>( aDimension );
|
2021-07-13 18:46:33 +00:00
|
|
|
const PCB_DIM_RADIAL* radial = dynamic_cast<const PCB_DIM_RADIAL*>( aDimension );
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_LEADER* leader = dynamic_cast<const PCB_DIM_LEADER*>( aDimension );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "(dimension" );
|
|
|
|
|
2022-01-05 09:57:32 +00:00
|
|
|
if( ortho ) // must be tested before aligned, because ortho is derived from aligned
|
|
|
|
// and aligned is not null
|
|
|
|
m_out->Print( 0, " (type orthogonal)" );
|
|
|
|
else if( aligned )
|
2020-09-12 20:09:40 +00:00
|
|
|
m_out->Print( 0, " (type aligned)" );
|
2021-12-04 23:52:00 +00:00
|
|
|
else if( leader )
|
2020-09-12 20:09:40 +00:00
|
|
|
m_out->Print( 0, " (type leader)" );
|
2021-12-04 23:52:00 +00:00
|
|
|
else if( center )
|
2020-09-17 00:54:58 +00:00
|
|
|
m_out->Print( 0, " (type center)" );
|
2021-12-04 23:52:00 +00:00
|
|
|
else if( radial )
|
2021-07-13 18:46:33 +00:00
|
|
|
m_out->Print( 0, " (type radial)" );
|
2020-09-12 20:09:40 +00:00
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format unknown dimension type!" ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( aDimension->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "locked", aDimension->IsLocked() );
|
|
|
|
|
2022-02-18 13:24:21 +00:00
|
|
|
formatLayer( aDimension->GetLayer() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aDimension->m_Uuid );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pts (xy %s %s) (xy %s %s))\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aDimension->GetStart().x ).c_str(),
|
|
|
|
formatInternalUnits( aDimension->GetStart().y ).c_str(),
|
|
|
|
formatInternalUnits( aDimension->GetEnd().x ).c_str(),
|
|
|
|
formatInternalUnits( aDimension->GetEnd().y ).c_str() );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
if( aligned )
|
2021-07-21 18:31:25 +00:00
|
|
|
{
|
2020-09-12 20:09:40 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(height %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aligned->GetHeight() ).c_str() );
|
2021-07-21 18:31:25 +00:00
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
if( radial )
|
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel+1, "(leader_length %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( radial->GetLeaderLength() ).c_str() );
|
2021-07-13 18:46:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 09:57:32 +00:00
|
|
|
if( ortho )
|
2021-07-21 18:31:25 +00:00
|
|
|
{
|
2020-09-22 02:32:40 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(orientation %d)\n",
|
|
|
|
static_cast<int>( ortho->GetOrientation() ) );
|
2021-07-21 18:31:25 +00:00
|
|
|
}
|
2020-09-22 02:32:40 +00:00
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
if( !center )
|
|
|
|
{
|
2023-03-04 23:15:43 +00:00
|
|
|
format( static_cast<const PCB_TEXT*>( aDimension ), aNestLevel + 1 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-01-12 15:24:39 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(format (prefix %s) (suffix %s) (units %d) (units_format %d) (precision %d)",
|
|
|
|
m_out->Quotew( aDimension->GetPrefix() ).c_str(),
|
|
|
|
m_out->Quotew( aDimension->GetSuffix() ).c_str(),
|
|
|
|
static_cast<int>( aDimension->GetUnitsMode() ),
|
|
|
|
static_cast<int>( aDimension->GetUnitsFormat() ),
|
2023-03-05 22:48:45 +00:00
|
|
|
static_cast<int>( aDimension->GetPrecision() ) );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
if( aDimension->GetOverrideTextEnabled() )
|
2023-01-12 15:24:39 +00:00
|
|
|
{
|
2020-12-27 09:18:23 +00:00
|
|
|
m_out->Print( 0, " (override_value %s)",
|
|
|
|
m_out->Quotew( aDimension->GetOverrideText() ).c_str() );
|
2023-01-12 15:24:39 +00:00
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
if( aDimension->GetSuppressZeroes() )
|
|
|
|
m_out->Print( 0, " suppress_zeroes" );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(style (thickness %s) (arrow_length %s) (text_position_mode %d)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aDimension->GetLineThickness() ).c_str(),
|
|
|
|
formatInternalUnits( aDimension->GetArrowLength() ).c_str(),
|
2020-09-09 03:17:08 +00:00
|
|
|
static_cast<int>( aDimension->GetTextPositionMode() ) );
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
if( aligned )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (extension_height %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aligned->GetExtensionHeight() ).c_str() );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( leader )
|
2021-07-13 18:46:33 +00:00
|
|
|
m_out->Print( 0, " (text_frame %d)", static_cast<int>( leader->GetTextBorder() ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, " (extension_offset %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aDimension->GetExtensionOffset() ).c_str() );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 15:46:33 +00:00
|
|
|
if( aDimension->GetKeepTextAligned() )
|
2020-09-11 23:52:45 +00:00
|
|
|
m_out->Print( 0, " keep_text_aligned" );
|
2020-09-09 03:17:08 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_SHAPE* aShape, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* parentFP = aShape->GetParentFootprint();
|
|
|
|
std::string prefix = parentFP ? "fp" : "gr";
|
2021-04-21 18:58:26 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( aShape->GetShape() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_line (start %s) (end %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
prefix.c_str(),
|
|
|
|
formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_rect (start %s) (end %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
prefix.c_str(),
|
|
|
|
formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_circle (center %s) (end %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
prefix.c_str(),
|
|
|
|
formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_arc (start %s) (mid %s) (end %s)\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
prefix.c_str(),
|
|
|
|
formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetArcMid(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2020-10-04 23:34:59 +00:00
|
|
|
if( aShape->IsPolyShapeValid() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-12-20 18:44:13 +00:00
|
|
|
const SHAPE_POLY_SET& poly = aShape->GetPolyShape();
|
|
|
|
const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_poly\n", prefix.c_str() );
|
2023-03-30 11:49:23 +00:00
|
|
|
formatPolyPts( outline, aNestLevel, ADVANCED_CFG::GetCfg().m_CompactSave, parentFP );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))\n",
|
2023-03-30 11:49:23 +00:00
|
|
|
prefix.c_str(),
|
|
|
|
formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetBezierC1(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetBezierC2(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( aShape->SHAPE_T_asString() );
|
2019-11-25 07:02:16 +00:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( aShape->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "locked", aShape->IsLocked() );
|
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
aShape->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-15 22:03:59 +00:00
|
|
|
// The filled flag represents if a solid fill is present on circles, rectangles and polygons
|
2021-07-21 18:31:25 +00:00
|
|
|
if( ( aShape->GetShape() == SHAPE_T::POLY )
|
2023-07-24 16:07:56 +00:00
|
|
|
|| ( aShape->GetShape() == SHAPE_T::RECTANGLE )
|
2021-07-21 18:31:25 +00:00
|
|
|
|| ( aShape->GetShape() == SHAPE_T::CIRCLE ) )
|
2020-11-15 22:03:59 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, aShape->IsFilled() ? " (fill solid)" : " (fill none)" );
|
2020-11-15 22:03:59 +00:00
|
|
|
}
|
2020-11-14 01:16:02 +00:00
|
|
|
|
2022-02-18 13:24:21 +00:00
|
|
|
formatLayer( aShape->GetLayer() );
|
2021-08-25 23:14:36 +00:00
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
if( aShape->GetNetCode() > 0 )
|
|
|
|
m_out->Print( 0, " (net %d)", m_mapping->Translate( aShape->GetNetCode() ) );
|
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aShape->m_Uuid, 0 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_REFERENCE_IMAGE* aBitmap, int aNestLevel ) const
|
2022-02-08 19:29:54 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
|
|
|
|
|
|
|
|
const wxImage* image = aBitmap->GetImage()->GetImageData();
|
|
|
|
|
|
|
|
wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "(image (at %s %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aBitmap->GetPosition().x ).c_str(),
|
|
|
|
formatInternalUnits( aBitmap->GetPosition().y ).c_str() );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2022-06-27 18:07:52 +00:00
|
|
|
formatLayer( aBitmap->GetLayer() );
|
|
|
|
|
2022-02-08 19:29:54 +00:00
|
|
|
if( aBitmap->GetImage()->GetScale() != 1.0 )
|
2023-12-12 20:38:55 +00:00
|
|
|
m_out->Print( 0, "(scale %g)", aBitmap->GetImage()->GetScale() );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2023-12-12 20:38:55 +00:00
|
|
|
if( const bool locked = aBitmap->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", locked );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(data" );
|
|
|
|
|
2023-06-08 15:54:36 +00:00
|
|
|
wxString out = wxBase64Encode( aBitmap->GetImage()->GetImageDataBuffer() );
|
2022-02-08 19:29:54 +00:00
|
|
|
|
|
|
|
// Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
|
2023-06-07 02:59:17 +00:00
|
|
|
// so use it in a vain attempt to be standard like.
|
2022-02-08 19:29:54 +00:00
|
|
|
#define MIME_BASE64_LENGTH 76
|
|
|
|
|
|
|
|
size_t first = 0;
|
|
|
|
|
|
|
|
while( first < out.Length() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
2023-11-24 23:20:16 +00:00
|
|
|
m_out->Print( aNestLevel + 2, "\"%s\"", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
|
2022-02-08 19:29:54 +00:00
|
|
|
first += MIME_BASE64_LENGTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
|
2023-12-12 20:38:55 +00:00
|
|
|
|
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aBitmap->m_Uuid, 0 );
|
|
|
|
|
2022-02-08 19:29:54 +00:00
|
|
|
m_out->Print( aNestLevel, ")\n" ); // Closes image token.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_TARGET* aTarget, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
|
|
|
|
( aTarget->GetShape() ) ? "x" : "plus",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aTarget->GetPosition() ).c_str(),
|
|
|
|
formatInternalUnits( aTarget->GetSize() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( aTarget->GetWidth() != 0 )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " (width %s)", formatInternalUnits( aTarget->GetWidth() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-02-18 13:24:21 +00:00
|
|
|
formatLayer( aTarget->GetLayer() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aTarget->m_Uuid, 0 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
|
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
const wxArrayString* initial_comments = aFootprint->GetInitialComments();
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( initial_comments )
|
|
|
|
{
|
2020-12-20 18:50:45 +00:00
|
|
|
for( unsigned i = 0; i < initial_comments->GetCount(); ++i )
|
|
|
|
m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" ); // improve readability?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 19:32:11 +00:00
|
|
|
if( m_ctl & CTL_OMIT_LIBNAME )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2020-11-15 12:20:59 +00:00
|
|
|
m_out->Print( aNestLevel, "(footprint %s",
|
2021-06-30 11:00:06 +00:00
|
|
|
m_out->Quotes( aFootprint->GetFPID().GetLibItemName() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2020-08-28 19:32:11 +00:00
|
|
|
else
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2020-11-15 12:20:59 +00:00
|
|
|
m_out->Print( aNestLevel, "(footprint %s",
|
2020-11-13 02:09:34 +00:00
|
|
|
m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-16 23:19:09 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_FOOTPRINT_VERSION ) )
|
2023-11-18 22:34:09 +00:00
|
|
|
m_out->Print( 0, " (version %d) (generator \"pcbnew\") (generator_version \"%s\")\n ",
|
|
|
|
SEXPR_BOARD_FILE_VERSION, GetMajorMinorVersion().c_str().AsChar() );
|
2020-11-16 23:19:09 +00:00
|
|
|
|
2023-12-12 20:42:04 +00:00
|
|
|
if( const bool locked = aFootprint->IsLocked() )
|
|
|
|
{
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", locked );
|
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-12-12 20:42:04 +00:00
|
|
|
if( const bool placed = aFootprint->IsPlaced() )
|
|
|
|
{
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "placed", placed );
|
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-02-18 13:24:21 +00:00
|
|
|
formatLayer( aFootprint->GetLayer() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-16 23:19:09 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_UUIDS ) )
|
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aFootprint->m_Uuid );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( !( m_ctl & CTL_OMIT_AT ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(at %s", formatInternalUnits( aFootprint->GetPosition() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
if( !aFootprint->GetOrientation().IsZero() )
|
2022-08-29 23:30:25 +00:00
|
|
|
m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aFootprint->GetOrientation() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:08:18 +00:00
|
|
|
if( !aFootprint->GetLibDescription().IsEmpty() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2023-06-19 17:08:18 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(descr %s)\n",
|
|
|
|
m_out->Quotew( aFootprint->GetLibDescription() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( !aFootprint->GetKeywords().IsEmpty() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(tags %s)\n",
|
2020-11-13 02:09:34 +00:00
|
|
|
m_out->Quotew( aFootprint->GetKeywords() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-05-24 12:39:25 +00:00
|
|
|
for( const PCB_FIELD* field : aFootprint->GetFields() )
|
2020-08-08 21:47:57 +00:00
|
|
|
{
|
2023-06-12 14:02:28 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(property %s %s",
|
2023-06-23 15:28:16 +00:00
|
|
|
m_out->Quotew( field->GetCanonicalName() ).c_str(),
|
2023-05-24 12:39:25 +00:00
|
|
|
m_out->Quotew( field->GetText() ).c_str() );
|
2023-06-12 14:02:28 +00:00
|
|
|
|
|
|
|
format( field, aNestLevel + 1 );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, ")\n" );
|
2020-08-08 21:47:57 +00:00
|
|
|
}
|
2023-09-29 16:02:57 +00:00
|
|
|
|
|
|
|
if( !aFootprint->GetFilters().empty() )
|
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel + 1, "(property ki_fp_filters %s)\n",
|
|
|
|
m_out->Quotew( aFootprint->GetFilters() ).c_str() );
|
|
|
|
}
|
2020-08-08 21:47:57 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_PATH ) && !aFootprint->GetPath().empty() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(path %s)\n",
|
2020-11-13 02:09:34 +00:00
|
|
|
m_out->Quotew( aFootprint->GetPath().AsString() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-06-19 13:26:33 +00:00
|
|
|
if( !aFootprint->GetSheetname().empty() )
|
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel + 1, "(sheetname %s)\n",
|
|
|
|
m_out->Quotew( aFootprint->GetSheetname() ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aFootprint->GetSheetfile().empty() )
|
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel + 1, "(sheetfile %s)\n",
|
|
|
|
m_out->Quotew( aFootprint->GetSheetfile() ).c_str() );
|
|
|
|
}
|
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aFootprint->GetLocalSolderMaskMargin().has_value() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
|
2024-01-10 11:28:29 +00:00
|
|
|
formatInternalUnits( aFootprint->GetLocalSolderMaskMargin().value() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aFootprint->GetLocalSolderPasteMargin().has_value() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
|
2024-01-10 11:28:29 +00:00
|
|
|
formatInternalUnits( aFootprint->GetLocalSolderPasteMargin().value() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aFootprint->GetLocalSolderPasteMarginRatio().has_value() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2024-02-25 21:25:44 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_paste_margin_ratio %s)\n",
|
2024-01-10 11:28:29 +00:00
|
|
|
FormatDouble2Str( aFootprint->GetLocalSolderPasteMarginRatio().value() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aFootprint->GetLocalClearance().has_value() )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(clearance %s)\n",
|
2024-01-10 11:28:29 +00:00
|
|
|
formatInternalUnits( aFootprint->GetLocalClearance().value() ).c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aFootprint->GetLocalZoneConnection() != ZONE_CONNECTION::INHERITED )
|
2022-08-19 17:34:53 +00:00
|
|
|
{
|
2019-12-28 07:43:29 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(zone_connect %d)\n",
|
2024-01-10 11:28:29 +00:00
|
|
|
static_cast<int>( aFootprint->GetLocalZoneConnection() ) );
|
2022-08-19 17:34:53 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
// Attributes
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFootprint->GetAttributes() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel+1, "(attr" );
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_SMD )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " smd" );
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
|
2020-08-26 21:43:38 +00:00
|
|
|
m_out->Print( 0, " through_hole" );
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_BOARD_ONLY )
|
2020-08-26 21:43:38 +00:00
|
|
|
m_out->Print( 0, " board_only" );
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES )
|
2020-08-28 10:06:55 +00:00
|
|
|
m_out->Print( 0, " exclude_from_pos_files" );
|
2020-08-26 21:43:38 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_BOM )
|
2020-08-27 23:52:58 +00:00
|
|
|
m_out->Print( 0, " exclude_from_bom" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-12-07 19:24:26 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_ALLOW_MISSING_COURTYARD )
|
|
|
|
m_out->Print( 0, " allow_missing_courtyard" );
|
|
|
|
|
2023-04-10 17:10:42 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_DNP )
|
|
|
|
m_out->Print( 0, " dnp" );
|
|
|
|
|
2021-08-12 16:58:30 +00:00
|
|
|
if( aFootprint->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES )
|
|
|
|
m_out->Print( 0, " allow_soldermask_bridges" );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2021-12-05 21:56:55 +00:00
|
|
|
if( aFootprint->GetPrivateLayers().any() )
|
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel+1, "(private_layers" );
|
|
|
|
|
|
|
|
for( PCB_LAYER_ID layer : aFootprint->GetPrivateLayers().Seq() )
|
|
|
|
{
|
|
|
|
wxString canonicalName( LSET::Name( layer ) );
|
|
|
|
m_out->Print( 0, " \"%s\"", canonicalName.ToStdString().c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2022-08-19 17:34:53 +00:00
|
|
|
if( aFootprint->IsNetTie() )
|
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel+1, "(net_tie_pad_groups" );
|
|
|
|
|
|
|
|
for( const wxString& group : aFootprint->GetNetTiePadGroups() )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " \"%s\"", EscapeString( group, CTX_QUOTED_STR ).ToStdString().c_str() );
|
2022-08-19 17:34:53 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2021-04-20 14:18:31 +00:00
|
|
|
Format( (BOARD_ITEM*) &aFootprint->Reference(), aNestLevel + 1 );
|
|
|
|
Format( (BOARD_ITEM*) &aFootprint->Value(), aNestLevel + 1 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::set<PAD*, FOOTPRINT::cmp_pads> sorted_pads( aFootprint->Pads().begin(),
|
|
|
|
aFootprint->Pads().end() );
|
2021-04-20 14:18:31 +00:00
|
|
|
std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> sorted_drawings(
|
|
|
|
aFootprint->GraphicalItems().begin(),
|
|
|
|
aFootprint->GraphicalItems().end() );
|
2023-03-30 11:49:23 +00:00
|
|
|
std::set<ZONE*, FOOTPRINT::cmp_zones> sorted_zones( aFootprint->Zones().begin(),
|
|
|
|
aFootprint->Zones().end() );
|
2020-11-13 02:09:34 +00:00
|
|
|
std::set<BOARD_ITEM*, PCB_GROUP::ptr_cmp> sorted_groups( aFootprint->Groups().begin(),
|
|
|
|
aFootprint->Groups().end() );
|
2020-07-24 22:08:36 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// Save drawing elements.
|
2020-07-24 22:08:36 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
for( BOARD_ITEM* gr : sorted_drawings )
|
2019-11-25 07:02:16 +00:00
|
|
|
Format( gr, aNestLevel+1 );
|
|
|
|
|
|
|
|
// Save pads.
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : sorted_pads )
|
2020-07-24 22:08:36 +00:00
|
|
|
Format( pad, aNestLevel+1 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
// Save zones.
|
2020-10-03 11:16:29 +00:00
|
|
|
for( BOARD_ITEM* zone : sorted_zones )
|
2020-07-24 22:08:36 +00:00
|
|
|
Format( zone, aNestLevel + 1 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-10-03 11:16:29 +00:00
|
|
|
// Save groups.
|
|
|
|
for( BOARD_ITEM* group : sorted_groups )
|
|
|
|
Format( group, aNestLevel + 1 );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// Save 3D info.
|
2020-11-13 02:09:34 +00:00
|
|
|
auto bs3D = aFootprint->Models().begin();
|
|
|
|
auto es3D = aFootprint->Models().end();
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
while( bs3D != es3D )
|
|
|
|
{
|
|
|
|
if( !bs3D->m_Filename.IsEmpty() )
|
|
|
|
{
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(model %s\n",
|
|
|
|
m_out->Quotew( bs3D->m_Filename ).c_str() );
|
|
|
|
|
|
|
|
if( !bs3D->m_Show )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "hide", !bs3D->m_Show );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-04-19 17:23:40 +00:00
|
|
|
if( bs3D->m_Opacity != 1.0 )
|
|
|
|
m_out->Print( aNestLevel+2, "(opacity %0.4f)", bs3D->m_Opacity );
|
|
|
|
|
2020-07-24 12:01:30 +00:00
|
|
|
m_out->Print( aNestLevel+2, "(offset (xyz %s %s %s))\n",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( bs3D->m_Offset.x ).c_str(),
|
|
|
|
FormatDouble2Str( bs3D->m_Offset.y ).c_str(),
|
|
|
|
FormatDouble2Str( bs3D->m_Offset.z ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( bs3D->m_Scale.x ).c_str(),
|
|
|
|
FormatDouble2Str( bs3D->m_Scale.y ).c_str(),
|
|
|
|
FormatDouble2Str( bs3D->m_Scale.z ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( bs3D->m_Rotation.x ).c_str(),
|
|
|
|
FormatDouble2Str( bs3D->m_Rotation.y ).c_str(),
|
|
|
|
FormatDouble2Str( bs3D->m_Rotation.z ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
|
|
|
}
|
2021-04-20 14:18:31 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
++bs3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::formatLayers( LSET aLayerMask, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-12-20 18:50:45 +00:00
|
|
|
std::string output;
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( aNestLevel == 0 )
|
|
|
|
output += ' ';
|
|
|
|
|
|
|
|
output += "(layers";
|
|
|
|
|
|
|
|
static const LSET cu_all( LSET::AllCuMask() );
|
2021-04-20 14:18:31 +00:00
|
|
|
static const LSET fr_bk( 2, B_Cu, F_Cu );
|
|
|
|
static const LSET adhes( 2, B_Adhes, F_Adhes );
|
|
|
|
static const LSET paste( 2, B_Paste, F_Paste );
|
|
|
|
static const LSET silks( 2, B_SilkS, F_SilkS );
|
|
|
|
static const LSET mask( 2, B_Mask, F_Mask );
|
|
|
|
static const LSET crt_yd( 2, B_CrtYd, F_CrtYd );
|
|
|
|
static const LSET fab( 2, B_Fab, F_Fab );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
LSET cu_mask = cu_all;
|
|
|
|
|
|
|
|
// output copper layers first, then non copper
|
|
|
|
|
|
|
|
if( ( aLayerMask & cu_mask ) == cu_mask )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.Cu" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~cu_all; // clear bits, so they are not output again below
|
|
|
|
}
|
|
|
|
else if( ( aLayerMask & cu_mask ) == fr_bk )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "F&B.Cu" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~fr_bk;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & adhes ) == adhes )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.Adhes" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~adhes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & paste ) == paste )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.Paste" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~paste;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & silks ) == silks )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.SilkS" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~silks;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & mask ) == mask )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.Mask" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & crt_yd ) == crt_yd )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.CrtYd" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~crt_yd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & fab ) == fab )
|
|
|
|
{
|
2022-12-28 14:39:59 +00:00
|
|
|
output += ' ' + m_out->Quotew( "*.Fab" );
|
2019-11-25 07:02:16 +00:00
|
|
|
aLayerMask &= ~fab;
|
|
|
|
}
|
|
|
|
|
|
|
|
// output any individual layers not handled in wildcard combos above
|
|
|
|
wxString layerName;
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
if( aLayerMask[layer] )
|
|
|
|
{
|
2020-09-22 21:50:59 +00:00
|
|
|
layerName = LSET::Name( PCB_LAYER_ID( layer ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
output += ' ';
|
|
|
|
output += m_out->Quotew( layerName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "%s)", output.c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PAD* aPad, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2022-10-18 12:00:37 +00:00
|
|
|
const BOARD* board = aPad->GetBoard();
|
|
|
|
const char* shape;
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
switch( aPad->GetShape() )
|
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE: shape = "circle"; break;
|
2024-01-15 17:29:55 +00:00
|
|
|
case PAD_SHAPE::RECTANGLE: shape = "rect"; break;
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::OVAL: shape = "oval"; break;
|
|
|
|
case PAD_SHAPE::TRAPEZOID: shape = "trapezoid"; break;
|
|
|
|
case PAD_SHAPE::CHAMFERED_RECT:
|
|
|
|
case PAD_SHAPE::ROUNDRECT: shape = "roundrect"; break;
|
|
|
|
case PAD_SHAPE::CUSTOM: shape = "custom"; break;
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* type;
|
|
|
|
|
|
|
|
switch( aPad->GetAttribute() )
|
|
|
|
{
|
2021-05-01 14:46:50 +00:00
|
|
|
case PAD_ATTRIB::PTH: type = "thru_hole"; break;
|
|
|
|
case PAD_ATTRIB::SMD: type = "smd"; break;
|
|
|
|
case PAD_ATTRIB::CONN: type = "connect"; break;
|
|
|
|
case PAD_ATTRIB::NPTH: type = "np_thru_hole"; break;
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
default:
|
2022-02-04 22:44:59 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "unknown pad attribute: %d" ),
|
|
|
|
aPad->GetAttribute() ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 10:36:45 +00:00
|
|
|
const char* property = nullptr;
|
|
|
|
|
|
|
|
switch( aPad->GetProperty() )
|
|
|
|
{
|
2021-05-01 14:58:30 +00:00
|
|
|
case PAD_PROP::NONE: break; // could be "none"
|
2021-09-06 07:15:18 +00:00
|
|
|
case PAD_PROP::BGA: property = "pad_prop_bga"; break;
|
2021-05-01 14:58:30 +00:00
|
|
|
case PAD_PROP::FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
|
|
|
|
case PAD_PROP::FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
|
2021-09-06 07:15:18 +00:00
|
|
|
case PAD_PROP::TESTPOINT: property = "pad_prop_testpoint"; break;
|
|
|
|
case PAD_PROP::HEATSINK: property = "pad_prop_heatsink"; break;
|
|
|
|
case PAD_PROP::CASTELLATED: property = "pad_prop_castellated"; break;
|
2024-03-04 21:42:57 +00:00
|
|
|
case PAD_PROP::MECHANICAL: property = "pad_prop_mechanical"; break;
|
2019-12-11 10:36:45 +00:00
|
|
|
|
|
|
|
default:
|
2022-02-04 22:44:59 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "unknown pad property: %d" ),
|
|
|
|
aPad->GetProperty() ) );
|
2019-12-11 10:36:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel, "(pad %s %s %s",
|
2021-08-23 23:10:21 +00:00
|
|
|
m_out->Quotew( aPad->GetNumber() ).c_str(),
|
2021-01-26 15:27:42 +00:00
|
|
|
type,
|
|
|
|
shape );
|
2021-04-21 18:58:26 +00:00
|
|
|
|
2023-04-02 17:02:41 +00:00
|
|
|
m_out->Print( 0, " (at %s", formatInternalUnits( aPad->GetFPRelativePosition() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
if( !aPad->GetOrientation().IsZero() )
|
2022-08-29 23:30:25 +00:00
|
|
|
m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aPad->GetOrientation() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
2021-01-08 16:32:28 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " (size %s)", formatInternalUnits( aPad->GetSize() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-05 01:42:27 +00:00
|
|
|
if( (aPad->GetDelta().x) != 0 || (aPad->GetDelta().y != 0 ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " (rect_delta %s)", formatInternalUnits( aPad->GetDelta() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-05 01:42:27 +00:00
|
|
|
VECTOR2I sz = aPad->GetDrillSize();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I shapeoffset = aPad->GetOffset();
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-05 01:42:27 +00:00
|
|
|
if( (sz.x > 0) || (sz.y > 0) ||
|
2019-11-25 07:02:16 +00:00
|
|
|
(shapeoffset.x != 0) || (shapeoffset.y != 0) )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (drill" );
|
|
|
|
|
2024-04-07 22:01:08 +00:00
|
|
|
if( aPad->GetDrillShape() == PAD_DRILL_SHAPE::OBLONG )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " oval" );
|
|
|
|
|
2022-01-05 01:42:27 +00:00
|
|
|
if( sz.x > 0 )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " %s", formatInternalUnits( sz.x ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-05 01:42:27 +00:00
|
|
|
if( sz.y > 0 && sz.x != sz.y )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " %s", formatInternalUnits( sz.y ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " (offset %s)", formatInternalUnits( aPad->GetOffset() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
|
|
|
|
2020-07-23 12:33:24 +00:00
|
|
|
// Add pad property, if exists.
|
|
|
|
if( property )
|
2019-12-11 10:36:45 +00:00
|
|
|
m_out->Print( 0, " (property %s)", property );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
formatLayers( aPad->GetLayerSet() );
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
|
2020-07-27 19:41:50 +00:00
|
|
|
{
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "remove_unused_layers", aPad->GetRemoveUnconnected() );
|
|
|
|
|
2020-07-27 19:41:50 +00:00
|
|
|
if( aPad->GetRemoveUnconnected() )
|
|
|
|
{
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "keep_end_layers", aPad->GetKeepTopBottom() );
|
2022-10-18 12:00:37 +00:00
|
|
|
|
2022-11-08 12:09:08 +00:00
|
|
|
if( board ) // Will be nullptr in footprint library
|
2022-10-18 12:00:37 +00:00
|
|
|
{
|
2022-11-08 12:09:08 +00:00
|
|
|
m_out->Print( 0, " (zone_layer_connections" );
|
2022-10-18 12:00:37 +00:00
|
|
|
|
2022-11-08 12:09:08 +00:00
|
|
|
for( LSEQ cu = board->GetEnabledLayers().CuStack(); cu; ++cu )
|
|
|
|
{
|
2023-02-05 13:07:30 +00:00
|
|
|
if( aPad->GetZoneLayerOverride( *cu ) == ZLO_FORCE_FLASHED )
|
2022-11-08 12:09:08 +00:00
|
|
|
m_out->Print( 0, " %s", m_out->Quotew( LSET::Name( *cu ) ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
2020-07-27 19:41:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// Output the radius ratio for rounded and chamfered rect pads
|
2021-05-01 12:22:35 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::ROUNDRECT || aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT)
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, " (roundrect_rratio %s)",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output the chamfer corners for chamfered rect pads
|
2021-05-01 12:22:35 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CHAMFERED_RECT)
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(chamfer_ratio %s)",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( aPad->GetChamferRectRatio() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, " (chamfer" );
|
|
|
|
|
|
|
|
if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_LEFT ) )
|
|
|
|
m_out->Print( 0, " top_left" );
|
|
|
|
|
|
|
|
if( ( aPad->GetChamferPositions() & RECT_CHAMFER_TOP_RIGHT ) )
|
|
|
|
m_out->Print( 0, " top_right" );
|
|
|
|
|
|
|
|
if( ( aPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_LEFT ) )
|
|
|
|
m_out->Print( 0, " bottom_left" );
|
|
|
|
|
|
|
|
if( ( aPad->GetChamferPositions() & RECT_CHAMFER_BOTTOM_RIGHT ) )
|
|
|
|
m_out->Print( 0, " bottom_right" );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string output;
|
|
|
|
|
|
|
|
// Unconnected pad is default net so don't save it.
|
2020-12-28 00:42:04 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_PAD_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
|
|
|
|
m_out->Quotew( aPad->GetNetname() ).c_str() );
|
2023-09-01 22:46:14 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-01-26 15:27:42 +00:00
|
|
|
// Pin functions and types are closely related to nets, so if CTL_OMIT_NETS is set, omit
|
|
|
|
// them as well (for instance when saved from library editor).
|
|
|
|
if( !( m_ctl & CTL_OMIT_PAD_NETS ) )
|
|
|
|
{
|
|
|
|
if( !aPad->GetPinFunction().IsEmpty() )
|
|
|
|
{
|
|
|
|
StrPrintf( &output, " (pinfunction %s)",
|
|
|
|
m_out->Quotew( aPad->GetPinFunction() ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aPad->GetPinType().IsEmpty() )
|
|
|
|
{
|
|
|
|
StrPrintf( &output, " (pintype %s)",
|
|
|
|
m_out->Quotew( aPad->GetPinType() ).c_str() );
|
|
|
|
}
|
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( aPad->GetPadToDieLength() != 0 )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
StrPrintf( &output, " (die_length %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aPad->GetLocalSolderMaskMargin().has_value() )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
StrPrintf( &output, " (solder_mask_margin %s)",
|
2024-01-10 11:28:29 +00:00
|
|
|
formatInternalUnits( aPad->GetLocalSolderMaskMargin().value() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aPad->GetLocalSolderPasteMargin().has_value() )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
StrPrintf( &output, " (solder_paste_margin %s)",
|
2024-01-10 11:28:29 +00:00
|
|
|
formatInternalUnits( aPad->GetLocalSolderPasteMargin().value() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aPad->GetLocalSolderPasteMarginRatio().has_value() )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
StrPrintf( &output, " (solder_paste_margin_ratio %s)",
|
2024-01-10 11:28:29 +00:00
|
|
|
FormatDouble2Str( aPad->GetLocalSolderPasteMarginRatio().value() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aPad->GetLocalClearance().has_value() )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2020-09-10 18:35:11 +00:00
|
|
|
StrPrintf( &output, " (clearance %s)",
|
2024-01-10 11:28:29 +00:00
|
|
|
formatInternalUnits( aPad->GetLocalClearance().value() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
if( aPad->GetLocalZoneConnection() != ZONE_CONNECTION::INHERITED )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2020-09-10 18:35:11 +00:00
|
|
|
StrPrintf( &output, " (zone_connect %d)",
|
2024-01-10 11:28:29 +00:00
|
|
|
static_cast<int>( aPad->GetLocalZoneConnection() ) );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-09-10 18:35:11 +00:00
|
|
|
if( aPad->GetThermalSpokeWidth() != 0 )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2021-08-08 13:37:14 +00:00
|
|
|
StrPrintf( &output, " (thermal_bridge_width %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aPad->GetThermalSpokeWidth() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-10 14:30:48 +00:00
|
|
|
EDA_ANGLE defaultThermalSpokeAngle = ANGLE_90;
|
|
|
|
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CIRCLE ||
|
|
|
|
( aPad->GetShape() == PAD_SHAPE::CUSTOM && aPad->GetAnchorPadShape() == PAD_SHAPE::CIRCLE ) )
|
|
|
|
{
|
|
|
|
defaultThermalSpokeAngle = ANGLE_45;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aPad->GetThermalSpokeAngle() != defaultThermalSpokeAngle )
|
2021-08-08 13:37:14 +00:00
|
|
|
{
|
|
|
|
StrPrintf( &output, " (thermal_bridge_angle %s)",
|
2022-08-29 23:30:25 +00:00
|
|
|
EDA_UNIT_UTILS::FormatAngle( aPad->GetThermalSpokeAngle() ).c_str() );
|
2021-08-08 13:37:14 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
if( aPad->GetThermalGap() != 0 )
|
2021-01-26 15:27:42 +00:00
|
|
|
{
|
2020-09-10 18:35:11 +00:00
|
|
|
StrPrintf( &output, " (thermal_gap %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aPad->GetThermalGap() ).c_str() );
|
2021-01-26 15:27:42 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( output.size() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
|
|
|
|
}
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
m_out->Print( aNestLevel+1, "(options" );
|
|
|
|
|
2024-04-08 13:09:20 +00:00
|
|
|
if( aPad->GetCustomShapeInZoneOpt() == PADSTACK::CUSTOM_SHAPE_ZONE_MODE::CONVEXHULL )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " (clearance convexhull)" );
|
|
|
|
#if 1 // Set to 1 to output the default option
|
|
|
|
else
|
|
|
|
m_out->Print( 0, " (clearance outline)" );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Output the anchor pad shape (circle/rect)
|
2023-06-02 09:10:48 +00:00
|
|
|
if( aPad->GetAnchorPadShape() == PAD_SHAPE::RECTANGLE )
|
2019-11-25 07:02:16 +00:00
|
|
|
shape = "rect";
|
|
|
|
else
|
|
|
|
shape = "circle";
|
|
|
|
|
|
|
|
m_out->Print( 0, " (anchor %s)", shape );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")"); // end of (options ...
|
|
|
|
|
|
|
|
// Output graphic primitive of the pad shape
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
m_out->Print( aNestLevel+1, "(primitives" );
|
|
|
|
|
|
|
|
int nested_level = aNestLevel+2;
|
|
|
|
|
|
|
|
// Output all basic shapes
|
2020-10-04 23:34:59 +00:00
|
|
|
for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
|
2020-06-24 11:12:39 +00:00
|
|
|
switch( primitive->GetShape() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2023-09-13 17:27:00 +00:00
|
|
|
if( primitive->IsProxyItem() )
|
|
|
|
{
|
|
|
|
m_out->Print( nested_level, "(gr_vector (start %s) (end %s)",
|
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_out->Print( nested_level, "(gr_line (start %s) (end %s)",
|
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2023-09-13 10:27:04 +00:00
|
|
|
if( primitive->IsProxyItem() )
|
2022-09-14 10:34:10 +00:00
|
|
|
{
|
|
|
|
m_out->Print( nested_level, "(gr_bbox (start %s) (end %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
2022-09-14 10:34:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_out->Print( nested_level, "(gr_rect (start %s) (end %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
2022-09-14 10:34:10 +00:00
|
|
|
}
|
2020-06-19 13:07:50 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2022-01-11 21:03:45 +00:00
|
|
|
m_out->Print( nested_level, "(gr_arc (start %s) (mid %s) (end %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetArcMid() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2020-11-14 01:16:02 +00:00
|
|
|
m_out->Print( nested_level, "(gr_circle (center %s) (end %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2020-11-14 01:16:02 +00:00
|
|
|
m_out->Print( nested_level, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( primitive->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetBezierC1() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetBezierC2() ).c_str(),
|
|
|
|
formatInternalUnits( primitive->GetEnd() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2021-08-01 00:14:02 +00:00
|
|
|
if( primitive->IsPolyShapeValid() )
|
|
|
|
{
|
|
|
|
const SHAPE_POLY_SET& poly = primitive->GetPolyShape();
|
|
|
|
const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
m_out->Print( nested_level, "(gr_poly\n" );
|
|
|
|
formatPolyPts( outline, nested_level, ADVANCED_CFG::GetCfg().m_CompactSave );
|
2023-06-21 17:42:24 +00:00
|
|
|
|
|
|
|
// Align the next info at the right place.
|
|
|
|
m_out->Print( nested_level, " " );
|
2021-08-01 00:14:02 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-11-14 01:16:02 +00:00
|
|
|
|
2023-09-13 17:27:00 +00:00
|
|
|
if( !primitive->IsProxyItem() )
|
|
|
|
m_out->Print( 0, " (width %s)", formatInternalUnits( primitive->GetWidth() ).c_str() );
|
2020-11-14 01:16:02 +00:00
|
|
|
|
2022-07-15 14:33:01 +00:00
|
|
|
// The filled flag represents if a solid fill is present on circles,
|
|
|
|
// rectangles and polygons
|
|
|
|
if( ( primitive->GetShape() == SHAPE_T::POLY )
|
2023-07-24 16:07:56 +00:00
|
|
|
|| ( primitive->GetShape() == SHAPE_T::RECTANGLE )
|
2022-07-15 14:33:01 +00:00
|
|
|
|| ( primitive->GetShape() == SHAPE_T::CIRCLE ) )
|
|
|
|
{
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "fill", primitive->IsFilled() );
|
2022-07-15 14:33:01 +00:00
|
|
|
}
|
2022-07-15 15:01:21 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
2023-06-21 17:42:24 +00:00
|
|
|
m_out->Print( aNestLevel+1, ")" ); // end of (primitives
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !isDefaultTeardropParameters( aPad->GetTeardropParams() ) )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
formatTeardropParameters( aPad->GetTeardropParams(), aNestLevel+1 );
|
|
|
|
}
|
|
|
|
|
2023-06-21 17:42:24 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aPad->m_Uuid );
|
2023-06-21 17:42:24 +00:00
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_TEXT* aText, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* parentFP = aText->GetParentFootprint();
|
|
|
|
std::string prefix;
|
|
|
|
std::string type;
|
2023-04-30 21:45:00 +00:00
|
|
|
VECTOR2I pos = aText->GetTextPos();
|
2023-06-12 14:02:28 +00:00
|
|
|
bool isField = dynamic_cast<const PCB_FIELD*>( aText ) != nullptr;
|
2022-03-08 16:35:26 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
// Always format dimension text as gr_text
|
|
|
|
if( dynamic_cast<const PCB_DIMENSION_BASE*>( aText ) )
|
|
|
|
parentFP = nullptr;
|
2022-03-08 16:35:26 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP )
|
|
|
|
{
|
|
|
|
prefix = "fp";
|
2023-06-06 17:30:03 +00:00
|
|
|
type = " user";
|
2023-04-30 21:45:00 +00:00
|
|
|
|
|
|
|
pos -= parentFP->GetPosition();
|
|
|
|
RotatePoint( pos, -parentFP->GetOrientation() );
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prefix = "gr";
|
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-06-12 14:02:28 +00:00
|
|
|
if( !isField )
|
|
|
|
{
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s_text%s %s", prefix.c_str(), type.c_str(),
|
2023-06-12 14:02:28 +00:00
|
|
|
m_out->Quotew( aText->GetText() ).c_str() );
|
2023-09-24 16:53:34 +00:00
|
|
|
|
|
|
|
if( aText->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", aText->IsLocked() );
|
2023-06-12 14:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, " (at %s", formatInternalUnits( pos ).c_str() );
|
2022-03-08 16:35:26 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
// Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle.
|
2023-06-27 06:53:04 +00:00
|
|
|
// To avoid issues in the future, always save the angle, even if it is 0
|
|
|
|
m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( parentFP && !aText->IsKeepUpright() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "unlocked", !aText->IsKeepUpright() );
|
|
|
|
|
2022-03-08 13:16:39 +00:00
|
|
|
formatLayer( aText->GetLayer(), aText->IsKnockout() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( parentFP && !aText->IsVisible() )
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "hide", !aText->IsVisible() );
|
2023-03-30 11:49:23 +00:00
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aText->m_Uuid );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-07-18 12:58:21 +00:00
|
|
|
aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
if( aText->GetFont() && aText->GetFont()->IsOutline() )
|
|
|
|
formatRenderCache( aText, aNestLevel + 1 );
|
|
|
|
|
2023-06-12 14:02:28 +00:00
|
|
|
if( !isField )
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) const
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* parentFP = aTextBox->GetParentFootprint();
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(%s %s\n",
|
2024-01-15 17:29:55 +00:00
|
|
|
aTextBox->Type() == PCB_TABLECELL_T ? "table_cell"
|
|
|
|
: parentFP ? "fp_text_box"
|
|
|
|
: "gr_text_box",
|
2022-01-30 10:52:52 +00:00
|
|
|
m_out->Quotew( aTextBox->GetText() ).c_str() );
|
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( aTextBox->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel, "locked", aTextBox->IsLocked() );
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
if( aTextBox->GetShape() == SHAPE_T::RECTANGLE )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2023-08-31 02:47:10 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(start %s) (end %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aTextBox->GetStart(), parentFP ).c_str(),
|
|
|
|
formatInternalUnits( aTextBox->GetEnd(), parentFP ).c_str() );
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
|
|
|
else if( aTextBox->GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
const SHAPE_POLY_SET& poly = aTextBox->GetPolyShape();
|
|
|
|
const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
formatPolyPts( outline, aNestLevel, true, parentFP );
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED_FOR( aTextBox->SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
|
2024-01-20 17:05:21 +00:00
|
|
|
m_out->Print( 0, " (margins %s %s %s %s)",
|
|
|
|
formatInternalUnits( aTextBox->GetMarginLeft() ).c_str(),
|
|
|
|
formatInternalUnits( aTextBox->GetMarginTop() ).c_str(),
|
|
|
|
formatInternalUnits( aTextBox->GetMarginRight() ).c_str(),
|
|
|
|
formatInternalUnits( aTextBox->GetMarginBottom() ).c_str() );
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
if( const PCB_TABLECELL* cell = dynamic_cast<const PCB_TABLECELL*>( aTextBox ) )
|
|
|
|
m_out->Print( 0, " (span %d %d)", cell->GetColSpan(), cell->GetRowSpan() );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
EDA_ANGLE angle = aTextBox->GetTextAngle();
|
|
|
|
|
|
|
|
if( parentFP )
|
|
|
|
{
|
|
|
|
angle -= parentFP->GetOrientation();
|
|
|
|
angle.Normalize720();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !angle.IsZero() )
|
|
|
|
m_out->Print( aNestLevel + 1, "(angle %s)", EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2022-02-18 13:24:21 +00:00
|
|
|
formatLayer( aTextBox->GetLayer() );
|
2023-08-31 02:47:10 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aTextBox->m_Uuid );
|
2022-01-30 10:52:52 +00:00
|
|
|
|
|
|
|
// PCB_TEXTBOXes are never hidden, so always omit "hide" attribute
|
2023-03-30 11:49:23 +00:00
|
|
|
aTextBox->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
|
2022-02-01 15:30:15 +00:00
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
if( aTextBox->Type() != PCB_TABLECELL_T )
|
|
|
|
{
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "border", aTextBox->IsBorderEnabled() );
|
2023-08-31 02:33:55 +00:00
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
aTextBox->GetStroke().Format( m_out, pcbIUScale, aNestLevel + 1 );
|
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
|
|
|
if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() )
|
|
|
|
formatRenderCache( aTextBox, aNestLevel + 1 );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_TABLE* aTable, int aNestLevel ) const
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aTable != nullptr && m_out != nullptr, "" );
|
|
|
|
|
2024-06-19 11:39:02 +00:00
|
|
|
m_out->Print( aNestLevel, "(table (column_count %d)",
|
2024-01-15 17:29:55 +00:00
|
|
|
aTable->GetColCount() );
|
|
|
|
|
|
|
|
if( aTable->IsLocked() )
|
2024-06-19 11:39:02 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", aTable->IsLocked() );
|
|
|
|
|
|
|
|
EDA_ANGLE angle = aTable->GetOrientation();
|
|
|
|
|
|
|
|
if( FOOTPRINT* parentFP = aTable->GetParentFootprint() )
|
|
|
|
{
|
|
|
|
angle -= parentFP->GetOrientation();
|
|
|
|
angle.Normalize720();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !angle.IsZero() )
|
|
|
|
m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
|
2024-01-15 17:29:55 +00:00
|
|
|
|
|
|
|
formatLayer( aTable->GetLayer() );
|
|
|
|
|
2024-06-19 11:39:02 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(border (external %s) (header %s)",
|
|
|
|
aTable->StrokeExternal() ? "yes" : "no",
|
|
|
|
aTable->StrokeHeader() ? "yes" : "no" );
|
|
|
|
|
|
|
|
if( aTable->StrokeExternal() || aTable->StrokeHeader() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " " );
|
|
|
|
aTable->GetBorderStroke().Format( m_out, pcbIUScale, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(separators (rows %s) (cols %s)",
|
|
|
|
aTable->StrokeRows() ? "yes" : "no",
|
|
|
|
aTable->StrokeColumns() ? "yes" : "no" );
|
|
|
|
|
|
|
|
if( aTable->StrokeRows() || aTable->StrokeColumns() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " " );
|
|
|
|
aTable->GetSeparatorsStroke().Format( m_out, pcbIUScale, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" ); // Close `separators` token.
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(column_widths" );
|
|
|
|
|
|
|
|
for( int col = 0; col < aTable->GetColCount(); ++col )
|
|
|
|
m_out->Print( 0, " %s", formatInternalUnits( aTable->GetColWidth( col ) ).c_str() );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(row_heights" );
|
|
|
|
|
|
|
|
for( int row = 0; row < aTable->GetRowCount(); ++row )
|
|
|
|
m_out->Print( 0, " %s", formatInternalUnits( aTable->GetRowHeight( row ) ).c_str() );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(cells\n" );
|
|
|
|
|
|
|
|
for( PCB_TABLECELL* cell : aTable->GetCells() )
|
|
|
|
format( static_cast<PCB_TEXTBOX*>( cell ), aNestLevel + 2 );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, ")\n" ); // Close `cells` token.
|
|
|
|
m_out->Print( aNestLevel, ")\n" ); // Close `table` token.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_GROUP* aGroup, int aNestLevel ) const
|
2020-08-11 19:37:07 +00:00
|
|
|
{
|
2020-09-25 17:37:03 +00:00
|
|
|
// Don't write empty groups
|
|
|
|
if( aGroup->GetItems().empty() )
|
|
|
|
return;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2023-12-15 13:33:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(group %s\n", m_out->Quotew( aGroup->GetName() ).c_str() );
|
|
|
|
|
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aGroup->m_Uuid );
|
2020-09-25 17:37:03 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( aGroup->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "locked", aGroup->IsLocked() );
|
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(members\n" );
|
|
|
|
|
|
|
|
wxArrayString memberIds;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : aGroup->GetItems() )
|
|
|
|
memberIds.Add( member->m_Uuid.AsString() );
|
|
|
|
|
|
|
|
memberIds.Sort();
|
|
|
|
|
|
|
|
for( const wxString& memberId : memberIds )
|
2023-09-27 23:05:30 +00:00
|
|
|
m_out->Print( aNestLevel + 2, "\"%s\"\n", TO_UTF8( memberId ) );
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2021-04-20 14:18:31 +00:00
|
|
|
m_out->Print( aNestLevel + 1, ")\n" ); // Close `members` token.
|
|
|
|
m_out->Print( aNestLevel, ")\n" ); // Close `group` token.
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_GENERATOR* aGenerator, int aNestLevel ) const
|
2023-10-07 01:55:45 +00:00
|
|
|
{
|
2023-12-15 13:33:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(generated\n" );
|
|
|
|
|
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aGenerator->m_Uuid );
|
2023-10-07 01:55:45 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(type %s) (name %s)\n",
|
|
|
|
TO_UTF8( aGenerator->GetGeneratorType() ),
|
|
|
|
m_out->Quotew( aGenerator->GetName() ).c_str() );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(layer %s)",
|
|
|
|
m_out->Quotew( LSET::Name( aGenerator->GetLayer() ) ).c_str() );
|
|
|
|
|
2023-12-12 20:47:15 +00:00
|
|
|
if( const bool locked = aGenerator->IsLocked() ) {
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", locked );
|
|
|
|
}
|
2023-10-07 01:55:45 +00:00
|
|
|
|
|
|
|
for( const auto& [key, value] : aGenerator->GetProperties() )
|
|
|
|
{
|
|
|
|
if( value.CheckType<double>() || value.CheckType<int>() || value.CheckType<long>()
|
|
|
|
|| value.CheckType<long long>() )
|
|
|
|
{
|
|
|
|
double val;
|
|
|
|
|
|
|
|
if( !value.GetAs( &val ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string buf = fmt::format( "{:.10g}", val );
|
|
|
|
|
|
|
|
// Don't quote numbers
|
|
|
|
m_out->Print( aNestLevel + 1, "(%s %s)\n", key.c_str(), buf.c_str() );
|
|
|
|
}
|
|
|
|
else if( value.CheckType<bool>() )
|
|
|
|
{
|
|
|
|
bool val;
|
|
|
|
value.GetAs( &val );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(%s %s)\n", key.c_str(), val ? "yes" : "no" );
|
|
|
|
}
|
|
|
|
else if( value.CheckType<VECTOR2I>() )
|
|
|
|
{
|
|
|
|
VECTOR2I val;
|
|
|
|
value.GetAs( &val );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(%s (xy %s))\n", key.c_str(),
|
|
|
|
formatInternalUnits( val ).c_str() );
|
|
|
|
}
|
|
|
|
else if( value.CheckType<SHAPE_LINE_CHAIN>() )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN val;
|
|
|
|
value.GetAs( &val );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(%s (pts\n", key.c_str() );
|
|
|
|
|
|
|
|
for( const VECTOR2I& pt : val.CPoints() )
|
|
|
|
m_out->Print( aNestLevel + 2, "(xy %s)\n", formatInternalUnits( pt ).c_str() );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "))\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString val;
|
|
|
|
|
|
|
|
if( value.CheckType<wxString>() )
|
|
|
|
{
|
|
|
|
value.GetAs( &val );
|
|
|
|
}
|
|
|
|
else if( value.CheckType<std::string>() )
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
value.GetAs( &str );
|
|
|
|
|
|
|
|
val = wxString::FromUTF8( str );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(%s %s)\n", key.c_str(), m_out->Quotew( val ).c_str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, "(members\n" );
|
|
|
|
|
|
|
|
wxArrayString memberIds;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : aGenerator->GetItems() )
|
|
|
|
memberIds.Add( member->m_Uuid.AsString() );
|
|
|
|
|
|
|
|
memberIds.Sort();
|
|
|
|
|
|
|
|
for( const wxString& memberId : memberIds )
|
|
|
|
m_out->Print( aNestLevel + 2, "%s\n", TO_UTF8( memberId ) );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel + 1, ")\n" ); // Close `members` token.
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" ); // Close `generator` token.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const PCB_TRACK* aTrack, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
if( aTrack->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer1, layer2;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_VIA* via = static_cast<const PCB_VIA*>( aTrack );
|
2022-10-18 12:00:37 +00:00
|
|
|
const BOARD* board = via->GetBoard();
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
wxCHECK_RET( board != nullptr, wxT( "Via has no parent." ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "(via" );
|
|
|
|
|
|
|
|
via->LayerPair( &layer1, &layer2 );
|
|
|
|
|
|
|
|
switch( via->GetViaType() )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
case VIATYPE::THROUGH: // Default shape not saved.
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case VIATYPE::BLIND_BURIED:
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " blind" );
|
|
|
|
break;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case VIATYPE::MICROVIA:
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " micro" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, " (at %s) (size %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aTrack->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( aTrack->GetWidth() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-02-26 19:24:59 +00:00
|
|
|
// Old boards were using UNDEFINED_DRILL_DIAMETER value in file for via drill when
|
|
|
|
// via drill was the netclass value.
|
|
|
|
// recent boards always set the via drill to the actual value, but now we need to
|
|
|
|
// always store the drill value, because netclass value is not stored in the board file.
|
|
|
|
// Otherwise the drill value of some (old) vias can be unknown
|
2019-11-25 07:02:16 +00:00
|
|
|
if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " (drill %s)", formatInternalUnits( via->GetDrill() ).c_str() );
|
|
|
|
else
|
|
|
|
m_out->Print( 0, " (drill %s)", formatInternalUnits( via->GetDrillValue() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, " (layers %s %s)",
|
2020-09-22 21:50:59 +00:00
|
|
|
m_out->Quotew( LSET::Name( layer1 ) ).c_str(),
|
|
|
|
m_out->Quotew( LSET::Name( layer2 ) ).c_str() );
|
2020-07-27 19:41:50 +00:00
|
|
|
|
2024-04-08 13:09:20 +00:00
|
|
|
switch( via->Padstack().UnconnectedLayerMode() )
|
2020-07-27 19:41:50 +00:00
|
|
|
{
|
2024-04-08 13:09:20 +00:00
|
|
|
case PADSTACK::UNCONNECTED_LAYER_MODE::REMOVE_ALL:
|
|
|
|
m_out->Print( 0, "(remove_unused_layers yes)" );
|
|
|
|
m_out->Print( 0, "(keep_end_layers no)" );
|
|
|
|
break;
|
2020-07-27 19:41:50 +00:00
|
|
|
|
2024-04-08 13:09:20 +00:00
|
|
|
case PADSTACK::UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END:
|
|
|
|
m_out->Print( 0, "(remove_unused_layers yes)" );
|
|
|
|
m_out->Print( 0, "(keep_end_layers yes)" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PADSTACK::UNCONNECTED_LAYER_MODE::KEEP_ALL:
|
|
|
|
break;
|
2020-07-27 19:41:50 +00:00
|
|
|
}
|
2020-12-20 21:29:43 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( via->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", via->IsLocked() );
|
|
|
|
|
2020-12-20 21:29:43 +00:00
|
|
|
if( via->GetIsFree() )
|
2023-09-24 16:53:34 +00:00
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "free", via->GetIsFree() );
|
2022-10-18 12:00:37 +00:00
|
|
|
|
|
|
|
if( via->GetRemoveUnconnected() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (zone_layer_connections" );
|
|
|
|
|
|
|
|
for( LSEQ cu = board->GetEnabledLayers().CuStack(); cu; ++cu )
|
|
|
|
{
|
2023-02-05 13:07:30 +00:00
|
|
|
if( via->GetZoneLayerOverride( *cu ) == ZLO_FORCE_FLASHED )
|
2022-10-18 12:00:37 +00:00
|
|
|
m_out->Print( 0, " %s", m_out->Quotew( LSET::Name( *cu ) ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
2023-05-12 21:03:54 +00:00
|
|
|
|
2024-06-18 21:49:00 +00:00
|
|
|
std::optional<bool> front = via->Padstack().FrontOuterLayers().has_solder_mask;
|
|
|
|
std::optional<bool> back = via->Padstack().BackOuterLayers().has_solder_mask;
|
2024-06-09 22:28:19 +00:00
|
|
|
|
2024-06-18 21:49:00 +00:00
|
|
|
if( front.has_value() || back.has_value() )
|
2024-06-09 22:28:19 +00:00
|
|
|
{
|
2024-06-18 21:49:00 +00:00
|
|
|
if( front.value_or( false ) || back.value_or( false ) )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (tenting " );
|
2024-06-09 22:28:19 +00:00
|
|
|
|
2024-06-18 21:49:00 +00:00
|
|
|
if( front.value_or( false ) )
|
|
|
|
m_out->Print( 0, " front" );
|
|
|
|
if( back.value_or( false ) )
|
|
|
|
m_out->Print( 0, " back" );
|
2024-06-09 22:28:19 +00:00
|
|
|
|
2024-06-18 21:49:00 +00:00
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (tenting none)" );
|
|
|
|
}
|
2024-06-09 16:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !isDefaultTeardropParameters( via->GetTeardropParams() ) )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
formatTeardropParameters( via->GetTeardropParams(), aNestLevel+1 );
|
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
2019-03-27 12:38:29 +00:00
|
|
|
else if( aTrack->Type() == PCB_ARC_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_ARC* arc = static_cast<const PCB_ARC*>( aTrack );
|
2019-03-27 12:38:29 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(arc (start %s) (mid %s) (end %s) (width %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( arc->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( arc->GetMid() ).c_str(),
|
|
|
|
formatInternalUnits( arc->GetEnd() ).c_str(),
|
|
|
|
formatInternalUnits( arc->GetWidth() ).c_str() );
|
2019-03-27 12:38:29 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( arc->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", arc->IsLocked() );
|
|
|
|
|
2020-09-22 21:50:59 +00:00
|
|
|
m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( arc->GetLayer() ) ).c_str() );
|
2019-03-27 12:38:29 +00:00
|
|
|
}
|
2019-11-25 07:02:16 +00:00
|
|
|
else
|
|
|
|
{
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aTrack->GetStart() ).c_str(),
|
|
|
|
formatInternalUnits( aTrack->GetEnd() ).c_str(),
|
|
|
|
formatInternalUnits( aTrack->GetWidth() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( aTrack->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", aTrack->IsLocked() );
|
|
|
|
|
2020-09-22 21:50:59 +00:00
|
|
|
m_out->Print( 0, " (layer %s)", m_out->Quotew( LSET::Name( aTrack->GetLayer() ) ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
|
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aTrack->m_Uuid );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::format( const ZONE* aZone, int aNestLevel ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2022-04-15 11:19:35 +00:00
|
|
|
// Save the NET info.
|
|
|
|
// For keepout and non copper zones, net code and net name are irrelevant
|
2020-11-11 23:05:59 +00:00
|
|
|
// so be sure a dummy value is stored, just for ZONE compatibility
|
2019-11-25 07:02:16 +00:00
|
|
|
// (perhaps netcode and netname should be not stored)
|
2022-04-15 11:19:35 +00:00
|
|
|
bool has_no_net = aZone->GetIsRuleArea() || !aZone->IsOnCopperLayer();
|
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
|
2022-04-15 11:19:35 +00:00
|
|
|
has_no_net ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
|
2023-02-12 21:29:26 +00:00
|
|
|
m_out->Quotew( has_no_net ? wxString( wxT("") ) : aZone->GetNetname() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-09-24 16:53:34 +00:00
|
|
|
if( aZone->IsLocked() )
|
|
|
|
KICAD_FORMAT::FormatBool( m_out, 0, "locked", aZone->IsLocked() );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// If a zone exists on multiple layers, format accordingly
|
2024-03-05 20:56:30 +00:00
|
|
|
LSET layers = aZone->GetLayerSet();
|
|
|
|
|
|
|
|
if( aZone->GetBoard() )
|
|
|
|
layers &= aZone->GetBoard()->GetEnabledLayers();
|
|
|
|
|
|
|
|
if( layers.count() > 1 )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2024-03-05 20:56:30 +00:00
|
|
|
formatLayers( layers );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-18 13:24:21 +00:00
|
|
|
formatLayer( aZone->GetFirstLayer() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 23:05:30 +00:00
|
|
|
KICAD_FORMAT::FormatUuid( m_out, aZone->m_Uuid );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-06-24 01:09:15 +00:00
|
|
|
if( !aZone->GetZoneName().empty() )
|
2020-06-26 02:19:51 +00:00
|
|
|
m_out->Print( 0, " (name %s)", m_out->Quotew( aZone->GetZoneName() ).c_str() );
|
2020-06-24 01:09:15 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
// Save the outline aux info
|
|
|
|
std::string hatch;
|
|
|
|
|
|
|
|
switch( aZone->GetHatchStyle() )
|
|
|
|
{
|
|
|
|
default:
|
2020-08-07 14:04:34 +00:00
|
|
|
case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: hatch = "none"; break;
|
|
|
|
case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: hatch = "edge"; break;
|
|
|
|
case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: hatch = "full"; break;
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aZone->GetBorderHatchPitch() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
if( aZone->GetAssignedPriority() > 0 )
|
|
|
|
m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetAssignedPriority() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-06-17 17:41:53 +00:00
|
|
|
// Add teardrop keywords in file: (attr (teardrop (type xxx)))where xxx is the teardrop type
|
2022-04-03 16:31:53 +00:00
|
|
|
if( aZone->IsTeardropArea() )
|
|
|
|
{
|
|
|
|
const char* td_type;
|
|
|
|
|
|
|
|
switch( aZone->GetTeardropAreaType() )
|
|
|
|
{
|
|
|
|
case TEARDROP_TYPE::TD_VIAPAD: // a teardrop on a via or pad
|
|
|
|
td_type = "padvia";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case TEARDROP_TYPE::TD_TRACKEND: // a teardrop on a track end
|
|
|
|
td_type = "track_end";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(attr (teardrop (type %s)))\n", td_type );
|
|
|
|
}
|
2022-06-17 17:41:53 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(connect_pads" );
|
|
|
|
|
|
|
|
switch( aZone->GetPadConnection() )
|
|
|
|
{
|
|
|
|
default:
|
2019-12-28 00:55:11 +00:00
|
|
|
case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
|
2019-11-25 07:02:16 +00:00
|
|
|
break;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case ZONE_CONNECTION::THT_THERMAL:
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " thru_hole_only" );
|
|
|
|
break;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case ZONE_CONNECTION::FULL:
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " yes" );
|
|
|
|
break;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
case ZONE_CONNECTION::NONE:
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " no" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
m_out->Print( 0, " (clearance %s))\n",
|
|
|
|
formatInternalUnits( aZone->GetLocalClearance().value() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2024-01-10 11:28:29 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(min_thickness %s)",
|
|
|
|
formatInternalUnits( aZone->GetMinThickness() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
// We continue to write this for 3rd-party parsers, but we no longer read it (as of V7).
|
|
|
|
m_out->Print( 0, " (filled_areas_thickness no)" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
if( aZone->GetIsRuleArea() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-04-20 14:18:31 +00:00
|
|
|
m_out->Print( aNestLevel + 1,
|
2022-07-11 15:21:29 +00:00
|
|
|
"(keepout (tracks %s) (vias %s) (pads %s) (copperpour %s) "
|
2021-04-20 14:18:31 +00:00
|
|
|
"(footprints %s))\n",
|
2019-11-25 07:02:16 +00:00
|
|
|
aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
|
|
|
|
aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
|
2020-05-07 00:30:46 +00:00
|
|
|
aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
|
|
|
|
aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
|
|
|
|
aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 14:18:31 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(fill" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
// Default is not filled.
|
|
|
|
if( aZone->IsFilled() )
|
|
|
|
m_out->Print( 0, " yes" );
|
|
|
|
|
|
|
|
// Default is polygon filled.
|
2019-12-20 14:11:39 +00:00
|
|
|
if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out->Print( 0, " (mode hatch)" );
|
|
|
|
|
|
|
|
m_out->Print( 0, " (thermal_gap %s) (thermal_bridge_width %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
|
|
|
|
formatInternalUnits( aZone->GetThermalReliefSpokeWidth() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( aZone->GetCornerSmoothingType() != ZONE_SETTINGS::SMOOTHING_NONE )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (smoothing" );
|
|
|
|
|
|
|
|
switch( aZone->GetCornerSmoothingType() )
|
|
|
|
{
|
|
|
|
case ZONE_SETTINGS::SMOOTHING_CHAMFER:
|
|
|
|
m_out->Print( 0, " chamfer" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZONE_SETTINGS::SMOOTHING_FILLET:
|
|
|
|
m_out->Print( 0, " fillet" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
|
|
|
|
aZone->GetCornerSmoothingType() ) );
|
|
|
|
}
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
|
|
|
|
if( aZone->GetCornerRadius() != 0 )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_out->Print( 0, " (radius %s)", formatInternalUnits( aZone->GetCornerRadius() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 02:19:51 +00:00
|
|
|
if( aZone->GetIslandRemovalMode() != ISLAND_REMOVAL_MODE::ALWAYS )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (island_removal_mode %d) (island_area_min %s)",
|
|
|
|
static_cast<int>( aZone->GetIslandRemovalMode() ),
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aZone->GetMinIslandArea() / pcbIUScale.IU_PER_MM ).c_str() );
|
2020-06-26 02:19:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel+2, "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
|
2023-03-30 11:49:23 +00:00
|
|
|
formatInternalUnits( aZone->GetHatchThickness() ).c_str(),
|
|
|
|
formatInternalUnits( aZone->GetHatchGap() ).c_str(),
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( aZone->GetHatchOrientation().AsDegrees() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
if( aZone->GetHatchSmoothingLevel() > 0 )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel+2, "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
|
2020-08-07 14:04:34 +00:00
|
|
|
aZone->GetHatchSmoothingLevel(),
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( aZone->GetHatchSmoothingValue() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
2020-08-07 14:04:34 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel+2, "(hatch_border_algorithm %s) (hatch_min_hole_area %s)",
|
|
|
|
aZone->GetHatchBorderAlgorithm() ? "hatch_thickness" : "min_thickness",
|
2022-09-17 03:35:16 +00:00
|
|
|
FormatDouble2Str( aZone->GetHatchHoleMinArea() ).c_str() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
|
|
|
|
if( aZone->GetNumCorners() )
|
|
|
|
{
|
2020-08-14 00:10:40 +00:00
|
|
|
SHAPE_POLY_SET::POLYGON poly = aZone->Outline()->Polygon(0);
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-08-14 00:10:40 +00:00
|
|
|
for( auto& chain : poly )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-08-14 00:10:40 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(polygon\n" );
|
2022-01-04 23:00:00 +00:00
|
|
|
formatPolyPts( chain, aNestLevel + 1, ADVANCED_CFG::GetCfg().m_CompactSave );
|
2020-12-20 18:50:45 +00:00
|
|
|
m_out->Print( aNestLevel + 1, ")\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the PolysList (filled areas)
|
2020-06-24 02:19:08 +00:00
|
|
|
for( PCB_LAYER_ID layer : aZone->GetLayerSet().Seq() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
const std::shared_ptr<SHAPE_POLY_SET>& fv = aZone->GetFilledPolysList( layer );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
for( int ii = 0; ii < fv->OutlineCount(); ++ii )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-08-14 00:10:40 +00:00
|
|
|
m_out->Print( aNestLevel + 1, "(filled_polygon\n" );
|
|
|
|
m_out->Print( aNestLevel + 2, "(layer %s)\n",
|
2021-08-01 00:14:02 +00:00
|
|
|
m_out->Quotew( LSET::Name( layer ) ).c_str() );
|
2020-08-14 00:10:40 +00:00
|
|
|
|
|
|
|
if( aZone->IsIsland( layer, ii ) )
|
|
|
|
m_out->Print( aNestLevel + 2, "(island)\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2022-02-15 17:34:38 +00:00
|
|
|
const SHAPE_LINE_CHAIN& chain = fv->COutline( ii );
|
2020-08-14 00:10:40 +00:00
|
|
|
|
2022-01-04 23:00:00 +00:00
|
|
|
formatPolyPts( chain, aNestLevel + 1, ADVANCED_CFG::GetCfg().m_CompactSave );
|
|
|
|
m_out->Print( aNestLevel + 1, ")\n" );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 04:31:22 +00:00
|
|
|
PCB_IO_KICAD_SEXPR::PCB_IO_KICAD_SEXPR( int aControlFlags ) : PCB_IO( wxS( "KiCad" ) ),
|
2021-04-22 21:20:34 +00:00
|
|
|
m_cache( nullptr ),
|
2019-11-25 07:02:16 +00:00
|
|
|
m_ctl( aControlFlags ),
|
2023-05-20 04:00:09 +00:00
|
|
|
m_mapping( new NETINFO_MAPPING() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
init( nullptr );
|
2019-11-25 07:02:16 +00:00
|
|
|
m_out = &m_sf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR::~PCB_IO_KICAD_SEXPR()
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
delete m_mapping;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
BOARD* PCB_IO_KICAD_SEXPR::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
2023-12-27 17:06:23 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties, PROJECT* aProject )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-08-06 18:37:43 +00:00
|
|
|
FILE_LINE_READER reader( aFileName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
unsigned lineCount = 0;
|
|
|
|
|
2024-06-20 22:33:03 +00:00
|
|
|
fontconfig::FONTCONFIG::SetReporter( &WXLOG_REPORTER::GetInstance() );
|
|
|
|
|
2023-12-27 17:06:23 +00:00
|
|
|
if( m_progressReporter )
|
2021-06-23 22:53:08 +00:00
|
|
|
{
|
2023-12-27 17:06:23 +00:00
|
|
|
m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
2023-12-27 17:06:23 +00:00
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2021-06-30 15:06:07 +00:00
|
|
|
THROW_IO_ERROR( _( "Open cancelled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
while( reader.ReadLine() )
|
|
|
|
lineCount++;
|
|
|
|
|
|
|
|
reader.Rewind();
|
|
|
|
}
|
|
|
|
|
2023-12-27 17:06:23 +00:00
|
|
|
BOARD* board = DoLoad( reader, aAppendToMe, aProperties, m_progressReporter, lineCount );
|
2020-08-06 18:37:43 +00:00
|
|
|
|
|
|
|
// Give the filename to the board if it's new
|
|
|
|
if( !aAppendToMe )
|
|
|
|
board->SetFileName( aFileName );
|
|
|
|
|
|
|
|
return board;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
BOARD* PCB_IO_KICAD_SEXPR::DoLoad( LINE_READER& aReader, BOARD* aAppendToMe, const STRING_UTF8_MAP* aProperties,
|
2021-11-25 12:22:40 +00:00
|
|
|
PROGRESS_REPORTER* aProgressReporter, unsigned aLineCount)
|
2020-08-06 18:37:43 +00:00
|
|
|
{
|
2019-11-25 07:02:16 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR_PARSER parser( &aReader, aAppendToMe, m_queryUserCallback, aProgressReporter, aLineCount );
|
2021-10-31 19:57:52 +00:00
|
|
|
BOARD* board;
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
board = dynamic_cast<BOARD*>( parser.Parse() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
catch( const FUTURE_FORMAT_ERROR& )
|
|
|
|
{
|
|
|
|
// Don't wrap a FUTURE_FORMAT_ERROR in another
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
if( parser.IsTooRecent() )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
|
2019-11-25 07:02:16 +00:00
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !board )
|
|
|
|
{
|
|
|
|
// The parser loaded something that was valid, but wasn't a board.
|
2021-10-31 19:57:52 +00:00
|
|
|
THROW_PARSE_ERROR( _( "This file does not contain a PCB." ), parser.CurSource(),
|
|
|
|
parser.CurLine(), parser.CurLineNumber(), parser.CurOffset() );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return board;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::init( const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-12-18 15:40:13 +00:00
|
|
|
m_board = nullptr;
|
|
|
|
m_reader = nullptr;
|
2019-11-25 07:02:16 +00:00
|
|
|
m_props = aProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::validateCache( const wxString& aLibraryPath, bool checkModified )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2024-06-20 22:33:03 +00:00
|
|
|
fontconfig::FONTCONFIG::SetReporter( nullptr );
|
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
|
|
|
|
{
|
|
|
|
// a spectacular episode in memory management:
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new FP_CACHE( this, aLibraryPath );
|
|
|
|
m_cache->Load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
bool aBestEfforts, const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
wxDir dir( aLibPath );
|
|
|
|
wxString errorMsg;
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
validateCache( aLibPath );
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
for( const auto& footprint : m_cache->GetFootprints() )
|
|
|
|
aFootprintNames.Add( footprint.first );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( !errorMsg.IsEmpty() && !aBestEfforts )
|
|
|
|
THROW_IO_ERROR( errorMsg );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
const FOOTPRINT* PCB_IO_KICAD_SEXPR::getFootprint( const wxString& aLibraryPath,
|
2021-11-25 12:22:40 +00:00
|
|
|
const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties,
|
2021-11-25 12:22:40 +00:00
|
|
|
bool checkModified )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
validateCache( aLibraryPath, checkModified );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& )
|
|
|
|
{
|
|
|
|
// do nothing with the error
|
|
|
|
}
|
|
|
|
|
2022-11-28 02:27:34 +00:00
|
|
|
FP_CACHE_FOOTPRINT_MAP& footprints = m_cache->GetFootprints();
|
|
|
|
FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( aFootprintName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
if( it == footprints.end() )
|
2019-11-25 07:02:16 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2020-11-15 12:20:59 +00:00
|
|
|
return it->second->GetFootprint();
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
const FOOTPRINT* PCB_IO_KICAD_SEXPR::GetEnumeratedFootprint( const wxString& aLibraryPath,
|
2021-11-25 12:22:40 +00:00
|
|
|
const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
bool PCB_IO_KICAD_SEXPR::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
// Note: checking the cache sounds like a good idea, but won't catch files which differ
|
|
|
|
// only in case.
|
|
|
|
//
|
|
|
|
// Since this goes out to the native filesystem, we get platform differences (ie: MSW's
|
|
|
|
// case-insensitive filesystem) handled "for free".
|
|
|
|
// Warning: footprint names frequently contain a point. So be careful when initializing
|
|
|
|
// wxFileName, and use a CTOR with extension specified
|
2023-12-28 02:10:01 +00:00
|
|
|
wxFileName footprintFile( aLibraryPath, aFootprintName, FILEEXT::KiCadFootprintFileExtension );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
return footprintFile.Exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
FOOTPRINT* PCB_IO_KICAD_SEXPR::ImportFootprint( const wxString& aFootprintPath, wxString& aFootprintNameOut,
|
2023-08-13 02:26:06 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
|
|
|
{
|
|
|
|
wxString fcontents;
|
|
|
|
wxFFile f( aFootprintPath );
|
|
|
|
|
2024-06-20 22:33:03 +00:00
|
|
|
fontconfig::FONTCONFIG::SetReporter( nullptr );
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
if( !f.IsOpened() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
f.ReadAll( &fcontents );
|
|
|
|
|
|
|
|
aFootprintNameOut = wxFileName( aFootprintPath ).GetName();
|
|
|
|
|
|
|
|
return dynamic_cast<FOOTPRINT*>( Parse( fcontents ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
FOOTPRINT* PCB_IO_KICAD_SEXPR::FootprintLoad( const wxString& aLibraryPath,
|
2021-11-25 12:22:40 +00:00
|
|
|
const wxString& aFootprintName,
|
|
|
|
bool aKeepUUID,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2024-06-20 22:33:03 +00:00
|
|
|
fontconfig::FONTCONFIG::SetReporter( nullptr );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
|
2020-12-04 12:14:07 +00:00
|
|
|
|
|
|
|
if( footprint )
|
|
|
|
{
|
2021-03-30 09:38:03 +00:00
|
|
|
FOOTPRINT* copy;
|
|
|
|
|
|
|
|
if( aKeepUUID )
|
|
|
|
copy = static_cast<FOOTPRINT*>( footprint->Clone() );
|
|
|
|
else
|
|
|
|
copy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
|
|
|
|
|
2020-12-04 12:14:07 +00:00
|
|
|
copy->SetParent( nullptr );
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
// In this public PLUGIN API function, we can safely assume it was
|
|
|
|
// called for saving into a library path.
|
|
|
|
m_ctl = CTL_FOR_LIBRARY;
|
|
|
|
|
|
|
|
validateCache( aLibraryPath );
|
|
|
|
|
|
|
|
if( !m_cache->IsWritable() )
|
|
|
|
{
|
|
|
|
if( !m_cache->Exists() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
const wxString msg = wxString::Format( _( "Library '%s' does not exist.\n"
|
2020-10-16 00:39:55 +00:00
|
|
|
"Would you like to create it?"),
|
|
|
|
aLibraryPath );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2023-03-24 23:45:56 +00:00
|
|
|
if( !Pgm().IsGUI()
|
|
|
|
|| wxMessageBox( msg, _( "Library Not Found" ), wxYES_NO | wxICON_QUESTION )
|
|
|
|
!= wxYES )
|
2019-11-25 07:02:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Save throws its own IO_ERROR on failure, so no need to recreate here
|
2020-12-18 15:40:13 +00:00
|
|
|
m_cache->Save( nullptr );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library '%s' is read only." ), aLibraryPath );
|
2019-11-25 07:02:16 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString footprintName = aFootprint->GetFPID().GetLibItemName();
|
|
|
|
|
2022-11-28 02:27:34 +00:00
|
|
|
FP_CACHE_FOOTPRINT_MAP& footprints = m_cache->GetFootprints();
|
2024-02-15 20:46:00 +00:00
|
|
|
wxString fpName = aFootprint->GetFPID().GetLibItemName().wx_str();
|
|
|
|
ReplaceIllegalFileNameChars( fpName, '_' );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-14 22:00:12 +00:00
|
|
|
// Quietly overwrite footprint and delete footprint file from path for any by same name.
|
2024-02-15 20:46:00 +00:00
|
|
|
wxFileName fn( aLibraryPath, fpName, FILEEXT::KiCadFootprintFileExtension );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
// Write through symlinks, don't replace them
|
2021-06-07 19:12:30 +00:00
|
|
|
WX_FILENAME::ResolvePossibleSymlinks( fn );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
if( !fn.IsOk() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
fn.GetFullPath() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fn.FileExists() && !fn.IsFileWritable() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete '%s'." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
fn.GetFullPath() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString fullPath = fn.GetFullPath();
|
|
|
|
wxString fullName = fn.GetFullName();
|
2022-11-28 02:27:34 +00:00
|
|
|
FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( footprintName );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
if( it != footprints.end() )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
|
2020-11-14 19:16:42 +00:00
|
|
|
footprints.erase( footprintName );
|
2019-11-25 07:02:16 +00:00
|
|
|
wxRemoveFile( fullPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
// I need my own copy for the cache
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aFootprint->Clone() );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2021-03-03 14:36:06 +00:00
|
|
|
// It's orientation should be zero and it should be on the front layer.
|
2022-01-13 17:27:36 +00:00
|
|
|
footprint->SetOrientation( ANGLE_0 );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->GetLayer() != F_Cu )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
if( cfg )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Flip( footprint->GetPosition(), cfg->m_FlipLeftRight );
|
2020-01-13 01:44:19 +00:00
|
|
|
else
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->Flip( footprint->GetPosition(), false );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 20:56:46 +00:00
|
|
|
// Detach it from the board and its group
|
2021-03-03 14:36:06 +00:00
|
|
|
footprint->SetParent( nullptr );
|
2023-06-28 20:56:46 +00:00
|
|
|
footprint->SetParentGroup( nullptr );
|
2021-03-03 14:36:06 +00:00
|
|
|
|
2019-11-25 07:02:16 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
|
2021-04-20 14:18:31 +00:00
|
|
|
footprints.insert( footprintName,
|
|
|
|
new FP_CACHE_ITEM( footprint, WX_FILENAME( fn.GetPath(), fullName ) ) );
|
2020-11-13 15:15:52 +00:00
|
|
|
m_cache->Save( footprint );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
validateCache( aLibraryPath );
|
|
|
|
|
|
|
|
if( !m_cache->IsWritable() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cache->Remove( aFootprintName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
long long PCB_IO_KICAD_SEXPR::GetLibraryTimestamp( const wxString& aLibraryPath ) const
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
return FP_CACHE::GetTimestamp( aLibraryPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
void PCB_IO_KICAD_SEXPR::CreateLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
if( wxDir::Exists( aLibraryPath ) )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path '%s'." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new FP_CACHE( this, aLibraryPath );
|
|
|
|
m_cache->Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool PCB_IO_KICAD_SEXPR::DeleteLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
fn.SetPath( aLibraryPath );
|
|
|
|
|
|
|
|
// Return if there is no library path to delete.
|
|
|
|
if( !fn.DirExists() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !fn.IsDirWritable() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete folder '%s'." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDir dir( aLibraryPath );
|
|
|
|
|
|
|
|
if( dir.HasSubDirs() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library folder '%s' has unexpected sub-folders." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// All the footprint files must be deleted before the directory can be deleted.
|
|
|
|
if( dir.HasFiles() )
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
wxFileName tmp;
|
|
|
|
wxArrayString files;
|
|
|
|
|
|
|
|
wxDir::GetAllFiles( aLibraryPath, &files );
|
|
|
|
|
|
|
|
for( i = 0; i < files.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
tmp = files[i];
|
|
|
|
|
2023-12-28 02:10:01 +00:00
|
|
|
if( tmp.GetExt() != FILEEXT::KiCadFootprintFileExtension )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unexpected file '%s' found in library "
|
|
|
|
"path '%s'." ),
|
|
|
|
files[i].GetData(),
|
|
|
|
aLibraryPath.GetData() ) );
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0; i < files.GetCount(); i++ )
|
|
|
|
wxRemoveFile( files[i] );
|
|
|
|
}
|
|
|
|
|
2021-06-27 13:24:02 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library '%s'." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
aLibraryPath.GetData() );
|
|
|
|
|
|
|
|
// Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
|
|
|
|
// we don't want that. we want bare metal portability with no UI here.
|
|
|
|
if( !wxRmdir( aLibraryPath ) )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' cannot be deleted." ),
|
2019-11-25 07:02:16 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// For some reason removing a directory in Windows is not immediately updated. This delay
|
|
|
|
// prevents an error when attempting to immediately recreate the same directory when over
|
|
|
|
// writing an existing library.
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
wxMilliSleep( 250L );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( m_cache && !m_cache->IsPath( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
delete m_cache;
|
2020-12-18 15:40:13 +00:00
|
|
|
m_cache = nullptr;
|
2019-11-25 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool PCB_IO_KICAD_SEXPR::IsLibraryWritable( const wxString& aLibraryPath )
|
2019-11-25 07:02:16 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
2020-12-18 15:40:13 +00:00
|
|
|
init( nullptr );
|
2019-11-25 07:02:16 +00:00
|
|
|
|
|
|
|
validateCache( aLibraryPath );
|
|
|
|
|
|
|
|
return m_cache->IsWritable();
|
|
|
|
}
|