Fix some bugs in Change Symbol and Update Symbols.

In particular, there was a typo that kept library values from being
updated, and there was missing logic to fetch the various field names
from the library parts (and the change-to part).

Also implements some performance gains by desisting from copying
LIB_FIELDs around every time we want to look at them.

Fixes https://gitlab.com/kicad/code/kicad/issues/6733

Fixes https://gitlab.com/kicad/code/kicad/issues/6749
This commit is contained in:
Jeff Young 2020-12-15 15:06:19 +00:00
parent ffdc46d313
commit 10e68daa37
16 changed files with 197 additions and 255 deletions

View File

@ -829,6 +829,12 @@ void LIB_PART::deleteAllFields()
}
void LIB_PART::AddField( LIB_FIELD* aField )
{
AddDrawItem( aField );
}
void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
{
deleteAllFields();
@ -844,31 +850,36 @@ void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
}
void LIB_PART::GetFields( LIB_FIELDS& aList )
void LIB_PART::GetFields( std::vector<LIB_FIELD*>& aList )
{
LIB_FIELD* field;
// Grab the MANDATORY_FIELDS first, in expected order given by
// enum NumFieldType
for( int id=0; id<MANDATORY_FIELDS; ++id )
{
field = GetField( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxASSERT( field );
aList.push_back( *field );
}
// Grab the MANDATORY_FIELDS first, in expected order given by enum NumFieldType
for( int id = 0; id < MANDATORY_FIELDS; ++id )
aList.push_back( GetField( id ) );
// Now grab all the rest of fields.
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
{
field = ( LIB_FIELD* ) &item;
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
if( field->IsMandatory() )
continue; // was added above
if( !field->IsMandatory() )
aList.push_back( field );
}
}
aList.push_back( *field );
void LIB_PART::GetFields( std::vector<LIB_FIELD>& aList )
{
// Grab the MANDATORY_FIELDS first, in expected order given by enum NumFieldType
for( int id = 0; id < MANDATORY_FIELDS; ++id )
aList.push_back( *GetField( id ) );
// Now grab all the rest of fields.
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
{
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
if( !field->IsMandatory() )
aList.push_back( *field );
}
}

View File

@ -255,7 +255,14 @@ public:
*
* @param aList - List to add fields to
*/
void GetFields( LIB_FIELDS& aList );
void GetFields( std::vector<LIB_FIELD*>& aList );
void GetFields( std::vector<LIB_FIELD>& aList );
/**
* Add a field. Takes ownership of the pointer.
* @param aField
*/
void AddField( LIB_FIELD* aField );
/**
* Find a field within this part matching \a aFieldName and returns it

View File

@ -237,22 +237,12 @@ void DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser( wxCommandEvent& aEvent )
void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
{
SCH_EDIT_FRAME* frame = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );
wxCHECK( frame, /* void */ );
LIB_ID newId;
SCH_SHEET_LIST hierarchy = frame->Schematic().GetSheets();
if( m_mode == MODE::CHANGE )
{
newId.Parse( m_newId->GetValue(), LIB_ID::ID_SCH );
if( !newId.IsValid() )
return;
}
// Load new non-mandatory fields from the library parts of all matching symbols
std::set<wxString> fieldNames;
// Load non-mandatory fields from all matching symbols and their library parts
std::vector<SCH_FIELD*> fields;
std::vector<LIB_FIELD*> libFields;
std::set<wxString> fieldNames;
for( SCH_SHEET_PATH& instance : hierarchy )
{
@ -269,10 +259,43 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
if( !isMatch( symbol, &instance ) )
continue;
std::vector<SCH_FIELD>& fields = symbol->GetFields();
symbol->GetFields( fields, false );
for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
fieldNames.insert( fields[i].GetName() );
fieldNames.insert( fields[i]->GetName() );
if( m_mode == MODE::UPDATE && symbol->GetPartRef() )
{
symbol->GetPartRef()->Flatten()->GetFields( libFields );
for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i )
fieldNames.insert( libFields[i]->GetName() );
}
}
}
// Load non-mandatory fields from the change-to library part
if( m_mode == MODE::CHANGE )
{
LIB_ID newId;
newId.Parse( m_newId->GetValue(), LIB_ID::ID_SCH );
if( newId.IsValid() )
{
LIB_PART* libSymbol = frame->GetLibPart( newId );
if( libSymbol )
{
std::unique_ptr<LIB_PART> flattenedPart = libSymbol->Flatten();
flattenedPart->GetFields( libFields );
for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i )
fieldNames.insert( libFields[i]->GetName() );
libFields.clear(); // flattenedPart is about to go out of scope...
}
}
}
@ -486,7 +509,7 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
return false;
}
std::unique_ptr< LIB_PART > flattenedSymbol = libSymbol->Flatten();
std::unique_ptr<LIB_PART> flattenedSymbol = libSymbol->Flatten();
if( flattenedSymbol->GetUnitCount() < aSymbol->GetUnit() )
{
@ -535,7 +558,7 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
else if( i == FOOTPRINT_FIELD )
aSymbol->SetFootprint( aInstance, libField->GetText() );
else
field->SetText( wxEmptyString );
field->SetText( libField->GetText() );
}
if( resetVis )
@ -550,9 +573,7 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
}
if( resetPositions )
{
field->SetTextPos( aSymbol->GetPosition() + libField->GetTextPos() );
}
}
else if( i >= MANDATORY_FIELDS && removeExtras )
{
@ -561,12 +582,12 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
}
}
LIB_FIELDS libFields;
std::vector<LIB_FIELD*> libFields;
libSymbol->GetFields( libFields );
for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i )
{
LIB_FIELD& libField = libFields[i];
const LIB_FIELD& libField = *libFields[i];
if( !alg::contains( m_updateFields, libField.GetName() ) )
continue;

View File

@ -113,10 +113,15 @@ DIALOG_SPICE_MODEL::DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aCompo
}
DIALOG_SPICE_MODEL::DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent, LIB_FIELDS* aFields )
: DIALOG_SPICE_MODEL_BASE( aParent ), m_component( aComponent ), m_schfields( nullptr ),
m_libfields( aFields ), m_useSchFields( false ),
m_spiceEmptyValidator( true ), m_notEmptyValidator( wxFILTER_EMPTY )
DIALOG_SPICE_MODEL::DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent,
std::vector<LIB_FIELD>* aFields ) :
DIALOG_SPICE_MODEL_BASE( aParent ),
m_component( aComponent ),
m_schfields( nullptr ),
m_libfields( aFields ),
m_useSchFields( false ),
m_spiceEmptyValidator( true ),
m_notEmptyValidator( wxFILTER_EMPTY )
{
Init();
}

View File

@ -38,8 +38,10 @@
class DIALOG_SPICE_MODEL : public DIALOG_SPICE_MODEL_BASE
{
public:
DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent, SCH_FIELDS* aSchFields );
DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent, LIB_FIELDS* aLibFields );
DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent,
std::vector<SCH_FIELD>* aSchFields );
DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent,
std::vector<LIB_FIELD>* aLibFields );
private:
/**
@ -124,8 +126,8 @@ private:
SCH_COMPONENT& m_component;
///> Fields from the component properties dialog
SCH_FIELDS* m_schfields;
LIB_FIELDS* m_libfields;
std::vector<SCH_FIELD>* m_schfields;
std::vector<LIB_FIELD>* m_libfields;
bool m_useSchFields;
///> Temporary field values

View File

@ -202,32 +202,31 @@ protected:
void SetHtmlFieldTable()
{
wxString fieldtable;
LIB_FIELDS fields;
wxString fieldtable;
std::vector<LIB_FIELD*> fields;
m_symbol->GetFields( fields );
for( auto const & field: fields )
{
fieldtable += GetHtmlFieldRow( field );
}
for( const LIB_FIELD* field: fields )
fieldtable += GetHtmlFieldRow( *field );
if( m_symbol->IsAlias() )
{
std::shared_ptr< LIB_PART > parent = m_symbol->GetParent().lock();
std::shared_ptr<LIB_PART> parent = m_symbol->GetParent().lock();
// Append all of the unique parent fields if this is an alias.
if( parent )
{
LIB_FIELDS parentFields;
std::vector<LIB_FIELD*> parentFields;
parent->GetFields( parentFields );
for( auto const& parentField : parentFields )
for( const LIB_FIELD* parentField : parentFields )
{
if( m_symbol->FindField( parentField.GetCanonicalName() ) )
if( m_symbol->FindField( parentField->GetCanonicalName() ) )
continue;
fieldtable += GetHtmlFieldRow( parentField );
fieldtable += GetHtmlFieldRow( *parentField );
}
}
}

View File

@ -215,6 +215,4 @@ private:
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
};
typedef std::vector< LIB_FIELD > LIB_FIELDS;
#endif // CLASS_LIBENTRY_FIELDS_H

View File

@ -458,10 +458,10 @@ XNODE* NETLIST_EXPORTER_XML::makeLibraries()
XNODE* NETLIST_EXPORTER_XML::makeLibParts()
{
XNODE* xlibparts = node( "libparts" ); // auto_ptr
XNODE* xlibparts = node( "libparts" ); // auto_ptr
LIB_PINS pinList;
LIB_FIELDS fieldList;
LIB_PINS pinList;
std::vector<LIB_FIELD*> fieldList;
m_libraries.clear();
@ -502,13 +502,13 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts()
XNODE* xfields;
xlibpart->AddChild( xfields = node( "fields" ) );
for( unsigned i=0; i<fieldList.size(); ++i )
for( const LIB_FIELD* field : fieldList )
{
if( !fieldList[i].GetText().IsEmpty() )
if( !field->GetText().IsEmpty() )
{
XNODE* xfield;
xfields->AddChild( xfield = node( "field", fieldList[i].GetText() ) );
xfield->AddAttribute( "name", fieldList[i].GetCanonicalName() );
xfields->AddChild( xfield = node( "field", field->GetText() ) );
xfield->AddAttribute( "name", field->GetCanonicalName() );
}
}

View File

@ -748,13 +748,14 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
{
if( m_part )
{
wxString symbolName;
LIB_FIELDS fields;
wxString symbolName;
std::vector<LIB_FIELD*> fields;
m_part->GetFields( fields );
for( const LIB_FIELD& libField : fields )
for( const LIB_FIELD* libField : fields )
{
int idx = libField.GetId();
int idx = libField->GetId();
SCH_FIELD* schField;
if( idx == REFERENCE_FIELD && !aResetRef )
@ -766,11 +767,11 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
}
else
{
schField = FindField( libField.GetCanonicalName() );
schField = FindField( libField->GetCanonicalName() );
if( !schField )
{
wxString fieldName = libField.GetCanonicalName();
wxString fieldName = libField->GetCanonicalName();
SCH_FIELD newField( wxPoint( 0, 0), GetFieldCount(), this, fieldName );
schField = AddField( newField );
}
@ -778,8 +779,8 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
if( aResetStyle )
{
schField->ImportValues( libField );
schField->SetTextPos( m_pos + libField.GetTextPos() );
schField->ImportValues( *libField );
schField->SetTextPos( m_pos + libField->GetTextPos() );
}
if( idx == VALUE_FIELD )
@ -793,7 +794,7 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
}
else
{
schField->SetText( libField.GetText() );
schField->SetText( libField->GetText() );
}
}
}

View File

@ -372,9 +372,7 @@ bool SCH_FIELD::IsReplaceable() const
if( m_id == VALUE_FIELD )
{
LIB_PART* part = parentSymbol->GetPartRef().get();
if( part && part->IsPower() )
if( parentSymbol->GetPartRef() && parentSymbol->GetPartRef()->IsPower() )
return false;
}
}

View File

@ -1014,10 +1014,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
if( !field )
{
field = new LIB_FIELD( aPart, FIELD1 );
std::vector<LIB_FIELD> partFields;
aPart->GetFields( partFields );
partFields.push_back( *field );
aPart->SetFields( partFields );
aPart->AddField( field );
}
field->SetName( "Part Name" );

View File

@ -1151,14 +1151,14 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
component->MirrorY( einstance.x.ToSchUnits() );
}
LIB_FIELDS partFields;
std::vector<LIB_FIELD*> partFields;
part->GetFields( partFields );
for( auto const& field : partFields )
for( const LIB_FIELD* field : partFields )
{
component->GetField( field.GetId() )->ImportValues( field );
component->GetField( field.GetId() )
->SetTextPos( component->GetPosition() + field.GetTextPos() );
component->GetField( field->GetId() )->ImportValues( *field );
component->GetField( field->GetId() )->SetTextPos( component->GetPosition()
+ field->GetTextPos() );
}
// If there is no footprint assigned, then prepend the reference value

View File

@ -297,8 +297,6 @@ class SCH_SEXPR_PLUGIN_CACHE
int m_versionMinor;
SCH_LIB_TYPE m_libType; // Is this cache a component or symbol library.
static FILL_TYPE parseFillMode( LINE_READER& aReader, const char* aLine,
const char** aOutput );
LIB_PART* removeSymbol( LIB_PART* aAlias );
static void saveSymbolDrawItem( LIB_ITEM* aItem, OUTPUTFORMATTER& aFormatter,
@ -308,7 +306,8 @@ class SCH_SEXPR_PLUGIN_CACHE
int aNestLevel = 0 );
static void saveCircle( LIB_CIRCLE* aCircle, OUTPUTFORMATTER& aFormatter,
int aNestLevel = 0 );
static void saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 );
static void saveField( const LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter,
int aNestLevel = 0 );
static void savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 );
static void savePolyLine( LIB_POLYLINE* aPolyLine, OUTPUTFORMATTER& aFormatter,
int aNestLevel = 0 );
@ -1520,7 +1519,7 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo
LOCALE_IO toggle );
int lastFieldId;
LIB_FIELDS fields;
std::vector<LIB_FIELD*> fields;
std::string name = aFormatter.Quotew( aSymbol->GetLibId().Format().wx_str() );
std::string unitName = aSymbol->GetLibId().GetLibItemName();
@ -1575,10 +1574,10 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo
aSymbol->GetFields( fields );
for( LIB_FIELD& field : fields )
saveField( &field, aFormatter, aNestLevel + 1 );
for( const LIB_FIELD* field : fields )
saveField( field, aFormatter, aNestLevel + 1 );
lastFieldId = fields.back().GetId() + 1;
lastFieldId = fields.back()->GetId() + 1;
// @todo At some point in the future the lock status (all units interchangeable) should
// be set deterministically. For now a custom lock propertery is used to preserve the
@ -1594,13 +1593,14 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo
// Save the draw items grouped by units.
std::vector<PART_UNITS> units = aSymbol->GetUnitDrawItems();
std::sort( units.begin(), units.end(), []( const PART_UNITS& a, const PART_UNITS& b )
{
if( a.m_unit == b.m_unit )
return a.m_convert < b.m_convert;
std::sort( units.begin(), units.end(),
[]( const PART_UNITS& a, const PART_UNITS& b )
{
if( a.m_unit == b.m_unit )
return a.m_convert < b.m_convert;
return a.m_unit < b.m_unit;
} );
return a.m_unit < b.m_unit;
} );
for( auto unit : units )
{
@ -1629,10 +1629,10 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo
aSymbol->GetFields( fields );
for( LIB_FIELD& field : fields )
saveField( &field, aFormatter, aNestLevel + 1 );
for( const LIB_FIELD* field : fields )
saveField( field, aFormatter, aNestLevel + 1 );
lastFieldId = fields.back().GetId() + 1;
lastFieldId = fields.back()->GetId() + 1;
saveDcmInfoAsFields( aSymbol, aFormatter, aNestLevel, lastFieldId );
}
@ -1730,8 +1730,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveSymbolDrawItem( LIB_ITEM* aItem, OUTPUTFORMATTE
}
void SCH_SEXPR_PLUGIN_CACHE::saveArc( LIB_ARC* aArc,
OUTPUTFORMATTER& aFormatter,
void SCH_SEXPR_PLUGIN_CACHE::saveArc( LIB_ARC* aArc, OUTPUTFORMATTER& aFormatter,
int aNestLevel )
{
wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
@ -1837,8 +1836,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveCircle( LIB_CIRCLE* aCircle,
}
void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField,
OUTPUTFORMATTER& aFormatter,
void SCH_SEXPR_PLUGIN_CACHE::saveField( const LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter,
int aNestLevel )
{
wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
@ -1956,8 +1954,7 @@ void SCH_SEXPR_PLUGIN_CACHE::savePolyLine( LIB_POLYLINE* aPolyLine,
}
void SCH_SEXPR_PLUGIN_CACHE::saveRectangle( LIB_RECTANGLE* aRectangle,
OUTPUTFORMATTER& aFormatter,
void SCH_SEXPR_PLUGIN_CACHE::saveRectangle( LIB_RECTANGLE* aRectangle, OUTPUTFORMATTER& aFormatter,
int aNestLevel )
{
wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
@ -1976,8 +1973,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveRectangle( LIB_RECTANGLE* aRectangle,
}
void SCH_SEXPR_PLUGIN_CACHE::saveText( LIB_TEXT* aText,
OUTPUTFORMATTER& aFormatter,
void SCH_SEXPR_PLUGIN_CACHE::saveText( LIB_TEXT* aText, OUTPUTFORMATTER& aFormatter,
int aNestLevel )
{
wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );

View File

@ -514,11 +514,11 @@ class SCH_LEGACY_PLUGIN_CACHE
static void saveArc( LIB_ARC* aArc, OUTPUTFORMATTER& aFormatter );
static void saveBezier( LIB_BEZIER* aBezier, OUTPUTFORMATTER& aFormatter );
static void saveCircle( LIB_CIRCLE* aCircle, OUTPUTFORMATTER& aFormatter );
static void saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter );
static void savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter );
static void saveField( const LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter );
static void savePin( const LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter );
static void savePolyLine( LIB_POLYLINE* aPolyLine, OUTPUTFORMATTER& aFormatter );
static void saveRectangle( LIB_RECTANGLE* aRectangle, OUTPUTFORMATTER& aFormatter );
static void saveText( LIB_TEXT* aText, OUTPUTFORMATTER& aFormatter );
static void saveText( const LIB_TEXT* aText, OUTPUTFORMATTER& aFormatter );
friend SCH_LEGACY_PLUGIN;
@ -3811,17 +3811,15 @@ void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aF
aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
}
LIB_FIELDS fields;
std::vector<LIB_FIELD*> fields;
aSymbol->GetFields( fields );
// Mandatory fields:
// may have their own save policy so there is a separate loop for them.
// Empty fields are saved, because the user may have set visibility,
// size and orientation
for( int i = 0; i < MANDATORY_FIELDS; ++i )
{
saveField( &fields[i], aFormatter );
}
for( int i = 0; i < MANDATORY_FIELDS; ++i )
saveField( fields[i], aFormatter );
// User defined fields:
// may have their own save policy so there is a separate loop for them.
@ -3833,10 +3831,10 @@ void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aF
// There is no need to save empty fields, i.e. no reason to preserve field
// names now that fields names come in dynamically through the template
// fieldnames.
if( !fields[i].GetText().IsEmpty() )
if( !fields[i]->GetText().IsEmpty() )
{
fields[i].SetId( fieldId++ );
saveField( &fields[i], aFormatter );
fields[i]->SetId( fieldId++ );
saveField( fields[i], aFormatter );
}
}
@ -3846,9 +3844,7 @@ void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aF
aFormatter.Print( 0, "ALIAS" );
for( unsigned i = 0; i < aliasNames.GetCount(); i++ )
{
aFormatter.Print( 0, " %s", TO_UTF8( aliasNames[i] ) );
}
aFormatter.Print( 0, "\n" );
}
@ -3861,9 +3857,7 @@ void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aF
aFormatter.Print( 0, "$FPLIST\n" );
for( unsigned i = 0; i < footprints.GetCount(); i++ )
{
aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
}
aFormatter.Print( 0, "$ENDFPLIST\n" );
}
@ -3880,39 +3874,15 @@ void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aF
{
switch( item.Type() )
{
case LIB_FIELD_T: // Fields have already been saved above.
continue;
case LIB_ARC_T:
saveArc( (LIB_ARC*) &item, aFormatter );
break;
case LIB_BEZIER_T:
saveBezier( (LIB_BEZIER*) &item, aFormatter );
break;
case LIB_CIRCLE_T:
saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
break;
case LIB_PIN_T:
savePin( (LIB_PIN* ) &item, aFormatter );
break;
case LIB_POLYLINE_T:
savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
break;
case LIB_RECTANGLE_T:
saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
break;
case LIB_TEXT_T:
saveText( ( LIB_TEXT* ) &item, aFormatter );
break;
default:
;
case LIB_FIELD_T: /* Fields have already been saved above. */ break;
case LIB_ARC_T: saveArc( (LIB_ARC*) &item, aFormatter ); break;
case LIB_BEZIER_T: saveBezier( (LIB_BEZIER*) &item, aFormatter ); break;
case LIB_CIRCLE_T: saveCircle( ( LIB_CIRCLE* ) &item, aFormatter ); break;
case LIB_PIN_T: savePin( (LIB_PIN* ) &item, aFormatter ); break;
case LIB_POLYLINE_T: savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter ); break;
case LIB_RECTANGLE_T: saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter ); break;
case LIB_TEXT_T: saveText( ( LIB_TEXT* ) &item, aFormatter ); break;
}
}
@ -3923,8 +3893,7 @@ void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aF
}
void SCH_LEGACY_PLUGIN_CACHE::saveArc( LIB_ARC* aArc,
OUTPUTFORMATTER& aFormatter )
void SCH_LEGACY_PLUGIN_CACHE::saveArc( LIB_ARC* aArc, OUTPUTFORMATTER& aFormatter )
{
wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
@ -3974,8 +3943,7 @@ void SCH_LEGACY_PLUGIN_CACHE::saveCircle( LIB_CIRCLE* aCircle,
}
void SCH_LEGACY_PLUGIN_CACHE::saveField( LIB_FIELD* aField,
OUTPUTFORMATTER& aFormatter )
void SCH_LEGACY_PLUGIN_CACHE::saveField( const LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter )
{
wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
@ -4022,8 +3990,7 @@ void SCH_LEGACY_PLUGIN_CACHE::saveField( LIB_FIELD* aField,
}
void SCH_LEGACY_PLUGIN_CACHE::savePin( LIB_PIN* aPin,
OUTPUTFORMATTER& aFormatter )
void SCH_LEGACY_PLUGIN_CACHE::savePin( const LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter )
{
wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
@ -4032,49 +3999,17 @@ void SCH_LEGACY_PLUGIN_CACHE::savePin( LIB_PIN* aPin,
switch( aPin->GetType() )
{
default:
case ELECTRICAL_PINTYPE::PT_INPUT:
Etype = 'I';
break;
case ELECTRICAL_PINTYPE::PT_OUTPUT:
Etype = 'O';
break;
case ELECTRICAL_PINTYPE::PT_BIDI:
Etype = 'B';
break;
case ELECTRICAL_PINTYPE::PT_TRISTATE:
Etype = 'T';
break;
case ELECTRICAL_PINTYPE::PT_PASSIVE:
Etype = 'P';
break;
case ELECTRICAL_PINTYPE::PT_UNSPECIFIED:
Etype = 'U';
break;
case ELECTRICAL_PINTYPE::PT_POWER_IN:
Etype = 'W';
break;
case ELECTRICAL_PINTYPE::PT_POWER_OUT:
Etype = 'w';
break;
case ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR:
Etype = 'C';
break;
case ELECTRICAL_PINTYPE::PT_OPENEMITTER:
Etype = 'E';
break;
case ELECTRICAL_PINTYPE::PT_NC:
Etype = 'N';
break;
case ELECTRICAL_PINTYPE::PT_INPUT: Etype = 'I'; break;
case ELECTRICAL_PINTYPE::PT_OUTPUT: Etype = 'O'; break;
case ELECTRICAL_PINTYPE::PT_BIDI: Etype = 'B'; break;
case ELECTRICAL_PINTYPE::PT_TRISTATE: Etype = 'T'; break;
case ELECTRICAL_PINTYPE::PT_PASSIVE: Etype = 'P'; break;
case ELECTRICAL_PINTYPE::PT_UNSPECIFIED: Etype = 'U'; break;
case ELECTRICAL_PINTYPE::PT_POWER_IN: Etype = 'W'; break;
case ELECTRICAL_PINTYPE::PT_POWER_OUT: Etype = 'w'; break;
case ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR: Etype = 'C'; break;
case ELECTRICAL_PINTYPE::PT_OPENEMITTER: Etype = 'E'; break;
case ELECTRICAL_PINTYPE::PT_NC: Etype = 'N'; break;
}
if( !aPin->GetName().IsEmpty() )
@ -4097,48 +4032,21 @@ void SCH_LEGACY_PLUGIN_CACHE::savePin( LIB_PIN* aPin,
switch( aPin->GetShape() )
{
case GRAPHIC_PINSHAPE::LINE:
break;
case GRAPHIC_PINSHAPE::INVERTED:
aFormatter.Print( 0, "I" );
break;
case GRAPHIC_PINSHAPE::CLOCK:
aFormatter.Print( 0, "C" );
break;
case GRAPHIC_PINSHAPE::INVERTED_CLOCK:
aFormatter.Print( 0, "IC" );
break;
case GRAPHIC_PINSHAPE::INPUT_LOW:
aFormatter.Print( 0, "L" );
break;
case GRAPHIC_PINSHAPE::CLOCK_LOW:
aFormatter.Print( 0, "CL" );
break;
case GRAPHIC_PINSHAPE::OUTPUT_LOW:
aFormatter.Print( 0, "V" );
break;
case GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK:
aFormatter.Print( 0, "F" );
break;
case GRAPHIC_PINSHAPE::NONLOGIC:
aFormatter.Print( 0, "X" );
break;
default:
assert( !"Invalid pin shape" );
case GRAPHIC_PINSHAPE::LINE: break;
case GRAPHIC_PINSHAPE::INVERTED: aFormatter.Print( 0, "I" ); break;
case GRAPHIC_PINSHAPE::CLOCK: aFormatter.Print( 0, "C" ); break;
case GRAPHIC_PINSHAPE::INVERTED_CLOCK: aFormatter.Print( 0, "IC" ); break;
case GRAPHIC_PINSHAPE::INPUT_LOW: aFormatter.Print( 0, "L" ); break;
case GRAPHIC_PINSHAPE::CLOCK_LOW: aFormatter.Print( 0, "CL" ); break;
case GRAPHIC_PINSHAPE::OUTPUT_LOW: aFormatter.Print( 0, "V" ); break;
case GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK: aFormatter.Print( 0, "F" ); break;
case GRAPHIC_PINSHAPE::NONLOGIC: aFormatter.Print( 0, "X" ); break;
default: wxFAIL_MSG( "Invalid pin shape" );
}
aFormatter.Print( 0, "\n" );
aPin->ClearFlags( IS_CHANGED );
const_cast<LIB_PIN*>( aPin )->ClearFlags( IS_CHANGED );
}
@ -4176,8 +4084,7 @@ void SCH_LEGACY_PLUGIN_CACHE::saveRectangle( LIB_RECTANGLE* aRectangle,
}
void SCH_LEGACY_PLUGIN_CACHE::saveText( LIB_TEXT* aText,
OUTPUTFORMATTER& aFormatter )
void SCH_LEGACY_PLUGIN_CACHE::saveText( const LIB_TEXT* aText, OUTPUTFORMATTER& aFormatter )
{
wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );

View File

@ -47,9 +47,9 @@ struct print_log_value<LIB_FIELD>
};
template <>
struct print_log_value<LIB_FIELDS>
struct print_log_value<std::vector<LIB_FIELD>>
{
inline void operator()( std::ostream& os, LIB_FIELDS const& f )
inline void operator()( std::ostream& os, std::vector<LIB_FIELD> const& f )
{
os << "LIB_FIELDS[ " << f.size() << " ]";
}
@ -96,7 +96,7 @@ bool FieldNameIdMatches( const LIB_FIELD& aField, const std::string& aExpectedNa
* @param aFields the fields to check
* @return true if valid
*/
bool AreDefaultFieldsCorrect( const LIB_FIELDS& aFields )
bool AreDefaultFieldsCorrect( const std::vector<LIB_FIELD>& aFields )
{
const unsigned expectedCount = NumFieldType::MANDATORY_FIELDS;
if( aFields.size() < expectedCount )

View File

@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE( DefaultDrawings )
*/
BOOST_AUTO_TEST_CASE( DefaultFields )
{
LIB_FIELDS fields;
std::vector<LIB_FIELD> fields;
m_part_no_data.GetFields( fields );
// Should get the 4 default fields
@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE( DefaultFields )
*/
BOOST_AUTO_TEST_CASE( AddedFields )
{
LIB_FIELDS fields;
std::vector<LIB_FIELD> fields;
m_part_no_data.GetFields( fields );
// Ctor takes non-const ref (?!)