|
|
|
@ -833,312 +833,6 @@ bool LIB_PART::Save( OUTPUTFORMATTER& aFormatter ) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool LIB_PART::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) |
|
|
|
{ |
|
|
|
int unused; |
|
|
|
char* p; |
|
|
|
char* componentName; |
|
|
|
char* prefix = NULL; |
|
|
|
char* line; |
|
|
|
|
|
|
|
bool result; |
|
|
|
wxString Msg; |
|
|
|
|
|
|
|
line = aLineReader.Line(); |
|
|
|
|
|
|
|
p = strtok( line, " \t\r\n" ); |
|
|
|
|
|
|
|
if( strcmp( p, "DEF" ) != 0 ) |
|
|
|
{ |
|
|
|
aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ), |
|
|
|
aLineReader.LineNumber() ); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Read DEF line:
|
|
|
|
char drawnum = 0; |
|
|
|
char drawname = 0; |
|
|
|
|
|
|
|
if( ( componentName = strtok( NULL, " \t\n" ) ) == NULL // Part name:
|
|
|
|
|| ( prefix = strtok( NULL, " \t\n" ) ) == NULL // Prefix name:
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // NumOfPins:
|
|
|
|
|| sscanf( p, "%d", &unused ) != 1 |
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // TextInside:
|
|
|
|
|| sscanf( p, "%d", &m_pinNameOffset ) != 1 |
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // DrawNums:
|
|
|
|
|| sscanf( p, "%c", &drawnum ) != 1 |
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // DrawNums:
|
|
|
|
|| sscanf( p, "%c", &drawname ) != 1 |
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // m_unitCount:
|
|
|
|
|| sscanf( p, "%d", &m_unitCount ) != 1 ) |
|
|
|
{ |
|
|
|
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), |
|
|
|
aLineReader.LineNumber() ); |
|
|
|
|
|
|
|
while( (line = aLineReader.ReadLine()) != NULL ) |
|
|
|
{ |
|
|
|
p = strtok( line, " \t\n" ); |
|
|
|
|
|
|
|
if( p && strcasecmp( p, "ENDDEF" ) == 0 ) |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Ensure m_unitCount is >= 1 (could be read as 0 in old libraries)
|
|
|
|
if( m_unitCount < 1 ) |
|
|
|
m_unitCount = 1; |
|
|
|
|
|
|
|
m_showPinNumbers = ( drawnum == 'N' ) ? false : true; |
|
|
|
m_showPinNames = ( drawname == 'N' ) ? false : true; |
|
|
|
|
|
|
|
// Copy part name and prefix.
|
|
|
|
if( componentName[0] != '~' ) |
|
|
|
{ |
|
|
|
SetName( FROM_UTF8( componentName ) ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
SetName( FROM_UTF8( &componentName[1] ) ); |
|
|
|
GetValueField().SetVisible( false ); |
|
|
|
} |
|
|
|
|
|
|
|
LIB_FIELD& reference = GetReferenceField(); |
|
|
|
|
|
|
|
if( strcmp( prefix, "~" ) == 0 ) |
|
|
|
{ |
|
|
|
reference.Empty(); |
|
|
|
reference.SetVisible( false ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
reference.SetText( FROM_UTF8( prefix ) ); |
|
|
|
} |
|
|
|
|
|
|
|
// Copy optional infos
|
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'L' ) |
|
|
|
m_unitsLocked = true; |
|
|
|
|
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'P' ) |
|
|
|
m_options = ENTRY_POWER; |
|
|
|
|
|
|
|
// Read next lines, until "ENDDEF" is found
|
|
|
|
while( ( line = aLineReader.ReadLine() ) != NULL ) |
|
|
|
{ |
|
|
|
p = strtok( line, " \t\r\n" ); |
|
|
|
|
|
|
|
// This is the error flag ( if an error occurs, result = false)
|
|
|
|
result = true; |
|
|
|
|
|
|
|
if( *line == '#' ) // a comment
|
|
|
|
continue; |
|
|
|
|
|
|
|
if( p == NULL ) // empty line
|
|
|
|
continue; |
|
|
|
|
|
|
|
if( line[0] == 'T' && line[1] == 'i' ) |
|
|
|
result = LoadDateAndTime( aLineReader ); |
|
|
|
else if( *line == 'F' ) |
|
|
|
result = LoadField( aLineReader, Msg ); |
|
|
|
else if( strcmp( p, "ENDDEF" ) == 0 ) // End of component description
|
|
|
|
goto ok; |
|
|
|
else if( strcmp( p, "DRAW" ) == 0 ) |
|
|
|
result = LoadDrawEntries( aLineReader, Msg ); |
|
|
|
else if( strncmp( p, "ALIAS", 5 ) == 0 ) |
|
|
|
{ |
|
|
|
p = strtok( NULL, "\r\n" ); |
|
|
|
result = LoadAliases( p, aErrorMsg ); |
|
|
|
} |
|
|
|
else if( strncmp( p, "$FPLIST", 5 ) == 0 ) |
|
|
|
result = LoadFootprints( aLineReader, Msg ); |
|
|
|
|
|
|
|
// End line or block analysis: test for an error
|
|
|
|
if( !result ) |
|
|
|
{ |
|
|
|
if( Msg.IsEmpty() ) |
|
|
|
aErrorMsg.Printf( wxT( "error occurred at line %d " ), aLineReader.LineNumber() ); |
|
|
|
else |
|
|
|
aErrorMsg.Printf( wxT( "error <%s> occurred at line %d " ), |
|
|
|
GetChars( Msg ), aLineReader.LineNumber() ); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
ok: |
|
|
|
// If we are here, this part is O.k. - put it in:
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool LIB_PART::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorMsg ) |
|
|
|
{ |
|
|
|
char* line; |
|
|
|
LIB_ITEM* newEntry = NULL; |
|
|
|
|
|
|
|
while( true ) |
|
|
|
{ |
|
|
|
if( !( line = aLineReader.ReadLine() ) ) |
|
|
|
{ |
|
|
|
aErrorMsg = wxT( "file ended prematurely loading component draw element" ); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if( strncmp( line, "ENDDRAW", 7 ) == 0 ) |
|
|
|
break; |
|
|
|
|
|
|
|
newEntry = NULL; |
|
|
|
|
|
|
|
switch( line[0] ) |
|
|
|
{ |
|
|
|
case 'A': // Arc
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_ARC( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'C': // Circle
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_CIRCLE( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'T': // Text
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_TEXT( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'S': // Square
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_RECTANGLE( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'X': // Pin Description
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_PIN( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'P': // Polyline
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_POLYLINE( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'B': // Bezier Curves
|
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_BEZIER( this ); |
|
|
|
break; |
|
|
|
|
|
|
|
case '#': // Comment
|
|
|
|
continue; |
|
|
|
|
|
|
|
case '\n': |
|
|
|
case '\r': |
|
|
|
case 0: // empty line
|
|
|
|
continue; |
|
|
|
|
|
|
|
default: |
|
|
|
aErrorMsg.Printf( wxT( "undefined DRAW command %c" ), line[0] ); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if( !newEntry->Load( aLineReader, aErrorMsg ) ) |
|
|
|
{ |
|
|
|
aErrorMsg.Printf( wxT( "error '%s' in DRAW command %c" ), |
|
|
|
GetChars( aErrorMsg ), line[0] ); |
|
|
|
delete newEntry; |
|
|
|
|
|
|
|
// Flush till end of draw section
|
|
|
|
do |
|
|
|
{ |
|
|
|
if( !aLineReader.ReadLine() ) |
|
|
|
{ |
|
|
|
aErrorMsg = wxT( "file ended prematurely while attempting " |
|
|
|
"to flush to end of drawing section." ); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} while( strncmp( line, "ENDDRAW", 7 ) != 0 ); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
m_drawings.push_back( newEntry ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool LIB_PART::LoadAliases( char* aLine, wxString& aErrorMsg ) |
|
|
|
{ |
|
|
|
char* text = strtok( aLine, " \t\r\n" ); |
|
|
|
|
|
|
|
while( text ) |
|
|
|
{ |
|
|
|
m_aliases.push_back( new LIB_ALIAS( FROM_UTF8( text ), this ) ); |
|
|
|
text = strtok( NULL, " \t\r\n" ); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool LIB_PART::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg ) |
|
|
|
{ |
|
|
|
LIB_FIELD* field = new LIB_FIELD( this ); |
|
|
|
|
|
|
|
if( !field->Load( aLineReader, aErrorMsg ) ) |
|
|
|
{ |
|
|
|
delete field; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if( (unsigned) field->GetId() < MANDATORY_FIELDS ) |
|
|
|
{ |
|
|
|
LIB_FIELD* fixedField = GetField( field->GetId() ); |
|
|
|
|
|
|
|
// this will fire only if somebody broke a constructor or editor.
|
|
|
|
// MANDATORY_FIELDS are always present in ram resident components, no
|
|
|
|
// exceptions, and they always have their names set, even fixed fields.
|
|
|
|
wxASSERT( fixedField ); |
|
|
|
|
|
|
|
*fixedField = *field; |
|
|
|
|
|
|
|
if( field->GetId() == VALUE ) |
|
|
|
SetName( field->GetText() ); |
|
|
|
|
|
|
|
delete field; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
m_drawings.push_back( field ); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool LIB_PART::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMsg ) |
|
|
|
{ |
|
|
|
char* line; |
|
|
|
char* p; |
|
|
|
|
|
|
|
while( true ) |
|
|
|
{ |
|
|
|
if( !( line = aLineReader.ReadLine() ) ) |
|
|
|
{ |
|
|
|
aErrorMsg = wxT( "file ended prematurely while loading footprints" ); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
p = strtok( line, " \t\r\n" ); |
|
|
|
|
|
|
|
if( strcasecmp( p, "$ENDFPLIST" ) == 0 ) |
|
|
|
break; |
|
|
|
|
|
|
|
m_FootprintList.Add( FROM_UTF8( p ) ); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const EDA_RECT LIB_PART::GetUnitBoundingBox( int aUnit, int aConvert ) const |
|
|
|
{ |
|
|
|
EDA_RECT bBox; |
|
|
|
|