32#include <wx/tokenzr.h>
33#include <wx/translation.h>
41static double toDouble(
const wxString& aToken )
44 aToken.ToCDouble( &value );
50static int toInt(
const wxString& aToken )
53 aToken.ToCLong( &value );
54 return static_cast<int>( value );
62 for( wxString line : wxStringTokenize( aContents, wxT(
"\n" ), wxTOKEN_RET_EMPTY ) )
64 line.Trim(
true ).Trim(
false );
66 if( line.IsEmpty() || line[0] ==
'#' )
69 return line.StartsWith( wxT(
"PCB FILE 4" ) ) || line.StartsWith( wxT(
"PCB FILE 5" ) );
79 m_reporter->Report( wxString::Format(
_(
"Autotrax import, line %d: %s" ),
m_lineNo, aMsg ),
93 aLine.Trim(
true ).Trim(
false );
101 return wxStringTokenize( aLine, wxT(
" \t\r\n" ), wxTOKEN_STRTOK );
112 wxArrayString tok =
tokenize( line );
114 if( tok.GetCount() < 6 )
116 warn(
_(
"insufficient track fields" ) );
137 wxArrayString tok =
tokenize( line );
139 if( tok.GetCount() < 6 )
141 warn(
_(
"insufficient arc fields" ) );
162 wxArrayString tok =
tokenize( line );
164 if( tok.GetCount() < 4 )
166 warn(
_(
"insufficient via fields" ) );
185 wxArrayString tok =
tokenize( line );
189 if( tok.GetCount() < 8 )
191 warn(
_(
"insufficient pad fields" ) );
219 wxArrayString tok =
tokenize( line );
221 if( tok.GetCount() < 5 )
223 warn(
_(
"insufficient fill fields" ) );
243 wxArrayString tok =
tokenize( line );
245 if( tok.GetCount() < 6 )
247 warn(
_(
"insufficient text fields" ) );
287 wxArrayString tok =
tokenize( line );
289 if( tok.GetCount() >= 2 )
296 warn(
_(
"insufficient component fields" ) );
304 if( kw.StartsWith( wxT(
"ENDCOMP" ) ) )
307 if( kw == wxT(
"CT" ) )
312 aOut.
tracks.push_back( t );
314 else if( kw == wxT(
"CA" ) )
319 aOut.
arcs.push_back( a );
321 else if( kw == wxT(
"CV" ) )
326 aOut.
vias.push_back( v );
328 else if( kw == wxT(
"CF" ) )
333 aOut.
fills.push_back( f );
335 else if( kw == wxT(
"CP" ) )
340 aOut.
pads.push_back( p );
342 else if( kw == wxT(
"CS" ) )
347 aOut.
texts.push_back( s );
364 wxString netName = line;
367 bool inNodeTable =
false;
373 if( s.StartsWith( wxT(
"ENDPCB" ) ) )
387 if( line == wxT(
"]" ) )
391 else if( s[0] ==
'(' )
395 else if( s[0] ==
')' )
399 else if( s[0] ==
'{' )
403 else if( s[0] ==
'}' )
407 else if( inNet && !inNodeTable && !netName.IsEmpty() )
409 m_board->netNodes.push_back( { netName, s } );
421 m_lines = wxStringTokenize( aContents, wxT(
"\n" ), wxTOKEN_RET_EMPTY );
425 bool haveHeader =
false;
435 if( kw.StartsWith( wxT(
"PCB FILE 4" ) ) )
440 else if( kw.StartsWith( wxT(
"PCB FILE 5" ) ) )
445 else if( kw.StartsWith( wxT(
"ENDPCB" ) ) )
449 else if( kw.StartsWith( wxT(
"NETDEF" ) ) )
453 else if( kw.StartsWith( wxT(
"COMP" ) ) )
459 else if( kw == wxT(
"FT" ) )
464 aBoard.
tracks.push_back( t );
466 else if( kw == wxT(
"FA" ) )
471 aBoard.
arcs.push_back( a );
473 else if( kw == wxT(
"FV" ) )
478 aBoard.
vias.push_back( v );
480 else if( kw == wxT(
"FF" ) )
485 aBoard.
fills.push_back( f );
487 else if( kw == wxT(
"FP" ) )
492 aBoard.
pads.push_back( p );
494 else if( kw == wxT(
"FS" ) )
499 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).