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(), 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(), 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(), 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 926 of file pcb_parser.cpp.

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

927 {
928  // avoid constructing another std::string, use lexer's directly
929  typename M::const_iterator it = aMap.find( curText );
930 
931  if( it == aMap.end() )
932  {
933 #if 0 && defined(DEBUG)
934  // dump the whole darn table, there's something wrong with it.
935  for( it = aMap.begin(); it != aMap.end(); ++it )
936  {
937  wxLogDebug( &aMap == (void*)&m_layerIndices ? wxT( "lm[%s] = %d" ) :
938  wxT( "lm[%s] = %08X" ), it->first.c_str(), it->second );
939  }
940 #endif
941 
942  wxString error = wxString::Format( _(
943  "Layer '%s' in file\n"
944  "'%s'\n"
945  "at line %d, position %d\n"
946  "was not defined in the layers section"
947  ),
948  GetChars( FROM_UTF8( CurText() ) ),
949  GetChars( CurSource() ),
950  CurLineNumber(), CurOffset() );
951 
952  THROW_IO_ERROR( error );
953  }
954 
955  return it->second;
956 }
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:169
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:688
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:813
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
void parsePAGE_INFO()
Definition: pcb_parser.cpp:632
#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:992
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 959 of file pcb_parser.cpp.

References PCB_KEYS_T::T_layer, and UNDEFINED_LAYER.

960 {
961  wxCHECK_MSG( CurTok() == T_layer, UNDEFINED_LAYER,
962  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layer." ) );
963 
964  NextTok();
965 
966  PCB_LAYER_ID layerIndex = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
967 
968  // Handle closing ) in object parser.
969 
970  return layerIndex;
971 }
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 974 of file pcb_parser.cpp.

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

975 {
976  wxCHECK_MSG( CurTok() == T_layers, LSET(),
977  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
978  wxT( " as item layer mask." ) );
979 
980  LSET layerMask;
981 
982  for( T token = NextTok(); token != T_RIGHT; token = NextTok() )
983  {
984  LSET mask = lookUpLayer<LSET>( m_layerMasks );
985  layerMask |= mask;
986  }
987 
988  return layerMask;
989 }
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 2241 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.

2242 {
2243  wxCHECK_MSG( CurTok() == T_pad, NULL,
2244  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) );
2245 
2246  wxSize sz;
2247  wxPoint pt;
2248 
2249  std::unique_ptr< D_PAD > pad( new D_PAD( aParent ) );
2250 
2252  pad->SetPadName( FromUTF8() );
2253 
2254  T token = NextTok();
2255 
2256  switch( token )
2257  {
2258  case T_thru_hole:
2259  pad->SetAttribute( PAD_ATTRIB_STANDARD );
2260  break;
2261 
2262  case T_smd:
2263  pad->SetAttribute( PAD_ATTRIB_SMD );
2264 
2265  // Default D_PAD object is thru hole with drill.
2266  // SMD pads have no hole
2267  pad->SetDrillSize( wxSize( 0, 0 ) );
2268  break;
2269 
2270  case T_connect:
2271  pad->SetAttribute( PAD_ATTRIB_CONN );
2272 
2273  // Default D_PAD object is thru hole with drill.
2274  // CONN pads have no hole
2275  pad->SetDrillSize( wxSize( 0, 0 ) );
2276  break;
2277 
2278  case T_np_thru_hole:
2279  pad->SetAttribute( PAD_ATTRIB_HOLE_NOT_PLATED );
2280  break;
2281 
2282  default:
2283  Expecting( "thru_hole, smd, connect, or np_thru_hole" );
2284  }
2285 
2286  token = NextTok();
2287 
2288  switch( token )
2289  {
2290  case T_circle:
2291  pad->SetShape( PAD_SHAPE_CIRCLE );
2292  break;
2293 
2294  case T_rect:
2295  pad->SetShape( PAD_SHAPE_RECT );
2296  break;
2297 
2298  case T_oval:
2299  pad->SetShape( PAD_SHAPE_OVAL );
2300  break;
2301 
2302  case T_trapezoid:
2303  pad->SetShape( PAD_SHAPE_TRAPEZOID );
2304  break;
2305 
2306  case T_roundrect:
2307  pad->SetShape( PAD_SHAPE_ROUNDRECT );
2308  break;
2309 
2310  default:
2311  Expecting( "circle, rectangle, roundrect, oval, trapezoid or custom" );
2312  }
2313 
2314  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2315  {
2316  if( token != T_LEFT )
2317  Expecting( T_LEFT );
2318 
2319  token = NextTok();
2320 
2321  switch( token )
2322  {
2323  case T_size:
2324  sz.SetWidth( parseBoardUnits( "width value" ) );
2325  sz.SetHeight( parseBoardUnits( "height value" ) );
2326  pad->SetSize( sz );
2327  NeedRIGHT();
2328  break;
2329 
2330  case T_at:
2331  pt.x = parseBoardUnits( "X coordinate" );
2332  pt.y = parseBoardUnits( "Y coordinate" );
2333  pad->SetPos0( pt );
2334  token = NextTok();
2335 
2336  if( token == T_NUMBER )
2337  {
2338  pad->SetOrientation( parseDouble() * 10.0 );
2339  NeedRIGHT();
2340  }
2341  else if( token != T_RIGHT )
2342  {
2343  Expecting( ") or angle value" );
2344  }
2345 
2346  break;
2347 
2348  case T_rect_delta:
2349  {
2350  wxSize delta;
2351  delta.SetWidth( parseBoardUnits( "rectangle delta width" ) );
2352  delta.SetHeight( parseBoardUnits( "rectangle delta height" ) );
2353  pad->SetDelta( delta );
2354  NeedRIGHT();
2355  }
2356  break;
2357 
2358  case T_drill:
2359  {
2360  bool haveWidth = false;
2361  wxSize drillSize = pad->GetDrillSize();
2362 
2363  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2364  {
2365  if( token == T_LEFT )
2366  token = NextTok();
2367 
2368  switch( token )
2369  {
2370  case T_oval:
2371  pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
2372  break;
2373 
2374  case T_NUMBER:
2375  {
2376  if( !haveWidth )
2377  {
2378  drillSize.SetWidth( parseBoardUnits() );
2379 
2380  // If height is not defined the width and height are the same.
2381  drillSize.SetHeight( drillSize.GetWidth() );
2382  haveWidth = true;
2383  }
2384  else
2385  {
2386  drillSize.SetHeight( parseBoardUnits() );
2387  }
2388 
2389  }
2390  break;
2391 
2392  case T_offset:
2393  pt.x = parseBoardUnits( "drill offset x" );
2394  pt.y = parseBoardUnits( "drill offset y" );
2395  pad->SetOffset( pt );
2396  NeedRIGHT();
2397  break;
2398 
2399  default:
2400  Expecting( "oval, size, or offset" );
2401  }
2402  }
2403 
2404  // This fixes a bug caused by setting the default D_PAD drill size to a value
2405  // other than 0 used to fix a bunch of debug assertions even though it is defined
2406  // as a through hole pad. Wouldn't a though hole pad with no drill be a surface
2407  // mount pad (or a conn pad which is a smd pad with no solder paste)?
2408  if( ( pad->GetAttribute() != PAD_ATTRIB_SMD ) && ( pad->GetAttribute() != PAD_ATTRIB_CONN ) )
2409  pad->SetDrillSize( drillSize );
2410  else
2411  pad->SetDrillSize( wxSize( 0, 0 ) );
2412 
2413  }
2414  break;
2415 
2416  case T_layers:
2417  {
2418  LSET layerMask = parseBoardItemLayersAsMask();
2419  pad->SetLayerSet( layerMask );
2420  }
2421  break;
2422 
2423  case T_net:
2424  if( ! pad->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
2426  wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ),
2428  );
2430  if( m_board && FromUTF8() != m_board->FindNet( pad->GetNetCode() )->GetNetname() )
2432  wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ),
2434  );
2435  NeedRIGHT();
2436  break;
2437 
2438  case T_die_length:
2439  pad->SetPadToDieLength( parseBoardUnits( T_die_length ) );
2440  NeedRIGHT();
2441  break;
2442 
2443  case T_solder_mask_margin:
2444  pad->SetLocalSolderMaskMargin( parseBoardUnits( T_solder_mask_margin ) );
2445  NeedRIGHT();
2446  break;
2447 
2448  case T_solder_paste_margin:
2449  pad->SetLocalSolderPasteMargin( parseBoardUnits( T_solder_paste_margin ) );
2450  NeedRIGHT();
2451  break;
2452 
2454  pad->SetLocalSolderPasteMarginRatio(
2455  parseDouble( "pad local solder paste margin ratio value" ) );
2456  NeedRIGHT();
2457  break;
2458 
2459  case T_clearance:
2460  pad->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
2461  NeedRIGHT();
2462  break;
2463 
2464  case T_zone_connect:
2465  pad->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
2466  NeedRIGHT();
2467  break;
2468 
2469  case T_thermal_width:
2470  pad->SetThermalWidth( parseBoardUnits( T_thermal_width ) );
2471  NeedRIGHT();
2472  break;
2473 
2474  case T_thermal_gap:
2475  pad->SetThermalGap( parseBoardUnits( T_thermal_gap ) );
2476  NeedRIGHT();
2477  break;
2478 
2479  case T_roundrect_rratio:
2480  pad->SetRoundRectRadiusRatio( parseDouble( "roundrect radius ratio" ) );
2481  NeedRIGHT();
2482  break;
2483 
2484  default:
2485  Expecting( "at, drill, layers, net, die_length, solder_mask_margin, roundrect_rratio,"
2486  "solder_paste_margin, solder_paste_margin_ratio, clearance, "
2487  "zone_connect, fp_poly, basic_shapes, thermal_width, or thermal_gap" );
2488  }
2489  }
2490 
2491  return pad.release();
2492 }
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:974
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 1568 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.

1569 {
1570  wxCHECK_MSG( CurTok() == T_dimension, NULL,
1571  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DIMENSION." ) );
1572 
1573  T token;
1574 
1575  std::unique_ptr<DIMENSION> dimension( new DIMENSION( NULL ) );
1576 
1577  dimension->SetValue( parseBoardUnits( "dimension value" ) );
1578  NeedLEFT();
1579  token = NextTok();
1580 
1581  if( token != T_width )
1582  Expecting( T_width );
1583 
1584  dimension->SetWidth( parseBoardUnits( "dimension width value" ) );
1585  NeedRIGHT();
1586 
1587  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1588  {
1589  if( token != T_LEFT )
1590  Expecting( T_LEFT );
1591 
1592  token = NextTok();
1593 
1594  switch( token )
1595  {
1596  case T_layer:
1597  dimension->SetLayer( parseBoardItemLayer() );
1598  NeedRIGHT();
1599  break;
1600 
1601  case T_tstamp:
1602  dimension->SetTimeStamp( parseHex() );
1603  NeedRIGHT();
1604  break;
1605 
1606  case T_gr_text:
1607  {
1608  TEXTE_PCB* text = parseTEXTE_PCB();
1609  dimension->Text() = *text;
1610  dimension->SetPosition( text->GetTextPos() );
1611  delete text;
1612  break;
1613  }
1614 
1615  case T_feature1:
1616  NeedLEFT();
1617  token = NextTok();
1618 
1619  if( token != T_pts )
1620  Expecting( T_pts );
1621 
1622  parseXY( &dimension->m_featureLineDO.x, &dimension->m_featureLineDO.y );
1623  parseXY( &dimension->m_featureLineDF.x, &dimension->m_featureLineDF.y );
1624  dimension->UpdateHeight();
1625  NeedRIGHT();
1626  NeedRIGHT();
1627  break;
1628 
1629  case T_feature2:
1630  NeedLEFT();
1631  token = NextTok();
1632 
1633  if( token != T_pts )
1634  Expecting( T_pts );
1635 
1636  parseXY( &dimension->m_featureLineGO.x, &dimension->m_featureLineGO.y );
1637  parseXY( &dimension->m_featureLineGF.x, &dimension->m_featureLineGF.y );
1638  dimension->UpdateHeight();
1639  NeedRIGHT();
1640  NeedRIGHT();
1641  break;
1642 
1643 
1644  case T_crossbar:
1645  NeedLEFT();
1646  token = NextTok();
1647 
1648  if( token != T_pts )
1649  Expecting( T_pts );
1650 
1651  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1652  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1653  dimension->UpdateHeight();
1654  NeedRIGHT();
1655  NeedRIGHT();
1656  break;
1657 
1658  case T_arrow1a:
1659  NeedLEFT();
1660  token = NextTok();
1661 
1662  if( token != T_pts )
1663  Expecting( T_pts );
1664 
1665  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1666  parseXY( &dimension->m_arrowD1F.x, &dimension->m_arrowD1F.y );
1667  NeedRIGHT();
1668  NeedRIGHT();
1669  break;
1670 
1671  case T_arrow1b:
1672  NeedLEFT();
1673  token = NextTok();
1674 
1675  if( token != T_pts )
1676  Expecting( T_pts );
1677 
1678  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1679  parseXY( &dimension->m_arrowD2F.x, &dimension->m_arrowD2F.y );
1680  NeedRIGHT();
1681  NeedRIGHT();
1682  break;
1683 
1684  case T_arrow2a:
1685  NeedLEFT();
1686  token = NextTok();
1687 
1688  if( token != T_pts )
1689  Expecting( T_pts );
1690 
1691  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1692  parseXY( &dimension->m_arrowG1F.x, &dimension->m_arrowG1F.y );
1693  NeedRIGHT();
1694  NeedRIGHT();
1695  break;
1696 
1697  case T_arrow2b:
1698  NeedLEFT();
1699  token = NextTok();
1700 
1701  if( token != T_pts )
1702  Expecting( T_pts );
1703 
1704  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1705  parseXY( &dimension->m_arrowG2F.x, &dimension->m_arrowG2F.y );
1706  NeedRIGHT();
1707  NeedRIGHT();
1708  break;
1709 
1710  default:
1711  Expecting( "layer, tstamp, gr_text, feature1, feature2 crossbar, arrow1a, "
1712  "arrow1b, arrow2a, or arrow2b" );
1713  }
1714  }
1715 
1716  return dimension.release();
1717 }
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:959
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 1336 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.

1337 {
1338  wxCHECK_MSG( CurTok() == T_gr_arc || CurTok() == T_gr_circle || CurTok() == T_gr_curve ||
1339  CurTok() == T_gr_line || CurTok() == T_gr_poly, NULL,
1340  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DRAWSEGMENT." ) );
1341 
1342  T token;
1343  wxPoint pt;
1344  std::unique_ptr< DRAWSEGMENT > segment( new DRAWSEGMENT( NULL ) );
1345 
1346  switch( CurTok() )
1347  {
1348  case T_gr_arc:
1349  segment->SetShape( S_ARC );
1350  NeedLEFT();
1351  token = NextTok();
1352 
1353  // the start keyword actually gives the arc center
1354  // Allows also T_center for future change
1355  if( token != T_start && token != T_center )
1356  Expecting( T_start );
1357 
1358  pt.x = parseBoardUnits( "X coordinate" );
1359  pt.y = parseBoardUnits( "Y coordinate" );
1360  segment->SetCenter( pt );
1361  NeedRIGHT();
1362  NeedLEFT();
1363  token = NextTok();
1364 
1365  if( token != T_end ) // the end keyword actually gives the starting point of the arc
1366  Expecting( T_end );
1367 
1368  pt.x = parseBoardUnits( "X coordinate" );
1369  pt.y = parseBoardUnits( "Y coordinate" );
1370  segment->SetArcStart( pt );
1371  NeedRIGHT();
1372  break;
1373 
1374  case T_gr_circle:
1375  segment->SetShape( S_CIRCLE );
1376  NeedLEFT();
1377  token = NextTok();
1378 
1379  if( token != T_center )
1380  Expecting( T_center );
1381 
1382  pt.x = parseBoardUnits( "X coordinate" );
1383  pt.y = parseBoardUnits( "Y coordinate" );
1384  segment->SetCenter( pt );
1385  NeedRIGHT();
1386  NeedLEFT();
1387 
1388  token = NextTok();
1389 
1390  if( token != T_end )
1391  Expecting( T_end );
1392 
1393  pt.x = parseBoardUnits( "X coordinate" );
1394  pt.y = parseBoardUnits( "Y coordinate" );
1395  segment->SetEnd( pt );
1396  NeedRIGHT();
1397  break;
1398 
1399  case T_gr_curve:
1400  segment->SetShape( S_CURVE );
1401  NeedLEFT();
1402  token = NextTok();
1403 
1404  if( token != T_pts )
1405  Expecting( T_pts );
1406 
1407  segment->SetStart( parseXY() );
1408  segment->SetBezControl1( parseXY() );
1409  segment->SetBezControl2( parseXY() );
1410  segment->SetEnd( parseXY() );
1411  NeedRIGHT();
1412  break;
1413 
1414  case T_gr_line:
1415  // Default DRAWSEGMENT type is S_SEGMENT.
1416  NeedLEFT();
1417  token = NextTok();
1418 
1419  if( token != T_start )
1420  Expecting( T_start );
1421 
1422  pt.x = parseBoardUnits( "X coordinate" );
1423  pt.y = parseBoardUnits( "Y coordinate" );
1424  segment->SetStart( pt );
1425  NeedRIGHT();
1426  NeedLEFT();
1427  token = NextTok();
1428 
1429  if( token != T_end )
1430  Expecting( T_end );
1431 
1432  pt.x = parseBoardUnits( "X coordinate" );
1433  pt.y = parseBoardUnits( "Y coordinate" );
1434  segment->SetEnd( pt );
1435  NeedRIGHT();
1436  break;
1437 
1438  case T_gr_poly:
1439  {
1440  segment->SetShape( S_POLYGON );
1441  NeedLEFT();
1442  token = NextTok();
1443 
1444  if( token != T_pts )
1445  Expecting( T_pts );
1446 
1447  std::vector< wxPoint > pts;
1448 
1449  while( (token = NextTok()) != T_RIGHT )
1450  pts.push_back( parseXY() );
1451 
1452  segment->SetPolyPoints( pts );
1453  }
1454  break;
1455 
1456  default:
1457  Expecting( "gr_arc, gr_circle, gr_curve, gr_line, or gr_poly" );
1458  }
1459 
1460  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1461  {
1462  if( token != T_LEFT )
1463  Expecting( T_LEFT );
1464 
1465  token = NextTok();
1466 
1467  switch( token )
1468  {
1469  case T_angle:
1470  segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
1471  break;
1472 
1473  case T_layer:
1474  segment->SetLayer( parseBoardItemLayer() );
1475  break;
1476 
1477  case T_width:
1478  segment->SetWidth( parseBoardUnits( T_width ) );
1479  break;
1480 
1481  case T_tstamp:
1482  segment->SetTimeStamp( parseHex() );
1483  break;
1484 
1485  case T_status:
1486  segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
1487  break;
1488 
1489  default:
1490  Expecting( "layer, width, tstamp, or status" );
1491  }
1492 
1493  NeedRIGHT();
1494  }
1495 
1496  return segment.release();
1497 }
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:959
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 2072 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.

2073 {
2074  wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve ||
2075  CurTok() == T_fp_line || CurTok() == T_fp_poly, NULL,
2076  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDGE_MODULE." ) );
2077 
2078  wxPoint pt;
2079  T token;
2080 
2081  std::unique_ptr< EDGE_MODULE > segment( new EDGE_MODULE( NULL ) );
2082 
2083  switch( CurTok() )
2084  {
2085  case T_fp_arc:
2086  segment->SetShape( S_ARC );
2087  NeedLEFT();
2088  token = NextTok();
2089 
2090  // the start keyword actually gives the arc center
2091  // Allows also T_center for future change
2092  if( token != T_start && token != T_center )
2093  Expecting( T_start );
2094 
2095  pt.x = parseBoardUnits( "X coordinate" );
2096  pt.y = parseBoardUnits( "Y coordinate" );
2097  segment->SetStart0( pt );
2098  NeedRIGHT();
2099  NeedLEFT();
2100  token = NextTok();
2101 
2102  if( token != T_end ) // end keyword actually gives the starting point of the arc
2103  Expecting( T_end );
2104 
2105  pt.x = parseBoardUnits( "X coordinate" );
2106  pt.y = parseBoardUnits( "Y coordinate" );
2107  segment->SetEnd0( pt );
2108  NeedRIGHT();
2109  NeedLEFT();
2110  token = NextTok();
2111 
2112  if( token != T_angle )
2113  Expecting( T_angle );
2114 
2115  segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
2116  NeedRIGHT();
2117  break;
2118 
2119  case T_fp_circle:
2120  segment->SetShape( S_CIRCLE );
2121  NeedLEFT();
2122  token = NextTok();
2123 
2124  if( token != T_center )
2125  Expecting( T_center );
2126 
2127  pt.x = parseBoardUnits( "X coordinate" );
2128  pt.y = parseBoardUnits( "Y coordinate" );
2129  segment->SetStart0( pt );
2130  NeedRIGHT();
2131  NeedLEFT();
2132  token = NextTok();
2133 
2134  if( token != T_end )
2135  Expecting( T_end );
2136 
2137  pt.x = parseBoardUnits( "X coordinate" );
2138  pt.y = parseBoardUnits( "Y coordinate" );
2139  segment->SetEnd0( pt );
2140  NeedRIGHT();
2141  break;
2142 
2143  case T_fp_curve:
2144  segment->SetShape( S_CURVE );
2145  NeedLEFT();
2146  token = NextTok();
2147 
2148  if( token != T_pts )
2149  Expecting( T_pts );
2150 
2151  segment->SetStart0( parseXY() );
2152  segment->SetBezControl1( parseXY() );
2153  segment->SetBezControl2( parseXY() );
2154  segment->SetEnd0( parseXY() );
2155  NeedRIGHT();
2156  break;
2157 
2158  case T_fp_line:
2159  // Default DRAWSEGMENT type is S_SEGMENT.
2160  NeedLEFT();
2161  token = NextTok();
2162 
2163  if( token != T_start )
2164  Expecting( T_start );
2165 
2166  pt.x = parseBoardUnits( "X coordinate" );
2167  pt.y = parseBoardUnits( "Y coordinate" );
2168  segment->SetStart0( pt );
2169 
2170  NeedRIGHT();
2171  NeedLEFT();
2172  token = NextTok();
2173 
2174  if( token != T_end )
2175  Expecting( T_end );
2176 
2177  pt.x = parseBoardUnits( "X coordinate" );
2178  pt.y = parseBoardUnits( "Y coordinate" );
2179  segment->SetEnd0( pt );
2180  NeedRIGHT();
2181  break;
2182 
2183  case T_fp_poly:
2184  {
2185  segment->SetShape( S_POLYGON );
2186  NeedLEFT();
2187  token = NextTok();
2188 
2189  if( token != T_pts )
2190  Expecting( T_pts );
2191 
2192  std::vector< wxPoint > pts;
2193 
2194  while( (token = NextTok()) != T_RIGHT )
2195  pts.push_back( parseXY() );
2196 
2197  segment->SetPolyPoints( pts );
2198  }
2199  break;
2200 
2201  default:
2202  Expecting( "fp_arc, fp_circle, fp_curve, fp_line, or fp_poly" );
2203  }
2204 
2205  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2206  {
2207  if( token != T_LEFT )
2208  Expecting( T_LEFT );
2209 
2210  token = NextTok();
2211 
2212  switch( token )
2213  {
2214  case T_layer:
2215  segment->SetLayer( parseBoardItemLayer() );
2216  break;
2217 
2218  case T_width:
2219  segment->SetWidth( parseBoardUnits( T_width ) );
2220  break;
2221 
2222  case T_tstamp:
2223  segment->SetTimeStamp( parseHex() );
2224  break;
2225 
2226  case T_status:
2227  segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
2228  break;
2229 
2230  default:
2231  Expecting( "layer or width" );
2232  }
2233 
2234  NeedRIGHT();
2235  }
2236 
2237  return segment.release();
2238 }
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:959
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  // ignore
615  parseInt( "no connect count" );
616  NeedRIGHT();
617  break;
618 
619  default: // Skip everything but the board thickness.
620  //wxLogDebug( wxT( "Skipping general section token %s " ), GetChars( GetTokenString( token ) ) );
621 
622  while( ( token = NextTok() ) != T_RIGHT )
623  {
624  if( !IsSymbol( token ) && token != T_NUMBER )
625  Expecting( "symbol or number" );
626  }
627  }
628  }
629 }
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 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:533
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:276
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 771 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.

772 {
773  T token;
774 
775  std::string name;
776  std::string type;
777  bool isVisible = true;
778 
779  aLayer->clear();
780 
781  if( CurTok() != T_LEFT )
782  Expecting( T_LEFT );
783 
784  // this layer_num is not used, we DO depend on LAYER_T however.
785  LAYER_NUM layer_num = parseInt( "layer index" );
786 
788  name = CurText();
789 
790  NeedSYMBOL();
791  type = CurText();
792 
793  token = NextTok();
794 
795  if( token == T_hide )
796  {
797  isVisible = false;
798  NeedRIGHT();
799  }
800  else if( token != T_RIGHT )
801  {
802  Expecting( "hide or )" );
803  }
804 
805  aLayer->m_name = FROM_UTF8( name.c_str() );
806  aLayer->m_type = LAYER::ParseType( type.c_str() );
807  aLayer->m_number = layer_num;
808  aLayer->m_visible = isVisible;
809 }
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:111
LAYER_T m_type
The type of the layer.
Definition: class_board.h:113
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:115
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:92
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:117
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 813 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.

814 {
815  wxCHECK_RET( CurTok() == T_layers,
816  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layers." ) );
817 
818  T token;
819  LSET visibleLayers;
820  LSET enabledLayers;
821  int copperLayerCount = 0;
822  LAYER layer;
823 
824  std::vector<LAYER> cu;
825 
826  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
827  {
828  parseLayer( &layer );
829 
830  if( layer.m_type == LT_UNDEFINED ) // it's a non-copper layer
831  break;
832 
833  cu.push_back( layer ); // it's copper
834  }
835 
836  // All Cu layers are parsed, but not the non-cu layers here.
837 
838  // The original *.kicad_pcb file format and the inverted
839  // Cu stack format both have all the Cu layers first, so use this
840  // trick to handle either. The layer number in the (layers ..)
841  // s-expression element are ignored.
842  if( cu.size() )
843  {
844  // Rework the layer numbers, which changed when the Cu stack
845  // was flipped. So we instead use position in the list.
846  cu[cu.size()-1].m_number = B_Cu;
847 
848  for( unsigned i=0; i < cu.size()-1; ++i )
849  {
850  cu[i].m_number = i;
851  }
852 
853  for( std::vector<LAYER>::const_iterator it = cu.begin(); it<cu.end(); ++it )
854  {
855  enabledLayers.set( it->m_number );
856 
857  if( it->m_visible )
858  visibleLayers.set( it->m_number );
859 
860  m_board->SetLayerDescr( PCB_LAYER_ID( it->m_number ), *it );
861 
862  UTF8 name = it->m_name;
863 
864  m_layerIndices[ name ] = PCB_LAYER_ID( it->m_number );
865  m_layerMasks[ name ] = LSET( PCB_LAYER_ID( it->m_number ) );
866  }
867 
868  copperLayerCount = cu.size();
869  }
870 
871  // process non-copper layers
872  while( token != T_RIGHT )
873  {
874  LAYER_ID_MAP::const_iterator it = m_layerIndices.find( UTF8( layer.m_name ) );
875 
876  if( it == m_layerIndices.end() )
877  {
878  wxString error = wxString::Format(
879  _( "Layer '%s' in file '%s' at line %d, is not in fixed layer hash" ),
880  GetChars( layer.m_name ),
881  GetChars( CurSource() ),
882  CurLineNumber(),
883  CurOffset()
884  );
885 
886  THROW_IO_ERROR( error );
887  }
888 
889  layer.m_number = it->second;
890 
891  enabledLayers.set( layer.m_number );
892 
893  if( layer.m_visible )
894  visibleLayers.set( layer.m_number );
895 
896  // DBG( printf( "aux m_visible:%s\n", layer.m_visible ? "true" : "false" );)
897 
898  m_board->SetLayerDescr( it->second, layer );
899 
900  token = NextTok();
901 
902  if( token != T_LEFT )
903  break;
904 
905  parseLayer( &layer );
906  }
907 
908  // We need at least 2 copper layers and there must be an even number of them.
909  if( copperLayerCount < 2 || (copperLayerCount % 2) != 0 )
910  {
911  wxString err = wxString::Format(
912  _( "%d is not a valid layer count" ), copperLayerCount );
913 
915  }
916 
917  m_board->SetCopperLayerCount( copperLayerCount );
918  m_board->SetEnabledLayers( enabledLayers );
919 
920  // call SetEnabledLayers before SetVisibleLayers()
921  m_board->SetVisibleLayers( visibleLayers );
922 }
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:111
LAYER_T m_type
The type of the layer.
Definition: class_board.h:113
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:115
#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:771
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:85
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:117
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 1720 of file pcb_parser.cpp.

1721 {
1722  try
1723  {
1724  return parseMODULE_unchecked( aInitialComments );
1725  }
1726  catch( const PARSE_ERROR& parse_error )
1727  {
1728  if( m_tooRecent )
1729  throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
1730  else
1731  throw;
1732  }
1733 }
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 1736 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.

1737 {
1738  wxCHECK_MSG( CurTok() == T_module, NULL,
1739  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as MODULE." ) );
1740 
1741  wxString name;
1742  wxPoint pt;
1743  T token;
1744  LIB_ID fpid;
1745 
1746  std::unique_ptr<MODULE> module( new MODULE( m_board ) );
1747 
1748  module->SetInitialComments( aInitialComments );
1749 
1750  token = NextTok();
1751 
1752  if( !IsSymbol( token ) && token != T_NUMBER )
1753  Expecting( "symbol|number" );
1754 
1755  name = FromUTF8();
1756 
1757  if( !name.IsEmpty() && fpid.Parse( TO_UTF8( FromUTF8() ) ) >= 0 )
1758  {
1759  wxString error;
1760  error.Printf( _( "invalid footprint ID in\nfile: <%s>\nline: %d\noffset: %d" ),
1762  THROW_IO_ERROR( error );
1763  }
1764 
1765  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1766  {
1767  if( token == T_LEFT )
1768  token = NextTok();
1769 
1770  switch( token )
1771  {
1772  case T_version:
1773  {
1774  // Theoretically a module nested in a PCB could declare its own version, though
1775  // as of writing this comment we don't do that. Just in case, take the greater
1776  // version.
1777  int this_version = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
1778  NeedRIGHT();
1779  m_requiredVersion = std::max( m_requiredVersion, this_version );
1781  break;
1782  }
1783 
1784  case T_locked:
1785  module->SetLocked( true );
1786  break;
1787 
1788  case T_placed:
1789  module->SetIsPlaced( true );
1790  break;
1791 
1792  case T_layer:
1793  {
1794  // Footprints can be only on the front side or the back side.
1795  // but because we can find some stupid layer in file, ensure a
1796  // acceptable layer is set for the footprint
1798  module->SetLayer( layer == B_Cu ? B_Cu : F_Cu );
1799  }
1800  NeedRIGHT();
1801  break;
1802 
1803  case T_tedit:
1804  module->SetLastEditTime( parseHex() );
1805  NeedRIGHT();
1806  break;
1807 
1808  case T_tstamp:
1809  module->SetTimeStamp( parseHex() );
1810  NeedRIGHT();
1811  break;
1812 
1813  case T_at:
1814  pt.x = parseBoardUnits( "X coordinate" );
1815  pt.y = parseBoardUnits( "Y coordinate" );
1816  module->SetPosition( pt );
1817  token = NextTok();
1818 
1819  if( token == T_NUMBER )
1820  {
1821  module->SetOrientation( parseDouble() * 10.0 );
1822  NeedRIGHT();
1823  }
1824  else if( token != T_RIGHT )
1825  {
1826  Expecting( T_RIGHT );
1827  }
1828 
1829  break;
1830 
1831  case T_descr:
1832  NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
1833  module->SetDescription( FromUTF8() );
1834  NeedRIGHT();
1835  break;
1836 
1837  case T_tags:
1838  NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
1839  module->SetKeywords( FromUTF8() );
1840  NeedRIGHT();
1841  break;
1842 
1843  case T_path:
1844  NeedSYMBOLorNUMBER(); // Paths can be numerical so a number is also a symbol here
1845  module->SetPath( FromUTF8() );
1846  NeedRIGHT();
1847  break;
1848 
1849  case T_autoplace_cost90:
1850  module->SetPlacementCost90( parseInt( "auto place cost at 90 degrees" ) );
1851  NeedRIGHT();
1852  break;
1853 
1854  case T_autoplace_cost180:
1855  module->SetPlacementCost180( parseInt( "auto place cost at 180 degrees" ) );
1856  NeedRIGHT();
1857  break;
1858 
1859  case T_solder_mask_margin:
1860  module->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin value" ) );
1861  NeedRIGHT();
1862  break;
1863 
1864  case T_solder_paste_margin:
1865  module->SetLocalSolderPasteMargin(
1866  parseBoardUnits( "local solder paste margin value" ) );
1867  NeedRIGHT();
1868  break;
1869 
1870  case T_solder_paste_ratio:
1871  module->SetLocalSolderPasteMarginRatio(
1872  parseDouble( "local solder paste margin ratio value" ) );
1873  NeedRIGHT();
1874  break;
1875 
1876  case T_clearance:
1877  module->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
1878  NeedRIGHT();
1879  break;
1880 
1881  case T_zone_connect:
1882  module->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
1883  NeedRIGHT();
1884  break;
1885 
1886  case T_thermal_width:
1887  module->SetThermalWidth( parseBoardUnits( "thermal width value" ) );
1888  NeedRIGHT();
1889  break;
1890 
1891  case T_thermal_gap:
1892  module->SetThermalGap( parseBoardUnits( "thermal gap value" ) );
1893  NeedRIGHT();
1894  break;
1895 
1896  case T_attr:
1897  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1898  {
1899  switch( token )
1900  {
1901  case T_smd:
1902  module->SetAttributes( module->GetAttributes() | MOD_CMS );
1903  break;
1904 
1905  case T_virtual:
1906  module->SetAttributes( module->GetAttributes() | MOD_VIRTUAL );
1907  break;
1908 
1909  default:
1910  Expecting( "smd and/or virtual" );
1911  }
1912  }
1913 
1914  break;
1915 
1916  case T_fp_text:
1917  {
1918  TEXTE_MODULE* text = parseTEXTE_MODULE();
1919  text->SetParent( module.get() );
1920  double orientation = text->GetTextAngle();
1921  orientation -= module->GetOrientation();
1922  text->SetTextAngle( orientation );
1923  text->SetDrawCoord();
1924 
1925  switch( text->GetType() )
1926  {
1928  module->Reference() = *text;
1929  delete text;
1930  break;
1931 
1933  module->Value() = *text;
1934  delete text;
1935  break;
1936 
1937  default:
1938  module->GraphicalItemsList().PushBack( text );
1939  }
1940  }
1941  break;
1942 
1943  case T_fp_arc:
1944  case T_fp_circle:
1945  case T_fp_curve:
1946  case T_fp_line:
1947  case T_fp_poly:
1948  {
1949  EDGE_MODULE* em = parseEDGE_MODULE();
1950  em->SetParent( module.get() );
1951  em->SetDrawCoord();
1952  module->GraphicalItemsList().PushBack( em );
1953  }
1954  break;
1955 
1956  case T_pad:
1957  {
1958  D_PAD* pad = parseD_PAD( module.get() );
1959  pt = pad->GetPos0();
1960 
1961  RotatePoint( &pt, module->GetOrientation() );
1962  pad->SetPosition( pt + module->GetPosition() );
1963  module->Add( pad, ADD_APPEND );
1964  }
1965  break;
1966 
1967  case T_model:
1968  module->Add3DModel( parse3DModel() );
1969  break;
1970 
1971  default:
1972  Expecting( "locked, placed, tedit, tstamp, at, descr, tags, path, "
1973  "autoplace_cost90, autoplace_cost180, solder_mask_margin, "
1974  "solder_paste_margin, solder_paste_ratio, clearance, "
1975  "zone_connect, thermal_width, thermal_gap, attr, fp_text, "
1976  "fp_arc, fp_circle, fp_curve, fp_line, fp_poly, pad, or model" );
1977  }
1978  }
1979 
1980  module->SetFPID( fpid );
1981  module->CalculateBoundingBox();
1982 
1983  return module.release();
1984 }
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:77
#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:959
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:79
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 1253 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.

1254 {
1255  wxCHECK_RET( CurTok() == T_net_class,
1256  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net class." ) );
1257 
1258  T token;
1259 
1260  NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
1261 
1262  // Read netclass name (can be a name or just a number like track width)
1264  nc->SetName( FromUTF8() );
1265  NeedSYMBOL();
1266  nc->SetDescription( FromUTF8() );
1267 
1268  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1269  {
1270  if( token != T_LEFT )
1271  Expecting( T_LEFT );
1272 
1273  token = NextTok();
1274 
1275  switch( token )
1276  {
1277  case T_clearance:
1278  nc->SetClearance( parseBoardUnits( T_clearance ) );
1279  break;
1280 
1281  case T_trace_width:
1282  nc->SetTrackWidth( parseBoardUnits( T_trace_width ) );
1283  break;
1284 
1285  case T_via_dia:
1286  nc->SetViaDiameter( parseBoardUnits( T_via_dia ) );
1287  break;
1288 
1289  case T_via_drill:
1290  nc->SetViaDrill( parseBoardUnits( T_via_drill ) );
1291  break;
1292 
1293  case T_uvia_dia:
1294  nc->SetuViaDiameter( parseBoardUnits( T_uvia_dia ) );
1295  break;
1296 
1297  case T_uvia_drill:
1298  nc->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
1299  break;
1300 
1301  case T_diff_pair_width:
1302  nc->SetDiffPairWidth( parseBoardUnits( T_diff_pair_width ) );
1303  break;
1304 
1305  case T_diff_pair_gap:
1306  nc->SetDiffPairGap( parseBoardUnits( T_diff_pair_gap ) );
1307  break;
1308 
1309  case T_add_net:
1311  nc->Add( FromUTF8() );
1312  break;
1313 
1314  default:
1315  Expecting( "clearance, trace_width, via_dia, via_drill, uvia_dia, uvia_drill, diff_pair_width, diff_pair_gap or add_net" );
1316  }
1317 
1318  NeedRIGHT();
1319  }
1320 
1321  if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
1322  {
1323  // Must have been a name conflict, this is a bad board file.
1324  // User may have done a hand edit to the file.
1325 
1326  // unique_ptr will delete nc on this code path
1327 
1328  wxString error;
1329  error.Printf( _( "duplicate NETCLASS name '%s' in file <%s> at line %d, offset %d" ),
1330  nc->GetName().GetData(), CurSource().GetData(), CurLineNumber(), CurOffset() );
1331  THROW_IO_ERROR( error );
1332  }
1333 }
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:533
#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 1227 of file pcb_parser.cpp.

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

1228 {
1229  wxCHECK_RET( CurTok() == T_net,
1230  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net." ) );
1231 
1232  int netCode = parseInt( "net number" );
1233 
1235  wxString name = FromUTF8();
1236 
1237  NeedRIGHT();
1238 
1239  // net 0 should be already in list, so store this net
1240  // if it is not the net 0, or if the net 0 does not exists.
1241  // (TODO: a better test.)
1243  {
1244  NETINFO_ITEM* net = new NETINFO_ITEM( m_board, name, netCode );
1245  m_board->Add( net );
1246 
1247  // Store the new code mapping
1248  pushValueIntoMap( netCode, net->GetNet() );
1249  }
1250 }
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.
Definition: class_netinfo.h:69
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 632 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.

633 {
634  wxCHECK_RET( CurTok() == T_page,
635  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
636 
637  T token;
638  PAGE_INFO pageInfo;
639 
640  NeedSYMBOL();
641 
642  wxString pageType = FromUTF8();
643 
644  if( !pageInfo.SetType( pageType ) )
645  {
646  wxString err;
647  err.Printf( _( "page type \"%s\" is not valid " ), GetChars( FromUTF8() ) );
649  }
650 
651  if( pageType == PAGE_INFO::Custom )
652  {
653  double width = parseDouble( "width" ); // width in mm
654 
655  // Perform some controls to avoid crashes if the size is edited by hands
656  if( width < 100.0 )
657  width = 100.0;
658  else if( width > 1200.0 )
659  width = 1200.0;
660 
661  double height = parseDouble( "height" ); // height in mm
662 
663  if( height < 100.0 )
664  height = 100.0;
665  else if( height > 1200.0 )
666  height = 1200.0;
667 
668  pageInfo.SetWidthMils( Mm2mils( width ) );
669  pageInfo.SetHeightMils( Mm2mils( height ) );
670  }
671 
672  token = NextTok();
673 
674  if( token == T_portrait )
675  {
676  pageInfo.SetPortrait( true );
677  NeedRIGHT();
678  }
679  else if( token != T_RIGHT )
680  {
681  Expecting( "portrait|)" );
682  }
683 
684  m_board->SetPageSettings( pageInfo );
685 }
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:549
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 3014 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.

3015 {
3016  wxCHECK_MSG( CurTok() == T_target, NULL,
3017  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TARGET." ) );
3018 
3019  wxPoint pt;
3020  T token;
3021 
3022  std::unique_ptr< PCB_TARGET > target( new PCB_TARGET( NULL ) );
3023 
3024  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
3025  {
3026  if( token == T_LEFT )
3027  token = NextTok();
3028 
3029  switch( token )
3030  {
3031  case T_x:
3032  target->SetShape( 1 );
3033  break;
3034 
3035  case T_plus:
3036  target->SetShape( 0 );
3037  break;
3038 
3039  case T_at:
3040  pt.x = parseBoardUnits( "target x position" );
3041  pt.y = parseBoardUnits( "target y position" );
3042  target->SetPosition( pt );
3043  NeedRIGHT();
3044  break;
3045 
3046  case T_size:
3047  target->SetSize( parseBoardUnits( "target size" ) );
3048  NeedRIGHT();
3049  break;
3050 
3051  case T_width:
3052  target->SetWidth( parseBoardUnits( "target thickness" ) );
3053  NeedRIGHT();
3054  break;
3055 
3056  case T_layer:
3057  target->SetLayer( parseBoardItemLayer() );
3058  NeedRIGHT();
3059  break;
3060 
3061  case T_tstamp:
3062  target->SetTimeStamp( parseHex() );
3063  NeedRIGHT();
3064  break;
3065 
3066  default:
3067  Expecting( "x, plus, at, size, width, layer or tstamp" );
3068  }
3069  }
3070 
3071  return target.release();
3072 }
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:959
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 992 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.

993 {
994  wxCHECK_RET( CurTok() == T_setup,
995  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as setup." ) );
996 
997  T token;
998  NETCLASSPTR defaultNetClass = m_board->GetDesignSettings().GetDefault();
999  // TODO Orson: is it really necessary to first operate on a copy and then apply it?
1000  // would not it be better to use reference here and apply all the changes instantly?
1001  BOARD_DESIGN_SETTINGS designSettings = m_board->GetDesignSettings();
1002  ZONE_SETTINGS zoneSettings = m_board->GetZoneSettings();
1003 
1004  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1005  {
1006  if( token != T_LEFT )
1007  Expecting( T_LEFT );
1008 
1009  token = NextTok();
1010 
1011  switch( token )
1012  {
1013  case T_last_trace_width: // not used now
1014  /* lastTraceWidth =*/ parseBoardUnits( T_last_trace_width );
1015  NeedRIGHT();
1016  break;
1017 
1018  case T_user_trace_width:
1019  designSettings.m_TrackWidthList.push_back( parseBoardUnits( T_user_trace_width ) );
1020  NeedRIGHT();
1021  break;
1022 
1023  case T_trace_clearance:
1024  defaultNetClass->SetClearance( parseBoardUnits( T_trace_clearance ) );
1025  NeedRIGHT();
1026  break;
1027 
1028  case T_zone_clearance:
1030  NeedRIGHT();
1031  break;
1032 
1033  case T_zone_45_only:
1034  zoneSettings.m_Zone_45_Only = parseBool();
1035  NeedRIGHT();
1036  break;
1037 
1038  case T_trace_min:
1039  designSettings.m_TrackMinWidth = parseBoardUnits( T_trace_min );
1040  NeedRIGHT();
1041  break;
1042 
1043  case T_segment_width:
1045  NeedRIGHT();
1046  break;
1047 
1048  case T_edge_width:
1049  designSettings.m_EdgeSegmentWidth = parseBoardUnits( T_edge_width );
1050  NeedRIGHT();
1051  break;
1052 
1053  case T_via_size:
1054  defaultNetClass->SetViaDiameter( parseBoardUnits( T_via_size ) );
1055  NeedRIGHT();
1056  break;
1057 
1058  case T_via_drill:
1059  defaultNetClass->SetViaDrill( parseBoardUnits( T_via_drill ) );
1060  NeedRIGHT();
1061  break;
1062 
1063  case T_via_min_size:
1064  designSettings.m_ViasMinSize = parseBoardUnits( T_via_min_size );
1065  NeedRIGHT();
1066  break;
1067 
1068  case T_via_min_drill:
1069  designSettings.m_ViasMinDrill = parseBoardUnits( T_via_min_drill );
1070  NeedRIGHT();
1071  break;
1072 
1073  case T_user_via:
1074  {
1075  int viaSize = parseBoardUnits( "user via size" );
1076  int viaDrill = parseBoardUnits( "user via drill" );
1077  designSettings.m_ViasDimensionsList.push_back( VIA_DIMENSION( viaSize, viaDrill ) );
1078  NeedRIGHT();
1079  }
1080  break;
1081 
1082  case T_uvia_size:
1083  defaultNetClass->SetuViaDiameter( parseBoardUnits( T_uvia_size ) );
1084  NeedRIGHT();
1085  break;
1086 
1087  case T_uvia_drill:
1088  defaultNetClass->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
1089  NeedRIGHT();
1090  break;
1091 
1092  case T_uvias_allowed:
1093  designSettings.m_MicroViasAllowed = parseBool();
1094  NeedRIGHT();
1095  break;
1096 
1098  designSettings.m_BlindBuriedViaAllowed = parseBool();
1099  NeedRIGHT();
1100  break;
1101 
1102  case T_uvia_min_size:
1104  NeedRIGHT();
1105  break;
1106 
1107  case T_uvia_min_drill:
1109  NeedRIGHT();
1110  break;
1111 
1112  case T_pcb_text_width:
1113  designSettings.m_PcbTextWidth = parseBoardUnits( T_pcb_text_width );
1114  NeedRIGHT();
1115  break;
1116 
1117  case T_pcb_text_size:
1118  designSettings.m_PcbTextSize.x = parseBoardUnits( "pcb text width" );
1119  designSettings.m_PcbTextSize.y = parseBoardUnits( "pcb text height" );
1120  NeedRIGHT();
1121  break;
1122 
1123  case T_mod_edge_width:
1125  NeedRIGHT();
1126  break;
1127 
1128  case T_mod_text_size:
1129  designSettings.m_ModuleTextSize.x = parseBoardUnits( "module text width" );
1130  designSettings.m_ModuleTextSize.y = parseBoardUnits( "module text height" );
1131  NeedRIGHT();
1132  break;
1133 
1134  case T_mod_text_width:
1136  NeedRIGHT();
1137  break;
1138 
1139  case T_pad_size:
1140  {
1141  wxSize sz;
1142  sz.SetWidth( parseBoardUnits( "master pad width" ) );
1143  sz.SetHeight( parseBoardUnits( "master pad height" ) );
1144  designSettings.m_Pad_Master.SetSize( sz );
1145  NeedRIGHT();
1146  }
1147  break;
1148 
1149  case T_pad_drill:
1150  {
1151  int drillSize = parseBoardUnits( T_pad_drill );
1152  designSettings.m_Pad_Master.SetDrillSize( wxSize( drillSize, drillSize ) );
1153  NeedRIGHT();
1154  }
1155  break;
1156 
1159  NeedRIGHT();
1160  break;
1161 
1164  NeedRIGHT();
1165  break;
1166 
1169  NeedRIGHT();
1170  break;
1171 
1174  NeedRIGHT();
1175  break;
1176 
1177  case T_aux_axis_origin:
1178  {
1179  int x = parseBoardUnits( "auxiliary origin X" );
1180  int y = parseBoardUnits( "auxiliary origin Y" );
1181  // m_board->SetAuxOrigin( wxPoint( x, y ) ); gets overwritten via SetDesignSettings below
1182  designSettings.m_AuxOrigin = wxPoint( x, y );
1183  NeedRIGHT();
1184  }
1185  break;
1186 
1187  case T_grid_origin:
1188  {
1189  int x = parseBoardUnits( "grid origin X" );
1190  int y = parseBoardUnits( "grid origin Y" );
1191  // m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten SetDesignSettings below
1192  designSettings.m_GridOrigin = wxPoint( x, y );
1193  NeedRIGHT();
1194  }
1195  break;
1196 
1197  case T_visible_elements:
1198  designSettings.SetVisibleElements( parseHex() | MIN_VISIBILITY_MASK );
1199  NeedRIGHT();
1200  break;
1201 
1202  case T_pcbplotparams:
1203  {
1204  PCB_PLOT_PARAMS plotParams;
1205  PCB_PLOT_PARAMS_PARSER parser( reader );
1206  // parser must share the same current line as our current PCB parser
1207  // synchronize it.
1208  parser.SyncLineReaderWith( *this );
1209 
1210  plotParams.Parse( &parser );
1211  SyncLineReaderWith( parser );
1212 
1213  m_board->SetPlotOptions( plotParams );
1214  }
1215  break;
1216 
1217  default:
1218  Unexpected( CurText() );
1219  }
1220  }
1221 
1222  m_board->SetDesignSettings( designSettings );
1223  m_board->SetZoneSettings( zoneSettings );
1224 }
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:558
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:557
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:533
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:543
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition: class_board.h:552
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 1987 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.

1988 {
1989  wxCHECK_MSG( CurTok() == T_fp_text, NULL,
1990  wxString::Format( wxT( "Cannot parse %s as TEXTE_MODULE at line %d, offset %d." ),
1991  GetChars( GetTokenString( CurTok() ) ),
1992  CurLineNumber(), CurOffset() ) );
1993 
1994  T token = NextTok();
1995 
1996  std::unique_ptr<TEXTE_MODULE> text( new TEXTE_MODULE( NULL ) );
1997 
1998  switch( token )
1999  {
2000  case T_reference:
2001  text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
2002  break;
2003 
2004  case T_value:
2005  text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
2006  break;
2007 
2008  case T_user:
2009  break; // Default type is user text.
2010 
2011  default:
2012  THROW_IO_ERROR( wxString::Format( _( "cannot handle footprint text type %s" ),
2013  GetChars( FromUTF8() ) ) );
2014  }
2015 
2017 
2018  text->SetText( FromUTF8() );
2019  NeedLEFT();
2020  token = NextTok();
2021 
2022  if( token != T_at )
2023  Expecting( T_at );
2024 
2025  wxPoint pt;
2026 
2027  pt.x = parseBoardUnits( "X coordinate" );
2028  pt.y = parseBoardUnits( "Y coordinate" );
2029  text->SetPos0( pt );
2030  token = NextTok();
2031 
2032  // If there is no orientation defined, then it is the default value of 0 degrees.
2033  if( token == T_NUMBER )
2034  {
2035  text->SetTextAngle( parseDouble() * 10.0 );
2036  NeedRIGHT();
2037  }
2038  else if( token != T_RIGHT )
2039  {
2040  Unexpected( CurText() );
2041  }
2042 
2043  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2044  {
2045  if( token == T_LEFT )
2046  token = NextTok();
2047 
2048  switch( token )
2049  {
2050  case T_layer:
2051  text->SetLayer( parseBoardItemLayer() );
2052  NeedRIGHT();
2053  break;
2054 
2055  case T_hide:
2056  text->SetVisible( false );
2057  break;
2058 
2059  case T_effects:
2060  parseEDA_TEXT( (EDA_TEXT*) text.get() );
2061  break;
2062 
2063  default:
2064  Expecting( "hide or effects" );
2065  }
2066  }
2067 
2068  return text.release();
2069 }
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:959
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 1500 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.

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