From 3c714f1d8cf3916a8442eff26014c50dbb0e8530 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 17 Mar 2019 22:07:32 -0400 Subject: [PATCH] Fix undo handling of SchematicCleanUp --- eeschema/bus-wire-junction.cpp | 30 +++++++++++++++++++++--------- eeschema/files-io.cpp | 4 ++-- eeschema/getpart.cpp | 2 +- eeschema/sch_edit_frame.cpp | 2 +- eeschema/sch_edit_frame.h | 4 +++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 7ac2c3a927..553f790639 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -434,7 +434,7 @@ void SCH_EDIT_FRAME::EndSegment() for( auto i : new_ends ) { if( screen->IsJunctionNeeded( i, true ) ) - AddJunction( i, true ); + AddJunction( i, true, false ); } if( IsBusUnfoldInProgress() ) @@ -633,6 +633,7 @@ bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool SaveCopyInUndoList( (SCH_ITEM*)line, UR_DELETED, aAppend ); RemoveFromScreen( (SCH_ITEM*)line ); + aAppend = true; retval = true; } @@ -641,7 +642,7 @@ bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool } -bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend, SCH_SCREEN* aScreen ) +bool SCH_EDIT_FRAME::SchematicCleanUp( bool aUndo, SCH_SCREEN* aScreen ) { SCH_ITEM* item = NULL; SCH_ITEM* secondItem = NULL; @@ -740,6 +741,9 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend, SCH_SCREEN* aScreen ) RemoveFromScreen( item, aScreen ); } + if( itemList.GetCount() && aUndo ) + SaveCopyInUndoList( itemList, UR_DELETED, true ); + return itemList.GetCount() > 0; } @@ -760,6 +764,9 @@ bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, newSegment->SetStartPoint( aPoint ); AddToScreen( newSegment, aScreen ); + if( aAppend ) + SaveCopyInUndoList( newSegment, UR_NEW, true ); + RefreshItem( aSegment ); aSegment->SetEndPoint( aPoint ); @@ -888,21 +895,26 @@ void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend ) } -SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( const wxPoint& aPosition, bool aAppend ) +SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( const wxPoint& aPosition, + bool aAppend, bool aFinal ) { SCH_JUNCTION* junction = new SCH_JUNCTION( aPosition ); bool broken_segments = false; AddToScreen( junction ); broken_segments = BreakSegments( aPosition, aAppend ); - TestDanglingEnds(); - OnModify(); SaveCopyInUndoList( junction, UR_NEW, broken_segments || aAppend ); - auto view = GetCanvas()->GetView(); - view->ClearPreview(); - view->ShowPreview( false ); - view->ClearHiddenFlags(); + if( aFinal ) + { + TestDanglingEnds(); + OnModify(); + + auto view = GetCanvas()->GetView(); + view->ClearPreview(); + view->ShowPreview( false ); + view->ClearHiddenFlags(); + } return junction; } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 60aa9f3ae0..3660711761 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -371,7 +371,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // Ensure the schematic is fully segmented on first display BreakSegmentsOnJunctions(); - SchematicCleanUp( true ); + SchematicCleanUp(); GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet. @@ -850,7 +850,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) // Ensure the schematic is fully segmented on first display BreakSegmentsOnJunctions(); - SchematicCleanUp( true ); + SchematicCleanUp(); GetScreen()->m_Initialized = true; SCH_TYPE_COLLECTOR components; diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 367652c3ed..17e0d4cb80 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -293,7 +293,7 @@ void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation ) if( item->GetFlags() == 0 ) { addCurrentItemToScreen(); - SchematicCleanUp( true ); + SchematicCleanUp(); } TestDanglingEnds(); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index efd0a68d4d..ffc0d6179f 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1519,7 +1519,7 @@ void SCH_EDIT_FRAME::RecalculateConnections() // Ensure schematic graph is accurate for( const auto& sheet : list ) - SchematicCleanUp( true, sheet.LastScreen() ); + SchematicCleanUp( false, sheet.LastScreen() ); g_ConnectionGraph->Recalculate( list ); } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index a4c17816fc..5a33aab07d 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -997,7 +997,9 @@ private: /** * Add a new junction at \a aPosition. */ - SCH_JUNCTION* AddJunction( const wxPoint& aPosition, bool aPutInUndoList = false ); + SCH_JUNCTION* AddJunction( const wxPoint& aPosition, + bool aAppendToUndo = false, + bool aFinal = true ); /** * Save a copy of the current wire image in the undo list.