28#include <wx/tokenzr.h>
29#include <wx/translation.h>
37static double toDouble(
const wxString& aToken )
40 aToken.ToCDouble( &value );
46static int toInt(
const wxString& aToken )
49 aToken.ToCLong( &value );
50 return static_cast<int>( value );
58 for( wxString line : wxStringTokenize( aContents, wxT(
"\n" ), wxTOKEN_RET_EMPTY ) )
60 line.Trim(
true ).Trim(
false );
62 if( line.IsEmpty() || line[0] ==
'#' )
65 return line.StartsWith( wxT(
"PCB FILE 4" ) ) || line.StartsWith( wxT(
"PCB FILE 5" ) );
75 m_reporter->Report( wxString::Format(
_(
"Autotrax import, line %d: %s" ),
m_lineNo, aMsg ),
89 aLine.Trim(
true ).Trim(
false );
97 return wxStringTokenize( aLine, wxT(
" \t\r\n" ), wxTOKEN_STRTOK );
108 wxArrayString tok =
tokenize( line );
110 if( tok.GetCount() < 6 )
112 warn(
_(
"insufficient track fields" ) );
133 wxArrayString tok =
tokenize( line );
135 if( tok.GetCount() < 6 )
137 warn(
_(
"insufficient arc fields" ) );
158 wxArrayString tok =
tokenize( line );
160 if( tok.GetCount() < 4 )
162 warn(
_(
"insufficient via fields" ) );
181 wxArrayString tok =
tokenize( line );
185 if( tok.GetCount() < 8 )
187 warn(
_(
"insufficient pad fields" ) );
215 wxArrayString tok =
tokenize( line );
217 if( tok.GetCount() < 5 )
219 warn(
_(
"insufficient fill fields" ) );
239 wxArrayString tok =
tokenize( line );
241 if( tok.GetCount() < 6 )
243 warn(
_(
"insufficient text fields" ) );
283 wxArrayString tok =
tokenize( line );
285 if( tok.GetCount() >= 2 )
292 warn(
_(
"insufficient component fields" ) );
300 if( kw.StartsWith( wxT(
"ENDCOMP" ) ) )
303 if( kw == wxT(
"CT" ) )
308 aOut.
tracks.push_back( t );
310 else if( kw == wxT(
"CA" ) )
315 aOut.
arcs.push_back( a );
317 else if( kw == wxT(
"CV" ) )
322 aOut.
vias.push_back( v );
324 else if( kw == wxT(
"CF" ) )
329 aOut.
fills.push_back( f );
331 else if( kw == wxT(
"CP" ) )
336 aOut.
pads.push_back( p );
338 else if( kw == wxT(
"CS" ) )
343 aOut.
texts.push_back( s );
360 wxString netName = line;
363 bool inNodeTable =
false;
369 if( s.StartsWith( wxT(
"ENDPCB" ) ) )
383 if( line == wxT(
"]" ) )
387 else if( s[0] ==
'(' )
391 else if( s[0] ==
')' )
395 else if( s[0] ==
'{' )
399 else if( s[0] ==
'}' )
403 else if( inNet && !inNodeTable && !netName.IsEmpty() )
405 m_board->netNodes.push_back( { netName, s } );
417 m_lines = wxStringTokenize( aContents, wxT(
"\n" ), wxTOKEN_RET_EMPTY );
421 bool haveHeader =
false;
431 if( kw.StartsWith( wxT(
"PCB FILE 4" ) ) )
436 else if( kw.StartsWith( wxT(
"PCB FILE 5" ) ) )
441 else if( kw.StartsWith( wxT(
"ENDPCB" ) ) )
445 else if( kw.StartsWith( wxT(
"NETDEF" ) ) )
449 else if( kw.StartsWith( wxT(
"COMP" ) ) )
455 else if( kw == wxT(
"FT" ) )
460 aBoard.
tracks.push_back( t );
462 else if( kw == wxT(
"FA" ) )
467 aBoard.
arcs.push_back( a );
469 else if( kw == wxT(
"FV" ) )
474 aBoard.
vias.push_back( v );
476 else if( kw == wxT(
"FF" ) )
481 aBoard.
fills.push_back( f );
483 else if( kw == wxT(
"FP" ) )
488 aBoard.
pads.push_back( p );
490 else if( kw == wxT(
"FS" ) )
495 aBoard.
texts.push_back( s );
static int toInt(const wxString &aToken)
Parse a token as an integer using the C locale, returning 0 on failure.
static double toDouble(const wxString &aToken)
Parse a token as a double using the C locale, returning 0 on failure so a malformed field degrades to...
bool parseVia(AUTOTRAX::VIA &aOut)
AUTOTRAX::BOARD_DATA * m_board
static bool Sniff(const wxString &aContents)
Cheap content sniff: the first non-blank, non-comment line is the magic header "PCB FILE 4" (Autotrax...
bool Parse(const wxString &aContents, AUTOTRAX::BOARD_DATA &aBoard)
Parse aContents into aBoard.
void parseComponent(AUTOTRAX::COMPONENT &aOut)
bool parseArc(AUTOTRAX::ARC &aOut)
bool parseTrack(AUTOTRAX::TRACK &aOut)
void warn(const wxString &aMsg) const
bool parseText(AUTOTRAX::TEXT &aOut)
bool parseFill(AUTOTRAX::FILL &aOut)
bool nextLine(wxString &aLine)
Return the next line trimmed of surrounding whitespace, or false at end of input.
static wxArrayString tokenize(const wxString &aLine)
Tokenize a whitespace-separated data line into C-locale-parseable tokens.
bool parsePad(AUTOTRAX::PAD &aOut)
Free or component arc (FA / CA).
int segments
quadrant bitmask; 15 = full circle
Everything parsed out of an Autotrax/Easytrax file, before any KiCad object is created.
std::vector< COMPONENT > components
std::vector< TRACK > tracks
int version
4 = Autotrax, 5 = Easytrax
std::vector< TEXT > texts
std::vector< FILL > fills
A placed component (COMP .. ENDCOMP) holding its own primitives.
std::vector< TRACK > tracks
std::vector< FILL > fills
std::vector< TEXT > texts
Free or component rectangular fill (FF / CF), Autotrax's only pour.
Free or component pad/pin (FP / CP).
int shape
1 round, 2 rect, 3 octagon, 4 round-rect
Free or component string (FS / CS).
int direction
0..3, multiplied by 90 degrees
Free or component track segment (FT / CT). All coordinates are in mils.
Free or component via (FV / CV).