Upgrade a couple of schematic actions to SCHEMATIC_COMMIT.

This commit is contained in:
Jeff Young 2023-06-07 15:30:56 +01:00
parent d5b5a3eaf4
commit 90c14ecdf7
2 changed files with 34 additions and 35 deletions

View File

@ -2144,11 +2144,10 @@ void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol, void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
const KIID& aSchematicSymbolUUID ) const KIID& aSchematicSymbolUUID )
{ {
bool appendToUndo = false; SCH_SHEET_PATH principalPath;
SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &principalPath );
SCH_SHEET_PATH principalPath; SCH_SYMBOL* principalSymbol = dynamic_cast<SCH_SYMBOL*>( item );
SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &principalPath ); SCHEMATIC_COMMIT commit( m_toolManager );
SCH_SYMBOL* principalSymbol = dynamic_cast<SCH_SYMBOL*>( item );
if( !principalSymbol ) if( !principalSymbol )
return; return;
@ -2158,7 +2157,7 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
if( principalSymbol->IsAnnotated( &principalPath ) ) if( principalSymbol->IsAnnotated( &principalPath ) )
principalRef = principalSymbol->GetRef( &principalPath, false ); principalRef = principalSymbol->GetRef( &principalPath, false );
std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > otherUnits; std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > allUnits;
for( const SCH_SHEET_PATH& path : Schematic().GetSheets() ) for( const SCH_SHEET_PATH& path : Schematic().GetSheets() )
{ {
@ -2170,37 +2169,36 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
|| ( candidateSymbol->IsAnnotated( &path ) || ( candidateSymbol->IsAnnotated( &path )
&& candidateSymbol->GetRef( &path, false ) == principalRef ) ) && candidateSymbol->GetRef( &path, false ) == principalRef ) )
{ {
otherUnits.emplace_back( candidateSymbol, path ); allUnits.emplace_back( candidateSymbol, path );
} }
} }
} }
for( auto& [ otherUnit, path ] : otherUnits ) for( auto& [ unit, path ] : allUnits )
{ {
// This needs to be done before the LIB_SYMBOL is changed to prevent stale // This needs to be done before the LIB_SYMBOL is changed to prevent stale
// library symbols in the schematic file. // library symbols in the schematic file.
path.LastScreen()->Remove( otherUnit ); path.LastScreen()->Remove( unit );
if( !otherUnit->IsNew() ) if( !unit->IsNew() )
{ commit.Modify( unit, path.LastScreen() );
SaveCopyInUndoList( path.LastScreen(), otherUnit, UNDO_REDO::CHANGED, appendToUndo );
appendToUndo = true;
}
otherUnit->SetLibSymbol( aSymbol.Flatten().release() ); unit->SetLibSymbol( aSymbol.Flatten().release() );
otherUnit->UpdateFields( &GetCurrentSheet(), unit->UpdateFields( &GetCurrentSheet(),
true, /* update style */ true, /* update style */
true, /* update ref */ true, /* update ref */
true, /* update other fields */ true, /* update other fields */
false, /* reset ref */ false, /* reset ref */
false /* reset other fields */ ); false /* reset other fields */ );
path.LastScreen()->Append( otherUnit ); path.LastScreen()->Append( unit );
GetCanvas()->GetView()->Update( otherUnit ); GetCanvas()->GetView()->Update( unit );
} }
if( !commit.Empty() )
commit.Push( _( "Save Symbol to Schematic" ) );
GetCanvas()->Refresh(); GetCanvas()->Refresh();
OnModify();
} }

View File

@ -1343,9 +1343,9 @@ static std::vector<KICAD_T> deletableItems =
int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
{ {
SCH_SCREEN* screen = m_frame->GetScreen(); SCH_SCREEN* screen = m_frame->GetScreen();
auto items = m_selectionTool->RequestSelection( deletableItems ).GetItems(); std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection( deletableItems ).GetItems();
bool appendToUndo = false; bool appendToUndo = false;
std::vector<VECTOR2I> pts; std::vector<VECTOR2I> pts;
if( items.empty() ) if( items.empty() )
@ -1507,11 +1507,12 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField ) void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField )
{ {
KICAD_T parentType = aField->GetParent() ? aField->GetParent()->Type() : SCHEMATIC_T; KICAD_T parentType = aField->GetParent() ? aField->GetParent()->Type() : SCHEMATIC_T;
SCHEMATIC_COMMIT commit( m_toolMgr );
// Save old symbol in undo list if not already in edit, or moving. // Save old symbol in undo list if not already in edit, or moving.
if( aField->GetEditFlags() == 0 ) // i.e. not edited, or moved if( aField->GetEditFlags() == 0 ) // i.e. not edited, or moved
saveCopyInUndoList( aField, UNDO_REDO::CHANGED ); commit.Modify( aField, m_frame->GetScreen() );
if( parentType == SCH_SYMBOL_T && aField->GetId() == REFERENCE_FIELD ) if( parentType == SCH_SYMBOL_T && aField->GetId() == REFERENCE_FIELD )
static_cast<SCH_ITEM*>( aField->GetParent() )->SetConnectivityDirty(); static_cast<SCH_ITEM*>( aField->GetParent() )->SetConnectivityDirty();
@ -1542,6 +1543,9 @@ void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField )
if( m_frame->eeconfig()->m_AutoplaceFields.enable || parentType == SCH_SHEET_T ) if( m_frame->eeconfig()->m_AutoplaceFields.enable || parentType == SCH_SHEET_T )
static_cast<SCH_ITEM*>( aField->GetParent() )->AutoAutoplaceFields( m_frame->GetScreen() ); static_cast<SCH_ITEM*>( aField->GetParent() )->AutoAutoplaceFields( m_frame->GetScreen() );
if( !commit.Empty() )
commit.Push( caption );
m_frame->UpdateItem( aField, false, true ); m_frame->UpdateItem( aField, false, true );
m_frame->OnModify(); m_frame->OnModify();
@ -1597,9 +1601,10 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent )
{ {
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems ); EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems );
SCH_ITEM* head = static_cast<SCH_ITEM*>( selection.Front() ); SCHEMATIC_COMMIT commit( m_toolMgr );
bool moving = head && head->IsMoving(); SCH_ITEM* head = static_cast<SCH_ITEM*>( selection.Front() );
bool moving = head && head->IsMoving();
if( selection.Empty() ) if( selection.Empty() )
return 0; return 0;
@ -1616,15 +1621,10 @@ int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent )
autoplaceItems.push_back( static_cast<SCH_ITEM*>( item->GetParent() ) ); autoplaceItems.push_back( static_cast<SCH_ITEM*>( item->GetParent() ) );
} }
bool appendUndo = false;
for( SCH_ITEM* sch_item : autoplaceItems ) for( SCH_ITEM* sch_item : autoplaceItems )
{ {
if( !moving && !sch_item->IsNew() ) if( !moving && !sch_item->IsNew() )
{ commit.Modify( sch_item, m_frame->GetScreen() );
saveCopyInUndoList( sch_item, UNDO_REDO::CHANGED, appendUndo, false );
appendUndo = true;
}
sch_item->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); sch_item->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true );
@ -1639,10 +1639,11 @@ int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent )
} }
else else
{ {
if( !commit.Empty() )
commit.Push( _( "Autoplace Fields" ) );
if( selection.IsHover() ) if( selection.IsHover() )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_frame->OnModify();
} }
return 0; return 0;