Make sure schematic symbol fields get transferred to symbol editor.

Fixes https://gitlab.com/kicad/code/kicad/issues/7501
This commit is contained in:
Jeff Young 2021-02-14 18:29:27 +00:00
parent ff61ca5fed
commit ec20121114
8 changed files with 47 additions and 29 deletions

View File

@ -593,10 +593,14 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
if( resetEffects ) if( resetEffects )
{ {
// Careful: the visible bit is also in Effects // Careful: the visible bit and position are also in Effects
bool visible = field->IsVisible(); bool visible = field->IsVisible();
wxPoint pos = field->GetPosition();
field->SetEffects( *libField ); field->SetEffects( *libField );
field->SetVisible( visible ); field->SetVisible( visible );
field->SetPosition( pos );
} }
if( resetPositions ) if( resetPositions )

View File

@ -163,10 +163,14 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
if( resetEffects ) if( resetEffects )
{ {
// Careful: the visible bit is also in Effects // Careful: the visible bit and position are also in Effects
bool visible = field.IsVisible(); bool visible = field.IsVisible();
wxPoint pos = field.GetPosition();
field.SetEffects( *parentField ); field.SetEffects( *parentField );
field.SetVisible( visible ); field.SetVisible( visible );
field.SetPosition( pos );
} }
if( resetPositions ) if( resetPositions )
@ -198,9 +202,8 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
LIB_FIELD* newField = &result.back(); LIB_FIELD* newField = &result.back();
newField->SetName( parentField->GetCanonicalName() ); newField->SetName( parentField->GetCanonicalName() );
newField->SetEffects( *parentField );
newField->SetText( parentField->GetText() ); newField->SetText( parentField->GetText() );
newField->SetTextPos( parentField->GetTextPos() ); newField->SetEffects( *parentField ); // Includes visible bit and position
} }
} }

View File

@ -1631,7 +1631,7 @@ void SCH_EDIT_FRAME::UpdateSymbolFromEditor( const LIB_PART& aSymbol )
// This should work for multiple selections of the same symbol even though the editor // This should work for multiple selections of the same symbol even though the editor
// only works for a single symbol selection. // only works for a single symbol selection.
for( auto item : selection ) for( EDA_ITEM* item : selection )
{ {
SCH_COMPONENT* symbol = dynamic_cast<SCH_COMPONENT*>( item ); SCH_COMPONENT* symbol = dynamic_cast<SCH_COMPONENT*>( item );

View File

@ -1284,26 +1284,44 @@ SELECTION& SYMBOL_EDIT_FRAME::GetCurrentSelection()
} }
void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( const std::unique_ptr<LIB_PART>& aSymbol, void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_COMPONENT* aSymbol )
const wxString& aReference, int aUnit,
int aConvert )
{ {
std::unique_ptr<LIB_PART> symbol = aSymbol->Flatten(); std::unique_ptr<LIB_PART> part = aSymbol->GetPartRef()->Flatten();
wxCHECK( symbol, /* void */ ); wxCHECK( part, /* void */ );
std::vector<LIB_FIELD> fullSetOfFields;
for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i )
{
SCH_FIELD* field = aSymbol->GetField( i );
wxPoint pos = field->GetPosition() - aSymbol->GetPosition();
LIB_FIELD libField( part.get(), field->GetId() );
if( i >= MANDATORY_FIELDS && !field->GetName( false ).IsEmpty() )
libField.SetName( field->GetName( false ) );
libField.SetText( field->GetText() );
libField.SetEffects( *field );
libField.SetPosition( wxPoint( pos.x, -pos.y ) );
fullSetOfFields.emplace_back( std::move( libField ) );
}
part->SetFields( fullSetOfFields );
if( m_my_part ) if( m_my_part )
SetCurPart( nullptr, false ); SetCurPart( nullptr, false );
m_isSymbolFromSchematic = true; m_isSymbolFromSchematic = true;
m_reference = aReference; m_reference = part->GetField( REFERENCE_FIELD )->GetText();
m_unit = aUnit > 0 ? aUnit : 1; m_unit = std::max( 1, aSymbol->GetUnit() );
m_convert = aConvert > 0 ? aConvert : 1; m_convert = std::max( 1, aSymbol->GetConvert() );
// The buffered screen for the part // The buffered screen for the part
SCH_SCREEN* tmpScreen = new SCH_SCREEN(); SCH_SCREEN* tmpScreen = new SCH_SCREEN();
SetScreen( tmpScreen ); SetScreen( tmpScreen );
SetCurPart( symbol.release(), true ); SetCurPart( part.release(), true );
ReCreateMenuBar(); ReCreateMenuBar();
ReCreateHToolbar(); ReCreateHToolbar();

View File

@ -330,12 +330,8 @@ public:
* Load a symbol from the schematic to edit in place. * Load a symbol from the schematic to edit in place.
* *
* @param aSymbol the symbol to edit. * @param aSymbol the symbol to edit.
* @param aReference the reference of the symbol to edit.
* @param aUnit the unit of the symbol to edit.
* @param aConvert the alternate body style of the symbol to edit.
*/ */
void LoadSymbolFromSchematic( const std::unique_ptr<LIB_PART>& aSymbol, void LoadSymbolFromSchematic( SCH_COMPONENT* aSymbol );
const wxString& aReference, int aUnit, int aConvert );
/** /**
* Test if a symbol is loaded and can be edited. * Test if a symbol is loaded and can be edited.

View File

@ -1396,9 +1396,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
{ {
auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ); auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true );
editor->LoadSymbolFromSchematic( component->GetPartRef(), editor->LoadSymbolFromSchematic( component );
component->GetRef( &m_frame->GetCurrentSheet() ),
component->GetUnit(), component->GetConvert() );
editor->Show( true ); editor->Show( true );
editor->Raise(); editor->Raise();

View File

@ -1569,7 +1569,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
} }
int SCH_EDITOR_CONTROL::EditWithLibEdit( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent )
{ {
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly );
@ -1588,8 +1588,7 @@ int SCH_EDITOR_CONTROL::EditWithLibEdit( const TOOL_EVENT& aEvent )
if( symbolEditor ) if( symbolEditor )
{ {
symbolEditor->LoadSymbolFromSchematic( sym->GetPartRef(), sym->GetRef( &currentSheet ), symbolEditor->LoadSymbolFromSchematic( sym );
sym->GetUnit(), sym->GetConvert() );
} }
return 0; return 0;
@ -1817,7 +1816,7 @@ void SCH_EDITOR_CONTROL::setTransitions()
Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::EditWithLibEdit, EE_ACTIONS::editWithLibEdit.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor, EE_ACTIONS::editWithLibEdit.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::ShowCvpcb, EE_ACTIONS::assignFootprints.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ShowCvpcb, EE_ACTIONS::assignFootprints.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::ImportFPAssignments, EE_ACTIONS::importFPAssignments.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ImportFPAssignments, EE_ACTIONS::importFPAssignments.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::Annotate, EE_ACTIONS::annotate.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Annotate, EE_ACTIONS::annotate.MakeEvent() );

View File

@ -112,7 +112,7 @@ public:
int Copy( const TOOL_EVENT& aEvent ); int Copy( const TOOL_EVENT& aEvent );
int Paste( const TOOL_EVENT& aEvent ); int Paste( const TOOL_EVENT& aEvent );
int EditWithLibEdit( const TOOL_EVENT& aEvent ); int EditWithSymbolEditor( const TOOL_EVENT& aEvent );
int ShowCvpcb( const TOOL_EVENT& aEvent ); int ShowCvpcb( const TOOL_EVENT& aEvent );
int Annotate( const TOOL_EVENT& aEvent ); int Annotate( const TOOL_EVENT& aEvent );
int EditSymbolFields( const TOOL_EVENT& aEvent ); int EditSymbolFields( const TOOL_EVENT& aEvent );