'Update Field Values' tool for eeschema
This commit is contained in:
parent
78c285b83a
commit
e29d77c891
|
@ -71,6 +71,7 @@ enum id_eeschema_frm
|
|||
ID_GET_ANNOTATE,
|
||||
ID_GET_ERC,
|
||||
ID_BACKANNO_ITEMS,
|
||||
ID_UPDATE_FIELDS,
|
||||
ID_GEN_PLOT_SCHEMATIC,
|
||||
|
||||
/* Schematic editor veritcal toolbar IDs */
|
||||
|
|
|
@ -443,6 +443,12 @@ void prepareEditMenu( wxMenu* aParentMenu )
|
|||
_( "Import Footprint Association File" ),
|
||||
HELP_IMPORT_FOOTPRINTS,
|
||||
KiBitmap( import_footprint_names_xpm ) );
|
||||
|
||||
// Update field values
|
||||
AddMenuItem( aParentMenu, ID_UPDATE_FIELDS,
|
||||
_( "Update Field Values" ),
|
||||
_( "Sets component fields to original library values" ),
|
||||
KiBitmap( update_fields_xpm ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -143,43 +143,8 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit,
|
|||
if( setNewItemFlag )
|
||||
m_Flags = IS_NEW | IS_MOVED;
|
||||
|
||||
// Import user defined fields from the library component:
|
||||
LIB_FIELDS libFields;
|
||||
|
||||
aPart.GetFields( libFields );
|
||||
|
||||
for( LIB_FIELDS::iterator it = libFields.begin(); it!=libFields.end(); ++it )
|
||||
{
|
||||
// Can no longer insert an empty name, since names are now keys. The
|
||||
// field index is not used beyond the first MANDATORY_FIELDS
|
||||
if( it->GetName().IsEmpty() )
|
||||
continue;
|
||||
|
||||
// See if field already exists (mandatory fields always exist).
|
||||
// for mandatory fields, the name and field id are fixed, so we use the
|
||||
// known and fixed id to get them (more reliable than names, which can be translated)
|
||||
// for other fields (custom fields), locate the field by same name
|
||||
// (field id has no known meaning for custom fields)
|
||||
int idx = it->GetId();
|
||||
SCH_FIELD* schField;
|
||||
|
||||
if( idx < MANDATORY_FIELDS )
|
||||
schField = GetField( idx );
|
||||
else
|
||||
schField = FindField( it->GetName() );
|
||||
|
||||
if( !schField )
|
||||
{
|
||||
SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, it->GetName() );
|
||||
schField = AddField( fld );
|
||||
}
|
||||
|
||||
schField->ImportValues( *it );
|
||||
schField->SetText( it->GetText() );
|
||||
|
||||
// Now the field is initialized, place it to the right position:
|
||||
schField->SetTextPos( m_Pos + it->GetTextPos() );
|
||||
}
|
||||
// Import user defined fields from the library component
|
||||
UpdateFields( true, true );
|
||||
|
||||
wxString msg = aPart.GetReferenceField().GetText();
|
||||
|
||||
|
@ -885,6 +850,53 @@ SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName, bool aIncludeDe
|
|||
}
|
||||
|
||||
|
||||
void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
|
||||
{
|
||||
if( PART_SPTR part = m_part.lock() )
|
||||
{
|
||||
LIB_FIELDS fields;
|
||||
part->GetFields( fields );
|
||||
|
||||
for( const LIB_FIELD& field : fields )
|
||||
{
|
||||
// Can no longer insert an empty name, since names are now keys. The
|
||||
// field index is not used beyond the first MANDATORY_FIELDS
|
||||
if( field.GetName().IsEmpty() )
|
||||
continue;
|
||||
|
||||
// See if field already exists (mandatory fields always exist).
|
||||
// for mandatory fields, the name and field id are fixed, so we use the
|
||||
// known and fixed id to get them (more reliable than names, which can be translated)
|
||||
// for other fields (custom fields), locate the field by same name
|
||||
// (field id has no known meaning for custom fields)
|
||||
int idx = field.GetId();
|
||||
SCH_FIELD* schField;
|
||||
|
||||
if( idx == REFERENCE && !aResetRef )
|
||||
continue;
|
||||
if( idx < MANDATORY_FIELDS )
|
||||
schField = GetField( idx );
|
||||
else
|
||||
schField = FindField( field.GetName() );
|
||||
|
||||
if( !schField )
|
||||
{
|
||||
SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, field.GetName() );
|
||||
schField = AddField( fld );
|
||||
}
|
||||
|
||||
if( aResetStyle )
|
||||
{
|
||||
schField->ImportValues( field );
|
||||
schField->SetTextPos( m_Pos + field.GetTextPos() );
|
||||
}
|
||||
|
||||
schField->SetText( field.GetText() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LIB_PIN* SCH_COMPONENT::GetPin( const wxString& number )
|
||||
{
|
||||
if( PART_SPTR part = m_part.lock() )
|
||||
|
|
|
@ -363,6 +363,13 @@ public:
|
|||
m_Fields = aFields; // vector copying, length is changed possibly
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores fields to the original library values.
|
||||
* @param aResetStyle selects whether fields should reset the position and text attribute.
|
||||
* @param aResetRef selects whether the reference field should be restored.
|
||||
*/
|
||||
void UpdateFields( bool aResetStyle, bool aResetRef = false );
|
||||
|
||||
/**
|
||||
* Return the number of fields in this symbol.
|
||||
*/
|
||||
|
|
|
@ -272,6 +272,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
|
|||
EVT_TOOL( ID_FIND_ITEMS, SCH_EDIT_FRAME::OnFindItems )
|
||||
EVT_TOOL( wxID_REPLACE, SCH_EDIT_FRAME::OnFindItems )
|
||||
EVT_TOOL( ID_BACKANNO_ITEMS, SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile )
|
||||
EVT_TOOL( ID_UPDATE_FIELDS, SCH_EDIT_FRAME::OnUpdateFields )
|
||||
EVT_TOOL( ID_SCH_MOVE_ITEM, SCH_EDIT_FRAME::OnMoveItem )
|
||||
EVT_TOOL( ID_AUTOPLACE_FIELDS, SCH_EDIT_FRAME::OnAutoplaceFields )
|
||||
EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
|
||||
|
@ -1003,6 +1004,33 @@ void SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile( wxCommandEvent& event )
|
|||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::OnUpdateFields( wxCommandEvent& event )
|
||||
{
|
||||
PICKED_ITEMS_LIST itemsList;
|
||||
SCH_TYPE_COLLECTOR c;
|
||||
c.Collect( GetScreen()->GetDrawItems(), SCH_COLLECTOR::ComponentsOnly );
|
||||
|
||||
// Create a single undo buffer entry for all components
|
||||
for( int i = 0; i < c.GetCount(); ++i )
|
||||
{
|
||||
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( c[i] );
|
||||
itemsList.PushItem( ITEM_PICKER( component, UR_CHANGED ) );
|
||||
}
|
||||
|
||||
SaveCopyInUndoList( itemsList, UR_CHANGED );
|
||||
|
||||
// Update fields
|
||||
for( int i = 0; i < c.GetCount(); ++i )
|
||||
{
|
||||
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( c[i] );
|
||||
component->UpdateFields( false );
|
||||
}
|
||||
|
||||
m_canvas->Refresh();
|
||||
DisplayInfoMessage( this, _( "Fields updated successfully" ) );
|
||||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
|
||||
{
|
||||
// wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
|
||||
|
|
|
@ -864,6 +864,7 @@ private:
|
|||
|
||||
void OnLoadFile( wxCommandEvent& event );
|
||||
void OnLoadCmpToFootprintLinkFile( wxCommandEvent& event );
|
||||
void OnUpdateFields( wxCommandEvent& event );
|
||||
void OnNewProject( wxCommandEvent& event );
|
||||
void OnLoadProject( wxCommandEvent& event );
|
||||
void OnAppendProject( wxCommandEvent& event );
|
||||
|
|
Loading…
Reference in New Issue