EDIT_TOOL::DragArcTrack Fix incorrect undo history when items are deleted
Need to make sure we only apply one COMMIT operation per object before calling COMMIT::Push() or COMMIT::Revert()
This commit is contained in:
parent
2b5c1bae97
commit
6e7ae93cc8
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 CERN
|
* Copyright (C) 2013 CERN
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 CERN
|
* Copyright (C) 2013 CERN
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 CERN
|
* Copyright (C) 2013 CERN
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||||
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (C) 2013-2017 CERN
|
* Copyright (C) 2013-2017 CERN
|
||||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -295,7 +295,6 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
|
||||||
Activate();
|
Activate();
|
||||||
|
|
||||||
ARC* theArc = static_cast<ARC*>( selection.Front() );
|
ARC* theArc = static_cast<ARC*>( selection.Front() );
|
||||||
m_commit->Modify( theArc );
|
|
||||||
|
|
||||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||||
|
|
||||||
|
@ -329,7 +328,6 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
|
||||||
if( itemsOnAnchor.size() == 1 && itemsOnAnchor.front()->Type() == PCB_TRACE_T )
|
if( itemsOnAnchor.size() == 1 && itemsOnAnchor.front()->Type() == PCB_TRACE_T )
|
||||||
{
|
{
|
||||||
retval = static_cast<TRACK*>( itemsOnAnchor.front() );
|
retval = static_cast<TRACK*>( itemsOnAnchor.front() );
|
||||||
m_commit->Modify( retval );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -349,6 +347,11 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
|
||||||
TRACK* trackOnStart = getUniqueConnectedTrack( theArc->GetStart() );
|
TRACK* trackOnStart = getUniqueConnectedTrack( theArc->GetStart() );
|
||||||
TRACK* trackOnEnd = getUniqueConnectedTrack( theArc->GetEnd() );
|
TRACK* trackOnEnd = getUniqueConnectedTrack( theArc->GetEnd() );
|
||||||
|
|
||||||
|
// Make copies of items to be edited
|
||||||
|
ARC* theArcCopy = new ARC( *theArc );
|
||||||
|
TRACK* trackOnStartCopy = new TRACK( *trackOnStart );
|
||||||
|
TRACK* trackOnEndCopy = new TRACK( *trackOnEnd );
|
||||||
|
|
||||||
if( !trackOnStart->IsNew() )
|
if( !trackOnStart->IsNew() )
|
||||||
{
|
{
|
||||||
tanStart.A = trackOnStart->GetStart();
|
tanStart.A = trackOnStart->GetStart();
|
||||||
|
@ -518,46 +521,50 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove zero length tracks
|
// Ensure we only do one commit operation on each object
|
||||||
if( theArc->GetStart() == theArc->GetEnd() )
|
auto processTrack =
|
||||||
m_commit->Remove( theArc );
|
[&]( TRACK* aTrack, TRACK* aTrackCopy )
|
||||||
|
|
||||||
auto cleanupTrack =
|
|
||||||
[&]( TRACK* aTrack )
|
|
||||||
{
|
{
|
||||||
if( aTrack->IsNew() )
|
if( aTrack->IsNew() )
|
||||||
{
|
{
|
||||||
getView()->Remove( aTrack );
|
getView()->Remove( aTrack );
|
||||||
|
|
||||||
if( aTrack->GetStart() == aTrack->GetEnd() )
|
if( aTrack->GetStart() == aTrack->GetEnd() )
|
||||||
|
{
|
||||||
delete aTrack;
|
delete aTrack;
|
||||||
|
delete aTrackCopy;
|
||||||
|
aTrack = nullptr;
|
||||||
|
aTrackCopy = nullptr;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_commit->Add( aTrack );
|
m_commit->Add( aTrack );
|
||||||
|
delete aTrackCopy;
|
||||||
|
aTrackCopy = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if( aTrack->GetStart() == aTrack->GetEnd() )
|
else if( aTrack->GetStart() == aTrack->GetEnd() )
|
||||||
{
|
{
|
||||||
|
aTrack->SwapData( aTrackCopy ); //restore the original before notifying COMMIT
|
||||||
m_commit->Remove( aTrack );
|
m_commit->Remove( aTrack );
|
||||||
}
|
delete aTrackCopy;
|
||||||
};
|
aTrackCopy = nullptr;
|
||||||
|
|
||||||
cleanupTrack( trackOnStart );
|
|
||||||
cleanupTrack( trackOnEnd );
|
|
||||||
|
|
||||||
// Should we commit?
|
|
||||||
if( restore_state )
|
|
||||||
{
|
|
||||||
m_commit->Revert();
|
|
||||||
|
|
||||||
if( trackOnStart->IsNew() )
|
|
||||||
delete trackOnStart;
|
|
||||||
|
|
||||||
if( trackOnEnd->IsNew() )
|
|
||||||
delete trackOnEnd;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_commit->Push( _( "Drag Arc Track" ) );
|
m_commit->Modified( aTrack, aTrackCopy );
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
processTrack( trackOnStart, trackOnStartCopy );
|
||||||
|
processTrack( trackOnEnd, trackOnEndCopy );
|
||||||
|
processTrack( theArc, theArcCopy );
|
||||||
|
|
||||||
|
// Should we commit?
|
||||||
|
if( restore_state )
|
||||||
|
m_commit->Revert();
|
||||||
|
else
|
||||||
|
m_commit->Push( _( "Drag Arc Track" ) );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013-2020 CERN
|
* Copyright (C) 2013-2020 CERN
|
||||||
* Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 CERN
|
* Copyright (C) 2017 CERN
|
||||||
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
||||||
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
|
Loading…
Reference in New Issue