35#include <drawing_sheet/drawing_sheet_lexer.h>
39using namespace DRAWINGSHEET_T;
118 const wxString& aSource ) :
119 DRAWING_SHEET_LEXER( aLine, aSource ),
120 m_requiredVersion( 0 )
146 for(
unsigned ii = 0; ii < aTextbase.Len(); ii++ )
148 if( aTextbase[ii] !=
'%' )
150 msg << aTextbase[ii];
154 if( ++ii >= aTextbase.Len() )
157 wxChar format = aTextbase[ii];
161 case '%': msg +=
'%';
break;
162 case 'D': msg += wxT(
"${ISSUE_DATE}" );
break;
163 case 'R': msg += wxT(
"${REVISION}" );
break;
164 case 'K': msg += wxT(
"${KICAD_VERSION}" );
break;
165 case 'Z': msg += wxT(
"${PAPER}" );
break;
166 case 'S': msg += wxT(
"${#}" );
break;
167 case 'N': msg += wxT(
"${##}" );
break;
168 case 'F': msg += wxT(
"${FILENAME}" );
break;
169 case 'L': msg += wxT(
"${LAYER}" );
break;
170 case 'P': msg += wxT(
"${SHEETPATH}" );
break;
171 case 'Y': msg += wxT(
"${COMPANY}" );
break;
172 case 'T': msg += wxT(
"${TITLE}" );
break;
174 format = aTextbase[++ii];
178 case '0': msg += wxT(
"${COMMENT1}" );
break;
179 case '1': msg += wxT(
"${COMMENT2}" );
break;
180 case '2': msg += wxT(
"${COMMENT3}" );
break;
181 case '3': msg += wxT(
"${COMMENT4}" );
break;
182 case '4': msg += wxT(
"${COMMENT5}" );
break;
183 case '5': msg += wxT(
"${COMMENT6}" );
break;
184 case '6': msg += wxT(
"${COMMENT7}" );
break;
185 case '7': msg += wxT(
"${COMMENT8}" );
break;
186 case '8': msg += wxT(
"${COMMENT9}" );
break;
210 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
212 if( token == T_LEFT )
257 NeedSYMBOLorNUMBER();
264 Unexpected( CurText() );
276 if( aHeaderType == T_kicad_wks || aHeaderType == T_drawing_sheet )
282 if( tok == T_version )
293 Expecting( T_version );
313 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
331 case T_textlinewidth:
351 case T_bottom_margin:
357 Unexpected( CurText() );
370 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
372 if( token == T_LEFT )
378 NeedSYMBOLorNUMBER();
379 aItem->
m_Info = FromUTF8();
388 NeedSYMBOLorNUMBER();
389 aItem->
m_Name = FromUTF8();
428 Unexpected( CurText() );
440 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
442 if( token == T_LEFT )
455 Unexpected( CurText() );
467 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
469 if( token == T_LEFT )
475 NeedSYMBOLorNUMBER();
476 aItem->
m_Name = FromUTF8();
510 NeedSYMBOLorNUMBER();
511 aItem->
m_Info = FromUTF8();
524 Unexpected( CurText() );
534 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
536 if( token == T_LEFT )
542 NeedSYMBOLorNUMBER();
549 Unexpected( CurText() );
566 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
572 default: Unexpected( CurText() );
break;
580 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
582 if( token == T_LEFT )
591 Unexpected( CurText() );
597 NeedSYMBOLorNUMBER();
598 aItem->
m_Info = FromUTF8();
607 NeedSYMBOLorNUMBER();
608 aItem->
m_Name = FromUTF8();
641 Unexpected( CurText() );
653 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
655 if( token == T_LEFT )
661 NeedSYMBOLorNUMBER();
662 aItem->
m_Info = FromUTF8();
671 NeedSYMBOLorNUMBER();
672 aItem->
m_Name = FromUTF8();
716 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
725 faceName = FromUTF8();
757 Unexpected( CurText() );
762 if( !faceName.IsEmpty() )
769 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
795 Unexpected( CurText() );
807 Unexpected( CurText() );
819 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
827 default: Unexpected( CurText() );
break;
836 if( token != T_NUMBER )
837 Expecting( T_NUMBER );
839 return atoi( CurText() );
848 else if( val > aMax )
859 if( token != T_NUMBER )
860 Expecting( T_NUMBER );
905 parser.
Parse(
this );
909 wxLogMessage( ioe.
What() );
911 catch(
const std::bad_alloc& )
913 wxLogMessage( wxS(
"Memory exhaustion reading drawing sheet" ) );
920 wxString fullFileName = aFullFileName;
924 if( fullFileName.IsEmpty() )
930 if( !wxFileExists( fullFileName ) )
932 wxLogMessage(
_(
"Drawing sheet '%s' not found." ), fullFileName );
938 wxFFile wksFile( fullFileName, wxS(
"rb" ) );
940 if( ! wksFile.IsOpened() )
942 wxLogMessage(
_(
"Drawing sheet '%s' could not be opened." ), fullFileName );
950 size_t filelen = wksFile.Length();
951 std::unique_ptr<char[]> buffer = std::make_unique<char[]>(filelen+10);
953 if( wksFile.Read( buffer.get(), filelen ) != filelen )
955 wxLogMessage(
_(
"Drawing sheet '%s' was not fully read." ), fullFileName.GetData() );
969 parser.
Parse(
this );
973 wxLogMessage( ioe.
What() );
976 catch(
const std::bad_alloc& )
978 wxLogMessage( wxS(
"Memory exhaustion reading drawing sheet" ) );
This class handle bitmap images in KiCad.
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData.
void SetScale(double aScale)
DRAWING_SHEET_PARSER holds data and functions pertinent to parsing a S-expression file for a DS_DATA_...
void parseCoordinate(POINT_COORD &aCoord)
void parseHeader(T aHeaderType)
Parse the data specified at the very beginning of the file, like version and the application used to ...
DRAWING_SHEET_PARSER(const char *aLine, const wxString &aSource)
void parseBitmap(DS_DATA_ITEM_BITMAP *aItem)
Parse a bitmap item starting by "( bitmap" and read parameters.
void readPngdata(DS_DATA_ITEM_BITMAP *aItem)
void parsePolygon(DS_DATA_ITEM_POLYGONS *aItem)
Parse a polygon item starting by "( polygon" and read parameters.
void parseText(DS_DATA_ITEM_TEXT *aItem)
Parse a text item starting by "(tbtext" and read parameters.
void Parse(DS_DATA_MODEL *aLayout)
int parseInt()
Parse an integer.
void readOption(DS_DATA_ITEM *aItem)
double parseDouble()
Parse a double.
void parseSetup(DS_DATA_MODEL *aLayout)
void parseGraphic(DS_DATA_ITEM *aItem)
Parse a graphic item starting by "(line" or "(rect" and read parameters.
void parsePolyOutline(DS_DATA_ITEM_POLYGONS *aItem)
Parse a list of corners starting by "( pts" and read coordinates.
double parseDouble()
Parse the current token as an ASCII numeric string with possible leading whitespace into a double pre...
BITMAP_BASE * m_ImageBitmap
void SetBoundingBox()
Calculate the bounding box of the set polygons.
void CloseContour()
Close the current contour, by storing the index of the last corner of the current polygon in m_polyIn...
void AppendCorner(const VECTOR2D &aCorner)
Add a corner in corner list.
GR_TEXT_H_ALIGN_T m_Hjustify
KIGFX::COLOR4D m_TextColor
VECTOR2D m_BoundingBoxSize
GR_TEXT_V_ALIGN_T m_Vjustify
Drawing sheet structure type definitions.
void SetPage1Option(PAGE_OPTION aChoice)
VECTOR2D m_IncrementVector
Handle the graphic items list to draw/plot the frame and title block.
void SetBottomMargin(double aMargin)
VECTOR2D m_DefaultTextSize
void SetRightMargin(double aMargin)
double m_DefaultLineWidth
static wxString DefaultLayout()
Return a string containing the empty layout shape.
static wxString EmptyLayout()
Return a string containing the empty layout shape.
void SetLeftMargin(double aMargin)
double m_DefaultTextThickness
void Append(DS_DATA_ITEM *aItem)
void AllowVoidList(bool Allow)
In KiCad applications, a drawing sheet is needed So if the list is empty, a default drawing sheet is ...
void ClearList()
Erase the list of items.
void SetTopMargin(double aMargin)
void SetFileFormatVersionAtLoad(int aVersion)
void SetPageLayout(const char *aPageLayout, bool aAppend=false, const wxString &aSource=wxT("Sexpr_string"))
Populate the list from a S expr description stored in a string.
bool LoadDrawingSheet(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout or the default layout if no custom layout is available.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
const char emptyDrawingSheet[]
wxString convertLegacyVariableRefs(const wxString &aTextbase)
const char defaultDrawingSheet[]
#define SEXPR_WORKSHEET_FILE_VERSION
This file contains the file format version information for the s-expression drawing sheet file format...
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
constexpr T Clamp(const T &lower, const T &value, const T &upper)
Limit value within the range lower <= value <= upper.