2012-12-28 20:52:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-09-21 12:58:08 +00:00
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-12-28 20:52:12 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file gpcb_plugin.cpp
|
|
|
|
* @brief Geda PCB file plugin implementation file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
|
|
|
#include <pcb_shape.h>
|
2020-10-04 12:35:04 +00:00
|
|
|
#include <plugins/geda/gpcb_plugin.h>
|
2020-10-25 18:53:05 +00:00
|
|
|
#include <wx_filename.h>
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
#include <wx/dir.h>
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
2012-12-28 20:52:12 +00:00
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <boost/ptr_container/ptr_map.hpp>
|
|
|
|
|
|
|
|
|
2015-10-12 23:31:26 +00:00
|
|
|
static inline long parseInt( const wxString& aValue, double aScalar )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2020-07-02 23:10:31 +00:00
|
|
|
double value = std::numeric_limits<double>::max();
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-10-12 23:31:26 +00:00
|
|
|
/*
|
|
|
|
* In 2011 gEDA/pcb introduced values with units, like "10mm" or "200mil".
|
|
|
|
* Unit-less values are still centimils (100000 units per inch), like with
|
|
|
|
* the previous format.
|
|
|
|
*
|
|
|
|
* Distinction between the even older format (mils, 1000 units per inch)
|
2020-11-14 19:16:42 +00:00
|
|
|
* and the pre-2011 format is done in ::parseFOOTPRINT already; the
|
2021-06-09 19:32:58 +00:00
|
|
|
* distinction is by whether an object definition opens with '(' or '['.
|
|
|
|
* All values with explicit unit open with a '[' so there's no need to
|
2015-10-12 23:31:26 +00:00
|
|
|
* consider this distinction when parsing them.
|
|
|
|
*
|
|
|
|
* The solution here is to watch for a unit and, if present, convert the
|
|
|
|
* value to centimils. All unit-less values are read unaltered. This way
|
2021-06-09 19:32:58 +00:00
|
|
|
* the code below can continue to consider all read values to be in mils or
|
2015-10-12 23:31:26 +00:00
|
|
|
* centimils. It also matches the strategy gEDA/pcb uses for backwards
|
|
|
|
* compatibility with its own layouts.
|
|
|
|
*
|
|
|
|
* Fortunately gEDA/pcb allows only units 'mil' and 'mm' in files, see
|
|
|
|
* definition of ALLOW_READABLE in gEDA/pcb's pcb_printf.h. So we don't
|
|
|
|
* have to test for all 11 units gEDA/pcb allows in user dialogs.
|
|
|
|
*/
|
|
|
|
if( aValue.EndsWith( wxT( "mm" ) ) )
|
|
|
|
{
|
|
|
|
aScalar *= 100000.0 / 25.4;
|
|
|
|
}
|
|
|
|
else if( aValue.EndsWith( wxT( "mil" ) ) )
|
|
|
|
{
|
|
|
|
aScalar *= 100.;
|
|
|
|
}
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-10-12 23:31:26 +00:00
|
|
|
// This conversion reports failure on strings as simple as "1000", still
|
|
|
|
// it returns the right result in &value. Thus, ignore the return value.
|
|
|
|
aValue.ToCDouble(&value);
|
2020-07-02 23:10:31 +00:00
|
|
|
if( value == std::numeric_limits<double>::max() ) // conversion really failed
|
2015-10-12 23:31:26 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Cannot convert '%s' to an integer." ),
|
2015-10-12 23:31:26 +00:00
|
|
|
aValue.GetData() ) );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-10-12 23:31:26 +00:00
|
|
|
return KiROUND( value * aScalar );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* helper class for creating a footprint library cache.
|
2012-12-28 20:52:12 +00:00
|
|
|
*
|
2020-11-13 11:17:15 +00:00
|
|
|
* The new footprint library design is a file path of individual footprint files
|
|
|
|
* that contain a single footprint per file. This class is a helper only for the
|
2021-11-25 12:22:40 +00:00
|
|
|
* footprint portion of the PLUGIN API, and only for the #PCB_PLUGIN plugin. It is
|
2012-12-28 20:52:12 +00:00
|
|
|
* private to this implementation file so it is not placed into a header.
|
|
|
|
*/
|
|
|
|
class GPCB_FPL_CACHE_ITEM
|
|
|
|
{
|
|
|
|
public:
|
2020-11-13 15:15:52 +00:00
|
|
|
GPCB_FPL_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
WX_FILENAME GetFileName() const { return m_filename; }
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* GetFootprint() const { return m_footprint.get(); }
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
WX_FILENAME m_filename; ///< The full file name and path of the footprint to cache.
|
|
|
|
std::unique_ptr<FOOTPRINT> m_footprint;
|
2012-12-28 20:52:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
GPCB_FPL_CACHE_ITEM::GPCB_FPL_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName ) :
|
2020-11-13 11:17:15 +00:00
|
|
|
m_filename( aFileName ),
|
|
|
|
m_footprint( aFootprint )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
typedef boost::ptr_map< std::string, GPCB_FPL_CACHE_ITEM > FOOTPRINT_MAP;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GPCB_FPL_CACHE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GPCB_FPL_CACHE( GPCB_PLUGIN* aOwner, const wxString& aLibraryPath );
|
|
|
|
|
|
|
|
wxString GetPath() const { return m_lib_path.GetPath(); }
|
|
|
|
bool IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
|
2020-11-13 23:03:36 +00:00
|
|
|
FOOTPRINT_MAP& GetFootprints() { return m_footprints; }
|
2012-12-28 20:52:12 +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.
|
|
|
|
|
|
|
|
/// Save not implemented for the Geda PCB footprint library format.
|
|
|
|
|
|
|
|
void Load();
|
|
|
|
|
|
|
|
void Remove( const wxString& aFootprintName );
|
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
/**
|
|
|
|
* Generate a timestamp representing all source files in the cache (including the
|
|
|
|
* parent directory).
|
2021-07-19 23:56:05 +00:00
|
|
|
*
|
2018-03-02 23:44:27 +00:00
|
|
|
* 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-12-12 17:42:38 +00:00
|
|
|
|
|
|
|
/**
|
2018-03-02 23:44:27 +00:00
|
|
|
* Return true if the cache is not up-to-date.
|
2013-12-12 17:42:38 +00:00
|
|
|
*/
|
2018-03-02 23:44:27 +00:00
|
|
|
bool IsModified();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FOOTPRINT* parseFOOTPRINT( LINE_READER* aLineReader );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test \a aFlag for \a aMask or \a aName.
|
|
|
|
*
|
|
|
|
* @param aFlag is a list of flags to test against: can be a bit field flag or a list name flag
|
|
|
|
* a bit field flag is an hexadecimal value: Ox00020000 a list name flag is a
|
|
|
|
* string list of flags, comma separated like square,option1.
|
|
|
|
* @param aMask is the flag list to test.
|
|
|
|
* @param aName is the flag name to find in list.
|
|
|
|
* @return true if found.
|
|
|
|
*/
|
|
|
|
bool testFlags( const wxString& aFlag, long aMask, const wxChar* aName );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract parameters and tokens from \a aLineReader and adds them to \a aParameterList.
|
|
|
|
*
|
|
|
|
* Delimiter characters are:
|
|
|
|
* [ ] ( ) Begin and end of parameter list and units indicator
|
|
|
|
* " is a string delimiter
|
|
|
|
* space is the param separator
|
|
|
|
* The first word is the keyword
|
|
|
|
* the second item is one of ( or [
|
|
|
|
* other are parameters (number or delimited string)
|
|
|
|
* last parameter is ) or ]
|
|
|
|
*
|
|
|
|
* @param aParameterList This list of parameters parsed.
|
|
|
|
* @param aLineReader The line reader object to parse.
|
|
|
|
*/
|
|
|
|
void parseParameters( wxArrayString& aParameterList, LINE_READER* aLineReader );
|
|
|
|
|
|
|
|
GPCB_PLUGIN* m_owner; ///< Plugin object that owns the cache.
|
|
|
|
wxFileName m_lib_path; ///< The path of the library.
|
|
|
|
FOOTPRINT_MAP m_footprints; ///< Map of footprint file name to FOOTPRINT*.
|
|
|
|
|
|
|
|
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.
|
2012-12-28 20:52:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GPCB_FPL_CACHE::GPCB_FPL_CACHE( GPCB_PLUGIN* aOwner, const wxString& aLibraryPath )
|
|
|
|
{
|
|
|
|
m_owner = aOwner;
|
|
|
|
m_lib_path.SetPath( aLibraryPath );
|
2018-03-02 23:44:27 +00:00
|
|
|
m_cache_timestamp = 0;
|
|
|
|
m_cache_dirty = true;
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPCB_FPL_CACHE::Load()
|
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_dirty = false;
|
|
|
|
m_cache_timestamp = 0;
|
|
|
|
|
2017-05-23 18:07:36 +00:00
|
|
|
// Note: like our .pretty footprint libraries, the gpcb footprint libraries are folders,
|
|
|
|
// and the footprints are the .fp files inside this folder.
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
wxDir dir( m_lib_path.GetPath() );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
if( !dir.IsOpened() )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' not found." ),
|
2012-12-28 20:52:12 +00:00
|
|
|
m_lib_path.GetPath().GetData() ) );
|
|
|
|
}
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
wxString fullName;
|
|
|
|
wxString fileSpec = wxT( "*." ) + GedaPcbFootprintLibFileExtension;
|
2012-12-28 20:52:12 +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_path.GetPath(), wxT( "dummyName" ) );
|
2018-08-03 16:53:38 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
if( !dir.GetFirst( &fullName, fileSpec ) )
|
2012-12-28 20:52:12 +00:00
|
|
|
return;
|
|
|
|
|
2017-05-23 18:07:36 +00:00
|
|
|
wxString cacheErrorMsg;
|
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
do
|
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
fn.SetFullName( fullName );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2017-05-23 18:07:36 +00:00
|
|
|
// Queue I/O errors so only files that fail to parse don't get loaded.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// reader now owns fp, will close on exception or return
|
|
|
|
FILE_LINE_READER reader( fn.GetFullPath() );
|
|
|
|
std::string name = TO_UTF8( fn.GetName() );
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT* footprint = parseFOOTPRINT( &reader );
|
2017-05-23 18:07:36 +00:00
|
|
|
|
|
|
|
// The footprint name is the file name without the extension.
|
2018-07-26 14:38:30 +00:00
|
|
|
footprint->SetFPID( LIB_ID( wxEmptyString, fn.GetName() ) );
|
2020-11-13 11:17:15 +00:00
|
|
|
m_footprints.insert( name, new GPCB_FPL_CACHE_ITEM( footprint, fn ) );
|
2017-05-23 18:07:36 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
if( !cacheErrorMsg.IsEmpty() )
|
2022-02-05 13:25:43 +00:00
|
|
|
cacheErrorMsg += wxT( "\n\n" );
|
2017-05-23 18:07:36 +00:00
|
|
|
|
|
|
|
cacheErrorMsg += ioe.What();
|
|
|
|
}
|
2018-08-05 11:56:02 +00:00
|
|
|
} while( dir.GetNext( &fullName ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2017-05-23 18:07:36 +00:00
|
|
|
if( !cacheErrorMsg.IsEmpty() )
|
|
|
|
THROW_IO_ERROR( cacheErrorMsg );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPCB_FPL_CACHE::Remove( const wxString& aFootprintName )
|
|
|
|
{
|
|
|
|
std::string footprintName = TO_UTF8( aFootprintName );
|
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT_MAP::const_iterator it = m_footprints.find( footprintName );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( it == m_footprints.end() )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library '%s' has no footprint '%s'." ),
|
2012-12-28 20:52:12 +00:00
|
|
|
m_lib_path.GetPath().GetData(),
|
|
|
|
aFootprintName.GetData() ) );
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Remove the footprint from the cache and delete the footprint file from the library.
|
2012-12-28 20:52:12 +00:00
|
|
|
wxString fullPath = it->second->GetFileName().GetFullPath();
|
2020-11-13 11:17:15 +00:00
|
|
|
m_footprints.erase( footprintName );
|
2012-12-28 20:52:12 +00:00
|
|
|
wxRemoveFile( fullPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
bool GPCB_FPL_CACHE::IsModified()
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_dirty = m_cache_dirty || GetTimestamp( m_lib_path.GetFullPath() ) != m_cache_timestamp;
|
2013-12-12 17:42:38 +00:00
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
return m_cache_dirty;
|
2013-12-12 17:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
long long GPCB_FPL_CACHE::GetTimestamp( const wxString& aLibPath )
|
2013-12-12 17:42:38 +00:00
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
wxString fileSpec = wxT( "*." ) + GedaPcbFootprintLibFileExtension;
|
2013-12-12 17:42:38 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
return TimestampDir( aLibPath, fileSpec );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT* GPCB_FPL_CACHE::parseFOOTPRINT( LINE_READER* aLineReader )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2022-09-16 23:25:07 +00:00
|
|
|
#define TEXT_DEFAULT_SIZE ( 40*pcbIUScale.IU_PER_MILS )
|
|
|
|
#define OLD_GPCB_UNIT_CONV pcbIUScale.IU_PER_MILS
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
// Old version unit = 1 mil, so conv_unit is 10 or 0.1
|
2022-09-16 23:25:07 +00:00
|
|
|
#define NEW_GPCB_UNIT_CONV ( 0.01*pcbIUScale.IU_PER_MILS )
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
int paramCnt;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
// GPCB unit = 0.01 mils and Pcbnew 0.1.
|
|
|
|
double conv_unit = NEW_GPCB_UNIT_CONV;
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I textPos;
|
2020-11-13 15:15:52 +00:00
|
|
|
wxString msg;
|
|
|
|
wxArrayString parameters;
|
|
|
|
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( nullptr );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( aLineReader->ReadLine() == nullptr )
|
2017-05-23 18:07:36 +00:00
|
|
|
{
|
2022-02-05 13:25:43 +00:00
|
|
|
msg = aLineReader->GetSource() + wxT( ": empty file" );
|
2017-05-23 18:07:36 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
parameters.Clear();
|
|
|
|
parseParameters( parameters, aLineReader );
|
|
|
|
paramCnt = parameters.GetCount();
|
|
|
|
|
|
|
|
/* From the Geda PCB documentation, valid Element definitions:
|
|
|
|
* Element [SFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TSFlags]
|
|
|
|
* Element (NFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TNFlags)
|
|
|
|
* Element (NFlags "Desc" "Name" "Value" TX TY TDir TScale TNFlags)
|
|
|
|
* Element (NFlags "Desc" "Name" TX TY TDir TScale TNFlags)
|
|
|
|
* Element ("Desc" "Name" TX TY TDir TScale TNFlags)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( parameters[0].CmpNoCase( wxT( "Element" ) ) != 0 )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
msg.Printf( _( "Unknown token '%s'" ), parameters[0] );
|
2012-12-28 20:52:12 +00:00
|
|
|
THROW_PARSE_ERROR( msg, aLineReader->GetSource(), (const char *)aLineReader,
|
|
|
|
aLineReader->LineNumber(), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( paramCnt < 10 || paramCnt > 14 )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Element token contains %d parameters." ), paramCnt );
|
|
|
|
THROW_PARSE_ERROR( msg, aLineReader->GetSource(), (const char *)aLineReader,
|
|
|
|
aLineReader->LineNumber(), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test symbol after "Element": if [ units = 0.01 mils, and if ( units = 1 mil
|
|
|
|
if( parameters[1] == wxT( "(" ) )
|
|
|
|
conv_unit = OLD_GPCB_UNIT_CONV;
|
|
|
|
|
|
|
|
if( paramCnt > 10 )
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetDescription( parameters[3] );
|
|
|
|
footprint->SetReference( parameters[4] );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetDescription( parameters[2] );
|
|
|
|
footprint->SetReference( parameters[3] );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read value
|
|
|
|
if( paramCnt > 10 )
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->SetValue( parameters[5] );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2015-10-14 18:22:47 +00:00
|
|
|
// With gEDA/pcb, value is meaningful after instantiation, only, so it's
|
|
|
|
// often empty in bare footprints.
|
2020-11-13 11:17:15 +00:00
|
|
|
if( footprint->Value().GetText().IsEmpty() )
|
|
|
|
footprint->Value().SetText( wxT( "Val**" ) );
|
2015-10-14 18:22:47 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
if( paramCnt == 14 )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
textPos = VECTOR2I( parseInt( parameters[8], conv_unit ),
|
|
|
|
parseInt( parameters[9], conv_unit ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
textPos = VECTOR2I( parseInt( parameters[6], conv_unit ),
|
|
|
|
parseInt( parameters[7], conv_unit ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
2015-10-12 23:31:26 +00:00
|
|
|
int orientation = parseInt( parameters[paramCnt-4], 1.0 );
|
2022-01-13 23:30:52 +00:00
|
|
|
footprint->Reference().SetTextAngle( ( orientation % 2) ? ANGLE_VERTICAL : ANGLE_HORIZONTAL );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-10-14 18:22:47 +00:00
|
|
|
// Calculate size: default height is 40 mils, width 30 mil.
|
2012-12-28 20:52:12 +00:00
|
|
|
// real size is: default * ibuf[idx+3] / 100 (size in gpcb is given in percent of default size
|
2015-10-14 18:22:47 +00:00
|
|
|
int thsize = parseInt( parameters[paramCnt-3], TEXT_DEFAULT_SIZE ) / 100;
|
2022-09-16 23:25:07 +00:00
|
|
|
thsize = std::max( (int)( 5 * pcbIUScale.IU_PER_MILS ), thsize ); // Ensure a minimal size = 5 mils
|
2015-10-14 18:22:47 +00:00
|
|
|
int twsize = thsize * 30 / 40;
|
|
|
|
int thickness = thsize / 8;
|
|
|
|
|
|
|
|
// gEDA/pcb aligns top/left, not pcbnew's default, center/center.
|
|
|
|
// Compensate for this by shifting the insertion point instead of the
|
2019-08-20 17:22:30 +00:00
|
|
|
// alignment, because alignment isn't changeable in the GUI.
|
2020-11-13 11:17:15 +00:00
|
|
|
textPos.x = textPos.x + twsize * footprint->GetReference().Len() / 2;
|
2015-10-14 18:22:47 +00:00
|
|
|
textPos.y += thsize / 2;
|
|
|
|
|
|
|
|
// gEDA/pcb draws a bit too low/left, while pcbnew draws a bit too
|
|
|
|
// high/right. Compensate for similar appearance.
|
|
|
|
textPos.x -= thsize / 10;
|
|
|
|
textPos.y += thsize / 2;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
footprint->Reference().SetFPRelativePosition( textPos );
|
2023-02-19 03:40:07 +00:00
|
|
|
footprint->Reference().SetTextSize( VECTOR2I( twsize, thsize ) );
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Reference().SetTextThickness( thickness );
|
2015-10-14 18:22:47 +00:00
|
|
|
|
|
|
|
// gEDA/pcb shows only one of value/reference/description at a time. Which
|
|
|
|
// one is selectable by a global menu setting. pcbnew needs reference as
|
|
|
|
// well as value visible, so place the value right below the reference.
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Value().SetTextAngle( footprint->Reference().GetTextAngle() );
|
|
|
|
footprint->Value().SetTextSize( footprint->Reference().GetTextSize() );
|
2020-11-24 22:16:41 +00:00
|
|
|
footprint->Value().SetTextThickness( footprint->Reference().GetTextThickness() );
|
2015-10-14 18:22:47 +00:00
|
|
|
textPos.y += thsize * 13 / 10; // 130% line height
|
2023-03-30 11:49:23 +00:00
|
|
|
footprint->Value().SetFPRelativePosition( textPos );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
while( aLineReader->ReadLine() )
|
|
|
|
{
|
|
|
|
parameters.Clear();
|
|
|
|
parseParameters( parameters, aLineReader );
|
|
|
|
|
|
|
|
if( parameters.IsEmpty() || parameters[0] == wxT( "(" ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( parameters[0] == wxT( ")" ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
paramCnt = parameters.GetCount();
|
|
|
|
|
|
|
|
// Test units value for a string line param (more than 3 parameters : ident [ xx ] )
|
|
|
|
if( paramCnt > 3 )
|
|
|
|
{
|
|
|
|
if( parameters[1] == wxT( "(" ) )
|
|
|
|
conv_unit = OLD_GPCB_UNIT_CONV;
|
|
|
|
else
|
|
|
|
conv_unit = NEW_GPCB_UNIT_CONV;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
wxLogTrace( traceGedaPcbPlugin, wxT( "%s parameter count = %d." ),
|
|
|
|
parameters[0], paramCnt );
|
2015-03-04 19:46:06 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
// Parse a line with format: ElementLine [X1 Y1 X2 Y2 Thickness]
|
|
|
|
if( parameters[0].CmpNoCase( wxT( "ElementLine" ) ) == 0 )
|
|
|
|
{
|
|
|
|
if( paramCnt != 8 )
|
|
|
|
{
|
2013-02-24 17:31:18 +00:00
|
|
|
msg.Printf( wxT( "ElementLine token contains %d parameters." ), paramCnt );
|
2012-12-28 20:52:12 +00:00
|
|
|
THROW_PARSE_ERROR( msg, aLineReader->GetSource(), (const char *)aLineReader,
|
|
|
|
aLineReader->LineNumber(), 0 );
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( footprint.get(), SHAPE_T::SEGMENT );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( F_SilkS );
|
2023-03-30 11:49:23 +00:00
|
|
|
shape->SetStart( VECTOR2I( parseInt( parameters[2], conv_unit ),
|
|
|
|
parseInt( parameters[3], conv_unit ) ) );
|
|
|
|
shape->SetEnd( VECTOR2I( parseInt( parameters[4], conv_unit ),
|
|
|
|
parseInt( parameters[5], conv_unit ) ) );
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( parseInt( parameters[6], conv_unit ),
|
|
|
|
PLOT_DASH_TYPE::SOLID ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
|
|
|
|
shape->Rotate( { 0, 0 }, footprint->GetOrientation() );
|
|
|
|
shape->Move( footprint->GetPosition() );
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Add( shape );
|
2012-12-28 20:52:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse an arc with format: ElementArc [X Y Width Height StartAngle DeltaAngle Thickness]
|
|
|
|
if( parameters[0].CmpNoCase( wxT( "ElementArc" ) ) == 0 )
|
|
|
|
{
|
|
|
|
if( paramCnt != 10 )
|
|
|
|
{
|
2013-02-24 17:31:18 +00:00
|
|
|
msg.Printf( wxT( "ElementArc token contains %d parameters." ), paramCnt );
|
2012-12-28 20:52:12 +00:00
|
|
|
THROW_PARSE_ERROR( msg, aLineReader->GetSource(), (const char *)aLineReader,
|
|
|
|
aLineReader->LineNumber(), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pcbnew does know ellipse so we must have Width = Height
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( footprint.get(), SHAPE_T::ARC );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( F_SilkS );
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Add( shape );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
// for and arc: ibuf[3] = ibuf[4]. Pcbnew does not know ellipses
|
2023-03-30 11:49:23 +00:00
|
|
|
int radius = ( parseInt( parameters[4], conv_unit ) +
|
|
|
|
parseInt( parameters[5], conv_unit ) ) / 2;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I centre( parseInt( parameters[2], conv_unit ),
|
|
|
|
parseInt( parameters[3], conv_unit ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
shape->SetCenter( centre );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
// Pcbnew start angles are inverted and 180 degrees from Geda PCB angles.
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE start_angle( (int) parseInt( parameters[6], -10.0 ), TENTHS_OF_A_DEGREE_T );
|
|
|
|
start_angle += ANGLE_180;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
// Pcbnew delta angle direction is the opposite of Geda PCB delta angles.
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE sweep_angle( (int) parseInt( parameters[7], -10.0 ), TENTHS_OF_A_DEGREE_T );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
// Geda PCB does not support circles.
|
2022-01-16 16:15:07 +00:00
|
|
|
if( sweep_angle == -ANGLE_360 )
|
2021-07-21 18:31:25 +00:00
|
|
|
shape->SetShape( SHAPE_T::CIRCLE );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
// Calculate start point coordinate of arc
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I arcStart( radius, 0 );
|
|
|
|
RotatePoint( arcStart, -start_angle );
|
2023-03-30 11:49:23 +00:00
|
|
|
shape->SetStart( arcStart + centre );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
// Angle value is clockwise in gpcb and Pcbnew.
|
2023-03-30 11:49:23 +00:00
|
|
|
shape->SetArcAngleAndEnd( sweep_angle );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( parseInt( parameters[8], conv_unit ),
|
|
|
|
PLOT_DASH_TYPE::SOLID ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
|
|
|
|
shape->Rotate( { 0, 0 }, footprint->GetOrientation() );
|
|
|
|
shape->Move( footprint->GetPosition() );
|
2012-12-28 20:52:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a Pad with no hole with format:
|
|
|
|
// Pad [rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" SFlags]
|
|
|
|
// Pad (rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" NFlags)
|
|
|
|
// Pad (aX1 aY1 aX2 aY2 Thickness "Name" "Number" NFlags)
|
|
|
|
// Pad (aX1 aY1 aX2 aY2 Thickness "Name" NFlags)
|
|
|
|
if( parameters[0].CmpNoCase( wxT( "Pad" ) ) == 0 )
|
|
|
|
{
|
|
|
|
if( paramCnt < 10 || paramCnt > 13 )
|
|
|
|
{
|
2013-02-24 17:31:18 +00:00
|
|
|
msg.Printf( wxT( "Pad token contains %d parameters." ), paramCnt );
|
2012-12-28 20:52:12 +00:00
|
|
|
THROW_PARSE_ERROR( msg, aLineReader->GetSource(), (const char *)aLineReader,
|
|
|
|
aLineReader->LineNumber(), 0 );
|
|
|
|
}
|
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( footprint.get() );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
static const LSET pad_front( 3, F_Cu, F_Mask, F_Paste );
|
|
|
|
static const LSET pad_back( 3, B_Cu, B_Mask, B_Paste );
|
|
|
|
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECTANGLE );
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
2014-06-24 16:17:18 +00:00
|
|
|
pad->SetLayerSet( pad_front );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
if( testFlags( parameters[paramCnt-2], 0x0080, wxT( "onsolder" ) ) )
|
2014-06-24 16:17:18 +00:00
|
|
|
pad->SetLayerSet( pad_back );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-10-14 18:22:47 +00:00
|
|
|
// Set the pad name:
|
|
|
|
// Pcbnew pad name is used for electrical connection calculations.
|
|
|
|
// Accordingly it should be mapped to gEDA's pin/pad number,
|
|
|
|
// which is used for the same purpose.
|
|
|
|
// gEDA also features a pin/pad "name", which is an arbitrary string
|
|
|
|
// and set to the pin name of the netlist on instantiation. Many gEDA
|
|
|
|
// bare footprints use identical strings for name and number, so this
|
|
|
|
// can be a bit confusing.
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( parameters[paramCnt-3] );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
int x1 = parseInt( parameters[2], conv_unit );
|
|
|
|
int x2 = parseInt( parameters[4], conv_unit );
|
|
|
|
int y1 = parseInt( parameters[3], conv_unit );
|
|
|
|
int y2 = parseInt( parameters[5], conv_unit );
|
|
|
|
int width = parseInt( parameters[6], conv_unit );
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I delta( x2 - x1, y2 - y1 );
|
2012-12-28 20:52:12 +00:00
|
|
|
double angle = atan2( (double)delta.y, (double)delta.x );
|
|
|
|
|
|
|
|
// Get the pad clearance and the solder mask clearance.
|
|
|
|
if( paramCnt == 13 )
|
|
|
|
{
|
2015-10-14 18:22:47 +00:00
|
|
|
int clearance = parseInt( parameters[7], conv_unit );
|
|
|
|
// One of gEDA's oddities is that clearance between pad and polygon
|
|
|
|
// is given as the gap on both sides of the pad together, so for
|
|
|
|
// KiCad it has to halfed.
|
|
|
|
pad->SetLocalClearance( clearance / 2 );
|
|
|
|
|
|
|
|
// In GEDA, the mask value is the size of the hole in this
|
|
|
|
// solder mask. In Pcbnew, it is a margin, therefore the distance
|
|
|
|
// between the copper and the mask
|
|
|
|
int maskMargin = parseInt( parameters[8], conv_unit );
|
|
|
|
maskMargin = ( maskMargin - width ) / 2;
|
|
|
|
pad->SetLocalSolderMaskMargin( maskMargin );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
// Negate angle (due to Y reversed axis)
|
|
|
|
EDA_ANGLE orient( -angle, RADIANS_T );
|
|
|
|
pad->SetOrientation( orient );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I padPos( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( KiROUND( EuclideanNorm( delta ) ) + width, width ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
padPos += footprint->GetPosition();
|
2012-12-28 20:52:12 +00:00
|
|
|
pad->SetPosition( padPos );
|
|
|
|
|
|
|
|
if( !testFlags( parameters[paramCnt-2], 0x0100, wxT( "square" ) ) )
|
|
|
|
{
|
|
|
|
if( pad->GetSize().x == pad->GetSize().y )
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2012-12-28 20:52:12 +00:00
|
|
|
else
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::OVAL );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
if( pad->GetSizeX() > 0 && pad->GetSizeY() > 0 )
|
|
|
|
{
|
|
|
|
footprint->Add( pad.release() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogError( _( "Invalid zero-sized pad ignored in\nfile: %s" ),
|
|
|
|
aLineReader->GetSource() );
|
|
|
|
}
|
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a Pin with through hole with format:
|
|
|
|
// Pin [rX rY Thickness Clearance Mask Drill "Name" "Number" SFlags]
|
|
|
|
// Pin (rX rY Thickness Clearance Mask Drill "Name" "Number" NFlags)
|
|
|
|
// Pin (aX aY Thickness Drill "Name" "Number" NFlags)
|
|
|
|
// Pin (aX aY Thickness Drill "Name" NFlags)
|
|
|
|
// Pin (aX aY Thickness "Name" NFlags)
|
|
|
|
if( parameters[0].CmpNoCase( wxT( "Pin" ) ) == 0 )
|
|
|
|
{
|
|
|
|
if( paramCnt < 8 || paramCnt > 12 )
|
|
|
|
{
|
2013-02-24 17:31:18 +00:00
|
|
|
msg.Printf( wxT( "Pin token contains %d parameters." ), paramCnt );
|
2012-12-28 20:52:12 +00:00
|
|
|
THROW_PARSE_ERROR( msg, aLineReader->GetSource(), (const char *)aLineReader,
|
|
|
|
aLineReader->LineNumber(), 0 );
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
PAD* pad = new PAD( footprint.get() );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
static const LSET pad_set = LSET::AllCuMask() | LSET( 3, F_SilkS, F_Mask, B_Mask );
|
|
|
|
|
|
|
|
pad->SetLayerSet( pad_set );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
if( testFlags( parameters[paramCnt-2], 0x0100, wxT( "square" ) ) )
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECTANGLE );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-10-14 18:22:47 +00:00
|
|
|
// Set the pad name:
|
|
|
|
// Pcbnew pad name is used for electrical connection calculations.
|
|
|
|
// Accordingly it should be mapped to gEDA's pin/pad number,
|
|
|
|
// which is used for the same purpose.
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( parameters[paramCnt-3] );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I padPos( parseInt( parameters[2], conv_unit ),
|
|
|
|
parseInt( parameters[3], conv_unit ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-03-04 20:08:57 +00:00
|
|
|
int padSize = parseInt( parameters[4], conv_unit );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( padSize, padSize ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-03-04 19:46:06 +00:00
|
|
|
int drillSize = 0;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2015-03-04 19:46:06 +00:00
|
|
|
// Get the pad clearance, solder mask clearance, and drill size.
|
|
|
|
if( paramCnt == 12 )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2015-10-14 18:22:47 +00:00
|
|
|
int clearance = parseInt( parameters[5], conv_unit );
|
|
|
|
// One of gEDA's oddities is that clearance between pad and polygon
|
|
|
|
// is given as the gap on both sides of the pad together, so for
|
|
|
|
// KiCad it has to halfed.
|
|
|
|
pad->SetLocalClearance( clearance / 2 );
|
|
|
|
|
|
|
|
// In GEDA, the mask value is the size of the hole in this
|
|
|
|
// solder mask. In Pcbnew, it is a margin, therefore the distance
|
|
|
|
// between the copper and the mask
|
|
|
|
int maskMargin = parseInt( parameters[6], conv_unit );
|
|
|
|
maskMargin = ( maskMargin - padSize ) / 2;
|
|
|
|
pad->SetLocalSolderMaskMargin( maskMargin );
|
|
|
|
|
2015-03-04 19:46:06 +00:00
|
|
|
drillSize = parseInt( parameters[7], conv_unit );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drillSize = parseInt( parameters[5], conv_unit );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetDrillSize( VECTOR2I( drillSize, drillSize ) );
|
2019-01-13 21:20:29 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
padPos += footprint->GetPosition();
|
2012-12-28 20:52:12 +00:00
|
|
|
pad->SetPosition( padPos );
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE::CIRCLE && pad->GetSize().x != pad->GetSize().y )
|
|
|
|
pad->SetShape( PAD_SHAPE::OVAL );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint->Add( pad );
|
2012-12-28 20:52:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
return footprint.release();
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPCB_FPL_CACHE::parseParameters( wxArrayString& aParameterList, LINE_READER* aLineReader )
|
|
|
|
{
|
|
|
|
char key;
|
|
|
|
wxString tmp;
|
|
|
|
char* line = aLineReader->Line();
|
|
|
|
|
|
|
|
// Last line already ready in main parser loop.
|
|
|
|
while( *line != 0 )
|
|
|
|
{
|
|
|
|
key = *line;
|
|
|
|
line++;
|
|
|
|
|
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
case '[':
|
|
|
|
case '(':
|
|
|
|
if( !tmp.IsEmpty() )
|
|
|
|
{
|
|
|
|
aParameterList.Add( tmp );
|
|
|
|
tmp.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.Append( key );
|
|
|
|
aParameterList.Add( tmp );
|
|
|
|
tmp.Clear();
|
|
|
|
|
|
|
|
// Opening delimiter "(" after Element statement. Any other occurrence is part
|
|
|
|
// of a keyword definition.
|
|
|
|
if( aParameterList.GetCount() == 1 )
|
|
|
|
{
|
2018-04-13 13:58:25 +00:00
|
|
|
wxLogTrace( traceGedaPcbPlugin, dump( aParameterList ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ']':
|
|
|
|
case ')':
|
|
|
|
if( !tmp.IsEmpty() )
|
|
|
|
{
|
|
|
|
aParameterList.Add( tmp );
|
|
|
|
tmp.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.Append( key );
|
|
|
|
aParameterList.Add( tmp );
|
2018-04-13 13:58:25 +00:00
|
|
|
wxLogTrace( traceGedaPcbPlugin, dump( aParameterList ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
// Element descriptions can span multiple lines.
|
|
|
|
line = aLineReader->ReadLine();
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
case '\t':
|
|
|
|
case ' ':
|
|
|
|
if( !tmp.IsEmpty() )
|
|
|
|
{
|
|
|
|
aParameterList.Add( tmp );
|
|
|
|
tmp.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '"':
|
|
|
|
// Handle empty quotes.
|
|
|
|
if( *line == '"' )
|
|
|
|
{
|
|
|
|
line++;
|
|
|
|
tmp.Clear();
|
|
|
|
aParameterList.Add( wxEmptyString );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( *line != 0 )
|
|
|
|
{
|
|
|
|
key = *line;
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( key == '"' )
|
|
|
|
{
|
|
|
|
aParameterList.Add( tmp );
|
|
|
|
tmp.Clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp.Append( key );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '#':
|
|
|
|
line = aLineReader->ReadLine();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
tmp.Append( key );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GPCB_FPL_CACHE::testFlags( const wxString& aFlag, long aMask, const wxChar* aName )
|
|
|
|
{
|
|
|
|
wxString number;
|
|
|
|
|
|
|
|
if( aFlag.StartsWith( wxT( "0x" ), &number ) || aFlag.StartsWith( wxT( "0X" ), &number ) )
|
|
|
|
{
|
|
|
|
long lflags;
|
|
|
|
|
|
|
|
if( number.ToLong( &lflags, 16 ) && ( lflags & aMask ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( aFlag.Contains( aName ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GPCB_PLUGIN::GPCB_PLUGIN() :
|
2021-04-22 21:20:34 +00:00
|
|
|
m_cache( nullptr ),
|
2012-12-28 20:52:12 +00:00
|
|
|
m_ctl( 0 )
|
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
m_reader = nullptr;
|
|
|
|
init( nullptr );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GPCB_PLUGIN::GPCB_PLUGIN( int aControlFlags ) :
|
2021-04-22 21:20:34 +00:00
|
|
|
m_cache( nullptr ),
|
2012-12-28 20:52:12 +00:00
|
|
|
m_ctl( aControlFlags )
|
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
m_reader = nullptr;
|
|
|
|
init( nullptr );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GPCB_PLUGIN::~GPCB_PLUGIN()
|
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void GPCB_PLUGIN::init( const STRING_UTF8_MAP* aProperties )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
|
|
|
m_props = aProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
void GPCB_PLUGIN::validateCache( const wxString& aLibraryPath, bool checkModified )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2018-03-02 23:44:27 +00:00
|
|
|
if( !m_cache || ( checkModified && m_cache->IsModified() ) )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
|
|
|
// a spectacular episode in memory management:
|
|
|
|
delete m_cache;
|
|
|
|
m_cache = new GPCB_FPL_CACHE( this, aLibraryPath );
|
|
|
|
m_cache->Load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
bool aBestEfforts, const STRING_UTF8_MAP* aProperties )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
2019-08-31 14:18:27 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
wxDir dir( aLibraryPath );
|
|
|
|
wxString errorMsg;
|
2013-12-13 23:01:42 +00:00
|
|
|
|
|
|
|
if( !dir.IsOpened() )
|
|
|
|
{
|
2019-08-31 14:18:27 +00:00
|
|
|
if( aBestEfforts )
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' not found." ),
|
2019-08-31 14:18:27 +00:00
|
|
|
aLibraryPath ) );
|
|
|
|
}
|
2013-12-13 23:01:42 +00:00
|
|
|
}
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
2017-06-09 13:02:26 +00:00
|
|
|
try
|
|
|
|
{
|
2018-03-02 23:44:27 +00:00
|
|
|
validateCache( aLibraryPath );
|
2017-06-09 13:02:26 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
errorMsg = ioe.What();
|
|
|
|
}
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
// Some of the files may have been parsed correctly so we want to add the valid files to
|
|
|
|
// the library.
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
for( const auto& footprint : m_cache->GetFootprints() )
|
|
|
|
aFootprintNames.Add( FROM_UTF8( footprint.first.c_str() ) );
|
2013-12-13 23:01:42 +00:00
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
if( !errorMsg.IsEmpty() && !aBestEfforts )
|
2017-06-09 13:02:26 +00:00
|
|
|
THROW_IO_ERROR( errorMsg );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* GPCB_PLUGIN::getFootprint( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties,
|
2020-11-13 15:15:52 +00:00
|
|
|
bool checkModified )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
validateCache( aLibraryPath, checkModified );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 23:03:36 +00:00
|
|
|
const FOOTPRINT_MAP& mods = m_cache->GetFootprints();
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT_MAP::const_iterator it = mods.find( TO_UTF8( aFootprintName ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
if( it == mods.end() )
|
2021-04-22 21:20:34 +00:00
|
|
|
return nullptr;
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
return it->second->GetFootprint();
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* GPCB_PLUGIN::GetEnumeratedFootprint( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2018-03-02 23:44:27 +00:00
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
|
2018-03-02 23:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* GPCB_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
2021-03-30 09:38:03 +00:00
|
|
|
bool aKeepUUID,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2018-03-02 23:44:27 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
|
2020-12-04 12:14:07 +00:00
|
|
|
|
|
|
|
if( footprint )
|
|
|
|
{
|
|
|
|
FOOTPRINT* copy = (FOOTPRINT*) footprint->Duplicate();
|
|
|
|
copy->SetParent( nullptr );
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2018-03-02 23:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-12 17:42:38 +00:00
|
|
|
void GPCB_PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
init( aProperties );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
validateCache( aLibraryPath );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
if( !m_cache->IsWritable() )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only." ),
|
2012-12-28 20:52:12 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cache->Remove( aFootprintName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
bool GPCB_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
|
2012-12-28 20:52:12 +00:00
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
fn.SetPath( aLibraryPath );
|
|
|
|
|
|
|
|
// Return if there is no library path to delete.
|
|
|
|
if( !fn.DirExists() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !fn.IsDirWritable() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete folder '%s'." ),
|
2012-12-28 20:52:12 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDir dir( aLibraryPath );
|
|
|
|
|
|
|
|
if( dir.HasSubDirs() )
|
|
|
|
{
|
2021-06-27 13:24:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library folder '%s' has unexpected sub-folders." ),
|
2012-12-28 20:52:12 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// All the footprint files must be deleted before the directory can be deleted.
|
|
|
|
if( dir.HasFiles() )
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
wxFileName tmp;
|
|
|
|
wxArrayString files;
|
|
|
|
|
|
|
|
wxDir::GetAllFiles( aLibraryPath, &files );
|
|
|
|
|
|
|
|
for( i = 0; i < files.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
tmp = files[i];
|
|
|
|
|
|
|
|
if( tmp.GetExt() != KiCadFootprintFileExtension )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unexpected file '%s' found in library '%s'." ),
|
|
|
|
files[i].GetData(),
|
|
|
|
aLibraryPath.GetData() ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0; i < files.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxRemoveFile( files[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 13:58:25 +00:00
|
|
|
wxLogTrace( traceGedaPcbPlugin, wxT( "Removing footprint library '%s'" ),
|
2012-12-28 20:52:12 +00:00
|
|
|
aLibraryPath.GetData() );
|
|
|
|
|
|
|
|
// Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
|
|
|
|
// we don't want that. we want bare metal portability with no UI here.
|
|
|
|
if( !wxRmdir( aLibraryPath ) )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' cannot be deleted." ),
|
2012-12-28 20:52:12 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// For some reason removing a directory in Windows is not immediately updated. This delay
|
|
|
|
// prevents an error when attempting to immediately recreate the same directory when over
|
|
|
|
// writing an existing library.
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
wxMilliSleep( 250L );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( m_cache && m_cache->GetPath() == aLibraryPath )
|
|
|
|
{
|
|
|
|
delete m_cache;
|
2021-04-22 21:20:34 +00:00
|
|
|
m_cache = nullptr;
|
2012-12-28 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-04 01:13:09 +00:00
|
|
|
long long GPCB_PLUGIN::GetLibraryTimestamp( const wxString& aLibraryPath ) const
|
2018-03-02 20:41:37 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
return GPCB_FPL_CACHE::GetTimestamp( aLibraryPath );
|
2018-03-02 20:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
bool GPCB_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
|
|
|
|
{
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
init( nullptr );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2018-03-02 23:44:27 +00:00
|
|
|
validateCache( aLibraryPath );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
|
|
|
return m_cache->IsWritable();
|
|
|
|
}
|