bool EXCELLON_IMAGE::Read_EXCELLON_File( FILE * aFile, const wxString & aFullFileName ) { /* Set the gerber scale: */ ResetDefaultValues(); m_FileName = aFullFileName; m_Current_File = aFile; SetLocaleTo_C_standard(); // FILE_LINE_READER will close the file. if( m_Current_File == NULL ) { wxMessageBox( wxT("NULL!"), m_FileName ); return false; } FILE_LINE_READER excellonReader( m_Current_File, m_FileName ); while( true ) { if( excellonReader.ReadLine() == 0 ) break; char* line = excellonReader.Line(); char* text = StrPurge( line ); if( *text == ';' ) // comment: skip line continue; if( m_State == EXCELLON_IMAGE::READ_HEADER_STATE ) { Execute_HEADER_Command( text ); } else { switch( *text ) { case 'M': Execute_HEADER_Command( text ); break; case 'G': /* Line type Gxx : command */ Execute_EXCELLON_G_Command( text ); break; case 'X': case 'Y': // command like X12550Y19250 Execute_Drill_Command(text); break; case 'I': case 'J': /* Auxiliary Move command */ m_IJPos = ReadIJCoord( text ); if( *text == '*' ) // command like X35142Y15945J504 { Execute_Drill_Command( text); } break; case 'T': // Tool command Select_Tool( text ); break; case '%': break; default: { wxString msg; msg.Printf( wxT( "Unexpected symbol <%c>" ), *text ); if( GetParent() ) GetParent()->ReportMessage( msg ); } break; } // End switch } } SetLocaleTo_Default(); return true; }
bool EXCELLON_IMAGE::LoadFile( const wxString & aFullFileName ) { // Set the default parmeter values: ResetDefaultValues(); ClearMessageList(); m_Current_File = wxFopen( aFullFileName, wxT( "rt" ) ); if( m_Current_File == NULL ) return false; m_FileName = aFullFileName; LOCALE_IO toggleIo; // FILE_LINE_READER will close the file. FILE_LINE_READER excellonReader( m_Current_File, m_FileName ); while( true ) { if( excellonReader.ReadLine() == 0 ) break; char* line = excellonReader.Line(); char* text = StrPurge( line ); if( *text == ';' ) // comment: skip line continue; if( m_State == EXCELLON_IMAGE::READ_HEADER_STATE ) { Execute_HEADER_Command( text ); } else { switch( *text ) { case 'M': Execute_HEADER_Command( text ); break; case 'G': /* Line type Gxx : command */ Execute_EXCELLON_G_Command( text ); break; case 'X': case 'Y': // command like X12550Y19250 Execute_Drill_Command(text); break; case 'I': case 'J': /* Auxiliary Move command */ m_IJPos = ReadIJCoord( text ); if( *text == '*' ) // command like X35142Y15945J504 { Execute_Drill_Command( text); } break; case 'T': // Tool command Select_Tool( text ); break; case '%': break; default: { wxString msg; msg.Printf( wxT( "Unexpected symbol <%c>" ), *text ); AddMessageToList( msg ); } break; } // End switch } } // Add our file attribute, to identify the drill file X2_ATTRIBUTE dummy; char* text = (char*)file_attribute; dummy.ParseAttribCmd( m_Current_File, NULL, 0, text ); delete m_FileFunction; m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy ); m_InUse = true; return true; }