2012-06-11 00:47:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN
|
2018-09-16 13:10:48 +00:00
|
|
|
* Copyright (C) 2012-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-11 00:47:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file pcb_parser.cpp
|
|
|
|
* @brief Pcbnew s-expression file format parser implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <common.h>
|
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
|
|
|
#include <confirm.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <trigo.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <title_block.h>
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_dimension.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_edge_mod.h>
|
2017-10-31 15:38:10 +00:00
|
|
|
#include <class_pcb_target.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <class_module.h>
|
2018-01-30 14:34:09 +00:00
|
|
|
#include <netclass.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <class_pad.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_zone.h>
|
2012-10-07 15:37:25 +00:00
|
|
|
#include <kicad_plugin.h>
|
2014-10-13 08:40:34 +00:00
|
|
|
#include <pcb_plot_params_parser.h>
|
2012-06-11 00:47:15 +00:00
|
|
|
#include <pcb_plot_params.h>
|
|
|
|
#include <zones.h>
|
|
|
|
#include <pcb_parser.h>
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
using namespace PCB_KEYS_T;
|
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2012-10-24 18:20:33 +00:00
|
|
|
void PCB_PARSER::init()
|
|
|
|
{
|
2016-05-10 19:07:35 +00:00
|
|
|
m_tooRecent = false;
|
|
|
|
m_requiredVersion = 0;
|
2012-11-14 07:15:59 +00:00
|
|
|
m_layerIndices.clear();
|
|
|
|
m_layerMasks.clear();
|
2012-10-24 18:20:33 +00:00
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
// Add untranslated default (i.e. english) layernames.
|
|
|
|
// Some may be overridden later if parsing a board rather than a footprint.
|
|
|
|
// The english name will survive if parsing only a footprint.
|
2017-03-13 03:19:33 +00:00
|
|
|
for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
|
2012-11-09 06:58:00 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
m_layerIndices[ untranslated ] = PCB_LAYER_ID( layer );
|
|
|
|
m_layerMasks[ untranslated ] = LSET( PCB_LAYER_ID( layer ) );
|
2012-11-09 06:58:00 +00:00
|
|
|
}
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
m_layerMasks[ "*.Cu" ] = LSET::AllCuMask();
|
|
|
|
m_layerMasks[ "F&B.Cu" ] = LSET( 2, F_Cu, B_Cu );
|
|
|
|
m_layerMasks[ "*.Adhes" ] = LSET( 2, B_Adhes, F_Adhes );
|
|
|
|
m_layerMasks[ "*.Paste" ] = LSET( 2, B_Paste, F_Paste );
|
|
|
|
m_layerMasks[ "*.Mask" ] = LSET( 2, B_Mask, F_Mask );
|
|
|
|
m_layerMasks[ "*.SilkS" ] = LSET( 2, B_SilkS, F_SilkS );
|
|
|
|
m_layerMasks[ "*.Fab" ] = LSET( 2, B_Fab, F_Fab );
|
2014-07-05 12:35:18 +00:00
|
|
|
m_layerMasks[ "*.CrtYd" ] = LSET( 2, B_CrtYd, F_CrtYd );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-07-05 20:42:59 +00:00
|
|
|
// This is for the first pretty & *.kicad_pcb formats, which had
|
|
|
|
// Inner1_Cu - Inner14_Cu with the numbering sequence
|
|
|
|
// reversed from the subsequent format's In1_Cu - In30_Cu numbering scheme.
|
|
|
|
// The newer format brought in an additional 16 Cu layers and flipped the cu stack but
|
2014-06-24 16:17:18 +00:00
|
|
|
// kept the gap between one of the outside layers and the last cu internal.
|
|
|
|
|
|
|
|
for( int i=1; i<=14; ++i )
|
|
|
|
{
|
2014-07-05 20:42:59 +00:00
|
|
|
std::string key = StrPrintf( "Inner%d.Cu", i );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
m_layerMasks[ key ] = LSET( PCB_LAYER_ID( In15_Cu - i ) );
|
2014-06-29 20:33:29 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
#if defined(DEBUG) && 0
|
|
|
|
printf( "m_layerMasks:\n" );
|
|
|
|
for( LSET_MAP::const_iterator it = m_layerMasks.begin(); it != m_layerMasks.end(); ++it )
|
|
|
|
{
|
|
|
|
printf( " [%s] == 0x%s\n", it->first.c_str(), it->second.FmtHex().c_str() );
|
2014-06-24 16:17:18 +00:00
|
|
|
}
|
2014-06-29 20:33:29 +00:00
|
|
|
|
|
|
|
printf( "m_layerIndices:\n" );
|
|
|
|
for( LAYER_ID_MAP::const_iterator it = m_layerIndices.begin(); it != m_layerIndices.end(); ++it )
|
|
|
|
{
|
|
|
|
printf( " [%s] == %d\n", it->first.c_str(), it->second );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-24 18:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-22 12:06:34 +00:00
|
|
|
void PCB_PARSER::pushValueIntoMap( int aIndex, int aValue )
|
|
|
|
{
|
|
|
|
// Add aValue in netcode mapping (m_netCodes) at index aNetCode
|
|
|
|
// ensure there is room in m_netCodes for that, and add room if needed.
|
|
|
|
|
|
|
|
if( (int)m_netCodes.size() <= aIndex )
|
|
|
|
m_netCodes.resize( aIndex+1 );
|
|
|
|
|
|
|
|
m_netCodes[aIndex] = aValue;
|
|
|
|
}
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
double PCB_PARSER::parseDouble()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
char* tmp;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
double fval = strtod( CurText(), &tmp );
|
|
|
|
|
|
|
|
if( errno )
|
|
|
|
{
|
|
|
|
wxString error;
|
2018-03-08 05:39:08 +00:00
|
|
|
error.Printf( _( "Invalid floating point number in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2012-06-11 00:47:15 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() );
|
|
|
|
|
|
|
|
THROW_IO_ERROR( error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( CurText() == tmp )
|
|
|
|
{
|
|
|
|
wxString error;
|
2018-03-08 05:39:08 +00:00
|
|
|
error.Printf( _( "Missing floating point number in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2012-06-11 00:47:15 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() );
|
|
|
|
|
|
|
|
THROW_IO_ERROR( error );
|
|
|
|
}
|
|
|
|
|
|
|
|
return fval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
bool PCB_PARSER::parseBool()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_yes )
|
|
|
|
return true;
|
|
|
|
else if( token == T_no )
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
Expecting( "yes or no" );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
int PCB_PARSER::parseVersion()
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
if( NextTok() != T_version )
|
|
|
|
Expecting( GetTokenText( T_version ) );
|
|
|
|
|
2016-05-10 22:57:10 +00:00
|
|
|
int pcb_version = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
|
2016-05-10 19:07:35 +00:00
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
|
|
|
|
return pcb_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PCB_PARSER::GetRequiredVersion()
|
|
|
|
{
|
|
|
|
int year, month, day;
|
|
|
|
|
|
|
|
year = m_requiredVersion / 10000;
|
|
|
|
month = ( m_requiredVersion / 100 ) - ( year * 100 );
|
|
|
|
day = m_requiredVersion - ( year * 10000 ) - ( month * 100 );
|
|
|
|
|
|
|
|
// wx throws an assertion, not a catchable exception, when the date is invalid.
|
|
|
|
// User input shouldn't give wx asserts, so check manually and throw a proper
|
|
|
|
// error instead
|
|
|
|
if( day <= 0 || month <= 0 || month > 12 ||
|
|
|
|
day > wxDateTime::GetNumberOfDays( (wxDateTime::Month)( month - 1 ), year ) )
|
|
|
|
{
|
|
|
|
wxString err;
|
2018-03-08 05:39:08 +00:00
|
|
|
err.Printf( _( "Cannot interpret date code %d" ), m_requiredVersion );
|
2016-05-10 19:07:35 +00:00
|
|
|
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDateTime date( day, (wxDateTime::Month)( month - 1 ), year, 0, 0, 0, 0 );
|
|
|
|
return date.FormatDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
wxPoint PCB_PARSER::parseXY()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
if( CurTok() != T_LEFT )
|
|
|
|
NeedLEFT();
|
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_xy )
|
|
|
|
Expecting( T_xy );
|
|
|
|
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseXY( int* aX, int* aY )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxPoint pt = parseXY();
|
|
|
|
|
|
|
|
if( aX )
|
|
|
|
*aX = pt.x;
|
|
|
|
|
|
|
|
if( aY )
|
|
|
|
*aY = pt.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseEDA_TEXT( EDA_TEXT* aText )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_effects,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDA_TEXT." ) );
|
|
|
|
|
|
|
|
T token;
|
|
|
|
|
2017-12-20 22:11:19 +00:00
|
|
|
// Prior to v5.0 text size was omitted from file format if equal to 60mils
|
|
|
|
// Now, it is always explicitly written to file
|
|
|
|
bool foundTextSize = false;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
2017-01-26 03:33:30 +00:00
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_font:
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_size:
|
2017-01-26 03:33:30 +00:00
|
|
|
{
|
|
|
|
wxSize sz;
|
|
|
|
sz.SetHeight( parseBoardUnits( "text height" ) );
|
|
|
|
sz.SetWidth( parseBoardUnits( "text width" ) );
|
|
|
|
aText->SetTextSize( sz );
|
|
|
|
NeedRIGHT();
|
2017-12-20 22:11:19 +00:00
|
|
|
|
|
|
|
foundTextSize = true;
|
2017-01-26 03:33:30 +00:00
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thickness:
|
|
|
|
aText->SetThickness( parseBoardUnits( "text thickness" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_bold:
|
|
|
|
aText->SetBold( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_italic:
|
|
|
|
aText->SetItalic( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "size, bold, or italic" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_justify:
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_left:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_right:
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_top:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_bottom:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_mirror:
|
|
|
|
aText->SetMirrored( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "left, right, top, bottom, or mirror" );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_hide:
|
|
|
|
aText->SetVisible( false );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "font, justify, or hide" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-20 22:11:19 +00:00
|
|
|
|
|
|
|
// Text size was not specified in file, force legacy default units
|
|
|
|
// 60mils is 1.524mm
|
|
|
|
if( !foundTextSize )
|
|
|
|
{
|
|
|
|
const float defaultTextSize = 1.524f * IU_PER_MM;
|
|
|
|
|
|
|
|
aText->SetTextSize( wxSize( defaultTextSize, defaultTextSize ) );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-27 14:25:20 +00:00
|
|
|
MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_model, NULL,
|
2017-10-27 14:25:20 +00:00
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as MODULE_3D_SETTINGS." ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
T token;
|
|
|
|
|
2017-10-27 14:25:20 +00:00
|
|
|
MODULE_3D_SETTINGS* n3D = new MODULE_3D_SETTINGS;
|
2012-12-30 15:40:05 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2016-08-03 17:39:39 +00:00
|
|
|
n3D->m_Filename = FromUTF8();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_at:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_xyz )
|
|
|
|
Expecting( T_xyz );
|
|
|
|
|
2017-11-14 09:53:59 +00:00
|
|
|
/* Note:
|
2017-11-23 10:21:48 +00:00
|
|
|
* Prior to KiCad v5, model offset was designated by "at",
|
|
|
|
* and the units were in inches.
|
|
|
|
* Now we use mm, but support reading of legacy files
|
2017-11-14 09:53:59 +00:00
|
|
|
*/
|
|
|
|
|
2017-11-23 10:21:48 +00:00
|
|
|
n3D->m_Offset.x = parseDouble( "x value" ) * 25.4f;
|
|
|
|
n3D->m_Offset.y = parseDouble( "y value" ) * 25.4f;
|
|
|
|
n3D->m_Offset.z = parseDouble( "z value" ) * 25.4f;
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_offset:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_xyz )
|
|
|
|
Expecting( T_xyz );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 3D model offset is in mm
|
|
|
|
*/
|
2016-07-19 17:35:25 +00:00
|
|
|
n3D->m_Offset.x = parseDouble( "x value" );
|
|
|
|
n3D->m_Offset.y = parseDouble( "y value" );
|
|
|
|
n3D->m_Offset.z = parseDouble( "z value" );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_scale:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_xyz )
|
|
|
|
Expecting( T_xyz );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
n3D->m_Scale.x = parseDouble( "x value" );
|
|
|
|
n3D->m_Scale.y = parseDouble( "y value" );
|
|
|
|
n3D->m_Scale.z = parseDouble( "z value" );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rotate:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_xyz )
|
|
|
|
Expecting( T_xyz );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
n3D->m_Rotation.x = parseDouble( "x value" );
|
|
|
|
n3D->m_Rotation.y = parseDouble( "y value" );
|
|
|
|
n3D->m_Rotation.z = parseDouble( "z value" );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "at, offset, scale, or rotate" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return n3D;
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
BOARD_ITEM* PCB_PARSER::Parse()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2013-06-23 19:18:33 +00:00
|
|
|
T token;
|
|
|
|
BOARD_ITEM* item;
|
|
|
|
LOCALE_IO toggle;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2013-06-23 19:18:33 +00:00
|
|
|
// MODULEs can be prefixed with an initial block of single line comments and these
|
|
|
|
// are kept for Format() so they round trip in s-expression form. BOARDs might
|
|
|
|
// eventually do the same, but currently do not.
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr<wxArrayString> initial_comments( ReadCommentLines() );
|
2013-06-23 19:18:33 +00:00
|
|
|
|
|
|
|
token = CurTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
switch( NextTok() )
|
|
|
|
{
|
|
|
|
case T_kicad_pcb:
|
|
|
|
if( m_board == NULL )
|
|
|
|
m_board = new BOARD();
|
|
|
|
|
|
|
|
item = (BOARD_ITEM*) parseBOARD();
|
|
|
|
break;
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
case T_module:
|
2013-06-23 19:18:33 +00:00
|
|
|
item = (BOARD_ITEM*) parseMODULE( initial_comments.release() );
|
2012-10-07 15:37:25 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
default:
|
|
|
|
wxString err;
|
2018-03-08 05:39:08 +00:00
|
|
|
err.Printf( _( "Unknown token \"%s\"" ), GetChars( FromUTF8() ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
BOARD* PCB_PARSER::parseBOARD()
|
2016-05-10 19:07:35 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return parseBOARD_unchecked();
|
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
|
|
|
if( m_tooRecent )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
|
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
BOARD* PCB_PARSER::parseBOARD_unchecked()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
T token;
|
|
|
|
|
|
|
|
parseHeader();
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_general:
|
|
|
|
parseGeneralSection();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_page:
|
|
|
|
parsePAGE_INFO();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_title_block:
|
|
|
|
parseTITLE_BLOCK();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_layers:
|
|
|
|
parseLayers();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_setup:
|
|
|
|
parseSetup();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_net:
|
|
|
|
parseNETINFO_ITEM();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_net_class:
|
|
|
|
parseNETCLASS();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_arc:
|
|
|
|
case T_gr_circle:
|
|
|
|
case T_gr_curve:
|
|
|
|
case T_gr_line:
|
|
|
|
case T_gr_poly:
|
|
|
|
m_board->Add( parseDRAWSEGMENT(), ADD_APPEND );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_text:
|
|
|
|
m_board->Add( parseTEXTE_PCB(), ADD_APPEND );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_dimension:
|
|
|
|
m_board->Add( parseDIMENSION(), ADD_APPEND );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_module:
|
|
|
|
m_board->Add( parseMODULE(), ADD_APPEND );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_segment:
|
2018-04-03 20:57:31 +00:00
|
|
|
m_board->Add( parseTRACK(), ADD_INSERT );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via:
|
2018-04-03 20:57:31 +00:00
|
|
|
m_board->Add( parseVIA(), ADD_INSERT );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_zone:
|
|
|
|
m_board->Add( parseZONE_CONTAINER(), ADD_APPEND );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_target:
|
|
|
|
m_board->Add( parsePCB_TARGET(), ADD_APPEND );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
wxString err;
|
|
|
|
err.Printf( _( "Unknown token \"%s\"" ), GetChars( FromUTF8() ) );
|
|
|
|
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 00:24:27 +00:00
|
|
|
if( m_undefinedLayers.size() > 0 )
|
|
|
|
{
|
|
|
|
bool deleteItems;
|
|
|
|
std::vector<BOARD_ITEM*> deleteList;
|
|
|
|
wxString msg = wxString::Format( _( "Items found on undefined layers. Do you wish to\n"
|
|
|
|
"rescue them to the Cmts.User layer?" ) );
|
|
|
|
wxString details = wxString::Format( _( "Undefined layers:" ) );
|
|
|
|
|
|
|
|
for( const wxString& undefinedLayer : m_undefinedLayers )
|
|
|
|
details += wxT( "\n " ) + undefinedLayer;
|
|
|
|
|
|
|
|
wxRichMessageDialog dlg( nullptr, msg, _( "Warning" ),
|
|
|
|
wxYES_NO | wxCANCEL | wxCENTRE | wxICON_WARNING | wxSTAY_ON_TOP );
|
|
|
|
dlg.ShowDetailedText( details );
|
|
|
|
dlg.SetYesNoCancelLabels( _( "Rescue" ), _( "Delete" ), _( "Cancel" ) );
|
|
|
|
|
|
|
|
switch( dlg.ShowModal() )
|
|
|
|
{
|
|
|
|
case wxID_YES: deleteItems = false; break;
|
|
|
|
case wxID_NO: deleteItems = true; break;
|
|
|
|
case wxID_CANCEL:
|
|
|
|
default: THROW_IO_ERROR( wxT( "CANCEL" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto visitItem = [&]( BOARD_ITEM* item )
|
|
|
|
{
|
|
|
|
if( item->GetLayer() == Rescue )
|
|
|
|
{
|
|
|
|
if( deleteItems )
|
|
|
|
deleteList.push_back( item );
|
|
|
|
else
|
|
|
|
item->SetLayer( Cmts_User );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for( TRACK* segm = m_board->m_Track; segm; segm = segm->Next() )
|
|
|
|
{
|
|
|
|
if( segm->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* via = (VIA*) segm;
|
|
|
|
PCB_LAYER_ID top_layer, bottom_layer;
|
|
|
|
|
|
|
|
if( via->GetViaType() == VIA_THROUGH )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
via->LayerPair( &top_layer, &bottom_layer );
|
|
|
|
|
|
|
|
if( top_layer == Rescue || bottom_layer == Rescue )
|
|
|
|
{
|
|
|
|
if( deleteItems )
|
|
|
|
deleteList.push_back( via );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( top_layer == Rescue )
|
|
|
|
top_layer = F_Cu;
|
|
|
|
|
|
|
|
if( bottom_layer == Rescue )
|
|
|
|
bottom_layer = B_Cu;
|
|
|
|
|
|
|
|
via->SetLayerPair( top_layer, bottom_layer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
visitItem( segm );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( TRACK* segm = m_board->m_SegZoneDeprecated; segm; segm = segm->Next() )
|
|
|
|
visitItem( segm );
|
|
|
|
|
|
|
|
for( BOARD_ITEM* zone : m_board->Zones() )
|
|
|
|
visitItem( zone );
|
|
|
|
|
|
|
|
for( BOARD_ITEM* drawing : m_board->Drawings() )
|
|
|
|
visitItem( drawing );
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : deleteList )
|
|
|
|
m_board->Delete( item );
|
|
|
|
|
|
|
|
m_undefinedLayers.clear();
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
return m_board;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseHeader()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_kicad_pcb,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a header." ) );
|
|
|
|
|
|
|
|
NeedLEFT();
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
T tok = NextTok();
|
|
|
|
if( tok == T_version )
|
|
|
|
{
|
2016-05-10 22:57:10 +00:00
|
|
|
m_requiredVersion = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
|
2016-05-10 19:07:35 +00:00
|
|
|
m_tooRecent = ( m_requiredVersion > SEXPR_BOARD_FILE_VERSION );
|
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
// Skip the host name and host build version information.
|
|
|
|
NeedLEFT();
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_requiredVersion = SEXPR_BOARD_FILE_VERSION;
|
|
|
|
m_tooRecent = ( m_requiredVersion > SEXPR_BOARD_FILE_VERSION );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
// Skip the host name and host build version information.
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->SetFileFormatVersionAtLoad( m_requiredVersion );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseGeneralSection()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_general,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
|
|
|
|
wxT( " as a general section." ) );
|
|
|
|
|
|
|
|
T token;
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_thickness:
|
|
|
|
m_board->GetDesignSettings().SetBoardThickness( parseBoardUnits( T_thickness ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2014-06-02 09:41:54 +00:00
|
|
|
case T_nets:
|
|
|
|
m_netCodes.resize( parseInt( "nets number" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_no_connects:
|
2017-06-23 16:39:42 +00:00
|
|
|
// ignore
|
|
|
|
parseInt( "no connect count" );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // Skip everything but the board thickness.
|
2016-09-20 15:59:43 +00:00
|
|
|
//wxLogDebug( wxT( "Skipping general section token %s " ), GetChars( GetTokenString( token ) ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
while( ( token = NextTok() ) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( !IsSymbol( token ) && token != T_NUMBER )
|
|
|
|
Expecting( "symbol or number" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parsePAGE_INFO()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_page,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
|
|
|
|
|
|
|
|
T token;
|
2012-06-25 23:52:57 +00:00
|
|
|
PAGE_INFO pageInfo;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
NeedSYMBOL();
|
|
|
|
|
|
|
|
wxString pageType = FromUTF8();
|
|
|
|
|
2012-06-25 23:52:57 +00:00
|
|
|
if( !pageInfo.SetType( pageType ) )
|
|
|
|
{
|
|
|
|
wxString err;
|
2018-03-08 05:39:08 +00:00
|
|
|
err.Printf( _( "Page type \"%s\" is not valid " ), GetChars( FromUTF8() ) );
|
2012-06-25 23:52:57 +00:00
|
|
|
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
if( pageType == PAGE_INFO::Custom )
|
|
|
|
{
|
2012-06-25 23:52:57 +00:00
|
|
|
double width = parseDouble( "width" ); // width in mm
|
|
|
|
|
|
|
|
// Perform some controls to avoid crashes if the size is edited by hands
|
|
|
|
if( width < 100.0 )
|
|
|
|
width = 100.0;
|
|
|
|
else if( width > 1200.0 )
|
|
|
|
width = 1200.0;
|
|
|
|
|
|
|
|
double height = parseDouble( "height" ); // height in mm
|
|
|
|
|
|
|
|
if( height < 100.0 )
|
|
|
|
height = 100.0;
|
|
|
|
else if( height > 1200.0 )
|
|
|
|
height = 1200.0;
|
|
|
|
|
|
|
|
pageInfo.SetWidthMils( Mm2mils( width ) );
|
|
|
|
pageInfo.SetHeightMils( Mm2mils( height ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_portrait )
|
|
|
|
{
|
2012-06-25 23:52:57 +00:00
|
|
|
pageInfo.SetPortrait( true );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else if( token != T_RIGHT )
|
|
|
|
{
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "portrait|)" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_board->SetPageSettings( pageInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseTITLE_BLOCK()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_title_block,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
|
|
|
|
wxT( " as TITLE_BLOCK." ) );
|
|
|
|
|
|
|
|
T token;
|
|
|
|
TITLE_BLOCK titleBlock;
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_title:
|
2012-12-30 15:40:05 +00:00
|
|
|
NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
titleBlock.SetTitle( FromUTF8() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_date:
|
2012-12-30 15:40:05 +00:00
|
|
|
NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
titleBlock.SetDate( FromUTF8() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rev:
|
|
|
|
NextTok();
|
|
|
|
titleBlock.SetRevision( FromUTF8() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_company:
|
|
|
|
NextTok();
|
|
|
|
titleBlock.SetCompany( FromUTF8() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_comment:
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
int commentNumber = parseInt( "comment" );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
switch( commentNumber )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
NextTok();
|
|
|
|
titleBlock.SetComment1( FromUTF8() );
|
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case 2:
|
|
|
|
NextTok();
|
|
|
|
titleBlock.SetComment2( FromUTF8() );
|
|
|
|
break;
|
2012-11-09 06:58:00 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case 3:
|
|
|
|
NextTok();
|
|
|
|
titleBlock.SetComment3( FromUTF8() );
|
|
|
|
break;
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case 4:
|
|
|
|
NextTok();
|
|
|
|
titleBlock.SetComment4( FromUTF8() );
|
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
default:
|
|
|
|
wxString err;
|
|
|
|
err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber );
|
|
|
|
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "title, date, rev, company, or comment" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->SetTitleBlock( titleBlock );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseLayer( LAYER* aLayer )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2012-11-09 06:58:00 +00:00
|
|
|
T token;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
std::string name;
|
2012-11-09 06:58:00 +00:00
|
|
|
std::string type;
|
|
|
|
bool isVisible = true;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
aLayer->clear();
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( CurTok() != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
// this layer_num is not used, we DO depend on LAYER_T however.
|
|
|
|
LAYER_NUM layer_num = parseInt( "layer index" );
|
|
|
|
|
2017-02-25 09:10:43 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2014-06-24 16:17:18 +00:00
|
|
|
name = CurText();
|
|
|
|
|
|
|
|
NeedSYMBOL();
|
|
|
|
type = CurText();
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_hide )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
isVisible = false;
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else if( token != T_RIGHT )
|
|
|
|
{
|
|
|
|
Expecting( "hide or )" );
|
|
|
|
}
|
|
|
|
|
|
|
|
aLayer->m_name = FROM_UTF8( name.c_str() );
|
|
|
|
aLayer->m_type = LAYER::ParseType( type.c_str() );
|
|
|
|
aLayer->m_number = layer_num;
|
|
|
|
aLayer->m_visible = isVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-01 13:17:32 +00:00
|
|
|
void PCB_PARSER::createOldLayerMapping( std::unordered_map< std::string, std::string >& aMap )
|
|
|
|
{
|
|
|
|
// N.B. This mapping only includes Italian, Polish and French as they were the only languages that
|
|
|
|
// mapped the layer names as of cc2022b1ac739aa673d2a0b7a2047638aa7a47b3 (kicad-i18n) when the
|
|
|
|
// bug was fixed in KiCad source.
|
|
|
|
|
|
|
|
// Italian
|
|
|
|
aMap["Adesivo.Retro"] = "B.Adhes";
|
|
|
|
aMap["Adesivo.Fronte"] = "F.Adhes";
|
|
|
|
aMap["Pasta.Retro"] = "B.Paste";
|
|
|
|
aMap["Pasta.Fronte"] = "F.Paste";
|
|
|
|
aMap["Serigrafia.Retro"] = "B.SilkS";
|
|
|
|
aMap["Serigrafia.Fronte"] = "F.SilkS";
|
|
|
|
aMap["Maschera.Retro"] = "B.Mask";
|
|
|
|
aMap["Maschera.Fronte"] = "F.Mask";
|
|
|
|
aMap["Grafica"] = "Dwgs.User";
|
|
|
|
aMap["Commenti"] = "Cmts.User";
|
|
|
|
aMap["Eco1"] = "Eco1.User";
|
|
|
|
aMap["Eco2"] = "Eco2.User";
|
|
|
|
aMap["Contorno.scheda"] = "Edge.Cuts";
|
|
|
|
|
|
|
|
// Polish
|
|
|
|
aMap["Kleju_Dolna"] = "B.Adhes";
|
|
|
|
aMap["Kleju_Gorna"] = "F.Adhes";
|
|
|
|
aMap["Pasty_Dolna"] = "B.Paste";
|
|
|
|
aMap["Pasty_Gorna"] = "F.Paste";
|
|
|
|
aMap["Opisowa_Dolna"] = "B.SilkS";
|
|
|
|
aMap["Opisowa_Gorna"] = "F.SilkS";
|
|
|
|
aMap["Maski_Dolna"] = "B.Mask";
|
|
|
|
aMap["Maski_Gorna"] = "F.Mask";
|
|
|
|
aMap["Rysunkowa"] = "Dwgs.User";
|
|
|
|
aMap["Komentarzy"] = "Cmts.User";
|
|
|
|
aMap["ECO1"] = "Eco1.User";
|
|
|
|
aMap["ECO2"] = "Eco2.User";
|
|
|
|
aMap["Krawedziowa"] = "Edge.Cuts";
|
|
|
|
|
|
|
|
// French
|
|
|
|
aMap["Dessous.Adhes"] = "B.Adhes";
|
|
|
|
aMap["Dessus.Adhes"] = "F.Adhes";
|
|
|
|
aMap["Dessous.Pate"] = "B.Paste";
|
|
|
|
aMap["Dessus.Pate"] = "F.Paste";
|
|
|
|
aMap["Dessous.SilkS"] = "B.SilkS";
|
|
|
|
aMap["Dessus.SilkS"] = "F.SilkS";
|
|
|
|
aMap["Dessous.Masque"] = "B.Mask";
|
|
|
|
aMap["Dessus.Masque"] = "F.Mask";
|
|
|
|
aMap["Dessin.User"] = "Dwgs.User";
|
|
|
|
aMap["Contours.Ci"] = "Edge.Cuts";
|
|
|
|
}
|
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseLayers()
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_layers,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layers." ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
T token;
|
|
|
|
LSET visibleLayers;
|
|
|
|
LSET enabledLayers;
|
|
|
|
int copperLayerCount = 0;
|
2014-06-30 18:45:43 +00:00
|
|
|
LAYER layer;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2019-04-01 13:17:32 +00:00
|
|
|
std::unordered_map< std::string, std::string > v3_layer_names;
|
2014-06-24 16:17:18 +00:00
|
|
|
std::vector<LAYER> cu;
|
2012-11-09 06:58:00 +00:00
|
|
|
|
2019-04-01 13:17:32 +00:00
|
|
|
createOldLayerMapping( v3_layer_names );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
parseLayer( &layer );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
if( layer.m_type == LT_UNDEFINED ) // it's a non-copper layer
|
|
|
|
break;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
cu.push_back( layer ); // it's copper
|
|
|
|
}
|
|
|
|
|
|
|
|
// All Cu layers are parsed, but not the non-cu layers here.
|
|
|
|
|
|
|
|
// The original *.kicad_pcb file format and the inverted
|
|
|
|
// Cu stack format both have all the Cu layers first, so use this
|
|
|
|
// trick to handle either. The layer number in the (layers ..)
|
|
|
|
// s-expression element are ignored.
|
|
|
|
if( cu.size() )
|
|
|
|
{
|
|
|
|
// Rework the layer numbers, which changed when the Cu stack
|
|
|
|
// was flipped. So we instead use position in the list.
|
|
|
|
cu[cu.size()-1].m_number = B_Cu;
|
|
|
|
|
|
|
|
for( unsigned i=0; i < cu.size()-1; ++i )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2014-06-29 21:50:06 +00:00
|
|
|
cu[i].m_number = i;
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
for( std::vector<LAYER>::const_iterator it = cu.begin(); it<cu.end(); ++it )
|
|
|
|
{
|
|
|
|
enabledLayers.set( it->m_number );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
if( it->m_visible )
|
|
|
|
visibleLayers.set( it->m_number );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
m_board->SetLayerDescr( PCB_LAYER_ID( it->m_number ), *it );
|
2012-11-14 07:15:59 +00:00
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
UTF8 name = it->m_name;
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
m_layerIndices[ name ] = PCB_LAYER_ID( it->m_number );
|
|
|
|
m_layerMasks[ name ] = LSET( PCB_LAYER_ID( it->m_number ) );
|
2014-06-29 21:50:06 +00:00
|
|
|
}
|
2014-06-25 04:36:02 +00:00
|
|
|
|
2014-06-29 21:50:06 +00:00
|
|
|
copperLayerCount = cu.size();
|
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
// process non-copper layers
|
|
|
|
while( token != T_RIGHT )
|
2014-06-29 21:50:06 +00:00
|
|
|
{
|
2014-06-30 18:45:43 +00:00
|
|
|
LAYER_ID_MAP::const_iterator it = m_layerIndices.find( UTF8( layer.m_name ) );
|
|
|
|
|
|
|
|
if( it == m_layerIndices.end() )
|
2014-06-29 21:50:06 +00:00
|
|
|
{
|
2019-04-01 13:17:32 +00:00
|
|
|
auto new_layer_it = v3_layer_names.find( layer.m_name.ToStdString() );
|
|
|
|
|
|
|
|
if( new_layer_it != v3_layer_names.end() )
|
|
|
|
it = m_layerIndices.find( new_layer_it->second );
|
|
|
|
|
|
|
|
if( it == m_layerIndices.end() )
|
|
|
|
{
|
|
|
|
wxString error = wxString::Format(
|
|
|
|
_( "Layer \"%s\" in file \"%s\" at line %d, is not in fixed layer hash" ),
|
|
|
|
GetChars( layer.m_name ),
|
|
|
|
GetChars( CurSource() ),
|
|
|
|
CurLineNumber(),
|
|
|
|
CurOffset()
|
|
|
|
);
|
|
|
|
|
|
|
|
THROW_IO_ERROR( error );
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are here, then we have found a translated layer name. Put it in the maps so that
|
|
|
|
// items on this layer get the appropriate layer ID number
|
|
|
|
m_layerIndices[ UTF8( layer.m_name ) ] = it->second;
|
|
|
|
m_layerMasks[ UTF8( layer.m_name ) ] = it->second;
|
|
|
|
layer.m_name = it->first;
|
2014-06-30 18:45:43 +00:00
|
|
|
}
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
layer.m_number = it->second;
|
|
|
|
enabledLayers.set( layer.m_number );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
if( layer.m_visible )
|
|
|
|
visibleLayers.set( layer.m_number );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2015-01-29 16:01:48 +00:00
|
|
|
m_board->SetLayerDescr( it->second, layer );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
token = NextTok();
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
if( token != T_LEFT )
|
|
|
|
break;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-06-30 18:45:43 +00:00
|
|
|
parseLayer( &layer );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need at least 2 copper layers and there must be an even number of them.
|
2014-06-24 16:17:18 +00:00
|
|
|
if( copperLayerCount < 2 || (copperLayerCount % 2) != 0 )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2012-11-09 06:58:00 +00:00
|
|
|
wxString err = wxString::Format(
|
|
|
|
_( "%d is not a valid layer count" ), copperLayerCount );
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->SetCopperLayerCount( copperLayerCount );
|
|
|
|
m_board->SetEnabledLayers( enabledLayers );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
// call SetEnabledLayers before SetVisibleLayers()
|
|
|
|
m_board->SetVisibleLayers( visibleLayers );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-30 17:24:04 +00:00
|
|
|
template<class T, class M>
|
2017-06-08 21:47:21 +00:00
|
|
|
T PCB_PARSER::lookUpLayer( const M& aMap )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2012-11-14 07:15:59 +00:00
|
|
|
// avoid constructing another std::string, use lexer's directly
|
2013-03-30 17:24:04 +00:00
|
|
|
typename M::const_iterator it = aMap.find( curText );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
if( it == aMap.end() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2013-05-01 15:48:00 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2012-11-14 07:15:59 +00:00
|
|
|
// dump the whole darn table, there's something wrong with it.
|
|
|
|
for( it = aMap.begin(); it != aMap.end(); ++it )
|
|
|
|
{
|
2013-09-24 18:45:57 +00:00
|
|
|
wxLogDebug( &aMap == (void*)&m_layerIndices ? wxT( "lm[%s] = %d" ) :
|
|
|
|
wxT( "lm[%s] = %08X" ), it->first.c_str(), it->second );
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-07 00:24:27 +00:00
|
|
|
m_undefinedLayers.insert( curText );
|
|
|
|
return Rescue;
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 06:58:00 +00:00
|
|
|
return it->second;
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
PCB_LAYER_ID PCB_PARSER::parseBoardItemLayer()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_layer, UNDEFINED_LAYER,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layer." ) );
|
|
|
|
|
|
|
|
NextTok();
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layerIndex = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
// Handle closing ) in object parser.
|
|
|
|
|
|
|
|
return layerIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
LSET PCB_PARSER::parseBoardItemLayersAsMask()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
wxCHECK_MSG( CurTok() == T_layers, LSET(),
|
2012-06-11 00:47:15 +00:00
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
|
|
|
|
wxT( " as item layer mask." ) );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET layerMask;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT; token = NextTok() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET mask = lookUpLayer<LSET>( m_layerMasks );
|
2012-11-14 07:15:59 +00:00
|
|
|
layerMask |= mask;
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return layerMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseSetup()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_setup,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as setup." ) );
|
|
|
|
|
|
|
|
T token;
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR defaultNetClass = 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-06-11 00:47:15 +00:00
|
|
|
BOARD_DESIGN_SETTINGS designSettings = m_board->GetDesignSettings();
|
|
|
|
ZONE_SETTINGS zoneSettings = m_board->GetZoneSettings();
|
|
|
|
|
2019-01-23 03:01:32 +00:00
|
|
|
// Missing soldermask min width value means that the user has set the value to 0 and
|
|
|
|
// not the default value (0.25mm)
|
|
|
|
designSettings.m_SolderMaskMinWidth = 0;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2012-09-24 06:39:59 +00:00
|
|
|
case T_last_trace_width: // not used now
|
|
|
|
/* lastTraceWidth =*/ parseBoardUnits( T_last_trace_width );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_user_trace_width:
|
2014-05-13 09:22:51 +00:00
|
|
|
designSettings.m_TrackWidthList.push_back( parseBoardUnits( T_user_trace_width ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_trace_clearance:
|
2014-05-13 09:22:51 +00:00
|
|
|
defaultNetClass->SetClearance( parseBoardUnits( T_trace_clearance ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_zone_clearance:
|
|
|
|
zoneSettings.m_ZoneClearance = parseBoardUnits( T_zone_clearance );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_zone_45_only:
|
|
|
|
zoneSettings.m_Zone_45_Only = parseBool();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_trace_min:
|
|
|
|
designSettings.m_TrackMinWidth = parseBoardUnits( T_trace_min );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via_size:
|
2014-05-13 09:22:51 +00:00
|
|
|
defaultNetClass->SetViaDiameter( parseBoardUnits( T_via_size ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via_drill:
|
2014-05-13 09:22:51 +00:00
|
|
|
defaultNetClass->SetViaDrill( parseBoardUnits( T_via_drill ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via_min_size:
|
|
|
|
designSettings.m_ViasMinSize = parseBoardUnits( T_via_min_size );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via_min_drill:
|
|
|
|
designSettings.m_ViasMinDrill = parseBoardUnits( T_via_min_drill );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_user_via:
|
2013-08-03 05:15:23 +00:00
|
|
|
{
|
|
|
|
int viaSize = parseBoardUnits( "user via size" );
|
|
|
|
int viaDrill = parseBoardUnits( "user via drill" );
|
2014-05-13 09:22:51 +00:00
|
|
|
designSettings.m_ViasDimensionsList.push_back( VIA_DIMENSION( viaSize, viaDrill ) );
|
2013-08-03 05:15:23 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvia_size:
|
2014-05-13 09:22:51 +00:00
|
|
|
defaultNetClass->SetuViaDiameter( parseBoardUnits( T_uvia_size ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvia_drill:
|
2014-05-13 09:22:51 +00:00
|
|
|
defaultNetClass->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvias_allowed:
|
|
|
|
designSettings.m_MicroViasAllowed = parseBool();
|
|
|
|
NeedRIGHT();
|
2013-08-28 16:14:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_blind_buried_vias_allowed:
|
|
|
|
designSettings.m_BlindBuriedViaAllowed = parseBool();
|
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvia_min_size:
|
|
|
|
designSettings.m_MicroViasMinSize = parseBoardUnits( T_uvia_min_size );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvia_min_drill:
|
|
|
|
designSettings.m_MicroViasMinDrill = parseBoardUnits( T_uvia_min_drill );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
// 6.0 TODO: change these names, or leave them?
|
|
|
|
// 6.0 TODO: add LAYER_CLASS_OTHERS read/write
|
|
|
|
// 6.0 TODO: add m_TextItalic read/write
|
|
|
|
// 6.0 TODO: add m_TextUpright read/write
|
|
|
|
|
|
|
|
case T_segment_width:
|
|
|
|
designSettings.m_LineThickness[ LAYER_CLASS_COPPER ] = parseBoardUnits( T_segment_width );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
case T_edge_width:
|
|
|
|
designSettings.m_LineThickness[ LAYER_CLASS_EDGES ] = parseBoardUnits( T_edge_width );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_mod_edge_width:
|
2018-04-28 15:22:25 +00:00
|
|
|
designSettings.m_LineThickness[ LAYER_CLASS_SILK ] = parseBoardUnits( T_mod_edge_width );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
case T_pcb_text_width:
|
|
|
|
designSettings.m_TextThickness[ LAYER_CLASS_COPPER ] = parseBoardUnits( T_pcb_text_width );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_mod_text_width:
|
2018-04-28 15:22:25 +00:00
|
|
|
designSettings.m_TextThickness[ LAYER_CLASS_SILK ] = parseBoardUnits( T_mod_text_width );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pcb_text_size:
|
|
|
|
designSettings.m_TextSize[ LAYER_CLASS_COPPER ].x = parseBoardUnits( "pcb text width" );
|
|
|
|
designSettings.m_TextSize[ LAYER_CLASS_COPPER ].y = parseBoardUnits( "pcb text height" );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_mod_text_size:
|
|
|
|
designSettings.m_TextSize[ LAYER_CLASS_SILK ].x = parseBoardUnits( "module text width" );
|
|
|
|
designSettings.m_TextSize[ LAYER_CLASS_SILK ].y = parseBoardUnits( "module text height" );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pad_size:
|
2013-08-03 05:15:23 +00:00
|
|
|
{
|
|
|
|
wxSize sz;
|
|
|
|
sz.SetWidth( parseBoardUnits( "master pad width" ) );
|
|
|
|
sz.SetHeight( parseBoardUnits( "master pad height" ) );
|
|
|
|
designSettings.m_Pad_Master.SetSize( sz );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pad_drill:
|
2013-08-03 05:15:23 +00:00
|
|
|
{
|
|
|
|
int drillSize = parseBoardUnits( T_pad_drill );
|
|
|
|
designSettings.m_Pad_Master.SetDrillSize( wxSize( drillSize, drillSize ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pad_to_mask_clearance:
|
2018-03-16 22:22:15 +00:00
|
|
|
designSettings.m_SolderMaskMargin = parseBoardUnits( T_pad_to_mask_clearance );
|
2012-11-05 20:20:34 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_mask_min_width:
|
|
|
|
designSettings.m_SolderMaskMinWidth = parseBoardUnits( T_solder_mask_min_width );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pad_to_paste_clearance:
|
|
|
|
designSettings.m_SolderPasteMargin = parseBoardUnits( T_pad_to_paste_clearance );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pad_to_paste_clearance_ratio:
|
|
|
|
designSettings.m_SolderPasteMarginRatio = parseDouble( T_pad_to_paste_clearance_ratio );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_aux_axis_origin:
|
2013-08-03 05:15:23 +00:00
|
|
|
{
|
|
|
|
int x = parseBoardUnits( "auxiliary origin X" );
|
|
|
|
int y = parseBoardUnits( "auxiliary origin Y" );
|
|
|
|
// m_board->SetAuxOrigin( wxPoint( x, y ) ); gets overwritten via SetDesignSettings below
|
|
|
|
designSettings.m_AuxOrigin = wxPoint( x, y );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_grid_origin:
|
|
|
|
{
|
|
|
|
int x = parseBoardUnits( "grid origin X" );
|
|
|
|
int y = parseBoardUnits( "grid origin Y" );
|
|
|
|
// m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten SetDesignSettings below
|
|
|
|
designSettings.m_GridOrigin = wxPoint( x, y );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_visible_elements:
|
2015-03-26 13:20:11 +00:00
|
|
|
designSettings.SetVisibleElements( parseHex() | MIN_VISIBILITY_MASK );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
case T_pcbplotparams:
|
2013-08-03 05:15:23 +00:00
|
|
|
{
|
|
|
|
PCB_PLOT_PARAMS plotParams;
|
|
|
|
PCB_PLOT_PARAMS_PARSER parser( reader );
|
2014-12-04 19:15:26 +00:00
|
|
|
// parser must share the same current line as our current PCB parser
|
|
|
|
// synchronize it.
|
|
|
|
parser.SyncLineReaderWith( *this );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
plotParams.Parse( &parser );
|
2014-12-04 19:15:26 +00:00
|
|
|
SyncLineReaderWith( parser );
|
2012-07-05 17:02:45 +00:00
|
|
|
|
2014-12-04 19:15:26 +00:00
|
|
|
m_board->SetPlotOptions( plotParams );
|
2013-08-03 05:15:23 +00:00
|
|
|
}
|
2012-06-13 23:04:42 +00:00
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Unexpected( CurText() );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->SetDesignSettings( designSettings );
|
|
|
|
m_board->SetZoneSettings( zoneSettings );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseNETINFO_ITEM()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_net,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net." ) );
|
|
|
|
|
2014-06-02 09:41:54 +00:00
|
|
|
int netCode = parseInt( "net number" );
|
2012-08-11 05:50:17 +00:00
|
|
|
|
|
|
|
NeedSYMBOLorNUMBER();
|
2012-06-11 00:47:15 +00:00
|
|
|
wxString name = FromUTF8();
|
2012-08-11 05:50:17 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
|
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.
|
|
|
|
// (TODO: a better test.)
|
2016-09-05 10:22:24 +00:00
|
|
|
if( netCode > NETINFO_LIST::UNCONNECTED || !m_board->FindNet( NETINFO_LIST::UNCONNECTED ) )
|
2012-06-30 08:20:04 +00:00
|
|
|
{
|
2014-06-02 09:41:54 +00:00
|
|
|
NETINFO_ITEM* net = new NETINFO_ITEM( m_board, name, netCode );
|
2016-09-05 10:22:24 +00:00
|
|
|
m_board->Add( net );
|
2014-06-02 09:41:54 +00:00
|
|
|
|
|
|
|
// Store the new code mapping
|
2015-01-22 12:06:34 +00:00
|
|
|
pushValueIntoMap( netCode, net->GetNet() );
|
2012-06-30 08:20:04 +00:00
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void PCB_PARSER::parseNETCLASS()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( CurTok() == T_net_class,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net class." ) );
|
|
|
|
|
|
|
|
T token;
|
|
|
|
|
2016-06-29 15:09:55 +00:00
|
|
|
NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-12-15 13:39:36 +00:00
|
|
|
// Read netclass name (can be a name or just a number like track width)
|
|
|
|
NeedSYMBOLorNUMBER();
|
2012-06-11 00:47:15 +00:00
|
|
|
nc->SetName( FromUTF8() );
|
|
|
|
NeedSYMBOL();
|
|
|
|
nc->SetDescription( FromUTF8() );
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_clearance:
|
|
|
|
nc->SetClearance( parseBoardUnits( T_clearance ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_trace_width:
|
|
|
|
nc->SetTrackWidth( parseBoardUnits( T_trace_width ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via_dia:
|
|
|
|
nc->SetViaDiameter( parseBoardUnits( T_via_dia ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_via_drill:
|
|
|
|
nc->SetViaDrill( parseBoardUnits( T_via_drill ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvia_dia:
|
|
|
|
nc->SetuViaDiameter( parseBoardUnits( T_uvia_dia ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_uvia_drill:
|
|
|
|
nc->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
|
|
|
|
break;
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
case T_diff_pair_width:
|
|
|
|
nc->SetDiffPairWidth( parseBoardUnits( T_diff_pair_width ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_diff_pair_gap:
|
|
|
|
nc->SetDiffPairGap( parseBoardUnits( T_diff_pair_gap ) );
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_add_net:
|
2012-08-11 05:50:17 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2012-06-11 00:47:15 +00:00
|
|
|
nc->Add( FromUTF8() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "clearance, trace_width, via_dia, via_drill, uvia_dia, uvia_drill, diff_pair_width, diff_pair_gap or add_net" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
2014-05-20 09:29:37 +00:00
|
|
|
if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
// Must have been a name conflict, this is a bad board file.
|
|
|
|
// User may have done a hand edit to the file.
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
// unique_ptr will delete nc on this code path
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
wxString error;
|
2018-03-08 05:39:08 +00:00
|
|
|
error.Printf( _( "Duplicate NETCLASS name \"%s\" in file \"%s\" at line %d, offset %d" ),
|
2012-06-11 12:04:34 +00:00
|
|
|
nc->GetName().GetData(), CurSource().GetData(), CurLineNumber(), CurOffset() );
|
2012-06-11 00:47:15 +00:00
|
|
|
THROW_IO_ERROR( error );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-16 13:10:48 +00:00
|
|
|
DRAWSEGMENT* PCB_PARSER::parseDRAWSEGMENT( bool aAllowCirclesZeroWidth )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_gr_arc || CurTok() == T_gr_circle || CurTok() == T_gr_curve ||
|
|
|
|
CurTok() == T_gr_line || CurTok() == T_gr_poly, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DRAWSEGMENT." ) );
|
|
|
|
|
|
|
|
T token;
|
2012-06-16 22:49:24 +00:00
|
|
|
wxPoint pt;
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< DRAWSEGMENT > segment( new DRAWSEGMENT( NULL ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
switch( CurTok() )
|
|
|
|
{
|
|
|
|
case T_gr_arc:
|
|
|
|
segment->SetShape( S_ARC );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
// the start keyword actually gives the arc center
|
|
|
|
// Allows also T_center for future change
|
|
|
|
if( token != T_start && token != T_center )
|
2012-06-11 00:47:15 +00:00
|
|
|
Expecting( T_start );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
2017-07-01 13:16:51 +00:00
|
|
|
segment->SetCenter( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
if( token != T_end ) // the end keyword actually gives the starting point of the arc
|
2012-06-11 00:47:15 +00:00
|
|
|
Expecting( T_end );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
2017-07-01 13:16:51 +00:00
|
|
|
segment->SetArcStart( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_circle:
|
|
|
|
segment->SetShape( S_CIRCLE );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_center )
|
|
|
|
Expecting( T_center );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
2017-07-01 13:16:51 +00:00
|
|
|
segment->SetCenter( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedLEFT();
|
|
|
|
|
|
|
|
token = NextTok();
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
if( token != T_end )
|
|
|
|
Expecting( T_end );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetEnd( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_curve:
|
|
|
|
segment->SetShape( S_CURVE );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
|
|
|
segment->SetStart( parseXY() );
|
|
|
|
segment->SetBezControl1( parseXY() );
|
|
|
|
segment->SetBezControl2( parseXY() );
|
|
|
|
segment->SetEnd( parseXY() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_line:
|
|
|
|
// Default DRAWSEGMENT type is S_SEGMENT.
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( token != T_start )
|
|
|
|
Expecting( T_start );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetStart( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( token != T_end )
|
|
|
|
Expecting( T_end );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetEnd( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_poly:
|
|
|
|
{
|
|
|
|
segment->SetShape( S_POLYGON );
|
2017-11-16 08:38:26 +00:00
|
|
|
segment->SetWidth( 0 ); // this is the default value. will be (perhaps) modified later
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
|
|
|
std::vector< wxPoint > pts;
|
|
|
|
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
pts.push_back( parseXY() );
|
|
|
|
|
|
|
|
segment->SetPolyPoints( pts );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "gr_arc, gr_circle, gr_curve, gr_line, or gr_poly" );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2012-06-16 22:49:24 +00:00
|
|
|
case T_angle:
|
|
|
|
segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_layer:
|
|
|
|
segment->SetLayer( parseBoardItemLayer() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_width:
|
|
|
|
segment->SetWidth( parseBoardUnits( T_width ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
segment->SetTimeStamp( parseHex() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_status:
|
2013-03-28 19:12:46 +00:00
|
|
|
segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "layer, width, tstamp, or status" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:30:48 +00:00
|
|
|
// Only filled polygons may have a zero-line width
|
|
|
|
// This is not permitted in KiCad but some external tools generate invalid
|
|
|
|
// files.
|
2018-09-16 13:10:48 +00:00
|
|
|
// However in custom pad shapes, zero-line width is allowed for filled circles
|
|
|
|
if( segment->GetShape() != S_POLYGON && segment->GetWidth() == 0 &&
|
|
|
|
!( segment->GetShape() == S_CIRCLE && aAllowCirclesZeroWidth ) )
|
2018-09-05 23:30:48 +00:00
|
|
|
segment->SetWidth( Millimeter2iu( DEFAULT_LINE_WIDTH ) );
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
return segment.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
TEXTE_PCB* PCB_PARSER::parseTEXTE_PCB()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_gr_text, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as TEXTE_PCB." ) );
|
|
|
|
|
|
|
|
T token;
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr<TEXTE_PCB> text( new TEXTE_PCB( m_board ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
|
|
|
|
text->SetText( FromUTF8() );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_at )
|
|
|
|
Expecting( T_at );
|
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
2017-01-23 20:30:11 +00:00
|
|
|
text->SetTextPos( pt );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
|
|
|
// If there is no orientation defined, then it is the default value of 0 degrees.
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_NUMBER )
|
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
text->SetTextAngle( parseDouble() * 10.0 );
|
2012-06-16 22:49:24 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else if( token != T_RIGHT )
|
|
|
|
{
|
|
|
|
Unexpected( CurText() );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_layer:
|
|
|
|
text->SetLayer( parseBoardItemLayer() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
text->SetTimeStamp( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_effects:
|
|
|
|
parseEDA_TEXT( (EDA_TEXT*) text.get() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "layer, tstamp or effects" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return text.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
DIMENSION* PCB_PARSER::parseDIMENSION()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_dimension, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DIMENSION." ) );
|
|
|
|
|
|
|
|
T token;
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr<DIMENSION> dimension( new DIMENSION( NULL ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
dimension->SetValue( parseBoardUnits( "dimension value" ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_width )
|
|
|
|
Expecting( T_width );
|
|
|
|
|
|
|
|
dimension->SetWidth( parseBoardUnits( "dimension width value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_layer:
|
|
|
|
dimension->SetLayer( parseBoardItemLayer() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
dimension->SetTimeStamp( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_text:
|
|
|
|
{
|
|
|
|
TEXTE_PCB* text = parseTEXTE_PCB();
|
2018-07-21 12:49:19 +00:00
|
|
|
|
2017-11-26 13:31:15 +00:00
|
|
|
// This copy (using the copy constructor) rebuild the text timestamp,
|
|
|
|
// that is not what we want.
|
2013-03-13 18:53:58 +00:00
|
|
|
dimension->Text() = *text;
|
2017-11-26 13:31:15 +00:00
|
|
|
// reinitialises the text time stamp to the right value (the dimension time stamp)
|
|
|
|
dimension->Text().SetTimeStamp( dimension->GetTimeStamp() );
|
2017-01-23 20:30:11 +00:00
|
|
|
dimension->SetPosition( text->GetTextPos() );
|
2018-07-21 12:49:19 +00:00
|
|
|
|
|
|
|
EDA_UNITS_T units = INCHES;
|
|
|
|
bool useMils = false;
|
|
|
|
FetchUnitsFromString( text->GetText(), units, useMils );
|
|
|
|
dimension->SetUnits( units, useMils );
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
delete text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case T_feature1:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_featureLineDO.x, &dimension->m_featureLineDO.y );
|
|
|
|
parseXY( &dimension->m_featureLineDF.x, &dimension->m_featureLineDF.y );
|
2014-03-12 09:46:11 +00:00
|
|
|
dimension->UpdateHeight();
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_feature2:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_featureLineGO.x, &dimension->m_featureLineGO.y );
|
|
|
|
parseXY( &dimension->m_featureLineGF.x, &dimension->m_featureLineGF.y );
|
2014-03-12 09:46:11 +00:00
|
|
|
dimension->UpdateHeight();
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case T_crossbar:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
|
|
|
|
parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
|
2014-03-12 09:46:11 +00:00
|
|
|
dimension->UpdateHeight();
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_arrow1a:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_arrowD1F.x, &dimension->m_arrowD1F.y );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_arrow1b:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_arrowD2F.x, &dimension->m_arrowD2F.y );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_arrow2a:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_arrowG1F.x, &dimension->m_arrowG1F.y );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_arrow2b:
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2014-02-11 12:22:30 +00:00
|
|
|
parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
|
2012-12-19 19:31:36 +00:00
|
|
|
parseXY( &dimension->m_arrowG2F.x, &dimension->m_arrowG2F.y );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "layer, tstamp, gr_text, feature1, feature2 crossbar, arrow1a, "
|
|
|
|
"arrow1b, arrow2a, or arrow2b" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dimension.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
MODULE* PCB_PARSER::parseMODULE( wxArrayString* aInitialComments )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return parseMODULE_unchecked( aInitialComments );
|
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
|
|
|
if( m_tooRecent )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
|
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MODULE* PCB_PARSER::parseMODULE_unchecked( wxArrayString* aInitialComments )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_module, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as MODULE." ) );
|
|
|
|
|
2013-09-17 14:03:16 +00:00
|
|
|
wxString name;
|
|
|
|
wxPoint pt;
|
|
|
|
T token;
|
2016-11-20 23:35:08 +00:00
|
|
|
LIB_ID fpid;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr<MODULE> module( new MODULE( m_board ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2013-06-23 19:18:33 +00:00
|
|
|
module->SetInitialComments( aInitialComments );
|
|
|
|
|
2016-05-10 19:07:35 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( !IsSymbol( token ) && token != T_NUMBER )
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "symbol|number" );
|
2016-05-10 19:07:35 +00:00
|
|
|
|
2013-09-17 14:03:16 +00:00
|
|
|
name = FromUTF8();
|
2013-09-17 00:52:08 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
if( !name.IsEmpty() && fpid.Parse( name, LIB_ID::ID_PCB, true ) >= 0 )
|
2013-09-17 00:52:08 +00:00
|
|
|
{
|
|
|
|
wxString error;
|
2018-03-08 05:39:08 +00:00
|
|
|
error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2013-09-17 00:52:08 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() );
|
|
|
|
THROW_IO_ERROR( error );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2020-02-28 22:36:56 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2016-05-10 19:07:35 +00:00
|
|
|
case T_version:
|
|
|
|
{
|
|
|
|
// Theoretically a module nested in a PCB could declare its own version, though
|
|
|
|
// as of writing this comment we don't do that. Just in case, take the greater
|
|
|
|
// version.
|
2016-05-10 22:57:10 +00:00
|
|
|
int this_version = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
|
2016-05-10 19:07:35 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
m_requiredVersion = std::max( m_requiredVersion, this_version );
|
2020-02-28 22:36:56 +00:00
|
|
|
m_tooRecent = ( m_requiredVersion > SEXPR_BOARD_FILE_VERSION );
|
2016-05-10 19:07:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_locked:
|
|
|
|
module->SetLocked( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_placed:
|
|
|
|
module->SetIsPlaced( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_layer:
|
2016-03-13 15:39:18 +00:00
|
|
|
{
|
|
|
|
// Footprints can be only on the front side or the back side.
|
|
|
|
// but because we can find some stupid layer in file, ensure a
|
|
|
|
// acceptable layer is set for the footprint
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer = parseBoardItemLayer();
|
2016-03-13 15:39:18 +00:00
|
|
|
module->SetLayer( layer == B_Cu ? B_Cu : F_Cu );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tedit:
|
|
|
|
module->SetLastEditTime( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
module->SetTimeStamp( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_at:
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
module->SetPosition( pt );
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_NUMBER )
|
|
|
|
{
|
|
|
|
module->SetOrientation( parseDouble() * 10.0 );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else if( token != T_RIGHT )
|
|
|
|
{
|
|
|
|
Expecting( T_RIGHT );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_descr:
|
2020-02-28 22:36:56 +00:00
|
|
|
NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
|
2012-06-11 00:47:15 +00:00
|
|
|
module->SetDescription( FromUTF8() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tags:
|
2020-02-28 22:36:56 +00:00
|
|
|
NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
|
2012-06-11 00:47:15 +00:00
|
|
|
module->SetKeywords( FromUTF8() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_path:
|
2012-12-30 15:40:05 +00:00
|
|
|
NeedSYMBOLorNUMBER(); // Paths can be numerical so a number is also a symbol here
|
2012-06-11 00:47:15 +00:00
|
|
|
module->SetPath( FromUTF8() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_autoplace_cost90:
|
2013-03-13 18:53:58 +00:00
|
|
|
module->SetPlacementCost90( parseInt( "auto place cost at 90 degrees" ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_autoplace_cost180:
|
2013-03-13 18:53:58 +00:00
|
|
|
module->SetPlacementCost180( parseInt( "auto place cost at 180 degrees" ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_mask_margin:
|
|
|
|
module->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_paste_margin:
|
|
|
|
module->SetLocalSolderPasteMargin(
|
2020-02-28 22:36:56 +00:00
|
|
|
parseBoardUnits( "local solder paste margin value" ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_paste_ratio:
|
|
|
|
module->SetLocalSolderPasteMarginRatio(
|
2020-02-28 22:36:56 +00:00
|
|
|
parseDouble( "local solder paste margin ratio value" ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_clearance:
|
|
|
|
module->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_zone_connect:
|
|
|
|
module->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thermal_width:
|
|
|
|
module->SetThermalWidth( parseBoardUnits( "thermal width value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thermal_gap:
|
|
|
|
module->SetThermalGap( parseBoardUnits( "thermal gap value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_attr:
|
2020-02-28 22:36:56 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_smd:
|
|
|
|
module->SetAttributes( module->GetAttributes() | MOD_CMS );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_virtual:
|
|
|
|
module->SetAttributes( module->GetAttributes() | MOD_VIRTUAL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "smd and/or virtual" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fp_text:
|
2020-02-28 22:36:56 +00:00
|
|
|
{
|
|
|
|
TEXTE_MODULE* text = parseTEXTE_MODULE();
|
|
|
|
text->SetParent( module.get() );
|
|
|
|
double orientation = text->GetTextAngle();
|
|
|
|
orientation -= module->GetOrientation();
|
|
|
|
text->SetTextAngle( orientation );
|
|
|
|
text->SetDrawCoord();
|
|
|
|
|
|
|
|
switch( text->GetType() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2020-02-28 22:36:56 +00:00
|
|
|
case TEXTE_MODULE::TEXT_is_REFERENCE:
|
|
|
|
module->Reference() = *text;
|
|
|
|
delete text;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEXTE_MODULE::TEXT_is_VALUE:
|
|
|
|
module->Value() = *text;
|
|
|
|
delete text;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
module->GraphicalItemsList().PushBack( text );
|
2014-06-29 20:33:29 +00:00
|
|
|
}
|
2020-02-28 22:36:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
case T_fp_arc:
|
2020-02-28 22:36:56 +00:00
|
|
|
{
|
|
|
|
EDGE_MODULE* em = parseEDGE_MODULE();
|
|
|
|
|
|
|
|
// Drop 0 and NaN angles as these can corrupt/crash the schematic
|
|
|
|
if( std::isnormal( em->GetAngle() ) )
|
2014-06-29 20:33:29 +00:00
|
|
|
{
|
|
|
|
em->SetParent( module.get() );
|
|
|
|
em->SetDrawCoord();
|
2017-04-25 09:06:24 +00:00
|
|
|
module->GraphicalItemsList().PushBack( em );
|
2014-06-29 20:33:29 +00:00
|
|
|
}
|
2020-02-28 22:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fp_circle:
|
|
|
|
case T_fp_curve:
|
|
|
|
case T_fp_line:
|
|
|
|
case T_fp_poly:
|
|
|
|
{
|
|
|
|
EDGE_MODULE* em = parseEDGE_MODULE();
|
|
|
|
em->SetParent( module.get() );
|
|
|
|
em->SetDrawCoord();
|
|
|
|
module->Add( em );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
case T_pad:
|
2020-02-28 22:36:56 +00:00
|
|
|
{
|
|
|
|
D_PAD* pad = parseD_PAD( module.get() );
|
|
|
|
pt = pad->GetPos0();
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2020-02-28 22:36:56 +00:00
|
|
|
RotatePoint( &pt, module->GetOrientation() );
|
|
|
|
pad->SetPosition( pt + module->GetPosition() );
|
|
|
|
module->Add( pad, ADD_APPEND );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
case T_model:
|
|
|
|
module->Add3DModel( parse3DModel() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "locked, placed, tedit, tstamp, at, descr, tags, path, "
|
|
|
|
"autoplace_cost90, autoplace_cost180, solder_mask_margin, "
|
|
|
|
"solder_paste_margin, solder_paste_ratio, clearance, "
|
|
|
|
"zone_connect, thermal_width, thermal_gap, attr, fp_text, "
|
|
|
|
"fp_arc, fp_circle, fp_curve, fp_line, fp_poly, pad, or model" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
module->SetFPID( fpid );
|
2012-11-12 16:19:10 +00:00
|
|
|
module->CalculateBoundingBox();
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
return module.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
TEXTE_MODULE* PCB_PARSER::parseTEXTE_MODULE()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_fp_text, NULL,
|
|
|
|
wxString::Format( wxT( "Cannot parse %s as TEXTE_MODULE at line %d, offset %d." ),
|
2012-08-29 17:28:33 +00:00
|
|
|
GetChars( GetTokenString( CurTok() ) ),
|
|
|
|
CurLineNumber(), CurOffset() ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
T token = NextTok();
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr<TEXTE_MODULE> text( new TEXTE_MODULE( NULL ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_reference:
|
2013-04-07 11:55:18 +00:00
|
|
|
text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_value:
|
2013-04-07 11:55:18 +00:00
|
|
|
text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_user:
|
|
|
|
break; // Default type is user text.
|
|
|
|
|
|
|
|
default:
|
2018-03-08 05:39:08 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Cannot handle footprint text type %s" ),
|
2012-06-11 00:47:15 +00:00
|
|
|
GetChars( FromUTF8() ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
|
|
|
|
text->SetText( FromUTF8() );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_at )
|
|
|
|
Expecting( T_at );
|
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
text->SetPos0( pt );
|
2012-06-16 22:49:24 +00:00
|
|
|
|
2017-11-25 19:55:32 +00:00
|
|
|
NextTok();
|
|
|
|
|
|
|
|
if( CurTok() == T_NUMBER )
|
2012-06-16 22:49:24 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
text->SetTextAngle( parseDouble() * 10.0 );
|
2017-11-25 19:55:32 +00:00
|
|
|
NextTok();
|
2012-06-16 22:49:24 +00:00
|
|
|
}
|
2017-11-25 19:55:32 +00:00
|
|
|
|
|
|
|
if( CurTok() == T_unlocked )
|
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
text->SetKeepUpright( false );
|
2017-11-25 19:55:32 +00:00
|
|
|
NextTok();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( CurTok() != T_RIGHT )
|
2012-06-16 22:49:24 +00:00
|
|
|
{
|
|
|
|
Unexpected( CurText() );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_layer:
|
|
|
|
text->SetLayer( parseBoardItemLayer() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_hide:
|
|
|
|
text->SetVisible( false );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_effects:
|
|
|
|
parseEDA_TEXT( (EDA_TEXT*) text.get() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "hide or effects" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return text.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
EDGE_MODULE* PCB_PARSER::parseEDGE_MODULE()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve ||
|
|
|
|
CurTok() == T_fp_line || CurTok() == T_fp_poly, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDGE_MODULE." ) );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
wxPoint pt;
|
2012-06-11 00:47:15 +00:00
|
|
|
T token;
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< EDGE_MODULE > segment( new EDGE_MODULE( NULL ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
switch( CurTok() )
|
|
|
|
{
|
|
|
|
case T_fp_arc:
|
|
|
|
segment->SetShape( S_ARC );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
// the start keyword actually gives the arc center
|
|
|
|
// Allows also T_center for future change
|
|
|
|
if( token != T_start && token != T_center )
|
2012-06-11 00:47:15 +00:00
|
|
|
Expecting( T_start );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetStart0( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
2012-06-27 20:07:37 +00:00
|
|
|
NeedLEFT();
|
2012-06-11 00:47:15 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
if( token != T_end ) // end keyword actually gives the starting point of the arc
|
2012-06-11 00:47:15 +00:00
|
|
|
Expecting( T_end );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetEnd0( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
2012-06-16 22:49:24 +00:00
|
|
|
NeedLEFT();
|
2012-06-11 00:47:15 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_angle )
|
|
|
|
Expecting( T_angle );
|
|
|
|
|
2012-12-14 21:37:59 +00:00
|
|
|
segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fp_circle:
|
|
|
|
segment->SetShape( S_CIRCLE );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_center )
|
|
|
|
Expecting( T_center );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetStart0( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_end )
|
|
|
|
Expecting( T_end );
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetEnd0( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fp_curve:
|
|
|
|
segment->SetShape( S_CURVE );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
|
|
|
segment->SetStart0( parseXY() );
|
2018-07-07 11:04:01 +00:00
|
|
|
segment->SetBezier0_C1( parseXY() );
|
|
|
|
segment->SetBezier0_C2( parseXY() );
|
2012-06-11 00:47:15 +00:00
|
|
|
segment->SetEnd0( parseXY() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fp_line:
|
|
|
|
// Default DRAWSEGMENT type is S_SEGMENT.
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
if( token != T_start )
|
|
|
|
Expecting( T_start );
|
|
|
|
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetStart0( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_end )
|
|
|
|
Expecting( T_end );
|
|
|
|
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
segment->SetEnd0( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fp_poly:
|
|
|
|
{
|
|
|
|
segment->SetShape( S_POLYGON );
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
|
|
|
std::vector< wxPoint > pts;
|
|
|
|
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
pts.push_back( parseXY() );
|
|
|
|
|
|
|
|
segment->SetPolyPoints( pts );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "fp_arc, fp_circle, fp_curve, fp_line, or fp_poly" );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_layer:
|
|
|
|
segment->SetLayer( parseBoardItemLayer() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_width:
|
|
|
|
segment->SetWidth( parseBoardUnits( T_width ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
segment->SetTimeStamp( parseHex() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_status:
|
2013-03-28 19:12:46 +00:00
|
|
|
segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "layer or width" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
2018-09-05 23:30:48 +00:00
|
|
|
// Only filled polygons may have a zero-line width
|
|
|
|
// This is not permitted in KiCad but some external tools generate invalid
|
|
|
|
// files.
|
|
|
|
if( segment->GetShape() != S_POLYGON && segment->GetWidth() == 0 )
|
|
|
|
segment->SetWidth( Millimeter2iu( DEFAULT_LINE_WIDTH ) );
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
return segment.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_pad, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) );
|
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
wxSize sz;
|
2012-06-11 00:47:15 +00:00
|
|
|
wxPoint pt;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< D_PAD > pad( new D_PAD( aParent ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
NeedSYMBOLorNUMBER();
|
2017-08-11 09:22:13 +00:00
|
|
|
pad->SetName( FromUTF8() );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_thru_hole:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB_STANDARD );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_smd:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB_SMD );
|
2013-02-13 01:01:22 +00:00
|
|
|
|
|
|
|
// Default D_PAD object is thru hole with drill.
|
2013-03-10 13:59:47 +00:00
|
|
|
// SMD pads have no hole
|
2013-02-13 01:01:22 +00:00
|
|
|
pad->SetDrillSize( wxSize( 0, 0 ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_connect:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB_CONN );
|
2013-03-10 13:59:47 +00:00
|
|
|
|
|
|
|
// Default D_PAD object is thru hole with drill.
|
|
|
|
// CONN pads have no hole
|
|
|
|
pad->SetDrillSize( wxSize( 0, 0 ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_np_thru_hole:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB_HOLE_NOT_PLATED );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "thru_hole, smd, connect, or np_thru_hole" );
|
|
|
|
}
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_circle:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetShape( PAD_SHAPE_CIRCLE );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
case T_rect:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetShape( PAD_SHAPE_RECT );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_oval:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetShape( PAD_SHAPE_OVAL );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_trapezoid:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetShape( PAD_SHAPE_TRAPEZOID );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
2016-04-06 18:15:49 +00:00
|
|
|
case T_roundrect:
|
|
|
|
pad->SetShape( PAD_SHAPE_ROUNDRECT );
|
|
|
|
break;
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
case T_custom:
|
|
|
|
pad->SetShape( PAD_SHAPE_CUSTOM );
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
default:
|
2016-04-06 18:15:49 +00:00
|
|
|
Expecting( "circle, rectangle, roundrect, oval, trapezoid or custom" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_size:
|
|
|
|
sz.SetWidth( parseBoardUnits( "width value" ) );
|
|
|
|
sz.SetHeight( parseBoardUnits( "height value" ) );
|
|
|
|
pad->SetSize( sz );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_at:
|
|
|
|
pt.x = parseBoardUnits( "X coordinate" );
|
|
|
|
pt.y = parseBoardUnits( "Y coordinate" );
|
|
|
|
pad->SetPos0( pt );
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_NUMBER )
|
|
|
|
{
|
|
|
|
pad->SetOrientation( parseDouble() * 10.0 );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else if( token != T_RIGHT )
|
|
|
|
{
|
|
|
|
Expecting( ") or angle value" );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
case T_rect_delta:
|
2014-06-29 20:33:29 +00:00
|
|
|
{
|
|
|
|
wxSize delta;
|
|
|
|
delta.SetWidth( parseBoardUnits( "rectangle delta width" ) );
|
|
|
|
delta.SetHeight( parseBoardUnits( "rectangle delta height" ) );
|
|
|
|
pad->SetDelta( delta );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-13 23:04:42 +00:00
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
case T_drill:
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2014-06-29 20:33:29 +00:00
|
|
|
bool haveWidth = false;
|
|
|
|
wxSize drillSize = pad->GetDrillSize();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
2012-06-13 23:04:42 +00:00
|
|
|
{
|
2014-06-29 20:33:29 +00:00
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2012-06-24 01:19:41 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
switch( token )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2014-06-29 20:33:29 +00:00
|
|
|
case T_oval:
|
2015-08-23 19:40:33 +00:00
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
|
2014-06-29 20:33:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NUMBER:
|
|
|
|
{
|
|
|
|
if( !haveWidth )
|
|
|
|
{
|
|
|
|
drillSize.SetWidth( parseBoardUnits() );
|
|
|
|
|
|
|
|
// If height is not defined the width and height are the same.
|
|
|
|
drillSize.SetHeight( drillSize.GetWidth() );
|
|
|
|
haveWidth = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drillSize.SetHeight( parseBoardUnits() );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_offset:
|
|
|
|
pt.x = parseBoardUnits( "drill offset x" );
|
|
|
|
pt.y = parseBoardUnits( "drill offset y" );
|
|
|
|
pad->SetOffset( pt );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "oval, size, or offset" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
// This fixes a bug caused by setting the default D_PAD drill size to a value
|
|
|
|
// other than 0 used to fix a bunch of debug assertions even though it is defined
|
|
|
|
// as a through hole pad. Wouldn't a though hole pad with no drill be a surface
|
|
|
|
// mount pad (or a conn pad which is a smd pad with no solder paste)?
|
2015-08-23 19:40:33 +00:00
|
|
|
if( ( pad->GetAttribute() != PAD_ATTRIB_SMD ) && ( pad->GetAttribute() != PAD_ATTRIB_CONN ) )
|
2014-06-29 20:33:29 +00:00
|
|
|
pad->SetDrillSize( drillSize );
|
|
|
|
else
|
|
|
|
pad->SetDrillSize( wxSize( 0, 0 ) );
|
2012-06-13 23:04:42 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_layers:
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET layerMask = parseBoardItemLayersAsMask();
|
|
|
|
pad->SetLayerSet( layerMask );
|
2012-11-14 07:15:59 +00:00
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_net:
|
2015-06-12 13:59:58 +00:00
|
|
|
if( ! pad->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
|
|
|
|
THROW_IO_ERROR(
|
2018-03-08 05:39:08 +00:00
|
|
|
wxString::Format( _( "Invalid net ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2015-06-12 13:59:58 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() )
|
|
|
|
);
|
2012-08-11 05:50:17 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2015-07-29 18:55:56 +00:00
|
|
|
if( m_board && FromUTF8() != m_board->FindNet( pad->GetNetCode() )->GetNetname() )
|
2015-06-12 13:59:58 +00:00
|
|
|
THROW_IO_ERROR(
|
2018-03-08 05:39:08 +00:00
|
|
|
wxString::Format( _( "Invalid net ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2015-06-12 13:59:58 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() )
|
|
|
|
);
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_die_length:
|
2012-12-12 11:57:17 +00:00
|
|
|
pad->SetPadToDieLength( parseBoardUnits( T_die_length ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_mask_margin:
|
|
|
|
pad->SetLocalSolderMaskMargin( parseBoardUnits( T_solder_mask_margin ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_paste_margin:
|
|
|
|
pad->SetLocalSolderPasteMargin( parseBoardUnits( T_solder_paste_margin ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_solder_paste_margin_ratio:
|
2013-04-19 07:14:27 +00:00
|
|
|
pad->SetLocalSolderPasteMarginRatio(
|
|
|
|
parseDouble( "pad local solder paste margin ratio value" ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_clearance:
|
|
|
|
pad->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_zone_connect:
|
|
|
|
pad->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thermal_width:
|
|
|
|
pad->SetThermalWidth( parseBoardUnits( T_thermal_width ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thermal_gap:
|
|
|
|
pad->SetThermalGap( parseBoardUnits( T_thermal_gap ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2016-04-06 18:15:49 +00:00
|
|
|
case T_roundrect_rratio:
|
|
|
|
pad->SetRoundRectRadiusRatio( parseDouble( "roundrect radius ratio" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
case T_options:
|
|
|
|
parseD_PAD_option( pad.get() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_primitives:
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
// Currently, I am using parseDRAWSEGMENT() to read basic shapes parameters,
|
|
|
|
// because they are the same as a DRAWSEGMENT.
|
|
|
|
// However it could be better to write a specific parser, to avoid possible issues
|
|
|
|
// if the DRAWSEGMENT parser is modified.
|
|
|
|
DRAWSEGMENT* dummysegm = NULL;
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_gr_arc:
|
|
|
|
dummysegm = parseDRAWSEGMENT();
|
2017-09-20 08:28:52 +00:00
|
|
|
pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetArcStart(),
|
2017-01-13 17:51:22 +00:00
|
|
|
dummysegm->GetAngle(), dummysegm->GetWidth() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_line:
|
|
|
|
dummysegm = parseDRAWSEGMENT();
|
2017-09-20 08:28:52 +00:00
|
|
|
pad->AddPrimitive( dummysegm->GetStart(), dummysegm->GetEnd(),
|
2017-01-13 17:51:22 +00:00
|
|
|
dummysegm->GetWidth() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_circle:
|
2018-09-16 13:10:48 +00:00
|
|
|
dummysegm = parseDRAWSEGMENT( true ); // Circles with 0 thickness are allowed
|
|
|
|
// ( filled circles )
|
2017-09-20 08:28:52 +00:00
|
|
|
pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetRadius(),
|
2017-01-13 17:51:22 +00:00
|
|
|
dummysegm->GetWidth() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_gr_poly:
|
|
|
|
dummysegm = parseDRAWSEGMENT();
|
2018-01-24 13:22:43 +00:00
|
|
|
pad->AddPrimitive( dummysegm->BuildPolyPointsList(), dummysegm->GetWidth() );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "gr_line, gr_arc, gr_circle or gr_poly" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dummysegm;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "at, drill, layers, net, die_length, solder_mask_margin, roundrect_rratio,\n"
|
|
|
|
"solder_paste_margin, solder_paste_margin_ratio, clearance,\n"
|
|
|
|
"zone_connect, fp_poly, primitives, thermal_width, or thermal_gap" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
// Be sure the custom shape polygon is built:
|
|
|
|
if( pad->GetShape() == PAD_SHAPE_CUSTOM )
|
2017-09-20 08:28:52 +00:00
|
|
|
pad->MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
return pad.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
bool PCB_PARSER::parseD_PAD_option( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
// Parse only the (option ...) inside a pad description
|
|
|
|
for( T token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_anchor:
|
|
|
|
token = NextTok();
|
|
|
|
// Custom shaped pads have a "anchor pad", which is the reference
|
|
|
|
// for connection calculations.
|
|
|
|
// Because this is an anchor, only the 2 very basic shapes are managed:
|
|
|
|
// circle and rect. The default is circle
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_circle: // default
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rect:
|
|
|
|
aPad->SetAnchorPadShape( PAD_SHAPE_RECT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
// Currently, because pad options is a moving target
|
|
|
|
// just skip unknown keywords
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_clearance:
|
|
|
|
token = NextTok();
|
|
|
|
// Custom shaped pads have a clearance area that is the pad shape
|
2018-03-16 18:11:36 +00:00
|
|
|
// (like usual pads) or the convew hull of the pad shape.
|
2017-01-13 17:51:22 +00:00
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_outline:
|
|
|
|
aPad->SetCustomShapeInZoneOpt( CUST_PAD_SHAPE_IN_ZONE_OUTLINE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_convexhull:
|
|
|
|
aPad->SetCustomShapeInZoneOpt( CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
// Currently, because pad options is a moving target
|
|
|
|
// just skip unknown keywords
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
// Currently, because pad options is a moving target
|
|
|
|
// just skip unknown keywords
|
|
|
|
while( (token = NextTok() ) != T_RIGHT )
|
|
|
|
{}
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
TRACK* PCB_PARSER::parseTRACK()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_segment, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as TRACK." ) );
|
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
T token;
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< TRACK > track( new TRACK( m_board ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_start:
|
|
|
|
pt.x = parseBoardUnits( "start x" );
|
|
|
|
pt.y = parseBoardUnits( "start y" );
|
|
|
|
track->SetStart( pt );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_end:
|
|
|
|
pt.x = parseBoardUnits( "end x" );
|
|
|
|
pt.y = parseBoardUnits( "end y" );
|
|
|
|
track->SetEnd( pt );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_width:
|
|
|
|
track->SetWidth( parseBoardUnits( "width" ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_layer:
|
|
|
|
track->SetLayer( parseBoardItemLayer() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_net:
|
2015-06-08 19:28:04 +00:00
|
|
|
if( ! track->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
|
|
|
|
THROW_IO_ERROR(
|
2018-03-08 05:39:08 +00:00
|
|
|
wxString::Format( _( "Invalid net ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2015-06-08 19:28:04 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() )
|
|
|
|
);
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
track->SetTimeStamp( parseHex() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_status:
|
2013-03-28 19:12:46 +00:00
|
|
|
track->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "start, end, width, layer, net, tstamp, or status" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
|
|
|
return track.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
VIA* PCB_PARSER::parseVIA()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_via, NULL,
|
2014-04-25 06:00:04 +00:00
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as VIA." ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
T token;
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< VIA > via( new VIA( m_board ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_blind:
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( VIA_BLIND_BURIED );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_micro:
|
2014-04-25 06:00:04 +00:00
|
|
|
via->SetViaType( VIA_MICROVIA );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_at:
|
|
|
|
pt.x = parseBoardUnits( "start x" );
|
|
|
|
pt.y = parseBoardUnits( "start y" );
|
|
|
|
via->SetStart( pt );
|
2012-06-13 23:04:42 +00:00
|
|
|
via->SetEnd( pt );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_size:
|
|
|
|
via->SetWidth( parseBoardUnits( "via width" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_drill:
|
|
|
|
via->SetDrill( parseBoardUnits( "drill diameter" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_layers:
|
2012-11-14 07:15:59 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID layer1, layer2;
|
2012-11-14 07:15:59 +00:00
|
|
|
NextTok();
|
2017-03-13 03:19:33 +00:00
|
|
|
layer1 = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
|
2012-11-14 07:15:59 +00:00
|
|
|
NextTok();
|
2017-03-13 03:19:33 +00:00
|
|
|
layer2 = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
|
2012-11-14 07:15:59 +00:00
|
|
|
via->SetLayerPair( layer1, layer2 );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_net:
|
2015-06-12 13:59:58 +00:00
|
|
|
if(! via->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true))
|
|
|
|
THROW_IO_ERROR(
|
2018-03-08 05:39:08 +00:00
|
|
|
wxString::Format( _( "Invalid net ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2015-06-12 13:59:58 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() )
|
|
|
|
);
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
via->SetTimeStamp( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_status:
|
2013-03-28 19:12:46 +00:00
|
|
|
via->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "blind, micro, at, size, drill, layers, net, tstamp, or status" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return via.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_zone, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
|
|
|
|
wxT( " as ZONE_CONTAINER." ) );
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
ZONE_CONTAINER::HATCH_STYLE hatchStyle = ZONE_CONTAINER::NO_HATCH;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
int hatchPitch = ZONE_CONTAINER::GetDefaultHatchPitch();
|
2012-06-11 00:47:15 +00:00
|
|
|
wxPoint pt;
|
|
|
|
T token;
|
2015-01-22 12:06:34 +00:00
|
|
|
int tmp;
|
|
|
|
wxString netnameFromfile; // the zone net name find in file
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-07-05 17:02:45 +00:00
|
|
|
// bigger scope since each filled_polygon is concatenated in here
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET pts;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< ZONE_CONTAINER > zone( new ZONE_CONTAINER( m_board ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
zone->SetPriority( 0 );
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_net:
|
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)
|
2015-01-22 12:06:34 +00:00
|
|
|
tmp = getNetCode( parseInt( "net number" ) );
|
|
|
|
|
|
|
|
if( tmp < 0 )
|
|
|
|
tmp = 0;
|
|
|
|
|
2015-06-12 13:59:58 +00:00
|
|
|
if( ! zone->SetNetCode( tmp, /* aNoAssert */ true ) )
|
|
|
|
THROW_IO_ERROR(
|
2018-03-08 05:39:08 +00:00
|
|
|
wxString::Format( _( "Invalid net ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
2015-06-12 13:59:58 +00:00
|
|
|
GetChars( CurSource() ), CurLineNumber(), CurOffset() )
|
|
|
|
);
|
2015-01-22 12:06:34 +00:00
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_net_name:
|
2013-02-28 16:17:24 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2015-01-22 12:06:34 +00:00
|
|
|
netnameFromfile = FromUTF8();
|
2012-06-11 00:47:15 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2017-09-27 16:56:06 +00:00
|
|
|
case T_layer: // keyword for zones that are on only one layer
|
2012-06-11 00:47:15 +00:00
|
|
|
zone->SetLayer( parseBoardItemLayer() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2017-09-27 16:56:06 +00:00
|
|
|
case T_layers: // keyword for zones that can live on a set of layer
|
|
|
|
// currently: keepout zones
|
|
|
|
zone->SetLayerSet( parseBoardItemLayersAsMask() );
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_tstamp:
|
|
|
|
zone->SetTimeStamp( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_hatch:
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_none && token != T_edge && token != T_full )
|
|
|
|
Expecting( "none, edge, or full" );
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
default:
|
2017-03-07 12:06:00 +00:00
|
|
|
case T_none: hatchStyle = ZONE_CONTAINER::NO_HATCH; break;
|
|
|
|
case T_edge: hatchStyle = ZONE_CONTAINER::DIAGONAL_EDGE; break;
|
|
|
|
case T_full: hatchStyle = ZONE_CONTAINER::DIAGONAL_FULL;
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hatchPitch = parseBoardUnits( "hatch pitch" );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_priority:
|
|
|
|
zone->SetPriority( parseInt( "zone priority" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_connect_pads:
|
2012-06-16 22:49:24 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
2012-06-16 22:49:24 +00:00
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_yes:
|
2015-08-18 14:19:17 +00:00
|
|
|
zone->SetPadConnection( PAD_ZONE_CONN_FULL );
|
2012-06-16 22:49:24 +00:00
|
|
|
break;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
case T_no:
|
2015-08-18 14:19:17 +00:00
|
|
|
zone->SetPadConnection( PAD_ZONE_CONN_NONE );
|
2012-06-16 22:49:24 +00:00
|
|
|
break;
|
|
|
|
|
2012-07-09 07:10:07 +00:00
|
|
|
case T_thru_hole_only:
|
2015-08-18 14:19:17 +00:00
|
|
|
zone->SetPadConnection( PAD_ZONE_CONN_THT_THERMAL );
|
2012-07-09 07:10:07 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-16 22:49:24 +00:00
|
|
|
case T_clearance:
|
|
|
|
zone->SetZoneClearance( parseBoardUnits( "zone clearance" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "yes, no, or clearance" );
|
|
|
|
}
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_min_thickness:
|
|
|
|
zone->SetMinThickness( parseBoardUnits( T_min_thickness ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fill:
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
2012-06-16 22:49:24 +00:00
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2012-06-16 22:49:24 +00:00
|
|
|
case T_yes:
|
|
|
|
zone->SetIsFilled( true );
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_mode:
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_segment && token != T_polygon )
|
|
|
|
Expecting( "segment or polygon" );
|
|
|
|
|
|
|
|
// @todo Create an enum for fill modes.
|
2017-12-04 18:06:47 +00:00
|
|
|
zone->SetFillMode( token == T_polygon ? ZFM_POLYGONS : ZFM_SEGMENTS );
|
2013-04-25 12:25:47 +00:00
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_arc_segments:
|
2013-03-18 19:36:07 +00:00
|
|
|
zone->SetArcSegmentCount( parseInt( "arc segment count" ) );
|
2013-04-25 12:25:47 +00:00
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thermal_gap:
|
|
|
|
zone->SetThermalReliefGap( parseBoardUnits( T_thermal_gap ) );
|
2013-04-25 12:25:47 +00:00
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_thermal_bridge_width:
|
|
|
|
zone->SetThermalReliefCopperBridge( parseBoardUnits( T_thermal_bridge_width ) );
|
2013-04-25 12:25:47 +00:00
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_smoothing:
|
|
|
|
switch( NextTok() )
|
|
|
|
{
|
|
|
|
case T_none:
|
|
|
|
zone->SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_NONE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_chamfer:
|
2016-02-02 20:32:11 +00:00
|
|
|
if( !zone->GetIsKeepout() ) // smoothing has meaning only for filled zones
|
2016-02-04 16:49:20 +00:00
|
|
|
zone->SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_CHAMFER );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fillet:
|
2016-02-02 20:32:11 +00:00
|
|
|
if( !zone->GetIsKeepout() ) // smoothing has meaning only for filled zones
|
2016-02-04 16:49:20 +00:00
|
|
|
zone->SetCornerSmoothingType( ZONE_SETTINGS::SMOOTHING_FILLET );
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Expecting( "none, chamfer, or fillet" );
|
|
|
|
}
|
2013-04-25 12:25:47 +00:00
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_radius:
|
2016-02-02 20:32:11 +00:00
|
|
|
tmp = parseBoardUnits( "corner radius" );
|
|
|
|
if( !zone->GetIsKeepout() ) // smoothing has meaning only for filled zones
|
|
|
|
zone->SetCornerRadius( tmp );
|
2013-04-25 12:25:47 +00:00
|
|
|
NeedRIGHT();
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "mode, arc_segments, thermal_gap, thermal_bridge_width, "
|
|
|
|
"smoothing, or radius" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
case T_keepout:
|
|
|
|
zone->SetIsKeepout( true );
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_tracks:
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_allowed && token != T_not_allowed )
|
|
|
|
Expecting( "allowed or not_allowed" );
|
|
|
|
zone->SetDoNotAllowTracks( token == T_not_allowed );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_vias:
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_allowed && token != T_not_allowed )
|
|
|
|
Expecting( "allowed or not_allowed" );
|
|
|
|
zone->SetDoNotAllowVias( token == T_not_allowed );
|
|
|
|
break;
|
|
|
|
|
2012-07-14 16:27:25 +00:00
|
|
|
case T_copperpour:
|
2012-07-13 18:55:29 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_allowed && token != T_not_allowed )
|
|
|
|
Expecting( "allowed or not_allowed" );
|
2012-07-14 16:27:25 +00:00
|
|
|
zone->SetDoNotAllowCopperPour( token == T_not_allowed );
|
2012-07-13 18:55:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "tracks, vias or copperpour" );
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_polygon:
|
2014-06-30 04:40:16 +00:00
|
|
|
{
|
|
|
|
std::vector< wxPoint > corners;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-04-07 06:02:26 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
2014-06-30 04:40:16 +00:00
|
|
|
{
|
|
|
|
corners.push_back( parseXY() );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
NeedRIGHT();
|
2017-04-07 06:02:26 +00:00
|
|
|
|
|
|
|
// Remark: The first polygon is the main outline.
|
|
|
|
// Others are holes inside the main outline.
|
2014-06-30 04:40:16 +00:00
|
|
|
zone->AddPolygon( corners );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_filled_polygon:
|
|
|
|
{
|
2014-06-30 04:40:16 +00:00
|
|
|
// "(filled_polygon (pts"
|
|
|
|
NeedLEFT();
|
|
|
|
token = NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
pts.NewOutline();
|
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
pts.Append( parseXY() );
|
2014-06-30 04:40:16 +00:00
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_fill_segments:
|
|
|
|
{
|
2017-12-04 18:06:47 +00:00
|
|
|
ZONE_SEGMENT_FILL segs;
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
|
|
|
Expecting( T_LEFT );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
token = NextTok();
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2014-06-30 04:40:16 +00:00
|
|
|
if( token != T_pts )
|
|
|
|
Expecting( T_pts );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
SEG segment( parseXY(), parseXY() );
|
2014-06-30 04:40:16 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
segs.push_back( segment );
|
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
zone->SetFillSegments( segs );
|
2014-06-30 04:40:16 +00:00
|
|
|
}
|
2012-06-11 00:47:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "net, layer/layers, tstamp, hatch, priority, connect_pads, min_thickness, "
|
|
|
|
"fill, polygon, filled_polygon, or fill_segments" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( zone->GetNumCorners() > 2 )
|
|
|
|
{
|
|
|
|
if( !zone->IsOnCopperLayer() )
|
|
|
|
{
|
2017-12-04 18:06:47 +00:00
|
|
|
zone->SetFillMode( ZFM_POLYGONS );
|
2014-02-25 10:47:27 +00:00
|
|
|
zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set hatch here, after outlines corners are read
|
2017-03-07 12:06:00 +00:00
|
|
|
zone->SetHatch( hatchStyle, hatchPitch, true );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( !pts.IsEmpty() )
|
2017-12-04 18:06:47 +00:00
|
|
|
zone->SetFilledPolysList( pts );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
2015-01-22 12:06:34 +00:00
|
|
|
// Ensure keepout and non copper zones do not have a net
|
|
|
|
// (which have no sense for these zones)
|
|
|
|
// the netcode 0 is used for these zones
|
|
|
|
bool zone_has_net = zone->IsOnCopperLayer() && !zone->GetIsKeepout();
|
|
|
|
|
|
|
|
if( !zone_has_net )
|
2014-02-25 10:47:27 +00:00
|
|
|
zone->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2013-03-10 13:59:47 +00:00
|
|
|
|
2015-01-22 12:06:34 +00:00
|
|
|
// Ensure the zone net name is valid, and matches the net code, for copper zones
|
|
|
|
if( zone_has_net && ( zone->GetNet()->GetNetname() != netnameFromfile ) )
|
|
|
|
{
|
|
|
|
// Can happens which old boards, with nonexistent nets ...
|
|
|
|
// or after being edited by hand
|
|
|
|
// We try to fix the mismatch.
|
|
|
|
NETINFO_ITEM* net = m_board->FindNet( netnameFromfile );
|
|
|
|
|
|
|
|
if( net ) // An existing net has the same net name. use it for the zone
|
|
|
|
zone->SetNetCode( net->GetNet() );
|
|
|
|
else // Not existing net: add a new net to keep trace of the zone netname
|
|
|
|
{
|
|
|
|
int newnetcode = m_board->GetNetCount();
|
|
|
|
net = new NETINFO_ITEM( m_board, netnameFromfile, newnetcode );
|
2016-09-05 10:22:24 +00:00
|
|
|
m_board->Add( net );
|
2015-01-22 12:06:34 +00:00
|
|
|
|
|
|
|
// Store the new code mapping
|
|
|
|
pushValueIntoMap( newnetcode, net->GetNet() );
|
|
|
|
// and update the zone netcode
|
|
|
|
zone->SetNetCode( net->GetNet() );
|
|
|
|
|
2017-09-27 16:56:06 +00:00
|
|
|
// FIXME: a call to any GUI item is not allowed in io plugins:
|
|
|
|
// Change this code to generate a warning message outside this plugin
|
2015-01-22 12:06:34 +00:00
|
|
|
// Prompt the user
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "There is a zone that belongs to a not existing net\n"
|
|
|
|
"\"%s\"\n"
|
|
|
|
"you should verify and edit it (run DRC test)." ),
|
|
|
|
GetChars( netnameFromfile ) );
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
return zone.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
PCB_TARGET* PCB_PARSER::parsePCB_TARGET()
|
2012-06-11 00:47:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( CurTok() == T_target, NULL,
|
|
|
|
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TARGET." ) );
|
|
|
|
|
|
|
|
wxPoint pt;
|
|
|
|
T token;
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
std::unique_ptr< PCB_TARGET > target( new PCB_TARGET( NULL ) );
|
2012-06-11 00:47:15 +00:00
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_x:
|
|
|
|
target->SetShape( 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_plus:
|
|
|
|
target->SetShape( 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_at:
|
|
|
|
pt.x = parseBoardUnits( "target x position" );
|
|
|
|
pt.y = parseBoardUnits( "target y position" );
|
|
|
|
target->SetPosition( pt );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_size:
|
|
|
|
target->SetSize( parseBoardUnits( "target size" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_width:
|
|
|
|
target->SetWidth( parseBoardUnits( "target thickness" ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2012-06-13 23:04:42 +00:00
|
|
|
case T_layer:
|
|
|
|
target->SetLayer( parseBoardItemLayer() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2012-06-11 00:47:15 +00:00
|
|
|
case T_tstamp:
|
|
|
|
target->SetTimeStamp( parseHex() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-16 18:11:36 +00:00
|
|
|
Expecting( "x, plus, at, size, width, layer or tstamp" );
|
2012-06-11 00:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target.release();
|
|
|
|
}
|