27#include <fmt/format.h> 
   38#include <drawing_sheet/drawing_sheet_lexer.h> 
   42using namespace DRAWINGSHEET_T;
 
  121                                            const wxString& aSource ) :
 
  122        DRAWING_SHEET_LEXER( aLine, aSource ),
 
 
  149    for( 
unsigned ii = 0; ii < aTextbase.Len(); ii++ )
 
  151        if( aTextbase[ii] != 
'%' )
 
  153            msg << aTextbase[ii];
 
  157        if( ++ii >= aTextbase.Len() )
 
  160        wxChar format = aTextbase[ii];
 
  164            case '%': msg += 
'%';                       
break;
 
  165            case 'D': msg += wxT( 
"${ISSUE_DATE}" );    
break;
 
  166            case 'R': msg += wxT( 
"${REVISION}" );      
break;
 
  167            case 'K': msg += wxT( 
"${KICAD_VERSION}" ); 
break;
 
  168            case 'Z': msg += wxT( 
"${PAPER}" );         
break;
 
  169            case 'S': msg += wxT( 
"${#}" );             
break;
 
  170            case 'N': msg += wxT( 
"${##}" );            
break;
 
  171            case 'F': msg += wxT( 
"${FILENAME}" );      
break;
 
  172            case 'L': msg += wxT( 
"${LAYER}" );         
break;
 
  173            case 'P': msg += wxT( 
"${SHEETPATH}" );     
break;
 
  174            case 'Y': msg += wxT( 
"${COMPANY}" );       
break;
 
  175            case 'T': msg += wxT( 
"${TITLE}" );         
break;
 
  177                format = aTextbase[++ii];
 
  181                case '0': msg += wxT( 
"${COMMENT1}" );  
break;
 
  182                case '1': msg += wxT( 
"${COMMENT2}" );  
break;
 
  183                case '2': msg += wxT( 
"${COMMENT3}" );  
break;
 
  184                case '3': msg += wxT( 
"${COMMENT4}" );  
break;
 
  185                case '4': msg += wxT( 
"${COMMENT5}" );  
break;
 
  186                case '5': msg += wxT( 
"${COMMENT6}" );  
break;
 
  187                case '6': msg += wxT( 
"${COMMENT7}" );  
break;
 
  188                case '7': msg += wxT( 
"${COMMENT8}" );  
break;
 
  189                case '8': msg += wxT( 
"${COMMENT9}" );  
break;
 
 
  223    for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  225        if( token == T_LEFT )
 
  236        case T_generator_version:
 
  285            NeedSYMBOLorNUMBER();
 
  292            Unexpected( CurText() );
 
 
  305    if( aHeaderType == T_kicad_wks || aHeaderType == T_drawing_sheet )
 
  311        if( tok == T_version )
 
  319            Expecting( T_version );
 
 
  334    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  352        case T_textlinewidth:
 
  372        case T_bottom_margin:
 
  378            Unexpected( CurText() );
 
 
  391    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  393        if( token == T_LEFT )
 
  399            NeedSYMBOLorNUMBER();
 
  400            aItem->
m_Info =  FromUTF8();
 
  409            NeedSYMBOLorNUMBER();
 
  410            aItem->
m_Name =  FromUTF8();
 
  449            Unexpected( CurText() );
 
 
  462    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  464        if( token == T_LEFT )
 
  477            Unexpected( CurText() );
 
 
  489    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  491        if( token == T_LEFT )
 
  497            NeedSYMBOLorNUMBER();
 
  498            aItem->
m_Name =  FromUTF8();
 
  532            NeedSYMBOLorNUMBER();
 
  533            aItem->
m_Info = FromUTF8();
 
  545            data.reserve( 1 << 19 );
 
  547            while( token != T_RIGHT )
 
  549                if( !IsSymbol( token ) )
 
  550                    Expecting( 
"base64 image data" );
 
  556            wxMemoryBuffer buffer = wxBase64Decode( data );
 
  573            Unexpected( CurText() );
 
 
  584    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  586        if( token == T_LEFT )
 
  592            NeedSYMBOLorNUMBER();
 
  599            Unexpected( CurText() );
 
 
  615    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  621        default:           Unexpected( CurText() );                   
break;
 
 
  629    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  631        if( token == T_LEFT )
 
  642                Unexpected( CurText() );
 
  648            NeedSYMBOLorNUMBER();
 
  649            aItem->
m_Info = FromUTF8();
 
  658            NeedSYMBOLorNUMBER();
 
  659            aItem->
m_Name = FromUTF8();
 
  692            Unexpected( CurText() );
 
 
  704    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  706        if( token == T_LEFT )
 
  712            NeedSYMBOLorNUMBER();
 
  713            aItem->
m_Info =  FromUTF8();
 
  722            NeedSYMBOLorNUMBER();
 
  723            aItem->
m_Name =  FromUTF8();
 
  767            for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  776                    faceName = FromUTF8();
 
  808                    Unexpected( CurText() );
 
  813            if( !faceName.IsEmpty() )
 
  820            for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  846                    Unexpected( CurText() );
 
  858            Unexpected( CurText() );
 
 
  870    for( 
T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
 
  878        default:         Unexpected( CurText() );     
break;
 
 
  888    if( token != T_NUMBER )
 
  889        Expecting( T_NUMBER );
 
  891    return atoi( CurText() );
 
 
  901    else if( val > aMax )
 
 
  912    if( token != T_NUMBER )
 
  913        Expecting( T_NUMBER );
 
 
  962        parser.
Parse( 
this );
 
 
  975        if( aFullFileName.IsEmpty() )
 
  981        if( !wxFileExists( aFullFileName ) )
 
  984                *aMsg = 
_( 
"File not found." );
 
  991    wxFFile wksFile( aFullFileName, wxS( 
"rb" ) );
 
  993    if( ! wksFile.IsOpened() )
 
  996            *aMsg = 
_( 
"File could not be opened." );
 
 1004    size_t filelen = wksFile.Length();
 
 1005    std::unique_ptr<char[]> buffer = std::make_unique<char[]>(filelen+10);
 
 1007    if( wksFile.Read( buffer.get(), filelen ) != filelen )
 
 1010            *aMsg = 
_( 
"Drawing sheet was not fully read." );
 
 1025            parser.
Parse( 
this );
 
 1034        catch( 
const std::bad_alloc& )
 
 1037                *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 #SaveData.
 
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)
 
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.
 
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.
 
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)
 
#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
 
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
 
VECTOR2< double > VECTOR2D