Fix refresh bug after a symbol reload from the file watcher.

Also moves EE_POINT_EDITOR to SCH_COMMIT.  (There was another refresh
bug in RollbackSymbolFromUndo() -- whose only caller was the
EE_POINT_EDITOR's old undo code).

Fixes https://gitlab.com/kicad/code/kicad/-/issues/14274
This commit is contained in:
Jeff Young 2023-07-02 10:34:32 +01:00
parent 4cbf512461
commit 03fd9c2086
5 changed files with 32 additions and 83 deletions

View File

@ -1447,6 +1447,9 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
SetCurSymbol( new LIB_SYMBOL( *lib_symbol ), false );
RebuildSymbolUnitsList();
SetShowDeMorgan( GetCurSymbol()->HasConversion() );
if( m_toolManager )
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
}
break;

View File

@ -276,8 +276,6 @@ public:
void GetSymbolFromUndoList();
void GetSymbolFromRedoList();
void RollbackSymbolFromUndo();
/**
* Free the undo or redo list from \a aList element.
*

View File

@ -163,28 +163,3 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
}
void SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo()
{
m_toolManager->RunAction( EE_ACTIONS::clearSelection );
// Load the last undo entry
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
// Check if we were already at the top of the stack
if( !undoCommand )
return;
ITEM_PICKER undoWrapper = undoCommand->PopItem();
delete undoCommand;
LIB_SYMBOL* symbol = (LIB_SYMBOL*) undoWrapper.GetItem();
symbol->ClearFlags( UR_TRANSIENT );
SetCurSymbol( symbol, false );
EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
selTool->RebuildSelection();
RebuildSymbolUnitsList();
SetShowDeMorgan( symbol->HasConversion() );
RebuildView();
}

View File

@ -28,6 +28,7 @@ using namespace std::placeholders;
#include "ee_point_editor.h"
#include <ee_grid_helper.h>
#include <tool/tool_manager.h>
#include <sch_commit.h>
#include <view/view_controls.h>
#include <geometry/seg.h>
#include <tools/ee_actions.h>
@ -436,7 +437,8 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
KIGFX::VIEW_CONTROLS* controls = getViewControls();
KIGFX::VIEW* view = getView();
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
EDA_ITEM* item = selection.Front();
SCH_COMMIT commit( m_toolMgr );
controls->ShowCursor( true );
@ -445,7 +447,6 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
setEditedPoint( nullptr );
updateEditedPoint( aEvent );
bool inDrag = false;
bool modified = false;
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
@ -460,10 +461,23 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
{
if( !inDrag )
{
saveItemsToUndo();
commit.Modify( m_editPoints->GetParent() );
if( m_editPoints->GetParent()->Type() == SCH_LINE_T )
{
std::pair<EDA_ITEM*, int> connected = m_editPoints->Point( LINE_START ).GetConnected();
if( connected.first )
commit.Modify( connected.first );
connected = m_editPoints->Point( LINE_END ).GetConnected();
if( connected.first )
commit.Modify( connected.first );
}
controls->ForceCursorPosition( false );
inDrag = true;
modified = true;
}
bool snap = !evt->DisableGridSnapping();
@ -479,11 +493,8 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
}
else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
{
if( modified )
{
m_frame->OnModify();
modified = false;
}
if( !commit.Empty() )
commit.Push( _( "Move Point" ) );
controls->SetAutoPan( false );
inDrag = false;
@ -492,9 +503,8 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
{
if( inDrag ) // Restore the last change
{
rollbackFromUndo();
commit.Revert();
inDrag = false;
modified = false;
break;
}
else if( evt->IsCancelInteractive() )
@ -522,9 +532,6 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
{
view->Remove( m_editPoints.get() );
if( modified )
m_frame->OnModify();
m_editPoints.reset();
m_frame->GetCanvas()->Refresh();
}
@ -1388,6 +1395,9 @@ int EE_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( m_editPoints->GetParent() );
SHAPE_LINE_CHAIN& poly = shape->GetPolyShape().Outline( 0 );
SCH_COMMIT commit( m_toolMgr );
commit.Modify( shape );
VECTOR2I cursor = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
VECTOR2I pos = mapCoords( cursor );
@ -1406,13 +1416,12 @@ int EE_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
}
}
saveItemsToUndo();
poly.Insert( closestLineStart + 1, pos );
updateItem( shape, true );
updatePoints();
m_frame->OnModify();
commit.Push( _( "Add Corner" ) );
return 0;
}
@ -1425,17 +1434,19 @@ int EE_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( m_editPoints->GetParent() );
SHAPE_LINE_CHAIN& poly = shape->GetPolyShape().Outline( 0 );
SCH_COMMIT commit( m_toolMgr );
commit.Modify( shape );
if( poly.GetPointCount() < 3 )
return 0;
saveItemsToUndo();
poly.Remove( getEditedPointIndex() );
updateItem( shape, true );
updatePoints();
m_frame->OnModify();
commit.Push( _( "Remove Corner" ) );
return 0;
}
@ -1448,41 +1459,6 @@ int EE_POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent )
}
void EE_POINT_EDITOR::saveItemsToUndo()
{
if( m_isSymbolEditor )
{
saveCopyInUndoList( m_editPoints->GetParent()->GetParent(), UNDO_REDO::LIBEDIT );
}
else
{
saveCopyInUndoList( (SCH_ITEM*) m_editPoints->GetParent(), UNDO_REDO::CHANGED );
if( m_editPoints->GetParent()->Type() == SCH_LINE_T )
{
std::pair<EDA_ITEM*, int> connected = m_editPoints->Point( LINE_START ).GetConnected();
if( connected.first )
saveCopyInUndoList( (SCH_ITEM*) connected.first, UNDO_REDO::CHANGED, true );
connected = m_editPoints->Point( LINE_END ).GetConnected();
if( connected.first )
saveCopyInUndoList( (SCH_ITEM*) connected.first, UNDO_REDO::CHANGED, true );
}
}
}
void EE_POINT_EDITOR::rollbackFromUndo()
{
if( m_isSymbolEditor )
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->RollbackSymbolFromUndo();
else
static_cast<SCH_EDIT_FRAME*>( m_frame )->RollbackSchematicFromUndo();
}
void EE_POINT_EDITOR::setTransitions()
{
Go( &EE_POINT_EDITOR::Main, EVENTS::PointSelectedEvent );

View File

@ -101,9 +101,6 @@ private:
int removeCorner( const TOOL_EVENT& aEvent );
int modifiedSelection( const TOOL_EVENT& aEvent );
void saveItemsToUndo();
void rollbackFromUndo();
private:
///< Currently edited point, NULL if there is none.
EDIT_POINT* m_editedPoint;