KiCad PCB EDA Suite
PCB_PARSER Class Reference

Class PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object. More...

#include <pcb_parser.h>

Inheritance diagram for PCB_PARSER:
PCB_LEXER DSNLEXER

Public Member Functions

 PCB_PARSER (LINE_READER *aReader=NULL)
 
LINE_READERSetLineReader (LINE_READER *aReader)
 Function SetLineReader sets aLineReader into the parser, and returns the previous one, if any. More...
 
void SetBoard (BOARD *aBoard)
 
BOARD_ITEMParse ()
 
bool IsTooRecent ()
 Return whether a version number, if any was parsed, was too recent. More...
 
wxString GetRequiredVersion ()
 Return a string representing the version of kicad required to open this file. More...
 
PCB_KEYS_T::T NextTok ()
 Function NextTok returns the next token found in the input file or T_EOF when reaching the end of file. More...
 
PCB_KEYS_T::T NeedSYMBOL ()
 Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(). More...
 
PCB_KEYS_T::T NeedSYMBOLorNUMBER ()
 Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool IsSymbol() or tok==T_NUMBER. More...
 
PCB_KEYS_T::T CurTok ()
 Function CurTok returns whatever NextTok() returned the last time it was called. More...
 
PCB_KEYS_T::T PrevTok ()
 Function PrevTok returns whatever NextTok() returned the 2nd to last time it was called. More...
 
bool SyncLineReaderWith (DSNLEXER &aLexer)
 Useable only for DSN lexers which share the same LINE_READER Synchronizes the pointers handling the data read by the LINE_READER Allows 2 DNSLEXER to share the same current line, when switching from a DNSLEXER to an other DNSLEXER. More...
 
void SetSpecctraMode (bool aMode)
 Function SetSpecctraMode changes the behavior of this lexer into or out of "specctra mode". More...
 
void PushReader (LINE_READER *aLineReader)
 Function PushReader manages a stack of LINE_READERs in order to handle nested file inclusion. More...
 
LINE_READERPopReader ()
 Function PopReader deletes the top most LINE_READER from an internal stack of LINE_READERs and in the case of FILE_LINE_READER this means the associated FILE is closed. More...
 
int NeedNUMBER (const char *aExpectation)
 Function NeedNUMBER calls NextTok() and then verifies that the token read is type DSN_NUMBER. More...
 
char SetStringDelimiter (char aStringDelimiter)
 Function SetStringDelimiter changes the string delimiter from the default " to some other character and returns the old value. More...
 
bool SetSpaceInQuotedTokens (bool val)
 Function SetSpaceInQuotedTokens changes the setting controlling whether a space in a quoted string is a terminator. More...
 
bool SetCommentsAreTokens (bool val)
 Function SetCommentsAreTokens changes the handling of comments. More...
 
wxArrayString * ReadCommentLines ()
 Function ReadCommentLines checks the next sequence of tokens and reads them into a wxArrayString if they are comments. More...
 
void Expecting (int aTok)
 Function Expecting throws an IO_ERROR exception with an input file specific error message. More...
 
void Expecting (const char *aTokenList)
 Function Expecting throws an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (int aTok)
 Function Unexpected throws an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (const char *aToken)
 Function Unexpected throws an IO_ERROR exception with an input file specific error message. More...
 
void Duplicate (int aTok)
 Function Duplicate throws an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one already seen in current context. More...
 
void NeedLEFT ()
 Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT. More...
 
void NeedRIGHT ()
 Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT. More...
 
const char * GetTokenText (int aTok)
 Function GetTokenText returns the C string representation of a DSN_T value. More...
 
wxString GetTokenString (int aTok)
 Function GetTokenString returns a quote wrapped wxString representation of a token value. More...
 
const char * CurText ()
 Function CurText returns a pointer to the current token's text. More...
 
const std::string & CurStr ()
 Function CurStr returns a reference to current token in std::string form. More...
 
wxString FromUTF8 ()
 Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream is UTF8 encoded. More...
 
int CurLineNumber ()
 Function CurLineNumber returns the current line number within my LINE_READER. More...
 
const char * CurLine ()
 Function CurLine returns the current line of text, from which the CurText() would return its token. More...
 
const wxString & CurSource ()
 Function CurFilename returns the current LINE_READER source. More...
 
int CurOffset ()
 Function CurOffset returns the byte offset within the current line, using a 1 based index. More...
 

Static Public Member Functions

static const char * TokenName (PCB_KEYS_T::T aTok)
 Function TokenName returns the name of the token in ASCII form. More...
 
static bool IsSymbol (int aTok)
 Function IsSymbol tests a token to see if it is a symbol. More...
 
static const char * Syntax (int aTok)
 

Protected Types

typedef std::vector< LINE_READER * > READER_STACK
 

Protected Member Functions

int readLine ()
 
int findToken (const std::string &aToken)
 Function findToken takes aToken string and looks up the string in the keywords table. More...
 
bool isStringTerminator (char cc)
 

Protected Attributes

bool iOwnReaders
 on readerStack, should I delete them? More...
 
const char * start
 
const char * next
 
const char * limit
 
char dummy [1]
 when there is no reader. More...
 
READER_STACK readerStack
 all the LINE_READERs by pointer. More...
 
LINE_READERreader
 no ownership. ownership is via readerStack, maybe, if iOwnReaders More...
 
bool specctraMode
 if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_in_quoted_tokens is functional else not. More...
 
char stringDelimiter
 
bool space_in_quoted_tokens
 blank spaces within quoted strings More...
 
bool commentsAreTokens
 true if should return comments as tokens More...
 
int prevTok
 curTok from previous NextTok() call. More...
 
int curOffset
 offset within current line of the current token More...
 
int curTok
 the current token obtained on last NextTok() More...
 
std::string curText
 the text of the current token More...
 
unsigned keywordCount
 count of keywords table More...
 
KEYWORD_MAP keyword_hash
 fast, specialized "C string" hashtable More...
 

Private Types

typedef boost::unordered_map< std::string, PCB_LAYER_IDLAYER_ID_MAP
 
typedef boost::unordered_map< std::string, LSETLSET_MAP
 

Private Member Functions

int getNetCode (int aNetCode)
 

Converts net code using the mapping table if available, otherwise returns unchanged net code if < 0 or if is is out of range

More...
 
void pushValueIntoMap (int aIndex, int aValue)
 function pushValueIntoMap Add aValue value in netcode mapping (m_netCodes) at index aIndex ensure there is room in m_netCodes for that, and add room if needed. More...
 
void init ()
 Function init clears and re-establishes m_layerMap with the default layer names. More...
 
void parseHeader ()
 
void parseGeneralSection ()
 
void parsePAGE_INFO ()
 
void parseTITLE_BLOCK ()
 
void parseLayers ()
 
void parseLayer (LAYER *aLayer)
 
void parseSetup ()
 
void parseNETINFO_ITEM ()
 
void parseNETCLASS ()
 
DRAWSEGMENTparseDRAWSEGMENT ()
 
TEXTE_PCBparseTEXTE_PCB ()
 
DIMENSIONparseDIMENSION ()
 
MODULEparseMODULE (wxArrayString *aInitialComments=0)
 Function parseMODULE. More...
 
MODULEparseMODULE_unchecked (wxArrayString *aInitialComments=0)
 Function parseMODULE_unchecked Parse a module, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. More...
 
TEXTE_MODULEparseTEXTE_MODULE ()
 
EDGE_MODULEparseEDGE_MODULE ()
 
D_PADparseD_PAD (MODULE *aParent=NULL)
 
TRACKparseTRACK ()
 
VIAparseVIA ()
 
ZONE_CONTAINERparseZONE_CONTAINER ()
 
PCB_TARGETparsePCB_TARGET ()
 
BOARDparseBOARD ()
 
BOARDparseBOARD_unchecked ()
 Function parseBOARD_unchecked Parse a module, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically. More...
 
template<class T , class M >
T lookUpLayer (const M &aMap)
 Function lookUpLayer parses the current token for the layer definition of a BOARD_ITEM object. More...
 
PCB_LAYER_ID parseBoardItemLayer ()
 Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object. More...
 
LSET parseBoardItemLayersAsMask ()
 Function parseBoardItemLayersAsMask parses the layers definition of a BOARD_ITEM object. More...
 
wxPoint parseXY ()
 Function parseXY parses a coordinate pair (xy X Y) in board units (mm). More...
 
void parseXY (int *aX, int *aY)
 
void parseEDA_TEXT (EDA_TEXT *aText)
 Function parseEDA_TEXT parses the common settings for any object derived from EDA_TEXT. More...
 
S3D_INFOparse3DModel ()
 
double parseDouble ()
 Function parseDouble parses the current token as an ASCII numeric string with possible leading whitespace into a double precision floating point number. More...
 
double parseDouble (const char *aExpected)
 
double parseDouble (PCB_KEYS_T::T aToken)
 
int parseBoardUnits ()
 
int parseBoardUnits (const char *aExpected)
 
int parseBoardUnits (PCB_KEYS_T::T aToken)
 
int parseInt ()
 
int parseInt (const char *aExpected)
 
long parseHex ()
 
bool parseBool ()
 
int parseVersion ()
 Parse a format version tag like (version 20160417) return the version. More...
 

Private Attributes

BOARDm_board
 
LAYER_ID_MAP m_layerIndices
 map layer name to it's index More...
 
LSET_MAP m_layerMasks
 map layer names to their masks More...
 
std::vector< int > m_netCodes
 net codes mapping for boards being loaded More...
 
bool m_tooRecent
 true if version parses as later than supported More...
 
int m_requiredVersion
 set to the KiCad format version this board requires More...
 

Detailed Description

Class PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object.

Definition at line 66 of file pcb_parser.h.

Member Typedef Documentation

typedef boost::unordered_map< std::string, PCB_LAYER_ID > PCB_PARSER::LAYER_ID_MAP
private

Definition at line 68 of file pcb_parser.h.

typedef boost::unordered_map< std::string, LSET > PCB_PARSER::LSET_MAP
private

Definition at line 69 of file pcb_parser.h.

typedef std::vector<LINE_READER*> DSNLEXER::READER_STACK
protectedinherited

Definition at line 89 of file dsnlexer.h.

Constructor & Destructor Documentation

PCB_PARSER::PCB_PARSER ( LINE_READER aReader = NULL)
inline

Definition at line 281 of file pcb_parser.h.

References init().

281  :
282  PCB_LEXER( aReader ),
283  m_board( 0 )
284  {
285  init();
286  }
PCB_LEXER(const std::string &aSExpression, const wxString &aSource=wxEmptyString)
Constructor ( const std::string&, const wxString& )
Definition: pcb_lexer.h:251
BOARD * m_board
Definition: pcb_parser.h:71
void init()
Function init clears and re-establishes m_layerMap with the default layer names.
Definition: pcb_parser.cpp:56

Member Function Documentation

const char* DSNLEXER::CurLine ( )
inlineinherited

Function CurLine returns the current line of text, from which the CurText() would return its token.

Definition at line 517 of file dsnlexer.h.

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and DSNLEXER::Unexpected().

518  {
519  return (const char*)(*reader);
520  }
int DSNLEXER::CurLineNumber ( )
inlineinherited

Function CurLineNumber returns the current line number within my LINE_READER.

Definition at line 507 of file dsnlexer.h.

References LINE_READER::LineNumber().

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), KICAD_NETLIST_PARSER::parseComponent(), and DSNLEXER::Unexpected().

508  {
509  return reader->LineNumber();
510  }
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
int DSNLEXER::CurOffset ( )
inlineinherited

Function CurOffset returns the byte offset within the current line, using a 1 based index.

Returns
int - a one based index into the current line.

Definition at line 538 of file dsnlexer.h.

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), KICAD_NETLIST_PARSER::parseComponent(), and DSNLEXER::Unexpected().

539  {
540  return curOffset + 1;
541  }
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:106
const wxString& DSNLEXER::CurSource ( )
inlineinherited

Function CurFilename returns the current LINE_READER source.

Returns
const wxString& - the source of the lines of text, e.g. a filename or "clipboard".

Definition at line 528 of file dsnlexer.h.

References LINE_READER::GetSource().

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), KICAD_NETLIST_PARSER::parseComponent(), and DSNLEXER::Unexpected().

529  {
530  return reader->GetSource();
531  }
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
const std::string& DSNLEXER::CurStr ( )
inlineinherited

Function CurStr returns a reference to current token in std::string form.

Definition at line 488 of file dsnlexer.h.

References DSNLEXER::curText.

Referenced by PCB_PLOT_PARAMS_PARSER::Parse(), and PAGE_LAYOUT_READER_PARSER::readPngdata().

489  {
490  return curText;
491  }
std::string curText
the text of the current token
Definition: dsnlexer.h:109
const char* DSNLEXER::CurText ( )
inlineinherited

Function CurText returns a pointer to the current token's text.

Definition at line 479 of file dsnlexer.h.

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doCIRCLE(), DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASSES(), DSN::SPECCTRA_DB::doCOMP_ORDER(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doCONNECT(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doGRID(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doLIBRARY(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doNETWORK(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPCB(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPROPERTIES(), DSN::SPECCTRA_DB::doQARC(), DSN::SPECCTRA_DB::doRECTANGLE(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doRESOLUTION(), DSN::SPECCTRA_DB::doROUTE(), DSN::SPECCTRA_DB::doRULE(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSPECCTRA_LAYER_PAIR(), DSN::SPECCTRA_DB::doSTRINGPROP(), DSN::SPECCTRA_DB::doSTRUCTURE(), DSN::SPECCTRA_DB::doSTRUCTURE_OUT(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOKPROP(), DSN::SPECCTRA_DB::doTOPOLOGY(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWINDOW(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSN::SPECCTRA_DB::doWIRING(), PCAD2KICAD::LoadInputFile(), PCB_PLOT_PARAMS_PARSER::Parse(), PAGE_LAYOUT_READER_PARSER::Parse(), TEMPLATE_FIELDNAME::Parse(), TEMPLATES::Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), KICAD_NETLIST_PARSER::parseComponent(), PAGE_LAYOUT_READER_PARSER::parseCoordinate(), PCB_PLOT_PARAMS_PARSER::parseDouble(), PAGE_LAYOUT_READER_PARSER::parseDouble(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), parseHex(), PCB_PLOT_PARAMS_PARSER::parseInt(), PAGE_LAYOUT_READER_PARSER::parseInt(), parseInt(), KICAD_NETLIST_PARSER::parseLibPartList(), KICAD_NETLIST_PARSER::parseNet(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parsePolyOutline(), PAGE_LAYOUT_READER_PARSER::parseSetup(), PAGE_LAYOUT_READER_PARSER::parseText(), DSN::SPECCTRA_DB::readCOMPnPIN(), PAGE_LAYOUT_READER_PARSER::readOption(), PAGE_LAYOUT_READER_PARSER::readPngdata(), DSN::SPECCTRA_DB::readTIME(), scanAtom(), and scanList().

480  {
481  return curText.c_str();
482  }
std::string curText
the text of the current token
Definition: dsnlexer.h:109
PCB_KEYS_T::T PCB_LEXER::CurTok ( )
inlineinherited

Function CurTok returns whatever NextTok() returned the last time it was called.

Definition at line 337 of file pcb_lexer.h.

References DSNLEXER::CurTok().

338  {
339  return (PCB_KEYS_T::T) DSNLEXER::CurTok();
340  }
int CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: dsnlexer.h:320
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
void DSNLEXER::Duplicate ( int  aTok)
inherited

Function Duplicate throws an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one already seen in current context.

Parameters
aTokis the token/keyword type which was not expected at the current input location.
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 377 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), DSNLEXER::GetTokenString(), and THROW_PARSE_ERROR.

Referenced by SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and LIB_TABLE_ROW::Parse().

378 {
379  wxString errText = wxString::Format(
380  _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
382 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void DSNLEXER::Expecting ( int  aTok)
inherited

Function Expecting throws an IO_ERROR exception with an input file specific error message.

Parameters
aTokis the token/keyword type which was expected at the current input location.
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 353 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), GetChars(), DSNLEXER::GetTokenString(), and THROW_PARSE_ERROR.

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doBOUNDARY(), DSN::SPECCTRA_DB::doCIRCLE(), DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASS_CLASS(), DSN::SPECCTRA_DB::doCLASSES(), DSN::SPECCTRA_DB::doCOMP_ORDER(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doCONNECT(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doGRID(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLAYER_NOISE_WEIGHT(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doLIBRARY(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doNETWORK(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPCB(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPLACEMENT(), DSN::SPECCTRA_DB::doPROPERTIES(), DSN::SPECCTRA_DB::doQARC(), DSN::SPECCTRA_DB::doRECTANGLE(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doRESOLUTION(), DSN::SPECCTRA_DB::doROUTE(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSPECCTRA_LAYER_PAIR(), DSN::SPECCTRA_DB::doSTRUCTURE(), DSN::SPECCTRA_DB::doSTRUCTURE_OUT(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOPOLOGY(), DSN::SPECCTRA_DB::doUNIT(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWINDOW(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSN::SPECCTRA_DB::doWIRING(), DSN::SPECCTRA_DB::LoadPCB(), DSN::SPECCTRA_DB::LoadSESSION(), DSNLEXER::NeedLEFT(), DSNLEXER::NeedRIGHT(), DSNLEXER::NeedSYMBOL(), DSNLEXER::NeedSYMBOLorNUMBER(), PCB_PLOT_PARAMS_PARSER::Parse(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), TEMPLATE_FIELDNAME::Parse(), LIB_TABLE_ROW::Parse(), PCB_PLOT_PARAMS_PARSER::parseBool(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PLOT_PARAMS_PARSER::parseDouble(), PAGE_LAYOUT_READER_PARSER::parseDouble(), PCB_PLOT_PARAMS_PARSER::parseInt(), PAGE_LAYOUT_READER_PARSER::parseInt(), KICAD_NETLIST_PARSER::parseLibPartList(), DSN::SPECCTRA_DB::readCOMPnPIN(), and DSN::SPECCTRA_DB::readTIME().

354 {
355  wxString errText = wxString::Format(
356  _("Expecting '%s'"), GetChars( GetTokenString( aTok ) ) );
358 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void DSNLEXER::Expecting ( const char *  aTokenList)
inherited

Function Expecting throws an IO_ERROR exception with an input file specific error message.

Parameters
aTokenListis the token/keyword type which was expected at the current input location, e.g. "pin|graphic|property"
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 361 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), GetChars(), and THROW_PARSE_ERROR.

362 {
363  wxString errText = wxString::Format(
364  _("Expecting '%s'"), GetChars( wxString::FromUTF8( text ) ) );
366 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
int DSNLEXER::findToken ( const std::string &  aToken)
inlineprotectedinherited

Function findToken takes aToken string and looks up the string in the keywords table.

Parameters
aTokenis a string to lookup in the keywords table.
Returns
int - with a value from the enum DSN_T matching the keyword text, or DSN_SYMBOL if aToken is not in the kewords table.

Definition at line 260 of file dsnlexer.cpp.

References DSN_SYMBOL, and DSNLEXER::keyword_hash.

Referenced by DSNLEXER::NextTok().

261 {
262  KEYWORD_MAP::const_iterator it = keyword_hash.find( tok.c_str() );
263  if( it != keyword_hash.end() )
264  return it->second;
265 
266  return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
267 }
KEYWORD_MAP keyword_hash
fast, specialized "C string" hashtable
Definition: dsnlexer.h:113
wxString DSNLEXER::FromUTF8 ( )
inlineinherited

Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.

Definition at line 498 of file dsnlexer.h.

Referenced by PAGE_LAYOUT_READER_PARSER::Parse(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), LIB_TABLE_ROW::Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), KICAD_NETLIST_PARSER::parseComponent(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parseText(), and DSNLEXER::ReadCommentLines().

499  {
500  return wxString::FromUTF8( curText.c_str() );
501  }
std::string curText
the text of the current token
Definition: dsnlexer.h:109
int PCB_PARSER::getNetCode ( int  aNetCode)
inlineprivate

Converts net code using the mapping table if available, otherwise returns unchanged net code if < 0 or if is is out of range

Definition at line 80 of file pcb_parser.h.

81  {
82  if( ( aNetCode >= 0 ) && ( aNetCode < (int) m_netCodes.size() ) )
83  return m_netCodes[aNetCode];
84 
85  return aNetCode;
86  }
std::vector< int > m_netCodes
net codes mapping for boards being loaded
Definition: pcb_parser.h:74
wxString PCB_PARSER::GetRequiredVersion ( )

Return a string representing the version of kicad required to open this file.

Not particularly meaningful if IsTooRecent() returns false.

Definition at line 182 of file pcb_parser.cpp.

References THROW_PARSE_ERROR.

Referenced by PCB_IO::Load(), and PCB_IO::Parse().

183 {
184  int year, month, day;
185 
186  year = m_requiredVersion / 10000;
187  month = ( m_requiredVersion / 100 ) - ( year * 100 );
188  day = m_requiredVersion - ( year * 10000 ) - ( month * 100 );
189 
190  // wx throws an assertion, not a catchable exception, when the date is invalid.
191  // User input shouldn't give wx asserts, so check manually and throw a proper
192  // error instead
193  if( day <= 0 || month <= 0 || month > 12 ||
194  day > wxDateTime::GetNumberOfDays( (wxDateTime::Month)( month - 1 ), year ) )
195  {
196  wxString err;
197  err.Printf( _( "cannot interpret date code %d" ), m_requiredVersion );
199  }
200 
201  wxDateTime date( day, (wxDateTime::Month)( month - 1 ), year, 0, 0, 0, 0 );
202  return date.FormatDate();
203 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:76
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString DSNLEXER::GetTokenString ( int  aTok)
inherited

Function GetTokenString returns a quote wrapped wxString representation of a token value.

Definition at line 334 of file dsnlexer.cpp.

References DSNLEXER::GetTokenText().

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), DSN::SPECCTRA_DB::makeVIA(), and DSNLEXER::Unexpected().

335 {
336  wxString ret;
337 
338  ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");
339 
340  return ret;
341 }
const char * GetTokenText(int aTok)
Function GetTokenText returns the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:315
const char * DSNLEXER::GetTokenText ( int  aTok)
inherited

Function GetTokenText returns the C string representation of a DSN_T value.

Definition at line 315 of file dsnlexer.cpp.

References DSNLEXER::keywordCount, DSNLEXER::keywords, KEYWORD::name, and DSNLEXER::Syntax().

Referenced by DSNLEXER::GetTokenString(), parseBoardUnits(), and parseDouble().

316 {
317  const char* ret;
318 
319  if( aTok < 0 )
320  {
321  return Syntax( aTok );
322  }
323  else if( (unsigned) aTok < keywordCount )
324  {
325  ret = keywords[aTok].name;
326  }
327  else
328  ret = "token too big";
329 
330  return ret;
331 }
const KEYWORD * keywords
table sorted by CMake for bsearch()
Definition: dsnlexer.h:111
const char * name
unique keyword.
Definition: dsnlexer.h:42
unsigned keywordCount
count of keywords table
Definition: dsnlexer.h:112
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:271
void PCB_PARSER::init ( )
private

Function init clears and re-establishes m_layerMap with the default layer names.

m_layerMap will have some of its entries overwritten whenever a (new) board is encountered.

Definition at line 56 of file pcb_parser.cpp.

References LSET::AllCuMask(), B_Adhes, B_CrtYd, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, F_Adhes, F_CrtYd, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, In15_Cu, LSET::Name(), PCB_LAYER_ID_COUNT, StrPrintf(), and TO_UTF8.

Referenced by PCB_PARSER(), and SetBoard().

57 {
58  m_tooRecent = false;
60  m_layerIndices.clear();
61  m_layerMasks.clear();
62 
63  // Add untranslated default (i.e. english) layernames.
64  // Some may be overridden later if parsing a board rather than a footprint.
65  // The english name will survive if parsing only a footprint.
66  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
67  {
68  std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
69 
70  m_layerIndices[ untranslated ] = PCB_LAYER_ID( layer );
71  m_layerMasks[ untranslated ] = LSET( PCB_LAYER_ID( layer ) );
72  }
73 
74  m_layerMasks[ "*.Cu" ] = LSET::AllCuMask();
75  m_layerMasks[ "F&B.Cu" ] = LSET( 2, F_Cu, B_Cu );
76  m_layerMasks[ "*.Adhes" ] = LSET( 2, B_Adhes, F_Adhes );
77  m_layerMasks[ "*.Paste" ] = LSET( 2, B_Paste, F_Paste );
78  m_layerMasks[ "*.Mask" ] = LSET( 2, B_Mask, F_Mask );
79  m_layerMasks[ "*.SilkS" ] = LSET( 2, B_SilkS, F_SilkS );
80  m_layerMasks[ "*.Fab" ] = LSET( 2, B_Fab, F_Fab );
81  m_layerMasks[ "*.CrtYd" ] = LSET( 2, B_CrtYd, F_CrtYd );
82 
83  // This is for the first pretty & *.kicad_pcb formats, which had
84  // Inner1_Cu - Inner14_Cu with the numbering sequence
85  // reversed from the subsequent format's In1_Cu - In30_Cu numbering scheme.
86  // The newer format brought in an additional 16 Cu layers and flipped the cu stack but
87  // kept the gap between one of the outside layers and the last cu internal.
88 
89  for( int i=1; i<=14; ++i )
90  {
91  std::string key = StrPrintf( "Inner%d.Cu", i );
92 
93  m_layerMasks[ key ] = LSET( PCB_LAYER_ID( In15_Cu - i ) );
94  }
95 
96 #if defined(DEBUG) && 0
97  printf( "m_layerMasks:\n" );
98  for( LSET_MAP::const_iterator it = m_layerMasks.begin(); it != m_layerMasks.end(); ++it )
99  {
100  printf( " [%s] == 0x%s\n", it->first.c_str(), it->second.FmtHex().c_str() );
101  }
102 
103  printf( "m_layerIndices:\n" );
104  for( LAYER_ID_MAP::const_iterator it = m_layerIndices.begin(); it != m_layerIndices.end(); ++it )
105  {
106  printf( " [%s] == %d\n", it->first.c_str(), it->second );
107  }
108 #endif
109 
110 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:639
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:75
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:73
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:76
LAYER_ID_MAP m_layerIndices
map layer name to it's index
Definition: pcb_parser.h:72
LSET_MAP m_layerMasks
map layer names to their masks
Definition: pcb_parser.h:73
bool DSNLEXER::isStringTerminator ( char  cc)
inlineprotectedinherited

Definition at line 147 of file dsnlexer.h.

Referenced by DSNLEXER::NextTok().

148  {
149  if( !space_in_quoted_tokens && cc==' ' )
150  return true;
151 
152  if( cc == stringDelimiter )
153  return true;
154 
155  return false;
156  }
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:101
char stringDelimiter
Definition: dsnlexer.h:100
bool DSNLEXER::IsSymbol ( int  aTok)
staticinherited

Function IsSymbol tests a token to see if it is a symbol.

This means it cannot be a special delimiter character such as DSN_LEFT, DSN_RIGHT, DSN_QUOTE, etc. It may however, coincidentally match a keyword and still be a symbol.

Definition at line 344 of file dsnlexer.cpp.

References DSN_STRING, and DSN_SYMBOL.

Referenced by DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASSES(), DSN::SPECCTRA_DB::doCOMP_ORDER(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSNLEXER::NeedSYMBOL(), DSNLEXER::NeedSYMBOLorNUMBER(), and DSN::SPECCTRA_DB::readCOMPnPIN().

345 {
346  // This is static and not inline to reduce code space.
347 
348  // if aTok is >= 0, then it is a coincidental match to a keyword.
349  return aTok==DSN_SYMBOL || aTok==DSN_STRING || aTok>=0;
350 }
bool PCB_PARSER::IsTooRecent ( )
inline

Return whether a version number, if any was parsed, was too recent.

Definition at line 314 of file pcb_parser.h.

References m_tooRecent.

Referenced by PCB_IO::Load(), and PCB_IO::Parse().

315  {
316  return m_tooRecent;
317  }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75
template<class T , class M >
T PCB_PARSER::lookUpLayer ( const M &  aMap)
private

Function lookUpLayer parses the current token for the layer definition of a BOARD_ITEM object.

Parameters
aMapis the LAYER_{NUM|MSK}_MAP to use for the lookup.
Exceptions
IO_ERRORif the layer is not valid.
PARSE_ERRORif the layer syntax is incorrect.
Returns
int - The result of the parsed BOARD_ITEM layer or set designator.

Definition at line 925 of file pcb_parser.cpp.

References Format(), FROM_UTF8(), GetChars(), and THROW_IO_ERROR.

926 {
927  // avoid constructing another std::string, use lexer's directly
928  typename M::const_iterator it = aMap.find( curText );
929 
930  if( it == aMap.end() )
931  {
932 #if 0 && defined(DEBUG)
933  // dump the whole darn table, there's something wrong with it.
934  for( it = aMap.begin(); it != aMap.end(); ++it )
935  {
936  wxLogDebug( &aMap == (void*)&m_layerIndices ? wxT( "lm[%s] = %d" ) :
937  wxT( "lm[%s] = %08X" ), it->first.c_str(), it->second );
938  }
939 #endif
940 
941  wxString error = wxString::Format( _(
942  "Layer '%s' in file\n"
943  "'%s'\n"
944  "at line %d, position %d\n"
945  "was not defined in the layers section"
946  ),
947  GetChars( FROM_UTF8( CurText() ) ),
948  GetChars( CurSource() ),
949  CurLineNumber(), CurOffset() );
950 
951  THROW_IO_ERROR( error );
952  }
953 
954  return it->second;
955 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
std::string curText
the text of the current token
Definition: dsnlexer.h:109
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
LAYER_ID_MAP m_layerIndices
map layer name to it's index
Definition: pcb_parser.h:72
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void DSNLEXER::NeedLEFT ( )
inherited

Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.

If it is not, an IO_ERROR is thrown.

Exceptions
IO_ERROR,ifthe next token is not a DSN_LEFT

Definition at line 393 of file dsnlexer.cpp.

References DSN_LEFT, DSNLEXER::Expecting(), and DSNLEXER::NextTok().

Referenced by SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), TEMPLATE_FIELDNAME::Parse(), and LIB_TABLE_ROW::Parse().

394 {
395  int tok = NextTok();
396  if( tok != DSN_LEFT )
397  Expecting( DSN_LEFT );
398 }
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
int DSNLEXER::NeedNUMBER ( const char *  aExpectation)
inherited

Function NeedNUMBER calls NextTok() and then verifies that the token read is type DSN_NUMBER.

If not, and IO_ERROR is thrown using text from aExpectation.

Returns
int - the actual token read in.
Exceptions
IO_ERROR,ifthe next token does not satisfy the above test

Definition at line 427 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), DSN_NUMBER, Format(), DSNLEXER::NextTok(), and THROW_PARSE_ERROR.

Referenced by parseDouble(), and parseInt().

428 {
429  int tok = NextTok();
430  if( tok != DSN_NUMBER )
431  {
432  wxString errText = wxString::Format(
433  _("need a NUMBER for '%s'"), wxString::FromUTF8( aExpectation ).GetData() );
435  }
436  return tok;
437 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
void DSNLEXER::NeedRIGHT ( )
inherited

Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.

If it is not, an IO_ERROR is thrown.

Exceptions
IO_ERROR,ifthe next token is not a DSN_RIGHT

Definition at line 401 of file dsnlexer.cpp.

References DSN_RIGHT, DSNLEXER::Expecting(), and DSNLEXER::NextTok().

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doBOUNDARY(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPLACEMENT(), DSN::SPECCTRA_DB::doPROPERTIES(), DSN::SPECCTRA_DB::doQARC(), DSN::SPECCTRA_DB::doRECTANGLE(), DSN::SPECCTRA_DB::doRESOLUTION(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSPECCTRA_LAYER_PAIR(), DSN::SPECCTRA_DB::doSTRINGPROP(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOKPROP(), DSN::SPECCTRA_DB::doUNIT(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), PCB_PLOT_PARAMS_PARSER::Parse(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), TEMPLATE_FIELDNAME::Parse(), LIB_TABLE_ROW::Parse(), KICAD_NETLIST_PARSER::Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), KICAD_NETLIST_PARSER::parseComponent(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), KICAD_NETLIST_PARSER::parseLibPartList(), KICAD_NETLIST_PARSER::parseNet(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parsePolyOutline(), PAGE_LAYOUT_READER_PARSER::parseSetup(), PAGE_LAYOUT_READER_PARSER::parseText(), and PAGE_LAYOUT_READER_PARSER::readPngdata().

402 {
403  int tok = NextTok();
404  if( tok != DSN_RIGHT )
405  Expecting( DSN_RIGHT );
406 }
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
PCB_KEYS_T::T PCB_LEXER::NeedSYMBOL ( )
inlineinherited

Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol().

If not, an IO_ERROR is thrown.

Returns
int - the actual token read in.
Exceptions
IO_ERROR,ifthe next token does not satisfy IsSymbol()

Definition at line 315 of file pcb_lexer.h.

References DSNLEXER::NeedSYMBOL().

316  {
318  }
int NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: dsnlexer.cpp:409
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
PCB_KEYS_T::T PCB_LEXER::NeedSYMBOLorNUMBER ( )
inlineinherited

Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool IsSymbol() or tok==T_NUMBER.

If not, an IO_ERROR is thrown.

Returns
int - the actual token read in.
Exceptions
IO_ERROR,ifthe next token does not satisfy the above test

Definition at line 328 of file pcb_lexer.h.

References DSNLEXER::NeedSYMBOLorNUMBER().

329  {
331  }
int NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: dsnlexer.cpp:418
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
PCB_KEYS_T::T PCB_LEXER::NextTok ( )
inlineinherited

Function NextTok returns the next token found in the input file or T_EOF when reaching the end of file.

Users should wrap this function to return an enum to aid in grammar debugging while running under a debugger, but leave this lower level function returning an int (so the enum does not collide with another usage).

Returns
PCB_KEYS_T::T - the type of token found next.
Exceptions
IO_ERROR- only if the LINE_READER throws it.

Definition at line 302 of file pcb_lexer.h.

References DSNLEXER::NextTok().

Referenced by parseHex().

303  {
304  return (PCB_KEYS_T::T) DSNLEXER::NextTok();
305  }
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
BOARD_ITEM * PCB_PARSER::Parse ( )

Definition at line 405 of file pcb_parser.cpp.

References GetChars(), PCB_KEYS_T::T_kicad_pcb, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_module, and THROW_PARSE_ERROR.

Referenced by GITHUB_PLUGIN::FootprintLoad(), PCB_IO::Load(), FP_CACHE::Load(), and PCB_IO::Parse().

406 {
407  T token;
408  BOARD_ITEM* item;
409  LOCALE_IO toggle;
410 
411  // MODULEs can be prefixed with an initial block of single line comments and these
412  // are kept for Format() so they round trip in s-expression form. BOARDs might
413  // eventually do the same, but currently do not.
414  std::unique_ptr<wxArrayString> initial_comments( ReadCommentLines() );
415 
416  token = CurTok();
417 
418  if( token != T_LEFT )
419  Expecting( T_LEFT );
420 
421  switch( NextTok() )
422  {
423  case T_kicad_pcb:
424  if( m_board == NULL )
425  m_board = new BOARD();
426 
427  item = (BOARD_ITEM*) parseBOARD();
428  break;
429 
430  case T_module:
431  item = (BOARD_ITEM*) parseMODULE( initial_comments.release() );
432  break;
433 
434  default:
435  wxString err;
436  err.Printf( _( "unknown token \"%s\"" ), GetChars( FromUTF8() ) );
438  }
439 
440  return item;
441 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
BOARD * parseBOARD()
Definition: pcb_parser.cpp:444
wxArrayString * ReadCommentLines()
Function ReadCommentLines checks the next sequence of tokens and reads them into a wxArrayString if t...
Definition: dsnlexer.cpp:811
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
BOARD * m_board
Definition: pcb_parser.h:71
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.
S3D_INFO * PCB_PARSER::parse3DModel ( )
private

Definition at line 335 of file pcb_parser.cpp.

References S3D_INFO::m_Filename, S3D_INFO::m_Offset, S3D_INFO::m_Rotation, S3D_INFO::m_Scale, parseDouble(), PCB_KEYS_T::T_at, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_model, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_rotate, PCB_KEYS_T::T_scale, PCB_KEYS_T::T_xyz, SGPOINT::x, SGPOINT::y, and SGPOINT::z.

336 {
337  wxCHECK_MSG( CurTok() == T_model, NULL,
338  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as S3D_INFO." ) );
339 
340  T token;
341 
342  S3D_INFO* n3D = new S3D_INFO;
344  n3D->m_Filename = FromUTF8();
345 
346  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
347  {
348  if( token != T_LEFT )
349  Expecting( T_LEFT );
350 
351  token = NextTok();
352 
353  switch( token )
354  {
355  case T_at:
356  NeedLEFT();
357  token = NextTok();
358 
359  if( token != T_xyz )
360  Expecting( T_xyz );
361 
362  n3D->m_Offset.x = parseDouble( "x value" );
363  n3D->m_Offset.y = parseDouble( "y value" );
364  n3D->m_Offset.z = parseDouble( "z value" );
365  NeedRIGHT();
366  break;
367 
368  case T_scale:
369  NeedLEFT();
370  token = NextTok();
371 
372  if( token != T_xyz )
373  Expecting( T_xyz );
374 
375  n3D->m_Scale.x = parseDouble( "x value" );
376  n3D->m_Scale.y = parseDouble( "y value" );
377  n3D->m_Scale.z = parseDouble( "z value" );
378  NeedRIGHT();
379  break;
380 
381  case T_rotate:
382  NeedLEFT();
383  token = NextTok();
384 
385  if( token != T_xyz )
386  Expecting( T_xyz );
387 
388  n3D->m_Rotation.x = parseDouble( "x value" );
389  n3D->m_Rotation.y = parseDouble( "y value" );
390  n3D->m_Rotation.z = parseDouble( "z value" );
391  NeedRIGHT();
392  break;
393 
394  default:
395  Expecting( "at, scale, or rotate" );
396  }
397 
398  NeedRIGHT();
399  }
400 
401  return n3D;
402 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
SGPOINT m_Offset
an offset (unit = inch) for the 3D shape
Definition: 3d_info.h:44
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void NeedLEFT()
Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:393
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
SGPOINT m_Rotation
an X,Y,Z rotation (unit = degrees) for the 3D shape
Definition: 3d_info.h:43
double z
Definition: sg_base.h:72
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
SGPOINT m_Scale
scaling factors for the 3D footprint shape
Definition: 3d_info.h:42
wxString m_Filename
The 3D shape filename in 3D library.
Definition: 3d_info.h:45
BOARD * PCB_PARSER::parseBOARD ( )
private

Definition at line 444 of file pcb_parser.cpp.

445 {
446  try
447  {
448  return parseBOARD_unchecked();
449  }
450  catch( const PARSE_ERROR& parse_error )
451  {
452  if( m_tooRecent )
453  throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
454  else
455  throw;
456  }
457 }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
BOARD * parseBOARD_unchecked()
Function parseBOARD_unchecked Parse a module, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR...
Definition: pcb_parser.cpp:460
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
BOARD * PCB_PARSER::parseBOARD_unchecked ( )
private

Function parseBOARD_unchecked Parse a module, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically.

Definition at line 460 of file pcb_parser.cpp.

References ADD_APPEND, GetChars(), PCB_KEYS_T::T_dimension, PCB_KEYS_T::T_general, PCB_KEYS_T::T_gr_arc, PCB_KEYS_T::T_gr_circle, PCB_KEYS_T::T_gr_curve, PCB_KEYS_T::T_gr_line, PCB_KEYS_T::T_gr_poly, PCB_KEYS_T::T_gr_text, PCB_KEYS_T::T_layers, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_module, PCB_KEYS_T::T_net, PCB_KEYS_T::T_net_class, PCB_KEYS_T::T_page, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_segment, PCB_KEYS_T::T_setup, PCB_KEYS_T::T_target, PCB_KEYS_T::T_title_block, PCB_KEYS_T::T_via, PCB_KEYS_T::T_zone, and THROW_PARSE_ERROR.

461 {
462  T token;
463 
464  parseHeader();
465 
466  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
467  {
468  if( token != T_LEFT )
469  Expecting( T_LEFT );
470 
471  token = NextTok();
472 
473  switch( token )
474  {
475  case T_general:
477  break;
478 
479  case T_page:
480  parsePAGE_INFO();
481  break;
482 
483  case T_title_block:
485  break;
486 
487  case T_layers:
488  parseLayers();
489  break;
490 
491  case T_setup:
492  parseSetup();
493  break;
494 
495  case T_net:
497  break;
498 
499  case T_net_class:
500  parseNETCLASS();
501  break;
502 
503  case T_gr_arc:
504  case T_gr_circle:
505  case T_gr_curve:
506  case T_gr_line:
507  case T_gr_poly:
509  break;
510 
511  case T_gr_text:
513  break;
514 
515  case T_dimension:
517  break;
518 
519  case T_module:
521  break;
522 
523  case T_segment:
525  break;
526 
527  case T_via:
529  break;
530 
531  case T_zone:
533  break;
534 
535  case T_target:
537  break;
538 
539  default:
540  wxString err;
541  err.Printf( _( "unknown token \"%s\"" ), GetChars( FromUTF8() ) );
543  }
544  }
545 
546  return m_board;
547 }
void parseHeader()
Definition: pcb_parser.cpp:550
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
TRACK * parseTRACK()
VIA * parseVIA()
void parseNETINFO_ITEM()
DIMENSION * parseDIMENSION()
void parseTITLE_BLOCK()
Definition: pcb_parser.cpp:687
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
void parseLayers()
Definition: pcb_parser.cpp:812
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
void parsePAGE_INFO()
Definition: pcb_parser.cpp:631
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
DRAWSEGMENT * parseDRAWSEGMENT()
PCB_TARGET * parsePCB_TARGET()
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
TEXTE_PCB * parseTEXTE_PCB()
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
void parseNETCLASS()
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
ZONE_CONTAINER * parseZONE_CONTAINER()
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
BOARD * m_board
Definition: pcb_parser.h:71
void parseGeneralSection()
Definition: pcb_parser.cpp:586
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.
void parseSetup()
Definition: pcb_parser.cpp:991
PCB_LAYER_ID PCB_PARSER::parseBoardItemLayer ( )
private

Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.

Exceptions
IO_ERRORif the layer is not valid.
PARSE_ERRORif the layer syntax is incorrect.
Returns
The index the parsed BOARD_ITEM layer.

Definition at line 958 of file pcb_parser.cpp.

References PCB_KEYS_T::T_layer, and UNDEFINED_LAYER.

959 {
960  wxCHECK_MSG( CurTok() == T_layer, UNDEFINED_LAYER,
961  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layer." ) );
962 
963  NextTok();
964 
965  PCB_LAYER_ID layerIndex = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
966 
967  // Handle closing ) in object parser.
968 
969  return layerIndex;
970 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
PCB_LAYER_ID
A quick note on layer IDs:
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
LAYER_ID_MAP m_layerIndices
map layer name to it's index
Definition: pcb_parser.h:72
LSET PCB_PARSER::parseBoardItemLayersAsMask ( )
private

Function parseBoardItemLayersAsMask parses the layers definition of a BOARD_ITEM object.

Exceptions
IO_ERRORif any of the layers is not valid.
PARSE_ERRORif the layers syntax is incorrect.
Returns
The mask of layers the parsed BOARD_ITEM is on.

Definition at line 973 of file pcb_parser.cpp.

References PCB_KEYS_T::T_layers, and PCB_KEYS_T::T_RIGHT.

974 {
975  wxCHECK_MSG( CurTok() == T_layers, LSET(),
976  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
977  wxT( " as item layer mask." ) );
978 
979  LSET layerMask;
980 
981  for( T token = NextTok(); token != T_RIGHT; token = NextTok() )
982  {
983  LSET mask = lookUpLayer<LSET>( m_layerMasks );
984  layerMask |= mask;
985  }
986 
987  return layerMask;
988 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
Class LSET is a set of PCB_LAYER_IDs.
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
LSET_MAP m_layerMasks
map layer names to their masks
Definition: pcb_parser.h:73
int PCB_PARSER::parseBoardUnits ( )
inlineprivate

Definition at line 230 of file pcb_parser.h.

References KiROUND(), and parseDouble().

Referenced by parseBoardUnits().

231  {
232  // There should be no major rounding issues here, since the values in
233  // the file are in mm and get converted to nano-meters.
234  // See test program tools/test-nm-biu-to-ascii-mm-round-tripping.cpp
235  // to confirm or experiment. Use a similar strategy in both places, here
236  // and in the test program. Make that program with:
237  // $ make test-nm-biu-to-ascii-mm-round-tripping
238  return KiROUND( parseDouble() * IU_PER_MM );
239  }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
int PCB_PARSER::parseBoardUnits ( const char *  aExpected)
inlineprivate

Definition at line 241 of file pcb_parser.h.

References KiROUND(), and parseDouble().

242  {
243  // Use here KiROUND, not KIROUND (see comments about them)
244  // when having a function as argument, because it will be called twice
245  // with KIROUND
246  return KiROUND( parseDouble( aExpected ) * IU_PER_MM );
247  }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
int PCB_PARSER::parseBoardUnits ( PCB_KEYS_T::T  aToken)
inlineprivate

Definition at line 249 of file pcb_parser.h.

References DSNLEXER::GetTokenText(), and parseBoardUnits().

250  {
251  return parseBoardUnits( GetTokenText( aToken ) );
252  }
const char * GetTokenText(int aTok)
Function GetTokenText returns the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:315
int parseBoardUnits()
Definition: pcb_parser.h:230
bool PCB_PARSER::parseBool ( )
private

Definition at line 154 of file pcb_parser.cpp.

References PCB_KEYS_T::T_no, and PCB_KEYS_T::T_yes.

155 {
156  T token = NextTok();
157 
158  if( token == T_yes )
159  return true;
160  else if( token == T_no )
161  return false;
162  else
163  Expecting( "yes or no" );
164 
165  return false;
166 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
D_PAD * PCB_PARSER::parseD_PAD ( MODULE aParent = NULL)
private

Definition at line 2236 of file pcb_parser.cpp.

References delta, Format(), GetChars(), PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, parseDouble(), parseInt(), PCB_KEYS_T::T_at, PCB_KEYS_T::T_circle, PCB_KEYS_T::T_clearance, PCB_KEYS_T::T_connect, PCB_KEYS_T::T_die_length, PCB_KEYS_T::T_drill, PCB_KEYS_T::T_layers, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_net, PCB_KEYS_T::T_np_thru_hole, PCB_KEYS_T::T_NUMBER, PCB_KEYS_T::T_offset, PCB_KEYS_T::T_oval, PCB_KEYS_T::T_pad, PCB_KEYS_T::T_rect, PCB_KEYS_T::T_rect_delta, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_roundrect, PCB_KEYS_T::T_roundrect_rratio, PCB_KEYS_T::T_size, PCB_KEYS_T::T_smd, PCB_KEYS_T::T_solder_mask_margin, PCB_KEYS_T::T_solder_paste_margin, PCB_KEYS_T::T_solder_paste_margin_ratio, PCB_KEYS_T::T_thermal_gap, PCB_KEYS_T::T_thermal_width, PCB_KEYS_T::T_thru_hole, PCB_KEYS_T::T_trapezoid, PCB_KEYS_T::T_zone_connect, THROW_IO_ERROR, wxPoint::x, and wxPoint::y.

2237 {
2238  wxCHECK_MSG( CurTok() == T_pad, NULL,
2239  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) );
2240 
2241  wxSize sz;
2242  wxPoint pt;
2243 
2244  std::unique_ptr< D_PAD > pad( new D_PAD( aParent ) );
2245 
2247  pad->SetPadName( FromUTF8() );
2248 
2249  T token = NextTok();
2250 
2251  switch( token )
2252  {
2253  case T_thru_hole:
2254  pad->SetAttribute( PAD_ATTRIB_STANDARD );
2255  break;
2256 
2257  case T_smd:
2258  pad->SetAttribute( PAD_ATTRIB_SMD );
2259 
2260  // Default D_PAD object is thru hole with drill.
2261  // SMD pads have no hole
2262  pad->SetDrillSize( wxSize( 0, 0 ) );
2263  break;
2264 
2265  case T_connect:
2266  pad->SetAttribute( PAD_ATTRIB_CONN );
2267 
2268  // Default D_PAD object is thru hole with drill.
2269  // CONN pads have no hole
2270  pad->SetDrillSize( wxSize( 0, 0 ) );
2271  break;
2272 
2273  case T_np_thru_hole:
2274  pad->SetAttribute( PAD_ATTRIB_HOLE_NOT_PLATED );
2275  break;
2276 
2277  default:
2278  Expecting( "thru_hole, smd, connect, or np_thru_hole" );
2279  }
2280 
2281  token = NextTok();
2282 
2283  switch( token )
2284  {
2285  case T_circle:
2286  pad->SetShape( PAD_SHAPE_CIRCLE );
2287  break;
2288 
2289  case T_rect:
2290  pad->SetShape( PAD_SHAPE_RECT );
2291  break;
2292 
2293  case T_oval:
2294  pad->SetShape( PAD_SHAPE_OVAL );
2295  break;
2296 
2297  case T_trapezoid:
2298  pad->SetShape( PAD_SHAPE_TRAPEZOID );
2299  break;
2300 
2301  case T_roundrect:
2302  pad->SetShape( PAD_SHAPE_ROUNDRECT );
2303  break;
2304 
2305  default:
2306  Expecting( "circle, rectangle, roundrect, oval, trapezoid or custom" );
2307  }
2308 
2309  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2310  {
2311  if( token != T_LEFT )
2312  Expecting( T_LEFT );
2313 
2314  token = NextTok();
2315 
2316  switch( token )
2317  {
2318  case T_size:
2319  sz.SetWidth( parseBoardUnits( "width value" ) );
2320  sz.SetHeight( parseBoardUnits( "height value" ) );
2321  pad->SetSize( sz );
2322  NeedRIGHT();
2323  break;
2324 
2325  case T_at:
2326  pt.x = parseBoardUnits( "X coordinate" );
2327  pt.y = parseBoardUnits( "Y coordinate" );
2328  pad->SetPos0( pt );
2329  token = NextTok();
2330 
2331  if( token == T_NUMBER )
2332  {
2333  pad->SetOrientation( parseDouble() * 10.0 );
2334  NeedRIGHT();
2335  }
2336  else if( token != T_RIGHT )
2337  {
2338  Expecting( ") or angle value" );
2339  }
2340 
2341  break;
2342 
2343  case T_rect_delta:
2344  {
2345  wxSize delta;
2346  delta.SetWidth( parseBoardUnits( "rectangle delta width" ) );
2347  delta.SetHeight( parseBoardUnits( "rectangle delta height" ) );
2348  pad->SetDelta( delta );
2349  NeedRIGHT();
2350  }
2351  break;
2352 
2353  case T_drill:
2354  {
2355  bool haveWidth = false;
2356  wxSize drillSize = pad->GetDrillSize();
2357 
2358  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2359  {
2360  if( token == T_LEFT )
2361  token = NextTok();
2362 
2363  switch( token )
2364  {
2365  case T_oval:
2366  pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
2367  break;
2368 
2369  case T_NUMBER:
2370  {
2371  if( !haveWidth )
2372  {
2373  drillSize.SetWidth( parseBoardUnits() );
2374 
2375  // If height is not defined the width and height are the same.
2376  drillSize.SetHeight( drillSize.GetWidth() );
2377  haveWidth = true;
2378  }
2379  else
2380  {
2381  drillSize.SetHeight( parseBoardUnits() );
2382  }
2383 
2384  }
2385  break;
2386 
2387  case T_offset:
2388  pt.x = parseBoardUnits( "drill offset x" );
2389  pt.y = parseBoardUnits( "drill offset y" );
2390  pad->SetOffset( pt );
2391  NeedRIGHT();
2392  break;
2393 
2394  default:
2395  Expecting( "oval, size, or offset" );
2396  }
2397  }
2398 
2399  // This fixes a bug caused by setting the default D_PAD drill size to a value
2400  // other than 0 used to fix a bunch of debug assertions even though it is defined
2401  // as a through hole pad. Wouldn't a though hole pad with no drill be a surface
2402  // mount pad (or a conn pad which is a smd pad with no solder paste)?
2403  if( ( pad->GetAttribute() != PAD_ATTRIB_SMD ) && ( pad->GetAttribute() != PAD_ATTRIB_CONN ) )
2404  pad->SetDrillSize( drillSize );
2405  else
2406  pad->SetDrillSize( wxSize( 0, 0 ) );
2407 
2408  }
2409  break;
2410 
2411  case T_layers:
2412  {
2413  LSET layerMask = parseBoardItemLayersAsMask();
2414  pad->SetLayerSet( layerMask );
2415  }
2416  break;
2417 
2418  case T_net:
2419  if( ! pad->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
2421  wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ),
2423  );
2425  if( m_board && FromUTF8() != m_board->FindNet( pad->GetNetCode() )->GetNetname() )
2427  wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ),
2429  );
2430  NeedRIGHT();
2431  break;
2432 
2433  case T_die_length:
2434  pad->SetPadToDieLength( parseBoardUnits( T_die_length ) );
2435  NeedRIGHT();
2436  break;
2437 
2438  case T_solder_mask_margin:
2439  pad->SetLocalSolderMaskMargin( parseBoardUnits( T_solder_mask_margin ) );
2440  NeedRIGHT();
2441  break;
2442 
2443  case T_solder_paste_margin:
2444  pad->SetLocalSolderPasteMargin( parseBoardUnits( T_solder_paste_margin ) );
2445  NeedRIGHT();
2446  break;
2447 
2449  pad->SetLocalSolderPasteMarginRatio(
2450  parseDouble( "pad local solder paste margin ratio value" ) );
2451  NeedRIGHT();
2452  break;
2453 
2454  case T_clearance:
2455  pad->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
2456  NeedRIGHT();
2457  break;
2458 
2459  case T_zone_connect:
2460  pad->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
2461  NeedRIGHT();
2462  break;
2463 
2464  case T_thermal_width:
2465  pad->SetThermalWidth( parseBoardUnits( T_thermal_width ) );
2466  NeedRIGHT();
2467  break;
2468 
2469  case T_thermal_gap:
2470  pad->SetThermalGap( parseBoardUnits( T_thermal_gap ) );
2471  NeedRIGHT();
2472  break;
2473 
2474  case T_roundrect_rratio:
2475  pad->SetRoundRectRadiusRatio( parseDouble( "roundrect radius ratio" ) );
2476  NeedRIGHT();
2477  break;
2478 
2479  default:
2480  Expecting( "at, drill, layers, net, die_length, solder_mask_margin, roundrect_rratio,"
2481  "solder_paste_margin, solder_paste_margin_ratio, clearance, "
2482  "zone_connect, fp_poly, basic_shapes, thermal_width, or thermal_gap" );
2483  }
2484  }
2485 
2486  return pad.release();
2487 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
LSET parseBoardItemLayersAsMask()
Function parseBoardItemLayersAsMask parses the layers definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:973
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
ZoneConnection
How pads are covered by copper in zone.
Definition: zones.h:55
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
static const int delta[8][2]
Definition: solve.cpp:112
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
Class LSET is a set of PCB_LAYER_IDs.
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:60
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int getNetCode(int aNetCode)
Converts net code using the mapping table if available, otherwise returns unchanged net code if < 0 o...
Definition: pcb_parser.h:80
BOARD * m_board
Definition: pcb_parser.h:71
Usual pad.
Definition: pad_shapes.h:58
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
int parseInt()
Definition: pcb_parser.h:254
DIMENSION * PCB_PARSER::parseDIMENSION ( )
private

Definition at line 1565 of file pcb_parser.cpp.

References EDA_TEXT::GetTextPos(), parseHex(), TEXTE_PCB::SetPosition(), PCB_KEYS_T::T_arrow1a, PCB_KEYS_T::T_arrow1b, PCB_KEYS_T::T_arrow2a, PCB_KEYS_T::T_arrow2b, PCB_KEYS_T::T_crossbar, PCB_KEYS_T::T_dimension, PCB_KEYS_T::T_feature1, PCB_KEYS_T::T_feature2, PCB_KEYS_T::T_gr_text, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_pts, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_tstamp, and PCB_KEYS_T::T_width.

1566 {
1567  wxCHECK_MSG( CurTok() == T_dimension, NULL,
1568  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DIMENSION." ) );
1569 
1570  T token;
1571 
1572  std::unique_ptr<DIMENSION> dimension( new DIMENSION( NULL ) );
1573 
1574  dimension->SetValue( parseBoardUnits( "dimension value" ) );
1575  NeedLEFT();
1576  token = NextTok();
1577 
1578  if( token != T_width )
1579  Expecting( T_width );
1580 
1581  dimension->SetWidth( parseBoardUnits( "dimension width value" ) );
1582  NeedRIGHT();
1583 
1584  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1585  {
1586  if( token != T_LEFT )
1587  Expecting( T_LEFT );
1588 
1589  token = NextTok();
1590 
1591  switch( token )
1592  {
1593  case T_layer:
1594  dimension->SetLayer( parseBoardItemLayer() );
1595  NeedRIGHT();
1596  break;
1597 
1598  case T_tstamp:
1599  dimension->SetTimeStamp( parseHex() );
1600  NeedRIGHT();
1601  break;
1602 
1603  case T_gr_text:
1604  {
1605  TEXTE_PCB* text = parseTEXTE_PCB();
1606  dimension->Text() = *text;
1607  dimension->SetPosition( text->GetTextPos() );
1608  delete text;
1609  break;
1610  }
1611 
1612  case T_feature1:
1613  NeedLEFT();
1614  token = NextTok();
1615 
1616  if( token != T_pts )
1617  Expecting( T_pts );
1618 
1619  parseXY( &dimension->m_featureLineDO.x, &dimension->m_featureLineDO.y );
1620  parseXY( &dimension->m_featureLineDF.x, &dimension->m_featureLineDF.y );
1621  dimension->UpdateHeight();
1622  NeedRIGHT();
1623  NeedRIGHT();
1624  break;
1625 
1626  case T_feature2:
1627  NeedLEFT();
1628  token = NextTok();
1629 
1630  if( token != T_pts )
1631  Expecting( T_pts );
1632 
1633  parseXY( &dimension->m_featureLineGO.x, &dimension->m_featureLineGO.y );
1634  parseXY( &dimension->m_featureLineGF.x, &dimension->m_featureLineGF.y );
1635  dimension->UpdateHeight();
1636  NeedRIGHT();
1637  NeedRIGHT();
1638  break;
1639 
1640 
1641  case T_crossbar:
1642  NeedLEFT();
1643  token = NextTok();
1644 
1645  if( token != T_pts )
1646  Expecting( T_pts );
1647 
1648  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1649  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1650  dimension->UpdateHeight();
1651  NeedRIGHT();
1652  NeedRIGHT();
1653  break;
1654 
1655  case T_arrow1a:
1656  NeedLEFT();
1657  token = NextTok();
1658 
1659  if( token != T_pts )
1660  Expecting( T_pts );
1661 
1662  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1663  parseXY( &dimension->m_arrowD1F.x, &dimension->m_arrowD1F.y );
1664  NeedRIGHT();
1665  NeedRIGHT();
1666  break;
1667 
1668  case T_arrow1b:
1669  NeedLEFT();
1670  token = NextTok();
1671 
1672  if( token != T_pts )
1673  Expecting( T_pts );
1674 
1675  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1676  parseXY( &dimension->m_arrowD2F.x, &dimension->m_arrowD2F.y );
1677  NeedRIGHT();
1678  NeedRIGHT();
1679  break;
1680 
1681  case T_arrow2a:
1682  NeedLEFT();
1683  token = NextTok();
1684 
1685  if( token != T_pts )
1686  Expecting( T_pts );
1687 
1688  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1689  parseXY( &dimension->m_arrowG1F.x, &dimension->m_arrowG1F.y );
1690  NeedRIGHT();
1691  NeedRIGHT();
1692  break;
1693 
1694  case T_arrow2b:
1695  NeedLEFT();
1696  token = NextTok();
1697 
1698  if( token != T_pts )
1699  Expecting( T_pts );
1700 
1701  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1702  parseXY( &dimension->m_arrowG2F.x, &dimension->m_arrowG2F.y );
1703  NeedRIGHT();
1704  NeedRIGHT();
1705  break;
1706 
1707  default:
1708  Expecting( "layer, tstamp, gr_text, feature1, feature2 crossbar, arrow1a, "
1709  "arrow1b, arrow2a, or arrow2b" );
1710  }
1711  }
1712 
1713  return dimension.release();
1714 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
wxPoint parseXY()
Function parseXY parses a coordinate pair (xy X Y) in board units (mm).
Definition: pcb_parser.cpp:206
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void NeedLEFT()
Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:393
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:958
TEXTE_PCB * parseTEXTE_PCB()
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
virtual void SetPosition(const wxPoint &aPos) override
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
long parseHex()
Definition: pcb_parser.h:265
Class DIMENSION.
double PCB_PARSER::parseDouble ( )
private

Function parseDouble parses the current token as an ASCII numeric string with possible leading whitespace into a double precision floating point number.

Exceptions
IO_ERRORif an error occurs attempting to convert the current token.
Returns
The result of the parsed token.

Definition at line 124 of file pcb_parser.cpp.

References GetChars(), and THROW_IO_ERROR.

Referenced by parseBoardUnits(), and parseDouble().

125 {
126  char* tmp;
127 
128  errno = 0;
129 
130  double fval = strtod( CurText(), &tmp );
131 
132  if( errno )
133  {
134  wxString error;
135  error.Printf( _( "invalid floating point number in\nfile: <%s>\nline: %d\noffset: %d" ),
137 
138  THROW_IO_ERROR( error );
139  }
140 
141  if( CurText() == tmp )
142  {
143  wxString error;
144  error.Printf( _( "missing floating point number in\nfile: <%s>\nline: %d\noffset: %d" ),
146 
147  THROW_IO_ERROR( error );
148  }
149 
150  return fval;
151 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
double PCB_PARSER::parseDouble ( const char *  aExpected)
inlineprivate

Definition at line 219 of file pcb_parser.h.

References DSNLEXER::NeedNUMBER(), and parseDouble().

220  {
221  NeedNUMBER( aExpected );
222  return parseDouble();
223  }
int NeedNUMBER(const char *aExpectation)
Function NeedNUMBER calls NextTok() and then verifies that the token read is type DSN_NUMBER...
Definition: dsnlexer.cpp:427
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
double PCB_PARSER::parseDouble ( PCB_KEYS_T::T  aToken)
inlineprivate

Definition at line 225 of file pcb_parser.h.

References DSNLEXER::GetTokenText(), and parseDouble().

226  {
227  return parseDouble( GetTokenText( aToken ) );
228  }
const char * GetTokenText(int aTok)
Function GetTokenText returns the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:315
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
DRAWSEGMENT * PCB_PARSER::parseDRAWSEGMENT ( )
private

Definition at line 1335 of file pcb_parser.cpp.

References parseDouble(), parseHex(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, PCB_KEYS_T::T_angle, PCB_KEYS_T::T_center, PCB_KEYS_T::T_end, PCB_KEYS_T::T_gr_arc, PCB_KEYS_T::T_gr_circle, PCB_KEYS_T::T_gr_curve, PCB_KEYS_T::T_gr_line, PCB_KEYS_T::T_gr_poly, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_pts, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_start, PCB_KEYS_T::T_status, PCB_KEYS_T::T_tstamp, PCB_KEYS_T::T_width, wxPoint::x, and wxPoint::y.

1336 {
1337  wxCHECK_MSG( CurTok() == T_gr_arc || CurTok() == T_gr_circle || CurTok() == T_gr_curve ||
1338  CurTok() == T_gr_line || CurTok() == T_gr_poly, NULL,
1339  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DRAWSEGMENT." ) );
1340 
1341  T token;
1342  wxPoint pt;
1343  std::unique_ptr< DRAWSEGMENT > segment( new DRAWSEGMENT( NULL ) );
1344 
1345  switch( CurTok() )
1346  {
1347  case T_gr_arc:
1348  segment->SetShape( S_ARC );
1349  NeedLEFT();
1350  token = NextTok();
1351 
1352  if( token != T_start )
1353  Expecting( T_start );
1354 
1355  pt.x = parseBoardUnits( "X coordinate" );
1356  pt.y = parseBoardUnits( "Y coordinate" );
1357  segment->SetStart( pt );
1358  NeedRIGHT();
1359  NeedLEFT();
1360  token = NextTok();
1361 
1362  if( token != T_end )
1363  Expecting( T_end );
1364 
1365  pt.x = parseBoardUnits( "X coordinate" );
1366  pt.y = parseBoardUnits( "Y coordinate" );
1367  segment->SetEnd( pt );
1368  NeedRIGHT();
1369  break;
1370 
1371  case T_gr_circle:
1372  segment->SetShape( S_CIRCLE );
1373  NeedLEFT();
1374  token = NextTok();
1375 
1376  if( token != T_center )
1377  Expecting( T_center );
1378 
1379  pt.x = parseBoardUnits( "X coordinate" );
1380  pt.y = parseBoardUnits( "Y coordinate" );
1381  segment->SetStart( pt );
1382  NeedRIGHT();
1383  NeedLEFT();
1384 
1385  token = NextTok();
1386 
1387  if( token != T_end )
1388  Expecting( T_end );
1389 
1390  pt.x = parseBoardUnits( "X coordinate" );
1391  pt.y = parseBoardUnits( "Y coordinate" );
1392  segment->SetEnd( pt );
1393  NeedRIGHT();
1394  break;
1395 
1396  case T_gr_curve:
1397  segment->SetShape( S_CURVE );
1398  NeedLEFT();
1399  token = NextTok();
1400 
1401  if( token != T_pts )
1402  Expecting( T_pts );
1403 
1404  segment->SetStart( parseXY() );
1405  segment->SetBezControl1( parseXY() );
1406  segment->SetBezControl2( parseXY() );
1407  segment->SetEnd( parseXY() );
1408  NeedRIGHT();
1409  break;
1410 
1411  case T_gr_line:
1412  // Default DRAWSEGMENT type is S_SEGMENT.
1413  NeedLEFT();
1414  token = NextTok();
1415 
1416  if( token != T_start )
1417  Expecting( T_start );
1418 
1419  pt.x = parseBoardUnits( "X coordinate" );
1420  pt.y = parseBoardUnits( "Y coordinate" );
1421  segment->SetStart( pt );
1422  NeedRIGHT();
1423  NeedLEFT();
1424  token = NextTok();
1425 
1426  if( token != T_end )
1427  Expecting( T_end );
1428 
1429  pt.x = parseBoardUnits( "X coordinate" );
1430  pt.y = parseBoardUnits( "Y coordinate" );
1431  segment->SetEnd( pt );
1432  NeedRIGHT();
1433  break;
1434 
1435  case T_gr_poly:
1436  {
1437  segment->SetShape( S_POLYGON );
1438  NeedLEFT();
1439  token = NextTok();
1440 
1441  if( token != T_pts )
1442  Expecting( T_pts );
1443 
1444  std::vector< wxPoint > pts;
1445 
1446  while( (token = NextTok()) != T_RIGHT )
1447  pts.push_back( parseXY() );
1448 
1449  segment->SetPolyPoints( pts );
1450  }
1451  break;
1452 
1453  default:
1454  Expecting( "gr_arc, gr_circle, gr_curve, gr_line, or gr_poly" );
1455  }
1456 
1457  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1458  {
1459  if( token != T_LEFT )
1460  Expecting( T_LEFT );
1461 
1462  token = NextTok();
1463 
1464  switch( token )
1465  {
1466  case T_angle:
1467  segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
1468  break;
1469 
1470  case T_layer:
1471  segment->SetLayer( parseBoardItemLayer() );
1472  break;
1473 
1474  case T_width:
1475  segment->SetWidth( parseBoardUnits( T_width ) );
1476  break;
1477 
1478  case T_tstamp:
1479  segment->SetTimeStamp( parseHex() );
1480  break;
1481 
1482  case T_status:
1483  segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
1484  break;
1485 
1486  default:
1487  Expecting( "layer, width, tstamp, or status" );
1488  }
1489 
1490  NeedRIGHT();
1491  }
1492 
1493  return segment.release();
1494 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
polygon (not yet used for tracks, but could be in microwave apps)
wxPoint parseXY()
Function parseXY parses a coordinate pair (xy X Y) in board units (mm).
Definition: pcb_parser.cpp:206
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void NeedLEFT()
Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:393
Arcs (with rounded ends)
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:958
Bezier Curve.
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
long parseHex()
Definition: pcb_parser.h:265
void PCB_PARSER::parseEDA_TEXT ( EDA_TEXT aText)
private

Function parseEDA_TEXT parses the common settings for any object derived from EDA_TEXT.

Exceptions
PARSE_ERRORif the text syntax is not valid.
Parameters
aTextA point to the EDA_TEXT object to save the parsed settings into.

Definition at line 238 of file pcb_parser.cpp.

References GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::SetBold(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), EDA_TEXT::SetMirrored(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetThickness(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), PCB_KEYS_T::T_bold, PCB_KEYS_T::T_bottom, PCB_KEYS_T::T_effects, PCB_KEYS_T::T_font, PCB_KEYS_T::T_hide, PCB_KEYS_T::T_italic, PCB_KEYS_T::T_justify, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_left, PCB_KEYS_T::T_mirror, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_right, PCB_KEYS_T::T_size, PCB_KEYS_T::T_thickness, and PCB_KEYS_T::T_top.

239 {
240  wxCHECK_RET( CurTok() == T_effects,
241  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDA_TEXT." ) );
242 
243  T token;
244 
245  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
246  {
247  if( token == T_LEFT )
248  token = NextTok();
249 
250  switch( token )
251  {
252  case T_font:
253  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
254  {
255  if( token == T_LEFT )
256  continue;
257 
258  switch( token )
259  {
260  case T_size:
261  {
262  wxSize sz;
263  sz.SetHeight( parseBoardUnits( "text height" ) );
264  sz.SetWidth( parseBoardUnits( "text width" ) );
265  aText->SetTextSize( sz );
266  NeedRIGHT();
267  }
268  break;
269 
270  case T_thickness:
271  aText->SetThickness( parseBoardUnits( "text thickness" ) );
272  NeedRIGHT();
273  break;
274 
275  case T_bold:
276  aText->SetBold( true );
277  break;
278 
279  case T_italic:
280  aText->SetItalic( true );
281  break;
282 
283  default:
284  Expecting( "size, bold, or italic" );
285  }
286  }
287  break;
288 
289  case T_justify:
290  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
291  {
292  if( token == T_LEFT )
293  continue;
294 
295  switch( token )
296  {
297  case T_left:
299  break;
300 
301  case T_right:
303  break;
304 
305  case T_top:
307  break;
308 
309  case T_bottom:
311  break;
312 
313  case T_mirror:
314  aText->SetMirrored( true );
315  break;
316 
317  default:
318  Expecting( "left, right, top, bottom, or mirror" );
319  }
320 
321  }
322  break;
323 
324  case T_hide:
325  aText->SetVisible( false );
326  break;
327 
328  default:
329  Expecting( "font, justify, or hide" );
330  }
331  }
332 }
void SetMirrored(bool isMirrored)
Definition: eda_text.h:178
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
void SetItalic(bool isItalic)
Definition: eda_text.h:169
void SetVisible(bool aVisible)
Definition: eda_text.h:175
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:194
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
void SetBold(bool aBold)
Definition: eda_text.h:172
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
EDGE_MODULE * PCB_PARSER::parseEDGE_MODULE ( )
private

Definition at line 2069 of file pcb_parser.cpp.

References parseDouble(), parseHex(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, PCB_KEYS_T::T_angle, PCB_KEYS_T::T_center, PCB_KEYS_T::T_end, PCB_KEYS_T::T_fp_arc, PCB_KEYS_T::T_fp_circle, PCB_KEYS_T::T_fp_curve, PCB_KEYS_T::T_fp_line, PCB_KEYS_T::T_fp_poly, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_pts, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_start, PCB_KEYS_T::T_status, PCB_KEYS_T::T_tstamp, PCB_KEYS_T::T_width, wxPoint::x, and wxPoint::y.

2070 {
2071  wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve ||
2072  CurTok() == T_fp_line || CurTok() == T_fp_poly, NULL,
2073  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDGE_MODULE." ) );
2074 
2075  wxPoint pt;
2076  T token;
2077 
2078  std::unique_ptr< EDGE_MODULE > segment( new EDGE_MODULE( NULL ) );
2079 
2080  switch( CurTok() )
2081  {
2082  case T_fp_arc:
2083  segment->SetShape( S_ARC );
2084  NeedLEFT();
2085  token = NextTok();
2086 
2087  if( token != T_start )
2088  Expecting( T_start );
2089 
2090  pt.x = parseBoardUnits( "X coordinate" );
2091  pt.y = parseBoardUnits( "Y coordinate" );
2092  segment->SetStart0( pt );
2093  NeedRIGHT();
2094  NeedLEFT();
2095  token = NextTok();
2096 
2097  if( token != T_end )
2098  Expecting( T_end );
2099 
2100  pt.x = parseBoardUnits( "X coordinate" );
2101  pt.y = parseBoardUnits( "Y coordinate" );
2102  segment->SetEnd0( pt );
2103  NeedRIGHT();
2104  NeedLEFT();
2105  token = NextTok();
2106 
2107  if( token != T_angle )
2108  Expecting( T_angle );
2109 
2110  segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
2111  NeedRIGHT();
2112  break;
2113 
2114  case T_fp_circle:
2115  segment->SetShape( S_CIRCLE );
2116  NeedLEFT();
2117  token = NextTok();
2118 
2119  if( token != T_center )
2120  Expecting( T_center );
2121 
2122  pt.x = parseBoardUnits( "X coordinate" );
2123  pt.y = parseBoardUnits( "Y coordinate" );
2124  segment->SetStart0( pt );
2125  NeedRIGHT();
2126  NeedLEFT();
2127  token = NextTok();
2128 
2129  if( token != T_end )
2130  Expecting( T_end );
2131 
2132  pt.x = parseBoardUnits( "X coordinate" );
2133  pt.y = parseBoardUnits( "Y coordinate" );
2134  segment->SetEnd0( pt );
2135  NeedRIGHT();
2136  break;
2137 
2138  case T_fp_curve:
2139  segment->SetShape( S_CURVE );
2140  NeedLEFT();
2141  token = NextTok();
2142 
2143  if( token != T_pts )
2144  Expecting( T_pts );
2145 
2146  segment->SetStart0( parseXY() );
2147  segment->SetBezControl1( parseXY() );
2148  segment->SetBezControl2( parseXY() );
2149  segment->SetEnd0( parseXY() );
2150  NeedRIGHT();
2151  break;
2152 
2153  case T_fp_line:
2154  // Default DRAWSEGMENT type is S_SEGMENT.
2155  NeedLEFT();
2156  token = NextTok();
2157 
2158  if( token != T_start )
2159  Expecting( T_start );
2160 
2161  pt.x = parseBoardUnits( "X coordinate" );
2162  pt.y = parseBoardUnits( "Y coordinate" );
2163  segment->SetStart0( pt );
2164 
2165  NeedRIGHT();
2166  NeedLEFT();
2167  token = NextTok();
2168 
2169  if( token != T_end )
2170  Expecting( T_end );
2171 
2172  pt.x = parseBoardUnits( "X coordinate" );
2173  pt.y = parseBoardUnits( "Y coordinate" );
2174  segment->SetEnd0( pt );
2175  NeedRIGHT();
2176  break;
2177 
2178  case T_fp_poly:
2179  {
2180  segment->SetShape( S_POLYGON );
2181  NeedLEFT();
2182  token = NextTok();
2183 
2184  if( token != T_pts )
2185  Expecting( T_pts );
2186 
2187  std::vector< wxPoint > pts;
2188 
2189  while( (token = NextTok()) != T_RIGHT )
2190  pts.push_back( parseXY() );
2191 
2192  segment->SetPolyPoints( pts );
2193  }
2194  break;
2195 
2196  default:
2197  Expecting( "fp_arc, fp_circle, fp_curve, fp_line, or fp_poly" );
2198  }
2199 
2200  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2201  {
2202  if( token != T_LEFT )
2203  Expecting( T_LEFT );
2204 
2205  token = NextTok();
2206 
2207  switch( token )
2208  {
2209  case T_layer:
2210  segment->SetLayer( parseBoardItemLayer() );
2211  break;
2212 
2213  case T_width:
2214  segment->SetWidth( parseBoardUnits( T_width ) );
2215  break;
2216 
2217  case T_tstamp:
2218  segment->SetTimeStamp( parseHex() );
2219  break;
2220 
2221  case T_status:
2222  segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
2223  break;
2224 
2225  default:
2226  Expecting( "layer or width" );
2227  }
2228 
2229  NeedRIGHT();
2230  }
2231 
2232  return segment.release();
2233 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
polygon (not yet used for tracks, but could be in microwave apps)
wxPoint parseXY()
Function parseXY parses a coordinate pair (xy X Y) in board units (mm).
Definition: pcb_parser.cpp:206
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void NeedLEFT()
Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:393
Arcs (with rounded ends)
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:958
Bezier Curve.
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
long parseHex()
Definition: pcb_parser.h:265
void PCB_PARSER::parseGeneralSection ( )
private

Definition at line 586 of file pcb_parser.cpp.

References parseInt(), PCB_KEYS_T::T_general, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_nets, PCB_KEYS_T::T_no_connects, PCB_KEYS_T::T_NUMBER, PCB_KEYS_T::T_RIGHT, and PCB_KEYS_T::T_thickness.

587 {
588  wxCHECK_RET( CurTok() == T_general,
589  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
590  wxT( " as a general section." ) );
591 
592  T token;
593 
594  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
595  {
596  if( token != T_LEFT )
597  Expecting( T_LEFT );
598 
599  token = NextTok();
600 
601  switch( token )
602  {
603  case T_thickness:
605  NeedRIGHT();
606  break;
607 
608  case T_nets:
609  m_netCodes.resize( parseInt( "nets number" ) );
610  NeedRIGHT();
611  break;
612 
613  case T_no_connects:
614  m_board->SetUnconnectedNetCount( parseInt( "no connect count" ) );
615  NeedRIGHT();
616  break;
617 
618  default: // Skip everything but the board thickness.
619  //wxLogDebug( wxT( "Skipping general section token %s " ), GetChars( GetTokenString( token ) ) );
620 
621  while( ( token = NextTok() ) != T_RIGHT )
622  {
623  if( !IsSymbol( token ) && token != T_NUMBER )
624  Expecting( "symbol or number" );
625  }
626  }
627  }
628 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
void SetUnconnectedNetCount(unsigned aCount)
Function SetUnconnectedNetCount sets the number of unconnected nets in the current rats nest to aCoun...
Definition: class_board.h:733
void SetBoardThickness(int aThickness)
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
static bool IsSymbol(int aTok)
Function IsSymbol tests a token to see if it is a symbol.
Definition: dsnlexer.cpp:344
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:528
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
std::vector< int > m_netCodes
net codes mapping for boards being loaded
Definition: pcb_parser.h:74
BOARD * m_board
Definition: pcb_parser.h:71
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
int parseInt()
Definition: pcb_parser.h:254
void PCB_PARSER::parseHeader ( )
private

Definition at line 550 of file pcb_parser.cpp.

References parseInt(), SEXPR_BOARD_FILE_VERSION, PCB_KEYS_T::T_kicad_pcb, and PCB_KEYS_T::T_version.

551 {
552  wxCHECK_RET( CurTok() == T_kicad_pcb,
553  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a header." ) );
554 
555  NeedLEFT();
556 
557  T tok = NextTok();
558  if( tok == T_version )
559  {
560  m_requiredVersion = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
562  NeedRIGHT();
563 
564  // Skip the host name and host build version information.
565  NeedLEFT();
566  NeedSYMBOL();
567  NeedSYMBOL();
568  NeedSYMBOL();
569  NeedRIGHT();
570  }
571  else
572  {
575 
576  // Skip the host name and host build version information.
577  NeedSYMBOL();
578  NeedSYMBOL();
579  NeedRIGHT();
580  }
581 
583 }
void SetFileFormatVersionAtLoad(int aVersion)
Definition: class_board.h:271
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void NeedLEFT()
Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:393
PCB_KEYS_T::T NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: pcb_lexer.h:315
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:76
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
BOARD * m_board
Definition: pcb_parser.h:71
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
int parseInt()
Definition: pcb_parser.h:254
long PCB_PARSER::parseHex ( )
inlineprivate

Definition at line 265 of file pcb_parser.h.

References DSNLEXER::CurText(), and PCB_LEXER::NextTok().

266  {
267  NextTok();
268  return strtol( CurText(), NULL, 16 );
269  }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
int PCB_PARSER::parseInt ( )
inlineprivate

Definition at line 254 of file pcb_parser.h.

References DSNLEXER::CurText().

Referenced by parseInt().

255  {
256  return (int)strtol( CurText(), NULL, 10 );
257  }
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
int PCB_PARSER::parseInt ( const char *  aExpected)
inlineprivate

Definition at line 259 of file pcb_parser.h.

References DSNLEXER::NeedNUMBER(), and parseInt().

260  {
261  NeedNUMBER( aExpected );
262  return parseInt();
263  }
int NeedNUMBER(const char *aExpectation)
Function NeedNUMBER calls NextTok() and then verifies that the token read is type DSN_NUMBER...
Definition: dsnlexer.cpp:427
int parseInt()
Definition: pcb_parser.h:254
void PCB_PARSER::parseLayer ( LAYER aLayer)
private

Definition at line 770 of file pcb_parser.cpp.

References LAYER::clear(), FROM_UTF8(), LAYER::m_name, LAYER::m_number, LAYER::m_type, LAYER::m_visible, name, parseInt(), LAYER::ParseType(), PCB_KEYS_T::T_hide, PCB_KEYS_T::T_LEFT, and PCB_KEYS_T::T_RIGHT.

771 {
772  T token;
773 
774  std::string name;
775  std::string type;
776  bool isVisible = true;
777 
778  aLayer->clear();
779 
780  if( CurTok() != T_LEFT )
781  Expecting( T_LEFT );
782 
783  // this layer_num is not used, we DO depend on LAYER_T however.
784  LAYER_NUM layer_num = parseInt( "layer index" );
785 
787  name = CurText();
788 
789  NeedSYMBOL();
790  type = CurText();
791 
792  token = NextTok();
793 
794  if( token == T_hide )
795  {
796  isVisible = false;
797  NeedRIGHT();
798  }
799  else if( token != T_RIGHT )
800  {
801  Expecting( "hide or )" );
802  }
803 
804  aLayer->m_name = FROM_UTF8( name.c_str() );
805  aLayer->m_type = LAYER::ParseType( type.c_str() );
806  aLayer->m_number = layer_num;
807  aLayer->m_visible = isVisible;
808 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
wxString m_name
The name of the layer, there should be no spaces in this name.
Definition: class_board.h:108
LAYER_T m_type
The type of the layer.
Definition: class_board.h:110
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
PCB_KEYS_T::T NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: pcb_lexer.h:315
bool m_visible
Definition: class_board.h:112
static LAYER_T ParseType(const char *aType)
Function ParseType converts a string to a LAYER_T.
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void clear()
Definition: class_board.h:89
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
const char * name
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
int m_number
Definition: class_board.h:114
int parseInt()
Definition: pcb_parser.h:254
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void PCB_PARSER::parseLayers ( )
private

Definition at line 812 of file pcb_parser.cpp.

References B_Cu, cu, Format(), GetChars(), LT_UNDEFINED, LAYER::m_name, LAYER::m_number, LAYER::m_type, LAYER::m_visible, name, PCB_KEYS_T::T_layers, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_RIGHT, THROW_IO_ERROR, and THROW_PARSE_ERROR.

813 {
814  wxCHECK_RET( CurTok() == T_layers,
815  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layers." ) );
816 
817  T token;
818  LSET visibleLayers;
819  LSET enabledLayers;
820  int copperLayerCount = 0;
821  LAYER layer;
822 
823  std::vector<LAYER> cu;
824 
825  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
826  {
827  parseLayer( &layer );
828 
829  if( layer.m_type == LT_UNDEFINED ) // it's a non-copper layer
830  break;
831 
832  cu.push_back( layer ); // it's copper
833  }
834 
835  // All Cu layers are parsed, but not the non-cu layers here.
836 
837  // The original *.kicad_pcb file format and the inverted
838  // Cu stack format both have all the Cu layers first, so use this
839  // trick to handle either. The layer number in the (layers ..)
840  // s-expression element are ignored.
841  if( cu.size() )
842  {
843  // Rework the layer numbers, which changed when the Cu stack
844  // was flipped. So we instead use position in the list.
845  cu[cu.size()-1].m_number = B_Cu;
846 
847  for( unsigned i=0; i < cu.size()-1; ++i )
848  {
849  cu[i].m_number = i;
850  }
851 
852  for( std::vector<LAYER>::const_iterator it = cu.begin(); it<cu.end(); ++it )
853  {
854  enabledLayers.set( it->m_number );
855 
856  if( it->m_visible )
857  visibleLayers.set( it->m_number );
858 
859  m_board->SetLayerDescr( PCB_LAYER_ID( it->m_number ), *it );
860 
861  UTF8 name = it->m_name;
862 
863  m_layerIndices[ name ] = PCB_LAYER_ID( it->m_number );
864  m_layerMasks[ name ] = LSET( PCB_LAYER_ID( it->m_number ) );
865  }
866 
867  copperLayerCount = cu.size();
868  }
869 
870  // process non-copper layers
871  while( token != T_RIGHT )
872  {
873  LAYER_ID_MAP::const_iterator it = m_layerIndices.find( UTF8( layer.m_name ) );
874 
875  if( it == m_layerIndices.end() )
876  {
877  wxString error = wxString::Format(
878  _( "Layer '%s' in file '%s' at line %d, is not in fixed layer hash" ),
879  GetChars( layer.m_name ),
880  GetChars( CurSource() ),
881  CurLineNumber(),
882  CurOffset()
883  );
884 
885  THROW_IO_ERROR( error );
886  }
887 
888  layer.m_number = it->second;
889 
890  enabledLayers.set( layer.m_number );
891 
892  if( layer.m_visible )
893  visibleLayers.set( layer.m_number );
894 
895  // DBG( printf( "aux m_visible:%s\n", layer.m_visible ? "true" : "false" );)
896 
897  m_board->SetLayerDescr( it->second, layer );
898 
899  token = NextTok();
900 
901  if( token != T_LEFT )
902  break;
903 
904  parseLayer( &layer );
905  }
906 
907  // We need at least 2 copper layers and there must be an even number of them.
908  if( copperLayerCount < 2 || (copperLayerCount % 2) != 0 )
909  {
910  wxString err = wxString::Format(
911  _( "%d is not a valid layer count" ), copperLayerCount );
912 
914  }
915 
916  m_board->SetCopperLayerCount( copperLayerCount );
917  m_board->SetEnabledLayers( enabledLayers );
918 
919  // call SetEnabledLayers before SetVisibleLayers()
920  m_board->SetVisibleLayers( visibleLayers );
921 }
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
wxString m_name
The name of the layer, there should be no spaces in this name.
Definition: class_board.h:108
LAYER_T m_type
The type of the layer.
Definition: class_board.h:110
void SetCopperLayerCount(int aCount)
#define cu(a)
Definition: auxiliary.h:88
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
bool SetLayerDescr(PCB_LAYER_ID aIndex, const LAYER &aLayer)
Function SetLayerDescr returns the type of the copper layer given by aLayer.
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
bool m_visible
Definition: class_board.h:112
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
void parseLayer(LAYER *aLayer)
Definition: pcb_parser.cpp:770
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class LAYER holds information pertinent to a layer of a BOARD.
Definition: class_board.h:82
BOARD * m_board
Definition: pcb_parser.h:71
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
const char * name
LAYER_ID_MAP m_layerIndices
map layer name to it's index
Definition: pcb_parser.h:72
int m_number
Definition: class_board.h:114
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...
LSET_MAP m_layerMasks
map layer names to their masks
Definition: pcb_parser.h:73
MODULE * PCB_PARSER::parseMODULE ( wxArrayString *  aInitialComments = 0)
private

Function parseMODULE.

Parameters
aInitialCommentsmay be a pointer to a heap allocated initial comment block or NULL. If not NULL, then caller has given ownership of a wxArrayString to this function and care must be taken to delete it even on exception.

Definition at line 1717 of file pcb_parser.cpp.

1718 {
1719  try
1720  {
1721  return parseMODULE_unchecked( aInitialComments );
1722  }
1723  catch( const PARSE_ERROR& parse_error )
1724  {
1725  if( m_tooRecent )
1726  throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
1727  else
1728  throw;
1729  }
1730 }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75
wxString GetRequiredVersion()
Return a string representing the version of kicad required to open this file.
Definition: pcb_parser.cpp:182
MODULE * parseMODULE_unchecked(wxArrayString *aInitialComments=0)
Function parseMODULE_unchecked Parse a module, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERRO...
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
MODULE * PCB_PARSER::parseMODULE_unchecked ( wxArrayString *  aInitialComments = 0)
private

Function parseMODULE_unchecked Parse a module, but do not replace PARSE_ERROR with FUTURE_FORMAT_ERROR automatically.

Definition at line 1733 of file pcb_parser.cpp.

References ADD_APPEND, B_Cu, F_Cu, GetChars(), D_PAD::GetPos0(), EDA_TEXT::GetTextAngle(), TEXTE_MODULE::GetType(), max, MOD_CMS, MOD_VIRTUAL, name, LIB_ID::Parse(), parseDouble(), parseHex(), parseInt(), RotatePoint(), EDGE_MODULE::SetDrawCoord(), TEXTE_MODULE::SetDrawCoord(), EDA_ITEM::SetParent(), D_PAD::SetPosition(), TEXTE_MODULE::SetTextAngle(), SEXPR_BOARD_FILE_VERSION, PCB_KEYS_T::T_at, PCB_KEYS_T::T_attr, PCB_KEYS_T::T_autoplace_cost180, PCB_KEYS_T::T_autoplace_cost90, PCB_KEYS_T::T_clearance, PCB_KEYS_T::T_descr, PCB_KEYS_T::T_fp_arc, PCB_KEYS_T::T_fp_circle, PCB_KEYS_T::T_fp_curve, PCB_KEYS_T::T_fp_line, PCB_KEYS_T::T_fp_poly, PCB_KEYS_T::T_fp_text, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_locked, PCB_KEYS_T::T_model, PCB_KEYS_T::T_module, PCB_KEYS_T::T_NUMBER, PCB_KEYS_T::T_pad, PCB_KEYS_T::T_path, PCB_KEYS_T::T_placed, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_smd, PCB_KEYS_T::T_solder_mask_margin, PCB_KEYS_T::T_solder_paste_margin, PCB_KEYS_T::T_solder_paste_ratio, PCB_KEYS_T::T_tags, PCB_KEYS_T::T_tedit, PCB_KEYS_T::T_thermal_gap, PCB_KEYS_T::T_thermal_width, PCB_KEYS_T::T_tstamp, PCB_KEYS_T::T_version, PCB_KEYS_T::T_virtual, PCB_KEYS_T::T_zone_connect, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, THROW_IO_ERROR, TO_UTF8, wxPoint::x, and wxPoint::y.

1734 {
1735  wxCHECK_MSG( CurTok() == T_module, NULL,
1736  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as MODULE." ) );
1737 
1738  wxString name;
1739  wxPoint pt;
1740  T token;
1741  LIB_ID fpid;
1742 
1743  std::unique_ptr<MODULE> module( new MODULE( m_board ) );
1744 
1745  module->SetInitialComments( aInitialComments );
1746 
1747  token = NextTok();
1748 
1749  if( !IsSymbol( token ) && token != T_NUMBER )
1750  Expecting( "symbol|number" );
1751 
1752  name = FromUTF8();
1753 
1754  if( !name.IsEmpty() && fpid.Parse( TO_UTF8( FromUTF8() ) ) >= 0 )
1755  {
1756  wxString error;
1757  error.Printf( _( "invalid footprint ID in\nfile: <%s>\nline: %d\noffset: %d" ),
1759  THROW_IO_ERROR( error );
1760  }
1761 
1762  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1763  {
1764  if( token == T_LEFT )
1765  token = NextTok();
1766 
1767  switch( token )
1768  {
1769  case T_version:
1770  {
1771  // Theoretically a module nested in a PCB could declare its own version, though
1772  // as of writing this comment we don't do that. Just in case, take the greater
1773  // version.
1774  int this_version = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
1775  NeedRIGHT();
1776  m_requiredVersion = std::max( m_requiredVersion, this_version );
1778  break;
1779  }
1780 
1781  case T_locked:
1782  module->SetLocked( true );
1783  break;
1784 
1785  case T_placed:
1786  module->SetIsPlaced( true );
1787  break;
1788 
1789  case T_layer:
1790  {
1791  // Footprints can be only on the front side or the back side.
1792  // but because we can find some stupid layer in file, ensure a
1793  // acceptable layer is set for the footprint
1795  module->SetLayer( layer == B_Cu ? B_Cu : F_Cu );
1796  }
1797  NeedRIGHT();
1798  break;
1799 
1800  case T_tedit:
1801  module->SetLastEditTime( parseHex() );
1802  NeedRIGHT();
1803  break;
1804 
1805  case T_tstamp:
1806  module->SetTimeStamp( parseHex() );
1807  NeedRIGHT();
1808  break;
1809 
1810  case T_at:
1811  pt.x = parseBoardUnits( "X coordinate" );
1812  pt.y = parseBoardUnits( "Y coordinate" );
1813  module->SetPosition( pt );
1814  token = NextTok();
1815 
1816  if( token == T_NUMBER )
1817  {
1818  module->SetOrientation( parseDouble() * 10.0 );
1819  NeedRIGHT();
1820  }
1821  else if( token != T_RIGHT )
1822  {
1823  Expecting( T_RIGHT );
1824  }
1825 
1826  break;
1827 
1828  case T_descr:
1829  NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
1830  module->SetDescription( FromUTF8() );
1831  NeedRIGHT();
1832  break;
1833 
1834  case T_tags:
1835  NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
1836  module->SetKeywords( FromUTF8() );
1837  NeedRIGHT();
1838  break;
1839 
1840  case T_path:
1841  NeedSYMBOLorNUMBER(); // Paths can be numerical so a number is also a symbol here
1842  module->SetPath( FromUTF8() );
1843  NeedRIGHT();
1844  break;
1845 
1846  case T_autoplace_cost90:
1847  module->SetPlacementCost90( parseInt( "auto place cost at 90 degrees" ) );
1848  NeedRIGHT();
1849  break;
1850 
1851  case T_autoplace_cost180:
1852  module->SetPlacementCost180( parseInt( "auto place cost at 180 degrees" ) );
1853  NeedRIGHT();
1854  break;
1855 
1856  case T_solder_mask_margin:
1857  module->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin value" ) );
1858  NeedRIGHT();
1859  break;
1860 
1861  case T_solder_paste_margin:
1862  module->SetLocalSolderPasteMargin(
1863  parseBoardUnits( "local solder paste margin value" ) );
1864  NeedRIGHT();
1865  break;
1866 
1867  case T_solder_paste_ratio:
1868  module->SetLocalSolderPasteMarginRatio(
1869  parseDouble( "local solder paste margin ratio value" ) );
1870  NeedRIGHT();
1871  break;
1872 
1873  case T_clearance:
1874  module->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
1875  NeedRIGHT();
1876  break;
1877 
1878  case T_zone_connect:
1879  module->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
1880  NeedRIGHT();
1881  break;
1882 
1883  case T_thermal_width:
1884  module->SetThermalWidth( parseBoardUnits( "thermal width value" ) );
1885  NeedRIGHT();
1886  break;
1887 
1888  case T_thermal_gap:
1889  module->SetThermalGap( parseBoardUnits( "thermal gap value" ) );
1890  NeedRIGHT();
1891  break;
1892 
1893  case T_attr:
1894  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1895  {
1896  switch( token )
1897  {
1898  case T_smd:
1899  module->SetAttributes( module->GetAttributes() | MOD_CMS );
1900  break;
1901 
1902  case T_virtual:
1903  module->SetAttributes( module->GetAttributes() | MOD_VIRTUAL );
1904  break;
1905 
1906  default:
1907  Expecting( "smd and/or virtual" );
1908  }
1909  }
1910 
1911  break;
1912 
1913  case T_fp_text:
1914  {
1915  TEXTE_MODULE* text = parseTEXTE_MODULE();
1916  text->SetParent( module.get() );
1917  double orientation = text->GetTextAngle();
1918  orientation -= module->GetOrientation();
1919  text->SetTextAngle( orientation );
1920  text->SetDrawCoord();
1921 
1922  switch( text->GetType() )
1923  {
1925  module->Reference() = *text;
1926  delete text;
1927  break;
1928 
1930  module->Value() = *text;
1931  delete text;
1932  break;
1933 
1934  default:
1935  module->GraphicalItems().PushBack( text );
1936  }
1937  }
1938  break;
1939 
1940  case T_fp_arc:
1941  case T_fp_circle:
1942  case T_fp_curve:
1943  case T_fp_line:
1944  case T_fp_poly:
1945  {
1946  EDGE_MODULE* em = parseEDGE_MODULE();
1947  em->SetParent( module.get() );
1948  em->SetDrawCoord();
1949  module->GraphicalItems().PushBack( em );
1950  }
1951  break;
1952 
1953  case T_pad:
1954  {
1955  D_PAD* pad = parseD_PAD( module.get() );
1956  pt = pad->GetPos0();
1957 
1958  RotatePoint( &pt, module->GetOrientation() );
1959  pad->SetPosition( pt + module->GetPosition() );
1960  module->Add( pad, ADD_APPEND );
1961  }
1962  break;
1963 
1964  case T_model:
1965  module->Add3DModel( parse3DModel() );
1966  break;
1967 
1968  default:
1969  Expecting( "locked, placed, tedit, tstamp, at, descr, tags, path, "
1970  "autoplace_cost90, autoplace_cost180, solder_mask_margin, "
1971  "solder_paste_margin, solder_paste_ratio, clearance, "
1972  "zone_connect, thermal_width, thermal_gap, attr, fp_text, "
1973  "fp_arc, fp_circle, fp_curve, fp_line, fp_poly, pad, or model" );
1974  }
1975  }
1976 
1977  module->SetFPID( fpid );
1978  module->CalculateBoundingBox();
1979 
1980  return module.release();
1981 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
S3D_INFO * parse3DModel()
Definition: pcb_parser.cpp:335
TEXT_TYPE GetType() const
ZoneConnection
How pads are covered by copper in zone.
Definition: zones.h:55
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:76
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:169
const wxPoint & GetPos0() const
Definition: class_pad.h:176
int Parse(const UTF8 &aId)
Function Parse.
Definition: lib_id.cpp:122
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
Class LIB_ID.
Definition: lib_id.h:56
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
int parseBoardUnits()
Definition: pcb_parser.h:230
double GetTextAngle() const
Definition: eda_text.h:164
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
PCB_LAYER_ID
A quick note on layer IDs:
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
static bool IsSymbol(int aTok)
Function IsSymbol tests a token to see if it is a symbol.
Definition: dsnlexer.cpp:344
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:958
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:76
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
EDGE_MODULE * parseEDGE_MODULE()
#define max(a, b)
Definition: auxiliary.h:86
BOARD * m_board
Definition: pcb_parser.h:71
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:78
void SetDrawCoord()
Set absolute coordinates.
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
const char * name
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
void SetTextAngle(double aAngle)
TEXTE_MODULE * parseTEXTE_MODULE()
D_PAD * parseD_PAD(MODULE *aParent=NULL)
long parseHex()
Definition: pcb_parser.h:265
int parseInt()
Definition: pcb_parser.h:254
void PCB_PARSER::parseNETCLASS ( )
private

Definition at line 1252 of file pcb_parser.cpp.

References PCB_KEYS_T::T_add_net, PCB_KEYS_T::T_clearance, PCB_KEYS_T::T_diff_pair_gap, PCB_KEYS_T::T_diff_pair_width, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_net_class, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_trace_width, PCB_KEYS_T::T_uvia_dia, PCB_KEYS_T::T_uvia_drill, PCB_KEYS_T::T_via_dia, PCB_KEYS_T::T_via_drill, and THROW_IO_ERROR.

1253 {
1254  wxCHECK_RET( CurTok() == T_net_class,
1255  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net class." ) );
1256 
1257  T token;
1258 
1259  NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
1260 
1261  // Read netclass name (can be a name or just a number like track width)
1263  nc->SetName( FromUTF8() );
1264  NeedSYMBOL();
1265  nc->SetDescription( FromUTF8() );
1266 
1267  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1268  {
1269  if( token != T_LEFT )
1270  Expecting( T_LEFT );
1271 
1272  token = NextTok();
1273 
1274  switch( token )
1275  {
1276  case T_clearance:
1277  nc->SetClearance( parseBoardUnits( T_clearance ) );
1278  break;
1279 
1280  case T_trace_width:
1281  nc->SetTrackWidth( parseBoardUnits( T_trace_width ) );
1282  break;
1283 
1284  case T_via_dia:
1285  nc->SetViaDiameter( parseBoardUnits( T_via_dia ) );
1286  break;
1287 
1288  case T_via_drill:
1289  nc->SetViaDrill( parseBoardUnits( T_via_drill ) );
1290  break;
1291 
1292  case T_uvia_dia:
1293  nc->SetuViaDiameter( parseBoardUnits( T_uvia_dia ) );
1294  break;
1295 
1296  case T_uvia_drill:
1297  nc->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
1298  break;
1299 
1300  case T_diff_pair_width:
1301  nc->SetDiffPairWidth( parseBoardUnits( T_diff_pair_width ) );
1302  break;
1303 
1304  case T_diff_pair_gap:
1305  nc->SetDiffPairGap( parseBoardUnits( T_diff_pair_gap ) );
1306  break;
1307 
1308  case T_add_net:
1310  nc->Add( FromUTF8() );
1311  break;
1312 
1313  default:
1314  Expecting( "clearance, trace_width, via_dia, via_drill, uvia_dia, uvia_drill, diff_pair_width, diff_pair_gap or add_net" );
1315  }
1316 
1317  NeedRIGHT();
1318  }
1319 
1320  if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
1321  {
1322  // Must have been a name conflict, this is a bad board file.
1323  // User may have done a hand edit to the file.
1324 
1325  // unique_ptr will delete nc on this code path
1326 
1327  wxString error;
1328  error.Printf( _( "duplicate NETCLASS name '%s' in file <%s> at line %d, offset %d" ),
1329  nc->GetName().GetData(), CurSource().GetData(), CurLineNumber(), CurOffset() );
1330  THROW_IO_ERROR( error );
1331  }
1332 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
PCB_KEYS_T::T NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: pcb_lexer.h:315
bool Add(NETCLASSPTR aNetclass)
Function Add takes aNetclass and puts it into this NETCLASSES container.
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:528
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
BOARD * m_board
Definition: pcb_parser.h:71
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
void PCB_PARSER::parseNETINFO_ITEM ( )
private

Definition at line 1226 of file pcb_parser.cpp.

References NETINFO_ITEM::GetNet(), name, parseInt(), PCB_KEYS_T::T_net, and NETINFO_LIST::UNCONNECTED.

1227 {
1228  wxCHECK_RET( CurTok() == T_net,
1229  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net." ) );
1230 
1231  int netCode = parseInt( "net number" );
1232 
1234  wxString name = FromUTF8();
1235 
1236  NeedRIGHT();
1237 
1238  // net 0 should be already in list, so store this net
1239  // if it is not the net 0, or if the net 0 does not exists.
1240  // (TODO: a better test.)
1242  {
1243  NETINFO_ITEM* net = new NETINFO_ITEM( m_board, name, netCode );
1244  m_board->Add( net );
1245 
1246  // Store the new code mapping
1247  pushValueIntoMap( netCode, net->GetNet() );
1248  }
1249 }
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
int GetNet() const
Function GetNet.
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
Class NETINFO_ITEM handles the data for a net.
BOARD * m_board
Definition: pcb_parser.h:71
void pushValueIntoMap(int aIndex, int aValue)
function pushValueIntoMap Add aValue value in netcode mapping (m_netCodes) at index aIndex ensure the...
Definition: pcb_parser.cpp:113
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
const char * name
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
int parseInt()
Definition: pcb_parser.h:254
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
void PCB_PARSER::parsePAGE_INFO ( )
private

Definition at line 631 of file pcb_parser.cpp.

References PAGE_INFO::Custom, GetChars(), Mm2mils(), parseDouble(), PAGE_INFO::SetHeightMils(), PAGE_INFO::SetPortrait(), PAGE_INFO::SetType(), PAGE_INFO::SetWidthMils(), PCB_KEYS_T::T_page, PCB_KEYS_T::T_portrait, PCB_KEYS_T::T_RIGHT, and THROW_PARSE_ERROR.

632 {
633  wxCHECK_RET( CurTok() == T_page,
634  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
635 
636  T token;
637  PAGE_INFO pageInfo;
638 
639  NeedSYMBOL();
640 
641  wxString pageType = FromUTF8();
642 
643  if( !pageInfo.SetType( pageType ) )
644  {
645  wxString err;
646  err.Printf( _( "page type \"%s\" is not valid " ), GetChars( FromUTF8() ) );
648  }
649 
650  if( pageType == PAGE_INFO::Custom )
651  {
652  double width = parseDouble( "width" ); // width in mm
653 
654  // Perform some controls to avoid crashes if the size is edited by hands
655  if( width < 100.0 )
656  width = 100.0;
657  else if( width > 1200.0 )
658  width = 1200.0;
659 
660  double height = parseDouble( "height" ); // height in mm
661 
662  if( height < 100.0 )
663  height = 100.0;
664  else if( height > 1200.0 )
665  height = 1200.0;
666 
667  pageInfo.SetWidthMils( Mm2mils( width ) );
668  pageInfo.SetHeightMils( Mm2mils( height ) );
669  }
670 
671  token = NextTok();
672 
673  if( token == T_portrait )
674  {
675  pageInfo.SetPortrait( true );
676  NeedRIGHT();
677  }
678  else if( token != T_RIGHT )
679  {
680  Expecting( "portrait|)" );
681  }
682 
683  m_board->SetPageSettings( pageInfo );
684 }
int Mm2mils(double x)
Convert mm to mils.
Definition: base_units.h:41
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: class_board.h:544
static const wxChar Custom[]
"User" defined page type
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
PCB_KEYS_T::T NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: pcb_lexer.h:315
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
bool SetType(const wxString &aStandardPageDescriptionName, bool IsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
void SetPortrait(bool isPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
void SetHeightMils(int aHeightInMils)
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
BOARD * m_board
Definition: pcb_parser.h:71
void SetWidthMils(int aWidthInMils)
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
PCB_TARGET * PCB_PARSER::parsePCB_TARGET ( )
private

Definition at line 3009 of file pcb_parser.cpp.

References parseHex(), PCB_KEYS_T::T_at, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_plus, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_size, PCB_KEYS_T::T_target, PCB_KEYS_T::T_tstamp, PCB_KEYS_T::T_width, PCB_KEYS_T::T_x, wxPoint::x, and wxPoint::y.

3010 {
3011  wxCHECK_MSG( CurTok() == T_target, NULL,
3012  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TARGET." ) );
3013 
3014  wxPoint pt;
3015  T token;
3016 
3017  std::unique_ptr< PCB_TARGET > target( new PCB_TARGET( NULL ) );
3018 
3019  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
3020  {
3021  if( token == T_LEFT )
3022  token = NextTok();
3023 
3024  switch( token )
3025  {
3026  case T_x:
3027  target->SetShape( 1 );
3028  break;
3029 
3030  case T_plus:
3031  target->SetShape( 0 );
3032  break;
3033 
3034  case T_at:
3035  pt.x = parseBoardUnits( "target x position" );
3036  pt.y = parseBoardUnits( "target y position" );
3037  target->SetPosition( pt );
3038  NeedRIGHT();
3039  break;
3040 
3041  case T_size:
3042  target->SetSize( parseBoardUnits( "target size" ) );
3043  NeedRIGHT();
3044  break;
3045 
3046  case T_width:
3047  target->SetWidth( parseBoardUnits( "target thickness" ) );
3048  NeedRIGHT();
3049  break;
3050 
3051  case T_layer:
3052  target->SetLayer( parseBoardItemLayer() );
3053  NeedRIGHT();
3054  break;
3055 
3056  case T_tstamp:
3057  target->SetTimeStamp( parseHex() );
3058  NeedRIGHT();
3059  break;
3060 
3061  default:
3062  Expecting( "x, plus, at, size, width, layer or tstamp" );
3063  }
3064  }
3065 
3066  return target.release();
3067 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:958
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
long parseHex()
Definition: pcb_parser.h:265
void PCB_PARSER::parseSetup ( )
private

Definition at line 991 of file pcb_parser.cpp.

References BOARD_DESIGN_SETTINGS::m_AuxOrigin, BOARD_DESIGN_SETTINGS::m_BlindBuriedViaAllowed, BOARD_DESIGN_SETTINGS::m_DrawSegmentWidth, BOARD_DESIGN_SETTINGS::m_EdgeSegmentWidth, BOARD_DESIGN_SETTINGS::m_GridOrigin, BOARD_DESIGN_SETTINGS::m_MicroViasAllowed, BOARD_DESIGN_SETTINGS::m_MicroViasMinDrill, BOARD_DESIGN_SETTINGS::m_MicroViasMinSize, BOARD_DESIGN_SETTINGS::m_ModuleSegmentWidth, BOARD_DESIGN_SETTINGS::m_ModuleTextSize, BOARD_DESIGN_SETTINGS::m_ModuleTextWidth, BOARD_DESIGN_SETTINGS::m_Pad_Master, BOARD_DESIGN_SETTINGS::m_PcbTextSize, BOARD_DESIGN_SETTINGS::m_PcbTextWidth, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, BOARD_DESIGN_SETTINGS::m_SolderPasteMargin, BOARD_DESIGN_SETTINGS::m_SolderPasteMarginRatio, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_TrackWidthList, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, BOARD_DESIGN_SETTINGS::m_ViasMinDrill, BOARD_DESIGN_SETTINGS::m_ViasMinSize, ZONE_SETTINGS::m_Zone_45_Only, ZONE_SETTINGS::m_ZoneClearance, MIN_VISIBILITY_MASK, PCB_PLOT_PARAMS::Parse(), parseDouble(), parseHex(), D_PAD::SetDrillSize(), D_PAD::SetSize(), BOARD_DESIGN_SETTINGS::SetVisibleElements(), DSNLEXER::SyncLineReaderWith(), PCB_KEYS_T::T_aux_axis_origin, PCB_KEYS_T::T_blind_buried_vias_allowed, PCB_KEYS_T::T_edge_width, PCB_KEYS_T::T_grid_origin, PCB_KEYS_T::T_last_trace_width, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_mod_edge_width, PCB_KEYS_T::T_mod_text_size, PCB_KEYS_T::T_mod_text_width, PCB_KEYS_T::T_pad_drill, PCB_KEYS_T::T_pad_size, PCB_KEYS_T::T_pad_to_mask_clearance, PCB_KEYS_T::T_pad_to_paste_clearance, PCB_KEYS_T::T_pad_to_paste_clearance_ratio, PCB_KEYS_T::T_pcb_text_size, PCB_KEYS_T::T_pcb_text_width, PCB_KEYS_T::T_pcbplotparams, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_segment_width, PCB_KEYS_T::T_setup, PCB_KEYS_T::T_solder_mask_min_width, PCB_KEYS_T::T_trace_clearance, PCB_KEYS_T::T_trace_min, PCB_KEYS_T::T_user_trace_width, PCB_KEYS_T::T_user_via, PCB_KEYS_T::T_uvia_drill, PCB_KEYS_T::T_uvia_min_drill, PCB_KEYS_T::T_uvia_min_size, PCB_KEYS_T::T_uvia_size, PCB_KEYS_T::T_uvias_allowed, PCB_KEYS_T::T_via_drill, PCB_KEYS_T::T_via_min_drill, PCB_KEYS_T::T_via_min_size, PCB_KEYS_T::T_via_size, PCB_KEYS_T::T_visible_elements, PCB_KEYS_T::T_zone_45_only, and PCB_KEYS_T::T_zone_clearance.

992 {
993  wxCHECK_RET( CurTok() == T_setup,
994  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as setup." ) );
995 
996  T token;
997  NETCLASSPTR defaultNetClass = m_board->GetDesignSettings().GetDefault();
998  // TODO Orson: is it really necessary to first operate on a copy and then apply it?
999  // would not it be better to use reference here and apply all the changes instantly?
1000  BOARD_DESIGN_SETTINGS designSettings = m_board->GetDesignSettings();
1001  ZONE_SETTINGS zoneSettings = m_board->GetZoneSettings();
1002 
1003  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1004  {
1005  if( token != T_LEFT )
1006  Expecting( T_LEFT );
1007 
1008  token = NextTok();
1009 
1010  switch( token )
1011  {
1012  case T_last_trace_width: // not used now
1013  /* lastTraceWidth =*/ parseBoardUnits( T_last_trace_width );
1014  NeedRIGHT();
1015  break;
1016 
1017  case T_user_trace_width:
1018  designSettings.m_TrackWidthList.push_back( parseBoardUnits( T_user_trace_width ) );
1019  NeedRIGHT();
1020  break;
1021 
1022  case T_trace_clearance:
1023  defaultNetClass->SetClearance( parseBoardUnits( T_trace_clearance ) );
1024  NeedRIGHT();
1025  break;
1026 
1027  case T_zone_clearance:
1029  NeedRIGHT();
1030  break;
1031 
1032  case T_zone_45_only:
1033  zoneSettings.m_Zone_45_Only = parseBool();
1034  NeedRIGHT();
1035  break;
1036 
1037  case T_trace_min:
1038  designSettings.m_TrackMinWidth = parseBoardUnits( T_trace_min );
1039  NeedRIGHT();
1040  break;
1041 
1042  case T_segment_width:
1044  NeedRIGHT();
1045  break;
1046 
1047  case T_edge_width:
1048  designSettings.m_EdgeSegmentWidth = parseBoardUnits( T_edge_width );
1049  NeedRIGHT();
1050  break;
1051 
1052  case T_via_size:
1053  defaultNetClass->SetViaDiameter( parseBoardUnits( T_via_size ) );
1054  NeedRIGHT();
1055  break;
1056 
1057  case T_via_drill:
1058  defaultNetClass->SetViaDrill( parseBoardUnits( T_via_drill ) );
1059  NeedRIGHT();
1060  break;
1061 
1062  case T_via_min_size:
1063  designSettings.m_ViasMinSize = parseBoardUnits( T_via_min_size );
1064  NeedRIGHT();
1065  break;
1066 
1067  case T_via_min_drill:
1068  designSettings.m_ViasMinDrill = parseBoardUnits( T_via_min_drill );
1069  NeedRIGHT();
1070  break;
1071 
1072  case T_user_via:
1073  {
1074  int viaSize = parseBoardUnits( "user via size" );
1075  int viaDrill = parseBoardUnits( "user via drill" );
1076  designSettings.m_ViasDimensionsList.push_back( VIA_DIMENSION( viaSize, viaDrill ) );
1077  NeedRIGHT();
1078  }
1079  break;
1080 
1081  case T_uvia_size:
1082  defaultNetClass->SetuViaDiameter( parseBoardUnits( T_uvia_size ) );
1083  NeedRIGHT();
1084  break;
1085 
1086  case T_uvia_drill:
1087  defaultNetClass->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
1088  NeedRIGHT();
1089  break;
1090 
1091  case T_uvias_allowed:
1092  designSettings.m_MicroViasAllowed = parseBool();
1093  NeedRIGHT();
1094  break;
1095 
1097  designSettings.m_BlindBuriedViaAllowed = parseBool();
1098  NeedRIGHT();
1099  break;
1100 
1101  case T_uvia_min_size:
1103  NeedRIGHT();
1104  break;
1105 
1106  case T_uvia_min_drill:
1108  NeedRIGHT();
1109  break;
1110 
1111  case T_pcb_text_width:
1112  designSettings.m_PcbTextWidth = parseBoardUnits( T_pcb_text_width );
1113  NeedRIGHT();
1114  break;
1115 
1116  case T_pcb_text_size:
1117  designSettings.m_PcbTextSize.x = parseBoardUnits( "pcb text width" );
1118  designSettings.m_PcbTextSize.y = parseBoardUnits( "pcb text height" );
1119  NeedRIGHT();
1120  break;
1121 
1122  case T_mod_edge_width:
1124  NeedRIGHT();
1125  break;
1126 
1127  case T_mod_text_size:
1128  designSettings.m_ModuleTextSize.x = parseBoardUnits( "module text width" );
1129  designSettings.m_ModuleTextSize.y = parseBoardUnits( "module text height" );
1130  NeedRIGHT();
1131  break;
1132 
1133  case T_mod_text_width:
1135  NeedRIGHT();
1136  break;
1137 
1138  case T_pad_size:
1139  {
1140  wxSize sz;
1141  sz.SetWidth( parseBoardUnits( "master pad width" ) );
1142  sz.SetHeight( parseBoardUnits( "master pad height" ) );
1143  designSettings.m_Pad_Master.SetSize( sz );
1144  NeedRIGHT();
1145  }
1146  break;
1147 
1148  case T_pad_drill:
1149  {
1150  int drillSize = parseBoardUnits( T_pad_drill );
1151  designSettings.m_Pad_Master.SetDrillSize( wxSize( drillSize, drillSize ) );
1152  NeedRIGHT();
1153  }
1154  break;
1155 
1158  NeedRIGHT();
1159  break;
1160 
1163  NeedRIGHT();
1164  break;
1165 
1168  NeedRIGHT();
1169  break;
1170 
1173  NeedRIGHT();
1174  break;
1175 
1176  case T_aux_axis_origin:
1177  {
1178  int x = parseBoardUnits( "auxiliary origin X" );
1179  int y = parseBoardUnits( "auxiliary origin Y" );
1180  // m_board->SetAuxOrigin( wxPoint( x, y ) ); gets overwritten via SetDesignSettings below
1181  designSettings.m_AuxOrigin = wxPoint( x, y );
1182  NeedRIGHT();
1183  }
1184  break;
1185 
1186  case T_grid_origin:
1187  {
1188  int x = parseBoardUnits( "grid origin X" );
1189  int y = parseBoardUnits( "grid origin Y" );
1190  // m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten SetDesignSettings below
1191  designSettings.m_GridOrigin = wxPoint( x, y );
1192  NeedRIGHT();
1193  }
1194  break;
1195 
1196  case T_visible_elements:
1197  designSettings.SetVisibleElements( parseHex() | MIN_VISIBILITY_MASK );
1198  NeedRIGHT();
1199  break;
1200 
1201  case T_pcbplotparams:
1202  {
1203  PCB_PLOT_PARAMS plotParams;
1204  PCB_PLOT_PARAMS_PARSER parser( reader );
1205  // parser must share the same current line as our current PCB parser
1206  // synchronize it.
1207  parser.SyncLineReaderWith( *this );
1208 
1209  plotParams.Parse( &parser );
1210  SyncLineReaderWith( parser );
1211 
1212  m_board->SetPlotOptions( plotParams );
1213  }
1214  break;
1215 
1216  default:
1217  Unexpected( CurText() );
1218  }
1219  }
1220 
1221  m_board->SetDesignSettings( designSettings );
1222  m_board->SetZoneSettings( zoneSettings );
1223 }
int m_SolderMaskMargin
Solder mask margin.
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
Struct VIA_DIMENSION is a small helper container to handle a stock of specific vias each with unique ...
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
Definition: class_board.h:553
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:552
NETCLASSPTR GetDefault() const
Function GetDefault.
wxPoint m_GridOrigin
origin for grid offsets
int m_SolderPasteMargin
Solder paste margin absolute value.
Class PCB_PLOT_PARAMS_PARSER is the parser class for PCB_PLOT_PARAMS.
int m_ModuleTextWidth
Default footprint texts thickness.
std::vector< int > m_TrackWidthList
Track width list.
int m_ModuleSegmentWidth
Default width for all graphic lines.
int m_PcbTextWidth
current Pcb (not module) Text width
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:369
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:187
wxSize m_ModuleTextSize
Default footprint texts size.
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
bool parseBool()
Definition: pcb_parser.cpp:154
#define MIN_VISIBILITY_MASK
wxSize m_PcbTextSize
current Pcb (not module) Text size
int m_TrackMinWidth
track min value for width ((min copper size value
int m_ViasMinSize
vias (not micro vias) min diameter
int m_DrawSegmentWidth
current graphic line width (not EDGE layer)
int m_ViasMinDrill
vias (not micro vias) min drill diameter
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:528
void SetSize(const wxSize &aSize)
Definition: class_pad.h:181
int m_ZoneClearance
Clearance value.
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:538
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition: class_board.h:547
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int m_MicroViasMinSize
micro vias (not vias) min diameter
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board...
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
Class ZONE_SETTINGS handles zones parameters.
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
bool SyncLineReaderWith(DSNLEXER &aLexer)
Useable only for DSN lexers which share the same LINE_READER Synchronizes the pointers handling the d...
Definition: dsnlexer.cpp:169
BOARD * m_board
Definition: pcb_parser.h:71
D_PAD m_Pad_Master
A dummy pad to store all default parameters.
void SetVisibleElements(int aMask)
Function SetVisibleElements changes the bit-mask of visible element categories.
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
bool m_MicroViasAllowed
true to allow micro vias
int m_MicroViasMinDrill
micro vias (not vias) min drill diameter
long parseHex()
Definition: pcb_parser.h:265
int m_EdgeSegmentWidth
current graphic line width (EDGE layer only)
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values...
void Parse(PCB_PLOT_PARAMS_PARSER *aParser)
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
wxPoint m_AuxOrigin
origin for plot exports
int m_SolderMaskMinWidth
Solder mask min width.
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
TEXTE_MODULE * PCB_PARSER::parseTEXTE_MODULE ( )
private

Definition at line 1984 of file pcb_parser.cpp.

References Format(), GetChars(), parseDouble(), PCB_KEYS_T::T_at, PCB_KEYS_T::T_effects, PCB_KEYS_T::T_fp_text, PCB_KEYS_T::T_hide, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_NUMBER, PCB_KEYS_T::T_reference, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_user, PCB_KEYS_T::T_value, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, THROW_IO_ERROR, wxPoint::x, and wxPoint::y.

1985 {
1986  wxCHECK_MSG( CurTok() == T_fp_text, NULL,
1987  wxString::Format( wxT( "Cannot parse %s as TEXTE_MODULE at line %d, offset %d." ),
1988  GetChars( GetTokenString( CurTok() ) ),
1989  CurLineNumber(), CurOffset() ) );
1990 
1991  T token = NextTok();
1992 
1993  std::unique_ptr<TEXTE_MODULE> text( new TEXTE_MODULE( NULL ) );
1994 
1995  switch( token )
1996  {
1997  case T_reference:
1998  text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
1999  break;
2000 
2001  case T_value:
2002  text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
2003  break;
2004 
2005  case T_user:
2006  break; // Default type is user text.
2007 
2008  default:
2009  THROW_IO_ERROR( wxString::Format( _( "cannot handle footprint text type %s" ),
2010  GetChars( FromUTF8() ) ) );
2011  }
2012 
2014 
2015  text->SetText( FromUTF8() );
2016  NeedLEFT();
2017  token = NextTok();
2018 
2019  if( token != T_at )
2020  Expecting( T_at );
2021 
2022  wxPoint pt;
2023 
2024  pt.x = parseBoardUnits( "X coordinate" );
2025  pt.y = parseBoardUnits( "Y coordinate" );
2026  text->SetPos0( pt );
2027  token = NextTok();
2028 
2029  // If there is no orientation defined, then it is the default value of 0 degrees.
2030  if( token == T_NUMBER )
2031  {
2032  text->SetTextAngle( parseDouble() * 10.0 );
2033  NeedRIGHT();
2034  }
2035  else if( token != T_RIGHT )
2036  {
2037  Unexpected( CurText() );
2038  }
2039 
2040  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2041  {
2042  if( token == T_LEFT )
2043  token = NextTok();
2044 
2045  switch( token )
2046  {
2047  case T_layer:
2048  text->SetLayer( parseBoardItemLayer() );
2049  NeedRIGHT();
2050  break;
2051 
2052  case T_hide:
2053  text->SetVisible( false );
2054  break;
2055 
2056  case T_effects:
2057  parseEDA_TEXT( (EDA_TEXT*) text.get() );
2058  break;
2059 
2060  default:
2061  Expecting( "hide or effects" );
2062  }
2063  }
2064 
2065  return text.release();
2066 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:302
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:369
void parseEDA_TEXT(EDA_TEXT *aText)
Function parseEDA_TEXT parses the common settings for any object derived from EDA_TEXT.
Definition: pcb_parser.cpp:238
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
int parseBoardUnits()
Definition: pcb_parser.h:230
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:337
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:114
void NeedLEFT()
Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:393
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:958
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:328
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
TEXTE_PCB * PCB_PARSER::parseTEXTE_PCB ( )
private

Definition at line 1497 of file pcb_parser.cpp.

References parseDouble(), parseHex(), PCB_KEYS_T::T_at, PCB_KEYS_T::T_effects, PCB_KEYS_T::T_gr_text, PCB_KEYS_T::T_layer, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_NUMBER, PCB_KEYS_T::T_RIGHT, PCB_KEYS_T::T_tstamp, wxPoint::x, and wxPoint::y.

1498 {
1499  wxCHECK_MSG( CurTok() == T_gr_text, NULL,
1500  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as TEXTE_PCB." ) );
1501 
1502  T token;
1503 
1504  std::unique_ptr<TEXTE_PCB> text( new TEXTE_PCB( m_board ) );
1506 
1507  text->SetText( FromUTF8() );
1508  NeedLEFT();
1509  token = NextTok();
1510 
1511  if( token != T_at )
1512  Expecting( T_at );
1513 
1514  wxPoint pt;
1515 
1516  pt.x = parseBoardUnits( "X coordinate" );
1517  pt.y = parseBoardUnits( "Y coordinate" );
1518  text->SetTextPos( pt );
1519 
1520  // If there is no orientation defined, then it is the default value of 0 degrees.
1521  token = NextTok();
1522 
1523  if( token == T_NUMBER )
1524  {
1525  text->SetTextAngle( parseDouble() * 10.0 );
1526  NeedRIGHT();
1527  }
1528  else if( token != T_RIGHT )
1529  {
1530  Unexpected( CurText() );
1531  }
1532 
1533  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1534  {
1535  if( token != T_LEFT )
1536  Expecting( T_LEFT );
1537 
1538  token = NextTok();
1539 
1540  switch( token )
1541  {
1542  case T_layer:
1543  text->SetLayer( parseBoardItemLayer() );
1544  NeedRIGHT();
1545  break;
1546 
1547  case T_tstamp:
1548  text->SetTimeStamp( parseHex() );
1549  NeedRIGHT();
1550  break;
1551 
1552  case T_effects:
1553  parseEDA_TEXT( (EDA_TEXT*) text.get() );
1554  break;
1555 
1556  default:
1557  Expecting( "layer, tstamp or effects" );