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 CLIPBOARD_PARSER

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 ()
 
MODULEparseMODULE (wxArrayString *aInitialComments=0)
 Function parseMODULE. More...
 
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 std::unordered_map< std::string, PCB_LAYER_IDLAYER_ID_MAP
 
typedef std::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_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)
 
bool parseD_PAD_option (D_PAD *aPad)
 
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...
 
MODULE_3D_SETTINGSparse3DModel ()
 
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 65 of file pcb_parser.h.

Member Typedef Documentation

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

Definition at line 67 of file pcb_parser.h.

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

Definition at line 68 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 274 of file pcb_parser.h.

References init().

274  :
275  PCB_LEXER( aReader ),
276  m_board( 0 )
277  {
278  init();
279  }
PCB_LEXER(const std::string &aSExpression, const wxString &aSource=wxEmptyString)
Constructor ( const std::string&, const wxString& )
Definition: pcb_lexer.h:257
BOARD * m_board
Definition: pcb_parser.h:70
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(), CLIPBOARD_IO::Load(), 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(), CLIPBOARD_IO::Load(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), FP_LIB_TABLE::Parse(), SYMBOL_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(), CLIPBOARD_IO::Load(), 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(), CLIPBOARD_IO::Load(), 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 343 of file pcb_lexer.h.

References DSNLEXER::CurTok().

344  {
345  return (PCB_KEYS_T::T) DSNLEXER::CurTok();
346  }
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 FP_LIB_TABLE::Parse(), SYMBOL_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(), FP_LIB_TABLE::Parse(), SYMBOL_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(), FP_LIB_TABLE::Parse(), SYMBOL_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 79 of file pcb_parser.h.

80  {
81  if( ( aNetCode >= 0 ) && ( aNetCode < (int) m_netCodes.size() ) )
82  return m_netCodes[aNetCode];
83 
84  return aNetCode;
85  }
std::vector< int > m_netCodes
net codes mapping for boards being loaded
Definition: pcb_parser.h:73
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 CLIPBOARD_IO::Load(), 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:75
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:646
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:74
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:74
#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:75
LAYER_ID_MAP m_layerIndices
map layer name to it's index
Definition: pcb_parser.h:71
LSET_MAP m_layerMasks
map layer names to their masks
Definition: pcb_parser.h:72
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 CLIPBOARD_IO::Load(), 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:74
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 943 of file pcb_parser.cpp.

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

944 {
945  // avoid constructing another std::string, use lexer's directly
946  typename M::const_iterator it = aMap.find( curText );
947 
948  if( it == aMap.end() )
949  {
950 #if 0 && defined(DEBUG)
951  // dump the whole darn table, there's something wrong with it.
952  for( it = aMap.begin(); it != aMap.end(); ++it )
953  {
954  wxLogDebug( &aMap == (void*)&m_layerIndices ? wxT( "lm[%s] = %d" ) :
955  wxT( "lm[%s] = %08X" ), it->first.c_str(), it->second );
956  }
957 #endif
958 
959  wxString error = wxString::Format( _(
960  "Layer '%s' in file\n"
961  "'%s'\n"
962  "at line %d, position %d\n"
963  "was not defined in the layers section"
964  ),
965  GetChars( FROM_UTF8( CurText() ) ),
966  GetChars( CurSource() ),
967  CurLineNumber(), CurOffset() );
968 
969  THROW_IO_ERROR( error );
970  }
971 
972  return it->second;
973 }
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
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:71
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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 FP_LIB_TABLE::Parse(), SYMBOL_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(), FP_LIB_TABLE::Parse(), SYMBOL_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 321 of file pcb_lexer.h.

References DSNLEXER::NeedSYMBOL().

322  {
324  }
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 334 of file pcb_lexer.h.

References DSNLEXER::NeedSYMBOLorNUMBER().

335  {
337  }
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 308 of file pcb_lexer.h.

References DSNLEXER::NextTok().

Referenced by parseHex().

309  {
310  return (PCB_KEYS_T::T) DSNLEXER::NextTok();
311  }
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 422 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(), CLIPBOARD_IO::Load(), PCB_IO::Load(), FP_CACHE::Load(), and PCB_IO::Parse().

423 {
424  T token;
425  BOARD_ITEM* item;
426  LOCALE_IO toggle;
427 
428  // MODULEs can be prefixed with an initial block of single line comments and these
429  // are kept for Format() so they round trip in s-expression form. BOARDs might
430  // eventually do the same, but currently do not.
431  std::unique_ptr<wxArrayString> initial_comments( ReadCommentLines() );
432 
433  token = CurTok();
434 
435  if( token != T_LEFT )
436  Expecting( T_LEFT );
437 
438  switch( NextTok() )
439  {
440  case T_kicad_pcb:
441  if( m_board == NULL )
442  m_board = new BOARD();
443 
444  item = (BOARD_ITEM*) parseBOARD();
445  break;
446 
447  case T_module:
448  item = (BOARD_ITEM*) parseMODULE( initial_comments.release() );
449  break;
450 
451  default:
452  wxString err;
453  err.Printf( _( "unknown token \"%s\"" ), GetChars( FromUTF8() ) );
455  }
456 
457  return item;
458 }
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:308
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
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:461
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:343
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:70
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.
MODULE_3D_SETTINGS * PCB_PARSER::parse3DModel ( )
private

Definition at line 335 of file pcb_parser.cpp.

References MODULE_3D_SETTINGS::m_Filename, MODULE_3D_SETTINGS::m_Offset, MODULE_3D_SETTINGS::m_Rotation, MODULE_3D_SETTINGS::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, MODULE_3D_SETTINGS::VECTOR3D::x, MODULE_3D_SETTINGS::VECTOR3D::y, and MODULE_3D_SETTINGS::VECTOR3D::z.

336 {
337  wxCHECK_MSG( CurTok() == T_model, NULL,
338  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as MODULE_3D_SETTINGS." ) );
339 
340  T token;
341 
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  /* Note:
363  * Prior to SEXPR_BOARD_FILE_VERSION 20171114,
364  * 3D model offset was read and written in inches
365  *
366  * Now, the offset is explicitly written in mm.
367  * If a board is read with an older version,
368  * the offset is converted from inches to mm
369  */
370 
371  n3D->m_Offset.x = parseDouble( "x value" );
372  n3D->m_Offset.y = parseDouble( "y value" );
373  n3D->m_Offset.z = parseDouble( "z value" );
374 
375  if(m_requiredVersion < 20171114L)
376  {
377  n3D->m_Offset.x *= 25.4f;
378  n3D->m_Offset.y *= 25.4f;
379  n3D->m_Offset.z *= 25.4f;
380  }
381 
382  NeedRIGHT();
383  break;
384 
385  case T_scale:
386  NeedLEFT();
387  token = NextTok();
388 
389  if( token != T_xyz )
390  Expecting( T_xyz );
391 
392  n3D->m_Scale.x = parseDouble( "x value" );
393  n3D->m_Scale.y = parseDouble( "y value" );
394  n3D->m_Scale.z = parseDouble( "z value" );
395  NeedRIGHT();
396  break;
397 
398  case T_rotate:
399  NeedLEFT();
400  token = NextTok();
401 
402  if( token != T_xyz )
403  Expecting( T_xyz );
404 
405  n3D->m_Rotation.x = parseDouble( "x value" );
406  n3D->m_Rotation.y = parseDouble( "y value" );
407  n3D->m_Rotation.z = parseDouble( "z value" );
408  NeedRIGHT();
409  break;
410 
411  default:
412  Expecting( "at, scale, or rotate" );
413  }
414 
415  NeedRIGHT();
416  }
417 
418  return n3D;
419 }
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:308
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:343
VECTOR3D m_Offset
3D model offset (mm)
Definition: class_module.h:100
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
wxString m_Filename
The 3D shape filename in 3D library.
Definition: class_module.h:101
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:75
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:334
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition: class_module.h:99
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
Definition: class_module.h:98
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
BOARD * PCB_PARSER::parseBOARD ( )
private

Definition at line 461 of file pcb_parser.cpp.

462 {
463  try
464  {
465  return parseBOARD_unchecked();
466  }
467  catch( const PARSE_ERROR& parse_error )
468  {
469  if( m_tooRecent )
470  throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
471  else
472  throw;
473  }
474 }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:74
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:477
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 477 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.

478 {
479  T token;
480 
481  parseHeader();
482 
483  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
484  {
485  if( token != T_LEFT )
486  Expecting( T_LEFT );
487 
488  token = NextTok();
489 
490  switch( token )
491  {
492  case T_general:
494  break;
495 
496  case T_page:
497  parsePAGE_INFO();
498  break;
499 
500  case T_title_block:
502  break;
503 
504  case T_layers:
505  parseLayers();
506  break;
507 
508  case T_setup:
509  parseSetup();
510  break;
511 
512  case T_net:
514  break;
515 
516  case T_net_class:
517  parseNETCLASS();
518  break;
519 
520  case T_gr_arc:
521  case T_gr_circle:
522  case T_gr_curve:
523  case T_gr_line:
524  case T_gr_poly:
526  break;
527 
528  case T_gr_text:
530  break;
531 
532  case T_dimension:
534  break;
535 
536  case T_module:
538  break;
539 
540  case T_segment:
542  break;
543 
544  case T_via:
546  break;
547 
548  case T_zone:
550  break;
551 
552  case T_target:
554  break;
555 
556  default:
557  wxString err;
558  err.Printf( _( "unknown token \"%s\"" ), GetChars( FromUTF8() ) );
560  }
561  }
562 
563  return m_board;
564 }
void parseHeader()
Definition: pcb_parser.cpp:567
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:308
TRACK * parseTRACK()
VIA * parseVIA()
void parseNETINFO_ITEM()
DIMENSION * parseDIMENSION()
void parseTITLE_BLOCK()
Definition: pcb_parser.cpp:705
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:830
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
void parsePAGE_INFO()
Definition: pcb_parser.cpp:649
#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:70
void parseGeneralSection()
Definition: pcb_parser.cpp:603
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()
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 976 of file pcb_parser.cpp.

References PCB_KEYS_T::T_layer, and UNDEFINED_LAYER.

977 {
978  wxCHECK_MSG( CurTok() == T_layer, UNDEFINED_LAYER,
979  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layer." ) );
980 
981  NextTok();
982 
983  PCB_LAYER_ID layerIndex = lookUpLayer<PCB_LAYER_ID>( m_layerIndices );
984 
985  // Handle closing ) in object parser.
986 
987  return layerIndex;
988 }
PCB_KEYS_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
Definition: pcb_lexer.h:308
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:71
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 991 of file pcb_parser.cpp.

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

992 {
993  wxCHECK_MSG( CurTok() == T_layers, LSET(),
994  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
995  wxT( " as item layer mask." ) );
996 
997  LSET layerMask;
998 
999  for( T token = NextTok(); token != T_RIGHT; token = NextTok() )
1000  {
1001  LSET mask = lookUpLayer<LSET>( m_layerMasks );
1002  layerMask |= mask;
1003  }
1004 
1005  return layerMask;
1006 }
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:308
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:72
int PCB_PARSER::parseBoardUnits ( )
inlineprivate

Definition at line 223 of file pcb_parser.h.

References KiROUND(), and parseDouble().

Referenced by parseBoardUnits().

224  {
225  // There should be no major rounding issues here, since the values in
226  // the file are in mm and get converted to nano-meters.
227  // See test program tools/test-nm-biu-to-ascii-mm-round-tripping.cpp
228  // to confirm or experiment. Use a similar strategy in both places, here
229  // and in the test program. Make that program with:
230  // $ make test-nm-biu-to-ascii-mm-round-tripping
231  return KiROUND( parseDouble() * IU_PER_MM );
232  }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
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 234 of file pcb_parser.h.

References KiROUND(), and parseDouble().

235  {
236  // Use here KiROUND, not KIROUND (see comments about them)
237  // when having a function as argument, because it will be called twice
238  // with KIROUND
239  return KiROUND( parseDouble( aExpected ) * IU_PER_MM );
240  }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
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 242 of file pcb_parser.h.

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

243  {
244  return parseBoardUnits( GetTokenText( aToken ) );
245  }
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:223
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:308
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 2258 of file pcb_parser.cpp.

References delta, Format(), DRAWSEGMENT::GetAngle(), DRAWSEGMENT::GetArcStart(), DRAWSEGMENT::GetCenter(), GetChars(), DRAWSEGMENT::GetEnd(), DRAWSEGMENT::GetPolyPoints(), DRAWSEGMENT::GetRadius(), DRAWSEGMENT::GetStart(), DRAWSEGMENT::GetWidth(), PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, PAD_DRILL_SHAPE_OBLONG, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, 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_custom, PCB_KEYS_T::T_die_length, PCB_KEYS_T::T_drill, PCB_KEYS_T::T_gr_arc, PCB_KEYS_T::T_gr_circle, PCB_KEYS_T::T_gr_line, PCB_KEYS_T::T_gr_poly, 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_options, PCB_KEYS_T::T_oval, PCB_KEYS_T::T_pad, PCB_KEYS_T::T_primitives, 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.

2259 {
2260  wxCHECK_MSG( CurTok() == T_pad, NULL,
2261  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as D_PAD." ) );
2262 
2263  wxSize sz;
2264  wxPoint pt;
2265 
2266  std::unique_ptr< D_PAD > pad( new D_PAD( aParent ) );
2267 
2269  pad->SetName( FromUTF8() );
2270 
2271  T token = NextTok();
2272 
2273  switch( token )
2274  {
2275  case T_thru_hole:
2276  pad->SetAttribute( PAD_ATTRIB_STANDARD );
2277  break;
2278 
2279  case T_smd:
2280  pad->SetAttribute( PAD_ATTRIB_SMD );
2281 
2282  // Default D_PAD object is thru hole with drill.
2283  // SMD pads have no hole
2284  pad->SetDrillSize( wxSize( 0, 0 ) );
2285  break;
2286 
2287  case T_connect:
2288  pad->SetAttribute( PAD_ATTRIB_CONN );
2289 
2290  // Default D_PAD object is thru hole with drill.
2291  // CONN pads have no hole
2292  pad->SetDrillSize( wxSize( 0, 0 ) );
2293  break;
2294 
2295  case T_np_thru_hole:
2296  pad->SetAttribute( PAD_ATTRIB_HOLE_NOT_PLATED );
2297  break;
2298 
2299  default:
2300  Expecting( "thru_hole, smd, connect, or np_thru_hole" );
2301  }
2302 
2303  token = NextTok();
2304 
2305  switch( token )
2306  {
2307  case T_circle:
2308  pad->SetShape( PAD_SHAPE_CIRCLE );
2309  break;
2310 
2311  case T_rect:
2312  pad->SetShape( PAD_SHAPE_RECT );
2313  break;
2314 
2315  case T_oval:
2316  pad->SetShape( PAD_SHAPE_OVAL );
2317  break;
2318 
2319  case T_trapezoid:
2320  pad->SetShape( PAD_SHAPE_TRAPEZOID );
2321  break;
2322 
2323  case T_roundrect:
2324  pad->SetShape( PAD_SHAPE_ROUNDRECT );
2325  break;
2326 
2327  case T_custom:
2328  pad->SetShape( PAD_SHAPE_CUSTOM );
2329  break;
2330 
2331  default:
2332  Expecting( "circle, rectangle, roundrect, oval, trapezoid or custom" );
2333  }
2334 
2335  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2336  {
2337  if( token != T_LEFT )
2338  Expecting( T_LEFT );
2339 
2340  token = NextTok();
2341 
2342  switch( token )
2343  {
2344  case T_size:
2345  sz.SetWidth( parseBoardUnits( "width value" ) );
2346  sz.SetHeight( parseBoardUnits( "height value" ) );
2347  pad->SetSize( sz );
2348  NeedRIGHT();
2349  break;
2350 
2351  case T_at:
2352  pt.x = parseBoardUnits( "X coordinate" );
2353  pt.y = parseBoardUnits( "Y coordinate" );
2354  pad->SetPos0( pt );
2355  token = NextTok();
2356 
2357  if( token == T_NUMBER )
2358  {
2359  pad->SetOrientation( parseDouble() * 10.0 );
2360  NeedRIGHT();
2361  }
2362  else if( token != T_RIGHT )
2363  {
2364  Expecting( ") or angle value" );
2365  }
2366 
2367  break;
2368 
2369  case T_rect_delta:
2370  {
2371  wxSize delta;
2372  delta.SetWidth( parseBoardUnits( "rectangle delta width" ) );
2373  delta.SetHeight( parseBoardUnits( "rectangle delta height" ) );
2374  pad->SetDelta( delta );
2375  NeedRIGHT();
2376  }
2377  break;
2378 
2379  case T_drill:
2380  {
2381  bool haveWidth = false;
2382  wxSize drillSize = pad->GetDrillSize();
2383 
2384  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2385  {
2386  if( token == T_LEFT )
2387  token = NextTok();
2388 
2389  switch( token )
2390  {
2391  case T_oval:
2392  pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
2393  break;
2394 
2395  case T_NUMBER:
2396  {
2397  if( !haveWidth )
2398  {
2399  drillSize.SetWidth( parseBoardUnits() );
2400 
2401  // If height is not defined the width and height are the same.
2402  drillSize.SetHeight( drillSize.GetWidth() );
2403  haveWidth = true;
2404  }
2405  else
2406  {
2407  drillSize.SetHeight( parseBoardUnits() );
2408  }
2409 
2410  }
2411  break;
2412 
2413  case T_offset:
2414  pt.x = parseBoardUnits( "drill offset x" );
2415  pt.y = parseBoardUnits( "drill offset y" );
2416  pad->SetOffset( pt );
2417  NeedRIGHT();
2418  break;
2419 
2420  default:
2421  Expecting( "oval, size, or offset" );
2422  }
2423  }
2424 
2425  // This fixes a bug caused by setting the default D_PAD drill size to a value
2426  // other than 0 used to fix a bunch of debug assertions even though it is defined
2427  // as a through hole pad. Wouldn't a though hole pad with no drill be a surface
2428  // mount pad (or a conn pad which is a smd pad with no solder paste)?
2429  if( ( pad->GetAttribute() != PAD_ATTRIB_SMD ) && ( pad->GetAttribute() != PAD_ATTRIB_CONN ) )
2430  pad->SetDrillSize( drillSize );
2431  else
2432  pad->SetDrillSize( wxSize( 0, 0 ) );
2433 
2434  }
2435  break;
2436 
2437  case T_layers:
2438  {
2439  LSET layerMask = parseBoardItemLayersAsMask();
2440  pad->SetLayerSet( layerMask );
2441  }
2442  break;
2443 
2444  case T_net:
2445  if( ! pad->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) )
2447  wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ),
2449  );
2451  if( m_board && FromUTF8() != m_board->FindNet( pad->GetNetCode() )->GetNetname() )
2453  wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ),
2455  );
2456  NeedRIGHT();
2457  break;
2458 
2459  case T_die_length:
2460  pad->SetPadToDieLength( parseBoardUnits( T_die_length ) );
2461  NeedRIGHT();
2462  break;
2463 
2464  case T_solder_mask_margin:
2465  pad->SetLocalSolderMaskMargin( parseBoardUnits( T_solder_mask_margin ) );
2466  NeedRIGHT();
2467  break;
2468 
2469  case T_solder_paste_margin:
2470  pad->SetLocalSolderPasteMargin( parseBoardUnits( T_solder_paste_margin ) );
2471  NeedRIGHT();
2472  break;
2473 
2475  pad->SetLocalSolderPasteMarginRatio(
2476  parseDouble( "pad local solder paste margin ratio value" ) );
2477  NeedRIGHT();
2478  break;
2479 
2480  case T_clearance:
2481  pad->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
2482  NeedRIGHT();
2483  break;
2484 
2485  case T_zone_connect:
2486  pad->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
2487  NeedRIGHT();
2488  break;
2489 
2490  case T_thermal_width:
2491  pad->SetThermalWidth( parseBoardUnits( T_thermal_width ) );
2492  NeedRIGHT();
2493  break;
2494 
2495  case T_thermal_gap:
2496  pad->SetThermalGap( parseBoardUnits( T_thermal_gap ) );
2497  NeedRIGHT();
2498  break;
2499 
2500  case T_roundrect_rratio:
2501  pad->SetRoundRectRadiusRatio( parseDouble( "roundrect radius ratio" ) );
2502  NeedRIGHT();
2503  break;
2504 
2505  case T_options:
2506  parseD_PAD_option( pad.get() );
2507  break;
2508 
2509  case T_primitives:
2510  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2511  {
2512  if( token == T_LEFT )
2513  token = NextTok();
2514 
2515  // Currently, I am using parseDRAWSEGMENT() to read basic shapes parameters,
2516  // because they are the same as a DRAWSEGMENT.
2517  // However it could be better to write a specific parser, to avoid possible issues
2518  // if the DRAWSEGMENT parser is modified.
2519  DRAWSEGMENT* dummysegm = NULL;
2520 
2521  switch( token )
2522  {
2523  case T_gr_arc:
2524  dummysegm = parseDRAWSEGMENT();
2525  pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetArcStart(),
2526  dummysegm->GetAngle(), dummysegm->GetWidth() );
2527  break;
2528 
2529  case T_gr_line:
2530  dummysegm = parseDRAWSEGMENT();
2531  pad->AddPrimitive( dummysegm->GetStart(), dummysegm->GetEnd(),
2532  dummysegm->GetWidth() );
2533  break;
2534 
2535  case T_gr_circle:
2536  dummysegm = parseDRAWSEGMENT();
2537  pad->AddPrimitive( dummysegm->GetCenter(), dummysegm->GetRadius(),
2538  dummysegm->GetWidth() );
2539  break;
2540 
2541  case T_gr_poly:
2542  dummysegm = parseDRAWSEGMENT();
2543  pad->AddPrimitive( dummysegm->GetPolyPoints(), dummysegm->GetWidth() );
2544  break;
2545 
2546  default:
2547  Expecting( "gr_line, gr_arc, gr_circle or gr_poly" );
2548  break;
2549  }
2550 
2551  delete dummysegm;
2552  }
2553  break;
2554 
2555  default:
2556  Expecting( "at, drill, layers, net, die_length, solder_mask_margin, roundrect_rratio,\n"
2557  "solder_paste_margin, solder_paste_margin_ratio, clearance,\n"
2558  "zone_connect, fp_poly, primitives, thermal_width, or thermal_gap" );
2559  }
2560  }
2561 
2562  // Be sure the custom shape polygon is built:
2563  if( pad->GetShape() == PAD_SHAPE_CUSTOM )
2564  pad->MergePrimitivesAsPolygon();
2565 
2566  return pad.release();
2567 }
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:308
LSET parseBoardItemLayersAsMask()
Function parseBoardItemLayersAsMask parses the layers definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:991
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
const wxPoint GetCenter() const override
Function GetCenter()
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:61
bool parseD_PAD_option(D_PAD *aPad)
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
const std::vector< wxPoint > GetPolyPoints() const
static const int delta[8][2]
Definition: solve.cpp:112
int parseBoardUnits()
Definition: pcb_parser.h:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
const wxPoint & GetArcStart() const
Class LSET is a set of PCB_LAYER_IDs.
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
DRAWSEGMENT * parseDRAWSEGMENT()
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
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:62
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:334
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
double GetAngle() const
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:79
BOARD * m_board
Definition: pcb_parser.h:70
Usual pad.
Definition: pad_shapes.h:60
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.
int GetWidth() const
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:247
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
bool PCB_PARSER::parseD_PAD_option ( D_PAD aPad)
private

Definition at line 2570 of file pcb_parser.cpp.

References CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL, CUST_PAD_SHAPE_IN_ZONE_OUTLINE, PAD_SHAPE_RECT, D_PAD::SetAnchorPadShape(), D_PAD::SetCustomShapeInZoneOpt(), PCB_KEYS_T::T_anchor, PCB_KEYS_T::T_circle, PCB_KEYS_T::T_clearance, PCB_KEYS_T::T_convexhull, PCB_KEYS_T::T_LEFT, PCB_KEYS_T::T_outline, PCB_KEYS_T::T_rect, and PCB_KEYS_T::T_RIGHT.

2571 {
2572  // Parse only the (option ...) inside a pad description
2573  for( T token = NextTok(); token != T_RIGHT; token = NextTok() )
2574  {
2575  if( token != T_LEFT )
2576  Expecting( T_LEFT );
2577 
2578  token = NextTok();
2579 
2580  switch( token )
2581  {
2582  case T_anchor:
2583  token = NextTok();
2584  // Custom shaped pads have a "anchor pad", which is the reference
2585  // for connection calculations.
2586  // Because this is an anchor, only the 2 very basic shapes are managed:
2587  // circle and rect. The default is circle
2588  switch( token )
2589  {
2590  case T_circle: // default
2591  break;
2592 
2593  case T_rect:
2595  break;
2596 
2597  default:
2598  // Currently, because pad options is a moving target
2599  // just skip unknown keywords
2600  break;
2601  }
2602  NeedRIGHT();
2603  break;
2604 
2605  case T_clearance:
2606  token = NextTok();
2607  // Custom shaped pads have a clearance area that is the pad shape
2608  // (like usual pads) or the convew hull of the pad shape.
2609  switch( token )
2610  {
2611  case T_outline:
2613  break;
2614 
2615  case T_convexhull:
2617  break;
2618 
2619  default:
2620  // Currently, because pad options is a moving target
2621  // just skip unknown keywords
2622  break;
2623  }
2624  NeedRIGHT();
2625  break;
2626 
2627  default:
2628  // Currently, because pad options is a moving target
2629  // just skip unknown keywords
2630  while( (token = NextTok() ) != T_RIGHT )
2631  {}
2632  break;
2633  }
2634  }
2635 
2636  return true;
2637 }
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:308
void SetAnchorPadShape(PAD_SHAPE_T aShape)
Function SetAnchorPadShape Set the shape of the anchor pad for custm shped pads.
Definition: class_pad.h:253
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 NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
void SetCustomShapeInZoneOpt(CUST_PAD_SHAPE_IN_ZONE aOption)
Set the option for the custom pad shape to use as clearance area in copper zones. ...
Definition: class_pad.h:242
DIMENSION * PCB_PARSER::parseDIMENSION ( )
private

Definition at line 1586 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.

1587 {
1588  wxCHECK_MSG( CurTok() == T_dimension, NULL,
1589  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as DIMENSION." ) );
1590 
1591  T token;
1592 
1593  std::unique_ptr<DIMENSION> dimension( new DIMENSION( NULL ) );
1594 
1595  dimension->SetValue( parseBoardUnits( "dimension value" ) );
1596  NeedLEFT();
1597  token = NextTok();
1598 
1599  if( token != T_width )
1600  Expecting( T_width );
1601 
1602  dimension->SetWidth( parseBoardUnits( "dimension width value" ) );
1603  NeedRIGHT();
1604 
1605  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1606  {
1607  if( token != T_LEFT )
1608  Expecting( T_LEFT );
1609 
1610  token = NextTok();
1611 
1612  switch( token )
1613  {
1614  case T_layer:
1615  dimension->SetLayer( parseBoardItemLayer() );
1616  NeedRIGHT();
1617  break;
1618 
1619  case T_tstamp:
1620  dimension->SetTimeStamp( parseHex() );
1621  NeedRIGHT();
1622  break;
1623 
1624  case T_gr_text:
1625  {
1626  TEXTE_PCB* text = parseTEXTE_PCB();
1627  dimension->Text() = *text;
1628  dimension->SetPosition( text->GetTextPos() );
1629  delete text;
1630  break;
1631  }
1632 
1633  case T_feature1:
1634  NeedLEFT();
1635  token = NextTok();
1636 
1637  if( token != T_pts )
1638  Expecting( T_pts );
1639 
1640  parseXY( &dimension->m_featureLineDO.x, &dimension->m_featureLineDO.y );
1641  parseXY( &dimension->m_featureLineDF.x, &dimension->m_featureLineDF.y );
1642  dimension->UpdateHeight();
1643  NeedRIGHT();
1644  NeedRIGHT();
1645  break;
1646 
1647  case T_feature2:
1648  NeedLEFT();
1649  token = NextTok();
1650 
1651  if( token != T_pts )
1652  Expecting( T_pts );
1653 
1654  parseXY( &dimension->m_featureLineGO.x, &dimension->m_featureLineGO.y );
1655  parseXY( &dimension->m_featureLineGF.x, &dimension->m_featureLineGF.y );
1656  dimension->UpdateHeight();
1657  NeedRIGHT();
1658  NeedRIGHT();
1659  break;
1660 
1661 
1662  case T_crossbar:
1663  NeedLEFT();
1664  token = NextTok();
1665 
1666  if( token != T_pts )
1667  Expecting( T_pts );
1668 
1669  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1670  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1671  dimension->UpdateHeight();
1672  NeedRIGHT();
1673  NeedRIGHT();
1674  break;
1675 
1676  case T_arrow1a:
1677  NeedLEFT();
1678  token = NextTok();
1679 
1680  if( token != T_pts )
1681  Expecting( T_pts );
1682 
1683  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1684  parseXY( &dimension->m_arrowD1F.x, &dimension->m_arrowD1F.y );
1685  NeedRIGHT();
1686  NeedRIGHT();
1687  break;
1688 
1689  case T_arrow1b:
1690  NeedLEFT();
1691  token = NextTok();
1692 
1693  if( token != T_pts )
1694  Expecting( T_pts );
1695 
1696  parseXY( &dimension->m_crossBarF.x, &dimension->m_crossBarF.y );
1697  parseXY( &dimension->m_arrowD2F.x, &dimension->m_arrowD2F.y );
1698  NeedRIGHT();
1699  NeedRIGHT();
1700  break;
1701 
1702  case T_arrow2a:
1703  NeedLEFT();
1704  token = NextTok();
1705 
1706  if( token != T_pts )
1707  Expecting( T_pts );
1708 
1709  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1710  parseXY( &dimension->m_arrowG1F.x, &dimension->m_arrowG1F.y );
1711  NeedRIGHT();
1712  NeedRIGHT();
1713  break;
1714 
1715  case T_arrow2b:
1716  NeedLEFT();
1717  token = NextTok();
1718 
1719  if( token != T_pts )
1720  Expecting( T_pts );
1721 
1722  parseXY( &dimension->m_crossBarO.x, &dimension->m_crossBarO.y );
1723  parseXY( &dimension->m_arrowG2F.x, &dimension->m_arrowG2F.y );
1724  NeedRIGHT();
1725  NeedRIGHT();
1726  break;
1727 
1728  default:
1729  Expecting( "layer, tstamp, gr_text, feature1, feature2 crossbar, arrow1a, "
1730  "arrow1b, arrow2a, or arrow2b" );
1731  }
1732  }
1733 
1734  return dimension.release();
1735 }
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:308
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:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:976
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:258
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
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
double PCB_PARSER::parseDouble ( const char *  aExpected)
inlineprivate

Definition at line 212 of file pcb_parser.h.

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

213  {
214  NeedNUMBER( aExpected );
215  return parseDouble();
216  }
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 218 of file pcb_parser.h.

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

219  {
220  return parseDouble( GetTokenText( aToken ) );
221  }
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 1353 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.

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

2090 {
2091  wxCHECK_MSG( CurTok() == T_fp_arc || CurTok() == T_fp_circle || CurTok() == T_fp_curve ||
2092  CurTok() == T_fp_line || CurTok() == T_fp_poly, NULL,
2093  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDGE_MODULE." ) );
2094 
2095  wxPoint pt;
2096  T token;
2097 
2098  std::unique_ptr< EDGE_MODULE > segment( new EDGE_MODULE( NULL ) );
2099 
2100  switch( CurTok() )
2101  {
2102  case T_fp_arc:
2103  segment->SetShape( S_ARC );
2104  NeedLEFT();
2105  token = NextTok();
2106 
2107  // the start keyword actually gives the arc center
2108  // Allows also T_center for future change
2109  if( token != T_start && token != T_center )
2110  Expecting( T_start );
2111 
2112  pt.x = parseBoardUnits( "X coordinate" );
2113  pt.y = parseBoardUnits( "Y coordinate" );
2114  segment->SetStart0( pt );
2115  NeedRIGHT();
2116  NeedLEFT();
2117  token = NextTok();
2118 
2119  if( token != T_end ) // end keyword actually gives the starting point of the arc
2120  Expecting( T_end );
2121 
2122  pt.x = parseBoardUnits( "X coordinate" );
2123  pt.y = parseBoardUnits( "Y coordinate" );
2124  segment->SetEnd0( pt );
2125  NeedRIGHT();
2126  NeedLEFT();
2127  token = NextTok();
2128 
2129  if( token != T_angle )
2130  Expecting( T_angle );
2131 
2132  segment->SetAngle( parseDouble( "segment angle" ) * 10.0 );
2133  NeedRIGHT();
2134  break;
2135 
2136  case T_fp_circle:
2137  segment->SetShape( S_CIRCLE );
2138  NeedLEFT();
2139  token = NextTok();
2140 
2141  if( token != T_center )
2142  Expecting( T_center );
2143 
2144  pt.x = parseBoardUnits( "X coordinate" );
2145  pt.y = parseBoardUnits( "Y coordinate" );
2146  segment->SetStart0( pt );
2147  NeedRIGHT();
2148  NeedLEFT();
2149  token = NextTok();
2150 
2151  if( token != T_end )
2152  Expecting( T_end );
2153 
2154  pt.x = parseBoardUnits( "X coordinate" );
2155  pt.y = parseBoardUnits( "Y coordinate" );
2156  segment->SetEnd0( pt );
2157  NeedRIGHT();
2158  break;
2159 
2160  case T_fp_curve:
2161  segment->SetShape( S_CURVE );
2162  NeedLEFT();
2163  token = NextTok();
2164 
2165  if( token != T_pts )
2166  Expecting( T_pts );
2167 
2168  segment->SetStart0( parseXY() );
2169  segment->SetBezControl1( parseXY() );
2170  segment->SetBezControl2( parseXY() );
2171  segment->SetEnd0( parseXY() );
2172  NeedRIGHT();
2173  break;
2174 
2175  case T_fp_line:
2176  // Default DRAWSEGMENT type is S_SEGMENT.
2177  NeedLEFT();
2178  token = NextTok();
2179 
2180  if( token != T_start )
2181  Expecting( T_start );
2182 
2183  pt.x = parseBoardUnits( "X coordinate" );
2184  pt.y = parseBoardUnits( "Y coordinate" );
2185  segment->SetStart0( pt );
2186 
2187  NeedRIGHT();
2188  NeedLEFT();
2189  token = NextTok();
2190 
2191  if( token != T_end )
2192  Expecting( T_end );
2193 
2194  pt.x = parseBoardUnits( "X coordinate" );
2195  pt.y = parseBoardUnits( "Y coordinate" );
2196  segment->SetEnd0( pt );
2197  NeedRIGHT();
2198  break;
2199 
2200  case T_fp_poly:
2201  {
2202  segment->SetShape( S_POLYGON );
2203  NeedLEFT();
2204  token = NextTok();
2205 
2206  if( token != T_pts )
2207  Expecting( T_pts );
2208 
2209  std::vector< wxPoint > pts;
2210 
2211  while( (token = NextTok()) != T_RIGHT )
2212  pts.push_back( parseXY() );
2213 
2214  segment->SetPolyPoints( pts );
2215  }
2216  break;
2217 
2218  default:
2219  Expecting( "fp_arc, fp_circle, fp_curve, fp_line, or fp_poly" );
2220  }
2221 
2222  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
2223  {
2224  if( token != T_LEFT )
2225  Expecting( T_LEFT );
2226 
2227  token = NextTok();
2228 
2229  switch( token )
2230  {
2231  case T_layer:
2232  segment->SetLayer( parseBoardItemLayer() );
2233  break;
2234 
2235  case T_width:
2236  segment->SetWidth( parseBoardUnits( T_width ) );
2237  break;
2238 
2239  case T_tstamp:
2240  segment->SetTimeStamp( parseHex() );
2241  break;
2242 
2243  case T_status:
2244  segment->SetStatus( static_cast<STATUS_FLAGS>( parseHex() ) );
2245  break;
2246 
2247  default:
2248  Expecting( "layer or width" );
2249  }
2250 
2251  NeedRIGHT();
2252  }
2253 
2254  return segment.release();
2255 }
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:308
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:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:976
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:258
void PCB_PARSER::parseGeneralSection ( )
private

Definition at line 603 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.

604 {
605  wxCHECK_RET( CurTok() == T_general,
606  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
607  wxT( " as a general section." ) );
608 
609  T token;
610 
611  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
612  {
613  if( token != T_LEFT )
614  Expecting( T_LEFT );
615 
616  token = NextTok();
617 
618  switch( token )
619  {
620  case T_thickness:
622  NeedRIGHT();
623  break;
624 
625  case T_nets:
626  m_netCodes.resize( parseInt( "nets number" ) );
627  NeedRIGHT();
628  break;
629 
630  case T_no_connects:
631  // ignore
632  parseInt( "no connect count" );
633  NeedRIGHT();
634  break;
635 
636  default: // Skip everything but the board thickness.
637  //wxLogDebug( wxT( "Skipping general section token %s " ), GetChars( GetTokenString( token ) ) );
638 
639  while( ( token = NextTok() ) != T_RIGHT )
640  {
641  if( !IsSymbol( token ) && token != T_NUMBER )
642  Expecting( "symbol or number" );
643  }
644  }
645  }
646 }
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:308
void SetBoardThickness(int aThickness)
int parseBoardUnits()
Definition: pcb_parser.h:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:532
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:73
BOARD * m_board
Definition: pcb_parser.h:70
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:247
void PCB_PARSER::parseHeader ( )
private

Definition at line 567 of file pcb_parser.cpp.

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

568 {
569  wxCHECK_RET( CurTok() == T_kicad_pcb,
570  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a header." ) );
571 
572  NeedLEFT();
573 
574  T tok = NextTok();
575  if( tok == T_version )
576  {
577  m_requiredVersion = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
579  NeedRIGHT();
580 
581  // Skip the host name and host build version information.
582  NeedLEFT();
583  NeedSYMBOL();
584  NeedSYMBOL();
585  NeedSYMBOL();
586  NeedRIGHT();
587  }
588  else
589  {
592 
593  // Skip the host name and host build version information.
594  NeedSYMBOL();
595  NeedSYMBOL();
596  NeedRIGHT();
597  }
598 
600 }
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:308
#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:74
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:343
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:321
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:75
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
BOARD * m_board
Definition: pcb_parser.h:70
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:247
long PCB_PARSER::parseHex ( )
inlineprivate

Definition at line 258 of file pcb_parser.h.

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

259  {
260  NextTok();
261  return strtol( CurText(), NULL, 16 );
262  }
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:308
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 247 of file pcb_parser.h.

References DSNLEXER::CurText().

Referenced by parseInt().

248  {
249  return (int)strtol( CurText(), NULL, 10 );
250  }
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 252 of file pcb_parser.h.

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

253  {
254  NeedNUMBER( aExpected );
255  return parseInt();
256  }
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:247
void PCB_PARSER::parseLayer ( LAYER aLayer)
private

Definition at line 788 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.

789 {
790  T token;
791 
792  std::string name;
793  std::string type;
794  bool isVisible = true;
795 
796  aLayer->clear();
797 
798  if( CurTok() != T_LEFT )
799  Expecting( T_LEFT );
800 
801  // this layer_num is not used, we DO depend on LAYER_T however.
802  LAYER_NUM layer_num = parseInt( "layer index" );
803 
805  name = CurText();
806 
807  NeedSYMBOL();
808  type = CurText();
809 
810  token = NextTok();
811 
812  if( token == T_hide )
813  {
814  isVisible = false;
815  NeedRIGHT();
816  }
817  else if( token != T_RIGHT )
818  {
819  Expecting( "hide or )" );
820  }
821 
822  aLayer->m_name = FROM_UTF8( name.c_str() );
823  aLayer->m_type = LAYER::ParseType( type.c_str() );
824  aLayer->m_number = layer_num;
825  aLayer->m_visible = isVisible;
826 }
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:308
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:343
PCB_KEYS_T::T NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: pcb_lexer.h:321
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:334
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:247
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 830 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.

831 {
832  wxCHECK_RET( CurTok() == T_layers,
833  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layers." ) );
834 
835  T token;
836  LSET visibleLayers;
837  LSET enabledLayers;
838  int copperLayerCount = 0;
839  LAYER layer;
840 
841  std::vector<LAYER> cu;
842 
843  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
844  {
845  parseLayer( &layer );
846 
847  if( layer.m_type == LT_UNDEFINED ) // it's a non-copper layer
848  break;
849 
850  cu.push_back( layer ); // it's copper
851  }
852 
853  // All Cu layers are parsed, but not the non-cu layers here.
854 
855  // The original *.kicad_pcb file format and the inverted
856  // Cu stack format both have all the Cu layers first, so use this
857  // trick to handle either. The layer number in the (layers ..)
858  // s-expression element are ignored.
859  if( cu.size() )
860  {
861  // Rework the layer numbers, which changed when the Cu stack
862  // was flipped. So we instead use position in the list.
863  cu[cu.size()-1].m_number = B_Cu;
864 
865  for( unsigned i=0; i < cu.size()-1; ++i )
866  {
867  cu[i].m_number = i;
868  }
869 
870  for( std::vector<LAYER>::const_iterator it = cu.begin(); it<cu.end(); ++it )
871  {
872  enabledLayers.set( it->m_number );
873 
874  if( it->m_visible )
875  visibleLayers.set( it->m_number );
876 
877  m_board->SetLayerDescr( PCB_LAYER_ID( it->m_number ), *it );
878 
879  UTF8 name = it->m_name;
880 
881  m_layerIndices[ name ] = PCB_LAYER_ID( it->m_number );
882  m_layerMasks[ name ] = LSET( PCB_LAYER_ID( it->m_number ) );
883  }
884 
885  copperLayerCount = cu.size();
886  }
887 
888  // process non-copper layers
889  while( token != T_RIGHT )
890  {
891  LAYER_ID_MAP::const_iterator it = m_layerIndices.find( UTF8( layer.m_name ) );
892 
893  if( it == m_layerIndices.end() )
894  {
895  wxString error = wxString::Format(
896  _( "Layer '%s' in file '%s' at line %d, is not in fixed layer hash" ),
897  GetChars( layer.m_name ),
898  GetChars( CurSource() ),
899  CurLineNumber(),
900  CurOffset()
901  );
902 
903  THROW_IO_ERROR( error );
904  }
905 
906  layer.m_number = it->second;
907 
908  enabledLayers.set( layer.m_number );
909 
910  if( layer.m_visible )
911  visibleLayers.set( layer.m_number );
912 
913  // DBG( printf( "aux m_visible:%s\n", layer.m_visible ? "true" : "false" );)
914 
915  m_board->SetLayerDescr( it->second, layer );
916 
917  token = NextTok();
918 
919  if( token != T_LEFT )
920  break;
921 
922  parseLayer( &layer );
923  }
924 
925  // We need at least 2 copper layers and there must be an even number of them.
926  if( copperLayerCount < 2 || (copperLayerCount % 2) != 0 )
927  {
928  wxString err = wxString::Format(
929  _( "%d is not a valid layer count" ), copperLayerCount );
930 
932  }
933 
934  m_board->SetCopperLayerCount( copperLayerCount );
935  m_board->SetEnabledLayers( enabledLayers );
936 
937  // call SetEnabledLayers before SetVisibleLayers()
938  m_board->SetVisibleLayers( visibleLayers );
939 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
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:308
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:343
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
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:788
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:70
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:71
int m_number
Definition: class_board.h:117
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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:72
MODULE * PCB_PARSER::parseMODULE ( wxArrayString *  aInitialComments = 0)

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 1738 of file pcb_parser.cpp.

Referenced by CLIPBOARD_PARSER::parseMODULE().

1739 {
1740  try
1741  {
1742  return parseMODULE_unchecked( aInitialComments );
1743  }
1744  catch( const PARSE_ERROR& parse_error )
1745  {
1746  if( m_tooRecent )
1747  throw FUTURE_FORMAT_ERROR( parse_error, GetRequiredVersion() );
1748  else
1749  throw;
1750  }
1751 }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:74
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 1754 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, wxPoint::x, and wxPoint::y.

1755 {
1756  wxCHECK_MSG( CurTok() == T_module, NULL,
1757  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as MODULE." ) );
1758 
1759  wxString name;
1760  wxPoint pt;
1761  T token;
1762  LIB_ID fpid;
1763 
1764  std::unique_ptr<MODULE> module( new MODULE( m_board ) );
1765 
1766  module->SetInitialComments( aInitialComments );
1767 
1768  token = NextTok();
1769 
1770  if( !IsSymbol( token ) && token != T_NUMBER )
1771  Expecting( "symbol|number" );
1772 
1773  name = FromUTF8();
1774 
1775  if( !name.IsEmpty() && fpid.Parse( FromUTF8() ) >= 0 )
1776  {
1777  wxString error;
1778  error.Printf( _( "invalid footprint ID in\nfile: <%s>\nline: %d\noffset: %d" ),
1780  THROW_IO_ERROR( error );
1781  }
1782 
1783  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1784  {
1785  if( token == T_LEFT )
1786  token = NextTok();
1787 
1788  switch( token )
1789  {
1790  case T_version:
1791  {
1792  // Theoretically a module nested in a PCB could declare its own version, though
1793  // as of writing this comment we don't do that. Just in case, take the greater
1794  // version.
1795  int this_version = parseInt( FromUTF8().mb_str( wxConvUTF8 ) );
1796  NeedRIGHT();
1797  m_requiredVersion = std::max( m_requiredVersion, this_version );
1799  break;
1800  }
1801 
1802  case T_locked:
1803  module->SetLocked( true );
1804  break;
1805 
1806  case T_placed:
1807  module->SetIsPlaced( true );
1808  break;
1809 
1810  case T_layer:
1811  {
1812  // Footprints can be only on the front side or the back side.
1813  // but because we can find some stupid layer in file, ensure a
1814  // acceptable layer is set for the footprint
1816  module->SetLayer( layer == B_Cu ? B_Cu : F_Cu );
1817  }
1818  NeedRIGHT();
1819  break;
1820 
1821  case T_tedit:
1822  module->SetLastEditTime( parseHex() );
1823  NeedRIGHT();
1824  break;
1825 
1826  case T_tstamp:
1827  module->SetTimeStamp( parseHex() );
1828  NeedRIGHT();
1829  break;
1830 
1831  case T_at:
1832  pt.x = parseBoardUnits( "X coordinate" );
1833  pt.y = parseBoardUnits( "Y coordinate" );
1834  module->SetPosition( pt );
1835  token = NextTok();
1836 
1837  if( token == T_NUMBER )
1838  {
1839  module->SetOrientation( parseDouble() * 10.0 );
1840  NeedRIGHT();
1841  }
1842  else if( token != T_RIGHT )
1843  {
1844  Expecting( T_RIGHT );
1845  }
1846 
1847  break;
1848 
1849  case T_descr:
1850  NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
1851  module->SetDescription( FromUTF8() );
1852  NeedRIGHT();
1853  break;
1854 
1855  case T_tags:
1856  NeedSYMBOLorNUMBER(); // some symbols can be 0508, so a number is also a symbol here
1857  module->SetKeywords( FromUTF8() );
1858  NeedRIGHT();
1859  break;
1860 
1861  case T_path:
1862  NeedSYMBOLorNUMBER(); // Paths can be numerical so a number is also a symbol here
1863  module->SetPath( FromUTF8() );
1864  NeedRIGHT();
1865  break;
1866 
1867  case T_autoplace_cost90:
1868  module->SetPlacementCost90( parseInt( "auto place cost at 90 degrees" ) );
1869  NeedRIGHT();
1870  break;
1871 
1872  case T_autoplace_cost180:
1873  module->SetPlacementCost180( parseInt( "auto place cost at 180 degrees" ) );
1874  NeedRIGHT();
1875  break;
1876 
1877  case T_solder_mask_margin:
1878  module->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin value" ) );
1879  NeedRIGHT();
1880  break;
1881 
1882  case T_solder_paste_margin:
1883  module->SetLocalSolderPasteMargin(
1884  parseBoardUnits( "local solder paste margin value" ) );
1885  NeedRIGHT();
1886  break;
1887 
1888  case T_solder_paste_ratio:
1889  module->SetLocalSolderPasteMarginRatio(
1890  parseDouble( "local solder paste margin ratio value" ) );
1891  NeedRIGHT();
1892  break;
1893 
1894  case T_clearance:
1895  module->SetLocalClearance( parseBoardUnits( "local clearance value" ) );
1896  NeedRIGHT();
1897  break;
1898 
1899  case T_zone_connect:
1900  module->SetZoneConnection( (ZoneConnection) parseInt( "zone connection value" ) );
1901  NeedRIGHT();
1902  break;
1903 
1904  case T_thermal_width:
1905  module->SetThermalWidth( parseBoardUnits( "thermal width value" ) );
1906  NeedRIGHT();
1907  break;
1908 
1909  case T_thermal_gap:
1910  module->SetThermalGap( parseBoardUnits( "thermal gap value" ) );
1911  NeedRIGHT();
1912  break;
1913 
1914  case T_attr:
1915  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1916  {
1917  switch( token )
1918  {
1919  case T_smd:
1920  module->SetAttributes( module->GetAttributes() | MOD_CMS );
1921  break;
1922 
1923  case T_virtual:
1924  module->SetAttributes( module->GetAttributes() | MOD_VIRTUAL );
1925  break;
1926 
1927  default:
1928  Expecting( "smd and/or virtual" );
1929  }
1930  }
1931  break;
1932 
1933  case T_fp_text:
1934  {
1935  TEXTE_MODULE* text = parseTEXTE_MODULE();
1936  text->SetParent( module.get() );
1937  double orientation = text->GetTextAngle();
1938  orientation -= module->GetOrientation();
1939  text->SetTextAngle( orientation );
1940  text->SetDrawCoord();
1941 
1942  switch( text->GetType() )
1943  {
1945  module->Reference() = *text;
1946  delete text;
1947  break;
1948 
1950  module->Value() = *text;
1951  delete text;
1952  break;
1953 
1954  default:
1955  module->GraphicalItemsList().PushBack( text );
1956  }
1957  }
1958  break;
1959 
1960  case T_fp_arc:
1961  case T_fp_circle:
1962  case T_fp_curve:
1963  case T_fp_line:
1964  case T_fp_poly:
1965  {
1966  EDGE_MODULE* em = parseEDGE_MODULE();
1967  em->SetParent( module.get() );
1968  em->SetDrawCoord();
1969  module->GraphicalItemsList().PushBack( em );
1970  }
1971  break;
1972 
1973  case T_pad:
1974  {
1975  D_PAD* pad = parseD_PAD( module.get() );
1976  pt = pad->GetPos0();
1977 
1978  RotatePoint( &pt, module->GetOrientation() );
1979  pad->SetPosition( pt + module->GetPosition() );
1980  module->Add( pad, ADD_APPEND );
1981  }
1982  break;
1983 
1984  case T_model:
1985  module->Add3DModel( parse3DModel() );
1986  break;
1987 
1988  default:
1989  Expecting( "locked, placed, tedit, tstamp, at, descr, tags, path, "
1990  "autoplace_cost90, autoplace_cost180, solder_mask_margin, "
1991  "solder_paste_margin, solder_paste_ratio, clearance, "
1992  "zone_connect, thermal_width, thermal_gap, attr, fp_text, "
1993  "fp_arc, fp_circle, fp_curve, fp_line, fp_poly, pad, or model" );
1994  }
1995  }
1996 
1997  module->SetFPID( fpid );
1998  module->CalculateBoundingBox();
1999 
2000  return module.release();
2001 }
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:308
TEXT_TYPE GetType() const
ZoneConnection
How pads are covered by copper in zone.
Definition: zones.h:55
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:76
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
const wxPoint & GetPos0() const
Definition: class_pad.h:263
int Parse(const UTF8 &aId)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:74
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
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:223
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:343
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
PCB_LAYER_ID
A quick note on layer IDs:
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:227
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:976
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
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:75
PCB_KEYS_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: pcb_lexer.h:334
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:70
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:78
void SetDrawCoord()
Set absolute coordinates.
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
double parseDouble()
Function parseDouble parses the current token as an ASCII numeric string with possible leading whites...
Definition: pcb_parser.cpp:124
const char * name
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
void SetTextAngle(double aAngle)
TEXTE_MODULE * parseTEXTE_MODULE()
D_PAD * parseD_PAD(MODULE *aParent=NULL)
long parseHex()
Definition: pcb_parser.h:258
int parseInt()
Definition: pcb_parser.h:247
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
MODULE_3D_SETTINGS * parse3DModel()
Definition: pcb_parser.cpp:335
void PCB_PARSER::parseNETCLASS ( )
private

Definition at line 1270 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.

1271 {
1272  wxCHECK_RET( CurTok() == T_net_class,
1273  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net class." ) );
1274 
1275  T token;
1276 
1277  NETCLASSPTR nc = std::make_shared<NETCLASS>( wxEmptyString );
1278 
1279  // Read netclass name (can be a name or just a number like track width)
1281  nc->SetName( FromUTF8() );
1282  NeedSYMBOL();
1283  nc->SetDescription( FromUTF8() );
1284 
1285  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1286  {
1287  if( token != T_LEFT )
1288  Expecting( T_LEFT );
1289 
1290  token = NextTok();
1291 
1292  switch( token )
1293  {
1294  case T_clearance:
1295  nc->SetClearance( parseBoardUnits( T_clearance ) );
1296  break;
1297 
1298  case T_trace_width:
1299  nc->SetTrackWidth( parseBoardUnits( T_trace_width ) );
1300  break;
1301 
1302  case T_via_dia:
1303  nc->SetViaDiameter( parseBoardUnits( T_via_dia ) );
1304  break;
1305 
1306  case T_via_drill:
1307  nc->SetViaDrill( parseBoardUnits( T_via_drill ) );
1308  break;
1309 
1310  case T_uvia_dia:
1311  nc->SetuViaDiameter( parseBoardUnits( T_uvia_dia ) );
1312  break;
1313 
1314  case T_uvia_drill:
1315  nc->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
1316  break;
1317 
1318  case T_diff_pair_width:
1319  nc->SetDiffPairWidth( parseBoardUnits( T_diff_pair_width ) );
1320  break;
1321 
1322  case T_diff_pair_gap:
1323  nc->SetDiffPairGap( parseBoardUnits( T_diff_pair_gap ) );
1324  break;
1325 
1326  case T_add_net:
1328  nc->Add( FromUTF8() );
1329  break;
1330 
1331  default:
1332  Expecting( "clearance, trace_width, via_dia, via_drill, uvia_dia, uvia_drill, diff_pair_width, diff_pair_gap or add_net" );
1333  }
1334 
1335  NeedRIGHT();
1336  }
1337 
1338  if( !m_board->GetDesignSettings().m_NetClasses.Add( nc ) )
1339  {
1340  // Must have been a name conflict, this is a bad board file.
1341  // User may have done a hand edit to the file.
1342 
1343  // unique_ptr will delete nc on this code path
1344 
1345  wxString error;
1346  error.Printf( _( "duplicate NETCLASS name '%s' in file <%s> at line %d, offset %d" ),
1347  nc->GetName().GetData(), CurSource().GetData(), CurLineNumber(), CurOffset() );
1348  THROW_IO_ERROR( error );
1349  }
1350 }
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:308
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:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:321
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:532
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:334
T
enum T contains all this lexer's tokens.
Definition: pcb_lexer.h:26
BOARD * m_board
Definition: pcb_parser.h:70
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
void PCB_PARSER::parseNETINFO_ITEM ( )
private

Definition at line 1244 of file pcb_parser.cpp.

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

1245 {
1246  wxCHECK_RET( CurTok() == T_net,
1247  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as net." ) );
1248 
1249  int netCode = parseInt( "net number" );
1250 
1252  wxString name = FromUTF8();
1253 
1254  NeedRIGHT();
1255 
1256  // net 0 should be already in list, so store this net
1257  // if it is not the net 0, or if the net 0 does not exists.
1258  // (TODO: a better test.)
1260  {
1261  NETINFO_ITEM* net = new NETINFO_ITEM( m_board, name, netCode );
1262  m_board->Add( net );
1263 
1264  // Store the new code mapping
1265  pushValueIntoMap( netCode, net->GetNet() );
1266  }
1267 }
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:343
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:334
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
BOARD * m_board
Definition: pcb_parser.h:70
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:247
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 649 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.

650 {
651  wxCHECK_RET( CurTok() == T_page,
652  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
653 
654  T token;
655  PAGE_INFO pageInfo;
656 
657  NeedSYMBOL();
658 
659  wxString pageType = FromUTF8();
660 
661  if( !pageInfo.SetType( pageType ) )
662  {
663  wxString err;
664  err.Printf( _( "page type \"%s\" is not valid " ), GetChars( FromUTF8() ) );
666  }
667 
668  if( pageType == PAGE_INFO::Custom )
669  {
670  double width = parseDouble( "width" ); // width in mm
671 
672  // Perform some controls to avoid crashes if the size is edited by hands
673  if( width < 100.0 )
674  width = 100.0;
675  else if( width > 1200.0 )
676  width = 1200.0;
677 
678  double height = parseDouble( "height" ); // height in mm
679 
680  if( height < 100.0 )
681  height = 100.0;
682  else if( height > 1200.0 )
683  height = 1200.0;
684 
685  pageInfo.SetWidthMils( Mm2mils( width ) );
686  pageInfo.SetHeightMils( Mm2mils( height ) );
687  }
688 
689  token = NextTok();
690 
691  if( token == T_portrait )
692  {
693  pageInfo.SetPortrait( true );
694  NeedRIGHT();
695  }
696  else if( token != T_RIGHT )
697  {
698  Expecting( "portrait|)" );
699  }
700 
701  m_board->SetPageSettings( pageInfo );
702 }
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:308
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: class_board.h:548
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:343
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:321
#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:70
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 3166 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.

3167 {
3168  wxCHECK_MSG( CurTok() == T_target, NULL,
3169  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as PCB_TARGET." ) );
3170 
3171  wxPoint pt;
3172  T token;
3173 
3174  std::unique_ptr< PCB_TARGET > target( new PCB_TARGET( NULL ) );
3175 
3176  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
3177  {
3178  if( token == T_LEFT )
3179  token = NextTok();
3180 
3181  switch( token )
3182  {
3183  case T_x:
3184  target->SetShape( 1 );
3185  break;
3186 
3187  case T_plus:
3188  target->SetShape( 0 );
3189  break;
3190 
3191  case T_at:
3192  pt.x = parseBoardUnits( "target x position" );
3193  pt.y = parseBoardUnits( "target y position" );
3194  target->SetPosition( pt );
3195  NeedRIGHT();
3196  break;
3197 
3198  case T_size:
3199  target->SetSize( parseBoardUnits( "target size" ) );
3200  NeedRIGHT();
3201  break;
3202 
3203  case T_width:
3204  target->SetWidth( parseBoardUnits( "target thickness" ) );
3205  NeedRIGHT();
3206  break;
3207 
3208  case T_layer:
3209  target->SetLayer( parseBoardItemLayer() );
3210  NeedRIGHT();
3211  break;
3212 
3213  case T_tstamp:
3214  target->SetTimeStamp( parseHex() );
3215  NeedRIGHT();
3216  break;
3217 
3218  default:
3219  Expecting( "x, plus, at, size, width, layer or tstamp" );
3220  }
3221  }
3222 
3223  return target.release();
3224 }
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:308
int parseBoardUnits()
Definition: pcb_parser.h:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
PCB_LAYER_ID parseBoardItemLayer()
Function parseBoardItemLayer parses the layer definition of a BOARD_ITEM object.
Definition: pcb_parser.cpp:976
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:258
void PCB_PARSER::parseSetup ( )
private

Definition at line 1009 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.

1010 {
1011  wxCHECK_RET( CurTok() == T_setup,
1012  wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as setup." ) );
1013 
1014  T token;
1015  NETCLASSPTR defaultNetClass = m_board->GetDesignSettings().GetDefault();
1016  // TODO Orson: is it really necessary to first operate on a copy and then apply it?
1017  // would not it be better to use reference here and apply all the changes instantly?
1018  BOARD_DESIGN_SETTINGS designSettings = m_board->GetDesignSettings();
1019  ZONE_SETTINGS zoneSettings = m_board->GetZoneSettings();
1020 
1021  for( token = NextTok(); token != T_RIGHT; token = NextTok() )
1022  {
1023  if( token != T_LEFT )
1024  Expecting( T_LEFT );
1025 
1026  token = NextTok();
1027 
1028  switch( token )
1029  {
1030  case T_last_trace_width: // not used now
1031  /* lastTraceWidth =*/ parseBoardUnits( T_last_trace_width );
1032  NeedRIGHT();
1033  break;
1034 
1035  case T_user_trace_width:
1036  designSettings.m_TrackWidthList.push_back( parseBoardUnits( T_user_trace_width ) );
1037  NeedRIGHT();
1038  break;
1039 
1040  case T_trace_clearance:
1041  defaultNetClass->SetClearance( parseBoardUnits( T_trace_clearance ) );
1042  NeedRIGHT();
1043  break;
1044 
1045  case T_zone_clearance:
1047  NeedRIGHT();
1048  break;
1049 
1050  case T_zone_45_only:
1051  zoneSettings.m_Zone_45_Only = parseBool();
1052  NeedRIGHT();
1053  break;
1054 
1055  case T_trace_min:
1056  designSettings.m_TrackMinWidth = parseBoardUnits( T_trace_min );
1057  NeedRIGHT();
1058  break;
1059 
1060  case T_segment_width:
1062  NeedRIGHT();
1063  break;
1064 
1065  case T_edge_width:
1066  designSettings.m_EdgeSegmentWidth = parseBoardUnits( T_edge_width );
1067  NeedRIGHT();
1068  break;
1069 
1070  case T_via_size:
1071  defaultNetClass->SetViaDiameter( parseBoardUnits( T_via_size ) );
1072  NeedRIGHT();
1073  break;
1074 
1075  case T_via_drill:
1076  defaultNetClass->SetViaDrill( parseBoardUnits( T_via_drill ) );
1077  NeedRIGHT();
1078  break;
1079 
1080  case T_via_min_size:
1081  designSettings.m_ViasMinSize = parseBoardUnits( T_via_min_size );
1082  NeedRIGHT();
1083  break;
1084 
1085  case T_via_min_drill:
1086  designSettings.m_ViasMinDrill = parseBoardUnits( T_via_min_drill );
1087  NeedRIGHT();
1088  break;
1089 
1090  case T_user_via:
1091  {
1092  int viaSize = parseBoardUnits( "user via size" );
1093  int viaDrill = parseBoardUnits( "user via drill" );
1094  designSettings.m_ViasDimensionsList.push_back( VIA_DIMENSION( viaSize, viaDrill ) );
1095  NeedRIGHT();
1096  }
1097  break;
1098 
1099  case T_uvia_size:
1100  defaultNetClass->SetuViaDiameter( parseBoardUnits( T_uvia_size ) );
1101  NeedRIGHT();
1102  break;
1103 
1104  case T_uvia_drill:
1105  defaultNetClass->SetuViaDrill( parseBoardUnits( T_uvia_drill ) );
1106  NeedRIGHT();
1107  break;
1108 
1109  case T_uvias_allowed:
1110  designSettings.m_MicroViasAllowed = parseBool();
1111  NeedRIGHT();
1112  break;
1113 
1115  designSettings.m_BlindBuriedViaAllowed = parseBool();
1116  NeedRIGHT();
1117  break;
1118 
1119  case T_uvia_min_size:
1121  NeedRIGHT();
1122  break;
1123 
1124  case T_uvia_min_drill:
1126  NeedRIGHT();
1127  break;
1128 
1129  case T_pcb_text_width:
1130  designSettings.m_PcbTextWidth = parseBoardUnits( T_pcb_text_width );
1131  NeedRIGHT();
1132  break;
1133 
1134  case T_pcb_text_size:
1135  designSettings.m_PcbTextSize.x = parseBoardUnits( "pcb text width" );
1136  designSettings.m_PcbTextSize.y = parseBoardUnits( "pcb text height" );
1137  NeedRIGHT();
1138  break;
1139 
1140  case T_mod_edge_width:
1142  NeedRIGHT();
1143  break;
1144 
1145  case T_mod_text_size:
1146  designSettings.m_ModuleTextSize.x = parseBoardUnits( "module text width" );
1147  designSettings.m_ModuleTextSize.y = parseBoardUnits( "module text height" );
1148  NeedRIGHT();
1149  break;
1150 
1151  case T_mod_text_width:
1153  NeedRIGHT();
1154  break;
1155 
1156  case T_pad_size:
1157  {
1158  wxSize sz;
1159  sz.SetWidth( parseBoardUnits( "master pad width" ) );
1160  sz.SetHeight( parseBoardUnits( "master pad height" ) );
1161  designSettings.m_Pad_Master.SetSize( sz );
1162  NeedRIGHT();
1163  }
1164  break;
1165 
1166  case T_pad_drill:
1167  {
1168  int drillSize = parseBoardUnits( T_pad_drill );
1169  designSettings.m_Pad_Master.SetDrillSize( wxSize( drillSize, drillSize ) );
1170  NeedRIGHT();
1171  }
1172  break;
1173 
1176  NeedRIGHT();
1177  break;
1178 
1181  NeedRIGHT();
1182  break;
1183 
1186  NeedRIGHT();
1187  break;
1188 
1191  NeedRIGHT();
1192  break;
1193 
1194  case T_aux_axis_origin:
1195  {
1196  int x = parseBoardUnits( "auxiliary origin X" );
1197  int y = parseBoardUnits( "auxiliary origin Y" );
1198  // m_board->SetAuxOrigin( wxPoint( x, y ) ); gets overwritten via SetDesignSettings below
1199  designSettings.m_AuxOrigin = wxPoint( x, y );
1200  NeedRIGHT();
1201  }
1202  break;
1203 
1204  case T_grid_origin:
1205  {
1206  int x = parseBoardUnits( "grid origin X" );
1207  int y = parseBoardUnits( "grid origin Y" );
1208  // m_board->SetGridOrigin( wxPoint( x, y ) ); gets overwritten SetDesignSettings below
1209  designSettings.m_GridOrigin = wxPoint( x, y );
1210  NeedRIGHT();
1211  }
1212  break;
1213 
1214  case T_visible_elements:
1215  designSettings.SetVisibleElements( parseHex() | MIN_VISIBILITY_MASK );
1216  NeedRIGHT();
1217  break;
1218 
1219  case T_pcbplotparams:
1220  {
1221  PCB_PLOT_PARAMS plotParams;
1222  PCB_PLOT_PARAMS_PARSER parser( reader );
1223  // parser must share the same current line as our current PCB parser
1224  // synchronize it.
1225  parser.SyncLineReaderWith( *this );
1226 
1227  plotParams.Parse( &parser );
1228  SyncLineReaderWith( parser );
1229 
1230  m_board->SetPlotOptions( plotParams );
1231  }
1232  break;
1233 
1234  default:
1235  Unexpected( CurText() );
1236  }
1237  }
1238 
1239  m_board->SetDesignSettings( designSettings );
1240  m_board->SetZoneSettings( zoneSettings );
1241 }
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:308
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:557
const ZONE_SETTINGS & GetZoneSettings() const
Definition: class_board.h:556
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:274
wxSize m_ModuleTextSize
Default footprint texts size.
int parseBoardUnits()
Definition: pcb_parser.h:223
PCB_KEYS_T::T CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: pcb_lexer.h:343
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:532
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
int m_ZoneClearance
Clearance value.
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:542
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
void SetPlotOptions(const PCB_PLOT_PARAMS &aOptions)
Definition: class_board.h:551
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:70
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:258
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 2004 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.

2005 {
2006  wxCHECK_MSG( CurTok() == T_fp_text, NULL,
2007  wxString::Format( wxT( "Cannot parse %s as TEXTE_MODULE at line %d, offset %d." ),
2008  GetChars( GetTokenString( CurTok() ) ),
2009  CurLineNumber(), CurOffset() ) );
2010 
2011  T token = NextTok();
2012 
2013  std::unique_ptr<TEXTE_MODULE> text( new TEXTE_MODULE( NULL ) );
2014 
2015  switch( token )
2016  {
2017  case T_reference:
2018  text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
2019  break;
2020 
2021  case T_value:
2022  text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
20