2012-06-09 17:00:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN
|
2018-04-13 13:58:25 +00:00
|
|
|
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-09 17:00:13 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <build_version.h> // LEGACY_BOARD_FILE_VERSION
|
|
|
|
#include <macros.h>
|
2012-10-07 15:37:25 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
#include <base_units.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_dimension.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_drawsegment.h>
|
2017-10-31 15:38:10 +00:00
|
|
|
#include <class_pcb_target.h>
|
2012-06-09 17:00:13 +00:00
|
|
|
#include <class_edge_mod.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <pcb_plot_params.h>
|
2012-06-09 17:00:13 +00:00
|
|
|
#include <zones.h>
|
|
|
|
#include <kicad_plugin.h>
|
|
|
|
#include <pcb_parser.h>
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/filename.h>
|
2012-06-09 17:00:13 +00:00
|
|
|
#include <wx/wfstream.h>
|
2012-10-07 15:37:25 +00:00
|
|
|
#include <boost/ptr_container/ptr_map.hpp>
|
|
|
|
#include <memory.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2012-10-07 15:37:25 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
using namespace PCB_KEYS_T;
|
|
|
|
|
2012-10-07 22:26:17 +00:00
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
///> Removes empty nets (i.e. with node count equal zero) from net classes
|
|
|
|
void filterNetClass( const BOARD& aBoard, NETCLASS& aNetClass )
|
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
auto connectivity = aBoard.GetConnectivity();
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2016-01-17 17:31:00 +00:00
|
|
|
for( NETCLASS::iterator it = aNetClass.begin(); it != aNetClass.end(); )
|
2014-05-13 09:22:51 +00:00
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = aBoard.FindNet( *it );
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
if( netinfo && connectivity->GetNodeCount( netinfo->GetNet() ) <= 0 ) // hopefully there are no nets with negative
|
2014-07-13 17:08:42 +00:00
|
|
|
aNetClass.Remove( it++ ); // node count, but you never know..
|
|
|
|
else
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
++it;
|
2014-05-13 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
/**
|
|
|
|
* Class FP_CACHE_ITEM
|
|
|
|
* is helper class for creating a footprint library cache.
|
|
|
|
*
|
|
|
|
* The new footprint library design is a file path of individual module files
|
|
|
|
* that contain a single module per file. This class is a helper only for the
|
|
|
|
* footprint portion of the PLUGIN API, and only for the #PCB_IO plugin. It is
|
|
|
|
* private to this implementation file so it is not placed into a header.
|
|
|
|
*/
|
|
|
|
class FP_CACHE_ITEM
|
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
WX_FILENAME m_filename;
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr<MODULE> m_module;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
public:
|
2018-08-05 11:56:02 +00:00
|
|
|
FP_CACHE_ITEM( MODULE* aModule, const WX_FILENAME& aFileName );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
const WX_FILENAME& GetFileName() const { return m_filename; }
|
|
|
|
const MODULE* GetModule() const { return m_module.get(); }
|
2012-10-07 15:37:25 +00:00
|
|
|
};
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
FP_CACHE_ITEM::FP_CACHE_ITEM( MODULE* aModule, const WX_FILENAME& aFileName ) :
|
|
|
|
m_filename( aFileName ),
|
2014-05-26 06:21:25 +00:00
|
|
|
m_module( aModule )
|
2018-08-05 11:56:02 +00:00
|
|
|
{ }
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2017-07-25 19:14:31 +00:00
|
|
|
typedef boost::ptr_map< wxString, FP_CACHE_ITEM > MODULE_MAP;
|
|
|
|
typedef MODULE_MAP::iterator MODULE_ITER;
|
|
|
|
typedef MODULE_MAP::const_iterator MODULE_CITER;
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
class FP_CACHE
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
PCB_IO* m_owner; // Plugin object that owns the cache.
|
|
|
|
wxFileName m_lib_path; // The path of the library.
|
|
|
|
wxString m_lib_raw_path; // For quick comparisons.
|
|
|
|
MODULE_MAP m_modules; // Map of footprint file name per MODULE*.
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2018-03-02 20:41:37 +00:00
|
|
|
bool m_cache_dirty; // Stored separately because it's expensive to check
|
|
|
|
// m_cache_timestamp against all the files.
|
|
|
|
long long m_cache_timestamp; // A hash of the timestamps for all the footprint
|
|
|
|
// files.
|
2018-02-10 23:10:39 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
public:
|
|
|
|
FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath );
|
|
|
|
|
2018-07-30 13:18:37 +00:00
|
|
|
wxString GetPath() const { return m_lib_raw_path; }
|
2014-05-26 06:21:25 +00:00
|
|
|
bool IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
|
2018-05-04 16:10:51 +00:00
|
|
|
bool Exists() const { return m_lib_path.IsOk() && m_lib_path.DirExists(); }
|
2014-05-26 06:21:25 +00:00
|
|
|
MODULE_MAP& GetModules() { return m_modules; }
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
// Most all functions in this class throw IO_ERROR exceptions. There are no
|
|
|
|
// error codes nor user interface calls from here, nor in any PLUGIN.
|
|
|
|
// Catch these exceptions higher up please.
|
|
|
|
|
2018-03-28 21:39:26 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
|
|
|
* Save the footprint cache or a single module from it to disk
|
|
|
|
*
|
|
|
|
* @param aModule if set, save only this module, otherwise, save the full library
|
|
|
|
*/
|
|
|
|
void Save( MODULE* aModule = NULL );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
void Load();
|
|
|
|
|
|
|
|
void Remove( const wxString& aFootprintName );
|
|
|
|
|
2018-02-23 12:21:06 +00:00
|
|
|
/**
|
|
|
|
* Function GetTimestamp
|
|
|
|
* Generate a timestamp representing all source files in the cache (including the
|
|
|
|
* parent directory).
|
|
|
|
* Timestamps should not be considered ordered. They either match or they don't.
|
|
|
|
*/
|
2018-08-03 16:53:38 +00:00
|
|
|
static long long GetTimestamp( const wxString& aLibPath );
|
2013-09-24 18:45:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsModified
|
2018-02-23 12:21:06 +00:00
|
|
|
* Return true if the cache is not up-to-date.
|
2013-09-24 18:45:57 +00:00
|
|
|
*/
|
2018-02-23 12:21:06 +00:00
|
|
|
bool IsModified();
|
2013-09-24 18:45:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsPath
|
|
|
|
* checks if \a aPath is the same as the current cache path.
|
|
|
|
*
|
|
|
|
* This tests paths by converting \a aPath using the native separators. Internally
|
|
|
|
* #FP_CACHE stores the current path using native separators. This prevents path
|
|
|
|
* miscompares on Windows due to the fact that paths can be stored with / instead of \\
|
|
|
|
* in the footprint library table.
|
|
|
|
*
|
|
|
|
* @param aPath is the library path to test against.
|
|
|
|
* @return true if \a aPath is the same as the cache path.
|
|
|
|
*/
|
|
|
|
bool IsPath( const wxString& aPath ) const;
|
2012-10-07 15:37:25 +00:00
|
|
|
};
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
FP_CACHE::FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath )
|
|
|
|
{
|
|
|
|
m_owner = aOwner;
|
2018-07-30 13:18:37 +00:00
|
|
|
m_lib_raw_path = aLibraryPath;
|
2012-10-07 15:37:25 +00:00
|
|
|
m_lib_path.SetPath( aLibraryPath );
|
2018-02-23 12:21:06 +00:00
|
|
|
m_cache_timestamp = 0;
|
|
|
|
m_cache_dirty = true;
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-03-28 21:39:26 +00:00
|
|
|
void FP_CACHE::Save( MODULE* aModule )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2018-02-23 12:21:06 +00:00
|
|
|
m_cache_timestamp = 0;
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
if( !m_lib_path.DirExists() && !m_lib_path.Mkdir() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Cannot create footprint library path \"%s\"" ),
|
2018-07-30 13:18:37 +00:00
|
|
|
m_lib_raw_path ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_lib_path.IsDirWritable() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library path \"%s\" is read only" ),
|
2018-07-30 13:18:37 +00:00
|
|
|
m_lib_raw_path ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
for( MODULE_ITER it = m_modules.begin(); it != m_modules.end(); ++it )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2018-03-28 21:39:26 +00:00
|
|
|
if( aModule && aModule != it->second->GetModule() )
|
|
|
|
continue;
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
WX_FILENAME fn = it->second->GetFileName();
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2014-12-11 12:00:59 +00:00
|
|
|
wxString tempFileName =
|
|
|
|
#ifdef USE_TMP_FILE
|
2018-08-05 11:56:02 +00:00
|
|
|
wxFileName::CreateTempFileName( fn.GetPath() );
|
2014-12-11 12:00:59 +00:00
|
|
|
#else
|
|
|
|
fn.GetFullPath();
|
|
|
|
#endif
|
2012-10-07 15:37:25 +00:00
|
|
|
// Allow file output stream to go out of scope to close the file stream before
|
|
|
|
// renaming the file.
|
|
|
|
{
|
2018-04-13 13:58:25 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file %s" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
GetChars( tempFileName ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-10-25 07:10:59 +00:00
|
|
|
FILE_OUTPUTFORMATTER formatter( tempFileName );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-10-25 05:52:55 +00:00
|
|
|
m_owner->SetOutputFormatter( &formatter );
|
|
|
|
m_owner->Format( (BOARD_ITEM*) it->second->GetModule() );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 12:00:59 +00:00
|
|
|
#ifdef USE_TMP_FILE
|
2012-10-07 15:37:25 +00:00
|
|
|
wxRemove( fn.GetFullPath() ); // it is not an error if this does not exist
|
|
|
|
|
2014-10-23 20:25:04 +00:00
|
|
|
// Even on linux you can see an _intermittent_ error when calling wxRename(),
|
|
|
|
// and it is fully inexplicable. See if this dodges the error.
|
|
|
|
wxMilliSleep( 250L );
|
|
|
|
|
|
|
|
if( !wxRenameFile( tempFileName, fn.GetFullPath() ) )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2013-10-31 21:30:57 +00:00
|
|
|
wxString msg = wxString::Format(
|
2017-12-15 11:37:46 +00:00
|
|
|
_( "Cannot rename temporary file \"%s\" to footprint library file \"%s\"" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
GetChars( tempFileName ),
|
|
|
|
GetChars( fn.GetFullPath() )
|
|
|
|
);
|
2013-10-31 21:30:57 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
2014-12-11 12:00:59 +00:00
|
|
|
#endif
|
2018-08-05 11:56:02 +00:00
|
|
|
m_cache_timestamp += fn.GetTimestamp();
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
2018-02-23 12:21:06 +00:00
|
|
|
|
|
|
|
m_cache_timestamp += m_lib_path.GetModificationTime().GetValue().GetValue();
|
2018-03-28 21:39:26 +00:00
|
|
|
|
|
|
|
// If we've saved the full cache, we clear the dirty flag.
|
|
|
|
if( !aModule )
|
|
|
|
m_cache_dirty = false;
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
void FP_CACHE::Load()
|
2018-02-24 17:41:44 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_dirty = false;
|
|
|
|
m_cache_timestamp = 0;
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
wxDir dir( m_lib_raw_path );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
if( !dir.IsOpened() )
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
wxString msg = wxString::Format( _( "Footprint library path \"%s\" does not exist" ),
|
|
|
|
m_lib_raw_path );
|
2013-10-31 21:30:57 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
wxString fullName;
|
|
|
|
wxString fileSpec = wxT( "*." ) + KiCadFootprintFileExtension;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
// wxFileName construction is egregiously slow. Construct it once and just swap out
|
2018-08-05 11:56:02 +00:00
|
|
|
// the filename thereafter.
|
|
|
|
WX_FILENAME fn( m_lib_raw_path, wxT( "dummyName" ) );
|
2018-08-03 16:53:38 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
if( dir.GetFirst( &fullName, fileSpec ) )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2017-05-03 19:27:07 +00:00
|
|
|
wxString cacheError;
|
|
|
|
|
2013-07-28 16:30:02 +00:00
|
|
|
do
|
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
fn.SetFullName( fullName );
|
2013-07-28 16:30:02 +00:00
|
|
|
|
2017-05-03 19:27:07 +00:00
|
|
|
// Queue I/O errors so only files that fail to parse don't get loaded.
|
|
|
|
try
|
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
FILE_LINE_READER reader( fn.GetFullPath() );
|
2012-10-24 18:20:33 +00:00
|
|
|
|
2017-05-03 19:27:07 +00:00
|
|
|
m_owner->m_parser->SetLineReader( &reader );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2017-07-25 19:14:31 +00:00
|
|
|
MODULE* footprint = (MODULE*) m_owner->m_parser->Parse();
|
2018-08-03 16:53:38 +00:00
|
|
|
wxString fpName = fn.GetName();
|
2017-07-25 19:14:31 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
footprint->SetFPID( LIB_ID( wxEmptyString, fpName ) );
|
2018-08-03 16:53:38 +00:00
|
|
|
m_modules.insert( fpName, new FP_CACHE_ITEM( footprint, fn ) );
|
2018-02-23 12:21:06 +00:00
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_timestamp += fn.GetTimestamp();
|
2017-05-03 19:27:07 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
if( !cacheError.IsEmpty() )
|
|
|
|
cacheError += "\n\n";
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2017-05-03 19:27:07 +00:00
|
|
|
cacheError += ioe.What();
|
|
|
|
}
|
2018-08-05 11:56:02 +00:00
|
|
|
} while( dir.GetNext( &fullName ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2017-05-03 19:27:07 +00:00
|
|
|
if( !cacheError.IsEmpty() )
|
|
|
|
THROW_IO_ERROR( cacheError );
|
2013-07-28 16:30:02 +00:00
|
|
|
}
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
void FP_CACHE::Remove( const wxString& aFootprintName )
|
|
|
|
{
|
2017-07-25 19:14:31 +00:00
|
|
|
MODULE_CITER it = m_modules.find( aFootprintName );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
if( it == m_modules.end() )
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
wxString msg = wxString::Format( _( "library \"%s\" has no footprint \"%s\" to delete" ),
|
|
|
|
m_lib_raw_path,
|
|
|
|
aFootprintName );
|
2013-10-31 21:30:57 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the module from the cache and delete the module file from the library.
|
|
|
|
wxString fullPath = it->second->GetFileName().GetFullPath();
|
2017-07-25 19:14:31 +00:00
|
|
|
m_modules.erase( aFootprintName );
|
2012-10-07 15:37:25 +00:00
|
|
|
wxRemoveFile( fullPath );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2013-09-24 18:45:57 +00:00
|
|
|
bool FP_CACHE::IsPath( const wxString& aPath ) const
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
return aPath == m_lib_raw_path;
|
2013-09-24 18:45:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-02-23 12:21:06 +00:00
|
|
|
bool FP_CACHE::IsModified()
|
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_dirty = m_cache_dirty || GetTimestamp( m_lib_path.GetFullPath() ) != m_cache_timestamp;
|
|
|
|
|
|
|
|
return m_cache_dirty;
|
2018-02-23 12:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
long long FP_CACHE::GetTimestamp( const wxString& aLibPath )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
wxString fileSpec = wxT( "*." ) + KiCadFootprintFileExtension;
|
2018-02-23 12:21:06 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
return TimestampDir( aLibPath, fileSpec );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-06-24 05:30:22 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
m_board = aBoard; // after init()
|
2012-06-09 17:00:13 +00:00
|
|
|
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
// Prepare net mapping that assures that net codes saved in a file are consecutive integers
|
|
|
|
m_mapping->SetBoard( aBoard );
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
FILE_OUTPUTFORMATTER formatter( aFileName );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out = &formatter; // no ownership
|
|
|
|
|
|
|
|
m_out->Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
|
2014-05-26 06:21:25 +00:00
|
|
|
formatter.Quotew( GetBuildVersion() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
Format( aBoard, 1 );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
BOARD_ITEM* PCB_IO::Parse( const wxString& aClipboardSourceInput )
|
2012-10-22 20:41:26 +00:00
|
|
|
{
|
|
|
|
std::string input = TO_UTF8( aClipboardSourceInput );
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
STRING_LINE_READER reader( input, wxT( "clipboard" ) );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-10-24 18:20:33 +00:00
|
|
|
m_parser->SetLineReader( &reader );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return m_parser->Parse();
|
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
|
|
|
if( m_parser->IsTooRecent() )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
|
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::Format( BOARD_ITEM* aItem, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle; // public API function, perform anything convenient for caller
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aItem->Type() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
case PCB_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<BOARD*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_DIMENSION_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<DIMENSION*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_LINE_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<DRAWSEGMENT*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<EDGE_MODULE*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TARGET_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<PCB_TARGET*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_MODULE_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<MODULE*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<D_PAD*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<TEXTE_PCB*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<TEXTE_MODULE*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_VIA_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<TRACK*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_ZONE_AREA_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
format( static_cast<ZONE_CONTAINER*>( aItem ), aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
void PCB_IO::formatLayer( const BOARD_ITEM* aItem ) const
|
|
|
|
{
|
2013-03-20 04:46:32 +00:00
|
|
|
if( m_ctl & CTL_STD_LAYER_NAMES )
|
2012-11-10 06:39:18 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = aItem->GetLayer();
|
2012-11-10 06:39:18 +00:00
|
|
|
|
|
|
|
// English layer names should never need quoting.
|
2013-03-20 04:46:32 +00:00
|
|
|
m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
|
2014-05-26 06:21:25 +00:00
|
|
|
}
|
|
|
|
else
|
2012-11-10 06:39:18 +00:00
|
|
|
m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 12:04:57 +00:00
|
|
|
void PCB_IO::formatSetup( BOARD* aBoard, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
// Setup
|
|
|
|
m_out->Print( aNestLevel, "(setup\n" );
|
|
|
|
|
|
|
|
// Save current default track width, for compatibility with older Pcbnew version;
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetCurrentTrackWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save custom tracks width list (the first is not saved here: this is the netclass value
|
2014-05-13 09:22:51 +00:00
|
|
|
for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_TrackWidthList[ii] ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetDefault()->GetClearance() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// ZONE_SETTINGS
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
|
|
|
|
aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(trace_min %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_TrackMinWidth ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save current default via size, for compatibility with older Pcbnew version;
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(via_size %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(via_drill %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_ViasMinSize ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_ViasMinDrill ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save custom vias diameters list (the first is not saved here: this is
|
|
|
|
// the netclass value
|
2014-05-13 09:22:51 +00:00
|
|
|
for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
|
|
|
|
FormatInternalUnits( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
// for old versions compatibility:
|
2014-05-13 09:22:51 +00:00
|
|
|
if( dsnSettings.m_BlindBuriedViaAllowed )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
|
|
|
|
( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
|
|
|
|
m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_MicroViasMinSize ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_MicroViasMinDrill ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
// 6.0 TODO: are we going to update the tokens we save these under?
|
|
|
|
// 6.0 TODO: need to save the LAYER_CLASS_OTHERS stuff
|
|
|
|
// 6.0 TODO: need to save the TextItalic and TextUpright settings
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(edge_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_LineThickness[ LAYER_CLASS_EDGES ] ).c_str() );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(segment_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_LineThickness[ LAYER_CLASS_COPPER ] ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_TextThickness[ LAYER_CLASS_COPPER ] ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_COPPER ].x ).c_str(),
|
|
|
|
FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_COPPER ].y ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_LineThickness[ LAYER_CLASS_SILK ] ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_SILK ].x ).c_str(),
|
|
|
|
FormatInternalUnits( dsnSettings.m_TextSize[ LAYER_CLASS_SILK ].y ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_TextThickness[ LAYER_CLASS_SILK ] ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
|
|
|
|
FormatInternalUnits( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_SolderMaskMargin ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
if( dsnSettings.m_SolderMaskMinWidth )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
|
2012-11-05 20:20:34 +00:00
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
if( dsnSettings.m_SolderPasteMargin != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
if( dsnSettings.m_SolderPasteMarginRatio != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
|
|
|
|
Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aBoard->GetAuxOrigin().x ).c_str(),
|
|
|
|
FormatInternalUnits( aBoard->GetAuxOrigin().y ).c_str() );
|
2013-08-03 05:15:23 +00:00
|
|
|
|
2013-08-03 16:16:57 +00:00
|
|
|
if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aBoard->GetGridOrigin().x ).c_str(),
|
|
|
|
FormatInternalUnits( aBoard->GetGridOrigin().y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
|
|
|
|
dsnSettings.GetVisibleElements() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out->Print( aNestLevel, ")\n\n" );
|
2017-05-18 16:43:01 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-09-17 12:04:57 +00:00
|
|
|
void PCB_IO::formatGeneral( BOARD* aBoard, int aNestLevel ) const
|
2017-05-18 16:43:01 +00:00
|
|
|
{
|
|
|
|
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
m_out->Print( aNestLevel, "(general\n" );
|
|
|
|
// Write Bounding box info
|
|
|
|
m_out->Print( aNestLevel+1, "(thickness %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
|
2017-05-18 16:43:01 +00:00
|
|
|
|
2017-09-17 12:04:57 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->Drawings().Size() );
|
2017-05-18 16:43:01 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
|
|
|
|
m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
|
|
|
|
m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
|
|
|
|
m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() );
|
|
|
|
m_out->Print( aNestLevel, ")\n\n" );
|
|
|
|
|
|
|
|
aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
|
|
|
|
aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
|
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-09-17 12:04:57 +00:00
|
|
|
void PCB_IO::formatBoardLayers( BOARD* aBoard, int aNestLevel ) const
|
2017-05-18 16:43:01 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel, "(layers\n" );
|
|
|
|
|
|
|
|
// Save only the used copper layers from front to back.
|
|
|
|
LSET visible_layers = aBoard->GetVisibleLayers();
|
|
|
|
|
|
|
|
for( LSEQ cu = aBoard->GetEnabledLayers().CuStack(); cu; ++cu )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = *cu;
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(%d %s %s", layer,
|
|
|
|
m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
|
|
|
|
LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
|
|
|
|
|
|
|
|
if( !visible_layers[layer] )
|
|
|
|
m_out->Print( 0, " hide" );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save used non-copper layers in the order they are defined.
|
|
|
|
// desired sequence for non Cu BOARD layers.
|
2017-09-29 09:44:05 +00:00
|
|
|
static const PCB_LAYER_ID non_cu[] =
|
|
|
|
{
|
2017-05-18 16:43:01 +00:00
|
|
|
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,
|
|
|
|
F_Fab
|
|
|
|
};
|
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
for( LSEQ seq = aBoard->GetEnabledLayers().Seq( non_cu, arrayDim( non_cu ) ); seq; ++seq )
|
2017-05-18 16:43:01 +00:00
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = *seq;
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(%d %s user", layer,
|
|
|
|
m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
|
|
|
|
|
|
|
|
if( !visible_layers[layer] )
|
|
|
|
m_out->Print( 0, " hide" );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n\n" );
|
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-09-17 12:04:57 +00:00
|
|
|
void PCB_IO::formatNetInformation( BOARD* aBoard, int aNestLevel ) const
|
2017-05-18 16:43:01 +00:00
|
|
|
{
|
|
|
|
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
|
2014-01-16 15:47:31 +00:00
|
|
|
net != netEnd; ++net )
|
2013-03-14 22:54:47 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel, "(net %d %s)\n",
|
|
|
|
m_mapping->Translate( net->GetNet() ),
|
|
|
|
m_out->Quotew( net->GetNetname() ).c_str() );
|
Modular-Kicad milestone B), major portions:
*) Rework the set language support, simplify it by using KIWAY. Now any major
frame with a "change language" menu can change the language for all KIWAY_PLAYERs
in the whole KIWAY. Multiple KIWAYs are not supported yet.
*) Simplify "modal wxFrame" support, and add that support exclusively to
KIWAY_PLAYER where it is inherited by all derivatives. The function
KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable.
*) Remove the requirements and assumptions that the wxFrame hierarchy always
had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers
and editors. This is no longer the case, nor required.
*) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the
KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame
quickly. It also gives control to the KIWAY as to frame hierarchical
relationships.
*) Change single_top to use the KIWAY for loading a KIFACE and instantiating
the single KIWAY_PLAYER, see bullet immediately above.
*) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this
gives the KIFACEs a chance to save their final configuration dope to disk.
*) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and
these modal frames are distinctly different than their non-modal equivalents.
KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor,
so this is another important reason for having a dedicated FRAME_T for each
modal wxFrame.
On balance, more lines were deleted than were added to achieve all this.
2014-05-03 17:40:19 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
// Save the default net class first.
|
2014-05-15 08:51:08 +00:00
|
|
|
NETCLASS defaultNC = *dsnSettings.GetDefault();
|
2014-05-13 09:22:51 +00:00
|
|
|
filterNetClass( *aBoard, defaultNC ); // Remove empty nets (from a copy of a netclass)
|
|
|
|
defaultNC.Format( m_out, aNestLevel, m_ctl );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save the rest of the net classes alphabetically.
|
2014-05-13 09:22:51 +00:00
|
|
|
for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
|
2014-05-26 06:21:25 +00:00
|
|
|
it != dsnSettings.m_NetClasses.end();
|
|
|
|
++it )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
NETCLASS netclass = *it->second;
|
|
|
|
filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
|
|
|
|
netclass.Format( m_out, aNestLevel, m_ctl );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
2017-04-15 16:08:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-09-17 12:04:57 +00:00
|
|
|
void PCB_IO::formatHeader( BOARD* aBoard, int aNestLevel ) const
|
2017-05-18 16:43:01 +00:00
|
|
|
{
|
2017-10-27 08:59:49 +00:00
|
|
|
formatGeneral( aBoard, aNestLevel );
|
2017-05-18 16:43:01 +00:00
|
|
|
// Layers.
|
2017-10-27 08:59:49 +00:00
|
|
|
formatBoardLayers( aBoard, aNestLevel );
|
2017-05-18 16:43:01 +00:00
|
|
|
// Setup
|
|
|
|
formatSetup( aBoard, aNestLevel );
|
|
|
|
// Save net codes and names
|
|
|
|
formatNetInformation( aBoard, aNestLevel );
|
|
|
|
}
|
|
|
|
|
2017-04-15 16:08:23 +00:00
|
|
|
void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
|
|
|
|
{
|
2017-10-27 08:59:49 +00:00
|
|
|
formatHeader( aBoard, aNestLevel );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save the modules.
|
2015-11-04 08:48:34 +00:00
|
|
|
for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
Format( module, aNestLevel );
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
// Save the graphical items on the board (not owned by a module)
|
2016-09-27 18:04:30 +00:00
|
|
|
for( auto item : aBoard->Drawings() )
|
2012-06-13 23:04:42 +00:00
|
|
|
Format( item, aNestLevel );
|
|
|
|
|
2016-09-27 18:04:30 +00:00
|
|
|
if( aBoard->Drawings().Size() )
|
2012-12-14 16:54:54 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
2012-06-13 23:04:42 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
// Do not save MARKER_PCBs, they can be regenerated easily.
|
|
|
|
|
|
|
|
// Save the tracks and vias.
|
2014-05-26 06:21:25 +00:00
|
|
|
for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
|
2012-06-09 17:00:13 +00:00
|
|
|
Format( track, aNestLevel );
|
|
|
|
|
2012-12-14 16:54:54 +00:00
|
|
|
if( aBoard->m_Track.GetCount() )
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
/// @todo Add warning here that the old segment filed zones are no longer supported and
|
|
|
|
/// will not be saved.
|
|
|
|
|
|
|
|
// Save the polygon (which are the newer technology) zones.
|
2014-05-26 06:21:25 +00:00
|
|
|
for( int i = 0; i < aBoard->GetAreaCount(); ++i )
|
2012-06-09 17:00:13 +00:00
|
|
|
Format( aBoard->GetArea( i ), aNestLevel );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( DIMENSION* aDimension, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel, "(dimension %s (width %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->GetValue() ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->GetWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
formatLayer( aDimension );
|
|
|
|
|
|
|
|
if( aDimension->GetTimeStamp() )
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)", (unsigned long)aDimension->GetTimeStamp() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2015-11-04 08:48:34 +00:00
|
|
|
Format( &aDimension->Text(), aNestLevel+1 );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(feature1 (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_featureLineDO.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_featureLineDO.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_featureLineDF.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_featureLineDF.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(feature2 (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_featureLineGO.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_featureLineGO.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_featureLineGF.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_featureLineGF.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(crossbar (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarF.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(arrow1a (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowD1F.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowD1F.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(arrow1b (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_crossBarF.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarF.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowD2F.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowD2F.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(arrow2a (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowG1F.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowG1F.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, "(arrow2b (pts (xy %s %s) (xy %s %s)))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aDimension->m_crossBarO.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_crossBarO.y ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowG2F.x ).c_str(),
|
|
|
|
FormatInternalUnits( aDimension->m_arrowG2F.y ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aSegment->GetShape() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
case S_SEGMENT: // Line
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aSegment->GetStart() ).c_str(),
|
|
|
|
FormatInternalUnits( aSegment->GetEnd() ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
|
|
|
if( aSegment->GetAngle() != 0.0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (angle %s)", FormatAngle( aSegment->GetAngle() ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_CIRCLE: // Circle
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(gr_circle (center %s) (end %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aSegment->GetStart() ).c_str(),
|
|
|
|
FormatInternalUnits( aSegment->GetEnd() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_ARC: // Arc
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aSegment->GetStart() ).c_str(),
|
|
|
|
FormatInternalUnits( aSegment->GetEnd() ).c_str(),
|
|
|
|
FormatAngle( aSegment->GetAngle() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_POLYGON: // Polygon
|
2018-01-24 13:22:43 +00:00
|
|
|
if( aSegment->IsPolyShapeValid() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET& poly = aSegment->GetPolyShape();
|
|
|
|
SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
|
|
|
|
int pointsCount = outline.PointCount();
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "(gr_poly (pts" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
for( int ii = 0; ii < pointsCount; ++ii )
|
|
|
|
{
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (xy %s)", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
|
2018-01-24 13:22:43 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
2018-04-02 17:02:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_CURVE: // Bezier curve
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aSegment->GetStart() ).c_str(),
|
|
|
|
FormatInternalUnits( aSegment->GetBezControl1() ).c_str(),
|
|
|
|
FormatInternalUnits( aSegment->GetBezControl2() ).c_str(),
|
|
|
|
FormatInternalUnits( aSegment->GetEnd() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
default:
|
2012-06-09 17:00:13 +00:00
|
|
|
wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
|
2018-04-02 17:02:47 +00:00
|
|
|
return;
|
2012-06-09 17:00:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
formatLayer( aSegment );
|
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (width %s)", FormatInternalUnits( aSegment->GetWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aSegment->GetTimeStamp() )
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)", (unsigned long)aSegment->GetTimeStamp() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aSegment->GetStatus() )
|
|
|
|
m_out->Print( 0, " (status %X)", aSegment->GetStatus() );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aModuleDrawing->GetShape() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
case S_SEGMENT: // Line
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
|
|
|
|
FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_CIRCLE: // Circle
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(fp_circle (center %s) (end %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
|
|
|
|
FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_ARC: // Arc
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
|
|
|
|
FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str(),
|
|
|
|
FormatAngle( aModuleDrawing->GetAngle() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
case S_POLYGON: // Polygonal segment
|
|
|
|
if( aModuleDrawing->IsPolyShapeValid() )
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
2018-01-24 13:22:43 +00:00
|
|
|
SHAPE_POLY_SET& poly = aModuleDrawing->GetPolyShape();
|
|
|
|
SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
|
|
|
|
int pointsCount = outline.PointCount();
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, "(fp_poly (pts" );
|
2012-08-11 05:50:17 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
for( int ii = 0; ii < pointsCount; ++ii )
|
2012-08-11 05:50:17 +00:00
|
|
|
{
|
2018-01-24 13:22:43 +00:00
|
|
|
int nestLevel = 0;
|
|
|
|
|
|
|
|
if( ii && !( ii%4 ) ) // newline every 4 pts
|
|
|
|
{
|
|
|
|
nestLevel = aNestLevel + 1;
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( nestLevel, "%s(xy %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
nestLevel ? "" : " ", FormatInternalUnits( outline.CPoint( ii ) ).c_str() );
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
m_out->Print( 0, ")" );
|
2012-08-11 05:50:17 +00:00
|
|
|
}
|
2018-04-02 17:02:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
|
|
|
|
return;
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
case S_CURVE: // Bezier curve
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(fp_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModuleDrawing->GetStart0() ).c_str(),
|
|
|
|
FormatInternalUnits( aModuleDrawing->GetBezier0_C1() ).c_str(),
|
|
|
|
FormatInternalUnits( aModuleDrawing->GetBezier0_C2() ).c_str(),
|
|
|
|
FormatInternalUnits( aModuleDrawing->GetEnd0() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
default:
|
2012-06-09 17:00:13 +00:00
|
|
|
wxFAIL_MSG( wxT( "Cannot format invalid DRAWSEGMENT type." ) );
|
2018-04-02 17:02:47 +00:00
|
|
|
return;
|
2012-06-09 17:00:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
formatLayer( aModuleDrawing );
|
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (width %s)", FormatInternalUnits( aModuleDrawing->GetWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
|
2014-05-26 06:21:25 +00:00
|
|
|
( aTarget->GetShape() ) ? "x" : "plus",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aTarget->GetPosition() ).c_str(),
|
|
|
|
FormatInternalUnits( aTarget->GetSize() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aTarget->GetWidth() != 0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (width %s)", FormatInternalUnits( aTarget->GetWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
formatLayer( aTarget );
|
|
|
|
|
|
|
|
if( aTarget->GetTimeStamp() )
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTarget->GetTimeStamp() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( MODULE* aModule, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
|
2013-06-23 19:18:33 +00:00
|
|
|
{
|
2013-06-24 05:30:22 +00:00
|
|
|
const wxArrayString* initial_comments = aModule->GetInitialComments();
|
|
|
|
|
|
|
|
if( initial_comments )
|
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
for( unsigned i=0; i<initial_comments->GetCount(); ++i )
|
|
|
|
m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
|
2013-06-24 05:30:22 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" ); // improve readability?
|
|
|
|
}
|
2013-06-23 19:18:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel, "(module %s",
|
|
|
|
m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aModule->IsLocked() )
|
2013-08-08 16:09:49 +00:00
|
|
|
m_out->Print( 0, " locked" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aModule->IsPlaced() )
|
2013-08-08 16:09:49 +00:00
|
|
|
m_out->Print( 0, " placed" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
formatLayer( aModule );
|
|
|
|
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tedit %lX)", (unsigned long)aModule->GetLastEditTime() );
|
2014-06-02 10:46:29 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)\n", (unsigned long)aModule->GetTimeStamp() );
|
2014-05-26 06:21:25 +00:00
|
|
|
}
|
|
|
|
else
|
2012-11-14 07:15:59 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_AT ) )
|
2013-11-28 16:40:23 +00:00
|
|
|
{
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(at %s", FormatInternalUnits( aModule->GetPosition() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-11-28 16:40:23 +00:00
|
|
|
if( aModule->GetOrientation() != 0.0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " %s", FormatAngle( aModule->GetOrientation() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-11-28 16:40:23 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !aModule->GetDescription().IsEmpty() )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(descr %s)\n",
|
|
|
|
m_out->Quotew( aModule->GetDescription() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !aModule->GetKeywords().IsEmpty() )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(tags %s)\n",
|
|
|
|
m_out->Quotew( aModule->GetKeywords() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
|
|
|
|
m_out->Print( aNestLevel+1, "(path %s)\n",
|
|
|
|
m_out->Quotew( aModule->GetPath() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetPlacementCost90() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetPlacementCost180() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aModule->GetLocalSolderMaskMargin() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModule->GetLocalSolderMaskMargin() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aModule->GetLocalSolderPasteMargin() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModule->GetLocalSolderPasteMargin() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
|
|
|
|
Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aModule->GetLocalClearance() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(clearance %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModule->GetLocalClearance() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2015-08-18 14:19:17 +00:00
|
|
|
if( aModule->GetZoneConnection() != PAD_ZONE_CONN_INHERITED )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(zone_connect %d)\n", aModule->GetZoneConnection() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetThermalWidth() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModule->GetThermalWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetThermalGap() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aModule->GetThermalGap() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
// Attributes
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetAttributes() != MOD_DEFAULT )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(attr" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetAttributes() & MOD_CMS )
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out->Print( 0, " smd" );
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( aModule->GetAttributes() & MOD_VIRTUAL )
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out->Print( 0, " virtual" );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
|
|
|
|
Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save drawing elements.
|
2017-04-25 09:06:24 +00:00
|
|
|
for( BOARD_ITEM* gr = aModule->GraphicalItemsList(); gr; gr = gr->Next() )
|
2014-05-26 06:21:25 +00:00
|
|
|
Format( gr, aNestLevel+1 );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save pads.
|
2017-04-25 09:06:24 +00:00
|
|
|
for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
|
2014-05-26 06:21:25 +00:00
|
|
|
format( pad, aNestLevel+1 );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save 3D info.
|
2017-10-27 14:25:20 +00:00
|
|
|
auto bs3D = aModule->Models().begin();
|
|
|
|
auto es3D = aModule->Models().end();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
while( bs3D != es3D )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
if( !bs3D->m_Filename.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(model %s\n",
|
2016-07-19 17:35:25 +00:00
|
|
|
m_out->Quotew( bs3D->m_Filename ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-11-23 10:21:48 +00:00
|
|
|
/* Write 3D model offset in mm
|
|
|
|
* 4.0.x wrote "at" which was actually in inches
|
2017-11-26 21:20:02 +00:00
|
|
|
* 5.0.x onwards, 3D model offset is written using "offset"
|
2017-11-27 10:46:53 +00:00
|
|
|
*
|
|
|
|
* If the offset is all zero, write "at" (fewer file changes)
|
|
|
|
* Otherwise, write "offset"
|
2017-11-23 10:21:48 +00:00
|
|
|
*/
|
2017-11-26 21:20:02 +00:00
|
|
|
|
2017-11-27 10:46:53 +00:00
|
|
|
wxString offsetTag = "offset";
|
|
|
|
|
|
|
|
if( bs3D->m_Offset.x == 0 &&
|
|
|
|
bs3D->m_Offset.y == 0 &&
|
|
|
|
bs3D->m_Offset.z == 0 )
|
|
|
|
{
|
|
|
|
offsetTag = "at";
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+2, "(%s (xyz %s %s %s))\n",
|
|
|
|
offsetTag.ToStdString().c_str(),
|
2016-07-19 17:35:25 +00:00
|
|
|
Double2Str( bs3D->m_Offset.x ).c_str(),
|
|
|
|
Double2Str( bs3D->m_Offset.y ).c_str(),
|
|
|
|
Double2Str( bs3D->m_Offset.z ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
|
2016-07-19 17:35:25 +00:00
|
|
|
Double2Str( bs3D->m_Scale.x ).c_str(),
|
|
|
|
Double2Str( bs3D->m_Scale.y ).c_str(),
|
|
|
|
Double2Str( bs3D->m_Scale.z ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
|
2016-07-19 17:35:25 +00:00
|
|
|
Double2Str( bs3D->m_Rotation.x ).c_str(),
|
|
|
|
Double2Str( bs3D->m_Rotation.y ).c_str(),
|
|
|
|
Double2Str( bs3D->m_Rotation.z ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
++bs3D;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
void PCB_IO::formatLayers( LSET aLayerMask, int aNestLevel ) const
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
std::string output;
|
2013-09-26 05:29:54 +00:00
|
|
|
|
|
|
|
if( aNestLevel == 0 )
|
|
|
|
output += ' ';
|
|
|
|
|
|
|
|
output += "(layers";
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
static const LSET cu_all( LSET::AllCuMask() );
|
|
|
|
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 );
|
|
|
|
|
|
|
|
LSET cu_mask = cu_all;
|
2012-11-14 07:15:59 +00:00
|
|
|
|
|
|
|
// output copper layers first, then non copper
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( aLayerMask & cu_mask ) == cu_mask )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
output += " *.Cu";
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= ~cu_all; // clear bits, so they are not output again below
|
2014-05-26 06:21:25 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
else if( ( aLayerMask & cu_mask ) == fr_bk )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
output += " F&B.Cu";
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= ~fr_bk;
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( aLayerMask & adhes ) == adhes )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
output += " *.Adhes";
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= ~adhes;
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( aLayerMask & paste ) == paste )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
output += " *.Paste";
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= ~paste;
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( aLayerMask & silks ) == silks )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
output += " *.SilkS";
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= ~silks;
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( aLayerMask & mask ) == mask )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
output += " *.Mask";
|
2014-06-24 16:17:18 +00:00
|
|
|
aLayerMask &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & crt_yd ) == crt_yd )
|
|
|
|
{
|
|
|
|
output += " *.CrtYd";
|
|
|
|
aLayerMask &= ~crt_yd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( aLayerMask & fab ) == fab )
|
|
|
|
{
|
|
|
|
output += " *.Fab";
|
|
|
|
aLayerMask &= ~fab;
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// output any individual layers not handled in wildcard combos above
|
|
|
|
|
|
|
|
wxString layerName;
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( aLayerMask[layer] )
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
|
2017-03-13 03:19:33 +00:00
|
|
|
layerName = m_board->GetLayerName( PCB_LAYER_ID( layer ) );
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
else // I am being called from FootprintSave()
|
2017-03-13 03:19:33 +00:00
|
|
|
layerName = BOARD::GetStandardLayerName( PCB_LAYER_ID( layer ) );
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2013-09-26 05:29:54 +00:00
|
|
|
output += ' ';
|
|
|
|
output += m_out->Quotew( layerName );
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 05:29:54 +00:00
|
|
|
m_out->Print( aNestLevel, "%s)", output.c_str() );
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2012-10-24 18:42:39 +00:00
|
|
|
const char* shape;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aPad->GetShape() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2017-01-13 17:51:22 +00:00
|
|
|
case PAD_SHAPE_CIRCLE: shape = "circle"; break;
|
|
|
|
case PAD_SHAPE_RECT: shape = "rect"; break;
|
|
|
|
case PAD_SHAPE_OVAL: shape = "oval"; break;
|
|
|
|
case PAD_SHAPE_TRAPEZOID: shape = "trapezoid"; break;
|
|
|
|
case PAD_SHAPE_ROUNDRECT: shape = "roundrect"; break;
|
|
|
|
case PAD_SHAPE_CUSTOM: shape = "custom"; break;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
default:
|
2014-05-26 06:21:25 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 18:42:39 +00:00
|
|
|
const char* type;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aPad->GetAttribute() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_ATTRIB_STANDARD: type = "thru_hole"; break;
|
|
|
|
case PAD_ATTRIB_SMD: type = "smd"; break;
|
|
|
|
case PAD_ATTRIB_CONN: type = "connect"; break;
|
|
|
|
case PAD_ATTRIB_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
default:
|
2018-11-16 08:43:40 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( "unknown pad attribute: %d", aPad->GetAttribute() ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel, "(pad %s %s %s",
|
2017-08-11 09:22:13 +00:00
|
|
|
m_out->Quotew( aPad->GetName() ).c_str(),
|
2014-05-26 06:21:25 +00:00
|
|
|
type, shape );
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetOrientation() != 0.0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " %s", FormatAngle( aPad->GetOrientation() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
m_out->Print( 0, ")" );
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (size %s)", FormatInternalUnits( aPad->GetSize() ).c_str() );
|
2012-06-13 23:04:42 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (rect_delta %s )", FormatInternalUnits( aPad->GetDelta() ).c_str() );
|
2012-06-13 23:04:42 +00:00
|
|
|
|
|
|
|
wxSize sz = aPad->GetDrillSize();
|
2013-04-10 19:20:35 +00:00
|
|
|
wxPoint shapeoffset = aPad->GetOffset();
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
|
|
|
|
(shapeoffset.x != 0) || (shapeoffset.y != 0) )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " (drill" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
|
2012-06-13 23:04:42 +00:00
|
|
|
m_out->Print( 0, " oval" );
|
|
|
|
|
2012-06-24 01:19:41 +00:00
|
|
|
if( sz.GetWidth() > 0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " %s", FormatInternalUnits( sz.GetWidth() ).c_str() );
|
2012-06-24 01:19:41 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " %s", FormatInternalUnits( sz.GetHeight() ).c_str() );
|
2012-06-13 23:04:42 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (offset %s)", FormatInternalUnits( aPad->GetOffset() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, ")" );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 16:31:11 +00:00
|
|
|
formatLayers( aPad->GetLayerSet() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2016-04-06 18:15:49 +00:00
|
|
|
// Output the radius ratio for rounded rect pads
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT )
|
|
|
|
{
|
2018-05-03 14:20:50 +00:00
|
|
|
m_out->Print( 0, " (roundrect_rratio %s)",
|
2016-04-06 18:15:49 +00:00
|
|
|
Double2Str( aPad->GetRoundRectRadiusRatio() ).c_str() );
|
|
|
|
}
|
|
|
|
|
2013-09-26 05:29:54 +00:00
|
|
|
std::string output;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-24 01:19:41 +00:00
|
|
|
// Unconnected pad is default net so don't save it.
|
2014-05-26 06:21:25 +00:00
|
|
|
if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
|
2014-02-25 10:47:27 +00:00
|
|
|
StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Quotew( aPad->GetNetname() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-12-12 11:57:17 +00:00
|
|
|
if( aPad->GetPadToDieLength() != 0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
StrPrintf( &output, " (die_length %s)", FormatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetLocalSolderMaskMargin() != 0 )
|
2018-05-03 14:20:50 +00:00
|
|
|
StrPrintf( &output, " (solder_mask_margin %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aPad->GetLocalSolderMaskMargin() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetLocalSolderPasteMargin() != 0 )
|
2018-05-03 14:20:50 +00:00
|
|
|
StrPrintf( &output, " (solder_paste_margin %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aPad->GetLocalSolderPasteMargin() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
|
2013-09-26 15:02:46 +00:00
|
|
|
StrPrintf( &output, " (solder_paste_margin_ratio %s)",
|
2018-05-03 14:20:50 +00:00
|
|
|
Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetLocalClearance() != 0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
StrPrintf( &output, " (clearance %s)", FormatInternalUnits( aPad->GetLocalClearance() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2015-08-18 14:19:17 +00:00
|
|
|
if( aPad->GetZoneConnection() != PAD_ZONE_CONN_INHERITED )
|
2013-09-26 15:02:46 +00:00
|
|
|
StrPrintf( &output, " (zone_connect %d)", aPad->GetZoneConnection() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetThermalWidth() != 0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
StrPrintf( &output, " (thermal_width %s)", FormatInternalUnits( aPad->GetThermalWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aPad->GetThermalGap() != 0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
StrPrintf( &output, " (thermal_gap %s)", FormatInternalUnits( aPad->GetThermalGap() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-09-26 05:29:54 +00:00
|
|
|
if( output.size() )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
|
2013-09-26 05:29:54 +00:00
|
|
|
}
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
m_out->Print( aNestLevel+1, "(options" );
|
|
|
|
|
|
|
|
if( aPad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL )
|
|
|
|
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)
|
|
|
|
if( aPad->GetAnchorPadShape() == PAD_SHAPE_RECT )
|
|
|
|
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
|
2017-09-20 08:28:52 +00:00
|
|
|
for( unsigned icnt = 0; icnt < aPad->GetPrimitives().size(); ++icnt )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
const PAD_CS_PRIMITIVE& primitive = aPad->GetPrimitives()[icnt];
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
switch( primitive.m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT: // usual segment : line with rounded ends
|
|
|
|
m_out->Print( nested_level, "(gr_line (start %s) (end %s) (width %s))",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( primitive.m_Start ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_End ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_Thickness ).c_str() );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC: // Arc with rounded ends
|
|
|
|
m_out->Print( nested_level, "(gr_arc (start %s) (end %s) (angle %s) (width %s))",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( primitive.m_Start ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_End ).c_str(),
|
|
|
|
FormatAngle( primitive.m_ArcAngle ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_Thickness ).c_str() );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE: // ring or circle (circle if width == 0
|
|
|
|
m_out->Print( nested_level, "(gr_circle (center %s) (end %s %s) (width %s))",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( primitive.m_Start ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_Start.x + primitive.m_Radius ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_Start.y ).c_str(),
|
|
|
|
FormatInternalUnits( primitive.m_Thickness ).c_str() );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON: // polygon
|
|
|
|
if( primitive.m_Poly.size() < 2 )
|
|
|
|
break; // Malformed polygon.
|
|
|
|
|
|
|
|
{
|
|
|
|
m_out->Print( nested_level, "(gr_poly (pts\n");
|
|
|
|
|
|
|
|
// Write the polygon corners coordinates:
|
|
|
|
const std::vector< wxPoint>& poly = primitive.m_Poly;
|
|
|
|
int newLine = 0;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < poly.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( newLine == 0 )
|
2018-05-03 14:20:50 +00:00
|
|
|
m_out->Print( nested_level+1, " (xy %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
|
2017-01-13 17:51:22 +00:00
|
|
|
else
|
2018-05-03 14:20:50 +00:00
|
|
|
m_out->Print( 0, " (xy %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( wxPoint( poly[ii].x, poly[ii].y ) ).c_str() );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
if( ++newLine > 4 )
|
|
|
|
{
|
|
|
|
newLine = 0;
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, ") (width %s))", FormatInternalUnits( primitive.m_Thickness ).c_str() );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n");
|
|
|
|
m_out->Print( aNestLevel+1, ")" ); // end of (basic_shapes
|
|
|
|
}
|
|
|
|
|
2013-09-26 05:29:54 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( TEXTE_PCB* aText, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel, "(gr_text %s (at %s",
|
|
|
|
m_out->Quotew( aText->GetText() ).c_str(),
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aText->GetTextPos() ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
if( aText->GetTextAngle() != 0.0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " %s", FormatAngle( aText->GetTextAngle() ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
formatLayer( aText );
|
|
|
|
|
|
|
|
if( aText->GetTimeStamp() )
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)", (unsigned long)aText->GetTimeStamp() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
wxString type;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aText->GetType() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
case TEXTE_MODULE::TEXT_is_REFERENCE: type = "reference"; break;
|
|
|
|
case TEXTE_MODULE::TEXT_is_VALUE: type = "value"; break;
|
|
|
|
case TEXTE_MODULE::TEXT_is_DIVERS: type = "user";
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
|
|
|
|
m_out->Quotew( type ).c_str(),
|
|
|
|
m_out->Quotew( aText->GetText() ).c_str(),
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aText->GetPos0() ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
// Due to Pcbnew history, fp_text angle is saved as an absolute on screen angle,
|
|
|
|
// but internally the angle is held relative to its parent footprint. parent
|
|
|
|
// may be NULL when saving a footprint outside a BOARD.
|
|
|
|
double orient = aText->GetTextAngle();
|
|
|
|
MODULE* parent = (MODULE*) aText->GetParent();
|
|
|
|
|
|
|
|
if( parent )
|
|
|
|
{
|
|
|
|
// GetTextAngle() is always in -360..+360 range because of
|
|
|
|
// TEXTE_MODULE::SetTextAngle(), but summing that angle with an
|
|
|
|
// additional board angle could kick sum up >= 360 or <= -360, so to have
|
|
|
|
// consistent results, normalize again for the BOARD save. A footprint
|
|
|
|
// save does not use this code path since parent is NULL.
|
|
|
|
#if 0
|
|
|
|
// This one could be considered reasonable if you like positive angles
|
|
|
|
// in your board text.
|
|
|
|
orient = NormalizeAnglePos( orient + parent->GetOrientation() );
|
|
|
|
#else
|
|
|
|
// Choose compatibility for now, even though this is only a 720 degree clamp
|
|
|
|
// with two possible values for every angle.
|
2017-10-23 13:35:03 +00:00
|
|
|
orient = NormalizeAngle360Min( orient + parent->GetOrientation() );
|
2017-01-23 20:30:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( orient != 0.0 )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " %s", FormatAngle( orient ).c_str() );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
if( !aText->IsKeepUpright() )
|
2017-11-25 19:55:32 +00:00
|
|
|
m_out->Print( 0, " unlocked" );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, ")" );
|
2012-06-11 00:47:15 +00:00
|
|
|
formatLayer( aText );
|
|
|
|
|
|
|
|
if( !aText->IsVisible() )
|
|
|
|
m_out->Print( 0, " hide" );
|
|
|
|
|
|
|
|
m_out->Print( 0, "\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-01-27 21:44:41 +00:00
|
|
|
aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
if( aTrack->Type() == PCB_VIA_T )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer1, layer2;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
const VIA* via = static_cast<const VIA*>( aTrack );
|
2014-06-24 16:17:18 +00:00
|
|
|
BOARD* board = (BOARD*) via->GetParent();
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText( MILLIMETRES ) +
|
2014-05-26 06:21:25 +00:00
|
|
|
wxT( " has no parent." ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( aNestLevel, "(via" );
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
via->LayerPair( &layer1, &layer2 );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( via->GetViaType() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2012-06-16 22:49:24 +00:00
|
|
|
case VIA_THROUGH: // Default shape not saved.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIA_BLIND_BURIED:
|
|
|
|
m_out->Print( 0, " blind" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIA_MICROVIA:
|
|
|
|
m_out->Print( 0, " micro" );
|
|
|
|
break;
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
default:
|
2014-05-26 06:21:25 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " (at %s) (size %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aTrack->GetStart() ).c_str(),
|
|
|
|
FormatInternalUnits( aTrack->GetWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
|
2019-01-08 05:42:50 +00:00
|
|
|
m_out->Print( 0, " (drill %s)", FormatInternalUnits( via->GetDrill() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, " (layers %s %s)",
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
|
|
|
|
m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
|
|
|
|
}
|
|
|
|
else
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aTrack->GetStart() ).c_str(), FormatInternalUnits( aTrack->GetEnd() ).c_str(),
|
|
|
|
FormatInternalUnits( aTrack->GetWidth() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, " (layer %s)", m_out->Quotew( aTrack->GetLayerName() ).c_str() );
|
|
|
|
}
|
|
|
|
|
2014-02-25 10:47:27 +00:00
|
|
|
m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aTrack->GetTimeStamp() != 0 )
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)", (unsigned long)aTrack->GetTimeStamp() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aTrack->GetStatus() != 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( 0, " (status %X)", aTrack->GetStatus() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
|
|
|
void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2013-03-01 19:59:29 +00:00
|
|
|
// Save the NET info; For keepout zones, net code and net name are irrelevant
|
|
|
|
// so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
|
|
|
|
// (perhaps netcode and netname should be not stored)
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
|
2014-05-26 06:21:25 +00:00
|
|
|
aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
|
|
|
|
m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-09-29 09:40:10 +00:00
|
|
|
// If a zone exists on multiple layers, format accordingly
|
|
|
|
if( aZone->GetLayerSet().count() > 1 )
|
|
|
|
{
|
|
|
|
formatLayers( aZone->GetLayerSet() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
formatLayer( aZone );
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2016-09-24 15:53:22 +00:00
|
|
|
m_out->Print( 0, " (tstamp %lX)", (unsigned long) aZone->GetTimeStamp() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
// Save the outline aux info
|
|
|
|
std::string hatch;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aZone->GetHatchStyle() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
default:
|
2017-03-07 12:06:00 +00:00
|
|
|
case ZONE_CONTAINER::NO_HATCH: hatch = "none"; break;
|
|
|
|
case ZONE_CONTAINER::DIAGONAL_EDGE: hatch = "edge"; break;
|
|
|
|
case ZONE_CONTAINER::DIAGONAL_FULL: hatch = "full"; break;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aZone->GetHatchPitch() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( aZone->GetPriority() > 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(connect_pads" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aZone->GetPadConnection() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
default:
|
2015-08-18 14:19:17 +00:00
|
|
|
case PAD_ZONE_CONN_THERMAL: // Default option not saved or loaded.
|
2012-06-16 22:49:24 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-18 14:19:17 +00:00
|
|
|
case PAD_ZONE_CONN_THT_THERMAL:
|
2012-07-09 07:10:07 +00:00
|
|
|
m_out->Print( 0, " thru_hole_only" );
|
|
|
|
break;
|
|
|
|
|
2015-08-18 14:19:17 +00:00
|
|
|
case PAD_ZONE_CONN_FULL:
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " yes" );
|
|
|
|
break;
|
|
|
|
|
2015-08-18 14:19:17 +00:00
|
|
|
case PAD_ZONE_CONN_NONE:
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " no" );
|
|
|
|
break;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " (clearance %s))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aZone->GetZoneClearance() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(min_thickness %s)\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aZone->GetMinThickness() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
if( aZone->GetIsKeepout() )
|
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
|
|
|
|
aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
|
|
|
|
aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
|
|
|
|
aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(fill" );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
|
|
|
// Default is not filled.
|
|
|
|
if( aZone->IsFilled() )
|
|
|
|
m_out->Print( 0, " yes" );
|
|
|
|
|
|
|
|
// Default is polygon filled.
|
|
|
|
if( aZone->GetFillMode() )
|
2012-06-19 04:23:42 +00:00
|
|
|
m_out->Print( 0, " (mode segment)" );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2012-06-19 04:08:00 +00:00
|
|
|
m_out->Print( 0, " (arc_segments %d) (thermal_gap %s) (thermal_bridge_width %s)",
|
2014-05-26 06:21:25 +00:00
|
|
|
aZone->GetArcSegmentCount(),
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
|
|
|
|
FormatInternalUnits( aZone->GetThermalReliefCopperBridge() ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( aZone->GetCornerSmoothingType() != ZONE_SETTINGS::SMOOTHING_NONE )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2012-06-19 04:23:42 +00:00
|
|
|
m_out->Print( 0, " (smoothing" );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
switch( aZone->GetCornerSmoothingType() )
|
2012-06-16 22:49:24 +00:00
|
|
|
{
|
|
|
|
case ZONE_SETTINGS::SMOOTHING_CHAMFER:
|
|
|
|
m_out->Print( 0, " chamfer" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZONE_SETTINGS::SMOOTHING_FILLET:
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( 0, " fillet" );
|
2012-06-16 22:49:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-05-26 06:21:25 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
|
|
|
|
aZone->GetCornerSmoothingType() ) );
|
2012-06-16 22:49:24 +00:00
|
|
|
}
|
2012-06-19 04:08:00 +00:00
|
|
|
m_out->Print( 0, ")" );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
|
|
|
if( aZone->GetCornerRadius() != 0 )
|
2012-06-19 04:08:00 +00:00
|
|
|
m_out->Print( 0, " (radius %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( aZone->GetCornerRadius() ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
int newLine = 0;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
if( aZone->GetNumCorners() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2017-04-07 06:02:26 +00:00
|
|
|
bool new_polygon = true;
|
|
|
|
bool is_closed = false;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto iterator = aZone->IterateWithHoles(); iterator; iterator++ )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2017-04-07 06:02:26 +00:00
|
|
|
if( new_polygon )
|
|
|
|
{
|
|
|
|
newLine = 0;
|
|
|
|
m_out->Print( aNestLevel+1, "(polygon\n" );
|
|
|
|
m_out->Print( aNestLevel+2, "(pts\n" );
|
|
|
|
new_polygon = false;
|
|
|
|
is_closed = false;
|
|
|
|
}
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( newLine == 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+3, "(xy %s %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
else
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " (xy %s %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( iterator->x ).c_str(), FormatInternalUnits( iterator->y ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( newLine < 4 )
|
|
|
|
{
|
|
|
|
newLine += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newLine = 0;
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
if( iterator.IsEndContour() )
|
2014-05-26 06:21:25 +00:00
|
|
|
{
|
2017-04-07 06:02:26 +00:00
|
|
|
is_closed = true;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( newLine != 0 )
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+2, ")\n" );
|
2017-04-07 06:02:26 +00:00
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
|
|
|
new_polygon = true;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
2014-05-26 06:21:25 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-04-07 06:02:26 +00:00
|
|
|
if( !is_closed ) // Should not happen, but...
|
2019-09-21 15:15:08 +00:00
|
|
|
{
|
|
|
|
if( newLine != 0 )
|
|
|
|
m_out->Print( 0, "\n" );
|
2017-04-07 06:02:26 +00:00
|
|
|
|
2019-09-21 15:15:08 +00:00
|
|
|
m_out->Print( aNestLevel+2, ")\n" );
|
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-07 06:02:26 +00:00
|
|
|
// Save the PolysList (filled areas)
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList();
|
2012-06-16 22:49:24 +00:00
|
|
|
newLine = 0;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( !fv.IsEmpty() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2017-04-07 06:02:26 +00:00
|
|
|
bool new_polygon = true;
|
|
|
|
bool is_closed = false;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto it = fv.CIterate(); it; ++it )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2017-04-07 06:02:26 +00:00
|
|
|
if( new_polygon )
|
|
|
|
{
|
|
|
|
newLine = 0;
|
|
|
|
m_out->Print( aNestLevel+1, "(filled_polygon\n" );
|
|
|
|
m_out->Print( aNestLevel+2, "(pts\n" );
|
|
|
|
new_polygon = false;
|
|
|
|
is_closed = false;
|
|
|
|
}
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( newLine == 0 )
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+3, "(xy %s %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( it->x ).c_str(), FormatInternalUnits( it->y ).c_str() );
|
2014-05-26 06:21:25 +00:00
|
|
|
else
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, " (xy %s %s)",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( it->x ) .c_str(), FormatInternalUnits( it->y ).c_str() );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( newLine < 4 )
|
|
|
|
{
|
|
|
|
newLine += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newLine = 0;
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( it.IsEndContour() )
|
2014-05-26 06:21:25 +00:00
|
|
|
{
|
2017-04-07 06:02:26 +00:00
|
|
|
is_closed = true;
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
if( newLine != 0 )
|
2012-06-16 22:49:24 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+2, ")\n" );
|
2017-04-07 06:02:26 +00:00
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
|
|
|
new_polygon = true;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
2014-05-26 06:21:25 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-04-07 06:02:26 +00:00
|
|
|
if( !is_closed ) // Should not happen, but...
|
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the filling segments list
|
2017-12-04 18:06:47 +00:00
|
|
|
const auto& segs = aZone->FillSegments();
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
if( segs.size() )
|
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(fill_segments\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
for( ZONE_SEGMENT_FILL::const_iterator it = segs.begin(); it != segs.end(); ++it )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
|
2019-01-08 05:42:50 +00:00
|
|
|
FormatInternalUnits( wxPoint( it->A ) ).c_str(),
|
|
|
|
FormatInternalUnits( wxPoint( it->B ) ).c_str() );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
PCB_IO::PCB_IO( int aControlFlags ) :
|
2014-05-26 06:21:25 +00:00
|
|
|
m_cache( 0 ),
|
|
|
|
m_ctl( aControlFlags ),
|
|
|
|
m_parser( new PCB_PARSER() ),
|
|
|
|
m_mapping( new NETINFO_MAPPING() )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2012-10-22 20:41:26 +00:00
|
|
|
init( 0 );
|
2012-06-09 17:00:13 +00:00
|
|
|
m_out = &m_sf;
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
PCB_IO::~PCB_IO()
|
|
|
|
{
|
|
|
|
delete m_cache;
|
2012-10-24 18:20:33 +00:00
|
|
|
delete m_parser;
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
delete m_mapping;
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
FILE_LINE_READER reader( aFileName );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2013-06-24 05:30:22 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
2012-10-24 18:20:33 +00:00
|
|
|
m_parser->SetLineReader( &reader );
|
|
|
|
m_parser->SetBoard( aAppendToMe );
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
BOARD* board;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
board = dynamic_cast<BOARD*>( m_parser->Parse() );
|
|
|
|
}
|
2016-10-10 15:04:48 +00:00
|
|
|
catch( const FUTURE_FORMAT_ERROR& )
|
2016-08-17 02:02:05 +00:00
|
|
|
{
|
|
|
|
// Don't wrap a FUTURE_FORMAT_ERROR in another
|
|
|
|
throw;
|
|
|
|
}
|
2016-05-10 19:07:35 +00:00
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
|
|
|
if( m_parser->IsTooRecent() )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
|
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2016-05-11 02:36:39 +00:00
|
|
|
if( !board )
|
|
|
|
{
|
|
|
|
// The parser loaded something that was valid, but wasn't a board.
|
|
|
|
THROW_PARSE_ERROR( _( "this file does not contain a PCB" ),
|
|
|
|
m_parser->CurSource(), m_parser->CurLine(),
|
|
|
|
m_parser->CurLineNumber(), m_parser->CurOffset() );
|
|
|
|
}
|
2012-08-29 16:59:50 +00:00
|
|
|
|
|
|
|
// Give the filename to the board if it's new
|
|
|
|
if( !aAppendToMe )
|
|
|
|
board->SetFileName( aFileName );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
return board;
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void PCB_IO::init( const PROPERTIES* aProperties )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
m_board = NULL;
|
2015-02-22 21:25:29 +00:00
|
|
|
m_reader = NULL;
|
|
|
|
m_loading_format_version = SEXPR_BOARD_FILE_VERSION;
|
2012-10-07 15:37:25 +00:00
|
|
|
m_props = aProperties;
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-02-24 17:41:44 +00:00
|
|
|
void PCB_IO::validateCache( const wxString& aLibraryPath, bool checkModified )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2018-03-04 01:13:09 +00:00
|
|
|
if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
// a spectacular episode in memory management:
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new FP_CACHE( this, aLibraryPath );
|
|
|
|
m_cache->Load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
|
|
|
|
bool aBestEfforts, const PROPERTIES* aProperties )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2019-08-31 14:18:27 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
wxDir dir( aLibPath );
|
|
|
|
wxString errorMsg;
|
2013-12-13 23:01:42 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
try
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2019-08-31 14:18:27 +00:00
|
|
|
validateCache( aLibPath );
|
2017-06-11 20:20:44 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
errorMsg = ioe.What();
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
2013-12-13 23:01:42 +00:00
|
|
|
|
2018-02-10 23:10:39 +00:00
|
|
|
// Some of the files may have been parsed correctly so we want to add the valid files to
|
|
|
|
// the library.
|
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
|
2017-07-25 19:14:31 +00:00
|
|
|
aFootprintNames.Add( it->first );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
if( !errorMsg.IsEmpty() && !aBestEfforts )
|
2017-06-11 20:20:44 +00:00
|
|
|
THROW_IO_ERROR( errorMsg );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-07-30 13:18:37 +00:00
|
|
|
const MODULE* PCB_IO::getFootprint( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
|
|
|
const PROPERTIES* aProperties,
|
|
|
|
bool checkModified )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
2018-02-24 17:41:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
validateCache( aLibraryPath, checkModified );
|
|
|
|
}
|
2018-04-18 07:10:29 +00:00
|
|
|
catch( const IO_ERROR& )
|
2018-02-24 17:41:44 +00:00
|
|
|
{
|
|
|
|
// do nothing with the error
|
|
|
|
}
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
const MODULE_MAP& mods = m_cache->GetModules();
|
|
|
|
|
2017-07-25 19:14:31 +00:00
|
|
|
MODULE_CITER it = mods.find( aFootprintName );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
if( it == mods.end() )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-30 13:18:37 +00:00
|
|
|
return it->second->GetModule();
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-07-30 13:18:37 +00:00
|
|
|
const MODULE* PCB_IO::GetEnumeratedFootprint( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
|
|
|
const PROPERTIES* aProperties )
|
2018-02-23 12:21:06 +00:00
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
|
2018-02-24 17:41:44 +00:00
|
|
|
}
|
2018-02-23 12:21:06 +00:00
|
|
|
|
|
|
|
|
2019-07-11 21:59:14 +00:00
|
|
|
bool PCB_IO::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
// 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".
|
|
|
|
|
|
|
|
wxFileName footprintFile( aLibraryPath, aFootprintName );
|
|
|
|
footprintFile.SetExt( KiCadFootprintFileExtension );
|
|
|
|
|
|
|
|
return footprintFile.Exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-24 17:41:44 +00:00
|
|
|
MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
const MODULE* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
|
|
|
|
return footprint ? new MODULE( *footprint ) : nullptr;
|
2018-02-23 12:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
|
2013-09-25 19:17:06 +00:00
|
|
|
const PROPERTIES* aProperties )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
// In this public PLUGIN API function, we can safely assume it was
|
|
|
|
// called for saving into a library path.
|
|
|
|
m_ctl = CTL_FOR_LIBRARY;
|
|
|
|
|
2018-02-23 12:21:06 +00:00
|
|
|
validateCache( aLibraryPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
if( !m_cache->IsWritable() )
|
|
|
|
{
|
2018-05-04 16:10:51 +00:00
|
|
|
if( !m_cache->Exists() )
|
|
|
|
{
|
2018-05-04 16:59:35 +00:00
|
|
|
const wxString msg = wxString::Format( _( "Library \"%s\" does not exist.\n"
|
2018-07-30 13:18:37 +00:00
|
|
|
"Would you like to create it?"),
|
|
|
|
GetChars( aLibraryPath ) );
|
2018-05-04 16:59:35 +00:00
|
|
|
|
2018-07-30 13:18:37 +00:00
|
|
|
if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
|
2018-05-04 16:59:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Save throws its own IO_ERROR on failure, so no need to recreate here
|
|
|
|
m_cache->Save( NULL );
|
2018-05-04 16:10:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library \"%s\" is read only" ), aLibraryPath );
|
2018-05-04 16:59:35 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
2018-05-04 16:10:51 +00:00
|
|
|
}
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 19:14:31 +00:00
|
|
|
wxString footprintName = aFootprint->GetFPID().GetLibItemName();
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
MODULE_MAP& mods = m_cache->GetModules();
|
|
|
|
|
|
|
|
// Quietly overwrite module and delete module file from path for any by same name.
|
2017-07-24 19:02:59 +00:00
|
|
|
wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetLibItemName(),
|
2016-11-20 23:35:08 +00:00
|
|
|
KiCadFootprintFileExtension );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2018-07-24 07:52:33 +00:00
|
|
|
#ifndef __WINDOWS__
|
2018-07-23 22:49:07 +00:00
|
|
|
// Write through symlinks, don't replace them
|
|
|
|
if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
|
|
|
|
{
|
|
|
|
char buffer[ PATH_MAX + 1 ];
|
|
|
|
ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
|
|
|
|
|
|
|
|
if( pathLen > 0 )
|
|
|
|
{
|
|
|
|
buffer[ pathLen ] = '\0';
|
|
|
|
fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
|
|
|
|
fn.Normalize();
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 07:52:33 +00:00
|
|
|
#endif
|
2018-07-23 22:49:07 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
if( !fn.IsOk() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint file name \"%s\" is not valid." ),
|
2018-07-30 13:18:37 +00:00
|
|
|
fn.GetFullPath() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( fn.FileExists() && !fn.IsFileWritable() )
|
|
|
|
{
|
2018-11-18 13:40:36 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "No write permissions to delete file \"%s\"" ),
|
2018-07-30 13:18:37 +00:00
|
|
|
fn.GetFullPath() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
wxString fullPath = fn.GetFullPath();
|
|
|
|
wxString fullName = fn.GetFullName();
|
2012-10-07 15:37:25 +00:00
|
|
|
MODULE_CITER it = mods.find( footprintName );
|
|
|
|
|
|
|
|
if( it != mods.end() )
|
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
mods.erase( footprintName );
|
2018-08-05 11:56:02 +00:00
|
|
|
wxRemoveFile( fullPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// I need my own copy for the cache
|
|
|
|
MODULE* module = new MODULE( *aFootprint );
|
|
|
|
|
|
|
|
// and it's time stamp must be 0, it should have no parent, orientation should
|
|
|
|
// be zero, and it should be on the front layer.
|
|
|
|
module->SetTimeStamp( 0 );
|
|
|
|
module->SetParent( 0 );
|
|
|
|
module->SetOrientation( 0 );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( module->GetLayer() != F_Cu )
|
2012-10-07 15:37:25 +00:00
|
|
|
module->Flip( module->GetPosition() );
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
|
2018-08-07 21:03:13 +00:00
|
|
|
mods.insert( footprintName, new FP_CACHE_ITEM( module, WX_FILENAME( fn.GetPath(), fullName ) ) );
|
2018-03-28 21:39:26 +00:00
|
|
|
m_cache->Save( module );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-05-03 14:20:50 +00:00
|
|
|
void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
|
|
|
|
const PROPERTIES* aProperties )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
init( aProperties );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2018-02-23 12:21:06 +00:00
|
|
|
validateCache( aLibraryPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
if( !m_cache->IsWritable() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library \"%s\" is read only" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_cache->Remove( aFootprintName );
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2018-02-05 20:55:00 +00:00
|
|
|
|
2018-03-04 01:13:09 +00:00
|
|
|
long long PCB_IO::GetLibraryTimestamp( const wxString& aLibraryPath ) const
|
2018-02-05 20:55:00 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
return FP_CACHE::GetTimestamp( aLibraryPath );
|
2018-02-05 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void PCB_IO::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
if( wxDir::Exists( aLibraryPath ) )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path \"%s\"" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new FP_CACHE( this, aLibraryPath );
|
|
|
|
m_cache->Save();
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
fn.SetPath( aLibraryPath );
|
|
|
|
|
|
|
|
// Return if there is no library path to delete.
|
|
|
|
if( !fn.DirExists() )
|
2012-11-19 16:19:38 +00:00
|
|
|
return false;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
if( !fn.IsDirWritable() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory \"%s\"" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxDir dir( aLibraryPath );
|
|
|
|
|
|
|
|
if( dir.HasSubDirs() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "library directory \"%s\" has unexpected sub-directories" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// All the footprint files must be deleted before the directory can be deleted.
|
|
|
|
if( dir.HasFiles() )
|
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
unsigned i;
|
|
|
|
wxFileName tmp;
|
2012-10-07 15:37:25 +00:00
|
|
|
wxArrayString files;
|
|
|
|
|
|
|
|
wxDir::GetAllFiles( aLibraryPath, &files );
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
for( i = 0; i < files.GetCount(); i++ )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
tmp = files[i];
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
if( tmp.GetExt() != KiCadFootprintFileExtension )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "unexpected file \"%s\" was found in library path \"%s\"" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
files[i].GetData(), aLibraryPath.GetData() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
for( i = 0; i < files.GetCount(); i++ )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
wxRemoveFile( files[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 13:58:25 +00:00
|
|
|
wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library \"%s\"" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
aLibraryPath.GetData() );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
// 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 ) )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "footprint library \"%s\" cannot be deleted" ),
|
2014-05-26 06:21:25 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2013-09-24 18:45:57 +00:00
|
|
|
if( m_cache && !m_cache->IsPath( aLibraryPath ) )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = NULL;
|
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
return true;
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 06:21:25 +00:00
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
bool PCB_IO::IsFootprintLibWritable( const wxString& aLibraryPath )
|
|
|
|
{
|
2014-05-26 06:21:25 +00:00
|
|
|
LOCALE_IO toggle;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
init( NULL );
|
|
|
|
|
2018-02-23 12:21:06 +00:00
|
|
|
validateCache( aLibraryPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
return m_cache->IsWritable();
|
|
|
|
}
|