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 01:35:43 +00:00
|
|
|
* Copyright (C) 2007-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2019-02-09 17:10:55 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras@wanadoo.fr
|
2022-01-13 13:45:48 +00:00
|
|
|
* Copyright (C) 1992-2022 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
This implements loading and saving a BOARD, behind the PLUGIN interface.
|
|
|
|
|
|
|
|
The definitions:
|
|
|
|
|
|
|
|
*) a Board Internal Unit (BIU) is a unit of length that is used only internally
|
|
|
|
to PCBNEW, and is nanometers when this work is done, but deci-mils until done.
|
|
|
|
|
|
|
|
The philosophies:
|
|
|
|
|
|
|
|
*) BIUs should be typed as such to distinguish them from ints. This is mostly
|
|
|
|
for human readability, and having the type nearby in the source supports this readability.
|
|
|
|
*) Do not assume that BIUs will always be int, doing a sscanf() into a BIU
|
|
|
|
does not make sense in case the size of the BIU changes.
|
|
|
|
*) variables are put onto the stack in an automatic, even when it might look
|
|
|
|
more efficient to do otherwise. This is so we can seem them with a debugger.
|
|
|
|
*) Global variables should not be touched from within a PLUGIN, since it will eventually
|
|
|
|
be in a DLL/DSO. This includes window information too. The PLUGIN API knows
|
|
|
|
nothing of wxFrame or globals and all error reporting must be done by throwing
|
|
|
|
an exception.
|
|
|
|
*) No wxWindowing calls are made in here, since the UI resides higher up than in here,
|
|
|
|
and is going to process a bucket of detailed information thrown from down here
|
|
|
|
in the form of an exception if an error happens.
|
|
|
|
*) Much of what we do in this source file is for human readability, not performance.
|
|
|
|
Simply avoiding strtok() more often than the old code washes out performance losses.
|
|
|
|
Remember strncmp() will bail as soon as a mismatch happens, not going all the way
|
|
|
|
to end of string unless a full match.
|
|
|
|
*) angles are in the process of migrating to doubles, and 'int' if used, is
|
|
|
|
only shortterm, and along with this a change, and transition from from
|
|
|
|
"tenths of degrees" to simply "degrees" in the double (which has no problem
|
|
|
|
representing any portion of a degree).
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cerrno>
|
2012-09-21 17:02:54 +00:00
|
|
|
#include <cmath>
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <plugins/legacy/legacy_plugin.h> // implement this here
|
2012-12-14 18:14:28 +00:00
|
|
|
#include <wx/ffile.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <wx/string.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <macros.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <properties.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <zones.h>
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-10-05 16:57:25 +00:00
|
|
|
#include <ignore.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <pcb_target.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <pcb_plot_params.h>
|
2014-10-13 08:40:34 +00:00
|
|
|
#include <pcb_plot_params_parser.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <trigo.h>
|
2019-04-10 09:19:16 +00:00
|
|
|
#include <confirm.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
typedef LEGACY_PLUGIN::BIU BIU;
|
|
|
|
|
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
typedef unsigned LEG_MASK;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
#define FIRST_LAYER 0
|
|
|
|
#define FIRST_COPPER_LAYER 0
|
|
|
|
#define LAYER_N_BACK 0
|
|
|
|
#define LAYER_N_2 1
|
|
|
|
#define LAYER_N_3 2
|
|
|
|
#define LAYER_N_4 3
|
|
|
|
#define LAYER_N_5 4
|
|
|
|
#define LAYER_N_6 5
|
|
|
|
#define LAYER_N_7 6
|
|
|
|
#define LAYER_N_8 7
|
|
|
|
#define LAYER_N_9 8
|
|
|
|
#define LAYER_N_10 9
|
|
|
|
#define LAYER_N_11 10
|
|
|
|
#define LAYER_N_12 11
|
|
|
|
#define LAYER_N_13 12
|
|
|
|
#define LAYER_N_14 13
|
|
|
|
#define LAYER_N_15 14
|
|
|
|
#define LAYER_N_FRONT 15
|
|
|
|
#define LAST_COPPER_LAYER LAYER_N_FRONT
|
|
|
|
|
|
|
|
#define FIRST_NON_COPPER_LAYER 16
|
|
|
|
#define ADHESIVE_N_BACK 16
|
|
|
|
#define ADHESIVE_N_FRONT 17
|
|
|
|
#define SOLDERPASTE_N_BACK 18
|
|
|
|
#define SOLDERPASTE_N_FRONT 19
|
|
|
|
#define SILKSCREEN_N_BACK 20
|
|
|
|
#define SILKSCREEN_N_FRONT 21
|
|
|
|
#define SOLDERMASK_N_BACK 22
|
|
|
|
#define SOLDERMASK_N_FRONT 23
|
|
|
|
#define DRAW_N 24
|
|
|
|
#define COMMENT_N 25
|
|
|
|
#define ECO1_N 26
|
|
|
|
#define ECO2_N 27
|
|
|
|
#define EDGE_N 28
|
|
|
|
#define LAST_NON_COPPER_LAYER 28
|
|
|
|
|
|
|
|
// Masks to identify a layer by a bit map
|
|
|
|
typedef unsigned LAYER_MSK;
|
|
|
|
#define LAYER_BACK (1 << LAYER_N_BACK) ///< bit mask for copper layer
|
|
|
|
#define LAYER_2 (1 << LAYER_N_2) ///< bit mask for layer 2
|
|
|
|
#define LAYER_3 (1 << LAYER_N_3) ///< bit mask for layer 3
|
|
|
|
#define LAYER_4 (1 << LAYER_N_4) ///< bit mask for layer 4
|
|
|
|
#define LAYER_5 (1 << LAYER_N_5) ///< bit mask for layer 5
|
|
|
|
#define LAYER_6 (1 << LAYER_N_6) ///< bit mask for layer 6
|
|
|
|
#define LAYER_7 (1 << LAYER_N_7) ///< bit mask for layer 7
|
|
|
|
#define LAYER_8 (1 << LAYER_N_8) ///< bit mask for layer 8
|
|
|
|
#define LAYER_9 (1 << LAYER_N_9) ///< bit mask for layer 9
|
|
|
|
#define LAYER_10 (1 << LAYER_N_10) ///< bit mask for layer 10
|
|
|
|
#define LAYER_11 (1 << LAYER_N_11) ///< bit mask for layer 11
|
|
|
|
#define LAYER_12 (1 << LAYER_N_12) ///< bit mask for layer 12
|
|
|
|
#define LAYER_13 (1 << LAYER_N_13) ///< bit mask for layer 13
|
|
|
|
#define LAYER_14 (1 << LAYER_N_14) ///< bit mask for layer 14
|
|
|
|
#define LAYER_15 (1 << LAYER_N_15) ///< bit mask for layer 15
|
|
|
|
#define LAYER_FRONT (1 << LAYER_N_FRONT) ///< bit mask for component layer
|
|
|
|
#define ADHESIVE_LAYER_BACK (1 << ADHESIVE_N_BACK)
|
|
|
|
#define ADHESIVE_LAYER_FRONT (1 << ADHESIVE_N_FRONT)
|
|
|
|
#define SOLDERPASTE_LAYER_BACK (1 << SOLDERPASTE_N_BACK)
|
|
|
|
#define SOLDERPASTE_LAYER_FRONT (1 << SOLDERPASTE_N_FRONT)
|
|
|
|
#define SILKSCREEN_LAYER_BACK (1 << SILKSCREEN_N_BACK)
|
|
|
|
#define SILKSCREEN_LAYER_FRONT (1 << SILKSCREEN_N_FRONT)
|
|
|
|
#define SOLDERMASK_LAYER_BACK (1 << SOLDERMASK_N_BACK)
|
|
|
|
#define SOLDERMASK_LAYER_FRONT (1 << SOLDERMASK_N_FRONT)
|
|
|
|
#define DRAW_LAYER (1 << DRAW_N)
|
|
|
|
#define COMMENT_LAYER (1 << COMMENT_N)
|
|
|
|
#define ECO1_LAYER (1 << ECO1_N)
|
|
|
|
#define ECO2_LAYER (1 << ECO2_N)
|
|
|
|
#define EDGE_LAYER (1 << EDGE_N)
|
|
|
|
|
|
|
|
// Helpful global layer masks:
|
|
|
|
// ALL_AUX_LAYERS layers are technical layers, ALL_NO_CU_LAYERS has user
|
|
|
|
// and edge layers too!
|
|
|
|
#define ALL_NO_CU_LAYERS 0x1FFF0000
|
|
|
|
#define ALL_CU_LAYERS 0x0000FFFF
|
|
|
|
#define FRONT_TECH_LAYERS (SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT \
|
|
|
|
| ADHESIVE_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT)
|
|
|
|
#define BACK_TECH_LAYERS (SILKSCREEN_LAYER_BACK | SOLDERMASK_LAYER_BACK \
|
|
|
|
| ADHESIVE_LAYER_BACK | SOLDERPASTE_LAYER_BACK)
|
|
|
|
#define ALL_TECH_LAYERS (FRONT_TECH_LAYERS | BACK_TECH_LAYERS)
|
|
|
|
#define BACK_LAYERS (LAYER_BACK | BACK_TECH_LAYERS)
|
|
|
|
#define FRONT_LAYERS (LAYER_FRONT | FRONT_TECH_LAYERS)
|
|
|
|
|
|
|
|
#define ALL_USER_LAYERS (DRAW_LAYER | COMMENT_LAYER | ECO1_LAYER | ECO2_LAYER )
|
|
|
|
|
|
|
|
#define NO_LAYERS 0x00000000
|
2012-05-20 13:14:46 +00:00
|
|
|
|
|
|
|
|
2012-05-11 09:02:35 +00:00
|
|
|
// Old internal units definition (UI = decimil)
|
|
|
|
#define PCB_LEGACY_INTERNAL_UNIT 10000
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/// Get the length of a string constant, at compile time
|
|
|
|
#define SZ( x ) (sizeof(x)-1)
|
|
|
|
|
|
|
|
|
2012-07-07 18:27:44 +00:00
|
|
|
static const char delims[] = " \t\r\n";
|
|
|
|
|
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
static bool inline isSpace( int c ) { return strchr( delims, c ) != nullptr; }
|
2012-07-07 18:27:44 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#define MASK(x) (1<<(x))
|
2012-07-07 18:27:44 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
void LEGACY_PLUGIN::checkpoint()
|
|
|
|
{
|
|
|
|
const unsigned PROGRESS_DELTA = 250;
|
|
|
|
|
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
unsigned curLine = m_reader->LineNumber();
|
|
|
|
|
|
|
|
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
|
|
|
|
{
|
2021-06-24 10:09:03 +00:00
|
|
|
m_progressReporter->SetCurrentProgress( ( (double) curLine )
|
|
|
|
/ std::max( 1U, m_lineCount ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( _( "Open cancelled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
m_lastProgressLine = curLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
//-----<BOARD Load Functions>---------------------------------------------------
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
/// C string compare test for a specific length of characters.
|
2016-08-16 08:27:09 +00:00
|
|
|
#define TESTLINE( x ) ( !strncasecmp( line, x, SZ( x ) ) && isSpace( line[SZ( x )] ) )
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/// C sub-string compare test for a specific length of characters.
|
2016-08-16 08:27:09 +00:00
|
|
|
#define TESTSUBSTR( x ) ( !strncasecmp( line, x, SZ( x ) ) )
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if 1
|
2012-04-16 03:18:41 +00:00
|
|
|
#define READLINE( rdr ) rdr->ReadLine()
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
/// The function and macro which follow comprise a shim which can be a
|
|
|
|
/// monitor on lines of text read in from the input file.
|
|
|
|
/// And it can be used as a trap.
|
2012-11-27 13:50:01 +00:00
|
|
|
static inline char* ReadLine( LINE_READER* rdr, const char* caller )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
char* ret = rdr->ReadLine();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
const char* line = rdr->Line();
|
|
|
|
|
|
|
|
#if 0 // trap
|
|
|
|
if( !strcmp( "loadSETUP", caller ) && !strcmp( "$EndSETUP\n", line ) )
|
|
|
|
{
|
|
|
|
int breakhere = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
#define READLINE( rdr ) ReadLine( rdr, __FUNCTION__ )
|
2012-04-07 18:05:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
static GR_TEXT_H_ALIGN_T horizJustify( const char* horizontal )
|
2012-08-11 19:14:45 +00:00
|
|
|
{
|
|
|
|
if( !strcmp( "L", horizontal ) )
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_H_ALIGN_LEFT;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
if( !strcmp( "R", horizontal ) )
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_H_ALIGN_RIGHT;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_H_ALIGN_CENTER;
|
2012-08-11 19:14:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
static GR_TEXT_V_ALIGN_T vertJustify( const char* vertical )
|
2012-08-11 19:14:45 +00:00
|
|
|
{
|
|
|
|
if( !strcmp( "T", vertical ) )
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_V_ALIGN_TOP;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
if( !strcmp( "B", vertical ) )
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_V_ALIGN_BOTTOM;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
return GR_TEXT_V_ALIGN_CENTER;
|
2012-08-11 19:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
/// Count the number of set layers in the mask
|
2014-06-25 04:36:02 +00:00
|
|
|
inline int layerMaskCountSet( LEG_MASK aMask )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
2014-06-25 14:24:02 +00:00
|
|
|
for( int i = 0; aMask; ++i, aMask >>= 1 )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
|
|
|
if( aMask & 1 )
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-25 11:16:05 +00:00
|
|
|
// return true if aLegacyLayerNum is a valid copper layer legacy id, therefore
|
|
|
|
// top, bottom or inner activated layer
|
2021-07-21 23:14:56 +00:00
|
|
|
inline bool is_leg_copperlayer_valid( int aCu_Count, int aLegacyLayerNum )
|
2015-07-25 11:16:05 +00:00
|
|
|
{
|
2021-07-21 23:14:56 +00:00
|
|
|
return aLegacyLayerNum == LAYER_N_FRONT || aLegacyLayerNum < aCu_Count;
|
2015-07-25 11:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
PCB_LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, int aLayerNum )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
|
|
|
int newid;
|
|
|
|
unsigned old = aLayerNum;
|
|
|
|
|
|
|
|
// this is a speed critical function, be careful.
|
|
|
|
|
2014-06-25 14:24:02 +00:00
|
|
|
if( unsigned( old ) <= unsigned( LAYER_N_FRONT ) )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
2019-02-09 17:10:55 +00:00
|
|
|
// In .brd files, the layers are numbered from back to front
|
|
|
|
// (the opposite of the .kicad_pcb files)
|
2014-06-24 16:17:18 +00:00
|
|
|
if( old == LAYER_N_FRONT )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
newid = F_Cu;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2014-06-25 04:36:02 +00:00
|
|
|
else if( old == LAYER_N_BACK )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-25 04:36:02 +00:00
|
|
|
newid = B_Cu;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
newid = cu_count - 1 - old;
|
|
|
|
wxASSERT( newid >= 0 );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-02-09 17:10:55 +00:00
|
|
|
// This is of course incorrect, but at least it avoid crashing pcbnew:
|
|
|
|
if( newid < 0 )
|
|
|
|
newid = 0;
|
2014-06-24 16:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( old )
|
|
|
|
{
|
|
|
|
case ADHESIVE_N_BACK: newid = B_Adhes; break;
|
|
|
|
case ADHESIVE_N_FRONT: newid = F_Adhes; break;
|
|
|
|
case SOLDERPASTE_N_BACK: newid = B_Paste; break;
|
|
|
|
case SOLDERPASTE_N_FRONT: newid = F_Paste; break;
|
|
|
|
case SILKSCREEN_N_BACK: newid = B_SilkS; break;
|
|
|
|
case SILKSCREEN_N_FRONT: newid = F_SilkS; break;
|
|
|
|
case SOLDERMASK_N_BACK: newid = B_Mask; break;
|
|
|
|
case SOLDERMASK_N_FRONT: newid = F_Mask; break;
|
|
|
|
case DRAW_N: newid = Dwgs_User; break;
|
|
|
|
case COMMENT_N: newid = Cmts_User; break;
|
|
|
|
case ECO1_N: newid = Eco1_User; break;
|
|
|
|
case ECO2_N: newid = Eco2_User; break;
|
|
|
|
case EDGE_N: newid = Edge_Cuts; break;
|
|
|
|
default:
|
2015-07-25 11:16:05 +00:00
|
|
|
// Remap all illegal non copper layers to comment layer
|
|
|
|
newid = Cmts_User;
|
2014-06-24 16:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
return PCB_LAYER_ID( newid );
|
2014-06-24 16:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET LEGACY_PLUGIN::leg_mask2new( int cu_count, unsigned aMask )
|
|
|
|
{
|
|
|
|
LSET ret;
|
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
if( ( aMask & ALL_CU_LAYERS ) == ALL_CU_LAYERS )
|
|
|
|
{
|
|
|
|
ret = LSET::AllCuMask();
|
|
|
|
|
|
|
|
aMask &= ~ALL_CU_LAYERS;
|
|
|
|
}
|
|
|
|
|
2014-06-25 14:24:02 +00:00
|
|
|
for( int i=0; aMask; ++i, aMask >>= 1 )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
|
|
|
if( aMask & 1 )
|
|
|
|
ret.set( leg_layer2new( cu_count, i ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
/**
|
2020-12-18 15:40:13 +00:00
|
|
|
* Parse an ASCII integer string with possible leading whitespace into
|
2012-04-07 18:05:56 +00:00
|
|
|
* an integer and updates the pointer at \a out if it is not NULL, just
|
|
|
|
* like "man strtol()". I can use this without casting, and its name says
|
|
|
|
* what I am doing.
|
|
|
|
*/
|
2021-07-19 23:56:05 +00:00
|
|
|
static inline int intParse( const char* next, const char** out = nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// please just compile this and be quiet, hide casting ugliness:
|
|
|
|
return (int) strtol( next, (char**) out, 10 );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
/**
|
2020-12-18 15:40:13 +00:00
|
|
|
* Parse an ASCII hex integer string with possible leading whitespace into
|
2021-07-19 23:56:05 +00:00
|
|
|
* a long integer and updates the pointer at \a out if it is not nullptr, just
|
2012-04-07 18:05:56 +00:00
|
|
|
* like "man strtol". I can use this without casting, and its name says
|
|
|
|
* what I am doing.
|
|
|
|
*/
|
2021-07-19 23:56:05 +00:00
|
|
|
static inline long hexParse( const char* next, const char** out = nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// please just compile this and be quiet, hide casting ugliness:
|
|
|
|
return strtol( next, (char**) out, 16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
BOARD* LEGACY_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
|
2021-06-23 22:53:08 +00:00
|
|
|
const PROPERTIES* aProperties, PROJECT* aProject,
|
|
|
|
PROGRESS_REPORTER* aProgressReporter )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
2021-05-31 00:56:44 +00:00
|
|
|
std::unique_ptr<BOARD> boardDeleter;
|
|
|
|
|
|
|
|
if( aAppendToMe )
|
|
|
|
{
|
|
|
|
m_board = aAppendToMe;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boardDeleter = std::make_unique<BOARD>();
|
|
|
|
m_board = boardDeleter.get();
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
// Give the filename to the board if it's new
|
|
|
|
if( !aAppendToMe )
|
|
|
|
m_board->SetFileName( aFileName );
|
|
|
|
|
2012-11-27 14:14:15 +00:00
|
|
|
FILE_LINE_READER reader( aFileName );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
m_reader = &reader;
|
|
|
|
m_progressReporter = aProgressReporter;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
checkVersion();
|
|
|
|
|
2021-06-23 22:53:08 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_lineCount = 0;
|
|
|
|
|
|
|
|
m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
|
|
|
|
|
|
|
|
if( !m_progressReporter->KeepRefreshing() )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( _( "Open cancelled by user." ) );
|
2021-06-23 22:53:08 +00:00
|
|
|
|
|
|
|
while( reader.ReadLine() )
|
|
|
|
m_lineCount++;
|
|
|
|
|
|
|
|
reader.Rewind();
|
|
|
|
}
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
loadAllSections( bool( aAppendToMe ) );
|
|
|
|
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( boardDeleter.release() ); // give it up so we dont delete it on exit
|
2021-06-23 22:53:08 +00:00
|
|
|
m_progressReporter = nullptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
return m_board;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadAllSections( bool doAppend )
|
|
|
|
{
|
|
|
|
// $GENERAL section is first
|
|
|
|
|
|
|
|
// $SHEETDESCR section is next
|
|
|
|
|
|
|
|
// $SETUP section is next
|
|
|
|
|
|
|
|
// Then follows $EQUIPOT and all the rest
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
// put the more frequent ones at the top, but realize TRACKs are loaded as a group
|
|
|
|
|
|
|
|
if( TESTLINE( "$MODULE" ) )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( m_board );
|
2013-06-27 21:34:01 +00:00
|
|
|
|
2016-11-20 23:35:08 +00:00
|
|
|
LIB_ID fpid;
|
2013-09-08 18:31:21 +00:00
|
|
|
std::string fpName = StrPurge( line + SZ( "$MODULE" ) );
|
2013-09-17 15:51:05 +00:00
|
|
|
|
2013-11-29 18:29:41 +00:00
|
|
|
// The footprint names in legacy libraries can contain the '/' and ':'
|
|
|
|
// characters which will cause the FPID parser to choke.
|
|
|
|
ReplaceIllegalFileNameChars( &fpName );
|
|
|
|
|
2013-09-17 15:51:05 +00:00
|
|
|
if( !fpName.empty() )
|
2020-12-17 23:32:23 +00:00
|
|
|
fpid.Parse( fpName, true );
|
2013-09-17 15:51:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint->SetFPID( fpid );
|
2013-06-27 21:34:01 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
loadFOOTPRINT( footprint.get());
|
|
|
|
m_board->Add( footprint.release(), ADD_MODE::APPEND );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$DRAWSEGMENT" ) )
|
|
|
|
{
|
|
|
|
loadPCB_LINE();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EQUIPOT" ) )
|
|
|
|
{
|
|
|
|
loadNETINFO_ITEM();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$TEXTPCB" ) )
|
|
|
|
{
|
|
|
|
loadPCB_TEXT();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$TRACK" ) )
|
|
|
|
{
|
2012-06-10 00:39:40 +00:00
|
|
|
loadTrackList( PCB_TRACE_T );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$NCLASS" ) )
|
|
|
|
{
|
|
|
|
loadNETCLASS();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$CZONE_OUTLINE" ) )
|
|
|
|
{
|
|
|
|
loadZONE_CONTAINER();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$COTATION" ) )
|
|
|
|
{
|
|
|
|
loadDIMENSION();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$PCB_TARGET" ) || TESTLINE( "$MIREPCB" ) )
|
|
|
|
{
|
|
|
|
loadPCB_TARGET();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$ZONE" ) )
|
|
|
|
{
|
2019-04-10 09:19:16 +00:00
|
|
|
// No longer supported; discard segment fills
|
|
|
|
loadTrackList( NOT_USED );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$GENERAL" ) )
|
|
|
|
{
|
|
|
|
loadGENERAL();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$SHEETDESCR" ) )
|
|
|
|
{
|
|
|
|
loadSHEET();
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$SETUP" ) )
|
|
|
|
{
|
|
|
|
if( !doAppend )
|
|
|
|
{
|
|
|
|
loadSETUP();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
// gobble until $EndSetup
|
2012-04-07 18:05:56 +00:00
|
|
|
if( TESTLINE( "$EndSETUP" ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndBOARD" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndBOARD'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::checkVersion()
|
|
|
|
{
|
|
|
|
// Read first line and TEST if it is a PCB file format header like this:
|
|
|
|
// "PCBNEW-BOARD Version 1 ...."
|
|
|
|
|
|
|
|
m_reader->ReadLine();
|
|
|
|
|
|
|
|
char* line = m_reader->Line();
|
|
|
|
|
|
|
|
if( !TESTLINE( "PCBNEW-BOARD" ) )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Unknown file type" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ver = 1; // if sccanf fails
|
|
|
|
sscanf( line, "PCBNEW-BOARD Version %d", &ver );
|
|
|
|
|
2012-04-08 19:01:54 +00:00
|
|
|
#if !defined(DEBUG)
|
2012-04-07 18:05:56 +00:00
|
|
|
if( ver > LEGACY_BOARD_FILE_VERSION )
|
|
|
|
{
|
2020-12-04 12:13:11 +00:00
|
|
|
m_error.Printf( _( "File '%s' has an unrecognized version: %d." ),
|
|
|
|
m_reader->GetSource().GetData(),
|
|
|
|
ver );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
2012-04-08 19:01:54 +00:00
|
|
|
#endif
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
m_loading_format_version = ver;
|
2012-12-20 18:05:18 +00:00
|
|
|
m_board->SetFileFormatVersionAtLoad( m_loading_format_version );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadGENERAL()
|
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2014-06-25 04:36:02 +00:00
|
|
|
bool saw_LayerCount = false;
|
2012-11-27 13:50:01 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "Units" ) )
|
|
|
|
{
|
|
|
|
// what are the engineering units of the lengths in the BOARD?
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( line + SZ("Units"), delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( !strcmp( data, "mm" ) )
|
|
|
|
{
|
2022-09-17 00:45:14 +00:00
|
|
|
diskToBiu = pcbIUScale.IU_PER_MM;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-25 04:36:02 +00:00
|
|
|
else if( TESTLINE( "LayerCount" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( "LayerCount" ) );
|
2020-04-16 12:40:09 +00:00
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
m_board->SetCopperLayerCount( tmp );
|
|
|
|
|
|
|
|
// This has to be set early so that leg_layer2new() works OK, and
|
|
|
|
// that means before parsing "EnabledLayers" and "VisibleLayers".
|
|
|
|
m_cu_count = tmp;
|
|
|
|
|
|
|
|
saw_LayerCount = true;
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "EnabledLayers" ) )
|
|
|
|
{
|
2014-06-25 04:36:02 +00:00
|
|
|
if( !saw_LayerCount )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$GENERAL's LayerCount" ) );
|
2014-06-25 04:36:02 +00:00
|
|
|
|
|
|
|
LEG_MASK enabledLayers = hexParse( line + SZ( "EnabledLayers" ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET new_mask = leg_mask2new( m_cu_count, enabledLayers );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
m_board->SetEnabledLayers( new_mask );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// layer visibility equals layer usage, unless overridden later via "VisibleLayers"
|
2014-06-25 04:36:02 +00:00
|
|
|
// Must call SetEnabledLayers() before calling SetVisibleLayers().
|
2014-06-24 16:17:18 +00:00
|
|
|
m_board->SetVisibleLayers( new_mask );
|
2020-04-16 12:40:09 +00:00
|
|
|
|
|
|
|
// Ensure copper layers count is not modified:
|
|
|
|
m_board->SetCopperLayerCount( m_cu_count );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "VisibleLayers" ) )
|
|
|
|
{
|
2020-07-19 07:32:53 +00:00
|
|
|
// Keep all enabled layers visible.
|
|
|
|
// the old visibility control does not make sense in current Pcbnew version
|
|
|
|
// However, this code works.
|
|
|
|
#if 0
|
2014-06-25 04:36:02 +00:00
|
|
|
if( !saw_LayerCount )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$GENERAL's LayerCount" ) );
|
2014-06-25 04:36:02 +00:00
|
|
|
|
|
|
|
LEG_MASK visibleLayers = hexParse( line + SZ( "VisibleLayers" ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
LSET new_mask = leg_mask2new( m_cu_count, visibleLayers );
|
|
|
|
|
|
|
|
m_board->SetVisibleLayers( new_mask );
|
2020-07-19 07:32:53 +00:00
|
|
|
#endif
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Ly" ) ) // Old format for Layer count
|
|
|
|
{
|
2014-06-25 04:36:02 +00:00
|
|
|
if( !saw_LayerCount )
|
|
|
|
{
|
|
|
|
LEG_MASK layer_mask = hexParse( line + SZ( "Ly" ) );
|
|
|
|
|
|
|
|
m_cu_count = layerMaskCountSet( layer_mask & ALL_CU_LAYERS );
|
|
|
|
m_board->SetCopperLayerCount( m_cu_count );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
saw_LayerCount = true;
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "BoardThickness" ) )
|
|
|
|
{
|
|
|
|
BIU thickn = biuParse( line + SZ( "BoardThickness" ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
m_board->GetDesignSettings().SetBoardThickness( thickn );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "NoConn" ) )
|
|
|
|
{
|
2017-06-23 16:39:42 +00:00
|
|
|
// ignore
|
|
|
|
intParse( line + SZ( "NoConn" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Di" ) )
|
|
|
|
{
|
2017-03-03 09:56:46 +00:00
|
|
|
biuParse( line + SZ( "Di" ), &data );
|
|
|
|
biuParse( data, &data );
|
|
|
|
biuParse( data, &data );
|
|
|
|
biuParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Nnets" ) )
|
|
|
|
{
|
2014-06-02 09:41:54 +00:00
|
|
|
m_netCodes.resize( intParse( line + SZ( "Nnets" ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2014-06-06 10:30:07 +00:00
|
|
|
else if( TESTLINE( "Nn" ) ) // id "Nnets" for old .brd files
|
|
|
|
{
|
|
|
|
m_netCodes.resize( intParse( line + SZ( "Nn" ) ) );
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "$EndGENERAL" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndGENERAL'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadSHEET()
|
|
|
|
{
|
|
|
|
char buf[260];
|
|
|
|
TITLE_BLOCK tb;
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2020-02-20 12:11:04 +00:00
|
|
|
char* data;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "Sheet" ) )
|
|
|
|
{
|
|
|
|
// e.g. "Sheet A3 16535 11700"
|
|
|
|
// width and height are in 1/1000th of an inch, always
|
|
|
|
PAGE_INFO page;
|
2020-02-20 12:11:04 +00:00
|
|
|
char* sname = strtok_r( line + SZ( "Sheet" ), delims, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( sname )
|
|
|
|
{
|
|
|
|
wxString wname = FROM_UTF8( sname );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
if( !page.SetType( wname ) )
|
|
|
|
{
|
2021-06-27 23:26:54 +00:00
|
|
|
m_error.Printf( _( "Unknown sheet type '%s' on line: %d." ),
|
2020-02-20 12:11:04 +00:00
|
|
|
wname.GetData(),
|
|
|
|
m_reader->LineNumber() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
char* width = strtok_r( nullptr, delims, &data );
|
|
|
|
char* height = strtok_r( nullptr, delims, &data );
|
|
|
|
char* orient = strtok_r( nullptr, delims, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// only parse the width and height if page size is custom ("User")
|
|
|
|
if( wname == PAGE_INFO::Custom )
|
|
|
|
{
|
|
|
|
if( width && height )
|
|
|
|
{
|
|
|
|
// legacy disk file describes paper in mils
|
|
|
|
// (1/1000th of an inch)
|
|
|
|
int w = intParse( width );
|
|
|
|
int h = intParse( height );
|
|
|
|
|
|
|
|
page.SetWidthMils( w );
|
|
|
|
page.SetHeightMils( h );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( orient && !strcmp( orient, "portrait" ) )
|
|
|
|
{
|
|
|
|
page.SetPortrait( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->SetPageSettings( page );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Title" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetTitle( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Date" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetDate( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Rev" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetRevision( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comp" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetCompany( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment1" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 0, FROM_UTF8( buf ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment2" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 1, FROM_UTF8( buf ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment3" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 2, FROM_UTF8( buf ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment4" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
2019-08-21 16:58:29 +00:00
|
|
|
tb.SetComment( 3, FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment5" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment( 4, FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment6" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment( 5, FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment7" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment( 6, FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment8" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment( 7, FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Comment9" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment( 8, FROM_UTF8( buf ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndSHEETDESCR" ) )
|
|
|
|
{
|
|
|
|
m_board->SetTitleBlock( tb );
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndSHEETDESCR'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadSETUP()
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
ZONE_SETTINGS zoneSettings = m_board->GetZoneSettings();
|
|
|
|
std::shared_ptr<NETCLASS> defaultNetclass = bds.m_NetSettings->m_DefaultNetClass;
|
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2020-05-31 21:42:04 +00:00
|
|
|
|
|
|
|
m_board->m_LegacyDesignSettingsLoaded = true;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "PcbPlotParams" ) )
|
|
|
|
{
|
|
|
|
PCB_PLOT_PARAMS plot_opts;
|
|
|
|
|
|
|
|
PCB_PLOT_PARAMS_PARSER parser( line + SZ( "PcbPlotParams" ), m_reader->GetSource() );
|
|
|
|
|
|
|
|
plot_opts.Parse( &parser );
|
|
|
|
|
|
|
|
m_board->SetPlotOptions( plot_opts );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "AuxiliaryAxisOrg" ) )
|
|
|
|
{
|
|
|
|
BIU gx = biuParse( line + SZ( "AuxiliaryAxisOrg" ), &data );
|
|
|
|
BIU gy = biuParse( data );
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
bds.SetAuxOrigin( VECTOR2I( gx, gy ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTSUBSTR( "Layer[" ) )
|
|
|
|
{
|
|
|
|
// eg: "Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>"
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer_num = intParse( line + SZ( "Layer[" ), &data );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
|
2014-06-25 04:36:02 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data+1, delims, &saveptr ); // +1 for ']'
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
if( data )
|
|
|
|
{
|
|
|
|
wxString layerName = FROM_UTF8( data );
|
2014-06-24 16:17:18 +00:00
|
|
|
m_board->SetLayerName( layer_id, layerName );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
data = strtok_r( nullptr, delims, &saveptr );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
if( data ) // optional in old board files
|
|
|
|
{
|
|
|
|
LAYER_T type = LAYER::ParseType( data );
|
2014-06-24 16:17:18 +00:00
|
|
|
m_board->SetLayerType( layer_id, type );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-13 16:48:42 +00:00
|
|
|
else if( TESTLINE( "TrackWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
defaultNetclass->SetTrackWidth( tmp );
|
2015-03-13 16:48:42 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "TrackWidthList" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TrackWidthList" ) );
|
2014-05-13 09:22:51 +00:00
|
|
|
bds.m_TrackWidthList.push_back( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "TrackClearence" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TrackClearence" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
defaultNetclass->SetClearance( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "TrackMinWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TrackMinWidth" ) );
|
|
|
|
bds.m_TrackMinWidth = tmp;
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZoneClearence" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ZoneClearence" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
zoneSettings.m_ZoneClearance = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2022-05-29 20:28:10 +00:00
|
|
|
else if( TESTLINE( "Zone_45_Only" ) ) // No longer used
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2022-05-29 20:28:10 +00:00
|
|
|
/* bool tmp = (bool) */ intParse( line + SZ( "Zone_45_Only" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "DrawSegmWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "DrawSegmWidth" ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_LineThickness[ LAYER_CLASS_COPPER ] = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "EdgeSegmWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "EdgeSegmWidth" ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_LineThickness[ LAYER_CLASS_EDGES ] = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "ViaMinSize" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaMinSize" ) );
|
|
|
|
bds.m_ViasMinSize = tmp;
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "MicroViaMinSize" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "MicroViaMinSize" ) );
|
|
|
|
bds.m_MicroViasMinSize = tmp;
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ViaSizeList" ) )
|
|
|
|
{
|
|
|
|
// e.g. "ViaSizeList DIAMETER [DRILL]"
|
|
|
|
|
|
|
|
BIU drill = 0;
|
|
|
|
BIU diameter = biuParse( line + SZ( "ViaSizeList" ), &data );
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
data = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
if( data ) // DRILL may not be present ?
|
|
|
|
drill = biuParse( data );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
bds.m_ViasDimensionsList.emplace_back( diameter, drill );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2015-03-13 16:48:42 +00:00
|
|
|
else if( TESTLINE( "ViaSize" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaSize" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
defaultNetclass->SetViaDiameter( tmp );
|
2015-03-13 16:48:42 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "ViaDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
defaultNetclass->SetViaDrill( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "ViaMinDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaMinDrill" ) );
|
2020-05-04 21:05:30 +00:00
|
|
|
bds.m_MinThroughDrill = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2015-03-13 16:48:42 +00:00
|
|
|
else if( TESTLINE( "MicroViaSize" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "MicroViaSize" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
defaultNetclass->SetuViaDiameter( tmp );
|
2015-03-13 16:48:42 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "MicroViaDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "MicroViaDrill" ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
defaultNetclass->SetuViaDrill( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "MicroViaMinDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "MicroViaMinDrill" ) );
|
|
|
|
bds.m_MicroViasMinDrill = tmp;
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "MicroViasAllowed" ) )
|
|
|
|
{
|
2022-07-13 02:45:19 +00:00
|
|
|
intParse( line + SZ( "MicroViasAllowed" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "TextPcbWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TextPcbWidth" ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_TextThickness[ LAYER_CLASS_COPPER ] = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "TextPcbSize" ) )
|
|
|
|
{
|
|
|
|
BIU x = biuParse( line + SZ( "TextPcbSize" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_TextSize[ LAYER_CLASS_COPPER ] = wxSize( x, y );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "EdgeModWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "EdgeModWidth" ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_LineThickness[ LAYER_CLASS_SILK ] = tmp;
|
|
|
|
bds.m_LineThickness[ LAYER_CLASS_OTHERS ] = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "TextModWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TextModWidth" ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_TextThickness[ LAYER_CLASS_SILK ] = tmp;
|
|
|
|
bds.m_TextThickness[ LAYER_CLASS_OTHERS ] = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "TextModSize" ) )
|
|
|
|
{
|
|
|
|
BIU x = biuParse( line + SZ( "TextModSize" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
bds.m_TextSize[ LAYER_CLASS_SILK ] = wxSize( x, y );
|
|
|
|
bds.m_TextSize[ LAYER_CLASS_OTHERS ] = wxSize( x, y );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "PadSize" ) )
|
|
|
|
{
|
|
|
|
BIU x = biuParse( line + SZ( "PadSize" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
2021-06-06 19:03:10 +00:00
|
|
|
bds.m_Pad_Master->SetSize( wxSize( x, y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "PadDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "PadDrill" ) );
|
2021-06-06 19:03:10 +00:00
|
|
|
bds.m_Pad_Master->SetDrillSize( wxSize( tmp, tmp ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Pad2MaskClearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "Pad2MaskClearance" ) );
|
2021-08-22 22:05:47 +00:00
|
|
|
bds.m_SolderMaskExpansion = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2012-11-05 20:20:34 +00:00
|
|
|
else if( TESTLINE( "SolderMaskMinWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "SolderMaskMinWidth" ) );
|
|
|
|
bds.m_SolderMaskMinWidth = tmp;
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "Pad2PasteClearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "Pad2PasteClearance" ) );
|
|
|
|
bds.m_SolderPasteMargin = tmp;
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Pad2PasteClearanceRatio" ) )
|
|
|
|
{
|
|
|
|
double ratio = atof( line + SZ( "Pad2PasteClearanceRatio" ) );
|
|
|
|
bds.m_SolderPasteMarginRatio = ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "GridOrigin" ) )
|
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
BIU x = biuParse( line + SZ( "GridOrigin" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
bds.SetGridOrigin( VECTOR2I( x, y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "VisibleElements" ) )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
// Keep all elements visible.
|
|
|
|
// the old visibility control does not make sense in current Pcbnew version,
|
|
|
|
// and this code does not work.
|
|
|
|
#if 0
|
2012-04-07 18:05:56 +00:00
|
|
|
int visibleElements = hexParse( line + SZ( "VisibleElements" ) );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-07-19 07:32:53 +00:00
|
|
|
// Does not work: each old item should be tested one by one to set
|
|
|
|
// visibility of new item list
|
2020-05-31 21:42:04 +00:00
|
|
|
GAL_SET visibles;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
for( size_t i = 0; i < visibles.size(); i++ )
|
|
|
|
visibles.set( i, visibleElements & ( 1u << i ) );
|
|
|
|
|
|
|
|
m_board->SetVisibleElements( visibles );
|
2021-07-19 23:56:05 +00:00
|
|
|
#endif
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndSETUP" ) )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
m_board->SetZoneSettings( zoneSettings );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2015-03-13 16:48:42 +00:00
|
|
|
// Very old *.brd file does not have NETCLASSes
|
2019-07-10 00:38:02 +00:00
|
|
|
// "TrackWidth", "ViaSize", "ViaDrill", "ViaMinSize", and "TrackClearence" were
|
|
|
|
// defined in SETUP; these values are put into the default NETCLASS until later board
|
|
|
|
// load code should override them. *.brd files which have been saved with knowledge
|
|
|
|
// of NETCLASSes will override these defaults, very old boards (before 2009) will not
|
|
|
|
// and use the setup values.
|
2015-03-13 16:48:42 +00:00
|
|
|
// However these values should be the same as default NETCLASS.
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 00:38:02 +00:00
|
|
|
/*
|
|
|
|
* Ensure tracks and vias sizes lists are ok:
|
2012-04-07 18:05:56 +00:00
|
|
|
* Sort lists by by increasing value and remove duplicates
|
2019-07-10 00:38:02 +00:00
|
|
|
* (the first value is not tested, because it is the netclass value)
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
2014-05-13 09:22:51 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
|
2021-07-19 23:56:05 +00:00
|
|
|
sort( designSettings.m_ViasDimensionsList.begin() + 1,
|
|
|
|
designSettings.m_ViasDimensionsList.end() );
|
2014-05-13 09:22:51 +00:00
|
|
|
sort( designSettings.m_TrackWidthList.begin() + 1, designSettings.m_TrackWidthList.end() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
for( unsigned ii = 1; ii < designSettings.m_ViasDimensionsList.size() - 1; ii++ )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
if( designSettings.m_ViasDimensionsList[ii] == designSettings.m_ViasDimensionsList[ii + 1] )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
designSettings.m_ViasDimensionsList.erase( designSettings.m_ViasDimensionsList.begin() + ii );
|
2012-04-07 18:05:56 +00:00
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
for( unsigned ii = 1; ii < designSettings.m_TrackWidthList.size() - 1; ii++ )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
if( designSettings.m_TrackWidthList[ii] == designSettings.m_TrackWidthList[ii + 1] )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-05-13 09:22:51 +00:00
|
|
|
designSettings.m_TrackWidthList.erase( designSettings.m_TrackWidthList.begin() + ii );
|
2012-04-07 18:05:56 +00:00
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void LEGACY_PLUGIN::loadFOOTPRINT( FOOTPRINT* aFootprint )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
char* line;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2012-04-16 03:18:41 +00:00
|
|
|
const char* data;
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
// most frequently encountered ones at the top
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
if( TESTSUBSTR( "D" ) && strchr( "SCAP", line[1] ) ) // read a drawing item, e.g. "DS"
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
loadFP_SHAPE( aFootprint );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$PAD" ) )
|
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
loadPAD( aFootprint );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( TESTSUBSTR( "T" ) ) // Read a footprint text description (ref, value, or drawing)
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
|
|
|
|
int tnum = intParse( line + SZ( "T" ) );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = nullptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
switch( tnum )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
case FP_TEXT::TEXT_is_REFERENCE:
|
2020-11-13 01:33:30 +00:00
|
|
|
text = &aFootprint->Reference();
|
2013-04-07 11:55:18 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
case FP_TEXT::TEXT_is_VALUE:
|
2020-11-13 01:33:30 +00:00
|
|
|
text = &aFootprint->Value();
|
2013-04-07 11:55:18 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-01 14:13:11 +00:00
|
|
|
// All other fields greater than 1.
|
|
|
|
default:
|
2020-11-13 01:33:30 +00:00
|
|
|
text = new FP_TEXT( aFootprint );
|
|
|
|
aFootprint->Add( text );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
loadMODULE_TEXT( text );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
// e.g. "Po 19120 39260 900 0 4E823D06 68183921-93a5-49ac-91b0-49d05a0e1647 ~~\r\n"
|
|
|
|
BIU pos_x = biuParse( line + SZ( "Po" ), &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
|
|
|
int orient = intParse( data, &data );
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer_num = intParse( data, &data );
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
|
2022-02-25 23:09:27 +00:00
|
|
|
|
|
|
|
[[maybe_unused]] long edittime = hexParse( data, &data );
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
char* uuid = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
data = strtok_r( (char*) data+1, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// data is now a two character long string
|
2012-05-25 06:58:52 +00:00
|
|
|
// Note: some old files do not have this field
|
|
|
|
if( data && data[0] == 'F' )
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetLocked( true );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-05-25 06:58:52 +00:00
|
|
|
if( data && data[1] == 'P' )
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetIsPlaced( true );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
aFootprint->SetPosition( VECTOR2I( pos_x, pos_y ) );
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetLayer( layer_id );
|
2022-01-13 17:27:36 +00:00
|
|
|
aFootprint->SetOrientation( EDA_ANGLE( orient, TENTHS_OF_A_DEGREE_T ) );
|
2020-11-13 01:33:30 +00:00
|
|
|
const_cast<KIID&>( aFootprint->m_Uuid ) = KIID( uuid );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Sc" ) ) // timestamp
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
char* uuid = strtok_r( (char*) line + SZ( "Sc" ), delims, (char**) &data );
|
2020-11-13 01:33:30 +00:00
|
|
|
const_cast<KIID&>( aFootprint->m_Uuid ) = KIID( uuid );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-12-05 21:56:55 +00:00
|
|
|
else if( TESTLINE( "Op" ) ) // (Op)tions for auto placement (no longer supported)
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-12-05 21:56:55 +00:00
|
|
|
hexParse( line + SZ( "Op" ), &data );
|
|
|
|
hexParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2020-11-14 21:21:54 +00:00
|
|
|
else if( TESTLINE( "At" ) ) // (At)tributes of footprint
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2020-08-26 21:43:38 +00:00
|
|
|
int attrs = 0;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
data = line + SZ( "At" );
|
|
|
|
|
|
|
|
if( strstr( data, "SMD" ) )
|
2020-11-13 02:09:34 +00:00
|
|
|
attrs |= FP_SMD;
|
2020-08-26 21:43:38 +00:00
|
|
|
else if( strstr( data, "VIRTUAL" ) )
|
2020-11-13 02:09:34 +00:00
|
|
|
attrs |= FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM;
|
2020-08-26 21:43:38 +00:00
|
|
|
else
|
2020-11-13 02:09:34 +00:00
|
|
|
attrs |= FP_THROUGH_HOLE | FP_EXCLUDE_FROM_POS_FILES;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetAttributes( attrs );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "AR" ) ) // Alternate Reference
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
// e.g. "AR /68183921-93a5-49ac-e164-49d05a0e1647/93a549d0-49d0-e164-91b0-49d05a0e1647"
|
|
|
|
data = strtok_r( line + SZ( "AR" ), delims, (char**) &data );
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
if( data )
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetPath( KIID_PATH( FROM_UTF8( data ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$SHAPE3D" ) )
|
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
load3D( aFootprint );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Cd" ) )
|
|
|
|
{
|
|
|
|
// e.g. "Cd Double rangee de contacts 2 x 4 pins\r\n"
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetDescription( FROM_UTF8( StrPurge( line + SZ( "Cd" ) ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Kw" ) ) // Key words
|
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetKeywords( FROM_UTF8( StrPurge( line + SZ( "Kw" ) ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".SolderPasteRatio" ) )
|
|
|
|
{
|
|
|
|
double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-16 00:45:43 +00:00
|
|
|
// Due to a bug in dialog editor in Footprint Editor, fixed in BZR version 3565
|
2012-05-18 08:33:57 +00:00
|
|
|
// this parameter can be broken.
|
|
|
|
// It should be >= -50% (no solder paste) and <= 0% (full area of the pad)
|
|
|
|
|
|
|
|
if( tmp < -0.50 )
|
|
|
|
tmp = -0.50;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-05-18 08:33:57 +00:00
|
|
|
if( tmp > 0.0 )
|
|
|
|
tmp = 0.0;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetLocalSolderPasteMarginRatio( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".SolderPaste" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetLocalSolderPasteMargin( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".SolderMask" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetLocalSolderMaskMargin( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".LocalClearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetLocalClearance( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".ZoneConnection" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( ".ZoneConnection" ) );
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->SetZoneConnection((ZONE_CONNECTION) tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".ThermalWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
|
2021-08-08 13:37:14 +00:00
|
|
|
ignore_unused( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".ThermalGap" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
|
2021-08-08 13:37:14 +00:00
|
|
|
ignore_unused( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndMODULE" ) )
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
return; // preferred exit
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 23:26:54 +00:00
|
|
|
wxString msg = wxString::Format( _( "Missing '$EndMODULE' for MODULE '%s'." ),
|
|
|
|
aFootprint->GetFPID().GetLibItemName().wx_str() );
|
2013-06-13 16:09:35 +00:00
|
|
|
THROW_IO_ERROR( msg );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void LEGACY_PLUGIN::loadPAD( FOOTPRINT* aFootprint )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
|
2020-11-12 22:30:02 +00:00
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "Sh" ) ) // (Sh)ape and padname
|
|
|
|
{
|
|
|
|
// e.g. "Sh "A2" C 520 520 0 0 900"
|
|
|
|
// or "Sh "1" R 157 1378 0 0 900"
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
// mypadnumber is LATIN1/CRYLIC for BOARD_FORMAT_VERSION 1, but for
|
|
|
|
// BOARD_FORMAT_VERSION 2, it is UTF8 from disk.
|
|
|
|
// Moving forward padnumbers will be in UTF8 on disk, as are all KiCad strings on disk.
|
|
|
|
char mypadnumber[50];
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
// +1 trailing whitespace.
|
2021-08-23 23:10:21 +00:00
|
|
|
data = data + ReadDelimitedText( mypadnumber, data, sizeof( mypadnumber ) ) + 1;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-07-07 18:27:44 +00:00
|
|
|
while( isSpace( *data ) )
|
|
|
|
++data;
|
2013-06-13 16:17:25 +00:00
|
|
|
|
|
|
|
unsigned char padchar = (unsigned char) *data++;
|
|
|
|
int padshape;
|
2012-07-07 18:27:44 +00:00
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
BIU size_x = biuParse( data, &data );
|
|
|
|
BIU size_y = biuParse( data, &data );
|
|
|
|
BIU delta_x = biuParse( data, &data );
|
|
|
|
BIU delta_y = biuParse( data, &data );
|
|
|
|
EDA_ANGLE orient = degParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-06-13 16:17:25 +00:00
|
|
|
switch( padchar )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case 'C': padshape = static_cast<int>( PAD_SHAPE::CIRCLE ); break;
|
|
|
|
case 'R': padshape = static_cast<int>( PAD_SHAPE::RECT ); break;
|
|
|
|
case 'O': padshape = static_cast<int>( PAD_SHAPE::OVAL ); break;
|
|
|
|
case 'T': padshape = static_cast<int>( PAD_SHAPE::TRAPEZOID ); break;
|
2012-04-07 18:05:56 +00:00
|
|
|
default:
|
2021-06-27 23:26:54 +00:00
|
|
|
m_error.Printf( _( "Unknown padshape '%c=0x%02x' on line: %d of footprint: '%s'." ),
|
2021-07-19 23:56:05 +00:00
|
|
|
padchar, padchar, m_reader->LineNumber(),
|
|
|
|
aFootprint->GetFPID().GetLibItemName().wx_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
// go through a wxString to establish a universal character set properly
|
2021-08-23 23:10:21 +00:00
|
|
|
wxString padNumber;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( m_loading_format_version == 1 )
|
|
|
|
{
|
|
|
|
// add 8 bit bytes, file format 1 was KiCad font type byte,
|
|
|
|
// simply promote those 8 bit bytes up into UNICODE. (subset of LATIN1)
|
2021-08-23 23:10:21 +00:00
|
|
|
const unsigned char* cp = (unsigned char*) mypadnumber;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
while( *cp )
|
2021-08-23 23:10:21 +00:00
|
|
|
padNumber += *cp++; // unsigned, ls 8 bits only
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// version 2, which is UTF8.
|
2021-08-23 23:10:21 +00:00
|
|
|
padNumber = FROM_UTF8( mypadnumber );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
// chances are both were ASCII, but why take chances?
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( padNumber );
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( static_cast<PAD_SHAPE>( padshape ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
pad->SetSize( wxSize( size_x, size_y ) );
|
|
|
|
pad->SetDelta( wxSize( delta_x, delta_y ) );
|
2022-01-16 16:15:07 +00:00
|
|
|
pad->SetOrientation( orient );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Dr" ) ) // (Dr)ill
|
|
|
|
{
|
|
|
|
// e.g. "Dr 350 0 0" or "Dr 0 0 0 O 0 0"
|
|
|
|
BIU drill_x = biuParse( line + SZ( "Dr" ), &data );
|
|
|
|
BIU drill_y = drill_x;
|
|
|
|
BIU offs_x = biuParse( data, &data );
|
|
|
|
BIU offs_y = biuParse( data, &data );
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
PAD_DRILL_SHAPE_T drShape = PAD_DRILL_SHAPE_CIRCLE;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data, delims, &saveptr );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
if( data ) // optional shape
|
|
|
|
{
|
|
|
|
if( data[0] == 'O' )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
drShape = PAD_DRILL_SHAPE_OBLONG;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
data = strtok_r( nullptr, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
drill_x = biuParse( data );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
data = strtok_r( nullptr, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
drill_y = biuParse( data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetDrillShape( drShape );
|
2022-01-01 17:11:21 +00:00
|
|
|
pad->SetOffset( VECTOR2I( offs_x, offs_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
pad->SetDrillSize( wxSize( drill_x, drill_y ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "At" ) ) // (At)tribute
|
|
|
|
{
|
|
|
|
// e.g. "At SMD N 00888000"
|
|
|
|
// sscanf( PtLine, "%s %s %X", BufLine, BufCar, &m_layerMask );
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
PAD_ATTRIB attribute;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-04-16 12:40:09 +00:00
|
|
|
data = strtok_r( line + SZ( "At" ), delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( !strcmp( data, "SMD" ) )
|
2021-05-01 14:46:50 +00:00
|
|
|
attribute = PAD_ATTRIB::SMD;
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( !strcmp( data, "CONN" ) )
|
2021-05-01 14:46:50 +00:00
|
|
|
attribute = PAD_ATTRIB::CONN;
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( !strcmp( data, "HOLE" ) )
|
2021-05-01 14:46:50 +00:00
|
|
|
attribute = PAD_ATTRIB::NPTH;
|
2012-04-07 18:05:56 +00:00
|
|
|
else
|
2021-05-01 14:46:50 +00:00
|
|
|
attribute = PAD_ATTRIB::PTH;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
strtok_r( nullptr, delims, &saveptr ); // skip unused prm
|
|
|
|
data = strtok_r( nullptr, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
LEG_MASK layer_mask = hexParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
pad->SetLayerSet( leg_mask2new( m_cu_count, layer_mask ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
pad->SetAttribute( attribute );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Ne" ) ) // (Ne)tname
|
|
|
|
{
|
|
|
|
// e.g. "Ne 461 "V5.0"
|
|
|
|
|
|
|
|
char buf[1024]; // can be fairly long
|
|
|
|
int netcode = intParse( line + SZ( "Ne" ), &data );
|
|
|
|
|
2014-06-02 09:41:54 +00:00
|
|
|
// Store the new code mapping
|
2014-06-03 07:32:57 +00:00
|
|
|
pad->SetNetCode( getNetCode( netcode ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// read Netname
|
|
|
|
ReadDelimitedText( buf, data, sizeof(buf) );
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2020-02-26 01:19:54 +00:00
|
|
|
if( m_board )
|
2021-06-15 12:08:26 +00:00
|
|
|
{
|
2020-02-26 01:19:54 +00:00
|
|
|
wxASSERT( m_board->FindNet( getNetCode( netcode ) )->GetNetname()
|
2021-06-15 12:08:26 +00:00
|
|
|
== ConvertToNewOverbarNotation( FROM_UTF8( StrPurge( buf ) ) ) );
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Po" ) ) // (Po)sition
|
|
|
|
{
|
|
|
|
// e.g. "Po 500 -500"
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I pos;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
pos.x = biuParse( line + SZ( "Po" ), &data );
|
|
|
|
pos.y = biuParse( data );
|
|
|
|
|
|
|
|
pad->SetPos0( pos );
|
2012-05-22 17:51:18 +00:00
|
|
|
// pad->SetPosition( pos ); set at function return
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Le" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "Le" ) );
|
2012-12-12 11:57:17 +00:00
|
|
|
pad->SetPadToDieLength( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".SolderMask" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
|
|
|
|
pad->SetLocalSolderMaskMargin( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( ".SolderPasteRatio" ) )
|
|
|
|
{
|
|
|
|
double tmp = atof( line + SZ( ".SolderPasteRatio" ) );
|
|
|
|
pad->SetLocalSolderPasteMarginRatio( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( ".SolderPaste" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
|
|
|
|
pad->SetLocalSolderPasteMargin( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( ".LocalClearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
|
|
|
|
pad->SetLocalClearance( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( ".ZoneConnection" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( ".ZoneConnection" ) );
|
2019-12-28 00:55:11 +00:00
|
|
|
pad->SetZoneConnection( (ZONE_CONNECTION) tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".ThermalWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
|
2020-09-10 18:35:11 +00:00
|
|
|
pad->SetThermalSpokeWidth( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( ".ThermalGap" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
|
|
|
|
pad->SetThermalGap( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndPAD" ) )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
// pad's "Position" is not relative to the footprint's, whereas Pos0 is relative
|
|
|
|
// to the footprint's but is the unrotated coordinate.
|
2012-05-22 17:51:18 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I padpos = pad->GetPos0();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
RotatePoint( padpos, aFootprint->GetOrientation() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
pad->SetPosition( padpos + aFootprint->GetPosition() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-08-14 01:51:14 +00:00
|
|
|
if( pad->GetSizeX() > 0 && pad->GetSizeY() > 0 )
|
|
|
|
{
|
|
|
|
aFootprint->Add( pad.release() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogError( _( "Invalid zero-sized pad ignored in\nfile: %s" ),
|
|
|
|
m_reader->GetSource() );
|
|
|
|
}
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndPAD'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void LEGACY_PLUGIN::loadFP_SHAPE( FOOTPRINT* aFootprint )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
SHAPE_T shape;
|
|
|
|
char* line = m_reader->Line(); // obtain current (old) line
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
switch( line[1] )
|
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case 'S': shape = SHAPE_T::SEGMENT; break;
|
|
|
|
case 'C': shape = SHAPE_T::CIRCLE; break;
|
|
|
|
case 'A': shape = SHAPE_T::ARC; break;
|
|
|
|
case 'P': shape = SHAPE_T::POLY; break;
|
2012-04-07 18:05:56 +00:00
|
|
|
default:
|
2021-06-27 23:26:54 +00:00
|
|
|
m_error.Printf( _( "Unknown FP_SHAPE type:'%c=0x%02x' on line %d of footprint '%s'." ),
|
2021-07-19 23:56:05 +00:00
|
|
|
(unsigned char) line[1], (unsigned char) line[1], m_reader->LineNumber(),
|
2021-06-27 23:26:54 +00:00
|
|
|
aFootprint->GetFPID().GetLibItemName().wx_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
std::unique_ptr<FP_SHAPE> dwg = std::make_unique<FP_SHAPE>( aFootprint, shape ); // a drawing
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
// common to all cases, and we have to check their values uniformly at end
|
2021-07-21 23:14:56 +00:00
|
|
|
BIU width = 1;
|
|
|
|
int layer = FIRST_NON_COPPER_LAYER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
switch( shape )
|
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2022-01-16 16:15:07 +00:00
|
|
|
BIU center0_x = biuParse( line + SZ( "DA" ), &data );
|
|
|
|
BIU center0_y = biuParse( data, &data );
|
|
|
|
BIU start0_x = biuParse( data, &data );
|
|
|
|
BIU start0_y = biuParse( data, &data );
|
|
|
|
EDA_ANGLE angle = degParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
width = biuParse( data, &data );
|
2021-07-21 23:14:56 +00:00
|
|
|
layer = intParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dwg->SetCenter0( VECTOR2I( center0_x, center0_y ) );
|
|
|
|
dwg->SetStart0( VECTOR2I( start0_x, start0_y ) );
|
2021-12-17 17:20:59 +00:00
|
|
|
dwg->SetArcAngleAndEnd0( angle, true );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
case SHAPE_T::CIRCLE:
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
|
|
|
// e.g. "DS -7874 -10630 7874 -10630 50 20\r\n"
|
|
|
|
BIU start0_x = biuParse( line + SZ( "DS" ), &data );
|
|
|
|
BIU start0_y = biuParse( data, &data );
|
|
|
|
BIU end0_x = biuParse( data, &data );
|
|
|
|
BIU end0_y = biuParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
width = biuParse( data, &data );
|
2021-07-21 23:14:56 +00:00
|
|
|
layer = intParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dwg->SetStart0( VECTOR2I( start0_x, start0_y ) );
|
|
|
|
dwg->SetEnd0( VECTOR2I( end0_x, end0_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
|
|
|
// e.g. "DP %d %d %d %d %d %d %d\n"
|
|
|
|
BIU start0_x = biuParse( line + SZ( "DP" ), &data );
|
|
|
|
BIU start0_y = biuParse( data, &data );
|
|
|
|
BIU end0_x = biuParse( data, &data );
|
|
|
|
BIU end0_y = biuParse( data, &data );
|
|
|
|
int ptCount = intParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
width = biuParse( data, &data );
|
2021-07-21 23:14:56 +00:00
|
|
|
layer = intParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dwg->SetStart0( VECTOR2I( start0_x, start0_y ) );
|
|
|
|
dwg->SetEnd0( VECTOR2I( end0_x, end0_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts;
|
2021-07-19 23:56:05 +00:00
|
|
|
pts.reserve( ptCount );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
for( int ii = 0; ii < ptCount; ++ii )
|
|
|
|
{
|
|
|
|
if( ( line = READLINE( m_reader ) ) == nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "S_POLGON point count mismatch." ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
// e.g. "Dl 23 44\n"
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( !TESTLINE( "Dl" ) )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing Dl point def" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
BIU x = biuParse( line + SZ( "Dl" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
|
|
|
pts.emplace_back( x, y );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
dwg->SetPolyPoints( pts );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// first switch code above prevents us from getting here.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a reasonable layer:
|
2020-11-14 14:29:11 +00:00
|
|
|
// layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints can use the
|
|
|
|
// copper layers, layer < FIRST_NON_COPPER_LAYER is allowed.
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layer < FIRST_LAYER || layer > LAST_NON_COPPER_LAYER )
|
2012-04-07 18:05:56 +00:00
|
|
|
layer = SILKSCREEN_N_FRONT;
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
dwg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
dwg->SetLayer( leg_layer2new( m_cu_count, layer ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* fpShape = dwg.release();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->Add( fpShape );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-11-13 21:07:01 +00:00
|
|
|
// this had been done at the FOOTPRINT level before, presumably because the FP_SHAPE needs
|
2020-11-14 21:21:54 +00:00
|
|
|
// to be already added to a footprint before this function will work.
|
2020-10-04 23:34:59 +00:00
|
|
|
fpShape->SetDrawCoord();
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void LEGACY_PLUGIN::loadMODULE_TEXT( FP_TEXT* aText )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
2012-08-11 19:14:45 +00:00
|
|
|
const char* txt_end;
|
|
|
|
const char* line = m_reader->Line(); // current (old) line
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
|
|
|
|
// or T1 0 500 600 400 900 80 M V 20 N"74LS245"
|
|
|
|
// ouch, the last example has no space between N and "74LS245" !
|
|
|
|
// that is an older version.
|
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
int type = intParse( line+1, &data );
|
|
|
|
BIU pos0_x = biuParse( data, &data );
|
|
|
|
BIU pos0_y = biuParse( data, &data );
|
|
|
|
BIU size0_y = biuParse( data, &data );
|
|
|
|
BIU size0_x = biuParse( data, &data );
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE orient = degParse( data, &data );
|
2022-01-13 17:27:36 +00:00
|
|
|
BIU thickn = biuParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// read the quoted text before the first call to strtok() which introduces
|
2021-06-09 19:32:58 +00:00
|
|
|
// NULs into the string and chops it into multiple C strings, something
|
2012-04-07 18:05:56 +00:00
|
|
|
// ReadDelimitedText() cannot traverse.
|
|
|
|
|
|
|
|
// convert the "quoted, escaped, UTF8, text" to a wxString, find it by skipping
|
|
|
|
// as far forward as needed until the first double quote.
|
2012-08-11 19:14:45 +00:00
|
|
|
txt_end = data + ReadDelimitedText( &m_field, data );
|
2022-02-05 02:06:25 +00:00
|
|
|
m_field.Replace( wxT( "%V" ), wxT( "${VALUE}" ) );
|
|
|
|
m_field.Replace( wxT( "%R" ), wxT( "${REFERENCE}" ) );
|
2021-06-15 12:08:26 +00:00
|
|
|
m_field = ConvertToNewOverbarNotation( m_field );
|
2012-04-07 18:05:56 +00:00
|
|
|
aText->SetText( m_field );
|
|
|
|
|
|
|
|
// after switching to strtok, there's no easy coming back because of the
|
|
|
|
// embedded nul(s?) placed to the right of the current field.
|
2013-04-04 21:35:01 +00:00
|
|
|
// (that's the reason why strtok was deprecated...)
|
2020-02-20 12:11:04 +00:00
|
|
|
char* mirror = strtok_r( (char*) data, delims, (char**) &data );
|
2021-07-19 23:56:05 +00:00
|
|
|
char* hide = strtok_r( nullptr, delims, (char**) &data );
|
|
|
|
char* tmp = strtok_r( nullptr, delims, (char**) &data );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer_num = tmp ? intParse( tmp ) : SILKSCREEN_N_FRONT;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
char* italic = strtok_r( nullptr, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
char* hjust = strtok_r( (char*) txt_end, delims, (char**) &data );
|
2021-07-19 23:56:05 +00:00
|
|
|
char* vjust = strtok_r( nullptr, delims, (char**) &data );
|
2012-08-11 19:14:45 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( type != FP_TEXT::TEXT_is_REFERENCE && type != FP_TEXT::TEXT_is_VALUE )
|
2020-10-04 23:34:59 +00:00
|
|
|
type = FP_TEXT::TEXT_is_DIVERS;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
aText->SetType( static_cast<FP_TEXT::TEXT_TYPE>( type ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
aText->SetPos0( VECTOR2I( pos0_x, pos0_y ) );
|
2017-01-23 20:30:11 +00:00
|
|
|
aText->SetTextSize( wxSize( size0_x, size0_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
orient -= ( static_cast<FOOTPRINT*>( aText->GetParentFootprint() ) )->GetOrientation();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
aText->SetTextAngle( orient );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
aText->SetTextThickness( thickn < 1 ? 0 : thickn );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
aText->SetMirrored( mirror && *mirror == 'M' );
|
|
|
|
|
|
|
|
aText->SetVisible( !(hide && *hide == 'I') );
|
|
|
|
|
|
|
|
aText->SetItalic( italic && *italic == 'I' );
|
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
if( hjust )
|
2012-08-15 17:55:48 +00:00
|
|
|
aText->SetHorizJustify( horizJustify( hjust ) );
|
2012-08-11 19:14:45 +00:00
|
|
|
|
|
|
|
if( vjust )
|
2012-08-15 17:55:48 +00:00
|
|
|
aText->SetVertJustify( vertJustify( vjust ) );
|
2012-08-11 19:14:45 +00:00
|
|
|
|
2019-02-09 17:10:55 +00:00
|
|
|
// A protection against mal formed (or edited by hand) files:
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_num < FIRST_LAYER )
|
|
|
|
layer_num = FIRST_LAYER;
|
|
|
|
else if( layer_num > LAST_NON_COPPER_LAYER )
|
|
|
|
layer_num = LAST_NON_COPPER_LAYER;
|
|
|
|
else if( layer_num == LAYER_N_BACK )
|
|
|
|
layer_num = SILKSCREEN_N_BACK;
|
|
|
|
else if( layer_num == LAYER_N_FRONT )
|
|
|
|
layer_num = SILKSCREEN_N_FRONT;
|
2019-02-09 17:10:55 +00:00
|
|
|
else if( layer_num < LAYER_N_FRONT ) // this case is a internal layer
|
|
|
|
layer_num = SILKSCREEN_N_FRONT;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2019-02-09 17:10:55 +00:00
|
|
|
aText->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// Calculate the actual position.
|
|
|
|
aText->SetDrawCoord();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void LEGACY_PLUGIN::load3D( FOOTPRINT* aFootprint )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2020-11-13 00:43:45 +00:00
|
|
|
FP_3DMODEL t3D;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "Na" ) ) // Shape File Name
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
ReadDelimitedText( buf, line + SZ( "Na" ), sizeof(buf) );
|
2016-07-19 17:35:25 +00:00
|
|
|
t3D.m_Filename = buf;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Sc" ) ) // Scale
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n", &t3D.m_Scale.x, &t3D.m_Scale.y,
|
2016-07-19 17:35:25 +00:00
|
|
|
&t3D.m_Scale.z );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Of" ) ) // Offset
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
sscanf( line + SZ( "Of" ), "%lf %lf %lf\n", &t3D.m_Offset.x, &t3D.m_Offset.y,
|
2016-07-19 17:35:25 +00:00
|
|
|
&t3D.m_Offset.z );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Ro" ) ) // Rotation
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n", &t3D.m_Rotation.x, &t3D.m_Rotation.y,
|
2016-07-19 17:35:25 +00:00
|
|
|
&t3D.m_Rotation.z );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndSHAPE3D" ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-13 01:33:30 +00:00
|
|
|
aFootprint->Models().push_back( t3D );
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndSHAPE3D'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPCB_LINE()
|
|
|
|
{
|
|
|
|
/* example:
|
|
|
|
$DRAWSEGMENT
|
|
|
|
Po 0 57500 -1000 57500 0 150
|
|
|
|
De 24 0 900 0 0
|
|
|
|
$EndDRAWSEGMENT
|
|
|
|
*/
|
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> dseg = std::make_unique<PCB_SHAPE>( m_board );
|
2013-12-10 23:41:34 +00:00
|
|
|
|
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "Po" ) )
|
|
|
|
{
|
|
|
|
int shape = intParse( line + SZ( "Po" ), &data );
|
|
|
|
BIU start_x = biuParse( data, &data );
|
|
|
|
BIU start_y = biuParse( data, &data );
|
|
|
|
BIU end_x = biuParse( data, &data );
|
|
|
|
BIU end_y = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data );
|
|
|
|
|
|
|
|
if( width < 0 )
|
|
|
|
width = 0;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
dseg->SetShape( static_cast<SHAPE_T>( shape ) );
|
2020-11-14 01:16:02 +00:00
|
|
|
dseg->SetFilled( false );
|
2021-07-17 19:56:18 +00:00
|
|
|
dseg->SetStroke( STROKE_PARAMS( width, PLOT_DASH_TYPE::SOLID ) );
|
2022-01-19 22:44:52 +00:00
|
|
|
|
|
|
|
if( dseg->GetShape() == SHAPE_T::ARC )
|
|
|
|
{
|
|
|
|
dseg->SetCenter( VECTOR2I( start_x, start_y ) );
|
|
|
|
dseg->SetStart( VECTOR2I( end_x, end_y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dseg->SetStart( VECTOR2I( start_x, start_y ) );
|
|
|
|
dseg->SetEnd( VECTOR2I( end_x, end_y ) );
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "De" ) )
|
|
|
|
{
|
|
|
|
BIU x = 0;
|
|
|
|
BIU y;
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( line + SZ( "De" ), delims, &saveptr );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
for( int i = 0; data; ++i, data = strtok_r( nullptr, delims, &saveptr ) )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
switch( i )
|
|
|
|
{
|
|
|
|
case 0:
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer;
|
|
|
|
layer = intParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layer < FIRST_NON_COPPER_LAYER )
|
|
|
|
layer = FIRST_NON_COPPER_LAYER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
else if( layer > LAST_NON_COPPER_LAYER )
|
|
|
|
layer = LAST_NON_COPPER_LAYER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
dseg->SetLayer( leg_layer2new( m_cu_count, layer ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-01-16 16:15:07 +00:00
|
|
|
{
|
|
|
|
EDA_ANGLE angle = degParse( data );
|
2021-12-17 17:20:59 +00:00
|
|
|
|
|
|
|
if( dseg->GetShape() == SHAPE_T::ARC )
|
2022-01-19 22:44:52 +00:00
|
|
|
dseg->SetArcAngleAndEnd( angle );
|
2021-12-17 17:20:59 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
2022-01-16 16:15:07 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
case 3:
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( dseg->m_Uuid ) = KIID( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2022-01-16 16:15:07 +00:00
|
|
|
{
|
2021-06-08 03:06:11 +00:00
|
|
|
EDA_ITEM_FLAGS state;
|
|
|
|
state = static_cast<EDA_ITEM_FLAGS>( hexParse( data ) );
|
2013-03-30 19:55:26 +00:00
|
|
|
dseg->SetState( state, true );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
2022-01-16 16:15:07 +00:00
|
|
|
}
|
|
|
|
// Bezier Control Points
|
2012-04-07 18:05:56 +00:00
|
|
|
case 5:
|
|
|
|
x = biuParse( data );
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
y = biuParse( data );
|
2022-01-01 17:11:21 +00:00
|
|
|
dseg->SetBezierC1( VECTOR2I( x, y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
x = biuParse( data );
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
y = biuParse( data );
|
2022-01-01 17:11:21 +00:00
|
|
|
dseg->SetBezierC2( VECTOR2I( x, y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndDRAWSEGMENT" ) )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
m_board->Add( dseg.release(), ADD_MODE::APPEND );
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndDRAWSEGMENT'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadNETINFO_ITEM()
|
|
|
|
{
|
2015-08-16 09:02:19 +00:00
|
|
|
/* a net description is something like
|
|
|
|
* $EQUIPOT
|
|
|
|
* Na 5 "/BIT1"
|
|
|
|
* St ~
|
|
|
|
* $EndEQUIPOT
|
|
|
|
*/
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
char buf[1024];
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
NETINFO_ITEM* net = nullptr;
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2014-06-06 10:30:07 +00:00
|
|
|
int netCode = 0;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "Na" ) )
|
|
|
|
{
|
|
|
|
// e.g. "Na 58 "/cpu.sch/PAD7"\r\n"
|
|
|
|
|
2014-06-02 09:41:54 +00:00
|
|
|
netCode = intParse( line + SZ( "Na" ), &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
ReadDelimitedText( buf, data, sizeof(buf) );
|
2015-08-16 09:02:19 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( net == nullptr )
|
2021-06-15 12:08:26 +00:00
|
|
|
{
|
|
|
|
net = new NETINFO_ITEM( m_board, ConvertToNewOverbarNotation( FROM_UTF8( buf ) ),
|
|
|
|
netCode );
|
|
|
|
}
|
2015-08-16 09:02:19 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Two net definitions in '$EQUIPOT' block" ) );
|
2015-08-16 09:02:19 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndEQUIPOT" ) )
|
2012-06-30 08:20:04 +00:00
|
|
|
{
|
|
|
|
// net 0 should be already in list, so store this net
|
|
|
|
// if it is not the net 0, or if the net 0 does not exists.
|
2021-07-19 23:56:05 +00:00
|
|
|
if( net && ( net->GetNetCode() > 0 || m_board->FindNet( 0 ) == nullptr ) )
|
2014-06-02 09:41:54 +00:00
|
|
|
{
|
2016-09-05 10:22:24 +00:00
|
|
|
m_board->Add( net );
|
2014-06-06 10:30:07 +00:00
|
|
|
|
|
|
|
// Be sure we have room to store the net in m_netCodes
|
|
|
|
if( (int)m_netCodes.size() <= netCode )
|
|
|
|
m_netCodes.resize( netCode+1 );
|
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
m_netCodes[netCode] = net->GetNetCode();
|
2021-07-19 23:56:05 +00:00
|
|
|
net = nullptr;
|
2014-06-02 09:41:54 +00:00
|
|
|
}
|
2012-06-30 08:20:04 +00:00
|
|
|
else
|
2014-06-02 09:41:54 +00:00
|
|
|
{
|
2012-06-30 08:20:04 +00:00
|
|
|
delete net;
|
2021-07-19 23:56:05 +00:00
|
|
|
net = nullptr; // Avoid double deletion.
|
2014-06-02 09:41:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
2012-06-30 08:20:04 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 08:28:12 +00:00
|
|
|
// If we are here, there is an error.
|
|
|
|
delete net;
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndEQUIPOT'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPCB_TEXT()
|
|
|
|
{
|
|
|
|
/* examples:
|
|
|
|
For a single line text:
|
|
|
|
----------------------
|
|
|
|
$TEXTPCB
|
|
|
|
Te "Text example"
|
|
|
|
Po 66750 53450 600 800 150 0
|
2015-07-25 11:16:05 +00:00
|
|
|
De 24 1 0 Italic
|
2012-04-07 18:05:56 +00:00
|
|
|
$EndTEXTPCB
|
|
|
|
|
|
|
|
For a multi line text:
|
|
|
|
---------------------
|
|
|
|
$TEXTPCB
|
|
|
|
Te "Text example"
|
|
|
|
Nl "Line 2"
|
|
|
|
Po 66750 53450 600 800 150 0
|
2015-07-25 11:16:05 +00:00
|
|
|
De 24 1 0 Italic
|
2012-04-07 18:05:56 +00:00
|
|
|
$EndTEXTPCB
|
|
|
|
Nl "line nn" is a line added to the current text
|
|
|
|
*/
|
|
|
|
|
|
|
|
char text[1024];
|
|
|
|
|
|
|
|
// maybe someday a constructor that takes all this data in one call?
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_TEXT* pcbtxt = new PCB_TEXT( m_board );
|
2019-12-28 00:55:11 +00:00
|
|
|
m_board->Add( pcbtxt, ADD_MODE::APPEND );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
char* line;
|
2012-11-27 13:50:01 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "Te" ) ) // Text line (or first line for multi line texts)
|
|
|
|
{
|
2012-05-24 01:18:30 +00:00
|
|
|
ReadDelimitedText( text, line + SZ( "Te" ), sizeof(text) );
|
2021-06-15 12:08:26 +00:00
|
|
|
pcbtxt->SetText( ConvertToNewOverbarNotation( FROM_UTF8( text ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "nl" ) ) // next line of the current text
|
|
|
|
{
|
|
|
|
ReadDelimitedText( text, line + SZ( "nl" ), sizeof(text) );
|
2012-05-24 01:18:30 +00:00
|
|
|
pcbtxt->SetText( pcbtxt->GetText() + wxChar( '\n' ) + FROM_UTF8( text ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
wxSize size;
|
|
|
|
BIU pos_x = biuParse( line + SZ( "Po" ), &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-13 23:30:52 +00:00
|
|
|
size.x = biuParse( data, &data );
|
|
|
|
size.y = biuParse( data, &data );
|
|
|
|
|
|
|
|
BIU thickn = biuParse( data, &data );
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE angle = degParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2017-01-23 20:30:11 +00:00
|
|
|
pcbtxt->SetTextSize( size );
|
2020-04-14 12:25:00 +00:00
|
|
|
pcbtxt->SetTextThickness( thickn );
|
2017-01-23 20:30:11 +00:00
|
|
|
pcbtxt->SetTextAngle( angle );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
pcbtxt->SetTextPos( VECTOR2I( pos_x, pos_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "De" ) )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
// e.g. "De 21 1 68183921-93a5-49ac-91b0-49d05a0e1647 Normal C\r\n"
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer_num = intParse( line + SZ( "De" ), &data );
|
|
|
|
int notMirrored = intParse( data, &data );
|
|
|
|
char* uuid = strtok_r( (char*) data, delims, (char**) &data );
|
|
|
|
char* style = strtok_r( nullptr, delims, (char**) &data );
|
|
|
|
char* hJustify = strtok_r( nullptr, delims, (char**) &data );
|
|
|
|
char* vJustify = strtok_r( nullptr, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
pcbtxt->SetMirrored( !notMirrored );
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( pcbtxt->m_Uuid ) = KIID( uuid );
|
2012-04-07 18:05:56 +00:00
|
|
|
pcbtxt->SetItalic( !strcmp( style, "Italic" ) );
|
|
|
|
|
|
|
|
if( hJustify )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-08-15 17:55:48 +00:00
|
|
|
pcbtxt->SetHorizJustify( horizJustify( hJustify ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else
|
|
|
|
{
|
2012-08-11 19:14:45 +00:00
|
|
|
// boom, somebody changed a constructor, I was relying on this:
|
2021-12-28 22:13:54 +00:00
|
|
|
wxASSERT( pcbtxt->GetHorizJustify() == GR_TEXT_H_ALIGN_CENTER );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
if( vJustify )
|
2012-08-15 17:55:48 +00:00
|
|
|
pcbtxt->SetVertJustify( vertJustify( vJustify ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_num < FIRST_COPPER_LAYER )
|
|
|
|
layer_num = FIRST_COPPER_LAYER;
|
|
|
|
else if( layer_num > LAST_NON_COPPER_LAYER )
|
|
|
|
layer_num = LAST_NON_COPPER_LAYER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2015-07-25 11:16:05 +00:00
|
|
|
if( layer_num >= FIRST_NON_COPPER_LAYER ||
|
|
|
|
is_leg_copperlayer_valid( m_cu_count, layer_num ) )
|
|
|
|
pcbtxt->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
|
|
|
else // not perfect, but putting this text on front layer is a workaround
|
|
|
|
pcbtxt->SetLayer( F_Cu );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndTEXTPCB" ) )
|
|
|
|
{
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndTEXTPCB'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-10 00:39:40 +00:00
|
|
|
void LEGACY_PLUGIN::loadTrackList( int aStructType )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
checkpoint();
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
// read two lines per loop iteration, each loop is one TRACK or VIA
|
|
|
|
// example first line:
|
2012-05-24 15:00:59 +00:00
|
|
|
// e.g. "Po 0 23994 28800 24400 28800 150 -1" for a track
|
|
|
|
// e.g. "Po 3 21086 17586 21086 17586 180 -1" for a via (uses sames start and end)
|
2012-04-07 18:05:56 +00:00
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( line[0] == '$' ) // $EndTRACK
|
|
|
|
return; // preferred exit
|
|
|
|
|
|
|
|
assert( TESTLINE( "Po" ) );
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
VIATYPE viatype = static_cast<VIATYPE>( intParse( line + SZ( "Po" ), &data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU start_x = biuParse( data, &data );
|
|
|
|
BIU start_y = biuParse( data, &data );
|
|
|
|
BIU end_x = biuParse( data, &data );
|
|
|
|
BIU end_y = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data, &data );
|
|
|
|
|
|
|
|
// optional 7th drill parameter (must be optional in an old format?)
|
2020-02-20 12:11:04 +00:00
|
|
|
data = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-08 19:01:54 +00:00
|
|
|
BIU drill = data ? biuParse( data ) : -1; // SetDefault() if < 0
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// Read the 2nd line to determine the exact type, one of:
|
2018-09-29 17:58:31 +00:00
|
|
|
// PCB_TRACE_T, PCB_VIA_T, or PCB_SEGZONE_T. The type field in 2nd line
|
2012-04-07 18:05:56 +00:00
|
|
|
// differentiates between PCB_TRACE_T and PCB_VIA_T. With virtual
|
|
|
|
// functions in use, it is critical to instantiate the PCB_VIA_T
|
|
|
|
// exactly.
|
2012-04-16 03:18:41 +00:00
|
|
|
READLINE( m_reader );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
line = m_reader->Line();
|
|
|
|
|
|
|
|
// example second line:
|
|
|
|
// "De 0 0 463 0 800000\r\n"
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
assert( TESTLINE( "De" ) );
|
|
|
|
#else
|
|
|
|
if( !TESTLINE( "De" ) )
|
|
|
|
{
|
|
|
|
// mandatory 2nd line is missing
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing 2nd line of a TRACK def" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-14 18:20:19 +00:00
|
|
|
int makeType;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// parse the 2nd line to determine the type of object
|
2020-02-20 12:11:04 +00:00
|
|
|
// e.g. "De 15 1 7 68183921-93a5-49ac-91b0-49d05a0e1647 0" for a via
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer_num = intParse( line + SZ( "De" ), &data );
|
|
|
|
int type = intParse( data, &data );
|
|
|
|
int net_code = intParse( data, &data );
|
|
|
|
char* uuid = strtok_r( (char*) data, delims, (char**) &data );
|
|
|
|
int flags_int = intParse( data, (const char**) &data );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
EDA_ITEM_FLAGS flags = static_cast<EDA_ITEM_FLAGS>( flags_int );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
if( aStructType == PCB_TRACE_T )
|
2019-04-18 13:59:11 +00:00
|
|
|
{
|
2019-04-10 09:19:16 +00:00
|
|
|
makeType = ( type == 1 ) ? PCB_VIA_T : PCB_TRACE_T;
|
2019-04-18 13:59:11 +00:00
|
|
|
}
|
2019-04-10 09:19:16 +00:00
|
|
|
else if (aStructType == NOT_USED )
|
2019-04-18 13:59:11 +00:00
|
|
|
{
|
2019-04-10 09:19:16 +00:00
|
|
|
continue;
|
2019-04-18 13:59:11 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else
|
2019-04-18 13:59:11 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "Segment type unknown" ) );
|
2019-04-18 13:59:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* newTrack;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
switch( makeType )
|
|
|
|
{
|
|
|
|
default:
|
2021-06-11 21:07:02 +00:00
|
|
|
case PCB_TRACE_T: newTrack = new PCB_TRACK( m_board ); break;
|
|
|
|
case PCB_VIA_T: newTrack = new PCB_VIA( m_board ); break;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( newTrack->m_Uuid ) = KIID( uuid );
|
2022-01-01 17:11:21 +00:00
|
|
|
newTrack->SetPosition( VECTOR2I( start_x, start_y ) );
|
|
|
|
newTrack->SetEnd( VECTOR2I( end_x, end_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
newTrack->SetWidth( width );
|
|
|
|
|
|
|
|
if( makeType == PCB_VIA_T ) // Ensure layers are OK when possible:
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA *via = static_cast<PCB_VIA*>( newTrack );
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( viatype );
|
|
|
|
|
|
|
|
if( drill < 0 )
|
|
|
|
via->SetDrillDefault();
|
|
|
|
else
|
|
|
|
via->SetDrill( drill );
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( via->GetViaType() == VIATYPE::THROUGH )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
via->SetLayerPair( F_Cu, B_Cu );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2014-06-25 17:01:50 +00:00
|
|
|
else
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID back = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
|
|
|
|
PCB_LAYER_ID front = leg_layer2new( m_cu_count, layer_num & 0xf );
|
2014-06-25 17:01:50 +00:00
|
|
|
|
2015-07-25 11:16:05 +00:00
|
|
|
if( is_leg_copperlayer_valid( m_cu_count, back ) &&
|
|
|
|
is_leg_copperlayer_valid( m_cu_count, front ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2015-07-25 11:16:05 +00:00
|
|
|
via->SetLayerPair( front, back );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2015-07-25 11:16:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
delete via;
|
2021-07-19 23:56:05 +00:00
|
|
|
newTrack = nullptr;
|
2015-07-25 11:16:05 +00:00
|
|
|
}
|
2014-06-25 17:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-25 11:16:05 +00:00
|
|
|
// A few legacy boards can have tracks on non existent layers, because
|
|
|
|
// reducing the number of layers does not remove tracks on removed layers
|
|
|
|
// If happens, skip them
|
|
|
|
if( is_leg_copperlayer_valid( m_cu_count, layer_num ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2015-07-25 11:16:05 +00:00
|
|
|
newTrack->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2015-07-25 11:16:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
delete newTrack;
|
2021-07-19 23:56:05 +00:00
|
|
|
newTrack = nullptr;
|
2015-07-25 11:16:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 11:16:05 +00:00
|
|
|
if( newTrack )
|
|
|
|
{
|
|
|
|
newTrack->SetNetCode( getNetCode( net_code ) );
|
|
|
|
newTrack->SetState( flags, true );
|
2014-05-22 17:34:28 +00:00
|
|
|
|
2015-07-25 11:16:05 +00:00
|
|
|
m_board->Add( newTrack );
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndTRACK'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadNETCLASS()
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
wxString netname;
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// create an empty NETCLASS without a name, but do not add it to the BOARD
|
|
|
|
// yet since that would bypass duplicate netclass name checking within the BOARD.
|
2016-06-05 11:49:25 +00:00
|
|
|
// store it temporarily in an unique_ptr until successfully inserted into the BOARD
|
2012-04-07 18:05:56 +00:00
|
|
|
// just before returning.
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NETCLASS> nc = std::make_shared<NETCLASS>( wxEmptyString );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "AddNet" ) ) // most frequent type of line
|
|
|
|
{
|
|
|
|
// e.g. "AddNet "V3.3D"\n"
|
|
|
|
ReadDelimitedText( buf, line + SZ( "AddNet" ), sizeof(buf) );
|
2021-06-15 12:08:26 +00:00
|
|
|
netname = ConvertToNewOverbarNotation( FROM_UTF8( buf ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
|
|
|
|
m_board->GetDesignSettings().m_NetSettings->m_NetClassPatternAssignments.push_back(
|
|
|
|
{
|
|
|
|
std::make_unique<EDA_COMBINED_MATCHER>( netname, CTX_NETCLASS ),
|
|
|
|
nc->GetName()
|
|
|
|
} );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Clearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "Clearance" ) );
|
|
|
|
nc->SetClearance( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "TrackWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TrackWidth" ) );
|
|
|
|
nc->SetTrackWidth( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ViaDia" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaDia" ) );
|
|
|
|
nc->SetViaDiameter( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ViaDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
|
|
|
|
nc->SetViaDrill( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "uViaDia" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "uViaDia" ) );
|
|
|
|
nc->SetuViaDiameter( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "uViaDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "uViaDrill" ) );
|
|
|
|
nc->SetuViaDrill( tmp );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Name" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line + SZ( "Name" ), sizeof(buf) );
|
|
|
|
nc->SetName( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Desc" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line + SZ( "Desc" ), sizeof(buf) );
|
|
|
|
nc->SetDescription( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$EndNCLASS" ) )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_board->GetDesignSettings().m_NetSettings->m_NetClasses.count( nc->GetName() ) )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// Must have been a name conflict, this is a bad board file.
|
|
|
|
// User may have done a hand edit to the file.
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
// unique_ptr will delete nc on this code path
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_error.Printf( _( "Duplicate NETCLASS name '%s'." ), nc->GetName() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
2022-08-14 11:03:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_board->GetDesignSettings().m_NetSettings->m_NetClasses[ nc->GetName() ] = nc;
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndNCLASS'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadZONE_CONTAINER()
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
std::unique_ptr<ZONE> zc = std::make_unique<ZONE>( m_board );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
ZONE_BORDER_DISPLAY_STYLE outline_hatch = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH;
|
2017-06-19 11:29:57 +00:00
|
|
|
bool endContour = false;
|
|
|
|
int holeIndex = -1; // -1 is the main outline; holeIndex >= 0 = hole index
|
2012-04-07 18:05:56 +00:00
|
|
|
char buf[1024];
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
2017-06-19 11:29:57 +00:00
|
|
|
if( TESTLINE( "ZCorner" ) ) // new corner of the zone outlines found
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// e.g. "ZCorner 25650 49500 0"
|
|
|
|
BIU x = biuParse( line + SZ( "ZCorner" ), &data );
|
|
|
|
BIU y = biuParse( data, &data );
|
|
|
|
|
2017-06-19 11:29:57 +00:00
|
|
|
if( endContour )
|
|
|
|
{
|
|
|
|
// the previous corner was the last corner of a contour.
|
|
|
|
// so this corner is the first of a new hole
|
|
|
|
endContour = false;
|
2017-03-07 12:06:00 +00:00
|
|
|
zc->NewHole();
|
2017-06-19 11:29:57 +00:00
|
|
|
holeIndex++;
|
|
|
|
}
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
zc->AppendCorner( VECTOR2I( x, y ), holeIndex );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2017-06-19 11:29:57 +00:00
|
|
|
// Is this corner the end of current contour?
|
|
|
|
// the next corner (if any) will be stored in a new contour (a hole)
|
|
|
|
// intParse( data )returns 0 = usual corner, 1 = last corner of the current contour:
|
|
|
|
endContour = intParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZInfo" ) ) // general info found
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
// e.g. 'ZInfo 68183921-93a5-49ac-91b0-49d05a0e1647 310 "COMMON"'
|
|
|
|
char* uuid = strtok_r( (char*) line + SZ( "ZInfo" ), delims, (char**) &data );
|
|
|
|
int netcode = intParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) )
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "ZInfo netname too long" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( zc->m_Uuid ) = KIID( uuid );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-06-30 08:20:04 +00:00
|
|
|
// Init the net code only, not the netname, to be sure
|
|
|
|
// the zone net name is the name read in file.
|
|
|
|
// (When mismatch, the user will be prompted in DRC, to fix the actual name)
|
2014-06-03 07:32:57 +00:00
|
|
|
zc->BOARD_CONNECTED_ITEM::SetNetCode( getNetCode( netcode ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZLayer" ) ) // layer found
|
|
|
|
{
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer_num = intParse( line + SZ( "ZLayer" ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
zc->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZAux" ) ) // aux info found
|
|
|
|
{
|
|
|
|
// e.g. "ZAux 7 E"
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "ZAux" ), &data ) );
|
2020-02-20 12:11:04 +00:00
|
|
|
char* hopt = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( !hopt )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
m_error.Printf( _( "Bad ZAux for CZONE_CONTAINER \"%s\"" ),
|
|
|
|
zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
switch( *hopt ) // upper case required
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2020-08-07 14:04:34 +00:00
|
|
|
case 'N': outline_hatch = ZONE_BORDER_DISPLAY_STYLE::NO_HATCH; break;
|
|
|
|
case 'E': outline_hatch = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE; break;
|
|
|
|
case 'F': outline_hatch = ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL; break;
|
2012-04-07 18:05:56 +00:00
|
|
|
default:
|
2020-02-20 12:11:04 +00:00
|
|
|
m_error.Printf( _( "Bad ZAux for CZONE_CONTAINER \"%s\"" ),
|
|
|
|
zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set hatch mode later, after reading corner outline data
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZSmoothing" ) )
|
|
|
|
{
|
|
|
|
// e.g. "ZSmoothing 0 0"
|
|
|
|
int smoothing = intParse( line + SZ( "ZSmoothing" ), &data );
|
|
|
|
BIU cornerRadius = biuParse( data );
|
|
|
|
|
|
|
|
if( smoothing >= ZONE_SETTINGS::SMOOTHING_LAST || smoothing < 0 )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
m_error.Printf( _( "Bad ZSmoothing for CZONE_CONTAINER \"%s\"" ),
|
|
|
|
zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
zc->SetCornerSmoothingType( smoothing );
|
|
|
|
zc->SetCornerRadius( cornerRadius );
|
|
|
|
}
|
2012-07-13 18:55:29 +00:00
|
|
|
else if( TESTLINE( "ZKeepout" ) )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
char* token;
|
2020-09-21 23:32:07 +00:00
|
|
|
zc->SetIsRuleArea( true );
|
2020-05-07 00:30:46 +00:00
|
|
|
zc->SetDoNotAllowPads( false ); // Not supported in legacy
|
|
|
|
zc->SetDoNotAllowFootprints( false ); // Not supported in legacy
|
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
// e.g. "ZKeepout tracks N vias N pads Y"
|
2020-02-20 12:11:04 +00:00
|
|
|
token = strtok_r( line + SZ( "ZKeepout" ), delims, (char**) &data );
|
2012-07-13 18:55:29 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
while( token )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
if( !strcmp( token, "tracks" ) )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
token = strtok_r( nullptr, delims, (char**) &data );
|
2020-02-20 12:11:04 +00:00
|
|
|
zc->SetDoNotAllowTracks( token && *token == 'N' );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
2020-02-20 12:11:04 +00:00
|
|
|
else if( !strcmp( token, "vias" ) )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
token = strtok_r( nullptr, delims, (char**) &data );
|
2020-02-20 12:11:04 +00:00
|
|
|
zc->SetDoNotAllowVias( token && *token == 'N' );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
2020-02-20 12:11:04 +00:00
|
|
|
else if( !strcmp( token, "copperpour" ) )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
token = strtok_r( nullptr, delims, (char**) &data );
|
2020-02-20 12:11:04 +00:00
|
|
|
zc->SetDoNotAllowCopperPour( token && *token == 'N' );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
token = strtok_r( nullptr, delims, (char**) &data );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "ZOptions" ) )
|
|
|
|
{
|
|
|
|
// e.g. "ZOptions 0 32 F 200 200"
|
|
|
|
int fillmode = intParse( line + SZ( "ZOptions" ), &data );
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( data, &data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
char fillstate = data[1]; // here e.g. " F"
|
|
|
|
BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F"
|
|
|
|
BIU thermalReliefCopperBridge = biuParse( data );
|
|
|
|
|
2019-04-10 09:19:16 +00:00
|
|
|
if( fillmode)
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
// SEGMENT fill mode no longer supported. Make sure user is OK with converting
|
|
|
|
// them.
|
2022-02-11 12:42:09 +00:00
|
|
|
if( m_showLegacySegmentZoneWarning )
|
2019-04-10 09:19:16 +00:00
|
|
|
{
|
|
|
|
KIDIALOG dlg( nullptr,
|
|
|
|
_( "The legacy segment fill mode is no longer supported.\n"
|
2022-02-11 12:42:09 +00:00
|
|
|
"Convert zones to smoothed polygon fills?" ),
|
2019-04-10 09:19:16 +00:00
|
|
|
_( "Legacy Zone Warning" ),
|
|
|
|
wxYES_NO | wxICON_WARNING );
|
|
|
|
|
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_NO )
|
|
|
|
THROW_IO_ERROR( wxT( "CANCEL" ) );
|
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
m_showLegacySegmentZoneWarning = false;
|
2019-04-10 09:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// User OK'd; switch to polygon mode
|
2019-12-20 14:11:39 +00:00
|
|
|
zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
2019-04-10 09:19:16 +00:00
|
|
|
m_board->SetModified();
|
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-03-06 10:49:08 +00:00
|
|
|
zc->SetIsFilled( fillstate == 'S' );
|
2012-04-07 18:05:56 +00:00
|
|
|
zc->SetThermalReliefGap( thermalReliefGap );
|
2020-09-17 13:14:45 +00:00
|
|
|
zc->SetThermalReliefSpokeWidth( thermalReliefCopperBridge );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found
|
|
|
|
{
|
|
|
|
// e.g. "ZClearance 40 I"
|
|
|
|
BIU clearance = biuParse( line + SZ( "ZClearance" ), &data );
|
2020-02-20 12:11:04 +00:00
|
|
|
char* padoption = strtok_r( (char*) data, delims, (char**) &data ); // data: " I"
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
ZONE_CONNECTION popt;
|
2012-04-07 18:05:56 +00:00
|
|
|
switch( *padoption )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
case 'I': popt = ZONE_CONNECTION::FULL; break;
|
|
|
|
case 'T': popt = ZONE_CONNECTION::THERMAL; break;
|
|
|
|
case 'H': popt = ZONE_CONNECTION::THT_THERMAL; break;
|
|
|
|
case 'X': popt = ZONE_CONNECTION::NONE; break;
|
2012-04-07 18:05:56 +00:00
|
|
|
default:
|
2017-12-15 11:37:46 +00:00
|
|
|
m_error.Printf( _( "Bad ZClearance padoption for CZONE_CONTAINER \"%s\"" ),
|
2020-02-20 12:11:04 +00:00
|
|
|
zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
zc->SetLocalClearance( clearance );
|
2012-04-07 18:05:56 +00:00
|
|
|
zc->SetPadConnection( popt );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZMinThickness" ) )
|
|
|
|
{
|
|
|
|
BIU thickness = biuParse( line + SZ( "ZMinThickness" ) );
|
|
|
|
zc->SetMinThickness( thickness );
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "ZPriority" ) )
|
|
|
|
{
|
|
|
|
int priority = intParse( line + SZ( "ZPriority" ) );
|
2022-03-01 14:53:35 +00:00
|
|
|
zc->SetAssignedPriority( priority );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$POLYSCORNERS" ) )
|
|
|
|
{
|
2017-06-19 11:29:57 +00:00
|
|
|
// Read the PolysList (polygons that are the solid areas in the filled zone)
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET polysList;
|
|
|
|
|
|
|
|
bool makeNewOutline = true;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "$endPOLYSCORNERS" ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// e.g. "39610 43440 0 0"
|
|
|
|
BIU x = biuParse( line, &data );
|
|
|
|
BIU y = biuParse( data, &data );
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( makeNewOutline )
|
|
|
|
polysList.NewOutline();
|
|
|
|
|
|
|
|
polysList.Append( x, y );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
// end_countour was a bool when file saved, so '0' or '1' here
|
|
|
|
bool end_contour = intParse( data, &data );
|
2015-07-27 19:45:57 +00:00
|
|
|
intParse( data ); // skip corner utility flag
|
|
|
|
|
|
|
|
makeNewOutline = end_contour;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-06-24 02:19:08 +00:00
|
|
|
zc->SetFilledPolysList( zc->GetLayer(), polysList );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "$FILLSEGMENTS" ) )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "$endFILLSEGMENTS" ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// e.g. ""%d %d %d %d\n"
|
2022-02-11 16:04:05 +00:00
|
|
|
ignore_unused( biuParse( line, &data ) );
|
|
|
|
ignore_unused( biuParse( data, &data ) );
|
|
|
|
ignore_unused( biuParse( data, &data ) );
|
|
|
|
ignore_unused( biuParse( data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$endCZONE_OUTLINE" ) )
|
|
|
|
{
|
2013-03-10 13:59:47 +00:00
|
|
|
// Ensure keepout does not have a net
|
|
|
|
// (which have no sense for a keepout zone)
|
2020-09-21 23:32:07 +00:00
|
|
|
if( zc->GetIsRuleArea() )
|
2014-02-25 10:47:27 +00:00
|
|
|
zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2013-03-10 13:59:47 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
// should always occur, but who knows, a zone without two corners
|
|
|
|
// is no zone at all, it's a spot?
|
|
|
|
|
|
|
|
if( zc->GetNumCorners() > 2 )
|
|
|
|
{
|
|
|
|
if( !zc->IsOnCopperLayer() )
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
zc->SetFillMode( ZONE_FILL_MODE::POLYGONS );
|
2014-02-25 10:47:27 +00:00
|
|
|
zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 14:04:34 +00:00
|
|
|
// HatchBorder here, after outlines corners are read
|
2012-04-07 18:05:56 +00:00
|
|
|
// Set hatch here, after outlines corners are read
|
2020-11-11 23:05:59 +00:00
|
|
|
zc->SetBorderDisplayStyle( outline_hatch, ZONE::GetDefaultHatchPitch(), true );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
m_board->Add( zc.release() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$endCZONE_OUTLINE'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadDIMENSION()
|
|
|
|
{
|
2021-12-04 23:52:00 +00:00
|
|
|
std::unique_ptr<PCB_DIM_ALIGNED> dim = std::make_unique<PCB_DIM_ALIGNED>( m_board,
|
|
|
|
PCB_DIM_ALIGNED_T );
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I crossBarO;
|
|
|
|
VECTOR2I crossBarF;
|
2013-12-10 23:41:34 +00:00
|
|
|
|
|
|
|
char* line;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "$endCOTATION" ) )
|
|
|
|
{
|
2021-12-17 17:20:59 +00:00
|
|
|
dim->UpdateHeight( crossBarF, crossBarO );
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
m_board->Add( dim.release(), ADD_MODE::APPEND );
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Va" ) )
|
|
|
|
{
|
|
|
|
BIU value = biuParse( line + SZ( "Va" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
// unused; dimension value is calculated from coordinates
|
|
|
|
( void )value;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Ge" ) )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
// e.g. "Ge 1 21 68183921-93a5-49ac-91b0-49d05a0e1647\r\n"
|
2021-07-21 23:14:56 +00:00
|
|
|
int shape = intParse( line + SZ( "De" ), (const char**) &data );
|
|
|
|
int layer_num = intParse( data, &data );
|
|
|
|
char* uuid = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
dim->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( dim->m_Uuid ) = KIID( uuid );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
// not used
|
|
|
|
( void )shape;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Te" ) )
|
|
|
|
{
|
|
|
|
char buf[2048];
|
|
|
|
|
|
|
|
ReadDelimitedText( buf, line + SZ( "Te" ), sizeof(buf) );
|
2021-12-17 23:31:37 +00:00
|
|
|
dim->SetOverrideText( FROM_UTF8( buf ) );
|
|
|
|
dim->SetOverrideTextEnabled( true );
|
|
|
|
dim->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
|
|
|
|
dim->SetAutoUnits();
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
2022-01-13 23:30:52 +00:00
|
|
|
BIU pos_x = biuParse( line + SZ( "Po" ), &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data, &data );
|
|
|
|
BIU height = biuParse( data, &data );
|
|
|
|
BIU thickn = biuParse( data, &data );
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE orient = degParse( data, &data );
|
2022-01-13 23:30:52 +00:00
|
|
|
char* mirror = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dim->Text().SetTextPos( VECTOR2I( pos_x, pos_y ) );
|
2021-12-17 17:20:59 +00:00
|
|
|
dim->Text().SetTextSize( wxSize( width, height ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
dim->Text().SetMirrored( mirror && *mirror == '0' );
|
2020-04-14 12:25:00 +00:00
|
|
|
dim->Text().SetTextThickness( thickn );
|
2017-01-23 20:30:11 +00:00
|
|
|
dim->Text().SetTextAngle( orient );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Sb" ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( biuParse( line + SZ( "Sb" ), &data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU crossBarOx = biuParse( data, &data );
|
|
|
|
BIU crossBarOy = biuParse( data, &data );
|
|
|
|
BIU crossBarFx = biuParse( data, &data );
|
|
|
|
BIU crossBarFy = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data );
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
dim->SetLineThickness( width );
|
2022-01-01 17:11:21 +00:00
|
|
|
crossBarO = VECTOR2I( crossBarOx, crossBarOy );
|
|
|
|
crossBarF = VECTOR2I( crossBarFx, crossBarFy );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Sd" ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "Sd" ), &data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU featureLineDOx = biuParse( data, &data );
|
|
|
|
BIU featureLineDOy = biuParse( data, &data );
|
2021-10-05 16:57:25 +00:00
|
|
|
|
|
|
|
ignore_unused( biuParse( data, &data ) );
|
|
|
|
ignore_unused( biuParse( data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dim->SetStart( VECTOR2I( featureLineDOx, featureLineDOy ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
else if( TESTLINE( "Sg" ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "Sg" ), &data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU featureLineGOx = biuParse( data, &data );
|
|
|
|
BIU featureLineGOy = biuParse( data, &data );
|
|
|
|
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( biuParse( data, &data ) );
|
|
|
|
ignore_unused( biuParse( data ) );
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dim->SetEnd( VECTOR2I( featureLineGOx, featureLineGOy ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( TESTLINE( "S1" ) ) // Arrow: no longer imported
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "S1" ), &data ) );
|
2014-03-06 09:43:40 +00:00
|
|
|
biuParse( data, &data ); // skipping excessive data
|
|
|
|
biuParse( data, &data ); // skipping excessive data
|
2020-09-09 03:17:08 +00:00
|
|
|
biuParse( data, &data );
|
|
|
|
biuParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( TESTLINE( "S2" ) ) // Arrow: no longer imported
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "S2" ), &data ) );
|
2014-03-06 09:43:40 +00:00
|
|
|
biuParse( data, &data ); // skipping excessive data
|
|
|
|
biuParse( data, &data ); // skipping excessive data
|
2020-09-09 03:17:08 +00:00
|
|
|
biuParse( data, &data );
|
|
|
|
biuParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( TESTLINE( "S3" ) ) // Arrow: no longer imported
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "S3" ), &data ) );
|
2014-03-06 09:43:40 +00:00
|
|
|
biuParse( data, &data ); // skipping excessive data
|
|
|
|
biuParse( data, &data ); // skipping excessive data
|
2020-09-09 03:17:08 +00:00
|
|
|
biuParse( data, &data );
|
|
|
|
biuParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
else if( TESTLINE( "S4" ) ) // Arrow: no longer imported
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( intParse( line + SZ( "S4" ), &data ) );
|
2014-03-06 09:43:40 +00:00
|
|
|
biuParse( data, &data ); // skipping excessive data
|
|
|
|
biuParse( data, &data ); // skipping excessive data
|
2020-09-09 03:17:08 +00:00
|
|
|
biuParse( data, &data );
|
|
|
|
biuParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$endCOTATION'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPCB_TARGET()
|
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != nullptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "$EndPCB_TARGET" ) || TESTLINE( "$EndMIREPCB" ) )
|
|
|
|
{
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
2021-07-21 23:14:56 +00:00
|
|
|
int shape = intParse( line + SZ( "Po" ), &data );
|
|
|
|
int layer_num = intParse( data, &data );
|
|
|
|
BIU pos_x = biuParse( data, &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
|
|
|
BIU size = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data, &data );
|
|
|
|
char* uuid = strtok_r( (char*) data, delims, (char**) &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer_num < FIRST_NON_COPPER_LAYER )
|
|
|
|
layer_num = FIRST_NON_COPPER_LAYER;
|
|
|
|
else if( layer_num > LAST_NON_COPPER_LAYER )
|
|
|
|
layer_num = LAST_NON_COPPER_LAYER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
PCB_TARGET* t = new PCB_TARGET( m_board, shape, leg_layer2new( m_cu_count, layer_num ),
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I( pos_x, pos_y ), size, width );
|
2019-12-28 00:55:11 +00:00
|
|
|
m_board->Add( t, ADD_MODE::APPEND );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( t->m_Uuid ) = KIID( uuid );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
THROW_IO_ERROR( wxT( "Missing '$EndDIMENSION'" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BIU LEGACY_PLUGIN::biuParse( const char* aValue, const char** nptrptr )
|
|
|
|
{
|
|
|
|
char* nptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
2012-06-24 18:41:37 +00:00
|
|
|
double fval = strtod( aValue, &nptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( errno )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
m_error.Printf( _( "Invalid floating point number in file: '%s'\nline: %d, offset: %d" ),
|
|
|
|
m_reader->GetSource().GetData(),
|
|
|
|
m_reader->LineNumber(),
|
|
|
|
aValue - m_reader->Line() + 1 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aValue == nptr )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
m_error.Printf( _( "Missing floating point number in file: '%s'\nline: %d, offset: %d" ),
|
|
|
|
m_reader->GetSource().GetData(),
|
|
|
|
m_reader->LineNumber(),
|
|
|
|
aValue - m_reader->Line() + 1 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nptrptr )
|
|
|
|
*nptrptr = nptr;
|
|
|
|
|
2012-06-23 23:21:03 +00:00
|
|
|
fval *= diskToBiu;
|
2012-04-08 19:01:54 +00:00
|
|
|
|
2012-06-23 23:21:03 +00:00
|
|
|
// fval is up into the whole number realm here, and should be bounded
|
|
|
|
// within INT_MIN to INT_MAX since BIU's are nanometers.
|
2012-06-25 14:44:47 +00:00
|
|
|
return KiROUND( fval );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE LEGACY_PLUGIN::degParse( const char* aValue, const char** nptrptr )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
char* nptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
double fval = strtod( aValue, &nptr );
|
|
|
|
|
|
|
|
if( errno )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
m_error.Printf( _( "Invalid floating point number in file: '%s'\nline: %d, offset: %d" ),
|
|
|
|
m_reader->GetSource().GetData(),
|
|
|
|
m_reader->LineNumber(),
|
|
|
|
aValue - m_reader->Line() + 1 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aValue == nptr )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
m_error.Printf( _( "Missing floating point number in file: '%s'\nline: %d, offset: %d" ),
|
|
|
|
m_reader->GetSource().GetData(),
|
|
|
|
m_reader->LineNumber(),
|
|
|
|
aValue - m_reader->Line() + 1 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nptrptr )
|
|
|
|
*nptrptr = nptr;
|
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
return EDA_ANGLE( fval, TENTHS_OF_A_DEGREE_T );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void LEGACY_PLUGIN::init( const PROPERTIES* aProperties )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2015-02-28 20:50:35 +00:00
|
|
|
m_loading_format_version = 0;
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_count = 16;
|
2021-07-19 23:56:05 +00:00
|
|
|
m_board = nullptr;
|
2022-02-11 12:42:09 +00:00
|
|
|
m_showLegacySegmentZoneWarning = true;
|
2012-04-07 18:05:56 +00:00
|
|
|
m_props = aProperties;
|
|
|
|
|
|
|
|
// conversion factor for saving RAM BIUs to KICAD legacy file format.
|
2022-09-17 00:45:14 +00:00
|
|
|
biuToDisk = 1.0 / pcbIUScale.IU_PER_MM; // BIUs are nanometers & file is mm
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-06-24 18:41:37 +00:00
|
|
|
// Conversion factor for loading KICAD legacy file format into BIUs in RAM
|
2012-04-07 18:05:56 +00:00
|
|
|
// Start by assuming the *.brd file is in deci-mils.
|
2012-06-24 18:41:37 +00:00
|
|
|
// If we see "Units mm" in the $GENERAL section, set diskToBiu to 1000000.0
|
2012-04-07 18:05:56 +00:00
|
|
|
// then, during the file loading process, to start a conversion from
|
2012-06-24 18:41:37 +00:00
|
|
|
// mm to nanometers. The deci-mil legacy files have no such "Units" marker
|
|
|
|
// so we must assume the file is in deci-mils until told otherwise.
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
diskToBiu = pcbIUScale.IU_PER_MILS / 10; // BIUs are nanometers
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
//-----<FOOTPRINT LIBRARY FUNCTIONS>--------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
The legacy file format is being obsoleted and this code will have a short
|
|
|
|
lifetime, so it only needs to be good enough for a short duration of time.
|
|
|
|
Caching all the MODULEs is a bit memory intensive, but it is a considerably
|
|
|
|
faster way of fulfilling the API contract. Otherwise, without the cache, you
|
2020-11-13 21:07:01 +00:00
|
|
|
would have to re-read the file when searching for any FOOTPRINT, and this would
|
2012-04-16 03:18:41 +00:00
|
|
|
be very problematic filling a FOOTPRINT_LIST via this PLUGIN API. If memory
|
|
|
|
becomes a concern, consider the cache lifetime policy, which determines the
|
2013-09-22 04:38:22 +00:00
|
|
|
time that a LP_CACHE is in RAM. Note PLUGIN lifetime also plays a role in
|
2012-04-16 03:18:41 +00:00
|
|
|
cache lifetime.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/ptr_container/ptr_map.hpp>
|
2012-04-17 03:12:53 +00:00
|
|
|
#include <wx/filename.h>
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
typedef boost::ptr_map< std::string, FOOTPRINT > FOOTPRINT_MAP;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* The footprint portion of the PLUGIN API, and only for the LEGACY_PLUGIN, so therefore is
|
|
|
|
* private to this implementation file, i.e. not placed into a header.
|
2012-04-16 03:18:41 +00:00
|
|
|
*/
|
2013-09-22 04:38:22 +00:00
|
|
|
struct LP_CACHE
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2013-09-22 04:38:22 +00:00
|
|
|
LP_CACHE( LEGACY_PLUGIN* aOwner, const wxString& aLibraryPath );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +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.
|
2012-04-16 03:18:41 +00:00
|
|
|
// Catch these exceptions higher up please.
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
void Load();
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
void ReadAndVerifyHeader( LINE_READER* aReader );
|
|
|
|
|
|
|
|
void SkipIndex( LINE_READER* aReader );
|
|
|
|
|
|
|
|
void LoadModules( LINE_READER* aReader );
|
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
bool IsModified();
|
|
|
|
static long long GetTimestamp( const wxString& aLibPath );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
LEGACY_PLUGIN* m_owner; // my owner, I need its LEGACY_PLUGIN::loadFOOTPRINT()
|
|
|
|
wxString m_lib_path;
|
|
|
|
FOOTPRINT_MAP m_footprints; // map or tuple of footprint_name vs. FOOTPRINT*
|
|
|
|
bool m_writable;
|
|
|
|
|
|
|
|
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-04-16 03:18:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
LP_CACHE::LP_CACHE( LEGACY_PLUGIN* aOwner, const wxString& aLibraryPath ) :
|
2012-04-16 03:18:41 +00:00
|
|
|
m_owner( aOwner ),
|
2013-01-02 04:05:48 +00:00
|
|
|
m_lib_path( aLibraryPath ),
|
2018-08-03 16:53:38 +00:00
|
|
|
m_writable( true ),
|
2018-08-04 14:45:12 +00:00
|
|
|
m_cache_dirty( true ),
|
|
|
|
m_cache_timestamp( 0 )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
bool LP_CACHE::IsModified()
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_dirty = m_cache_dirty || GetTimestamp( m_lib_path ) != m_cache_timestamp;
|
|
|
|
|
|
|
|
return m_cache_dirty;
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
|
2018-08-03 16:53:38 +00:00
|
|
|
long long LP_CACHE::GetTimestamp( const wxString& aLibPath )
|
|
|
|
{
|
|
|
|
return wxFileName( aLibPath ).GetModificationTime().GetValue().GetValue();
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::Load()
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_dirty = false;
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
FILE_LINE_READER reader( m_lib_path );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
ReadAndVerifyHeader( &reader );
|
|
|
|
SkipIndex( &reader );
|
|
|
|
LoadModules( &reader );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
// Remember the file modification time of library file when the
|
|
|
|
// cache snapshot was made, so that in a networked environment we will
|
|
|
|
// reload the cache as needed.
|
2018-08-03 16:53:38 +00:00
|
|
|
m_cache_timestamp = GetTimestamp( m_lib_path );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line = aReader->ReadLine();
|
2020-02-20 12:11:04 +00:00
|
|
|
char* data;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
if( !line )
|
2019-08-31 14:18:27 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "File '%s' is empty." ), m_lib_path ) );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
if( !TESTLINE( "PCBNEW-LibModule-V1" ) )
|
2019-08-31 14:18:27 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "File '%s' is not a legacy library." ), m_lib_path ) );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = aReader->ReadLine() ) != nullptr )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( TESTLINE( "Units" ) )
|
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
const char* units = strtok_r( line + SZ( "Units" ), delims, &data );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !strcmp( units, "mm" ) )
|
2022-09-17 00:45:14 +00:00
|
|
|
m_owner->diskToBiu = pcbIUScale.IU_PER_MM;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$INDEX" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
return;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::SkipIndex( LINE_READER* aReader )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
// Some broken INDEX sections have more than one section, due to prior bugs.
|
|
|
|
// So we must read the next line after $EndINDEX tag,
|
|
|
|
// to see if this is not a new $INDEX tag.
|
2012-11-27 13:50:01 +00:00
|
|
|
bool exit = false;
|
|
|
|
char* line = aReader->Line();
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
do
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "$INDEX" ) )
|
|
|
|
{
|
|
|
|
exit = false;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
while( ( line = aReader->ReadLine() ) != nullptr )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "$EndINDEX" ) )
|
|
|
|
{
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( exit )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-04-16 03:18:41 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
|
|
|
} while( ( line = aReader->ReadLine() ) != nullptr );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::LoadModules( LINE_READER* aReader )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
m_owner->SetReader( aReader );
|
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line = aReader->Line();
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
// test first for the $MODULE, even before reading because of INDEX bug.
|
|
|
|
if( TESTLINE( "$MODULE" ) )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::unique_ptr<FOOTPRINT> fp_ptr = std::make_unique<FOOTPRINT>( m_owner->m_board );
|
2013-06-13 16:09:35 +00:00
|
|
|
|
|
|
|
std::string footprintName = StrPurge( line + SZ( "$MODULE" ) );
|
|
|
|
|
2013-11-29 18:29:41 +00:00
|
|
|
// The footprint names in legacy libraries can contain the '/' and ':'
|
2016-11-20 23:35:08 +00:00
|
|
|
// characters which will cause the LIB_ID parser to choke.
|
2013-11-29 18:29:41 +00:00
|
|
|
ReplaceIllegalFileNameChars( &footprintName );
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
// set the footprint name first thing, so exceptions can use name.
|
2020-11-13 15:15:52 +00:00
|
|
|
fp_ptr->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_owner->loadFOOTPRINT( fp_ptr.get());
|
2013-06-13 16:09:35 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* fp = fp_ptr.release(); // exceptions after this are not expected.
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
// Not sure why this is asserting on debug builds. The debugger shows the
|
|
|
|
// strings are the same. If it's not really needed maybe it can be removed.
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-05-09 00:26:15 +00:00
|
|
|
/*
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-05-09 00:26:15 +00:00
|
|
|
There was a bug in old legacy library management code
|
|
|
|
(pre-LEGACY_PLUGIN) which was introducing duplicate footprint names
|
|
|
|
in legacy libraries without notification. To best recover from such
|
|
|
|
bad libraries, and use them to their fullest, there are a few
|
|
|
|
strategies that could be used. (Note: footprints must have unique
|
|
|
|
names to be accepted into this cache.) The strategy used here is to
|
|
|
|
append a differentiating version counter to the end of the name as:
|
|
|
|
_v2, _v3, etc.
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-05-09 00:26:15 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT_MAP::const_iterator it = m_footprints.find( footprintName );
|
2012-05-09 00:26:15 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( it == m_footprints.end() ) // footprintName is not present in cache yet.
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2020-11-14 19:16:42 +00:00
|
|
|
if( !m_footprints.insert( footprintName, fp ).second )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "error doing cache insert using guaranteed unique name" ) );
|
2020-11-14 19:16:42 +00:00
|
|
|
}
|
2012-05-09 00:26:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
// Bad library has a duplicate of this footprintName, generate a
|
|
|
|
// unique footprint name and load it anyway.
|
2012-05-09 00:26:15 +00:00
|
|
|
bool nameOK = false;
|
|
|
|
int version = 2;
|
2012-05-20 13:14:46 +00:00
|
|
|
char buf[48];
|
2012-05-09 00:26:15 +00:00
|
|
|
|
|
|
|
while( !nameOK )
|
|
|
|
{
|
2012-05-20 13:14:46 +00:00
|
|
|
std::string newName = footprintName;
|
|
|
|
|
|
|
|
newName += "_v";
|
|
|
|
sprintf( buf, "%d", version++ );
|
|
|
|
newName += buf;
|
2012-05-09 00:26:15 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
it = m_footprints.find( newName );
|
2012-05-09 00:26:15 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( it == m_footprints.end() )
|
2012-05-09 00:26:15 +00:00
|
|
|
{
|
|
|
|
nameOK = true;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
fp->SetFPID( LIB_ID( wxEmptyString, newName ) );
|
2012-05-09 00:26:15 +00:00
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
if( !m_footprints.insert( newName, fp ).second )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxFAIL_MSG( wxT( "error doing cache insert using guaranteed unique "
|
|
|
|
"name" ) );
|
2020-11-14 19:16:42 +00:00
|
|
|
}
|
2012-05-09 00:26:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
} while( ( line = aReader->ReadLine() ) != nullptr );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-04 01:13:09 +00:00
|
|
|
long long LEGACY_PLUGIN::GetLibraryTimestamp( const wxString& aLibraryPath ) const
|
2018-03-02 20:41:37 +00:00
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
return LP_CACHE::GetTimestamp( aLibraryPath );
|
2018-03-02 20:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath )
|
|
|
|
{
|
2018-08-03 16:53:38 +00:00
|
|
|
if( !m_cache || m_cache->m_lib_path != aLibraryPath || m_cache->IsModified() )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
// a spectacular episode in memory management:
|
2012-04-16 03:18:41 +00:00
|
|
|
delete m_cache;
|
2013-09-22 04:38:22 +00:00
|
|
|
m_cache = new LP_CACHE( this, aLibraryPath );
|
2012-04-17 01:35:43 +00:00
|
|
|
m_cache->Load();
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
|
|
|
|
bool aBestEfforts, const PROPERTIES* aProperties )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2019-08-31 14:18:27 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
wxString errorMsg;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
2019-08-31 14:18:27 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cacheLib( aLibPath );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
errorMsg = ioe.What();
|
|
|
|
}
|
2012-04-16 03:18:41 +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-04-16 03:18:41 +00:00
|
|
|
|
2020-11-14 19:16:42 +00:00
|
|
|
for( const auto& footprint : m_cache->m_footprints )
|
|
|
|
aFootprintNames.Add( FROM_UTF8( footprint.first.c_str() ) );
|
2019-08-31 14:18:27 +00:00
|
|
|
|
|
|
|
if( !errorMsg.IsEmpty() && !aBestEfforts )
|
|
|
|
THROW_IO_ERROR( errorMsg );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
|
2021-07-19 23:56:05 +00:00
|
|
|
const wxString& aFootprintName, bool aKeepUUID,
|
2020-11-13 15:15:52 +00:00
|
|
|
const PROPERTIES* aProperties )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT_MAP& footprints = m_cache->m_footprints;
|
2020-11-14 19:16:42 +00:00
|
|
|
FOOTPRINT_MAP::const_iterator it = footprints.find( TO_UTF8( aFootprintName ) );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( it == footprints.end() )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 21:07:01 +00:00
|
|
|
// Return copy of already loaded FOOTPRINT
|
2020-12-04 12:14:07 +00:00
|
|
|
FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate();
|
|
|
|
copy->SetParent( nullptr );
|
|
|
|
return copy;
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-04 12:13:11 +00:00
|
|
|
bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath,
|
|
|
|
const PROPERTIES* aProperties )
|
2012-04-17 01:35:43 +00:00
|
|
|
{
|
|
|
|
wxFileName fn = aLibraryPath;
|
|
|
|
|
|
|
|
if( !fn.FileExists() )
|
2012-11-19 16:19:38 +00:00
|
|
|
return false;
|
2012-04-17 01:35:43 +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( wxRemove( aLibraryPath ) )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' cannot be deleted." ),
|
2020-12-04 12:13:11 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
2012-05-05 04:55:36 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
if( m_cache && m_cache->m_lib_path == aLibraryPath )
|
2012-05-05 04:55:36 +00:00
|
|
|
{
|
|
|
|
delete m_cache;
|
2021-04-22 21:20:34 +00:00
|
|
|
m_cache = nullptr;
|
2012-05-05 04:55:36 +00:00
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
return true;
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LEGACY_PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
#if 0 // no support for 32 Cu layers in legacy format
|
|
|
|
return false;
|
|
|
|
#else
|
2012-04-17 01:35:43 +00:00
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
init( nullptr );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
|
|
|
return m_cache->m_writable;
|
2014-06-24 16:17:18 +00:00
|
|
|
#endif
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
LEGACY_PLUGIN::LEGACY_PLUGIN() :
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_count( 16 ), // for FootprintLoad()
|
2020-02-20 12:11:04 +00:00
|
|
|
m_board( nullptr ),
|
|
|
|
m_props( nullptr ),
|
2021-06-23 22:53:08 +00:00
|
|
|
m_progressReporter( nullptr ),
|
|
|
|
m_lastProgressLine( 0 ),
|
|
|
|
m_lineCount( 0 ),
|
2020-02-20 12:11:04 +00:00
|
|
|
m_reader( nullptr ),
|
|
|
|
m_fp( nullptr ),
|
2021-05-15 12:02:27 +00:00
|
|
|
m_cache( nullptr )
|
2012-04-17 06:13:22 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
init( nullptr );
|
2012-04-17 06:13:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
LEGACY_PLUGIN::~LEGACY_PLUGIN()
|
|
|
|
{
|
|
|
|
delete m_cache;
|
|
|
|
}
|