2013-07-26 13:20:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-08-13 17:51:22 +00:00
|
|
|
* Copyright (C) 2013 CERN
|
2019-05-20 10:23:32 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-08-13 17:51:22 +00:00
|
|
|
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2013-07-26 13:20:08 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_proxy_undo_item.h>
|
2020-10-13 05:04:31 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-26 15:36:40 +00:00
|
|
|
#include <tool/actions.h>
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "pl_editor_frame.h"
|
|
|
|
#include "tools/pl_selection_tool.h"
|
2020-07-13 11:21:40 +00:00
|
|
|
|
|
|
|
void PL_EDITOR_FRAME::SaveCopyInUndoList()
|
2013-07-26 13:20:08 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* copyItem = new DS_PROXY_UNDO_ITEM( this );
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER wrapper( GetScreen(), copyItem, UNDO_REDO::LIBEDIT );
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
lastcmd->PushItem( wrapper );
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToUndoList( lastcmd );
|
2013-07-26 13:20:08 +00:00
|
|
|
|
|
|
|
// Clear redo list, because after new save there is no redo to do.
|
2020-07-13 13:50:35 +00:00
|
|
|
ClearUndoORRedoList( REDO_LIST );
|
2013-07-26 13:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-22 13:05:11 +00:00
|
|
|
/* Redo the last edit:
|
2013-07-26 13:20:08 +00:00
|
|
|
* - Place the current edited layout in undo list
|
|
|
|
* - Get previous version of the current edited layput
|
|
|
|
*/
|
2019-05-20 10:23:32 +00:00
|
|
|
void PL_EDITOR_FRAME::GetLayoutFromRedoList()
|
2013-07-26 13:20:08 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
if ( GetRedoCommandCount() <= 0 )
|
2013-07-26 13:20:08 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER redoWrapper = PopCommandFromRedoList()->PopItem();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* redoItem = static_cast<DS_PROXY_UNDO_ITEM*>( redoWrapper.GetItem() );
|
2019-05-26 15:36:40 +00:00
|
|
|
bool pageSettingsAndTitleBlock = redoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
PICKED_ITEMS_LIST* undoCmd = new PICKED_ITEMS_LIST();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER undoWrapper( GetScreen(), undoItem );
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
undoCmd->PushItem( undoWrapper );
|
|
|
|
PushCommandToUndoList( undoCmd );
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
selTool->ClearSelection();
|
2019-06-13 17:28:55 +00:00
|
|
|
redoItem->Restore( this, GetCanvas()->GetView() );
|
2019-05-26 15:36:40 +00:00
|
|
|
selTool->RebuildSelection();
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
delete redoItem;
|
|
|
|
|
|
|
|
if( pageSettingsAndTitleBlock )
|
|
|
|
HardRedraw(); // items based off of corners will need re-calculating
|
|
|
|
else
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2013-07-26 13:20:08 +00:00
|
|
|
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-22 13:05:11 +00:00
|
|
|
/* Undo the last edit:
|
2013-07-26 13:20:08 +00:00
|
|
|
* - Place the current layout in Redo list
|
|
|
|
* - Get previous version of the current edited layout
|
|
|
|
*/
|
2019-05-20 10:23:32 +00:00
|
|
|
void PL_EDITOR_FRAME::GetLayoutFromUndoList()
|
2013-07-26 13:20:08 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
if ( GetUndoCommandCount() <= 0 )
|
2013-07-26 13:20:08 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
|
2019-05-26 15:36:40 +00:00
|
|
|
bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
PICKED_ITEMS_LIST* redoCmd = new PICKED_ITEMS_LIST();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* redoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER redoWrapper( GetScreen(), redoItem );
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
redoCmd->PushItem( redoWrapper );
|
|
|
|
PushCommandToRedoList( redoCmd );
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
selTool->ClearSelection();
|
2019-06-13 17:28:55 +00:00
|
|
|
undoItem->Restore( this, GetCanvas()->GetView() );
|
2019-05-26 15:36:40 +00:00
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
|
|
|
delete undoItem;
|
|
|
|
|
|
|
|
if( pageSettingsAndTitleBlock )
|
|
|
|
HardRedraw(); // items based off of corners will need re-calculating
|
|
|
|
else
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2013-07-26 13:20:08 +00:00
|
|
|
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2013-07-26 13:20:08 +00:00
|
|
|
/* Remove the last command in Undo List.
|
|
|
|
* Used to clean the uUndo stack after a cancel command
|
|
|
|
*/
|
2019-05-20 10:23:32 +00:00
|
|
|
void PL_EDITOR_FRAME::RollbackFromUndo()
|
2013-07-26 13:20:08 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PL_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
if ( GetUndoCommandCount() <= 0 )
|
2013-07-26 13:20:08 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
|
2019-05-26 15:36:40 +00:00
|
|
|
bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
|
|
|
|
|
|
|
|
selTool->ClearSelection();
|
2019-06-13 17:28:55 +00:00
|
|
|
undoItem->Restore( this, GetCanvas()->GetView() );
|
2019-05-26 15:36:40 +00:00
|
|
|
selTool->RebuildSelection();
|
2013-07-26 13:20:08 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
delete undoItem;
|
2019-05-24 09:23:05 +00:00
|
|
|
|
2019-05-26 15:36:40 +00:00
|
|
|
if( pageSettingsAndTitleBlock )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( ACTIONS::zoomFitScreen );
|
2019-05-26 15:36:40 +00:00
|
|
|
HardRedraw(); // items based off of corners will need re-calculating
|
|
|
|
}
|
|
|
|
else
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2013-07-26 13:20:08 +00:00
|
|
|
}
|