2013-07-19 18:27:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2013 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
|
2022-01-17 17:02:44 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-07-19 18:27:22 +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
|
|
|
|
*/
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
#include <wx/ffile.h>
|
|
|
|
#include <wx/log.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_painter.h>
|
2021-08-27 11:52:13 +00:00
|
|
|
#include <drawing_sheet/drawing_sheet_lexer.h>
|
|
|
|
#include <drawing_sheet/ds_file_versions.h>
|
2022-02-28 18:02:00 +00:00
|
|
|
#include <font/font.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
using namespace DRAWINGSHEET_T;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
/**
|
2021-08-27 11:52:13 +00:00
|
|
|
* DRAWING_SHEET_PARSER
|
2013-07-19 18:27:22 +00:00
|
|
|
* holds data and functions pertinent to parsing a S-expression file
|
2021-02-22 23:47:17 +00:00
|
|
|
* for a DS_DATA_MODEL.
|
2013-07-19 18:27:22 +00:00
|
|
|
*/
|
2021-08-27 11:52:13 +00:00
|
|
|
class DRAWING_SHEET_PARSER : public DRAWING_SHEET_LEXER
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-08-27 11:52:13 +00:00
|
|
|
DRAWING_SHEET_PARSER( const char* aLine, const wxString& aSource );
|
2021-02-22 23:47:17 +00:00
|
|
|
void Parse( DS_DATA_MODEL* aLayout );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
private:
|
2021-06-10 22:39:03 +00:00
|
|
|
int m_requiredVersion;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse the data specified at the very beginning of the file, like version and the
|
|
|
|
* application used to create this file.
|
|
|
|
*/
|
|
|
|
void parseHeader( T aHeaderType );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse an integer.
|
|
|
|
*/
|
|
|
|
int parseInt();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse an integer and constrain it between two values.
|
|
|
|
*
|
2013-07-19 18:27:22 +00:00
|
|
|
* @param aMin is the smallest return value.
|
|
|
|
* @param aMax is the largest return value.
|
|
|
|
* @return int - the parsed integer.
|
|
|
|
*/
|
|
|
|
int parseInt( int aMin, int aMax );
|
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse a double.
|
|
|
|
*
|
2013-07-19 18:27:22 +00:00
|
|
|
* @return double - the parsed double.
|
|
|
|
*/
|
|
|
|
double parseDouble();
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void parseSetup( DS_DATA_MODEL* aLayout );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse a graphic item starting by "(line" or "(rect" and read parameters.
|
2016-03-22 09:46:18 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
void parseGraphic( DS_DATA_ITEM * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse a text item starting by "(tbtext" and read parameters.
|
2016-03-22 09:46:18 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
void parseText( DS_DATA_ITEM_TEXT * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse a polygon item starting by "( polygon" and read parameters.
|
|
|
|
* the list of corners included in this description is read by parsePolyOutline.
|
2016-03-22 09:46:18 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
void parsePolygon( DS_DATA_ITEM_POLYGONS * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse a list of corners starting by "( pts" and read coordinates.
|
2016-03-22 09:46:18 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
void parsePolyOutline( DS_DATA_ITEM_POLYGONS * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-10 22:39:03 +00:00
|
|
|
* Parse a bitmap item starting by "( bitmap" and read parameters.
|
2016-03-22 09:46:18 +00:00
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
void parseBitmap( DS_DATA_ITEM_BITMAP * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void parseCoordinate( POINT_COORD& aCoord);
|
2021-02-22 23:47:17 +00:00
|
|
|
void readOption( DS_DATA_ITEM * aItem );
|
|
|
|
void readPngdata( DS_DATA_ITEM_BITMAP * aItem );
|
2013-07-19 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// PCB_PLOT_PARAMS_PARSER
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
DRAWING_SHEET_PARSER::DRAWING_SHEET_PARSER( const char* aLine,
|
|
|
|
const wxString& aSource ) :
|
|
|
|
DRAWING_SHEET_LEXER( aLine, aSource ),
|
2021-06-10 22:39:03 +00:00
|
|
|
m_requiredVersion( 0 )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
wxString convertLegacyVariableRefs( const wxString& aTextbase )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Legacy formats
|
|
|
|
* %% = replaced by %
|
|
|
|
* %K = Kicad version
|
|
|
|
* %Z = paper format name (A4, USLetter)
|
|
|
|
* %Y = company name
|
|
|
|
* %D = date
|
|
|
|
* %R = revision
|
|
|
|
* %S = sheet number
|
|
|
|
* %N = number of sheets
|
|
|
|
* %L = layer name
|
|
|
|
* %Cx = comment (x = 0 to 9 to identify the comment)
|
|
|
|
* %F = filename
|
|
|
|
* %P = sheet path (sheet full name)
|
|
|
|
* %T = title
|
|
|
|
*/
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aTextbase.Len(); ii++ )
|
|
|
|
{
|
|
|
|
if( aTextbase[ii] != '%' )
|
|
|
|
{
|
|
|
|
msg << aTextbase[ii];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ++ii >= aTextbase.Len() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
wxChar format = aTextbase[ii];
|
|
|
|
|
|
|
|
switch( format )
|
|
|
|
{
|
|
|
|
case '%': msg += '%'; break;
|
|
|
|
case 'D': msg += wxT( "${ISSUE_DATE}" ); break;
|
|
|
|
case 'R': msg += wxT( "${REVISION}" ); break;
|
|
|
|
case 'K': msg += wxT( "${KICAD_VERSION}" ); break;
|
|
|
|
case 'Z': msg += wxT( "${PAPER}" ); break;
|
|
|
|
case 'S': msg += wxT( "${#}" ); break;
|
|
|
|
case 'N': msg += wxT( "${##}" ); break;
|
|
|
|
case 'F': msg += wxT( "${FILENAME}" ); break;
|
|
|
|
case 'L': msg += wxT( "${LAYER}" ); break;
|
2022-04-09 14:38:47 +00:00
|
|
|
case 'P': msg += wxT( "${SHEETPATH}" ); break;
|
2020-03-26 11:02:59 +00:00
|
|
|
case 'Y': msg += wxT( "${COMPANY}" ); break;
|
|
|
|
case 'T': msg += wxT( "${TITLE}" ); break;
|
|
|
|
case 'C':
|
|
|
|
format = aTextbase[++ii];
|
|
|
|
|
|
|
|
switch( format )
|
|
|
|
{
|
2021-02-21 17:27:28 +00:00
|
|
|
case '0': msg += wxT( "${COMMENT1}" ); break;
|
|
|
|
case '1': msg += wxT( "${COMMENT2}" ); break;
|
|
|
|
case '2': msg += wxT( "${COMMENT3}" ); break;
|
|
|
|
case '3': msg += wxT( "${COMMENT4}" ); break;
|
|
|
|
case '4': msg += wxT( "${COMMENT5}" ); break;
|
|
|
|
case '5': msg += wxT( "${COMMENT6}" ); break;
|
|
|
|
case '6': msg += wxT( "${COMMENT7}" ); break;
|
|
|
|
case '7': msg += wxT( "${COMMENT8}" ); break;
|
|
|
|
case '8': msg += wxT( "${COMMENT9}" ); break;
|
2020-03-26 11:02:59 +00:00
|
|
|
}
|
2020-04-24 23:44:09 +00:00
|
|
|
break;
|
2020-03-26 11:02:59 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::Parse( DS_DATA_MODEL* aLayout )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* item;
|
2019-05-26 18:35:20 +00:00
|
|
|
LOCALE_IO toggle;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-06-10 22:39:03 +00:00
|
|
|
NeedLEFT();
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
parseHeader( token );
|
|
|
|
aLayout->SetFileFormatVersionAtLoad( m_requiredVersion );
|
|
|
|
|
|
|
|
for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_setup: // Defines default values for graphic items
|
2013-07-20 19:36:19 +00:00
|
|
|
parseSetup( aLayout );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_line:
|
2021-02-22 23:47:17 +00:00
|
|
|
item = new DS_DATA_ITEM( DS_DATA_ITEM::DS_SEGMENT );
|
2013-07-19 18:27:22 +00:00
|
|
|
parseGraphic( item );
|
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rect:
|
2021-02-22 23:47:17 +00:00
|
|
|
item = new DS_DATA_ITEM( DS_DATA_ITEM::DS_RECT );
|
2013-07-19 18:27:22 +00:00
|
|
|
parseGraphic( item );
|
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_polygon:
|
2021-02-22 23:47:17 +00:00
|
|
|
item = new DS_DATA_ITEM_POLYGONS();
|
|
|
|
parsePolygon( (DS_DATA_ITEM_POLYGONS*) item );
|
2013-07-19 18:27:22 +00:00
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
case T_bitmap:
|
2021-02-22 23:47:17 +00:00
|
|
|
item = new DS_DATA_ITEM_BITMAP( NULL );
|
|
|
|
parseBitmap( (DS_DATA_ITEM_BITMAP*) item );
|
2013-10-18 17:38:03 +00:00
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
case T_tbtext:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2021-02-22 23:47:17 +00:00
|
|
|
item = new DS_DATA_ITEM_TEXT( convertLegacyVariableRefs( FromUTF8() ) );
|
|
|
|
parseText( (DS_DATA_ITEM_TEXT*) item );
|
2013-07-19 18:27:22 +00:00
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parseHeader( T aHeaderType )
|
2021-06-10 22:39:03 +00:00
|
|
|
{
|
|
|
|
// The older files had no versioning and their first token after the initial left parenthesis
|
|
|
|
// was a `page_layout` or `drawing_sheet` token. The newer files have versions and have a
|
|
|
|
// `kicad_wks` token instead.
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
if( aHeaderType == T_kicad_wks || aHeaderType == T_drawing_sheet )
|
2021-06-10 22:39:03 +00:00
|
|
|
{
|
|
|
|
NeedLEFT();
|
|
|
|
|
|
|
|
T tok = NextTok();
|
|
|
|
|
|
|
|
if( tok == T_version )
|
|
|
|
{
|
|
|
|
m_requiredVersion = parseInt();
|
2021-08-27 11:52:13 +00:00
|
|
|
|
|
|
|
if( m_requiredVersion > SEXPR_WORKSHEET_FILE_VERSION )
|
|
|
|
throw FUTURE_FORMAT_ERROR( FromUTF8() );
|
|
|
|
|
2021-06-10 22:39:03 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Expecting( T_version );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore generator info.
|
|
|
|
NeedLEFT();
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedSYMBOL();
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We assign version 0 to files that were created before there was any versioning of
|
|
|
|
// worksheets. The below line is not strictly necessary, as `m_requiredVersion` is already
|
|
|
|
// initialized to 0 in the constructor.
|
|
|
|
m_requiredVersion = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parseSetup( DS_DATA_MODEL* aLayout )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_LEFT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_linewidth:
|
2019-05-25 13:56:52 +00:00
|
|
|
aLayout->m_DefaultLineWidth = parseDouble();
|
2013-07-19 18:27:22 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_textsize:
|
2019-05-25 13:56:52 +00:00
|
|
|
aLayout->m_DefaultTextSize.x = parseDouble();
|
|
|
|
aLayout->m_DefaultTextSize.y = parseDouble();
|
2013-07-19 18:27:22 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_textlinewidth:
|
2019-05-25 13:56:52 +00:00
|
|
|
aLayout->m_DefaultTextThickness = parseDouble();
|
2013-07-19 18:27:22 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2013-07-20 19:36:19 +00:00
|
|
|
case T_left_margin:
|
|
|
|
aLayout->SetLeftMargin( parseDouble() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_right_margin:
|
|
|
|
aLayout->SetRightMargin( parseDouble() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_top_margin:
|
|
|
|
aLayout->SetTopMargin( parseDouble() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_bottom_margin:
|
|
|
|
aLayout->SetBottomMargin( parseDouble() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-20 11:47:04 +00:00
|
|
|
|
|
|
|
// The file is well-formed. If it has no further items, then that's the way the
|
|
|
|
// user wants it.
|
|
|
|
aLayout->AllowVoidList( true );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 11:47:04 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parsePolygon( DS_DATA_ITEM_POLYGONS * aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_comment:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Info = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pos:
|
|
|
|
parseCoordinate( aItem->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_name:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Name = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_option:
|
|
|
|
readOption( aItem );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pts:
|
|
|
|
parsePolyOutline( aItem );
|
|
|
|
aItem->CloseContour();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rotate:
|
2022-01-16 21:15:20 +00:00
|
|
|
aItem->m_Orient = EDA_ANGLE( parseDouble(), DEGREES_T );
|
2013-07-19 18:27:22 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_repeat:
|
|
|
|
aItem->m_RepeatCount = parseInt( -1, 100 );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incrx:
|
|
|
|
aItem->m_IncrementVector.x = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incry:
|
|
|
|
aItem->m_IncrementVector.y = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_linewidth:
|
|
|
|
aItem->m_LineWidth = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aItem->SetBoundingBox();
|
|
|
|
}
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parsePolyOutline( DS_DATA_ITEM_POLYGONS * aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D corner;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_xy:
|
|
|
|
corner.x = parseDouble();
|
|
|
|
corner.y = parseDouble();
|
|
|
|
aItem->AppendCorner( corner );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:48:43 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parseBitmap( DS_DATA_ITEM_BITMAP * aItem )
|
2013-10-18 17:38:03 +00:00
|
|
|
{
|
|
|
|
BITMAP_BASE* image = new BITMAP_BASE;
|
|
|
|
aItem->m_ImageBitmap = image;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-10-18 17:38:03 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_name:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Name = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pos:
|
|
|
|
parseCoordinate( aItem->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_repeat:
|
|
|
|
aItem->m_RepeatCount = parseInt( -1, 100 );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incrx:
|
|
|
|
aItem->m_IncrementVector.x = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incry:
|
|
|
|
aItem->m_IncrementVector.y = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_linewidth:
|
|
|
|
aItem->m_LineWidth = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_scale:
|
2016-07-11 19:48:46 +00:00
|
|
|
aItem->m_ImageBitmap->SetScale( parseDouble() );
|
2013-10-18 17:38:03 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2022-01-17 17:02:44 +00:00
|
|
|
case T_comment:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Info = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
case T_pngdata:
|
|
|
|
readPngdata( aItem );
|
|
|
|
break;
|
|
|
|
|
2015-11-03 16:03:44 +00:00
|
|
|
case T_option:
|
|
|
|
readOption( aItem );
|
|
|
|
break;
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::readPngdata( DS_DATA_ITEM_BITMAP * aItem )
|
2013-10-18 17:38:03 +00:00
|
|
|
{
|
|
|
|
std::string tmp;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-10-18 17:38:03 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
case T_data:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
tmp += CurStr();
|
|
|
|
tmp += "\n";
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
2013-10-18 17:38:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += "EndData";
|
|
|
|
|
|
|
|
wxString msg;
|
2016-04-23 15:44:17 +00:00
|
|
|
STRING_LINE_READER str_reader( tmp, wxT("Png kicad_wks data") );
|
|
|
|
|
|
|
|
if( ! aItem->m_ImageBitmap->LoadData( str_reader, msg ) )
|
2013-10-18 17:38:03 +00:00
|
|
|
wxLogMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::readOption( DS_DATA_ITEM * aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
switch( token )
|
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
case T_page1only: aItem->SetPage1Option( FIRST_PAGE_ONLY ); break;
|
|
|
|
case T_notonpage1: aItem->SetPage1Option( SUBSEQUENT_PAGES ); break;
|
|
|
|
default: Unexpected( CurText() ); break;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parseGraphic( DS_DATA_ITEM * aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2016-03-22 09:46:18 +00:00
|
|
|
else
|
|
|
|
{
|
2018-04-08 10:28:59 +00:00
|
|
|
// If another token than T_LEFT is read here, this is an error
|
2016-03-22 09:46:18 +00:00
|
|
|
// however, due to a old bug in kicad, the token T_end can be found
|
|
|
|
// without T_LEFT in a very few .wks files (perhaps only one in a demo).
|
|
|
|
// So this ugly hack disables the error detection.
|
|
|
|
if( token != T_end )
|
|
|
|
Unexpected( CurText() );
|
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_comment:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2016-03-22 09:46:18 +00:00
|
|
|
aItem->m_Info = FromUTF8();
|
2013-07-19 18:27:22 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_option:
|
|
|
|
readOption( aItem );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_name:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Name = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_start:
|
|
|
|
parseCoordinate( aItem->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_end:
|
|
|
|
parseCoordinate( aItem->m_End );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_repeat:
|
|
|
|
aItem->m_RepeatCount = parseInt( -1, 100 );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incrx:
|
|
|
|
aItem->m_IncrementVector.x = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incry:
|
|
|
|
aItem->m_IncrementVector.y = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_linewidth:
|
|
|
|
aItem->m_LineWidth = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parseText( DS_DATA_ITEM_TEXT* aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-06-10 22:39:03 +00:00
|
|
|
if( m_requiredVersion < 20210606 )
|
|
|
|
aItem->m_TextBase = ConvertToNewOverbarNotation( aItem->m_TextBase );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_comment:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Info = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_option:
|
|
|
|
readOption( aItem );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_name:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aItem->m_Name = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pos:
|
|
|
|
parseCoordinate( aItem->m_Pos );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_repeat:
|
|
|
|
aItem->m_RepeatCount = parseInt( -1, 100 );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incrx:
|
|
|
|
aItem->m_IncrementVector.x = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incry:
|
|
|
|
aItem->m_IncrementVector.y = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_incrlabel:
|
|
|
|
aItem->m_IncrementLabel = parseInt(INT_MIN, INT_MAX);
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_maxlen:
|
|
|
|
aItem->m_BoundingBoxSize.x = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_maxheight:
|
|
|
|
aItem->m_BoundingBoxSize.y = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_font:
|
2022-02-28 18:02:00 +00:00
|
|
|
{
|
|
|
|
wxString faceName;
|
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
aItem->m_TextColor = COLOR4D::UNSPECIFIED;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_LEFT:
|
|
|
|
break;
|
|
|
|
|
2022-02-28 18:02:00 +00:00
|
|
|
case T_face:
|
|
|
|
NeedSYMBOL();
|
|
|
|
faceName = FromUTF8();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
case T_bold:
|
2019-05-20 10:23:32 +00:00
|
|
|
aItem->m_Bold = true;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_italic:
|
2019-05-20 10:23:32 +00:00
|
|
|
aItem->m_Italic = true;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_size:
|
|
|
|
aItem->m_TextSize.x = parseDouble();
|
|
|
|
aItem->m_TextSize.y = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
case T_color:
|
|
|
|
aItem->m_TextColor.r = parseInt( 0, 255 ) / 255.0;
|
|
|
|
aItem->m_TextColor.g = parseInt( 0, 255 ) / 255.0;
|
|
|
|
aItem->m_TextColor.b = parseInt( 0, 255 ) / 255.0;
|
|
|
|
aItem->m_TextColor.a = Clamp( parseDouble(), 0.0, 1.0 );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
case T_linewidth:
|
|
|
|
aItem->m_LineWidth = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-02-28 18:02:00 +00:00
|
|
|
|
|
|
|
if( !faceName.IsEmpty() )
|
|
|
|
aItem->m_Font = KIFONT::FONT::GetFont( faceName, aItem->m_Bold, aItem->m_Italic );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
2022-02-28 18:02:00 +00:00
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
case T_justify:
|
2019-05-20 10:23:32 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_center:
|
2021-12-28 22:13:54 +00:00
|
|
|
aItem->m_Hjustify = GR_TEXT_H_ALIGN_CENTER;
|
|
|
|
aItem->m_Vjustify = GR_TEXT_V_ALIGN_CENTER;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_left:
|
2021-12-28 22:13:54 +00:00
|
|
|
aItem->m_Hjustify = GR_TEXT_H_ALIGN_LEFT;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_right:
|
2021-12-28 22:13:54 +00:00
|
|
|
aItem->m_Hjustify = GR_TEXT_H_ALIGN_RIGHT;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_top:
|
2021-12-28 22:13:54 +00:00
|
|
|
aItem->m_Vjustify = GR_TEXT_V_ALIGN_TOP;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_bottom:
|
2021-12-28 22:13:54 +00:00
|
|
|
aItem->m_Vjustify = GR_TEXT_V_ALIGN_BOTTOM;
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rotate:
|
|
|
|
aItem->m_Orient = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse an expression like " 25 1 ltcorner)"
|
2021-08-27 11:52:13 +00:00
|
|
|
void DRAWING_SHEET_PARSER::parseCoordinate( POINT_COORD& aCoord)
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
aCoord.m_Pos.x = parseDouble();
|
|
|
|
aCoord.m_Pos.y = parseDouble();
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
switch( token )
|
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
case T_ltcorner: aCoord.m_Anchor = LT_CORNER; break;
|
|
|
|
case T_lbcorner: aCoord.m_Anchor = LB_CORNER; break;
|
|
|
|
case T_rbcorner: aCoord.m_Anchor = RB_CORNER; break;
|
|
|
|
case T_rtcorner: aCoord.m_Anchor = RT_CORNER; break;
|
2022-03-31 18:43:08 +00:00
|
|
|
default: Unexpected( CurText() ); break;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
int DRAWING_SHEET_PARSER::parseInt()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_NUMBER )
|
|
|
|
Expecting( T_NUMBER );
|
|
|
|
|
2021-06-10 22:39:03 +00:00
|
|
|
return atoi( CurText() );
|
|
|
|
}
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
int DRAWING_SHEET_PARSER::parseInt( int aMin, int aMax )
|
2021-06-10 22:39:03 +00:00
|
|
|
{
|
|
|
|
int val = parseInt();
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
if( val < aMin )
|
|
|
|
val = aMin;
|
|
|
|
else if( val > aMax )
|
|
|
|
val = aMax;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
double DRAWING_SHEET_PARSER::parseDouble()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_NUMBER )
|
|
|
|
Expecting( T_NUMBER );
|
|
|
|
|
|
|
|
double val = strtod( CurText(), NULL );
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// defaultDrawingSheet is the default drawing sheet using the S expr.
|
2021-02-22 23:47:17 +00:00
|
|
|
extern const char defaultDrawingSheet[];
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL::SetDefaultLayout()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
SetPageLayout( defaultDrawingSheet, false, wxT( "default page" ) );
|
2018-02-13 00:54:33 +00:00
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
// Returns defaultDrawingSheet as a string;
|
|
|
|
wxString DS_DATA_MODEL::DefaultLayout()
|
2018-02-13 00:54:33 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
return wxString( defaultDrawingSheet );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// emptyDrawingSheet is a "empty" drawing sheet using the S expr.
|
2018-02-13 00:54:33 +00:00
|
|
|
// there is a 0 length line to fool something somewhere.
|
2021-02-22 23:47:17 +00:00
|
|
|
extern const char emptyDrawingSheet[];
|
2018-02-13 00:54:33 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL::SetEmptyLayout()
|
2018-02-13 00:54:33 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
SetPageLayout( emptyDrawingSheet, false, wxT( "empty page" ) );
|
2018-02-13 00:54:33 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 13:48:43 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
wxString DS_DATA_MODEL::EmptyLayout()
|
2018-02-13 00:54:33 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
return wxString( emptyDrawingSheet );
|
2018-02-13 00:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL::SetPageLayout( const char* aPageLayout, bool Append, const wxString& aSource )
|
2013-07-26 12:50:29 +00:00
|
|
|
{
|
|
|
|
if( ! Append )
|
|
|
|
ClearList();
|
|
|
|
|
2021-10-31 19:57:52 +00:00
|
|
|
DRAWING_SHEET_PARSER parser( aPageLayout, wxT( "Sexpr_string" ) );
|
2013-07-26 12:50:29 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
parser.Parse( this );
|
2013-07-26 12:50:29 +00:00
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-07-26 12:50:29 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
wxLogMessage( ioe.What() );
|
2013-07-26 12:50:29 +00:00
|
|
|
}
|
2021-10-31 19:57:52 +00:00
|
|
|
catch( const std::bad_alloc& )
|
|
|
|
{
|
|
|
|
wxLogMessage( "Memory exhaustion reading drawing sheet" );
|
|
|
|
}
|
2013-07-26 12:50:29 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-05-01 17:17:39 +00:00
|
|
|
bool DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
wxString fullFileName = aFullFileName;
|
|
|
|
|
|
|
|
if( !Append )
|
|
|
|
{
|
|
|
|
if( fullFileName.IsEmpty() )
|
|
|
|
wxGetEnv( wxT( "KICAD_WKSFILE" ), &fullFileName );
|
|
|
|
|
2021-05-01 19:55:08 +00:00
|
|
|
if( fullFileName.IsEmpty() )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-05-01 19:55:08 +00:00
|
|
|
SetDefaultLayout();
|
|
|
|
return true; // we assume its fine / default init
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !wxFileExists( fullFileName ) )
|
|
|
|
{
|
2021-07-13 18:58:25 +00:00
|
|
|
wxLogMessage( _( "Drawing sheet '%s' not found." ), fullFileName );
|
2013-07-19 18:27:22 +00:00
|
|
|
SetDefaultLayout();
|
2021-05-01 17:17:39 +00:00
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 18:11:51 +00:00
|
|
|
wxFFile wksFile( fullFileName, "rb" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
if( ! wksFile.IsOpened() )
|
|
|
|
{
|
2021-07-13 18:58:25 +00:00
|
|
|
wxLogMessage( _( "Drawing sheet '%s' could not be opened." ), fullFileName );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( !Append )
|
|
|
|
SetDefaultLayout();
|
2021-07-13 18:58:25 +00:00
|
|
|
|
2021-05-01 17:17:39 +00:00
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 20:48:58 +00:00
|
|
|
size_t filelen = wksFile.Length();
|
2021-05-01 17:17:39 +00:00
|
|
|
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(filelen+10);
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-05-01 17:17:39 +00:00
|
|
|
if( wksFile.Read( buffer.get(), filelen ) != filelen )
|
|
|
|
{
|
2021-07-13 18:58:25 +00:00
|
|
|
wxLogMessage( _( "Drawing sheet '%s' was not fully read." ), fullFileName.GetData() );
|
2021-05-01 17:17:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer[filelen]=0;
|
2014-12-31 12:31:19 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( ! Append )
|
|
|
|
ClearList();
|
2014-12-31 12:31:19 +00:00
|
|
|
|
2021-10-31 19:57:52 +00:00
|
|
|
DRAWING_SHEET_PARSER parser( buffer.get(), fullFileName );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-10-31 19:57:52 +00:00
|
|
|
parser.Parse( this );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
wxLogMessage( ioe.What() );
|
2021-05-01 17:17:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch( const std::bad_alloc& )
|
|
|
|
{
|
|
|
|
wxLogMessage( "Memory exhaustion reading drawing sheet" );
|
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:17:39 +00:00
|
|
|
return true;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|