23#include <fmt/format.h>
36#include <drawing_sheet/drawing_sheet_lexer.h>
40using namespace DRAWINGSHEET_T;
119 const wxString& aSource ) :
120 DRAWING_SHEET_LEXER( aLine, aSource ),
147 for(
unsigned ii = 0; ii < aTextbase.Len(); ii++ )
149 if( aTextbase[ii] !=
'%' )
151 msg << aTextbase[ii];
155 if( ++ii >= aTextbase.Len() )
158 wxChar format = aTextbase[ii];
162 case '%': msg +=
'%';
break;
163 case 'D': msg += wxT(
"${ISSUE_DATE}" );
break;
164 case 'R': msg += wxT(
"${REVISION}" );
break;
165 case 'K': msg += wxT(
"${KICAD_VERSION}" );
break;
166 case 'Z': msg += wxT(
"${PAPER}" );
break;
167 case 'S': msg += wxT(
"${#}" );
break;
168 case 'N': msg += wxT(
"${##}" );
break;
169 case 'F': msg += wxT(
"${FILENAME}" );
break;
170 case 'L': msg += wxT(
"${LAYER}" );
break;
171 case 'P': msg += wxT(
"${SHEETPATH}" );
break;
172 case 'Y': msg += wxT(
"${COMPANY}" );
break;
173 case 'T': msg += wxT(
"${TITLE}" );
break;
175 format = aTextbase[++ii];
179 case '0': msg += wxT(
"${COMMENT1}" );
break;
180 case '1': msg += wxT(
"${COMMENT2}" );
break;
181 case '2': msg += wxT(
"${COMMENT3}" );
break;
182 case '3': msg += wxT(
"${COMMENT4}" );
break;
183 case '4': msg += wxT(
"${COMMENT5}" );
break;
184 case '5': msg += wxT(
"${COMMENT6}" );
break;
185 case '6': msg += wxT(
"${COMMENT7}" );
break;
186 case '7': msg += wxT(
"${COMMENT8}" );
break;
187 case '8': msg += wxT(
"${COMMENT9}" );
break;
224 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
226 if( token == T_LEFT )
237 case T_generator_version:
286 NeedSYMBOLorNUMBER();
293 Unexpected( CurText() );
306 if( aHeaderType == T_kicad_wks || aHeaderType == T_drawing_sheet )
312 if( tok == T_version )
320 Expecting( T_version );
335 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
353 case T_textlinewidth:
373 case T_bottom_margin:
379 Unexpected( CurText() );
392 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
394 if( token == T_LEFT )
400 NeedSYMBOLorNUMBER();
401 aItem->
m_Info = FromUTF8();
410 NeedSYMBOLorNUMBER();
411 aItem->
m_Name = FromUTF8();
450 Unexpected( CurText() );
463 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
465 if( token == T_LEFT )
478 Unexpected( CurText() );
490 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
492 if( token == T_LEFT )
498 NeedSYMBOLorNUMBER();
499 aItem->
m_Name = FromUTF8();
533 NeedSYMBOLorNUMBER();
534 aItem->
m_Info = FromUTF8();
546 data.reserve( 1 << 19 );
548 while( token != T_RIGHT )
550 if( !IsSymbol( token ) )
551 Expecting(
"base64 image data" );
557 wxMemoryBuffer buffer = wxBase64Decode( data );
574 Unexpected( CurText() );
585 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
587 if( token == T_LEFT )
593 NeedSYMBOLorNUMBER();
600 Unexpected( CurText() );
616 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
622 default: Unexpected( CurText() );
break;
630 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
632 if( token == T_LEFT )
643 Unexpected( CurText() );
649 NeedSYMBOLorNUMBER();
650 aItem->
m_Info = FromUTF8();
659 NeedSYMBOLorNUMBER();
660 aItem->
m_Name = FromUTF8();
693 Unexpected( CurText() );
705 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
707 if( token == T_LEFT )
713 NeedSYMBOLorNUMBER();
714 aItem->
m_Info = FromUTF8();
723 NeedSYMBOLorNUMBER();
724 aItem->
m_Name = FromUTF8();
768 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
777 faceName = FromUTF8();
809 Unexpected( CurText() );
814 if( !faceName.IsEmpty() )
821 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
847 Unexpected( CurText() );
859 Unexpected( CurText() );
871 for(
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
879 default: Unexpected( CurText() );
break;
889 if( token != T_NUMBER )
890 Expecting( T_NUMBER );
892 return atoi( CurText() );
902 else if( val > aMax )
913 if( token != T_NUMBER )
914 Expecting( T_NUMBER );
956 static const wxString
name( wxS(
"empty.kicad_wks" ) );
963 std::vector<const EMBEDDED_FILES*> aEmbeddedFilesStack, wxString* aMsg )
988 parser.
Parse(
this );
1001 if( aFullFileName.IsEmpty() )
1007 if( !wxFileExists( aFullFileName ) )
1010 *aMsg =
_(
"File not found." );
1017 wxFFile wksFile( aFullFileName, wxS(
"rb" ) );
1019 if( ! wksFile.IsOpened() )
1022 *aMsg =
_(
"File could not be opened." );
1030 size_t filelen = wksFile.Length();
1031 std::unique_ptr<char[]> buffer = std::make_unique<char[]>(filelen+10);
1033 if( wksFile.Read( buffer.get(), filelen ) != filelen )
1036 *aMsg =
_(
"Drawing sheet was not fully read." );
1051 parser.
Parse(
this );
1060 catch(
const std::bad_alloc& )
1063 *aMsg =
_(
"Ran out of memory." );
This class handle bitmap images in KiCad.
bool LoadLegacyData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveImageData.
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
void SetScale(double aScale)
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Hold data and functions pertinent to parsing a S-expression file for a DS_DATA_MODEL.
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)
wxString m_generatorVersion
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.
bool LoadDrawingSheet(const wxString &aFullFileName, wxString *aMsg, bool aAppend=false)
Populate the list with a custom layout or the default layout if no custom layout is available.
void SetBottomMargin(double aMargin)
VECTOR2D m_DefaultTextSize
void SetRightMargin(double aMargin)
void SetGenerator(const wxString &aGenerator)
bool LoadFromName(const wxString &aSheetName, const wxString &aBasePath, PROJECT *aProject, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack, wxString *aMsg)
Populate the list from aSheetName, which is either EmptyLayoutName, an embedded file reference or a p...
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)
static const wxString & EmptyLayoutName()
Return the reserved drawing-sheet name that marks a design as deliberately having no sheet,...
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.
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
bool SetProject(const PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
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, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Container for project specific data.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
const char emptyDrawingSheet[]
const char defaultDrawingSheet[]
wxString convertLegacyVariableRefs(const wxString &aTextbase)
constexpr int DS_MAX_REPEAT_COUNT
Upper bound on DS_DATA_ITEM::m_RepeatCount.
#define SEXPR_WORKSHEET_FILE_VERSION
This file contains the file format version information for the s-expression drawing sheet file format...
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
PGM_BASE & Pgm()
The global program "get" accessor.
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
VECTOR2< double > VECTOR2D