Move TestDanglingEnds() to SCH_COMMIT.

Also fixes a bug where Convert Symbol wasn't undoable.

Also cleans up some SetModified() call no longer needed with SCH_COMMIT.

Also fixes bug where revert of a modification didn't update the screen's
RTree.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15030
This commit is contained in:
Jeff Young 2023-06-23 19:59:18 +01:00
parent f56ea370be
commit 237cc7eee1
9 changed files with 20 additions and 48 deletions

View File

@ -400,10 +400,7 @@ void DIALOG_CHANGE_SYMBOLS::onOkButtonClicked( wxCommandEvent& aEvent )
}
if( processMatchingSymbols( &commit) )
{
parent->TestDanglingEnds(); // This will also redraw the changed symbols.
commit.Push( m_mode == MODE::CHANGE ? _( "Change Symbols" ) : _( "Update Symbols" ) );
}
m_messagePanel->Flush( false );
}

View File

@ -866,7 +866,6 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow()
}
currentScreen->Append( m_symbol );
GetParent()->TestDanglingEnds();
GetParent()->UpdateItem( m_symbol, false, true );
if( !commit.Empty() )

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -36,7 +36,7 @@
#include <symbol_tree_model_adapter.h>
#include <symbol_editor/symbol_editor_settings.h>
#include <sch_symbol.h>
#include <symbol_library_common.h>
#include <sch_commit.h>
#include <sch_edit_frame.h>
#include <symbol_lib_table.h>
#include <tool/tool_manager.h>
@ -240,6 +240,7 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SYMBOL_LIBRARY_FILTER
void SCH_EDIT_FRAME::SelectUnit( SCH_SYMBOL* aSymbol, int aUnit )
{
SCH_COMMIT commit( m_toolManager );
LIB_SYMBOL* symbol = GetLibSymbol( aSymbol->GetLibId() );
if( !symbol )
@ -253,26 +254,20 @@ void SCH_EDIT_FRAME::SelectUnit( SCH_SYMBOL* aSymbol, int aUnit )
if( aUnit > unitCount )
aUnit = unitCount;
EDA_ITEM_FLAGS savedFlags = aSymbol->GetFlags();
if( !aSymbol->GetEditFlags() ) // No command in progress: save in undo list
SaveCopyInUndoList( GetScreen(), aSymbol, UNDO_REDO::CHANGED, false );
commit.Modify( aSymbol, GetScreen() );
/* Update the unit number. */
aSymbol->SetUnitSelection( &GetCurrentSheet(), aUnit );
aSymbol->SetUnit( aUnit );
aSymbol->ClearFlags();
aSymbol->SetFlags( savedFlags ); // Restore m_Flag modified by SetUnit()
if( !aSymbol->GetEditFlags() ) // No command in progress: update schematic
if( !commit.Empty() )
{
if( eeconfig()->m_AutoplaceFields.enable )
aSymbol->AutoAutoplaceFields( GetScreen() );
TestDanglingEnds();
UpdateItem( aSymbol, false, true );
OnModify();
commit.Push( _( "Change Unit" ) );
}
}
@ -282,7 +277,8 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_SYMBOL* aSymbol )
if( !aSymbol || !aSymbol->GetLibSymbolRef() )
return;
wxString msg;
SCH_COMMIT commit( m_toolManager );
wxString msg;
if( !aSymbol->GetLibSymbolRef()->HasConversion() )
{
@ -295,7 +291,7 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_SYMBOL* aSymbol )
return;
}
EDA_ITEM_FLAGS savedFlags = aSymbol->GetFlags();
commit.Modify( aSymbol, GetScreen() );
aSymbol->SetConvert( aSymbol->GetConvert() + 1 );
@ -307,14 +303,10 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_SYMBOL* aSymbol )
if( aSymbol->GetConvert() > LIB_ITEM::LIB_CONVERT::DEMORGAN )
aSymbol->SetConvert( LIB_ITEM::LIB_CONVERT::BASE );
TestDanglingEnds();
aSymbol->ClearFlags();
aSymbol->SetFlags( savedFlags ); // Restore m_flags (modified by SetConvert())
// If selected make sure all the now-included pins are selected
if( aSymbol->IsSelected() )
m_toolManager->RunAction<EDA_ITEM*>( EE_ACTIONS::addItemToSel, true, aSymbol );
UpdateItem( aSymbol, false, true );
OnModify();
commit.Push( _( "Convert Symbol" ) );
}

View File

@ -347,6 +347,9 @@ void SCH_COMMIT::pushSchEdit( const wxString& aMessage, int aCommitFlags )
if( selectedModified )
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
if( frame )
frame->TestDanglingEnds();
if( !( aCommitFlags & SKIP_SET_DIRTY ) )
{
if( frame )
@ -499,6 +502,8 @@ void SCH_COMMIT::Revert()
if( view )
view->Add( item );
screen->Update( item );
delete copy;
break;
}
@ -525,7 +530,10 @@ void SCH_COMMIT::Revert()
selTool->RebuildSelection();
if( frame )
{
frame->RecalculateConnections( nullptr, NO_CLEANUP );
frame->TestDanglingEnds();
}
clear();
}

View File

@ -70,14 +70,6 @@ std::string toUTFTildaText( const wxString& txt )
* Used to draw a dummy shape when a LIB_SYMBOL is not found in library
*
* This symbol is a 400 mils square with the text "??"
* DEF DUMMY U 0 40 Y Y 1 0 N
* F0 "U" 0 -350 60 H V
* F1 "DUMMY" 0 350 60 H V
* DRAW
* T 0 0 0 150 0 0 0 ??
* S -200 200 200 -200 0 1 0
* ENDDRAW
* ENDDEF
*/
static LIB_SYMBOL* dummy()
{
@ -387,11 +379,7 @@ void SCH_SYMBOL::UpdatePins()
void SCH_SYMBOL::SetUnit( int aUnit )
{
if( m_unit != aUnit )
{
UpdateUnit( aUnit );
SetModified();
}
UpdateUnit( aUnit );
}
@ -409,7 +397,6 @@ void SCH_SYMBOL::SetConvert( int aConvert )
// The convert may have a different pin layout so the update the pin map.
UpdatePins();
SetModified();
}
}
@ -417,10 +404,7 @@ void SCH_SYMBOL::SetConvert( int aConvert )
void SCH_SYMBOL::SetTransform( const TRANSFORM& aTransform )
{
if( m_transform != aTransform )
{
m_transform = aTransform;
SetModified();
}
}

View File

@ -851,10 +851,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
SCH_COMMIT commit( m_toolMgr );
commit.Add( newItem, screen );
if( type == SCH_JUNCTION_T )
m_frame->TestDanglingEnds();
else
m_frame->SchematicCleanUp( &commit );
m_frame->SchematicCleanUp( &commit );
commit.Push( description );
}

View File

@ -923,7 +923,6 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
lwbTool->AddJunctionsIfNeeded( commit, &selectionCopy );
m_frame->SchematicCleanUp( commit );
m_frame->TestDanglingEnds();
if( !localCommit.Empty() )
localCommit.Push( _( "Rotate" ) );
@ -1121,7 +1120,6 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
lwbTool->AddJunctionsIfNeeded( commit, &selectionCopy );
m_frame->SchematicCleanUp( commit );
m_frame->TestDanglingEnds();
}
if( !localCommit.Empty() )
@ -1311,7 +1309,6 @@ int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent )
lwbTool->AddJunctionsIfNeeded( &commit, &newItems );
m_frame->SchematicCleanUp( &commit );
m_frame->TestDanglingEnds();
}
m_frame->GetCanvas()->Refresh();

View File

@ -1223,7 +1223,6 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
item->ClearEditFlags();
m_frame->TestDanglingEnds();
commit.Push( _( "Draw Wires" ) );
}

View File

@ -1756,7 +1756,6 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
m_toolMgr->PostEvent( EVENTS::SelectedItemsMoved );
m_frame->SchematicCleanUp( &commit );
m_frame->TestDanglingEnds();
commit.Push( _( "Align" ) );
return 0;