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 41 of file kicad_clipboard.h.

Constructor & Destructor Documentation

◆ CLIPBOARD_PARSER()

CLIPBOARD_PARSER::CLIPBOARD_PARSER ( LINE_READER aReader = NULL)
inline

Definition at line 44 of file kicad_clipboard.h.

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

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

184 {
185  int year, month, day;
186 
187  year = m_requiredVersion / 10000;
188  month = ( m_requiredVersion / 100 ) - ( year * 100 );
189  day = m_requiredVersion - ( year * 10000 ) - ( month * 100 );
190 
191  // wx throws an assertion, not a catchable exception, when the date is invalid.
192  // User input shouldn't give wx asserts, so check manually and throw a proper
193  // error instead
194  if( day <= 0 || month <= 0 || month > 12 ||
195  day > wxDateTime::GetNumberOfDays( (wxDateTime::Month)( month - 1 ), year ) )
196  {
197  wxString err;
198  err.Printf( _( "Cannot interpret date code %d" ), m_requiredVersion );
199  THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
200  }
201 
202  wxDateTime date( day, (wxDateTime::Month)( month - 1 ), year, 0, 0, 0, 0 );
203  return date.FormatDate();
204 }
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
string & err
Definition: json11.cpp:598
int m_requiredVersion
set to the KiCad format version this board requires
Definition: pcb_parser.h:76

References err, and THROW_PARSE_ERROR.

Referenced by CLIPBOARD_IO::Load(), PCB_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 333 of file pcb_parser.h.

334  {
335  return m_tooRecent;
336  }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:75

References PCB_PARSER::m_tooRecent.

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

◆ Parse()

BOARD_ITEM * PCB_PARSER::Parse ( )
inherited

Definition at line 443 of file pcb_parser.cpp.

444 {
445  T token;
446  BOARD_ITEM* item;
447  LOCALE_IO toggle;
448 
449  // MODULEs can be prefixed with an initial block of single line comments and these
450  // are kept for Format() so they round trip in s-expression form. BOARDs might
451  // eventually do the same, but currently do not.
452  std::unique_ptr<wxArrayString> initial_comments( ReadCommentLines() );
453 
454  token = CurTok();
455 
456  if( token != T_LEFT )
457  Expecting( T_LEFT );
458 
459  switch( NextTok() )
460  {
461  case T_kicad_pcb:
462  if( m_board == NULL )
463  m_board = new BOARD();
464 
465  item = (BOARD_ITEM*) parseBOARD();
466  break;
467 
468  case T_module:
469  item = (BOARD_ITEM*) parseMODULE( initial_comments.release() );
470  break;
471 
472  default:
473  wxString err;
474  err.Printf( _( "Unknown token \"%s\"" ), GetChars( FromUTF8() ) );
475  THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
476  }
477 
478  return item;
479 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:180
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:482
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
string & err
Definition: json11.cpp:598
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:171
BOARD * m_board
Definition: pcb_parser.h:70
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.

References err, GetChars(), and THROW_PARSE_ERROR.

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

◆ parseMODULE()

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

Definition at line 46 of file kicad_clipboard.h.

47  {
48  MODULE* mod = PCB_PARSER::parseMODULE( aInitialComments );
49 
50  //TODO: figure out better way of handling paths
51  mod->SetPath( wxT( "" ) );
52  return mod;
53  }
MODULE * parseMODULE(wxArrayString *aInitialComments=0)
Function parseMODULE.
#define mod(a, n)
Definition: greymap.cpp:24

References mod, and PCB_PARSER::parseMODULE().

◆ SetBoard()

void PCB_PARSER::SetBoard ( BOARD aBoard)
inlineinherited

Definition at line 315 of file pcb_parser.h.

316  {
317  init();
318  m_board = aBoard;
319  }
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:57

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

Referenced by CLIPBOARD_IO::Load(), and PCB_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 308 of file pcb_parser.h.

309  {
310  LINE_READER* ret = PopReader();
311  PushReader( aReader );
312  return ret;
313  }
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81

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


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