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>
|
2012-07-13 18:55:29 +00:00
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras@wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see change_log.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).
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-09-21 17:02:54 +00:00
|
|
|
#include <cmath>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2012-12-14 18:14:28 +00:00
|
|
|
#include <wx/ffile.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
#include <legacy_plugin.h> // implement this here
|
|
|
|
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <zones.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_pcb_text.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_dimension.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_mire.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <3d_struct.h>
|
|
|
|
#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 <drawtxt.h>
|
2012-04-11 09:47:57 +00:00
|
|
|
#include <convert_to_biu.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <trigo.h>
|
2012-12-14 18:14:28 +00:00
|
|
|
#include <build_version.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-05-20 09:29:37 +00:00
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
typedef LEGACY_PLUGIN::BIU BIU;
|
|
|
|
|
|
|
|
|
2014-01-19 13:12:57 +00:00
|
|
|
#define VERSION_ERROR_FORMAT _( "File '%s' is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file." )
|
2012-04-07 18:05:56 +00:00
|
|
|
#define UNKNOWN_GRAPHIC_FORMAT _( "unknown graphic type: %d")
|
|
|
|
#define UNKNOWN_PAD_FORMAT _( "unknown pad type: %d")
|
|
|
|
#define UNKNOWN_PAD_ATTRIBUTE _( "unknown pad attribute: %d" )
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
|
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 NB_COPPER_LAYERS (LAST_COPPER_LAYER - FIRST_COPPER_LAYER + 1)
|
|
|
|
|
|
|
|
#define FIRST_NON_COPPER_LAYER 16
|
|
|
|
#define FIRST_TECHNICAL_LAYER 16
|
|
|
|
#define FIRST_USER_LAYER 24
|
|
|
|
#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
|
|
|
|
#define LAST_TECHNICAL_LAYER 23
|
|
|
|
#define LAST_USER_LAYER 27
|
|
|
|
#define NB_PCB_LAYERS (LAST_NON_COPPER_LAYER + 1)
|
|
|
|
#define UNUSED_LAYER_29 29
|
|
|
|
#define UNUSED_LAYER_30 30
|
|
|
|
#define UNUSED_LAYER_31 31
|
|
|
|
#define NB_GERBER_LAYERS 32
|
|
|
|
#define NB_LAYERS 32
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
// extra bits 0xE0000000
|
|
|
|
|
|
|
|
// Helpful global layer masks:
|
|
|
|
// ALL_AUX_LAYERS layers are technical layers, ALL_NO_CU_LAYERS has user
|
|
|
|
// and edge layers too!
|
|
|
|
#define ALL_LAYERS 0x1FFFFFFF // Pcbnew used 29 layers
|
|
|
|
#define FULL_LAYERS 0xFFFFFFFF // Gerbview used 32 layers
|
|
|
|
#define ALL_NO_CU_LAYERS 0x1FFF0000
|
|
|
|
#define ALL_CU_LAYERS 0x0000FFFF
|
|
|
|
#define INTERNAL_CU_LAYERS 0x00007FFE
|
|
|
|
#define EXTERNAL_CU_LAYERS 0x00008001
|
|
|
|
#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";
|
|
|
|
|
|
|
|
|
|
|
|
static bool inline isSpace( int c ) { return strchr( delims, c ) != 0; }
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#define MASK(x) (1<<(x))
|
2012-07-07 18:27:44 +00:00
|
|
|
|
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.
|
2012-07-07 18:27:44 +00:00
|
|
|
#define TESTLINE( x ) ( !strnicmp( 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.
|
|
|
|
#define TESTSUBSTR( x ) ( !strnicmp( line, x, SZ( x ) ) )
|
|
|
|
|
|
|
|
|
|
|
|
#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();
|
|
|
|
printf( "%-6u %s: %s", rdr->LineNumber(), caller, 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
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
/* corrected old junk, element 14 was wrong. can delete.
|
|
|
|
// Look up Table for conversion copper layer count -> general copper layer mask:
|
2014-06-25 04:36:02 +00:00
|
|
|
static const LEG_MASK all_cu_mask[] = {
|
2014-06-24 16:17:18 +00:00
|
|
|
0x0001, 0x8001, 0x8003, 0x8007,
|
|
|
|
0x800F, 0x801F, 0x803F, 0x807F,
|
|
|
|
0x80FF, 0x81FF, 0x83FF, 0x87FF,
|
|
|
|
0x8FFF, 0x9FFF, 0xBFFF, 0xFFFF
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-11-15 16:04:10 +00:00
|
|
|
using namespace std; // auto_ptr
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
|
|
|
|
static inline const char* ShowVertJustify( EDA_TEXT_VJUSTIFY_T vertical )
|
|
|
|
{
|
|
|
|
const char* rs;
|
|
|
|
switch( vertical )
|
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP: rs = "T"; break;
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER: rs = "C"; break;
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM: rs = "B"; break;
|
|
|
|
default: rs = "?"; break;
|
|
|
|
}
|
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char* ShowHorizJustify( EDA_TEXT_HJUSTIFY_T horizontal )
|
|
|
|
{
|
|
|
|
const char* rs;
|
|
|
|
switch( horizontal )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT: rs = "L"; break;
|
|
|
|
case GR_TEXT_HJUSTIFY_CENTER: rs = "C"; break;
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT: rs = "R"; break;
|
|
|
|
default: rs = "?"; break;
|
|
|
|
}
|
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
static EDA_TEXT_HJUSTIFY_T horizJustify( const char* horizontal )
|
2012-08-11 19:14:45 +00:00
|
|
|
{
|
|
|
|
if( !strcmp( "L", horizontal ) )
|
|
|
|
return GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
if( !strcmp( "R", horizontal ) )
|
|
|
|
return GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
return GR_TEXT_HJUSTIFY_CENTER;
|
|
|
|
}
|
|
|
|
|
2012-08-15 17:55:48 +00:00
|
|
|
static EDA_TEXT_VJUSTIFY_T vertJustify( const char* vertical )
|
2012-08-11 19:14:45 +00:00
|
|
|
{
|
|
|
|
if( !strcmp( "T", vertical ) )
|
|
|
|
return GR_TEXT_VJUSTIFY_TOP;
|
|
|
|
if( !strcmp( "B", vertical ) )
|
|
|
|
return GR_TEXT_VJUSTIFY_BOTTOM;
|
|
|
|
return GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LAYER_ID LEGACY_PLUGIN::leg_layer2new( int cu_count, LAYER_NUM aLayerNum )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
if( old == LAYER_N_FRONT )
|
|
|
|
newid = F_Cu;
|
2014-06-25 04:36:02 +00:00
|
|
|
else if( old == LAYER_N_BACK )
|
|
|
|
newid = B_Cu;
|
2014-06-24 16:17:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
newid = cu_count - 1 - old;
|
|
|
|
|
|
|
|
wxASSERT( newid >= 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
wxASSERT( 0 );
|
|
|
|
newid = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LAYER_ID( newid );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Function intParse
|
|
|
|
* parses an ASCII integer string with possible leading whitespace into
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static inline int intParse( const char* next, const char** out = NULL )
|
|
|
|
{
|
|
|
|
// please just compile this and be quiet, hide casting ugliness:
|
|
|
|
return (int) strtol( next, (char**) out, 10 );
|
|
|
|
}
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
/**
|
|
|
|
* Function layerParse
|
|
|
|
* Like intParse but returns a LAYER_NUM
|
|
|
|
*/
|
|
|
|
static inline LAYER_NUM layerParse( const char* next, const char** out = NULL )
|
|
|
|
{
|
|
|
|
return intParse( next, out );
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function hexParse
|
|
|
|
* parses an ASCII hex integer string with possible leading whitespace into
|
|
|
|
* a long 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.
|
|
|
|
*/
|
|
|
|
static inline long hexParse( const char* next, const char** out = NULL )
|
|
|
|
{
|
|
|
|
// please just compile this and be quiet, hide casting ugliness:
|
|
|
|
return strtol( next, (char**) out, 16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
BOARD* LEGACY_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
|
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 );
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
m_board = aAppendToMe ? aAppendToMe : new BOARD();
|
|
|
|
|
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-04-07 18:05:56 +00:00
|
|
|
// delete on exception, iff I own m_board, according to aAppendToMe
|
2012-11-15 16:04:10 +00:00
|
|
|
auto_ptr<BOARD> deleter( aAppendToMe ? NULL : m_board );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 14:14:15 +00:00
|
|
|
FILE_LINE_READER reader( aFileName );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
m_reader = &reader; // member function accessibility
|
|
|
|
|
|
|
|
checkVersion();
|
|
|
|
|
|
|
|
loadAllSections( bool( aAppendToMe ) );
|
|
|
|
|
|
|
|
deleter.release();
|
|
|
|
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
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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" ) )
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
auto_ptr<MODULE> module( new MODULE( m_board ) );
|
2013-06-27 21:34:01 +00:00
|
|
|
|
2013-09-17 15:51:05 +00:00
|
|
|
FPID 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() )
|
|
|
|
fpid = FPID( fpName );
|
|
|
|
|
|
|
|
module->SetFPID( fpid );
|
2013-06-27 21:34:01 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
loadMODULE( module.get() );
|
2013-06-13 16:09:35 +00:00
|
|
|
m_board->Add( module.release(), ADD_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" ) )
|
|
|
|
{
|
2012-06-10 00:39:40 +00:00
|
|
|
loadTrackList( PCB_ZONE_T );
|
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
|
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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" ) )
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndBOARD'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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" ) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Unknown file type" );
|
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2012-05-13 15:31:58 +00:00
|
|
|
// "File '%s' is format version: %d.\nI only support format version <= %d.\nPlease upgrade Pcbnew to load this file."
|
2012-04-08 19:01:54 +00:00
|
|
|
m_error.Printf( VERSION_ERROR_FORMAT,
|
|
|
|
m_reader->GetSource().GetData(), ver, LEGACY_BOARD_FILE_VERSION );
|
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
|
|
|
|
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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" ) )
|
|
|
|
{
|
2012-06-19 19:25:41 +00:00
|
|
|
diskToBiu = 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" ) );
|
|
|
|
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 )
|
|
|
|
THROW_IO_ERROR( "Missing '$GENERAL's LayerCount" );
|
|
|
|
|
|
|
|
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-25 04:36:02 +00:00
|
|
|
//DBG( printf( "EnabledLayers: %s\n", new_mask.FmtHex().c_str() );)
|
|
|
|
|
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 );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "VisibleLayers" ) )
|
|
|
|
{
|
2014-06-25 04:36:02 +00:00
|
|
|
if( !saw_LayerCount )
|
|
|
|
THROW_IO_ERROR( "Missing '$GENERAL's LayerCount" );
|
|
|
|
|
|
|
|
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 );
|
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 );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
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( "Links" ) )
|
|
|
|
{
|
|
|
|
// Info only, do nothing, but only for a short while.
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if( TESTLINE( "NoConn" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( "NoConn" ) );
|
2013-01-09 18:52:44 +00:00
|
|
|
m_board->SetUnconnectedNetCount( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Di" ) )
|
|
|
|
{
|
|
|
|
BIU x1 = biuParse( line + SZ( "Di" ), &data );
|
|
|
|
BIU y1 = biuParse( data, &data );
|
|
|
|
BIU x2 = biuParse( data, &data );
|
|
|
|
BIU y2 = biuParse( data );
|
|
|
|
|
|
|
|
EDA_RECT bbbox( wxPoint( x1, y1 ), wxSize( x2-x1, y2-y1 ) );
|
|
|
|
|
|
|
|
m_board->SetBoundingBox( bbbox );
|
|
|
|
}
|
|
|
|
|
2014-06-06 10:30:07 +00:00
|
|
|
/* This is no more usefull, so this info is no more parsed
|
|
|
|
// Read the number of segments of type DRAW, TRACK, ZONE
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "Ndraw" ) )
|
|
|
|
{
|
|
|
|
NbDraw = intParse( line + SZ( "Ndraw" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Ntrack" ) )
|
|
|
|
{
|
|
|
|
NbTrack = intParse( line + SZ( "Ntrack" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Nzone" ) )
|
|
|
|
{
|
|
|
|
NbZone = intParse( line + SZ( "Nzone" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Nmodule" ) )
|
|
|
|
{
|
|
|
|
NbMod = intParse( line + SZ( "Nmodule" ) );
|
2014-06-02 09:41:54 +00:00
|
|
|
}*/
|
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" ) )
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndGENERAL'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadSHEET()
|
|
|
|
{
|
|
|
|
char buf[260];
|
|
|
|
TITLE_BLOCK tb;
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* sname = strtok_r( line + SZ( "Sheet" ), delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( sname )
|
|
|
|
{
|
|
|
|
wxString wname = FROM_UTF8( sname );
|
|
|
|
if( !page.SetType( wname ) )
|
|
|
|
{
|
|
|
|
m_error.Printf( _( "Unknown sheet type '%s' on line:%d" ),
|
|
|
|
wname.GetData(), m_reader->LineNumber() );
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
char* width = strtok_r( NULL, delims, &saveptr );
|
|
|
|
char* height = strtok_r( NULL, delims, &saveptr );
|
|
|
|
char* orient = strtok_r( NULL, delims, &saveptr );
|
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) );
|
|
|
|
tb.SetComment1( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Comment2" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment2( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Comment3" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment3( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Comment4" ) )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, line, sizeof(buf) );
|
|
|
|
tb.SetComment4( FROM_UTF8( buf ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndSHEETDESCR" ) )
|
|
|
|
{
|
|
|
|
m_board->SetTitleBlock( tb );
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndSHEETDESCR'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadSETUP()
|
|
|
|
{
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR netclass_default = m_board->GetDesignSettings().GetDefault();
|
2014-05-13 09:22:51 +00:00
|
|
|
// TODO Orson: is it really necessary to first operate on a copy and then apply it?
|
|
|
|
// would not it be better to use reference here and apply all the changes instantly?
|
2012-04-07 18:05:56 +00:00
|
|
|
BOARD_DESIGN_SETTINGS bds = m_board->GetDesignSettings();
|
|
|
|
ZONE_SETTINGS zs = m_board->GetZoneSettings();
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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 );
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// m_board->SetAuxOrigin( wxPoint( gx, gy ) ); gets overwritten by SetDesignSettings() below
|
|
|
|
bds.m_AuxOrigin = wxPoint( gx, gy );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 04:36:02 +00:00
|
|
|
/* Done from $General above's "LayerCount"
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "Layers" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( "Layers" ) );
|
|
|
|
m_board->SetCopperLayerCount( tmp );
|
2014-06-25 04:36:02 +00:00
|
|
|
|
|
|
|
m_cu_count = tmp;
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2014-06-25 04:36:02 +00:00
|
|
|
*/
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
else if( TESTSUBSTR( "Layer[" ) )
|
|
|
|
{
|
|
|
|
// eg: "Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>"
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM layer_num = layerParse( line + SZ( "Layer[" ), &data );
|
2014-06-25 04:36:02 +00:00
|
|
|
LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
|
|
|
|
|
|
|
|
/*
|
|
|
|
switch( layer_num )
|
|
|
|
{
|
|
|
|
case LAYER_N_BACK:
|
|
|
|
layer_id = B_Cu;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_N_FRONT:
|
|
|
|
layer_id = F_Cu;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
layer_id = LAYER_ID( layer_num );
|
|
|
|
}
|
|
|
|
*/
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data+1, delims, &saveptr ); // +1 for ']'
|
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
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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" ) );
|
|
|
|
netclass_default->SetClearance( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "TrackMinWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TrackMinWidth" ) );
|
|
|
|
bds.m_TrackMinWidth = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "ZoneClearence" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ZoneClearence" ) );
|
|
|
|
zs.m_ZoneClearance = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Zone_45_Only" ) )
|
|
|
|
{
|
|
|
|
bool tmp = (bool) intParse( line + SZ( "Zone_45_Only" ) );
|
|
|
|
zs.m_Zone_45_Only = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "DrawSegmWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "DrawSegmWidth" ) );
|
|
|
|
bds.m_DrawSegmentWidth = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "EdgeSegmWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "EdgeSegmWidth" ) );
|
|
|
|
bds.m_EdgeSegmentWidth = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
if( data ) // DRILL may not be present ?
|
|
|
|
drill = biuParse( data );
|
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
bds.m_ViasDimensionsList.push_back( VIA_DIMENSION( diameter,
|
|
|
|
drill ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "ViaDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaDrill" ) );
|
|
|
|
netclass_default->SetViaDrill( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "ViaMinDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "ViaMinDrill" ) );
|
|
|
|
bds.m_ViasMinDrill = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "MicroViaDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "MicroViaDrill" ) );
|
|
|
|
netclass_default->SetuViaDrill( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "MicroViaMinDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "MicroViaMinDrill" ) );
|
|
|
|
bds.m_MicroViasMinDrill = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "MicroViasAllowed" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( "MicroViasAllowed" ) );
|
|
|
|
bds.m_MicroViasAllowed = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "TextPcbWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TextPcbWidth" ) );
|
|
|
|
bds.m_PcbTextWidth = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "TextPcbSize" ) )
|
|
|
|
{
|
|
|
|
BIU x = biuParse( line + SZ( "TextPcbSize" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
|
|
|
bds.m_PcbTextSize = wxSize( x, y );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "EdgeModWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "EdgeModWidth" ) );
|
|
|
|
bds.m_ModuleSegmentWidth = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "TextModWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "TextModWidth" ) );
|
|
|
|
bds.m_ModuleTextWidth = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "TextModSize" ) )
|
|
|
|
{
|
|
|
|
BIU x = biuParse( line + SZ( "TextModSize" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
|
|
|
bds.m_ModuleTextSize = wxSize( x, y );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "PadSize" ) )
|
|
|
|
{
|
|
|
|
BIU x = biuParse( line + SZ( "PadSize" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
|
|
|
bds.m_Pad_Master.SetSize( wxSize( x, y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "PadDrill" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "PadDrill" ) );
|
|
|
|
bds.m_Pad_Master.SetDrillSize( wxSize( tmp, tmp ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Pad2MaskClearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( "Pad2MaskClearance" ) );
|
|
|
|
bds.m_SolderMaskMargin = tmp;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten by SetDesignSettings() below
|
|
|
|
bds.m_GridOrigin = wxPoint( x, y );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "VisibleElements" ) )
|
|
|
|
{
|
|
|
|
int visibleElements = hexParse( line + SZ( "VisibleElements" ) );
|
|
|
|
bds.SetVisibleElements( visibleElements );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndSETUP" ) )
|
|
|
|
{
|
|
|
|
m_board->SetDesignSettings( bds );
|
|
|
|
m_board->SetZoneSettings( zs );
|
|
|
|
|
|
|
|
// Until such time as the *.brd file does not have the
|
|
|
|
// global parameters:
|
|
|
|
// "TrackWidth", "TrackMinWidth", "ViaSize", "ViaDrill",
|
|
|
|
// "ViaMinSize", and "TrackClearence", put those same global
|
|
|
|
// values 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, old boards will not.
|
|
|
|
//
|
|
|
|
// @todo: I expect that at some point we can remove said global
|
|
|
|
// parameters from the *.brd file since the ones in the
|
|
|
|
// default netclass serve the same purpose. If needed
|
|
|
|
// at all, the global defaults should go into a preferences
|
|
|
|
// file instead so they are there to start new board
|
|
|
|
// projects.
|
2014-05-15 08:51:08 +00:00
|
|
|
m_board->GetDesignSettings().GetDefault()->SetParams( m_board->GetDesignSettings() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo: this code is currently unreachable, would need a goto, to get here.
|
|
|
|
// that may be better handled with an #ifdef
|
|
|
|
|
|
|
|
/* Ensure tracks and vias sizes lists are ok:
|
|
|
|
* Sort lists by by increasing value and remove duplicates
|
|
|
|
* (the first value is not tested, because it is the netclass value
|
|
|
|
*/
|
2014-05-13 09:22:51 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& designSettings = m_board->GetDesignSettings();
|
|
|
|
sort( designSettings.m_ViasDimensionsList.begin() + 1, designSettings.m_ViasDimensionsList.end() );
|
|
|
|
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--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
void LEGACY_PLUGIN::loadMODULE( MODULE* aModule )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
loadMODULE_EDGE( aModule );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$PAD" ) )
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
loadPAD( aModule );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read a footprint text description (ref, value, or drawing)
|
|
|
|
else if( TESTSUBSTR( "T" ) )
|
|
|
|
{
|
|
|
|
// e.g. "T1 6940 -16220 350 300 900 60 M I 20 N "CFCARD"\r\n"
|
|
|
|
|
|
|
|
int tnum = intParse( line + SZ( "T" ) );
|
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
TEXTE_MODULE* textm = 0;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
switch( tnum )
|
|
|
|
{
|
|
|
|
case TEXTE_MODULE::TEXT_is_REFERENCE:
|
2013-06-13 16:09:35 +00:00
|
|
|
textm = &aModule->Reference();
|
2013-04-07 11:55:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TEXTE_MODULE::TEXT_is_VALUE:
|
2013-06-13 16:09:35 +00:00
|
|
|
textm = &aModule->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:
|
2013-06-13 16:09:35 +00:00
|
|
|
textm = new TEXTE_MODULE( aModule );
|
|
|
|
aModule->GraphicalItems().PushBack( textm );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
loadMODULE_TEXT( textm );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
|
|
|
// e.g. "Po 19120 39260 900 0 4E823D06 46EAAFA5 ~~\r\n"
|
|
|
|
|
|
|
|
// sscanf( PtLine, "%d %d %d %d %lX %lX %s", &m_Pos.x, &m_Pos.y, &m_Orient, &m_Layer, &m_LastEdit_Time, &m_TimeStamp, BufCar1 );
|
|
|
|
|
|
|
|
BIU pos_x = biuParse( line + SZ( "Po" ), &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
|
|
|
int orient = intParse( data, &data );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
LAYER_NUM layer_num = layerParse( data, &data );
|
|
|
|
LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
long edittime = hexParse( data, &data );
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp = hexParse( data, &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data+1, delims, &saveptr );
|
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' )
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetLocked( true );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-05-25 06:58:52 +00:00
|
|
|
if( data && data[1] == 'P' )
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetIsPlaced( true );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetPosition( wxPoint( pos_x, pos_y ) );
|
2014-06-24 16:17:18 +00:00
|
|
|
aModule->SetLayer( layer_id );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetOrientation( orient );
|
|
|
|
aModule->SetTimeStamp( timestamp );
|
|
|
|
aModule->SetLastEditTime( edittime );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 21:34:01 +00:00
|
|
|
/* footprint name set earlier, immediately after MODULE construction
|
2012-04-07 18:05:56 +00:00
|
|
|
else if( TESTLINE( "Li" ) ) // Library name of footprint
|
|
|
|
{
|
2012-05-09 00:26:15 +00:00
|
|
|
// There can be whitespace in the footprint name on some old libraries.
|
|
|
|
// Grab everything after "Li" up to end of line:
|
2013-09-08 18:31:21 +00:00
|
|
|
//aModule->SetFPID( FROM_UTF8( StrPurge( line + SZ( "Li" ) ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2013-06-27 21:34:01 +00:00
|
|
|
*/
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
else if( TESTLINE( "Sc" ) ) // timestamp
|
|
|
|
{
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp = hexParse( line + SZ( "Sc" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetTimeStamp( timestamp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Op" ) ) // (Op)tions for auto placement
|
|
|
|
{
|
|
|
|
int itmp1 = hexParse( line + SZ( "Op" ), &data );
|
|
|
|
int itmp2 = hexParse( data );
|
|
|
|
|
|
|
|
int cntRot180 = itmp2 & 0x0F;
|
|
|
|
if( cntRot180 > 10 )
|
|
|
|
cntRot180 = 10;
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetPlacementCost180( cntRot180 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
int cntRot90 = itmp1 & 0x0F;
|
|
|
|
if( cntRot90 > 10 )
|
|
|
|
cntRot90 = 0;
|
|
|
|
|
|
|
|
itmp1 = (itmp1 >> 4) & 0x0F;
|
|
|
|
if( itmp1 > 10 )
|
|
|
|
itmp1 = 0;
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetPlacementCost90( (itmp1 << 4) | cntRot90 );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "At" ) ) // (At)tributes of module
|
|
|
|
{
|
|
|
|
int attrs = MOD_DEFAULT;
|
|
|
|
|
|
|
|
data = line + SZ( "At" );
|
|
|
|
|
|
|
|
if( strstr( data, "SMD" ) )
|
|
|
|
attrs |= MOD_CMS;
|
|
|
|
|
|
|
|
if( strstr( data, "VIRTUAL" ) )
|
|
|
|
attrs |= MOD_VIRTUAL;
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetAttributes( attrs );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "AR" ) ) // Alternate Reference
|
|
|
|
{
|
|
|
|
// e.g. "AR /47BA2624/45525076"
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( line + SZ( "AR" ), delims, &saveptr );
|
2013-06-13 16:09:35 +00:00
|
|
|
if( data )
|
|
|
|
aModule->SetPath( FROM_UTF8( data ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$SHAPE3D" ) )
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
load3D( aModule );
|
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"
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetDescription( FROM_UTF8( StrPurge( line + SZ( "Cd" ) ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Kw" ) ) // Key words
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->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" ) );
|
2012-05-18 08:33:57 +00:00
|
|
|
// Due to a bug in dialog editor in Modedit, fixed in BZR version 3565
|
|
|
|
// 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;
|
|
|
|
if( tmp > 0.0 )
|
|
|
|
tmp = 0.0;
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetLocalSolderPasteMarginRatio( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".SolderPaste" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".SolderPaste" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetLocalSolderPasteMargin( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".SolderMask" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".SolderMask" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetLocalSolderMaskMargin( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".LocalClearance" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".LocalClearance" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetLocalClearance( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".ZoneConnection" ) )
|
|
|
|
{
|
|
|
|
int tmp = intParse( line + SZ( ".ZoneConnection" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetZoneConnection( (ZoneConnection)tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".ThermalWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetThermalWidth( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".ThermalGap" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->SetThermalGap( tmp );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndMODULE" ) )
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
aModule->CalculateBoundingBox();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
return; // preferred exit
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 02:17:07 +00:00
|
|
|
wxString msg = wxString::Format(
|
|
|
|
wxT( "Missing '$EndMODULE' for MODULE '%s'" ),
|
|
|
|
GetChars( aModule->GetFPID().GetFootprintName() ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
|
|
|
|
THROW_IO_ERROR( msg );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPAD( MODULE* aModule )
|
|
|
|
{
|
2012-11-15 16:04:10 +00:00
|
|
|
auto_ptr<D_PAD> pad( new D_PAD( aModule ) );
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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"
|
|
|
|
|
|
|
|
// mypadname is LATIN1/CRYLIC for BOARD_FORMAT_VERSION 1,
|
|
|
|
// but for BOARD_FORMAT_VERSION 2, it is UTF8 from disk.
|
|
|
|
// So we have to go through two code paths. Moving forward
|
|
|
|
// padnames will be in UTF8 on disk, as are all KiCad strings on disk.
|
|
|
|
char mypadname[50];
|
|
|
|
|
|
|
|
data = line + SZ( "Sh" ) + 1; // +1 skips trailing whitespace
|
|
|
|
|
|
|
|
data = data + ReadDelimitedText( mypadname, data, sizeof(mypadname) ) + 1; // +1 trailing whitespace
|
|
|
|
|
|
|
|
// sscanf( PtLine, " %s %d %d %d %d %d", BufCar, &m_Size.x, &m_Size.y, &m_DeltaSize.x, &m_DeltaSize.y, &m_Orient );
|
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
|
|
|
|
2012-04-07 18:05:56 +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 );
|
|
|
|
double orient = degParse( data );
|
|
|
|
|
2013-06-13 16:17:25 +00:00
|
|
|
switch( padchar )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
case 'C': padshape = PAD_CIRCLE; break;
|
|
|
|
case 'R': padshape = PAD_RECT; break;
|
|
|
|
case 'O': padshape = PAD_OVAL; break;
|
|
|
|
case 'T': padshape = PAD_TRAPEZOID; break;
|
|
|
|
default:
|
2014-01-19 13:12:57 +00:00
|
|
|
m_error.Printf( _( "Unknown padshape '%c=0x%02x' on line: %d of module: '%s'" ),
|
2013-09-08 18:31:21 +00:00
|
|
|
padchar,
|
|
|
|
padchar,
|
|
|
|
m_reader->LineNumber(),
|
2014-01-02 02:17:07 +00:00
|
|
|
GetChars( aModule->GetFPID().GetFootprintName() )
|
2013-06-13 16:09:35 +00:00
|
|
|
);
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
// go through a wxString to establish a universal character set properly
|
|
|
|
wxString padname;
|
|
|
|
|
|
|
|
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)
|
|
|
|
const unsigned char* cp = (unsigned char*) mypadname;
|
|
|
|
while( *cp )
|
|
|
|
{
|
|
|
|
padname += *cp++; // unsigned, ls 8 bits only
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// version 2, which is UTF8.
|
|
|
|
padname = FROM_UTF8( mypadname );
|
|
|
|
}
|
|
|
|
// chances are both were ASCII, but why take chances?
|
|
|
|
|
|
|
|
pad->SetPadName( padname );
|
|
|
|
pad->SetShape( PAD_SHAPE_T( padshape ) );
|
|
|
|
pad->SetSize( wxSize( size_x, size_y ) );
|
|
|
|
pad->SetDelta( wxSize( delta_x, delta_y ) );
|
|
|
|
pad->SetOrientation( orient );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Dr" ) ) // (Dr)ill
|
|
|
|
{
|
|
|
|
// e.g. "Dr 350 0 0" or "Dr 0 0 0 O 0 0"
|
|
|
|
// sscanf( PtLine, "%d %d %d %s %d %d", &m_Drill.x, &m_Offset.x, &m_Offset.y, BufCar, &dx, &dy );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2014-01-26 14:20:58 +00:00
|
|
|
PAD_DRILL_SHAPE_T drShape = PAD_DRILL_CIRCLE;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
if( data ) // optional shape
|
|
|
|
{
|
|
|
|
if( data[0] == 'O' )
|
|
|
|
{
|
2014-01-26 14:20:58 +00:00
|
|
|
drShape = PAD_DRILL_OBLONG;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
drill_x = biuParse( data );
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
drill_y = biuParse( data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetDrillShape( drShape );
|
|
|
|
pad->SetOffset( wxPoint( offs_x, offs_y ) );
|
|
|
|
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 );
|
|
|
|
|
|
|
|
PAD_ATTR_T attribute;
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( line + SZ( "At" ), delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( !strcmp( data, "SMD" ) )
|
|
|
|
attribute = PAD_SMD;
|
|
|
|
else if( !strcmp( data, "CONN" ) )
|
|
|
|
attribute = PAD_CONN;
|
|
|
|
else if( !strcmp( data, "HOLE" ) )
|
|
|
|
attribute = PAD_HOLE_NOT_PLATED;
|
|
|
|
else
|
|
|
|
attribute = PAD_STANDARD;
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr ); // skip BufCar
|
|
|
|
data = strtok_r( NULL, 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) );
|
2014-02-12 17:04:27 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if( m_board )
|
2014-06-03 07:32:57 +00:00
|
|
|
assert( m_board->FindNet( getNetCode( netcode ) )->GetNetname() ==
|
2014-06-02 09:41:54 +00:00
|
|
|
FROM_UTF8( StrPurge( buf ) ) );
|
2014-02-12 17:04:27 +00:00
|
|
|
#endif /* NDEBUG */
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Po" ) ) // (Po)sition
|
|
|
|
{
|
|
|
|
// e.g. "Po 500 -500"
|
|
|
|
wxPoint pos;
|
|
|
|
|
|
|
|
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" ) );
|
|
|
|
pad->SetZoneConnection( (ZoneConnection)tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".ThermalWidth" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalWidth" ) );
|
|
|
|
pad->SetThermalWidth( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( ".ThermalGap" ) )
|
|
|
|
{
|
|
|
|
BIU tmp = biuParse( line + SZ( ".ThermalGap" ) );
|
|
|
|
pad->SetThermalGap( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndPAD" ) )
|
|
|
|
{
|
2012-05-22 17:51:18 +00:00
|
|
|
// pad's "Position" is not relative to the module's,
|
|
|
|
// whereas Pos0 is relative to the module's but is the unrotated coordinate.
|
|
|
|
|
|
|
|
wxPoint padpos = pad->GetPos0();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
RotatePoint( &padpos, aModule->GetOrientation() );
|
|
|
|
|
|
|
|
pad->SetPosition( padpos + aModule->GetPosition() );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->Pads().PushBack( pad.release() );
|
2012-04-07 18:05:56 +00:00
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndPAD'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadMODULE_EDGE( MODULE* aModule )
|
|
|
|
{
|
2012-04-16 03:18:41 +00:00
|
|
|
STROKE_T shape;
|
|
|
|
char* line = m_reader->Line(); // obtain current (old) line
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
switch( line[1] )
|
|
|
|
{
|
|
|
|
case 'S': shape = S_SEGMENT; break;
|
|
|
|
case 'C': shape = S_CIRCLE; break;
|
|
|
|
case 'A': shape = S_ARC; break;
|
|
|
|
case 'P': shape = S_POLYGON; break;
|
|
|
|
default:
|
2013-06-13 16:09:35 +00:00
|
|
|
m_error.Printf( wxT( "Unknown EDGE_MODULE type:'%c=0x%02x' on line:%d of module:'%s'" ),
|
|
|
|
(unsigned char) line[1],
|
|
|
|
(unsigned char) line[1],
|
|
|
|
m_reader->LineNumber(),
|
2014-01-02 02:17:07 +00:00
|
|
|
GetChars( aModule->GetFPID().GetFootprintName() )
|
2013-06-13 16:09:35 +00:00
|
|
|
);
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
2012-11-15 16:04:10 +00:00
|
|
|
auto_ptr<EDGE_MODULE> dwg( new EDGE_MODULE( aModule, 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
|
2014-06-24 16:17:18 +00:00
|
|
|
BIU width = 1;
|
|
|
|
LAYER_NUM layer = FIRST_NON_COPPER_LAYER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
switch( shape )
|
|
|
|
{
|
|
|
|
case S_ARC:
|
|
|
|
{
|
|
|
|
// sscanf( Line + 3, "%d %d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &m_Angle, &m_Width, &m_Layer );
|
|
|
|
BIU start0_x = biuParse( line + SZ( "DA" ), &data );
|
|
|
|
BIU start0_y = biuParse( data, &data );
|
|
|
|
BIU end0_x = biuParse( data, &data );
|
|
|
|
BIU end0_y = biuParse( data, &data );
|
|
|
|
double angle = degParse( data, &data );
|
|
|
|
|
|
|
|
width = biuParse( data, &data );
|
2013-03-31 13:27:46 +00:00
|
|
|
layer = layerParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
dwg->SetAngle( angle );
|
|
|
|
dwg->m_Start0 = wxPoint( start0_x, start0_y );
|
|
|
|
dwg->m_End0 = wxPoint( end0_x, end0_y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_SEGMENT:
|
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
|
|
|
// e.g. "DS -7874 -10630 7874 -10630 50 20\r\n"
|
|
|
|
// sscanf( Line + 3, "%d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &m_Width, &m_Layer );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
width = biuParse( data, &data );
|
2013-03-31 13:27:46 +00:00
|
|
|
layer = layerParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
dwg->m_Start0 = wxPoint( start0_x, start0_y );
|
|
|
|
dwg->m_End0 = wxPoint( end0_x, end0_y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
// e.g. "DP %d %d %d %d %d %d %d\n"
|
|
|
|
// sscanf( Line + 3, "%d %d %d %d %d %d %d", &m_Start0.x, &m_Start0.y, &m_End0.x, &m_End0.y, &pointCount, &m_Width, &m_Layer );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
width = biuParse( data, &data );
|
2013-03-31 13:27:46 +00:00
|
|
|
layer = layerParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
dwg->m_Start0 = wxPoint( start0_x, start0_y );
|
|
|
|
dwg->m_End0 = wxPoint( end0_x, end0_y );
|
|
|
|
|
|
|
|
std::vector<wxPoint> pts;
|
|
|
|
pts.reserve( ptCount );
|
|
|
|
|
|
|
|
for( int ii = 0; ii<ptCount; ++ii )
|
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
if( ( line = READLINE( m_reader ) ) == NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "S_POLGON point count mismatch." );
|
|
|
|
}
|
|
|
|
|
|
|
|
// e.g. "Dl 23 44\n"
|
|
|
|
|
|
|
|
if( !TESTLINE( "Dl" ) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "Missing Dl point def" );
|
|
|
|
}
|
|
|
|
|
|
|
|
BIU x = biuParse( line + SZ( "Dl" ), &data );
|
|
|
|
BIU y = biuParse( data );
|
|
|
|
|
|
|
|
pts.push_back( wxPoint( x, y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
dwg->SetPolyPoints( pts );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// first switch code above prevents us from getting here.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a reasonable width:
|
|
|
|
|
|
|
|
/* @todo no MAX_WIDTH in out of reach header.
|
|
|
|
if( width <= 1 )
|
|
|
|
width = 1;
|
|
|
|
else if( width > MAX_WIDTH )
|
|
|
|
width = MAX_WIDTH;
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check for a reasonable layer:
|
|
|
|
// m_Layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints
|
|
|
|
// can use the copper layers m_Layer < FIRST_NON_COPPER_LAYER is allowed.
|
|
|
|
// @todo: changes use of EDGE_MODULE these footprints and allows only
|
|
|
|
// m_Layer >= FIRST_NON_COPPER_LAYER
|
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;
|
|
|
|
|
|
|
|
dwg->SetWidth( width );
|
2014-06-24 16:17:18 +00:00
|
|
|
dwg->SetLayer( leg_layer2new( m_cu_count, layer ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
EDGE_MODULE* em = dwg.release();
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->GraphicalItems().PushBack( em );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// this had been done at the MODULE level before, presumably because the
|
|
|
|
// EDGE_MODULE needs to be already added to a module before this function will work.
|
|
|
|
em->SetDrawCoord();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadMODULE_TEXT( TEXTE_MODULE* aText )
|
|
|
|
{
|
|
|
|
const char* data;
|
2012-08-11 19:14:45 +00:00
|
|
|
const char* txt_end;
|
|
|
|
const char* line = m_reader->Line(); // current (old) line
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
// sscanf( line + 1, "%d %d %d %d %d %d %d %s %s %d %s",
|
|
|
|
// &type, &m_Pos0.x, &m_Pos0.y, &m_Size.y, &m_Size.x,
|
|
|
|
// &m_Orient, &m_Thickness, BufCar1, BufCar2, &layer, BufCar3 ) >= 10 )
|
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.
|
|
|
|
|
|
|
|
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 );
|
|
|
|
double orient = degParse( data, &data );
|
|
|
|
BIU thickn = biuParse( data, &data );
|
|
|
|
|
|
|
|
// read the quoted text before the first call to strtok() which introduces
|
|
|
|
// NULs into the string and chops it into mutliple C strings, something
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
#if 1 && defined(DEBUG)
|
|
|
|
if( m_field == wxT( "ARM_C8" ) )
|
|
|
|
{
|
|
|
|
int breakhere = 1;
|
|
|
|
(void) breakhere;
|
|
|
|
}
|
|
|
|
#endif
|
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...)
|
2013-12-10 23:41:34 +00:00
|
|
|
char* mirror = strtok_r( (char*) data, delims, &saveptr );
|
|
|
|
char* hide = strtok_r( NULL, delims, &saveptr );
|
|
|
|
char* tmp = strtok_r( NULL, delims, &saveptr );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
LAYER_NUM layer_num = tmp ? layerParse( tmp ) : SILKSCREEN_N_FRONT;
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
char* italic = strtok_r( NULL, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
char* hjust = strtok_r( (char*) txt_end, delims, &saveptr );
|
|
|
|
char* vjust = strtok_r( NULL, delims, &saveptr );
|
2012-08-11 19:14:45 +00:00
|
|
|
|
2013-04-10 07:23:20 +00:00
|
|
|
if( type != TEXTE_MODULE::TEXT_is_REFERENCE
|
2013-04-07 11:55:18 +00:00
|
|
|
&& type != TEXTE_MODULE::TEXT_is_VALUE )
|
|
|
|
type = TEXTE_MODULE::TEXT_is_DIVERS;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
aText->SetType( static_cast<TEXTE_MODULE::TEXT_TYPE>( type ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
aText->SetPos0( wxPoint( pos0_x, pos0_y ) );
|
|
|
|
aText->SetSize( wxSize( size0_x, size0_y ) );
|
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
orient -= ( static_cast<MODULE*>( aText->GetParent() ) )->GetOrientation();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
aText->SetOrientation( orient );
|
|
|
|
|
|
|
|
// @todo put in accessors?
|
|
|
|
// Set a reasonable width:
|
|
|
|
if( thickn < 1 )
|
|
|
|
thickn = 1;
|
|
|
|
|
2012-04-08 23:32:32 +00:00
|
|
|
/* this is better left to the dialogs UIs
|
2012-04-07 18:05:56 +00:00
|
|
|
aText->SetThickness( Clamp_Text_PenSize( thickn, aText->GetSize() ) );
|
|
|
|
*/
|
2012-04-08 23:32:32 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
aText->SetThickness( thickn );
|
|
|
|
|
|
|
|
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
|
|
|
|
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;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::load3D( MODULE* aModule )
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
S3D_MASTER* t3D = aModule->Models();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-01-25 12:23:29 +00:00
|
|
|
if( !t3D->GetShape3DName().IsEmpty() )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
S3D_MASTER* n3D = new S3D_MASTER( aModule );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->Models().PushBack( n3D );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
t3D = n3D;
|
|
|
|
}
|
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "Na" ) ) // Shape File Name
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
ReadDelimitedText( buf, line + SZ( "Na" ), sizeof(buf) );
|
2014-01-25 12:23:29 +00:00
|
|
|
t3D->SetShape3DName( FROM_UTF8( buf ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Sc" ) ) // Scale
|
|
|
|
{
|
2014-08-09 18:18:04 +00:00
|
|
|
sscanf( line + SZ( "Sc" ), "%lf %lf %lf\n",
|
2012-04-07 18:05:56 +00:00
|
|
|
&t3D->m_MatScale.x,
|
|
|
|
&t3D->m_MatScale.y,
|
|
|
|
&t3D->m_MatScale.z );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Of" ) ) // Offset
|
|
|
|
{
|
2014-08-09 18:18:04 +00:00
|
|
|
sscanf( line + SZ( "Of" ), "%lf %lf %lf\n",
|
2012-04-07 18:05:56 +00:00
|
|
|
&t3D->m_MatPosition.x,
|
|
|
|
&t3D->m_MatPosition.y,
|
|
|
|
&t3D->m_MatPosition.z );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Ro" ) ) // Rotation
|
|
|
|
{
|
2014-08-09 18:18:04 +00:00
|
|
|
sscanf( line + SZ( "Ro" ), "%lf %lf %lf\n",
|
2012-04-07 18:05:56 +00:00
|
|
|
&t3D->m_MatRotation.x,
|
|
|
|
&t3D->m_MatRotation.y,
|
|
|
|
&t3D->m_MatRotation.z );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndSHAPE3D" ) )
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndSHAPE3D'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPCB_LINE()
|
|
|
|
{
|
|
|
|
/* example:
|
|
|
|
$DRAWSEGMENT
|
|
|
|
Po 0 57500 -1000 57500 0 150
|
|
|
|
De 24 0 900 0 0
|
|
|
|
$EndDRAWSEGMENT
|
|
|
|
*/
|
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
auto_ptr<DRAWSEGMENT> dseg( new DRAWSEGMENT( m_board ) );
|
2013-12-10 23:41:34 +00:00
|
|
|
|
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "Po" ) )
|
|
|
|
{
|
|
|
|
// sscanf( line + 2, " %d %d %d %d %d %d", &m_Shape, &m_Start.x, &m_Start.y, &m_End.x, &m_End.y, &m_Width );
|
|
|
|
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;
|
|
|
|
|
2012-05-22 17:51:18 +00:00
|
|
|
dseg->SetShape( STROKE_T( shape ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
dseg->SetWidth( width );
|
|
|
|
dseg->SetStart( wxPoint( start_x, start_y ) );
|
|
|
|
dseg->SetEnd( wxPoint( end_x, end_y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
for( int i = 0; data; ++i, data = strtok_r( NULL, delims, &saveptr ) )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
switch( i )
|
|
|
|
{
|
|
|
|
case 0:
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer;
|
|
|
|
layer = layerParse( 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:
|
|
|
|
int mtype;
|
|
|
|
mtype = intParse( data );
|
|
|
|
dseg->SetType( mtype ); // m_Type
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
double angle;
|
|
|
|
angle = degParse( data );
|
|
|
|
dseg->SetAngle( angle ); // m_Angle
|
|
|
|
break;
|
|
|
|
case 3:
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp;
|
2012-04-07 18:05:56 +00:00
|
|
|
timestamp = hexParse( data );
|
|
|
|
dseg->SetTimeStamp( timestamp );
|
|
|
|
break;
|
|
|
|
case 4:
|
2013-04-07 11:55:18 +00:00
|
|
|
STATUS_FLAGS state;
|
|
|
|
state = static_cast<STATUS_FLAGS>( hexParse( data ) );
|
2013-03-30 19:55:26 +00:00
|
|
|
dseg->SetState( state, true );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Bezier Control Points
|
|
|
|
case 5:
|
|
|
|
x = biuParse( data );
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
y = biuParse( data );
|
|
|
|
dseg->SetBezControl1( wxPoint( x, y ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
x = biuParse( data );
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
y = biuParse( data );
|
|
|
|
dseg->SetBezControl2( wxPoint( x, y ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndDRAWSEGMENT" ) )
|
|
|
|
{
|
|
|
|
m_board->Add( dseg.release(), ADD_APPEND );
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndDRAWSEGMENT'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadNETINFO_ITEM()
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
2014-03-06 08:14:06 +00:00
|
|
|
NETINFO_ITEM* net = NULL;
|
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
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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) );
|
2014-01-09 14:51:47 +00:00
|
|
|
net = new NETINFO_ITEM( m_board, FROM_UTF8( buf ), netCode );
|
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.
|
2014-03-06 08:14:06 +00:00
|
|
|
if( net != NULL && ( net->GetNet() > 0 || m_board->FindNet( 0 ) == NULL ) )
|
2014-06-02 09:41:54 +00:00
|
|
|
{
|
2012-06-30 08:20:04 +00:00
|
|
|
m_board->AppendNet( 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 );
|
|
|
|
|
2014-06-02 09:41:54 +00:00
|
|
|
m_netCodes[netCode] = net->GetNet();
|
|
|
|
}
|
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;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndEQUIPOT'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPCB_TEXT()
|
|
|
|
{
|
|
|
|
/* examples:
|
|
|
|
For a single line text:
|
|
|
|
----------------------
|
|
|
|
$TEXTPCB
|
|
|
|
Te "Text example"
|
|
|
|
Po 66750 53450 600 800 150 0
|
|
|
|
From 24 1 0 Italic
|
|
|
|
$EndTEXTPCB
|
|
|
|
|
|
|
|
For a multi line text:
|
|
|
|
---------------------
|
|
|
|
$TEXTPCB
|
|
|
|
Te "Text example"
|
|
|
|
Nl "Line 2"
|
|
|
|
Po 66750 53450 600 800 150 0
|
|
|
|
From 24 1 0 Italic
|
|
|
|
$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?
|
2012-11-27 13:50:01 +00:00
|
|
|
TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
|
2012-04-07 18:05:56 +00:00
|
|
|
m_board->Add( pcbtxt, ADD_APPEND );
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2012-11-27 13:50:01 +00:00
|
|
|
|
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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) );
|
2012-04-07 18:05:56 +00:00
|
|
|
pcbtxt->SetText( FROM_UTF8( text ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
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" ) )
|
|
|
|
{
|
|
|
|
// sscanf( line + 2, " %d %d %d %d %d %d", &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Size.y, &m_Thickness, &m_Orient );
|
|
|
|
wxSize size;
|
|
|
|
|
|
|
|
BIU pos_x = biuParse( line + SZ( "Po" ), &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
|
|
|
size.x = biuParse( data, &data );
|
|
|
|
size.y = biuParse( data, &data );
|
|
|
|
BIU thickn = biuParse( data, &data );
|
|
|
|
double angle = degParse( data );
|
|
|
|
|
|
|
|
// Ensure the text has minimal size to see this text on screen:
|
|
|
|
|
|
|
|
/* @todo wait until we are firmly in the nanometer world
|
|
|
|
if( sz.x < 5 )
|
|
|
|
sz.x = 5;
|
|
|
|
|
|
|
|
if( sz.y < 5 )
|
|
|
|
sz.y = 5;
|
|
|
|
*/
|
|
|
|
|
|
|
|
pcbtxt->SetSize( size );
|
|
|
|
|
|
|
|
/* @todo move into an accessor
|
|
|
|
// Set a reasonable width:
|
|
|
|
if( thickn < 1 )
|
|
|
|
thickn = 1;
|
|
|
|
|
|
|
|
thickn = Clamp_Text_PenSize( thickn, size );
|
|
|
|
*/
|
|
|
|
|
|
|
|
pcbtxt->SetThickness( thickn );
|
|
|
|
pcbtxt->SetOrientation( angle );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
pcbtxt->SetTextPosition( wxPoint( pos_x, pos_y ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "De" ) )
|
|
|
|
{
|
|
|
|
// e.g. "De 21 1 0 Normal C\r\n"
|
|
|
|
// sscanf( line + 2, " %d %d %lX %s %c\n", &m_Layer, &normal_display, &m_TimeStamp, style, &hJustify );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM layer_num = layerParse( line + SZ( "De" ), &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
int notMirrored = intParse( data, &data );
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp = hexParse( data, &data );
|
2013-12-10 23:41:34 +00:00
|
|
|
char* style = strtok_r( (char*) data, delims, &saveptr );
|
|
|
|
char* hJustify = strtok_r( NULL, delims, &saveptr );
|
|
|
|
char* vJustify = strtok_r( NULL, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
pcbtxt->SetMirrored( !notMirrored );
|
|
|
|
pcbtxt->SetTimeStamp( timestamp );
|
|
|
|
pcbtxt->SetItalic( !strcmp( style, "Italic" ) );
|
|
|
|
|
|
|
|
if( hJustify )
|
2012-08-15 17:55:48 +00:00
|
|
|
pcbtxt->SetHorizJustify( horizJustify( hJustify ) );
|
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:
|
|
|
|
wxASSERT( pcbtxt->GetHorizJustify() == GR_TEXT_HJUSTIFY_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
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
pcbtxt->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$EndTEXTPCB" ) )
|
|
|
|
{
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndTEXTPCB'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-11-27 13:50:01 +00:00
|
|
|
|
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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
|
|
|
|
|
|
|
|
// int arg_count = sscanf( line + 2, " %d %d %d %d %d %d %d", &shape, &tempStartX, &tempStartY, &tempEndX, &tempEndY, &width, &drill );
|
|
|
|
|
|
|
|
assert( TESTLINE( "Po" ) );
|
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
VIATYPE_T viatype = static_cast<VIATYPE_T>( 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?)
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( (char*) data, delims, &saveptr );
|
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:
|
|
|
|
// PCB_TRACE_T, PCB_VIA_T, or PCB_ZONE_T. The type field in 2nd line
|
|
|
|
// 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
|
|
|
|
THROW_IO_ERROR( "Missing 2nd line of a TRACK def" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int makeType;
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timeStamp;
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM layer_num;
|
|
|
|
int type, net_code, flags_int;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// parse the 2nd line to determine the type of object
|
2012-05-24 15:00:59 +00:00
|
|
|
// e.g. "De 15 1 7 0 0" for a via
|
2014-06-24 16:17:18 +00:00
|
|
|
sscanf( line + SZ( "De" ), " %d %d %d %lX %X", &layer_num, &type, &net_code,
|
2013-03-28 19:12:46 +00:00
|
|
|
&timeStamp, &flags_int );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2013-03-28 19:12:46 +00:00
|
|
|
STATUS_FLAGS flags;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2013-03-28 19:12:46 +00:00
|
|
|
flags = static_cast<STATUS_FLAGS>( flags_int );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( aStructType==PCB_TRACE_T && type==1 )
|
|
|
|
makeType = PCB_VIA_T;
|
|
|
|
else
|
|
|
|
makeType = aStructType;
|
|
|
|
|
2014-05-22 17:34:28 +00:00
|
|
|
TRACK* newTrack;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
switch( makeType )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
newTrack = new TRACK( m_board );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_VIA_T:
|
2014-04-25 06:00:04 +00:00
|
|
|
newTrack = new VIA( m_board );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_ZONE_T: // this is now deprecated, but exist in old boards
|
|
|
|
newTrack = new SEGZONE( m_board );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
newTrack->SetTimeStamp( timeStamp );
|
|
|
|
|
|
|
|
newTrack->SetPosition( wxPoint( start_x, start_y ) );
|
|
|
|
newTrack->SetEnd( wxPoint( end_x, end_y ) );
|
|
|
|
|
|
|
|
newTrack->SetWidth( width );
|
|
|
|
|
|
|
|
if( makeType == PCB_VIA_T ) // Ensure layers are OK when possible:
|
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
VIA *via = static_cast<VIA*>( newTrack );
|
|
|
|
via->SetViaType( viatype );
|
|
|
|
|
|
|
|
if( drill < 0 )
|
|
|
|
via->SetDrillDefault();
|
|
|
|
else
|
|
|
|
via->SetDrill( drill );
|
|
|
|
|
|
|
|
if( via->GetViaType() == VIA_THROUGH )
|
2014-06-24 16:17:18 +00:00
|
|
|
via->SetLayerPair( F_Cu, B_Cu );
|
2014-06-25 17:01:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LAYER_ID back = leg_layer2new( m_cu_count, (layer_num >> 4) & 0xf );
|
|
|
|
LAYER_ID front = leg_layer2new( m_cu_count, layer_num & 0xf );
|
|
|
|
|
|
|
|
via->SetLayerPair( front, back );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newTrack->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 07:32:57 +00:00
|
|
|
newTrack->SetNetCode( getNetCode( net_code ) );
|
2013-03-30 19:55:26 +00:00
|
|
|
newTrack->SetState( flags, true );
|
2014-05-22 17:34:28 +00:00
|
|
|
|
|
|
|
m_board->Add( newTrack );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndTRACK'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
2012-11-15 16:04:10 +00:00
|
|
|
// store it temporarily in an auto_ptr until successfully inserted into the BOARD
|
2012-04-07 18:05:56 +00:00
|
|
|
// just before returning.
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR nc = boost::make_shared<NETCLASS>( wxEmptyString );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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) );
|
|
|
|
netname = FROM_UTF8( buf );
|
|
|
|
nc->Add( netname );
|
|
|
|
}
|
|
|
|
|
|
|
|
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" ) )
|
|
|
|
{
|
2014-05-20 09:29:37 +00:00
|
|
|
if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
|
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.
|
|
|
|
|
2012-11-15 16:04:10 +00:00
|
|
|
// auto_ptr will delete nc on this code path
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
m_error.Printf( _( "duplicate NETCLASS name '%s'" ), nc->GetName().GetData() );
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndNCLASS'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadZONE_CONTAINER()
|
|
|
|
{
|
2012-11-15 16:04:10 +00:00
|
|
|
auto_ptr<ZONE_CONTAINER> zc( new ZONE_CONTAINER( m_board ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-07-30 07:40:25 +00:00
|
|
|
CPolyLine::HATCH_STYLE outline_hatch = CPolyLine::NO_HATCH;
|
2012-04-07 18:05:56 +00:00
|
|
|
bool sawCorner = false;
|
|
|
|
char buf[1024];
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "ZCorner" ) ) // new corner found
|
|
|
|
{
|
|
|
|
// e.g. "ZCorner 25650 49500 0"
|
|
|
|
BIU x = biuParse( line + SZ( "ZCorner" ), &data );
|
|
|
|
BIU y = biuParse( data, &data );
|
|
|
|
int flag = intParse( data );
|
|
|
|
|
|
|
|
if( !sawCorner )
|
2013-03-20 14:50:12 +00:00
|
|
|
zc->Outline()->Start( zc->GetLayer(), x, y, outline_hatch );
|
2012-04-07 18:05:56 +00:00
|
|
|
else
|
|
|
|
zc->AppendCorner( wxPoint( x, y ) );
|
|
|
|
|
|
|
|
sawCorner = true;
|
|
|
|
|
|
|
|
if( flag )
|
2013-03-20 14:50:12 +00:00
|
|
|
zc->Outline()->CloseLastContour();
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "ZInfo" ) ) // general info found
|
|
|
|
{
|
|
|
|
// e.g. 'ZInfo 479194B1 310 "COMMON"'
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp = hexParse( line + SZ( "ZInfo" ), &data );
|
2012-04-07 18:05:56 +00:00
|
|
|
int netcode = intParse( data, &data );
|
|
|
|
|
|
|
|
if( ReadDelimitedText( buf, data, sizeof(buf) ) > (int) sizeof(buf) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( "ZInfo netname too long" );
|
|
|
|
}
|
|
|
|
|
|
|
|
zc->SetTimeStamp( timestamp );
|
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
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM layer_num = layerParse( line + SZ( "ZLayer" ) );
|
|
|
|
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"
|
|
|
|
int ignore = intParse( line + SZ( "ZAux" ), &data );
|
2013-12-10 23:41:34 +00:00
|
|
|
char* hopt = strtok_r( (char*) data, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( !hopt )
|
|
|
|
{
|
2014-01-14 10:41:06 +00:00
|
|
|
m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( *hopt ) // upper case required
|
|
|
|
{
|
|
|
|
case 'N': outline_hatch = CPolyLine::NO_HATCH; break;
|
|
|
|
case 'E': outline_hatch = CPolyLine::DIAGONAL_EDGE; break;
|
|
|
|
case 'F': outline_hatch = CPolyLine::DIAGONAL_FULL; break;
|
|
|
|
|
|
|
|
default:
|
2014-01-14 10:41:06 +00:00
|
|
|
m_error.Printf( wxT( "Bad ZAux for CZONE_CONTAINER '%s'" ), zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) ignore;
|
|
|
|
|
|
|
|
// 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 )
|
|
|
|
{
|
2014-01-14 10:41:06 +00:00
|
|
|
m_error.Printf( wxT( "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" ) )
|
|
|
|
{
|
|
|
|
zc->SetIsKeepout( true );
|
|
|
|
// e.g. "ZKeepout tracks N vias N pads Y"
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( line + SZ( "ZKeepout" ), delims, &saveptr );
|
2012-07-13 18:55:29 +00:00
|
|
|
|
|
|
|
while( data )
|
|
|
|
{
|
|
|
|
if( !strcmp( data, "tracks" ) )
|
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
2012-07-13 18:55:29 +00:00
|
|
|
zc->SetDoNotAllowTracks( data && *data == 'N' );
|
|
|
|
}
|
|
|
|
else if( !strcmp( data, "vias" ) )
|
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
2012-07-13 18:55:29 +00:00
|
|
|
zc->SetDoNotAllowVias( data && *data == 'N' );
|
|
|
|
}
|
2012-07-14 16:27:25 +00:00
|
|
|
else if( !strcmp( data, "copperpour" ) )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
2012-07-14 16:27:25 +00:00
|
|
|
zc->SetDoNotAllowCopperPour( data && *data == 'N' );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 23:41:34 +00:00
|
|
|
data = strtok_r( NULL, delims, &saveptr );
|
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 );
|
|
|
|
int arcsegcount = intParse( data, &data );
|
|
|
|
char fillstate = data[1]; // here e.g. " F"
|
|
|
|
BIU thermalReliefGap = biuParse( data += 2 , &data ); // +=2 for " F"
|
|
|
|
BIU thermalReliefCopperBridge = biuParse( data );
|
|
|
|
|
|
|
|
zc->SetFillMode( fillmode ? 1 : 0 );
|
|
|
|
|
|
|
|
// @todo ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF: don't really want pcbnew.h
|
|
|
|
// in here, after all, its a PLUGIN and global data is evil.
|
|
|
|
// put in accessor
|
|
|
|
if( arcsegcount >= 32 )
|
|
|
|
arcsegcount = 32;
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
zc->SetArcSegmentCount( arcsegcount );
|
2014-03-06 10:49:08 +00:00
|
|
|
zc->SetIsFilled( fillstate == 'S' );
|
2012-04-07 18:05:56 +00:00
|
|
|
zc->SetThermalReliefGap( thermalReliefGap );
|
|
|
|
zc->SetThermalReliefCopperBridge( thermalReliefCopperBridge );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "ZClearance" ) ) // Clearance and pad options info found
|
|
|
|
{
|
|
|
|
// e.g. "ZClearance 40 I"
|
|
|
|
BIU clearance = biuParse( line + SZ( "ZClearance" ), &data );
|
2013-12-10 23:41:34 +00:00
|
|
|
char* padoption = strtok_r( (char*) data, delims, &saveptr ); // data: " I"
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
ZoneConnection popt;
|
|
|
|
switch( *padoption )
|
|
|
|
{
|
|
|
|
case 'I': popt = PAD_IN_ZONE; break;
|
|
|
|
case 'T': popt = THERMAL_PAD; break;
|
2012-07-09 07:10:07 +00:00
|
|
|
case 'H': popt = THT_THERMAL; break;
|
2012-04-07 18:05:56 +00:00
|
|
|
case 'X': popt = PAD_NOT_IN_ZONE; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_error.Printf( wxT( "Bad ZClearance padoption for CZONE_CONTAINER '%s'" ),
|
2014-01-14 10:41:06 +00:00
|
|
|
zc->GetNetname().GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
zc->SetZoneClearance( clearance );
|
|
|
|
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" ) );
|
|
|
|
zc->SetPriority( priority );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$POLYSCORNERS" ) )
|
|
|
|
{
|
|
|
|
// Read the PolysList (polygons used for fill areas in the zone)
|
2013-05-03 17:51:10 +00:00
|
|
|
CPOLYGONS_LIST polysList;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
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 );
|
|
|
|
|
|
|
|
bool end_contour = intParse( data, &data ); // end_countour was a bool when file saved, so '0' or '1' here
|
2013-03-26 09:58:40 +00:00
|
|
|
int cornerUtilityFlg = intParse( data );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-05-09 19:08:12 +00:00
|
|
|
polysList.Append( CPolyPt( x, y, end_contour, cornerUtilityFlg ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
2012-06-02 21:19:17 +00:00
|
|
|
zc->AddFilledPolysList( polysList );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "$FILLSEGMENTS" ) )
|
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "$endFILLSEGMENTS" ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// e.g. ""%d %d %d %d\n"
|
|
|
|
BIU sx = biuParse( line, &data );
|
|
|
|
BIU sy = biuParse( data, &data );
|
|
|
|
BIU ex = biuParse( data, &data );
|
|
|
|
BIU ey = biuParse( data );
|
|
|
|
|
2013-03-20 14:50:12 +00:00
|
|
|
zc->FillSegments().push_back( SEGMENT( wxPoint( sx, sy ), wxPoint( ex, ey ) ) );
|
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)
|
|
|
|
if( zc->GetIsKeepout() )
|
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() )
|
|
|
|
{
|
|
|
|
zc->SetFillMode( 0 );
|
2014-02-25 10:47:27 +00:00
|
|
|
zc->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:40:25 +00:00
|
|
|
// Hatch here, after outlines corners are read
|
2012-04-07 18:05:56 +00:00
|
|
|
// Set hatch here, after outlines corners are read
|
2013-03-20 14:50:12 +00:00
|
|
|
zc->Outline()->SetHatch( outline_hatch,
|
|
|
|
Mils2iu( CPolyLine::GetDefaultHatchPitchMils() ),
|
|
|
|
true );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
m_board->Add( zc.release() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$endCZONE_OUTLINE'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadDIMENSION()
|
|
|
|
{
|
2012-11-15 16:04:10 +00:00
|
|
|
auto_ptr<DIMENSION> dim( new DIMENSION( m_board ) );
|
2013-12-10 23:41:34 +00:00
|
|
|
|
|
|
|
char* line;
|
|
|
|
char* saveptr;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "$endCOTATION" ) )
|
|
|
|
{
|
|
|
|
m_board->Add( dim.release(), ADD_APPEND );
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Va" ) )
|
|
|
|
{
|
|
|
|
BIU value = biuParse( line + SZ( "Va" ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
dim->SetValue( value );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Ge" ) )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_NUM layer_num;
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp;
|
2012-04-07 18:05:56 +00:00
|
|
|
int shape;
|
2013-03-31 13:27:46 +00:00
|
|
|
int ilayer;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
sscanf( line + SZ( "Ge" ), " %d %d %lX", &shape, &ilayer, ×tamp );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( ilayer < FIRST_NON_COPPER_LAYER )
|
2014-06-24 16:17:18 +00:00
|
|
|
layer_num = FIRST_NON_COPPER_LAYER;
|
2013-03-31 13:27:46 +00:00
|
|
|
else if( ilayer > LAST_NON_COPPER_LAYER )
|
2014-06-24 16:17:18 +00:00
|
|
|
layer_num = LAST_NON_COPPER_LAYER;
|
|
|
|
else
|
|
|
|
layer_num = ilayer;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
dim->SetLayer( leg_layer2new( m_cu_count, layer_num ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
dim->SetTimeStamp( timestamp );
|
|
|
|
dim->SetShape( shape );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Te" ) )
|
|
|
|
{
|
|
|
|
char buf[2048];
|
|
|
|
|
|
|
|
ReadDelimitedText( buf, line + SZ( "Te" ), sizeof(buf) );
|
2013-03-13 18:53:58 +00:00
|
|
|
dim->SetText( FROM_UTF8( buf ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d %d", &m_Text->m_Pos.x, &m_Text->m_Pos.y,
|
|
|
|
// &m_Text->m_Size.x, &m_Text->m_Size.y, &thickness, &orientation, &normal_display );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
double orient = degParse( data, &data );
|
2013-12-10 23:41:34 +00:00
|
|
|
char* mirror = strtok_r( (char*) data, delims, &saveptr );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// This sets both DIMENSION's position and internal m_Text's.
|
|
|
|
// @todo: But why do we even know about internal m_Text?
|
|
|
|
dim->SetPosition( wxPoint( pos_x, pos_y ) );
|
|
|
|
dim->SetTextSize( wxSize( width, height ) );
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
dim->Text().SetMirrored( mirror && *mirror == '0' );
|
|
|
|
dim->Text().SetThickness( thickn );
|
|
|
|
dim->Text().SetOrientation( orient );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Sb" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_crossBarOx, &m_crossBarOy, &m_crossBarFx, &m_crossBarFy, &m_Width );
|
|
|
|
|
|
|
|
int ignore = biuParse( line + SZ( "Sb" ), &data );
|
|
|
|
BIU crossBarOx = biuParse( data, &data );
|
|
|
|
BIU crossBarOy = biuParse( data, &data );
|
|
|
|
BIU crossBarFx = biuParse( data, &data );
|
|
|
|
BIU crossBarFy = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_crossBarO.x = crossBarOx;
|
|
|
|
dim->m_crossBarO.y = crossBarOy;
|
|
|
|
dim->m_crossBarF.x = crossBarFx;
|
|
|
|
dim->m_crossBarF.y = crossBarFy;
|
2013-03-13 18:53:58 +00:00
|
|
|
dim->SetWidth( width );
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Sd" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_featureLineDOx, &m_featureLineDOy, &m_featureLineDFx, &m_featureLineDFy, &Dummy );
|
|
|
|
|
|
|
|
int ignore = intParse( line + SZ( "Sd" ), &data );
|
|
|
|
BIU featureLineDOx = biuParse( data, &data );
|
|
|
|
BIU featureLineDOy = biuParse( data, &data );
|
|
|
|
BIU featureLineDFx = biuParse( data, &data );
|
|
|
|
BIU featureLineDFy = biuParse( data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_featureLineDO.x = featureLineDOx;
|
|
|
|
dim->m_featureLineDO.y = featureLineDOy;
|
|
|
|
dim->m_featureLineDF.x = featureLineDFx;
|
|
|
|
dim->m_featureLineDF.y = featureLineDFy;
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Sg" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_featureLineGOx, &m_featureLineGOy, &m_featureLineGFx, &m_featureLineGFy, &Dummy );
|
|
|
|
|
|
|
|
int ignore = intParse( line + SZ( "Sg" ), &data );
|
|
|
|
BIU featureLineGOx = biuParse( data, &data );
|
|
|
|
BIU featureLineGOy = biuParse( data, &data );
|
|
|
|
BIU featureLineGFx = biuParse( data, &data );
|
|
|
|
BIU featureLineGFy = biuParse( data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_featureLineGO.x = featureLineGOx;
|
|
|
|
dim->m_featureLineGO.y = featureLineGOy;
|
|
|
|
dim->m_featureLineGF.x = featureLineGFx;
|
|
|
|
dim->m_featureLineGF.y = featureLineGFy;
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "S1" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowD1Ox, &m_arrowD1Oy, &m_arrowD1Fx, &m_arrowD1Fy, &Dummy );
|
|
|
|
|
|
|
|
int ignore = 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
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU arrowD1Fx = biuParse( data, &data );
|
|
|
|
BIU arrowD1Fy = biuParse( data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_arrowD1F.x = arrowD1Fx;
|
|
|
|
dim->m_arrowD1F.y = arrowD1Fy;
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "S2" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowD2Ox, &m_arrowD2Oy, &m_arrowD2Fx, &m_arrowD2Fy, &Dummy );
|
|
|
|
|
|
|
|
int ignore = 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
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU arrowD2Fx = biuParse( data, &data );
|
|
|
|
BIU arrowD2Fy = biuParse( data, &data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_arrowD2F.x = arrowD2Fx;
|
|
|
|
dim->m_arrowD2F.y = arrowD2Fy;
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "S3" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d\n", &Dummy, &m_arrowG1Ox, &m_arrowG1Oy, &m_arrowG1Fx, &m_arrowG1Fy, &Dummy );
|
|
|
|
int ignore = 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
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU arrowG1Fx = biuParse( data, &data );
|
|
|
|
BIU arrowG1Fy = biuParse( data, &data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_arrowG1F.x = arrowG1Fx;
|
|
|
|
dim->m_arrowG1F.y = arrowG1Fy;
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "S4" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %d %d %d %d %d %d", &Dummy, &m_arrowG2Ox, &m_arrowG2Oy, &m_arrowG2Fx, &m_arrowG2Fy, &Dummy );
|
|
|
|
int ignore = 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
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU arrowG2Fx = biuParse( data, &data );
|
|
|
|
BIU arrowG2Fy = biuParse( data, &data );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
dim->m_arrowG2F.x = arrowG2Fx;
|
|
|
|
dim->m_arrowG2F.y = arrowG2Fy;
|
2012-04-07 18:05:56 +00:00
|
|
|
(void) ignore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$endCOTATION'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::loadPCB_TARGET()
|
|
|
|
{
|
2012-11-27 13:50:01 +00:00
|
|
|
char* line;
|
|
|
|
|
|
|
|
while( ( line = READLINE( m_reader ) ) != NULL )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
const char* data;
|
|
|
|
|
|
|
|
if( TESTLINE( "$EndPCB_TARGET" ) || TESTLINE( "$EndMIREPCB" ) )
|
|
|
|
{
|
|
|
|
return; // preferred exit
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( TESTLINE( "Po" ) )
|
|
|
|
{
|
|
|
|
// sscanf( Line + 2, " %X %d %d %d %d %d %lX", &m_Shape, &m_Layer, &m_Pos.x, &m_Pos.y, &m_Size, &m_Width, &m_TimeStamp );
|
|
|
|
|
|
|
|
int shape = intParse( line + SZ( "Po" ), &data );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
LAYER_NUM layer_num = layerParse( data, &data );
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
BIU pos_x = biuParse( data, &data );
|
|
|
|
BIU pos_y = biuParse( data, &data );
|
|
|
|
BIU size = biuParse( data, &data );
|
|
|
|
BIU width = biuParse( data, &data );
|
2012-05-25 01:52:04 +00:00
|
|
|
time_t timestamp = hexParse( 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;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
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 ),
|
|
|
|
wxPoint( pos_x, pos_y ), size, width );
|
2012-04-07 18:05:56 +00:00
|
|
|
m_board->Add( t, ADD_APPEND );
|
|
|
|
|
|
|
|
t->SetTimeStamp( timestamp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( "Missing '$EndDIMENSION'" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
m_error.Printf( _( "invalid float number in file: '%s'\nline: %d, offset: %d" ),
|
2013-04-10 07:23:20 +00:00
|
|
|
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 )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
m_error.Printf( _( "missing float number in file: '%s'\nline: %d, offset: %d" ),
|
2013-04-10 07:23:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double LEGACY_PLUGIN::degParse( const char* aValue, const char** nptrptr )
|
|
|
|
{
|
|
|
|
char* nptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
double fval = strtod( aValue, &nptr );
|
|
|
|
|
|
|
|
if( errno )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
m_error.Printf( _( "invalid float number in file: '%s'\nline: %d, offset: %d" ),
|
2012-04-07 18:05:56 +00:00
|
|
|
m_reader->GetSource().GetData(), m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
|
|
|
|
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aValue == nptr )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
m_error.Printf( _( "missing float number in file: '%s'\nline: %d, offset: %d" ),
|
2012-04-07 18:05:56 +00:00
|
|
|
m_reader->GetSource().GetData(), m_reader->LineNumber(), aValue - m_reader->Line() + 1 );
|
|
|
|
|
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nptrptr )
|
|
|
|
*nptrptr = nptr;
|
|
|
|
|
|
|
|
return fval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void LEGACY_PLUGIN::init( const PROPERTIES* aProperties )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
m_cu_count = 16;
|
2012-04-16 03:18:41 +00:00
|
|
|
m_board = NULL;
|
2012-04-07 18:05:56 +00:00
|
|
|
m_props = aProperties;
|
|
|
|
|
|
|
|
// conversion factor for saving RAM BIUs to KICAD legacy file format.
|
2012-06-24 18:41:37 +00:00
|
|
|
biuToDisk = 1.0/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
|
|
|
|
2013-08-06 23:21:40 +00:00
|
|
|
diskToBiu = IU_PER_DECIMILS; // BIUs are nanometers
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
void LEGACY_PLUGIN::SaveModule3D( const MODULE* me ) const
|
|
|
|
{
|
|
|
|
for( S3D_MASTER* t3D = me->Models(); t3D; t3D = t3D->Next() )
|
|
|
|
{
|
|
|
|
if( !t3D->GetShape3DName().IsEmpty() )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$SHAPE3D\n" );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Na %s\n", EscapedUTF8( t3D->GetShape3DName() ).c_str() );
|
|
|
|
|
|
|
|
fprintf(m_fp,
|
|
|
|
#if defined(DEBUG)
|
|
|
|
// use old formats for testing, just to verify compatibility
|
|
|
|
// using "diff", then switch to more concise form for release builds.
|
|
|
|
"Sc %lf %lf %lf\n",
|
|
|
|
#else
|
|
|
|
"Sc %.10g %.10g %.10g\n",
|
|
|
|
#endif
|
|
|
|
t3D->m_MatScale.x,
|
|
|
|
t3D->m_MatScale.y,
|
|
|
|
t3D->m_MatScale.z );
|
|
|
|
|
|
|
|
fprintf(m_fp,
|
|
|
|
#if defined(DEBUG)
|
|
|
|
"Of %lf %lf %lf\n",
|
|
|
|
#else
|
|
|
|
"Of %.10g %.10g %.10g\n",
|
|
|
|
#endif
|
|
|
|
t3D->m_MatPosition.x,
|
|
|
|
t3D->m_MatPosition.y,
|
|
|
|
t3D->m_MatPosition.z );
|
|
|
|
|
|
|
|
fprintf(m_fp,
|
|
|
|
#if defined(DEBUG)
|
|
|
|
"Ro %lf %lf %lf\n",
|
|
|
|
#else
|
|
|
|
"Ro %.10g %.10g %.10g\n",
|
|
|
|
#endif
|
|
|
|
t3D->m_MatRotation.x,
|
|
|
|
t3D->m_MatRotation.y,
|
|
|
|
t3D->m_MatRotation.z );
|
|
|
|
|
|
|
|
fprintf( m_fp, "$EndSHAPE3D\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
//-----<BOARD Save Functions>---------------------------------------------------
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#define SPBUFZ 50 // wire all usages of this together.
|
|
|
|
|
|
|
|
int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const
|
|
|
|
{
|
|
|
|
double engUnits = biuToDisk * aValue;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 )
|
|
|
|
{
|
|
|
|
len = snprintf( buf, SPBUFZ, "%.10f", engUnits );
|
|
|
|
|
|
|
|
while( --len > 0 && buf[len] == '0' )
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The %.10g is about optimal since we are dealing with a bounded
|
|
|
|
// range on aValue, and we can be sure that there will never
|
|
|
|
// be a reason to have more than 6 digits to the right of the
|
|
|
|
// decimal point because we are converting from integer
|
|
|
|
// (signed whole numbers) nanometers to mm. A value of
|
|
|
|
// 0.000001 is one nanometer, the smallest positive nonzero value
|
|
|
|
// that we can ever have here. If you ever see a board file with
|
|
|
|
// more digits to the right of the decimal point than 6, this is a
|
|
|
|
// possibly a bug in a formatting string nearby.
|
|
|
|
len = snprintf( buf, SPBUFZ, "%.10g", engUnits );
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LEGACY_PLUGIN::fmtBIU( BIU aValue ) const
|
|
|
|
{
|
|
|
|
char temp[SPBUFZ];
|
|
|
|
|
|
|
|
int len = biuSprintf( temp, aValue );
|
|
|
|
|
|
|
|
return std::string( temp, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LEGACY_PLUGIN::fmtDEG( double aAngle ) const
|
|
|
|
{
|
|
|
|
char temp[50];
|
|
|
|
|
|
|
|
// @todo a hook site to convert from tenths degrees to degrees for BOARD_FORMAT_VERSION 2.
|
|
|
|
|
|
|
|
// MINGW: snprintf() comes from gcc folks, sprintf() comes from Microsoft.
|
|
|
|
int len = snprintf( temp, sizeof( temp ), "%.10g", aAngle );
|
|
|
|
|
|
|
|
return std::string( temp, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LEGACY_PLUGIN::fmtBIUPair( BIU first, BIU second ) const
|
|
|
|
{
|
|
|
|
char temp[2*SPBUFZ+2];
|
|
|
|
char* cp = temp;
|
|
|
|
|
|
|
|
cp += biuSprintf( cp, first );
|
|
|
|
|
|
|
|
*cp++ = ' ';
|
|
|
|
|
|
|
|
cp += biuSprintf( cp, second );
|
|
|
|
|
|
|
|
return std::string( temp, cp - temp );
|
|
|
|
}
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void LEGACY_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
|
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 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
FILE* fp = wxFopen( aFileName, wxT( "w" ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
if( !fp )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
m_error.Printf( _( "Unable to open file '%s'" ), aFileName.GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
THROW_IO_ERROR( m_error );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_filename = aFileName;
|
|
|
|
|
|
|
|
// wxf now owns fp, will close on exception or return
|
|
|
|
wxFFile wxf( fp );
|
|
|
|
|
|
|
|
m_fp = fp; // member function accessibility
|
|
|
|
|
2012-12-14 18:14:28 +00:00
|
|
|
wxString header = wxString::Format(
|
|
|
|
wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s\n\n" ),
|
|
|
|
LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(),
|
|
|
|
GetBuildVersion().GetData() );
|
|
|
|
|
|
|
|
// save a file header, if caller provided one (with trailing \n hopefully).
|
|
|
|
fprintf( m_fp, "%s", TO_UTF8( header ) );
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
SaveBOARD( aBoard );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString LEGACY_PLUGIN::writeError() const
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
return wxString::Format( _( "error writing to file '%s'" ), m_filename.GetData() );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_WRITE_ERROR() \
|
|
|
|
do { \
|
|
|
|
if( ferror( m_fp ) ) \
|
|
|
|
{ \
|
|
|
|
THROW_IO_ERROR( writeError() ); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
// With the advent of the LSET expansion it was agreed to abort the legacy save since
|
|
|
|
// we'd have to expand the old format in order to suppor the new LAYER_IDs.
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void LEGACY_PLUGIN::SaveBOARD( const BOARD* aBoard ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
m_mapping->SetBoard( aBoard );
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
saveGENERAL( aBoard );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
saveSHEET( aBoard );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
saveSETUP( aBoard );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
saveBOARD_ITEMS( aBoard );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void LEGACY_PLUGIN::saveGENERAL( const BOARD* aBoard ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, "$GENERAL\n" );
|
|
|
|
fprintf( m_fp, "encoding utf-8\n" );
|
|
|
|
|
|
|
|
// tell folks the units used within the file, as early as possible here.
|
|
|
|
fprintf( m_fp, "Units mm\n" );
|
|
|
|
|
|
|
|
// Write copper layer count
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "LayerCount %d\n", aBoard->GetCopperLayerCount() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/* No, EnabledLayers has this information, plus g_TabAllCopperLayerMask is
|
|
|
|
global and globals are not allowed in a plugin.
|
|
|
|
fprintf( m_fp,
|
|
|
|
"Ly %8X\n",
|
|
|
|
g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS );
|
|
|
|
*/
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "EnabledLayers %08X\n", aBoard->GetEnabledLayers() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
if( aBoard->GetEnabledLayers() != aBoard->GetVisibleLayers() )
|
|
|
|
fprintf( m_fp, "VisibleLayers %08X\n", aBoard->GetVisibleLayers() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "Links %d\n", aBoard->GetRatsnestsCount() );
|
2013-01-09 18:52:44 +00:00
|
|
|
fprintf( m_fp, "NoConn %d\n", aBoard->GetUnconnectedNetCount() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// Write Bounding box info
|
2012-04-17 02:58:03 +00:00
|
|
|
EDA_RECT bbbox = ((BOARD*)aBoard)->ComputeBoundingBox();
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
fprintf( m_fp, "Di %s %s\n",
|
|
|
|
fmtBIUPair( bbbox.GetX(), bbbox.GetY() ).c_str(),
|
|
|
|
fmtBIUPair( bbbox.GetRight(), bbbox.GetBottom() ).c_str() );
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "Ndraw %d\n", aBoard->m_Drawings.GetCount() );
|
|
|
|
fprintf( m_fp, "Ntrack %d\n", aBoard->GetNumSegmTrack() );
|
|
|
|
fprintf( m_fp, "Nzone %d\n", aBoard->GetNumSegmZone() );
|
2012-06-09 17:00:13 +00:00
|
|
|
fprintf( m_fp, "BoardThickness %s\n", fmtBIU( aBoard->GetDesignSettings().GetBoardThickness() ).c_str() );
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "Nmodule %d\n", aBoard->m_Modules.GetCount() );
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
fprintf( m_fp, "Nnets %d\n", m_mapping->GetSize() );
|
2012-04-07 18:05:56 +00:00
|
|
|
fprintf( m_fp, "$EndGENERAL\n\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void LEGACY_PLUGIN::saveSHEET( const BOARD* aBoard ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2012-04-17 02:58:03 +00:00
|
|
|
const PAGE_INFO& pageInfo = aBoard->GetPageSettings();
|
|
|
|
const TITLE_BLOCK& tb = ((BOARD*)aBoard)->GetTitleBlock();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "$SHEETDESCR\n" );
|
|
|
|
|
|
|
|
// paper is described in mils
|
|
|
|
fprintf( m_fp, "Sheet %s %d %d%s\n",
|
|
|
|
TO_UTF8( pageInfo.GetType() ),
|
|
|
|
pageInfo.GetWidthMils(),
|
|
|
|
pageInfo.GetHeightMils(),
|
|
|
|
!pageInfo.IsCustom() && pageInfo.IsPortrait() ?
|
|
|
|
" portrait" : ""
|
|
|
|
);
|
|
|
|
|
|
|
|
fprintf( m_fp, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
|
|
|
|
fprintf( m_fp, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
|
|
|
|
fprintf( m_fp, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
|
|
|
|
fprintf( m_fp, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
|
|
|
|
fprintf( m_fp, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() );
|
|
|
|
fprintf( m_fp, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() );
|
|
|
|
fprintf( m_fp, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() );
|
|
|
|
fprintf( m_fp, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() );
|
|
|
|
fprintf( m_fp, "$EndSHEETDESCR\n\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void LEGACY_PLUGIN::saveSETUP( const BOARD* aBoard ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2012-04-17 02:58:03 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR netclass_default = bds.GetDefault();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "$SETUP\n" );
|
|
|
|
|
|
|
|
/* Internal units are nobody's business, they are internal.
|
|
|
|
Units used in the file are now in the "Units" attribute of $GENERAL.
|
2012-05-11 09:02:35 +00:00
|
|
|
fprintf( m_fp,, "InternalUnit %f INCH\n", 1.0 / PCB_LEGACY_INTERNAL_UNIT );
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "Layers %d\n", aBoard->GetCopperLayerCount() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
unsigned layerMask = ALL_CU_LAYERS & aBoard->GetEnabledLayers();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
for( LAYER_NUM layer = FIRST_LAYER; layer <= LAST_COPPER_LAYER; ++layer )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layerMask & MASK( layer ) )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, "Layer[%d] %s %s\n", layer,
|
2012-04-17 02:58:03 +00:00
|
|
|
TO_UTF8( aBoard->GetLayerName( layer ) ),
|
|
|
|
LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save current default track width, for compatibility with older Pcbnew version;
|
2014-05-13 09:22:51 +00:00
|
|
|
fprintf( m_fp, "TrackWidth %s\n",
|
|
|
|
fmtBIU( aBoard->GetDesignSettings().GetCurrentTrackWidth() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// Save custom tracks width list (the first is not saved here: this is the netclass value
|
2014-05-13 09:22:51 +00:00
|
|
|
for( unsigned ii = 1; ii < aBoard->GetDesignSettings().m_TrackWidthList.size(); ii++ )
|
|
|
|
fprintf( m_fp, "TrackWidthList %s\n", fmtBIU( aBoard->GetDesignSettings().m_TrackWidthList[ii] ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "TrackClearence %s\n", fmtBIU( netclass_default->GetClearance() ).c_str() );
|
|
|
|
|
|
|
|
// ZONE_SETTINGS
|
2012-04-17 02:58:03 +00:00
|
|
|
fprintf( m_fp, "ZoneClearence %s\n", fmtBIU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
|
|
|
|
fprintf( m_fp, "Zone_45_Only %d\n", aBoard->GetZoneSettings().m_Zone_45_Only );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "TrackMinWidth %s\n", fmtBIU( bds.m_TrackMinWidth ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "DrawSegmWidth %s\n", fmtBIU( bds.m_DrawSegmentWidth ).c_str() );
|
|
|
|
fprintf( m_fp, "EdgeSegmWidth %s\n", fmtBIU( bds.m_EdgeSegmentWidth ).c_str() );
|
|
|
|
|
|
|
|
// Save current default via size, for compatibility with older Pcbnew version;
|
|
|
|
fprintf( m_fp, "ViaSize %s\n", fmtBIU( netclass_default->GetViaDiameter() ).c_str() );
|
|
|
|
fprintf( m_fp, "ViaDrill %s\n", fmtBIU( netclass_default->GetViaDrill() ).c_str() );
|
|
|
|
fprintf( m_fp, "ViaMinSize %s\n", fmtBIU( bds.m_ViasMinSize ).c_str() );
|
|
|
|
fprintf( m_fp, "ViaMinDrill %s\n", fmtBIU( bds.m_ViasMinDrill ).c_str() );
|
|
|
|
|
|
|
|
// Save custom vias diameters list (the first is not saved here: this is
|
|
|
|
// the netclass value
|
2014-05-13 09:22:51 +00:00
|
|
|
for( unsigned ii = 1; ii < aBoard->GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
|
2012-04-07 18:05:56 +00:00
|
|
|
fprintf( m_fp, "ViaSizeList %s %s\n",
|
2014-05-13 09:22:51 +00:00
|
|
|
fmtBIU( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter ).c_str(),
|
|
|
|
fmtBIU( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// for old versions compatibility:
|
|
|
|
fprintf( m_fp, "MicroViaSize %s\n", fmtBIU( netclass_default->GetuViaDiameter() ).c_str() );
|
|
|
|
fprintf( m_fp, "MicroViaDrill %s\n", fmtBIU( netclass_default->GetuViaDrill() ).c_str() );
|
|
|
|
fprintf( m_fp, "MicroViasAllowed %s\n", fmtBIU( bds.m_MicroViasAllowed ).c_str() );
|
|
|
|
fprintf( m_fp, "MicroViaMinSize %s\n", fmtBIU( bds.m_MicroViasMinSize ).c_str() );
|
|
|
|
fprintf( m_fp, "MicroViaMinDrill %s\n", fmtBIU( bds.m_MicroViasMinDrill ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "TextPcbWidth %s\n", fmtBIU( bds.m_PcbTextWidth ).c_str() );
|
|
|
|
fprintf( m_fp, "TextPcbSize %s\n", fmtBIUSize( bds.m_PcbTextSize ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "EdgeModWidth %s\n", fmtBIU( bds.m_ModuleSegmentWidth ).c_str() );
|
|
|
|
fprintf( m_fp, "TextModSize %s\n", fmtBIUSize( bds.m_ModuleTextSize ).c_str() );
|
|
|
|
fprintf( m_fp, "TextModWidth %s\n", fmtBIU( bds.m_ModuleTextWidth ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "PadSize %s\n", fmtBIUSize( bds.m_Pad_Master.GetSize() ).c_str() );
|
|
|
|
fprintf( m_fp, "PadDrill %s\n", fmtBIU( bds.m_Pad_Master.GetDrillSize().x ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Pad2MaskClearance %s\n", fmtBIU( bds.m_SolderMaskMargin ).c_str() );
|
2012-11-05 20:20:34 +00:00
|
|
|
fprintf( m_fp, "SolderMaskMinWidth %s\n", fmtBIU( bds.m_SolderMaskMinWidth ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( bds.m_SolderPasteMargin != 0 )
|
|
|
|
fprintf( m_fp, "Pad2PasteClearance %s\n", fmtBIU( bds.m_SolderPasteMargin ).c_str() );
|
|
|
|
|
|
|
|
if( bds.m_SolderPasteMarginRatio != 0 )
|
|
|
|
fprintf( m_fp, "Pad2PasteClearanceRatio %g\n", bds.m_SolderPasteMarginRatio );
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
fprintf( m_fp, "GridOrigin %s\n", fmtBIUPoint( aBoard->GetGridOrigin() ).c_str() );
|
|
|
|
fprintf( m_fp, "AuxiliaryAxisOrg %s\n", fmtBIUPoint( aBoard->GetAuxOrigin() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-08 19:01:54 +00:00
|
|
|
fprintf( m_fp, "VisibleElements %X\n", bds.GetVisibleElements() );
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
STRING_FORMATTER sf;
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
aBoard->GetPlotOptions().Format( &sf, 0 );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
wxString record = FROM_UTF8( sf.GetString().c_str() );
|
|
|
|
|
|
|
|
record.Replace( wxT("\n"), wxT(""), true );
|
|
|
|
record.Replace( wxT(" "), wxT(" "), true);
|
|
|
|
|
|
|
|
fprintf( m_fp, "PcbPlotParams %s\n", TO_UTF8( record ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "$EndSETUP\n\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void LEGACY_PLUGIN::saveBOARD_ITEMS( const BOARD* aBoard ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// save the nets
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
|
|
|
|
net != netEnd; ++net )
|
|
|
|
{
|
|
|
|
saveNETINFO_ITEM( *net );
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// Saved nets do not include netclass names, so save netclasses after nets.
|
2014-05-13 09:22:51 +00:00
|
|
|
saveNETCLASSES( &aBoard->GetDesignSettings().m_NetClasses );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// save the modules
|
2012-04-17 02:58:03 +00:00
|
|
|
for( MODULE* m = aBoard->m_Modules; m; m = (MODULE*) m->Next() )
|
2014-06-24 16:17:18 +00:00
|
|
|
saveMODULE( m );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// save the graphics owned by the board (not owned by a module)
|
2012-04-17 02:58:03 +00:00
|
|
|
for( BOARD_ITEM* gr = aBoard->m_Drawings; gr; gr = gr->Next() )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
switch( gr->Type() )
|
|
|
|
{
|
|
|
|
case PCB_TEXT_T:
|
|
|
|
savePCB_TEXT( (TEXTE_PCB*) gr );
|
|
|
|
break;
|
|
|
|
case PCB_LINE_T:
|
|
|
|
savePCB_LINE( (DRAWSEGMENT*) gr );
|
|
|
|
break;
|
|
|
|
case PCB_TARGET_T:
|
|
|
|
savePCB_TARGET( (PCB_TARGET*) gr );
|
|
|
|
break;
|
|
|
|
case PCB_DIMENSION_T:
|
2014-05-13 09:22:51 +00:00
|
|
|
saveDIMENSION( (DIMENSION*) gr );
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, gr->Type() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do not save MARKER_PCBs, they can be regenerated easily
|
|
|
|
|
|
|
|
// save the tracks & vias
|
|
|
|
fprintf( m_fp, "$TRACK\n" );
|
2012-04-17 02:58:03 +00:00
|
|
|
for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
|
2012-04-07 18:05:56 +00:00
|
|
|
saveTRACK( track );
|
|
|
|
fprintf( m_fp, "$EndTRACK\n" );
|
|
|
|
|
|
|
|
// save the old obsolete zones which were done by segments (tracks)
|
|
|
|
fprintf( m_fp, "$ZONE\n" );
|
2012-04-17 02:58:03 +00:00
|
|
|
for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() )
|
2012-04-07 18:05:56 +00:00
|
|
|
saveTRACK( zone );
|
|
|
|
fprintf( m_fp, "$EndZONE\n" );
|
|
|
|
|
|
|
|
// save the polygon (which are the newer technology) zones
|
2012-04-17 02:58:03 +00:00
|
|
|
for( int i=0; i < aBoard->GetAreaCount(); ++i )
|
|
|
|
saveZONE_CONTAINER( aBoard->GetArea( i ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "$EndBOARD\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$EQUIPOT\n" );
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
fprintf( m_fp, "Na %d %s\n", m_mapping->Translate( aNet->GetNet() ),
|
|
|
|
EscapedUTF8( aNet->GetNetname() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
fprintf( m_fp, "St %s\n", "~" );
|
|
|
|
fprintf( m_fp, "$EndEQUIPOT\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void LEGACY_PLUGIN::saveNETCLASSES( const NETCLASSES* aNetClasses ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// save the default first.
|
2012-04-17 02:58:03 +00:00
|
|
|
saveNETCLASS( aNetClasses->GetDefault() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// the rest will be alphabetical in the *.brd file.
|
2012-04-17 02:58:03 +00:00
|
|
|
for( NETCLASSES::const_iterator it = aNetClasses->begin(); it != aNetClasses->end(); ++it )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR netclass = it->second;
|
2012-04-07 18:05:56 +00:00
|
|
|
saveNETCLASS( netclass );
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-20 09:29:37 +00:00
|
|
|
void LEGACY_PLUGIN::saveNETCLASS( const NETCLASSPTR nc ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, "$NCLASS\n" );
|
|
|
|
fprintf( m_fp, "Name %s\n", EscapedUTF8( nc->GetName() ).c_str() );
|
|
|
|
fprintf( m_fp, "Desc %s\n", EscapedUTF8( nc->GetDescription() ).c_str() );
|
|
|
|
|
2012-04-08 23:32:32 +00:00
|
|
|
fprintf( m_fp, "Clearance %s\n", fmtBIU( nc->GetClearance() ).c_str() );
|
|
|
|
fprintf( m_fp, "TrackWidth %s\n", fmtBIU( nc->GetTrackWidth() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-08 23:32:32 +00:00
|
|
|
fprintf( m_fp, "ViaDia %s\n", fmtBIU( nc->GetViaDiameter() ).c_str() );
|
|
|
|
fprintf( m_fp, "ViaDrill %s\n", fmtBIU( nc->GetViaDrill() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-04-08 23:32:32 +00:00
|
|
|
fprintf( m_fp, "uViaDia %s\n", fmtBIU( nc->GetuViaDiameter() ).c_str() );
|
|
|
|
fprintf( m_fp, "uViaDrill %s\n", fmtBIU( nc->GetuViaDrill() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
for( NETCLASS::const_iterator it = nc->begin(); it!=nc->end(); ++it )
|
|
|
|
fprintf( m_fp, "AddNet %s\n", EscapedUTF8( *it ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "$EndNCLASS\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::saveMODULE_TEXT( const TEXTE_MODULE* me ) const
|
|
|
|
{
|
|
|
|
MODULE* parent = (MODULE*) me->GetParent();
|
|
|
|
double orient = me->GetOrientation();
|
|
|
|
|
|
|
|
// Due to the Pcbnew history, m_Orient is saved in screen value
|
|
|
|
// but it is handled as relative to its parent footprint
|
|
|
|
if( parent )
|
|
|
|
orient += parent->GetOrientation();
|
|
|
|
|
|
|
|
wxString txt = me->GetText();
|
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
fprintf( m_fp, "T%d %s %s %s %s %c %c %d %c %s",
|
2012-04-07 18:05:56 +00:00
|
|
|
me->GetType(),
|
|
|
|
fmtBIUPoint( me->GetPos0() ).c_str(), // m_Pos0.x, m_Pos0.y,
|
2012-08-11 19:14:45 +00:00
|
|
|
|
|
|
|
// legacy has goofed reversed order: ( y, x )
|
|
|
|
fmtBIUPair( me->GetSize().y, me->GetSize().x ).c_str(),
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtDEG( orient ).c_str(),
|
|
|
|
fmtBIU( me->GetThickness() ).c_str(), // m_Thickness,
|
|
|
|
me->IsMirrored() ? 'M' : 'N',
|
|
|
|
me->IsVisible() ? 'V' : 'I',
|
|
|
|
me->GetLayer(),
|
|
|
|
me->IsItalic() ? 'I' : 'N',
|
|
|
|
EscapedUTF8( txt ).c_str()
|
|
|
|
);
|
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
if( me->GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER ||
|
|
|
|
me->GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, " %s %s\n",
|
|
|
|
ShowHorizJustify( me->GetHorizJustify() ),
|
|
|
|
ShowVertJustify( me->GetVertJustify() )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf( m_fp, "\n" );
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::saveMODULE_EDGE( const EDGE_MODULE* me ) const
|
|
|
|
{
|
|
|
|
switch( me->GetShape() )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
fprintf( m_fp, "DS %s %s %s %d\n",
|
|
|
|
fmtBIUPoint( me->m_Start0 ).c_str(),
|
|
|
|
fmtBIUPoint( me->m_End0 ).c_str(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str(),
|
|
|
|
me->GetLayer() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
fprintf( m_fp, "DC %s %s %s %d\n",
|
|
|
|
fmtBIUPoint( me->m_Start0 ).c_str(),
|
|
|
|
fmtBIUPoint( me->m_End0 ).c_str(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str(),
|
|
|
|
me->GetLayer() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
fprintf( m_fp, "DA %s %s %s %s %d\n",
|
|
|
|
fmtBIUPoint( me->m_Start0 ).c_str(),
|
|
|
|
fmtBIUPoint( me->m_End0 ).c_str(),
|
|
|
|
fmtDEG( me->GetAngle() ).c_str(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str(),
|
|
|
|
me->GetLayer() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
const std::vector<wxPoint>& polyPoints = me->GetPolyPoints();
|
|
|
|
|
|
|
|
fprintf( m_fp, "DP %s %s %d %s %d\n",
|
|
|
|
fmtBIUPoint( me->m_Start0 ).c_str(),
|
|
|
|
fmtBIUPoint( me->m_End0 ).c_str(),
|
|
|
|
(int) polyPoints.size(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str(),
|
|
|
|
me->GetLayer() );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i<polyPoints.size(); ++i )
|
|
|
|
fprintf( m_fp, "Dl %s\n", fmtBIUPoint( polyPoints[i] ).c_str() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, me->GetShape() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::savePAD( const D_PAD* me ) const
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$PAD\n" );
|
|
|
|
|
|
|
|
int cshape;
|
|
|
|
|
|
|
|
switch( me->GetShape() )
|
|
|
|
{
|
|
|
|
case PAD_CIRCLE: cshape = 'C'; break;
|
|
|
|
case PAD_RECT: cshape = 'R'; break;
|
|
|
|
case PAD_OVAL: cshape = 'O'; break;
|
|
|
|
case PAD_TRAPEZOID: cshape = 'T'; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_FORMAT, me->GetShape() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BOARD_FORMAT_VERSION == 1 // saving mode is a compile time option
|
|
|
|
|
|
|
|
wxString wpadname = me->GetPadName(); // universal character set padname
|
|
|
|
std::string spadname;
|
|
|
|
|
|
|
|
for( unsigned i = 0; wpadname.size(); ++i )
|
|
|
|
{
|
|
|
|
// truncate from universal character down to 8 bit foreign jibber
|
|
|
|
// jabber byte. This basically duplicates what was done in the old
|
|
|
|
// BOARD_FORMAT_VERSION 1 code. Any characters that were in the 8 bit
|
|
|
|
// character space were OK.
|
|
|
|
spadname += (char) wpadname[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "Sh \"%s\" %c %s %s %s\n",
|
|
|
|
spadname.c_str(), // probably ASCII, but possibly jibber jabber
|
|
|
|
#else
|
|
|
|
|
|
|
|
fprintf( m_fp, "Sh %s %c %s %s %s\n",
|
|
|
|
// legacy VERSION 2 simply uses UTF8, wrapped in quotes,
|
|
|
|
// and 99.99 % of the time there is no difference between 1 & 2,
|
|
|
|
// since ASCII is a subset of UTF8. But if they were not using
|
|
|
|
// ASCII pad names, then there is a difference in the file.
|
|
|
|
EscapedUTF8( me->GetPadName() ).c_str(),
|
|
|
|
#endif
|
|
|
|
cshape,
|
|
|
|
fmtBIUSize( me->GetSize() ).c_str(),
|
|
|
|
fmtBIUSize( me->GetDelta() ).c_str(),
|
|
|
|
fmtDEG( me->GetOrientation() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Dr %s %s",
|
|
|
|
fmtBIU( me->GetDrillSize().x ).c_str(),
|
|
|
|
fmtBIUPoint( me->GetOffset() ).c_str() );
|
|
|
|
|
2014-01-26 14:20:58 +00:00
|
|
|
if( me->GetDrillShape() == PAD_DRILL_OBLONG )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, " %c %s", 'O', fmtBIUSize( me->GetDrillSize() ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "\n" );
|
|
|
|
|
|
|
|
const char* texttype;
|
|
|
|
|
|
|
|
switch( me->GetAttribute() )
|
|
|
|
{
|
|
|
|
case PAD_STANDARD: texttype = "STD"; break;
|
|
|
|
case PAD_SMD: texttype = "SMD"; break;
|
|
|
|
case PAD_CONN: texttype = "CONN"; break;
|
|
|
|
case PAD_HOLE_NOT_PLATED: texttype = "HOLE"; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_ATTRIBUTE, me->GetAttribute() ) );
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
fprintf( m_fp, "At %s N %08X\n", texttype, me->GetLayerSet() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-05-25 15:36:24 +00:00
|
|
|
fprintf( m_fp, "Ne %d %s\n", m_mapping->Translate( me->GetNetCode() ),
|
|
|
|
EscapedUTF8( me->GetNetname() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "Po %s\n", fmtBIUPoint( me->GetPos0() ).c_str() );
|
|
|
|
|
2012-12-12 11:57:17 +00:00
|
|
|
if( me->GetPadToDieLength() != 0 )
|
|
|
|
fprintf( m_fp, "Le %s\n", fmtBIU( me->GetPadToDieLength() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->GetLocalSolderMaskMargin() != 0 )
|
|
|
|
fprintf( m_fp, ".SolderMask %s\n", fmtBIU( me->GetLocalSolderMaskMargin() ).c_str() );
|
|
|
|
|
|
|
|
if( me->GetLocalSolderPasteMargin() != 0 )
|
|
|
|
fprintf( m_fp, ".SolderPaste %s\n", fmtBIU( me->GetLocalSolderPasteMargin() ).c_str() );
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
double ratio = me->GetLocalSolderPasteMarginRatio();
|
|
|
|
if( ratio != 0.0 )
|
|
|
|
fprintf( m_fp, ".SolderPasteRatio %g\n", ratio );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->GetLocalClearance() != 0 )
|
|
|
|
fprintf( m_fp, ".LocalClearance %s\n", fmtBIU( me->GetLocalClearance( ) ).c_str() );
|
|
|
|
|
|
|
|
if( me->GetZoneConnection() != UNDEFINED_CONNECTION )
|
|
|
|
fprintf( m_fp, ".ZoneConnection %d\n", me->GetZoneConnection() );
|
|
|
|
|
|
|
|
if( me->GetThermalWidth() != 0 )
|
2012-11-24 16:02:10 +00:00
|
|
|
fprintf( m_fp, ".ThermalWidth %s\n", fmtBIU( me->GetThermalWidth() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->GetThermalGap() != 0 )
|
2012-11-24 16:02:10 +00:00
|
|
|
fprintf( m_fp, ".ThermalGap %s\n", fmtBIU( me->GetThermalGap() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "$EndPAD\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
void LEGACY_PLUGIN::saveMODULE( const MODULE* me ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
char statusTxt[3];
|
|
|
|
double orient = me->GetOrientation();
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
// Do not save full FPID. Only the footprint name. The legacy file format should
|
|
|
|
// never support FPIDs.
|
|
|
|
fprintf( m_fp, "$MODULE %s\n", me->GetFPID().GetFootprintName().c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
statusTxt[0] = me->IsLocked() ? 'F' : '~';
|
|
|
|
statusTxt[1] = me->IsPlaced() ? 'P' : '~';
|
|
|
|
statusTxt[2] = '\0';
|
|
|
|
|
|
|
|
fprintf( m_fp, "Po %s %s %d %08lX %08lX %s\n",
|
|
|
|
fmtBIUPoint( me->GetPosition() ).c_str(), // m_Pos.x, m_Pos.y,
|
|
|
|
fmtDEG( orient ).c_str(),
|
|
|
|
me->GetLayer(),
|
|
|
|
me->GetLastEditTime(),
|
|
|
|
me->GetTimeStamp(),
|
|
|
|
statusTxt );
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
fprintf( m_fp, "Li %s\n", me->GetFPID().GetFootprintName().c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( !me->GetDescription().IsEmpty() )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "Cd %s\n", TO_UTF8( me->GetDescription() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !me->GetKeywords().IsEmpty() )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "Kw %s\n", TO_UTF8( me->GetKeywords() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "Sc %lX\n", me->GetTimeStamp() );
|
|
|
|
fprintf( m_fp, "AR %s\n", TO_UTF8( me->GetPath() ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
fprintf( m_fp, "Op %X %X 0\n", me->GetPlacementCost90(), me->GetPlacementCost180() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->GetLocalSolderMaskMargin() != 0 )
|
|
|
|
fprintf( m_fp, ".SolderMask %s\n", fmtBIU( me->GetLocalSolderMaskMargin() ).c_str() );
|
|
|
|
|
|
|
|
if( me->GetLocalSolderPasteMargin() != 0 )
|
|
|
|
fprintf( m_fp, ".SolderPaste %s\n", fmtBIU( me->GetLocalSolderPasteMargin() ).c_str() );
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
double ratio = me->GetLocalSolderPasteMarginRatio();
|
|
|
|
if( ratio != 0.0 )
|
|
|
|
fprintf( m_fp, ".SolderPasteRatio %g\n", ratio );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->GetLocalClearance() != 0 )
|
|
|
|
fprintf( m_fp, ".LocalClearance %s\n", fmtBIU( me->GetLocalClearance( ) ).c_str() );
|
|
|
|
|
|
|
|
if( me->GetZoneConnection() != UNDEFINED_CONNECTION )
|
|
|
|
fprintf( m_fp, ".ZoneConnection %d\n", me->GetZoneConnection() );
|
|
|
|
|
|
|
|
if( me->GetThermalWidth() != 0 )
|
2012-11-24 16:02:10 +00:00
|
|
|
fprintf( m_fp, ".ThermalWidth %s\n", fmtBIU( me->GetThermalWidth() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->GetThermalGap() != 0 )
|
2012-11-24 16:02:10 +00:00
|
|
|
fprintf( m_fp, ".ThermalGap %s\n", fmtBIU( me->GetThermalGap() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// attributes
|
|
|
|
if( me->GetAttributes() != MOD_DEFAULT )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "At" );
|
|
|
|
|
|
|
|
if( me->GetAttributes() & MOD_CMS )
|
|
|
|
fprintf( m_fp, " SMD" );
|
|
|
|
|
|
|
|
if( me->GetAttributes() & MOD_VIRTUAL )
|
|
|
|
fprintf( m_fp, " VIRTUAL" );
|
|
|
|
|
|
|
|
fprintf( m_fp, "\n" );
|
|
|
|
}
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
saveMODULE_TEXT( &me->Reference() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
saveMODULE_TEXT( &me->Value() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// save drawing elements
|
2013-03-18 19:36:07 +00:00
|
|
|
for( BOARD_ITEM* gr = me->GraphicalItems(); gr; gr = gr->Next() )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
switch( gr->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
saveMODULE_TEXT( static_cast<TEXTE_MODULE*>( gr ));
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2014-09-10 15:18:42 +00:00
|
|
|
saveMODULE_EDGE( static_cast<EDGE_MODULE*>( gr ));
|
2012-04-07 18:05:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, gr->Type() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
for( D_PAD* pad = me->Pads(); pad; pad = pad->Next() )
|
2012-04-07 18:05:56 +00:00
|
|
|
savePAD( pad );
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
SaveModule3D( me );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
fprintf( m_fp, "$EndMODULE %s\n", me->GetFPID().GetFootprintName().c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::savePCB_TARGET( const PCB_TARGET* me ) const
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$PCB_TARGET\n" );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Po %X %d %s %s %s %lX\n",
|
|
|
|
me->GetShape(),
|
|
|
|
me->GetLayer(),
|
|
|
|
fmtBIUPoint( me->GetPosition() ).c_str(),
|
|
|
|
fmtBIU( me->GetSize() ).c_str(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str(),
|
|
|
|
me->GetTimeStamp()
|
|
|
|
);
|
|
|
|
|
|
|
|
fprintf( m_fp, "$EndPCB_TARGET\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::savePCB_LINE( const DRAWSEGMENT* me ) const
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$DRAWSEGMENT\n" );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Po %d %s %s %s\n",
|
|
|
|
me->GetShape(),
|
|
|
|
fmtBIUPoint( me->GetStart() ).c_str(),
|
|
|
|
fmtBIUPoint( me->GetEnd() ).c_str(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
if( me->GetType() != S_CURVE )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "De %d %d %s %lX %X\n",
|
|
|
|
me->GetLayer(),
|
|
|
|
me->GetType(),
|
|
|
|
fmtDEG( me->GetAngle() ).c_str(),
|
|
|
|
me->GetTimeStamp(),
|
|
|
|
me->GetStatus()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "De %d %d %s %lX %X %s %s\n",
|
|
|
|
me->GetLayer(),
|
|
|
|
me->GetType(),
|
|
|
|
fmtDEG( me->GetAngle() ).c_str(),
|
|
|
|
me->GetTimeStamp(),
|
|
|
|
me->GetStatus(),
|
|
|
|
fmtBIUPoint( me->GetBezControl1() ).c_str(),
|
|
|
|
fmtBIUPoint( me->GetBezControl2() ).c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "$EndDRAWSEGMENT\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::saveTRACK( const TRACK* me ) const
|
|
|
|
{
|
|
|
|
int type = 0;
|
2014-04-25 06:00:04 +00:00
|
|
|
VIATYPE_T viatype = VIA_NOT_DEFINED;
|
|
|
|
int drill = UNDEFINED_DRILL_DIAMETER;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
if( me->Type() == PCB_VIA_T )
|
2014-04-25 06:00:04 +00:00
|
|
|
{
|
|
|
|
const VIA *via = static_cast<const VIA *>(me);
|
2012-04-07 18:05:56 +00:00
|
|
|
type = 1;
|
2014-04-25 06:00:04 +00:00
|
|
|
viatype = via->GetViaType();
|
|
|
|
drill = via->GetDrill();
|
|
|
|
}
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf(m_fp, "Po %d %s %s %s %s\n",
|
2014-04-25 06:00:04 +00:00
|
|
|
viatype,
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIUPoint( me->GetStart() ).c_str(),
|
|
|
|
fmtBIUPoint( me->GetEnd() ).c_str(),
|
|
|
|
fmtBIU( me->GetWidth() ).c_str(),
|
2014-04-25 06:00:04 +00:00
|
|
|
drill == UNDEFINED_DRILL_DIAMETER ?
|
|
|
|
"-1" : fmtBIU( drill ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf(m_fp, "De %d %d %d %lX %X\n",
|
2014-05-25 15:36:24 +00:00
|
|
|
me->GetLayer(), type, m_mapping->Translate( me->GetNetCode() ),
|
2012-04-07 18:05:56 +00:00
|
|
|
me->GetTimeStamp(), me->GetStatus() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::saveZONE_CONTAINER( const ZONE_CONTAINER* me ) const
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$CZONE_OUTLINE\n" );
|
|
|
|
|
|
|
|
// Save the outline main info
|
2013-03-01 19:59:29 +00:00
|
|
|
// For keepout zones, net code and net name are irrelevant, so we store a dummy value
|
|
|
|
// just for ZONE_CONTAINER compatibility
|
2012-04-07 18:05:56 +00:00
|
|
|
fprintf( m_fp, "ZInfo %lX %d %s\n",
|
2013-03-01 19:59:29 +00:00
|
|
|
me->GetTimeStamp(),
|
2014-05-25 15:36:24 +00:00
|
|
|
me->GetIsKeepout() ? 0 : m_mapping->Translate( me->GetNetCode() ),
|
2014-01-14 10:41:06 +00:00
|
|
|
EscapedUTF8( me->GetIsKeepout() ? wxT("") : me->GetNetname() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
// Save the outline layer info
|
|
|
|
fprintf( m_fp, "ZLayer %d\n", me->GetLayer() );
|
|
|
|
|
|
|
|
// Save the outline aux info
|
|
|
|
int outline_hatch;
|
|
|
|
|
|
|
|
switch( me->GetHatchStyle() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case CPolyLine::NO_HATCH: outline_hatch = 'N'; break;
|
|
|
|
case CPolyLine::DIAGONAL_EDGE: outline_hatch = 'E'; break;
|
|
|
|
case CPolyLine::DIAGONAL_FULL: outline_hatch = 'F'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "ZAux %d %c\n", me->GetNumCorners(), outline_hatch );
|
|
|
|
|
|
|
|
if( me->GetPriority() > 0 )
|
|
|
|
fprintf( m_fp, "ZPriority %d\n", me->GetPriority() );
|
|
|
|
|
|
|
|
// Save pad option and clearance
|
|
|
|
char padoption;
|
|
|
|
|
|
|
|
switch( me->GetPadConnection() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case PAD_IN_ZONE: padoption = 'I'; break;
|
|
|
|
case THERMAL_PAD: padoption = 'T'; break;
|
2012-07-09 07:10:07 +00:00
|
|
|
case THT_THERMAL: padoption = 'H'; break; // H is for 'hole' since it reliefs holes only
|
2012-04-07 18:05:56 +00:00
|
|
|
case PAD_NOT_IN_ZONE: padoption = 'X'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "ZClearance %s %c\n",
|
|
|
|
fmtBIU( me->GetZoneClearance() ).c_str(),
|
|
|
|
padoption );
|
|
|
|
|
|
|
|
fprintf( m_fp, "ZMinThickness %s\n", fmtBIU( me->GetMinThickness() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "ZOptions %d %d %c %s %s\n",
|
|
|
|
me->GetFillMode(),
|
2013-03-18 19:36:07 +00:00
|
|
|
me->GetArcSegmentCount(),
|
2012-04-07 18:05:56 +00:00
|
|
|
me->IsFilled() ? 'S' : 'F',
|
|
|
|
fmtBIU( me->GetThermalReliefGap() ).c_str(),
|
|
|
|
fmtBIU( me->GetThermalReliefCopperBridge() ).c_str() );
|
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
if( me->GetIsKeepout() )
|
|
|
|
{
|
2012-07-14 16:27:25 +00:00
|
|
|
fprintf( m_fp, "ZKeepout tracks %c vias %c copperpour %c\n",
|
2012-07-13 18:55:29 +00:00
|
|
|
me->GetDoNotAllowTracks() ? 'N' : 'Y',
|
|
|
|
me->GetDoNotAllowVias() ? 'N' : 'Y',
|
2012-07-14 16:27:25 +00:00
|
|
|
me->GetDoNotAllowCopperPour() ? 'N' : 'Y' );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
fprintf( m_fp, "ZSmoothing %d %s\n",
|
|
|
|
me->GetCornerSmoothingType(),
|
|
|
|
fmtBIU( me->GetCornerRadius() ).c_str() );
|
|
|
|
|
|
|
|
// Save the corner list
|
2013-05-03 17:51:10 +00:00
|
|
|
const CPOLYGONS_LIST& cv = me->Outline()->m_CornersList;
|
2013-03-20 14:50:12 +00:00
|
|
|
|
2013-05-09 19:08:12 +00:00
|
|
|
for( unsigned it = 0; it < cv.GetCornersCount(); ++it )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, "ZCorner %s %d\n",
|
2013-05-08 18:20:58 +00:00
|
|
|
fmtBIUPair( cv.GetX( it ), cv.GetY( it ) ).c_str(),
|
|
|
|
cv.IsEndContour( it ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the PolysList
|
2013-05-03 17:51:10 +00:00
|
|
|
const CPOLYGONS_LIST& fv = me->GetFilledPolysList();
|
2013-05-09 19:08:12 +00:00
|
|
|
if( fv.GetCornersCount() )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, "$POLYSCORNERS\n" );
|
|
|
|
|
2013-05-09 19:08:12 +00:00
|
|
|
for( unsigned it = 0; it < fv.GetCornersCount(); ++it )
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
fprintf( m_fp, "%s %d %d\n",
|
2013-05-08 18:20:58 +00:00
|
|
|
fmtBIUPair( fv.GetX( it ), fv.GetY( it ) ).c_str(),
|
|
|
|
fv.IsEndContour( it ),
|
|
|
|
fv.GetUtility( it ) );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "$endPOLYSCORNERS\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::vector< SEGMENT > SEGMENTS;
|
|
|
|
|
|
|
|
// Save the filling segments list
|
2013-03-20 14:50:12 +00:00
|
|
|
const SEGMENTS& segs = me->FillSegments();
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
if( segs.size() )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "$FILLSEGMENTS\n" );
|
|
|
|
|
|
|
|
for( SEGMENTS::const_iterator it = segs.begin(); it != segs.end(); ++it )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, "%s %s\n",
|
|
|
|
fmtBIUPoint( it->m_Start ).c_str(),
|
|
|
|
fmtBIUPoint( it->m_End ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "$endFILLSEGMENTS\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( m_fp, "$endCZONE_OUTLINE\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
void LEGACY_PLUGIN::saveDIMENSION( const DIMENSION* me ) const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
|
|
|
// note: COTATION was the previous name of DIMENSION
|
|
|
|
// this old keyword is used here for compatibility
|
|
|
|
fprintf( m_fp, "$COTATION\n" );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Ge %d %d %lX\n", me->GetShape(), me->GetLayer(), me->GetTimeStamp() );
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
fprintf( m_fp, "Va %s\n", fmtBIU( me->GetValue() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !me->GetText().IsEmpty() )
|
|
|
|
fprintf( m_fp, "Te %s\n", EscapedUTF8( me->GetText() ).c_str() );
|
2012-04-07 18:05:56 +00:00
|
|
|
else
|
|
|
|
fprintf( m_fp, "Te \"?\"\n" );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Po %s %s %s %s %d\n",
|
2013-03-18 19:36:07 +00:00
|
|
|
fmtBIUPoint( me->Text().GetTextPosition() ).c_str(),
|
2013-03-13 18:53:58 +00:00
|
|
|
fmtBIUSize( me->Text().GetSize() ).c_str(),
|
|
|
|
fmtBIU( me->Text().GetThickness() ).c_str(),
|
|
|
|
fmtDEG( me->Text().GetOrientation() ).c_str(),
|
|
|
|
me->Text().IsMirrored() ? 0 : 1 // strange but true
|
2012-04-07 18:05:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
fprintf( m_fp, "Sb %d %s %s %s\n", S_SEGMENT,
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(),
|
|
|
|
fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Sd %d %s %s %s\n", S_SEGMENT,
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_featureLineDO.x, me->m_featureLineDO.y ).c_str(),
|
|
|
|
fmtBIUPair( me->m_featureLineDF.x, me->m_featureLineDF.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "Sg %d %s %s %s\n", S_SEGMENT,
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_featureLineGO.x, me->m_featureLineGO.y ).c_str(),
|
|
|
|
fmtBIUPair( me->m_featureLineGF.x, me->m_featureLineGF.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "S1 %d %s %s %s\n", S_SEGMENT,
|
2014-02-11 12:22:30 +00:00
|
|
|
fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(),
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_arrowD1F.x, me->m_arrowD1F.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "S2 %d %s %s %s\n", S_SEGMENT,
|
2014-02-11 12:22:30 +00:00
|
|
|
fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(),
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_arrowD2F.x, me->m_arrowD2F.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "S3 %d %s %s %s\n", S_SEGMENT,
|
2014-02-11 12:22:30 +00:00
|
|
|
fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(),
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_arrowG1F.x, me->m_arrowG1F.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "S4 %d %s %s %s\n", S_SEGMENT,
|
2014-02-11 12:22:30 +00:00
|
|
|
fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(),
|
2012-12-19 19:31:36 +00:00
|
|
|
fmtBIUPair( me->m_arrowG2F.x, me->m_arrowG2F.y ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIU( me->GetWidth() ).c_str() );
|
|
|
|
|
|
|
|
fprintf( m_fp, "$endCOTATION\n" );
|
|
|
|
|
|
|
|
CHECK_WRITE_ERROR();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LEGACY_PLUGIN::savePCB_TEXT( const TEXTE_PCB* me ) const
|
|
|
|
{
|
|
|
|
if( me->GetText().IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf( m_fp, "$TEXTPCB\n" );
|
|
|
|
|
|
|
|
wxArrayString* list = wxStringSplit( me->GetText(), '\n' );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < list->Count(); ii++ )
|
|
|
|
{
|
|
|
|
wxString txt = list->Item( ii );
|
|
|
|
|
|
|
|
if ( ii == 0 )
|
|
|
|
fprintf( m_fp, "Te %s\n", EscapedUTF8( txt ).c_str() );
|
|
|
|
else
|
|
|
|
fprintf( m_fp, "nl %s\n", EscapedUTF8( txt ).c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete list;
|
|
|
|
|
|
|
|
fprintf( m_fp, "Po %s %s %s %s\n",
|
2013-03-18 19:36:07 +00:00
|
|
|
fmtBIUPoint( me->GetTextPosition() ).c_str(),
|
2012-04-07 18:05:56 +00:00
|
|
|
fmtBIUSize( me->GetSize() ).c_str(),
|
|
|
|
fmtBIU( me->GetThickness() ).c_str(),
|
|
|
|
fmtDEG( me->GetOrientation() ).c_str() );
|
|
|
|
|
2012-08-11 19:14:45 +00:00
|
|
|
fprintf( m_fp, "De %d %d %lX %s",
|
2012-04-07 18:05:56 +00:00
|
|
|
me->GetLayer(),
|
|
|
|
!me->IsMirrored(),
|
|
|
|
me->GetTimeStamp(),
|
2012-08-11 19:14:45 +00:00
|
|
|
me->IsItalic() ? "Italic" : "Normal" );
|
|
|
|
|
|
|
|
if( me->GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER ||
|
|
|
|
me->GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER )
|
|
|
|
{
|
|
|
|
fprintf( m_fp, " %s %s\n",
|
|
|
|
ShowHorizJustify( me->GetHorizJustify() ),
|
|
|
|
ShowVertJustify( me->GetVertJustify() )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf( m_fp, "\n" );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
fprintf( m_fp, "$EndTEXTPCB\n" );
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#endif // NO LEGACY_PLUGIN::Save()
|
|
|
|
|
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
|
|
|
|
would have to re-read the file when searching for any MODULE, and this would
|
|
|
|
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
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
typedef boost::ptr_map< std::string, MODULE > MODULE_MAP;
|
2012-04-16 03:18:41 +00:00
|
|
|
typedef MODULE_MAP::iterator MODULE_ITER;
|
|
|
|
typedef MODULE_MAP::const_iterator MODULE_CITER;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-22 04:38:22 +00:00
|
|
|
* Class LP_CACHE
|
2012-04-16 03:18:41 +00:00
|
|
|
* assists only for 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.
|
|
|
|
*/
|
2013-09-22 04:38:22 +00:00
|
|
|
struct LP_CACHE
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LEGACY_PLUGIN* m_owner; // my owner, I need its LEGACY_PLUGIN::loadMODULE()
|
2013-01-02 04:05:48 +00:00
|
|
|
wxString m_lib_path;
|
2012-04-16 03:18:41 +00:00
|
|
|
wxDateTime m_mod_time;
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE_MAP m_modules; // map or tuple of footprint_name vs. MODULE*
|
2012-04-16 03:18:41 +00:00
|
|
|
bool m_writable;
|
|
|
|
|
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.
|
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
/// save the entire legacy library to m_lib_path;
|
2012-04-16 03:18:41 +00:00
|
|
|
void Save();
|
|
|
|
|
|
|
|
void SaveHeader( FILE* aFile );
|
|
|
|
|
|
|
|
void SaveIndex( FILE* aFile );
|
|
|
|
|
|
|
|
void SaveModules( FILE* aFile );
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
void SaveEndOfFile( FILE* aFile )
|
|
|
|
{
|
|
|
|
fprintf( aFile, "$EndLIBRARY\n" );
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
|
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 );
|
|
|
|
|
|
|
|
wxDateTime GetLibModificationTime();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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 ),
|
2012-04-17 01:35:43 +00:00
|
|
|
m_writable( true )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
wxDateTime LP_CACHE::GetLibModificationTime()
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
wxFileName fn( m_lib_path );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
// update the writable flag while we have a wxFileName, in a network this
|
|
|
|
// is possibly quite dynamic anyway.
|
2012-04-16 03:18:41 +00:00
|
|
|
m_writable = fn.IsFileWritable();
|
|
|
|
|
|
|
|
return fn.GetModificationTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::Load()
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
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.
|
|
|
|
m_mod_time = GetLibModificationTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2013-12-10 23:41:34 +00:00
|
|
|
char* saveptr;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
if( !line )
|
2012-04-17 01:35:43 +00:00
|
|
|
goto L_bad_library;
|
|
|
|
|
|
|
|
if( !TESTLINE( "PCBNEW-LibModule-V1" ) )
|
|
|
|
goto L_bad_library;
|
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = aReader->ReadLine() ) != NULL )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( TESTLINE( "Units" ) )
|
|
|
|
{
|
2013-12-10 23:41:34 +00:00
|
|
|
const char* units = strtok_r( line + SZ( "Units" ), delims, &saveptr );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !strcmp( units, "mm" ) )
|
|
|
|
{
|
2012-06-17 16:06:12 +00:00
|
|
|
m_owner->diskToBiu = IU_PER_MM;
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if( TESTLINE( "$INDEX" ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
L_bad_library:
|
2014-01-19 13:12:57 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "File '%s' is empty or is not a legacy library" ),
|
2013-01-02 04:05:48 +00:00
|
|
|
m_lib_path.GetData() ) );
|
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;
|
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
while( ( line = aReader->ReadLine() ) != NULL )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
if( TESTLINE( "$EndINDEX" ) )
|
|
|
|
{
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( exit )
|
|
|
|
break;
|
2012-11-27 13:50:01 +00:00
|
|
|
} while( ( line = aReader->ReadLine() ) != NULL );
|
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" ) )
|
|
|
|
{
|
2013-06-13 16:09:35 +00:00
|
|
|
auto_ptr<MODULE> module( new MODULE( m_owner->m_board ) );
|
|
|
|
|
|
|
|
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 ':'
|
|
|
|
// characters which will cause the FPID parser to choke.
|
|
|
|
ReplaceIllegalFileNameChars( &footprintName );
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
// set the footprint name first thing, so exceptions can use name.
|
2013-09-08 18:31:21 +00:00
|
|
|
module->SetFPID( FPID( footprintName ) );
|
2013-06-13 16:09:35 +00:00
|
|
|
|
|
|
|
#if 0 && defined( DEBUG )
|
|
|
|
printf( "%s\n", footprintName.c_str() );
|
|
|
|
if( footprintName == "QFN40" )
|
|
|
|
{
|
|
|
|
int breakhere = 1;
|
|
|
|
(void) breakhere;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
m_owner->loadMODULE( module.get() );
|
2013-06-13 16:09:35 +00:00
|
|
|
|
|
|
|
MODULE* m = module.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.
|
|
|
|
// wxASSERT( footprintName == m->GetFPID().GetFootprintName() );
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
MODULE_CITER it = m_modules.find( footprintName );
|
|
|
|
|
|
|
|
if( it == m_modules.end() ) // footprintName is not present in cache yet.
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-05-09 00:26:15 +00:00
|
|
|
std::pair<MODULE_ITER, bool> r = m_modules.insert( footprintName, m );
|
|
|
|
|
|
|
|
wxASSERT_MSG( r.second, wxT( "error doing cache insert using guaranteed unique name" ) );
|
|
|
|
(void) r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bad library has a duplicate of this footprintName, generate a
|
|
|
|
// unique footprint name and load it anyway.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
it = m_modules.find( newName );
|
|
|
|
|
|
|
|
if( it == m_modules.end() )
|
|
|
|
{
|
|
|
|
nameOK = true;
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
m->SetFPID( FPID( newName ) );
|
2012-05-09 00:26:15 +00:00
|
|
|
std::pair<MODULE_ITER, bool> r = m_modules.insert( newName, m );
|
|
|
|
|
|
|
|
wxASSERT_MSG( r.second, wxT( "error doing cache insert using guaranteed unique name" ) );
|
|
|
|
(void) r;
|
|
|
|
}
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 13:50:01 +00:00
|
|
|
} while( ( line = aReader->ReadLine() ) != NULL );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#if 0
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::Save()
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
if( !m_writable )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2014-01-19 13:12:57 +00:00
|
|
|
_( "Legacy library file '%s' is read only" ), m_lib_path.GetData() ) );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 15:41:08 +00:00
|
|
|
wxString tempFileName;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-18 12:24:40 +00:00
|
|
|
// a block {} scope to fire wxFFile wxf()'s destructor
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-08-28 15:41:08 +00:00
|
|
|
// CreateTempFileName works better with an absolute path
|
2013-01-02 04:05:48 +00:00
|
|
|
wxFileName abs_lib_name( m_lib_path );
|
2012-08-28 15:41:08 +00:00
|
|
|
|
|
|
|
abs_lib_name.MakeAbsolute();
|
|
|
|
tempFileName = wxFileName::CreateTempFileName( abs_lib_name.GetFullPath() );
|
|
|
|
|
2013-07-28 16:30:39 +00:00
|
|
|
//wxLogDebug( wxT( "tempFileName:'%s' m_lib_path:'%s'\n" ), TO_UTF8( tempFileName ), TO_UTF8( m_lib_path ) );
|
2012-08-28 15:41:08 +00:00
|
|
|
|
2012-04-18 12:24:40 +00:00
|
|
|
FILE* fp = wxFopen( tempFileName, wxT( "w" ) );
|
|
|
|
if( !fp )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2014-01-19 13:12:57 +00:00
|
|
|
_( "Unable to open or create legacy library file '%s'" ),
|
2013-01-02 04:05:48 +00:00
|
|
|
m_lib_path.GetData() ) );
|
2012-04-18 12:24:40 +00:00
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-18 12:24:40 +00:00
|
|
|
// wxf now owns fp, will close on exception or exit from
|
|
|
|
// this block {} scope
|
|
|
|
wxFFile wxf( fp );
|
|
|
|
|
|
|
|
SaveHeader( fp );
|
2012-08-28 15:41:08 +00:00
|
|
|
SaveIndex( fp );
|
2012-04-18 12:24:40 +00:00
|
|
|
SaveModules( fp );
|
|
|
|
SaveEndOfFile( fp );
|
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-18 12:24:40 +00:00
|
|
|
// fp is now closed here, and that seems proper before trying to rename
|
2013-01-02 04:05:48 +00:00
|
|
|
// the temporary file to m_lib_path.
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2013-01-02 04:05:48 +00:00
|
|
|
wxRemove( m_lib_path ); // it is not an error if this does not exist
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
// Even on linux you can see an _intermittent_ error when calling wxRename(),
|
|
|
|
// and it is fully inexplicable. See if this dodges the error.
|
|
|
|
wxMilliSleep( 250L );
|
|
|
|
|
2014-10-23 20:25:04 +00:00
|
|
|
if( !wxRenameFile( tempFileName, m_lib_path ) )
|
2012-04-17 01:35:43 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2014-01-19 13:12:57 +00:00
|
|
|
_( "Unable to rename tempfile '%s' to library file '%s'" ),
|
2012-04-17 01:35:43 +00:00
|
|
|
tempFileName.GetData(),
|
2013-01-02 04:05:48 +00:00
|
|
|
m_lib_path.GetData() ) );
|
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::SaveHeader( FILE* aFile )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
fprintf( aFile, "%s %s\n", FOOTPRINT_LIBRARY_HEADER, TO_UTF8( DateAndTime() ) );
|
|
|
|
fprintf( aFile, "# encoding utf-8\n" );
|
2012-04-17 01:35:43 +00:00
|
|
|
fprintf( aFile, "Units mm\n" );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::SaveIndex( FILE* aFile )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
|
|
|
fprintf( aFile, "$INDEX\n" );
|
|
|
|
|
|
|
|
for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it )
|
|
|
|
{
|
2012-05-20 13:14:46 +00:00
|
|
|
fprintf( aFile, "%s\n", it->first.c_str() );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( aFile, "$EndINDEX\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
void LP_CACHE::SaveModules( FILE* aFile )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
m_owner->SetFilePtr( aFile );
|
|
|
|
|
|
|
|
for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
m_owner->saveMODULE( it->second );
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
#endif
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath )
|
|
|
|
{
|
2013-01-02 04:05:48 +00:00
|
|
|
if( !m_cache || m_cache->m_lib_path != aLibraryPath ||
|
2012-04-17 01:35:43 +00:00
|
|
|
// somebody else on a network touched the library:
|
2012-04-16 03:18:41 +00:00
|
|
|
m_cache->m_mod_time != m_cache->GetLibModificationTime() )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
wxArrayString LEGACY_PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, 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 );
|
|
|
|
|
|
|
|
const MODULE_MAP& mods = m_cache->m_modules;
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
wxArrayString ret;
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
|
|
|
|
{
|
2012-05-20 13:14:46 +00:00
|
|
|
ret.Add( FROM_UTF8( it->first.c_str() ) );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
MODULE* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName, 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 );
|
|
|
|
|
|
|
|
const MODULE_MAP& mods = m_cache->m_modules;
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
MODULE_CITER it = mods.find( TO_UTF8( aFootprintName ) );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
if( it == mods.end() )
|
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
/*
|
2012-04-16 03:18:41 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "No '%s' footprint in library '%s'" ),
|
|
|
|
aFootprintName.GetData(), aLibraryPath.GetData() ) );
|
2012-04-17 01:35:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
return NULL;
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy constructor to clone the already loaded MODULE
|
|
|
|
return new MODULE( *it->second );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#if 0 // omit FootprintSave()
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void LEGACY_PLUGIN::FootprintSave( const wxString& aLibraryPath,
|
|
|
|
const MODULE* aFootprint, 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 );
|
|
|
|
|
|
|
|
if( !m_cache->m_writable )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
std::string footprintName = aFootprint->GetFPID().GetFootprintName();
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
MODULE_MAP& mods = m_cache->m_modules;
|
|
|
|
|
|
|
|
// quietly overwrite any by same name.
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE_CITER it = mods.find( footprintName );
|
2012-04-16 03:18:41 +00:00
|
|
|
if( it != mods.end() )
|
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
mods.erase( footprintName );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
// I need my own copy for the cache
|
|
|
|
MODULE* my_module = new MODULE( *aFootprint );
|
|
|
|
|
|
|
|
// and it's time stamp must be 0, it should have no parent, orientation should
|
|
|
|
// be zero, and it should be on the front layer.
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
my_module->SetTimeStamp( 0 );
|
|
|
|
my_module->SetParent( 0 );
|
|
|
|
|
|
|
|
my_module->SetOrientation( 0 );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( my_module->GetLayer() != F_Cu )
|
2012-04-17 01:35:43 +00:00
|
|
|
my_module->Flip( my_module->GetPosition() );
|
|
|
|
|
|
|
|
mods.insert( footprintName, my_module );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
m_cache->Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void LEGACY_PLUGIN::FootprintDelete( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName, 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( NULL );
|
|
|
|
|
|
|
|
cacheLib( aLibraryPath );
|
|
|
|
|
|
|
|
if( !m_cache->m_writable )
|
|
|
|
{
|
2014-01-19 13:12:57 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) );
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
std::string footprintName = TO_UTF8( aFootprintName );
|
|
|
|
|
|
|
|
size_t erasedCount = m_cache->m_modules.erase( footprintName );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
if( erasedCount != 1 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2014-01-19 13:12:57 +00:00
|
|
|
_( "library '%s' has no footprint '%s' to delete" ),
|
2012-04-16 03:18:41 +00:00
|
|
|
aLibraryPath.GetData(), aFootprintName.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cache->Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void LEGACY_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( wxFileExists( aLibraryPath ) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2014-01-19 13:12:57 +00:00
|
|
|
_( "library '%s' already exists, will not create a new" ),
|
2012-04-17 01:35:43 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
init( NULL );
|
|
|
|
|
|
|
|
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->Save();
|
|
|
|
m_cache->Load(); // update m_writable and m_mod_time
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#endif // omit FootprintSave()
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2013-09-25 19:17:06 +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 ) )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
2014-01-19 13:12:57 +00:00
|
|
|
_( "library '%s' cannot be deleted" ),
|
2012-04-17 01:35:43 +00:00
|
|
|
aLibraryPath.GetData() ) );
|
|
|
|
}
|
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;
|
|
|
|
m_cache = 0;
|
|
|
|
}
|
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;
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
init( NULL );
|
|
|
|
|
|
|
|
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()
|
2012-04-17 06:13:22 +00:00
|
|
|
m_board( 0 ),
|
|
|
|
m_props( 0 ),
|
|
|
|
m_reader( 0 ),
|
|
|
|
m_fp( 0 ),
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
m_cache( 0 ),
|
|
|
|
m_mapping( new NETINFO_MAPPING() )
|
2012-04-17 06:13:22 +00:00
|
|
|
{
|
|
|
|
init( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
LEGACY_PLUGIN::~LEGACY_PLUGIN()
|
|
|
|
{
|
|
|
|
delete m_cache;
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
delete m_mapping;
|
2012-04-16 03:18:41 +00:00
|
|
|
}
|