2013-07-19 18:27:22 +00:00
|
|
|
/**
|
2013-09-17 00:52:08 +00:00
|
|
|
* @file common/page_layout/page_layout_reader.cpp
|
2013-07-19 18:27:22 +00:00
|
|
|
* @brief read an S expression of description of graphic items and texts
|
|
|
|
* to build a title block and page layout
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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>.
|
2018-01-29 08:39:13 +00:00
|
|
|
* Copyright (C) 1992-2018 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <base_struct.h>
|
2019-05-25 11:05:39 +00:00
|
|
|
#include <ws_painter.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <ws_draw_item.h>
|
2019-05-25 11:05:39 +00:00
|
|
|
#include <ws_data_model.h>
|
2019-07-03 09:08:55 +00:00
|
|
|
#include <page_layout/page_layout_reader_lexer.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2018-02-13 13:48:43 +00:00
|
|
|
#include <wx/file.h>
|
|
|
|
#include <wx/mstream.h>
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
using namespace TB_READER_T;
|
|
|
|
|
|
|
|
/**
|
2020-01-10 14:31:00 +00:00
|
|
|
* PAGE_LAYOUT_READER_PARSER
|
2013-07-19 18:27:22 +00:00
|
|
|
* holds data and functions pertinent to parsing a S-expression file
|
2019-05-25 11:05:39 +00:00
|
|
|
* for a WS_DATA_MODEL.
|
2013-07-19 18:27:22 +00:00
|
|
|
*/
|
|
|
|
class PAGE_LAYOUT_READER_PARSER : public PAGE_LAYOUT_READER_LEXER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PAGE_LAYOUT_READER_PARSER( const char* aLine, const wxString& aSource );
|
2019-05-25 11:05:39 +00:00
|
|
|
void Parse( WS_DATA_MODEL* aLayout );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function parseInt
|
|
|
|
* parses an integer and constrains it between two values.
|
|
|
|
* @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 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function parseDouble
|
|
|
|
* parses a double
|
|
|
|
* @return double - the parsed double.
|
|
|
|
*/
|
|
|
|
double parseDouble();
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void parseSetup( WS_DATA_MODEL* aLayout );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a graphic item starting by "(line" or "(rect" and read parameters.
|
|
|
|
*/
|
2019-05-25 11:05:39 +00:00
|
|
|
void parseGraphic( WS_DATA_ITEM * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a text item starting by "(tbtext" and read parameters.
|
|
|
|
*/
|
2019-05-25 11:05:39 +00:00
|
|
|
void parseText( WS_DATA_ITEM_TEXT * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a polygon item starting by "( polygon" and read parameters.
|
|
|
|
* the list of corners included in this description is read by parsePolyOutline
|
|
|
|
*/
|
2019-05-25 11:05:39 +00:00
|
|
|
void parsePolygon( WS_DATA_ITEM_POLYGONS * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a list of corners starting by "( pts" and read coordinates.
|
|
|
|
*/
|
2019-05-25 11:05:39 +00:00
|
|
|
void parsePolyOutline( WS_DATA_ITEM_POLYGONS * aItem );
|
2016-03-22 09:46:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a bitmap item starting by "( bitmap" and read parameters.
|
|
|
|
*/
|
2019-05-25 11:05:39 +00:00
|
|
|
void parseBitmap( WS_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);
|
2019-05-25 11:05:39 +00:00
|
|
|
void readOption( WS_DATA_ITEM * aItem );
|
|
|
|
void readPngdata( WS_DATA_ITEM_BITMAP * aItem );
|
2013-07-19 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// PCB_PLOT_PARAMS_PARSER
|
|
|
|
|
|
|
|
PAGE_LAYOUT_READER_PARSER::PAGE_LAYOUT_READER_PARSER( const char* aLine, const wxString& aSource ) :
|
|
|
|
PAGE_LAYOUT_READER_LEXER( aLine, aSource )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::Parse( WS_DATA_MODEL* aLayout )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2019-05-25 11:05:39 +00:00
|
|
|
WS_DATA_ITEM* item;
|
2019-05-26 18:35:20 +00:00
|
|
|
LOCALE_IO toggle;
|
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();
|
|
|
|
|
|
|
|
if( token == T_page_layout )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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:
|
2019-05-25 11:05:39 +00:00
|
|
|
item = new WS_DATA_ITEM( WS_DATA_ITEM::WS_SEGMENT );
|
2013-07-19 18:27:22 +00:00
|
|
|
parseGraphic( item );
|
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_rect:
|
2019-05-25 11:05:39 +00:00
|
|
|
item = new WS_DATA_ITEM( WS_DATA_ITEM::WS_RECT );
|
2013-07-19 18:27:22 +00:00
|
|
|
parseGraphic( item );
|
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_polygon:
|
2019-05-25 11:05:39 +00:00
|
|
|
item = new WS_DATA_ITEM_POLYGONS();
|
|
|
|
parsePolygon( (WS_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:
|
2019-05-25 11:05:39 +00:00
|
|
|
item = new WS_DATA_ITEM_BITMAP( NULL );
|
|
|
|
parseBitmap( (WS_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();
|
2019-05-25 11:05:39 +00:00
|
|
|
item = new WS_DATA_ITEM_TEXT( FromUTF8() );
|
|
|
|
parseText( (WS_DATA_ITEM_TEXT*) item );
|
2013-07-19 18:27:22 +00:00
|
|
|
aLayout->Append( item );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::parseSetup( WS_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
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::parsePolygon( WS_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:
|
|
|
|
aItem->m_Orient = parseDouble();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::parsePolyOutline( WS_DATA_ITEM_POLYGONS * aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
DPOINT corner;
|
|
|
|
|
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
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::parseBitmap( WS_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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::readPngdata( WS_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::readOption( WS_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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::parseGraphic( WS_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void PAGE_LAYOUT_READER_PARSER::parseText( WS_DATA_ITEM_TEXT* 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_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:
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case T_linewidth:
|
|
|
|
aItem->m_LineWidth = parseDouble();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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:
|
|
|
|
aItem->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER;
|
|
|
|
aItem->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_left:
|
|
|
|
aItem->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_right:
|
|
|
|
aItem->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_top:
|
|
|
|
aItem->m_Vjustify = GR_TEXT_VJUSTIFY_TOP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_bottom:
|
|
|
|
aItem->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
|
|
|
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)"
|
|
|
|
void PAGE_LAYOUT_READER_PARSER::parseCoordinate( POINT_COORD& aCoord)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
default: Unexpected( CurText() ); break;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PAGE_LAYOUT_READER_PARSER::parseInt( int aMin, int aMax )
|
|
|
|
{
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_NUMBER )
|
|
|
|
Expecting( T_NUMBER );
|
|
|
|
|
|
|
|
int val = atoi( CurText() );
|
|
|
|
|
|
|
|
if( val < aMin )
|
|
|
|
val = aMin;
|
|
|
|
else if( val > aMax )
|
|
|
|
val = aMax;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double PAGE_LAYOUT_READER_PARSER::parseDouble()
|
|
|
|
{
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_NUMBER )
|
|
|
|
Expecting( T_NUMBER );
|
|
|
|
|
|
|
|
double val = strtod( CurText(), NULL );
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaultPageLayout is the default page layout description
|
|
|
|
// using the S expr.
|
|
|
|
// see page_layout_default_shape.cpp
|
|
|
|
extern const char defaultPageLayout[];
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void WS_DATA_MODEL::SetDefaultLayout()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2018-02-13 00:54:33 +00:00
|
|
|
SetPageLayout( defaultPageLayout, false, wxT( "default page" ) );
|
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2018-02-13 00:54:33 +00:00
|
|
|
// Returns defaultPageLayout as a string;
|
2019-05-25 11:05:39 +00:00
|
|
|
wxString WS_DATA_MODEL::DefaultLayout()
|
2018-02-13 00:54:33 +00:00
|
|
|
{
|
2018-02-13 13:48:43 +00:00
|
|
|
return wxString( defaultPageLayout );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 00:54:33 +00:00
|
|
|
// emptyPageLayout is a "empty" page layout description
|
|
|
|
// there is a 0 length line to fool something somewhere.
|
|
|
|
// using the S expr.
|
|
|
|
// see page_layout_empty_description.cpp
|
|
|
|
extern const char emptyPageLayout[];
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void WS_DATA_MODEL::SetEmptyLayout()
|
2018-02-13 00:54:33 +00:00
|
|
|
{
|
|
|
|
SetPageLayout( emptyPageLayout, false, wxT( "empty page" ) );
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:48:43 +00:00
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
wxString WS_DATA_MODEL::EmptyLayout()
|
2018-02-13 00:54:33 +00:00
|
|
|
{
|
2018-02-13 13:48:43 +00:00
|
|
|
return wxString( emptyPageLayout );
|
2018-02-13 00:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void WS_DATA_MODEL::SetPageLayout( const char* aPageLayout, bool Append, const wxString& aSource )
|
2013-07-26 12:50:29 +00:00
|
|
|
{
|
|
|
|
if( ! Append )
|
|
|
|
ClearList();
|
|
|
|
|
|
|
|
PAGE_LAYOUT_READER_PARSER lp_parser( aPageLayout, wxT( "Sexpr_string" ) );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
lp_parser.Parse( this );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2019-05-25 11:05:39 +00:00
|
|
|
void WS_DATA_MODEL::SetPageLayout( 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 );
|
|
|
|
|
|
|
|
if( fullFileName.IsEmpty() || !wxFileExists( fullFileName ) )
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
if( !fullFileName.IsEmpty() )
|
2019-05-26 15:36:40 +00:00
|
|
|
wxLogMessage( wxT( "Page layout file <%s> not found" ), fullFileName.GetData() );
|
2013-07-19 18:27:22 +00:00
|
|
|
#endif
|
|
|
|
SetDefaultLayout();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFile wksFile( fullFileName );
|
|
|
|
|
|
|
|
if( ! wksFile.IsOpened() )
|
|
|
|
{
|
|
|
|
if( !Append )
|
|
|
|
SetDefaultLayout();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int filelen = wksFile.Length();
|
|
|
|
char * buffer = new char[filelen+10];
|
|
|
|
|
|
|
|
if( wksFile.Read( buffer, filelen ) != filelen )
|
2019-05-24 13:37:55 +00:00
|
|
|
wxLogMessage( _("The file \"%s\" was not fully read"), fullFileName.GetData() );
|
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
|
|
|
|
|
|
|
PAGE_LAYOUT_READER_PARSER pl_parser( buffer, fullFileName );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-12-31 12:31:19 +00:00
|
|
|
pl_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() );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
}
|