KiCad PCB EDA Suite
CLIPBOARD_PARSER Class Reference

#include <kicad_clipboard.h>

Inheritance diagram for CLIPBOARD_PARSER:
PCB_PARSER

Public Member Functions

 CLIPBOARD_PARSER (LINE_READER *aReader=NULL)
 
MODULEparseMODULE (wxArrayString *aInitialComments)
 
LINE_READERSetLineReader (LINE_READER *aReader)
 Function SetLineReader sets aLineReader into the parser, and returns the previous one, if any. More...
 
void SetBoard (BOARD *aBoard)
 
BOARD_ITEMParse ()
 
bool IsTooRecent ()
 Return whether a version number, if any was parsed, was too recent. More...
 
wxString GetRequiredVersion ()
 Return a string representing the version of kicad required to open this file. More...
 

Detailed Description

Definition at line 40 of file kicad_clipboard.h.

Constructor & Destructor Documentation

◆ CLIPBOARD_PARSER()

CLIPBOARD_PARSER::CLIPBOARD_PARSER ( LINE_READER aReader = NULL)
inline

Definition at line 43 of file kicad_clipboard.h.

43 : PCB_PARSER( aReader ) {};
PCB_PARSER(LINE_READER *aReader=NULL)
Definition: pcb_parser.h:321

Member Function Documentation

◆ GetRequiredVersion()

wxString PCB_PARSER::GetRequiredVersion ( )
inherited

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

Not particularly meaningful if IsTooRecent() returns false.

Definition at line 208 of file pcb_parser.cpp.

209 {
210  int year, month, day;
211 
212  year = m_requiredVersion / 10000;
213  month = ( m_requiredVersion / 100 ) - ( year * 100 );
214  day = m_requiredVersion - ( year * 10000 ) - ( month * 100 );
215 
216  // wx throws an assertion, not a catchable exception, when the date is invalid.
217  // User input shouldn't give wx asserts, so check manually and throw a proper
218  // error instead
219  if( day <= 0 || month <= 0 || month > 12 ||
220  day > wxDateTime::GetNumberOfDays( (wxDateTime::Month)( month - 1 ), year ) )
221  {
222  wxString err;
223  err.Printf( _( "Cannot interpret date code %d" ), m_requiredVersion );
224  THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
225  }
226 
227  wxDateTime date( day, (wxDateTime::Month)( month - 1 ), year, 0, 0, 0, 0 );
228  return date.FormatDate();
229 }
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:80
#define _(s)
Definition: 3d_actions.cpp:33

References _, and THROW_PARSE_ERROR.

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

◆ IsTooRecent()

bool PCB_PARSER::IsTooRecent ( )
inlineinherited

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

Definition at line 363 of file pcb_parser.h.

364  {
365  return m_tooRecent;
366  }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:79

References PCB_PARSER::m_tooRecent.

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

◆ Parse()

BOARD_ITEM * PCB_PARSER::Parse ( )
inherited

Definition at line 481 of file pcb_parser.cpp.

482 {
483  T token;
484  BOARD_ITEM* item;
485  LOCALE_IO toggle;
486 
487  // MODULEs can be prefixed with an initial block of single line comments and these
488  // are kept for Format() so they round trip in s-expression form. BOARDs might
489  // eventually do the same, but currently do not.
490  std::unique_ptr<wxArrayString> initial_comments( ReadCommentLines() );
491 
492  token = CurTok();
493 
494  if( token != T_LEFT )
495  Expecting( T_LEFT );
496 
497  switch( NextTok() )
498  {
499  case T_kicad_pcb:
500  if( m_board == NULL )
501  m_board = new BOARD();
502 
503  item = (BOARD_ITEM*) parseBOARD();
504  break;
505 
506  case T_module:
507  item = (BOARD_ITEM*) parseMODULE( initial_comments.release() );
508  break;
509 
510  default:
511  wxString err;
512  err.Printf( _( "Unknown token \"%s\"" ), GetChars( FromUTF8() ) );
513  THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
514  }
515 
516  return item;
517 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
BOARD * parseBOARD()
Definition: pcb_parser.cpp:520
T
enum T contains all this lexer's tokens.
#define NULL
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
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:153
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
BOARD * m_board
Definition: pcb_parser.h:74
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.

References _, GetChars(), NULL, DRCRULE_T::T_LEFT, and THROW_PARSE_ERROR.

Referenced by PCB_IO::DoLoad(), GITHUB_PLUGIN::FootprintLoad(), CLIPBOARD_IO::Load(), FP_CACHE::Load(), parse(), PCB_IO::Parse(), KI_TEST::ReadBoardItemFromFile(), and KI_TEST::ReadBoardItemFromStream().

◆ parseMODULE()

MODULE* CLIPBOARD_PARSER::parseMODULE ( wxArrayString *  aInitialComments)
inline

Definition at line 45 of file kicad_clipboard.h.

46  {
47  return PCB_PARSER::parseMODULE( aInitialComments );
48  }
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.

References PCB_PARSER::parseMODULE().

◆ SetBoard()

void PCB_PARSER::SetBoard ( BOARD aBoard)
inlineinherited

Definition at line 344 of file pcb_parser.h.

345  {
346  init();
347  m_board = aBoard;
348  m_resetKIIDs = true;
349  }
BOARD * m_board
Definition: pcb_parser.h:74
void init()
Function init clears and re-establishes m_layerMap with the default layer names.
Definition: pcb_parser.cpp:58
bool m_resetKIIDs
reading into an existing board; reset UUIDs
Definition: pcb_parser.h:81

References PCB_PARSER::init(), PCB_PARSER::m_board, and PCB_PARSER::m_resetKIIDs.

Referenced by PCB_IO::DoLoad(), and CLIPBOARD_IO::Load().

◆ SetLineReader()

LINE_READER* PCB_PARSER::SetLineReader ( LINE_READER aReader)
inlineinherited

Function SetLineReader sets aLineReader into the parser, and returns the previous one, if any.

Parameters
aReaderis what to read from for tokens, no ownership is received.
Returns
LINE_READER* - previous LINE_READER or NULL if none.

Definition at line 337 of file pcb_parser.h.

338  {
339  LINE_READER* ret = PopReader();
340  PushReader( aReader );
341  return ret;
342  }
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81

Referenced by PCB_IO::DoLoad(), GITHUB_PLUGIN::FootprintLoad(), CLIPBOARD_IO::Load(), FP_CACHE::Load(), parse(), PCB_IO::Parse(), KI_TEST::ReadBoardItemFromFile(), and KI_TEST::ReadBoardItemFromStream().


The documentation for this class was generated from the following file: