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 ( 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:278

Member Function Documentation

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

References err, and THROW_PARSE_ERROR.

Referenced by PCB_PARSER::IsTooRecent(), CLIPBOARD_IO::Load(), and PCB_IO::Load().

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 );
198  THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
199  }
200 
201  wxDateTime date( day, (wxDateTime::Month)( month - 1 ), year, 0, 0, 0, 0 );
202  return date.FormatDate();
203 }
#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:75
bool PCB_PARSER::IsTooRecent ( )
inlineinherited

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

Definition at line 318 of file pcb_parser.h.

References PCB_PARSER::GetRequiredVersion(), and PCB_PARSER::m_tooRecent.

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

319  {
320  return m_tooRecent;
321  }
bool m_tooRecent
true if version parses as later than supported
Definition: pcb_parser.h:74
BOARD_ITEM * PCB_PARSER::Parse ( )
inherited

Definition at line 442 of file pcb_parser.cpp.

References err, GetChars(), and THROW_PARSE_ERROR.

Referenced by GITHUB_PLUGIN::FootprintLoad(), CLIPBOARD_IO::Load(), PCB_IO::Load(), and PCB_PARSER::SetBoard().

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

Definition at line 46 of file kicad_clipboard.h.

References mod, PCB_PARSER::parseMODULE(), and MODULE::SetPath().

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
void SetPath(const wxString &aPath)
Definition: class_module.h:203
void PCB_PARSER::SetBoard ( BOARD aBoard)
inlineinherited

Definition at line 300 of file pcb_parser.h.

References PCB_PARSER::init(), PCB_PARSER::Parse(), and PCB_PARSER::parseMODULE().

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

301  {
302  init();
303  m_board = aBoard;
304  }
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
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 293 of file pcb_parser.h.

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

294  {
295  LINE_READER* ret = PopReader();
296  PushReader( aReader );
297  return ret;
298  }
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81

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