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:303

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

185 {
186  int year, month, day;
187 
188  year = m_requiredVersion / 10000;
189  month = ( m_requiredVersion / 100 ) - ( year * 100 );
190  day = m_requiredVersion - ( year * 10000 ) - ( month * 100 );
191 
192  // wx throws an assertion, not a catchable exception, when the date is invalid.
193  // User input shouldn't give wx asserts, so check manually and throw a proper
194  // error instead
195  if( day <= 0 || month <= 0 || month > 12 ||
196  day > wxDateTime::GetNumberOfDays( (wxDateTime::Month)( month - 1 ), year ) )
197  {
198  wxString err;
199  err.Printf( _( "Cannot interpret date code %d" ), m_requiredVersion );
200  THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
201  }
202 
203  wxDateTime date( day, (wxDateTime::Month)( month - 1 ), year, 0, 0, 0, 0 );
204  return date.FormatDate();
205 }
#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 343 of file pcb_parser.h.

344  {
345  return m_tooRecent;
346  }
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 444 of file pcb_parser.cpp.

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

326  {
327  init();
328  m_board = aBoard;
329  }
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 318 of file pcb_parser.h.

319  {
320  LINE_READER* ret = PopReader();
321  PushReader( aReader );
322  return ret;
323  }
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: