32 #include <drawing_sheet/drawing_sheet_reader_lexer.h> 36 #include <wx/mstream.h> 39 using namespace TB_READER_T;
107 const wxString& aSource ) :
108 DRAWING_SHEET_READER_LEXER( aLine, aSource )
134 for(
unsigned ii = 0; ii < aTextbase.Len(); ii++ )
136 if( aTextbase[ii] !=
'%' )
138 msg << aTextbase[ii];
142 if( ++ii >= aTextbase.Len() )
145 wxChar format = aTextbase[ii];
149 case '%': msg +=
'%';
break;
150 case 'D': msg += wxT(
"${ISSUE_DATE}" );
break;
151 case 'R': msg += wxT(
"${REVISION}" );
break;
152 case 'K': msg += wxT(
"${KICAD_VERSION}" );
break;
153 case 'Z': msg += wxT(
"${PAPER}" );
break;
154 case 'S': msg += wxT(
"${#}" );
break;
155 case 'N': msg += wxT(
"${##}" );
break;
156 case 'F': msg += wxT(
"${FILENAME}" );
break;
157 case 'L': msg += wxT(
"${LAYER}" );
break;
158 case 'P': msg += wxT(
"${SHEETNAME}" );
break;
159 case 'Y': msg += wxT(
"${COMPANY}" );
break;
160 case 'T': msg += wxT(
"${TITLE}" );
break;
162 format = aTextbase[++ii];
166 case '0': msg += wxT(
"${COMMENT1}" );
break;
167 case '1': msg += wxT(
"${COMMENT2}" );
break;
168 case '2': msg += wxT(
"${COMMENT3}" );
break;
169 case '3': msg += wxT(
"${COMMENT4}" );
break;
170 case '4': msg += wxT(
"${COMMENT5}" );
break;
171 case '5': msg += wxT(
"${COMMENT6}" );
break;
172 case '6': msg += wxT(
"${COMMENT7}" );
break;
173 case '7': msg += wxT(
"${COMMENT8}" );
break;
174 case '8': msg += wxT(
"${COMMENT9}" );
break;
192 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
194 if( token == T_LEFT )
197 if( token == T_page_layout || token == T_drawing_sheet )
231 NeedSYMBOLorNUMBER();
238 Unexpected( CurText() );
247 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
265 case T_textlinewidth:
285 case T_bottom_margin:
291 Unexpected( CurText() );
304 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
306 if( token == T_LEFT )
312 NeedSYMBOLorNUMBER();
313 aItem->
m_Info = FromUTF8();
322 NeedSYMBOLorNUMBER();
323 aItem->
m_Name = FromUTF8();
362 Unexpected( CurText() );
374 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
376 if( token == T_LEFT )
389 Unexpected( CurText() );
401 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
403 if( token == T_LEFT )
409 NeedSYMBOLorNUMBER();
410 aItem->
m_Name = FromUTF8();
452 Unexpected( CurText() );
462 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
464 if( token == T_LEFT )
470 NeedSYMBOLorNUMBER();
477 Unexpected( CurText() );
494 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
500 default: Unexpected( CurText() );
break;
508 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
510 if( token == T_LEFT )
519 Unexpected( CurText() );
525 NeedSYMBOLorNUMBER();
526 aItem->
m_Info = FromUTF8();
535 NeedSYMBOLorNUMBER();
536 aItem->
m_Name = FromUTF8();
569 Unexpected( CurText() );
578 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
580 if( token == T_LEFT )
586 NeedSYMBOLorNUMBER();
587 aItem->
m_Info = FromUTF8();
596 NeedSYMBOLorNUMBER();
597 aItem->
m_Name = FromUTF8();
636 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
663 Unexpected( CurText() );
670 for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
696 Unexpected( CurText() );
708 Unexpected( CurText() );
720 for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
728 default: Unexpected( CurText() );
break;
737 if( token != T_NUMBER )
738 Expecting( T_NUMBER );
740 int val = atoi( CurText() );
744 else if( val > aMax )
755 if( token != T_NUMBER )
756 Expecting( T_NUMBER );
758 double val = strtod( CurText(),
NULL );
802 lp_parser.
Parse(
this );
806 wxLogMessage( ioe.
What() );
813 wxString fullFileName = aFullFileName;
817 if( fullFileName.IsEmpty() )
818 wxGetEnv( wxT(
"KICAD_WKSFILE" ), &fullFileName );
820 if( fullFileName.IsEmpty() || !wxFileExists( fullFileName ) )
823 if( !fullFileName.IsEmpty() )
824 wxLogMessage( wxT(
"Drawing sheet file <%s> not found" ), fullFileName.GetData() );
831 wxFFile wksFile( fullFileName,
"rb" );
833 if( ! wksFile.IsOpened() )
840 size_t filelen = wksFile.Length();
841 char * buffer =
new char[filelen+10];
843 if( wksFile.Read( buffer, filelen ) != filelen )
844 wxLogMessage(
_(
"The file \"%s\" was not fully read"), fullFileName.GetData() );
856 pl_parser.
Parse(
this );
860 wxLogMessage( ioe.
What() );
void ClearList()
Erase the list of items.
Handle the graphic items list to draw/plot the frame and title block.
void 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.
EDA_TEXT_VJUSTIFY_T m_Vjustify
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
void parsePolygon(DS_DATA_ITEM_POLYGONS *aItem)
parse a polygon item starting by "( polygon" and read parameters.
static wxString DefaultLayout()
Return a string containing the empty layout shape.
void SetScale(double aScale)
void SetBottomMargin(double aMargin)
void SetBoundingBox()
Calculate the bounding box of the set polygons.
void readOption(DS_DATA_ITEM *aItem)
double m_DefaultLineWidth
DRAWING_SHEET_READER_PARSER holds data and functions pertinent to parsing a S-expression file for a D...
void SetLeftMargin(double aMargin)
static double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
void readPngdata(DS_DATA_ITEM_BITMAP *aItem)
void parseText(DS_DATA_ITEM_TEXT *aItem)
parse a text item starting by "(tbtext" and read parameters.
void parseBitmap(DS_DATA_ITEM_BITMAP *aItem)
parse a bitmap item starting by "( bitmap" and read parameters.
void SetRightMargin(double aMargin)
double m_DefaultTextThickness
This class handle bitmap images in KiCad.
EDA_TEXT_HJUSTIFY_T m_Hjustify
BITMAP_BASE * m_ImageBitmap
void AllowVoidList(bool Allow)
In KiCad applications, a page layout description is needed So if the list is empty,...
virtual const wxString What() const
A composite of Problem() and Where()
int parseInt(int aMin, int aMax)
Function parseInt parses an integer and constrains it between two values.
void CloseContour()
Closes the current contour, by storing the index of the last corner of the current polygon in m_polyI...
void SetTopMargin(double aMargin)
void parseGraphic(DS_DATA_ITEM *aItem)
parse a graphic item starting by "(line" or "(rect" and read parameters.
static wxString EmptyLayout()
Return a string containing the empty layout shape.
const char defaultDrawingSheet[]
void parseCoordinate(POINT_COORD &aCoord)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void Parse(DS_DATA_MODEL *aLayout)
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.
void SetPage1Option(PAGE_OPTION aChoice)
wxString convertLegacyVariableRefs(const wxString &aTextbase)
void parseSetup(DS_DATA_MODEL *aLayout)
Drawing sheet structure type definitions.
DRAWING_SHEET_READER_PARSER(const char *aLine, const wxString &aSource)
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData.
void parsePolyOutline(DS_DATA_ITEM_POLYGONS *aItem)
parse a list of corners starting by "( pts" and read coordinates.
double parseDouble()
Function parseDouble parses a double.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
const char emptyDrawingSheet[]
void AppendCorner(const DPOINT &aCorner)
Add a corner in corner list.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
void Append(DS_DATA_ITEM *aItem)