2012-04-07 18:05:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-04-17 14:18:14 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-04-07 18:05:56 +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
|
|
|
|
*/
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
#ifndef PCB_IO_KICAD_LEGACY_H_
|
|
|
|
#define PCB_IO_KICAD_LEGACY_H_
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcb_io/pcb_io.h>
|
|
|
|
#include <pcb_io/pcb_io_mgr.h>
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <richio.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <string>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2016-06-29 15:09:55 +00:00
|
|
|
#include <memory>
|
2022-01-16 16:15:07 +00:00
|
|
|
#include <geometry/eda_angle.h>
|
2016-06-29 15:09:55 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
// FOOTPRINT_LIBRARY_HEADER_CNT gives the number of characters to compare to detect
|
|
|
|
// a footprint library. A few variants may have been used, and so we can only be
|
|
|
|
// sure that the header contains "PCBNEW-LibModule-V", not "PCBNEW-LibModule-V1".
|
2016-06-29 15:09:55 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
|
2016-05-10 19:07:35 +00:00
|
|
|
#define FOOTPRINT_LIBRARY_HEADER_CNT 18
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
class PCB_TARGET;
|
2020-11-13 15:15:52 +00:00
|
|
|
class FOOTPRINT;
|
2012-04-07 18:05:56 +00:00
|
|
|
class NETCLASS;
|
2020-11-11 23:05:59 +00:00
|
|
|
class ZONE;
|
2021-06-11 16:59:28 +00:00
|
|
|
class PCB_DIMENSION_BASE;
|
2012-04-07 18:05:56 +00:00
|
|
|
class NETINFO_ITEM;
|
2023-03-30 11:49:23 +00:00
|
|
|
class PCB_TEXT;
|
2020-11-12 22:30:02 +00:00
|
|
|
class PAD;
|
2013-09-22 04:38:22 +00:00
|
|
|
struct LP_CACHE;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-18 15:40:13 +00:00
|
|
|
* A #PLUGIN derivation which could possibly be put into a DLL/DSO.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
2012-04-17 06:13:22 +00:00
|
|
|
* As with any PLUGIN, there is no UI, i.e. windowing calls allowed.
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
2023-12-24 01:21:58 +00:00
|
|
|
class PCB_IO_KICAD_LEGACY : public PCB_IO
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
friend struct LP_CACHE;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
public:
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_LEGACY();
|
|
|
|
~PCB_IO_KICAD_LEGACY();
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "Eagle ver. 6.x XML PCB files" ), { "brd" } );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
|
2023-08-13 02:26:06 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "Legacy footprint library files" ), { "mod", "emp" } );
|
2023-08-13 02:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CanReadBoard( const wxString& aFileName ) const override;
|
|
|
|
bool CanReadFootprint( const wxString& aFileName ) const override;
|
|
|
|
|
2023-08-13 02:11:58 +00:00
|
|
|
BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
2023-12-27 17:06:23 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
2021-03-30 09:38:03 +00:00
|
|
|
bool aBestEfforts,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2021-03-30 09:38:03 +00:00
|
|
|
bool aKeepUUID = false,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool DeleteLibrary( const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2018-03-04 01:13:09 +00:00
|
|
|
long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
|
2018-03-02 20:41:37 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool IsLibraryWritable( const wxString& aLibraryPath ) override;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2020-12-04 12:13:11 +00:00
|
|
|
typedef int BIU;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
|
2012-04-17 02:58:03 +00:00
|
|
|
|
2015-07-25 11:16:05 +00:00
|
|
|
// return the new .kicad_pcb layer id from the old (legacy) layer id
|
2021-07-21 23:14:56 +00:00
|
|
|
static PCB_LAYER_ID leg_layer2new( int cu_count, int aLayerNum );
|
2015-07-25 11:16:05 +00:00
|
|
|
|
2020-12-04 12:13:11 +00:00
|
|
|
static LSET leg_mask2new( int cu_count, unsigned aMask );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
protected:
|
2021-06-23 22:53:08 +00:00
|
|
|
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
|
2022-11-06 16:51:52 +00:00
|
|
|
void init( const STRING_UTF8_MAP* aProperties );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
void checkpoint();
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Converts net code using the mapping table if available,
|
|
|
|
///< otherwise returns unchanged net code
|
2014-06-03 07:32:57 +00:00
|
|
|
inline int getNetCode( int aNetCode )
|
|
|
|
{
|
2016-10-11 14:00:43 +00:00
|
|
|
if( (unsigned int) aNetCode < m_netCodes.size() )
|
2014-06-03 07:32:57 +00:00
|
|
|
return m_netCodes[aNetCode];
|
|
|
|
|
|
|
|
return aNetCode;
|
|
|
|
}
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
/**
|
2020-12-18 15:40:13 +00:00
|
|
|
* Parse an ASCII decimal floating point value and scales it into a BIU according to the
|
|
|
|
* current value of diskToBui.
|
2012-04-07 18:05:56 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* This function is the complement of #fmtBIU(). One has to know what the other is doing.
|
2012-04-07 18:05:56 +00:00
|
|
|
*
|
2020-12-18 15:40:13 +00:00
|
|
|
* @param aValue is the ASCII value in C locale form with possible leading whitespace
|
|
|
|
* @param nptrptr may be NULL, but if not, then it tells where to put a pointer to the
|
|
|
|
* next unconsumed input text. See "man strtod" for more information.
|
|
|
|
* @return the converted Board Internal Unit.
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
2020-12-18 15:40:13 +00:00
|
|
|
BIU biuParse( const char* aValue, const char** nptrptr = nullptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/**
|
2022-01-16 16:15:07 +00:00
|
|
|
* Parse an ASCII decimal floating point value which is certainly an angle in tenths of
|
|
|
|
* a degree.
|
2012-04-07 18:05:56 +00:00
|
|
|
*
|
2020-12-18 15:40:13 +00:00
|
|
|
* @param aValue is the ASCII value in C locale form with possible leading whitespace.
|
|
|
|
* @param nptrptr may be NULL, but if not, then it tells where to put a pointer to the
|
|
|
|
* next unconsumed input text. See "man strtod" for more information.
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE degParse( const char* aValue, const char** nptrptr = nullptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2023-08-12 14:37:02 +00:00
|
|
|
static int getVersion( LINE_READER* aReader );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
void loadAllSections( bool doAppend );
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
void loadGENERAL();
|
|
|
|
void loadSETUP();
|
|
|
|
void loadSHEET();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void load3D( FOOTPRINT* aFootprint );
|
|
|
|
void loadPAD( FOOTPRINT* aFootprint );
|
2023-03-30 11:49:23 +00:00
|
|
|
void loadMODULE_TEXT( PCB_TEXT* aText );
|
2020-11-13 15:15:52 +00:00
|
|
|
void loadFP_SHAPE( FOOTPRINT* aFootprint );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
void loadPCB_LINE();
|
|
|
|
void loadNETINFO_ITEM();
|
|
|
|
void loadPCB_TEXT();
|
|
|
|
void loadNETCLASS();
|
2020-11-13 15:15:52 +00:00
|
|
|
void loadFOOTPRINT( FOOTPRINT* aFootprint );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-18 15:40:13 +00:00
|
|
|
* Read a list of segments (Tracks and Vias, or Segzones)
|
2012-04-07 18:05:56 +00:00
|
|
|
*
|
2019-04-10 09:19:16 +00:00
|
|
|
* @param aStructType is either PCB_TRACE_T to indicate tracks and vias, or NOT_USED
|
|
|
|
* to indicate oldschool zone segments (which are discarded).
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
2012-06-10 00:39:40 +00:00
|
|
|
void loadTrackList( int aStructType );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
|
|
|
|
void loadDIMENSION(); // "$COTATION"
|
|
|
|
void loadPCB_TARGET(); // "$PCB_TARGET"
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
/// we only cache one footprint library for now, this determines which one.
|
|
|
|
void cacheLib( const wxString& aLibraryPath );
|
2020-12-04 12:13:11 +00:00
|
|
|
|
|
|
|
protected:
|
2021-06-23 22:53:08 +00:00
|
|
|
int m_cu_count;
|
2020-12-04 12:13:11 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
wxString m_error; ///< for throwing exceptions
|
|
|
|
PROGRESS_REPORTER* m_progressReporter; ///< may be NULL, no ownership
|
|
|
|
unsigned m_lastProgressLine;
|
|
|
|
unsigned m_lineCount; ///< for progress reporting
|
2020-12-04 12:13:11 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
LINE_READER* m_reader; ///< no ownership here.
|
|
|
|
FILE* m_fp; ///< no ownership here.
|
2020-12-04 12:13:11 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
wxString m_field; ///< reused to stuff FOOTPRINT fields.
|
|
|
|
int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing?
|
|
|
|
LP_CACHE* m_cache;
|
2022-02-11 12:42:09 +00:00
|
|
|
bool m_showLegacySegmentZoneWarning;
|
2020-12-04 12:13:11 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
std::vector<int> m_netCodes; ///< net codes mapping for boards being loaded
|
2020-12-04 12:13:11 +00:00
|
|
|
|
|
|
|
double biuToDisk; ///< convert from BIUs to disk engineering units
|
|
|
|
///< with this scale factor
|
|
|
|
|
|
|
|
double diskToBiu; ///< convert from disk engineering units to BIUs
|
2023-08-13 02:26:06 +00:00
|
|
|
///< with this scale factor
|
2012-04-07 18:05:56 +00:00
|
|
|
};
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
#endif // PCB_IO_KICAD_LEGACY_H_
|