Commit 61e65654 authored by jean-pierre charras's avatar jean-pierre charras

Eeschema: fixed bug 577083. Also fixed a bad import of predefined fields when...

Eeschema: fixed bug 577083. Also fixed a bad import of predefined fields when loading a component from a library, when this component has some empty fields like footprint and documentation but have user fields not void.
parent 4bbdeab9
......@@ -137,10 +137,9 @@ bool LIB_FIELD::Load( char* line, wxString& errorMsg )
char fieldUserName[1024];
char* text;
if( sscanf( line + 1, "%d", &m_FieldId ) != 1
|| m_FieldId < REFERENCE || m_FieldId >= NUMBER_OF_FIELDS )
if( sscanf( line + 1, "%d", &m_FieldId ) != 1 || m_FieldId < 0 )
{
errorMsg = _( "invalid field number defined" );
errorMsg = wxT( "invalid field header" );
return false;
}
......
......@@ -63,8 +63,6 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent,
const wxPoint& pos, bool setNewItemFlag ) :
SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
{
size_t i;
LIB_FIELD_LIST libFields;
Init( pos );
......@@ -76,32 +74,34 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent,
if( setNewItemFlag )
m_Flags = IS_NEW | IS_MOVED;
// Import predefined fields from the library component:
LIB_FIELD_LIST libFields;
libComponent.GetFields( libFields );
for( i = 0; i < libFields.size(); i++ )
for( size_t i = 0; i < libFields.size(); i++ )
{
if( libFields[i].m_Text.IsEmpty() && libFields[i].m_Name.IsEmpty() )
continue;
int field_idx = libFields[i].m_FieldId;
/* Add extra fields if library component has more than the default
* number of fields.
*/
if( (int) i >= GetFieldCount() )
if( field_idx >= GetFieldCount() )
{
while( (int) i >= GetFieldCount() )
while( field_idx >= GetFieldCount() )
{
SCH_FIELD field( wxPoint( 0, 0 ), GetFieldCount(), this,
ReturnDefaultFieldName( i ) );
ReturnDefaultFieldName( field_idx ) );
AddField( field );
}
}
SCH_FIELD* schField = GetField( i );
SCH_FIELD* schField = GetField( field_idx );
schField->m_Pos = m_Pos + libFields[i].m_Pos;
schField->ImportValues( libFields[i] );
schField->m_Text = libFields[i].m_Text;
schField->m_Name = ( i < FIELD1 ) ? ReturnDefaultFieldName( i ) :
schField->m_Name = ( field_idx < FIELD1 ) ? ReturnDefaultFieldName( field_idx ) :
libFields[i].m_Name;
}
......@@ -156,9 +156,9 @@ void SCH_COMPONENT::Init( const wxPoint& pos )
m_Transform[1][0] = 0;
m_Transform[1][1] = -1;
m_Fields.reserve( NUMBER_OF_FIELDS );
m_Fields.reserve( DEFAULT_NUMBER_OF_FIELDS );
for( int i = 0; i < NUMBER_OF_FIELDS; ++i )
for( int i = 0; i < DEFAULT_NUMBER_OF_FIELDS; ++i )
{
SCH_FIELD field( pos, i, this, ReturnDefaultFieldName( i ) );
......@@ -1174,7 +1174,7 @@ bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void * aAuxData )
if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS ) )
return false;
for( size_t i = VALUE+1; i < NUMBER_OF_FIELDS; i++ )
for( size_t i = VALUE+1; i < m_Fields.size(); i++ )
{
if( GetField( i )->Matches( aSearchData, aAuxData ) )
return true;
......
......@@ -35,6 +35,8 @@ struct Error
/**
* Enum NumFieldType
* is the numbered set of all fields a SCH_COMPONENT can hold
* Note more than 8 user fields are allowed, but for efficiency reasons
* the defualt number of users fields is 8
*/
enum NumFieldType {
REFERENCE = 0, ///< Field Reference of part, i.e. "IC21"
......@@ -51,7 +53,7 @@ enum NumFieldType {
FIELD7,
FIELD8,
NUMBER_OF_FIELDS
DEFAULT_NUMBER_OF_FIELDS
};
......
......@@ -421,7 +421,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers( void )
m_LibEntry->GetFields( fields );
// copy all the fields to a work area
m_FieldsBuf.reserve(NUMBER_OF_FIELDS);
m_FieldsBuf.reserve(DEFAULT_NUMBER_OF_FIELDS);
// Creates a working copy of fields
for( size_t i = 0; i < fields.size(); i++ )
......@@ -430,7 +430,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers( void )
// Display 12 fields (or more), and add missing fields
LIB_FIELD blank( 2 );
unsigned fcount = m_FieldsBuf.size();
for( unsigned ii = 2; ii < NUMBER_OF_FIELDS; ii++ )
for( unsigned ii = 2; ii < DEFAULT_NUMBER_OF_FIELDS; ii++ )
{
unsigned jj;
for ( jj = 2; jj < fcount; jj ++ )
......@@ -449,7 +449,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers( void )
// Now, all fields with Id 0 to NUMBER_OF_FIELDS-1 exist
// init default fields names
for( int ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ )
{
if( m_FieldsBuf[ii].m_Name.IsEmpty() || ii < FIELD1 )
m_FieldsBuf[ii].m_Name = ReturnDefaultFieldName( ii );
......
......@@ -54,7 +54,7 @@ static void PlotLibPart( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem )
Entry->Plot( plotter, DrawLibItem->m_Multi, DrawLibItem->m_Convert,
DrawLibItem->m_Pos, TransMat );
bool isMulti = Entry->GetPartCount() > 1;
for( int fieldId = 0; fieldId < NUMBER_OF_FIELDS; fieldId++ )
for( int fieldId = 0; fieldId < DrawLibItem->GetFieldCount(); fieldId++ )
{
PlotTextField( plotter, DrawLibItem, fieldId, isMulti, 0 );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment