2014-10-19 22:17:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2020-01-16 14:09:40 +00:00
|
|
|
* Copyright (C) 2014-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2014-10-19 22:17:43 +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
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
|
|
|
#include <symbol_library_manager.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <widgets/lib_tree.h>
|
|
|
|
#include <symbol_tree_pane.h>
|
2019-05-06 12:32:51 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_actions.h>
|
2019-05-11 10:06:28 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* aItem, UNDO_REDO aUndoType, bool aAppend )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
wxASSERT_MSG( !aAppend, "Append not needed/supported for symbol editor" );
|
2019-05-12 11:49:58 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( !aItem )
|
2020-01-12 19:47:13 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
LIB_PART* copyItem;
|
2017-11-08 16:32:56 +00:00
|
|
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
copyItem = new LIB_PART( * (LIB_PART*) aItem );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-05-20 18:29:35 +00:00
|
|
|
// Clear current flags (which can be temporary set by a current edit command).
|
2020-07-13 11:21:40 +00:00
|
|
|
copyItem->ClearTempFlags();
|
|
|
|
copyItem->ClearEditFlags();
|
|
|
|
copyItem->SetFlags( UR_TRANSIENT );
|
2009-07-23 15:37:00 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
ITEM_PICKER wrapper( GetScreen(), copyItem, aUndoType );
|
2017-11-08 16:32:56 +00:00
|
|
|
lastcmd->PushItem( wrapper );
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToUndoList( lastcmd );
|
2010-10-22 12:11:52 +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 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
if( GetRedoCommandCount() <= 0 )
|
2009-07-29 13:10:36 +00:00
|
|
|
return;
|
2009-07-23 15:37:00 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-06 12:32:51 +00:00
|
|
|
|
2017-11-08 16:32:56 +00:00
|
|
|
// Load the last redo entry
|
2020-07-13 11:21:40 +00:00
|
|
|
PICKED_ITEMS_LIST* redoCommand = PopCommandFromRedoList();
|
2018-01-19 18:56:01 +00:00
|
|
|
ITEM_PICKER redoWrapper = redoCommand->PopItem();
|
|
|
|
delete redoCommand;
|
|
|
|
LIB_PART* part = (LIB_PART*) redoWrapper.GetItem();
|
2018-02-15 09:22:47 +00:00
|
|
|
wxCHECK( part, /* void */ );
|
2019-04-22 08:58:06 +00:00
|
|
|
part->ClearFlags( UR_TRANSIENT );
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO undoRedoType = redoWrapper.GetStatus();
|
2018-01-19 18:56:01 +00:00
|
|
|
|
|
|
|
// Store the current part in the undo buffer
|
|
|
|
PICKED_ITEMS_LIST* undoCommand = new PICKED_ITEMS_LIST();
|
2019-12-13 21:51:59 +00:00
|
|
|
LIB_PART* oldPart = m_my_part;
|
2019-04-22 08:58:06 +00:00
|
|
|
oldPart->SetFlags( UR_TRANSIENT );
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER undoWrapper( GetScreen(), oldPart, undoRedoType );
|
2018-01-19 18:56:01 +00:00
|
|
|
undoCommand->PushItem( undoWrapper );
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToUndoList( undoCommand );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2014-08-26 15:16:30 +00:00
|
|
|
// Do not delete the previous part by calling SetCurPart( part )
|
|
|
|
// which calls delete <previous part>.
|
|
|
|
// <previous part> is now put in undo list and is owned by this list
|
|
|
|
// Just set the current part to the part which come from the redo list
|
2019-12-13 21:51:59 +00:00
|
|
|
m_my_part = part;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
2018-01-19 18:56:01 +00:00
|
|
|
{
|
|
|
|
wxString lib = GetCurLib();
|
|
|
|
m_libMgr->UpdatePartAfterRename( part, oldPart->GetName(), lib );
|
|
|
|
|
|
|
|
// Reselect the renamed part
|
2018-07-27 20:47:51 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
|
2018-01-19 18:56:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
SetShowDeMorgan( part->HasConversion() );
|
2018-10-05 12:55:34 +00:00
|
|
|
updateTitle();
|
2018-10-18 09:50:43 +00:00
|
|
|
|
|
|
|
RebuildView();
|
2011-12-22 13:28:11 +00:00
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
if( GetUndoCommandCount() <= 0 )
|
2009-07-29 13:10:36 +00:00
|
|
|
return;
|
2009-07-23 15:37:00 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-06 12:32:51 +00:00
|
|
|
|
2017-11-08 16:32:56 +00:00
|
|
|
// Load the last undo entry
|
2020-07-13 11:21:40 +00:00
|
|
|
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
|
2018-01-19 18:56:01 +00:00
|
|
|
ITEM_PICKER undoWrapper = undoCommand->PopItem();
|
|
|
|
delete undoCommand;
|
|
|
|
LIB_PART* part = (LIB_PART*) undoWrapper.GetItem();
|
2018-02-15 09:22:47 +00:00
|
|
|
wxCHECK( part, /* void */ );
|
2019-04-22 08:58:06 +00:00
|
|
|
part->ClearFlags( UR_TRANSIENT );
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO undoRedoType = undoWrapper.GetStatus();
|
2018-01-19 18:56:01 +00:00
|
|
|
|
|
|
|
// Store the current part in the redo buffer
|
|
|
|
PICKED_ITEMS_LIST* redoCommand = new PICKED_ITEMS_LIST();
|
2019-12-13 21:51:59 +00:00
|
|
|
LIB_PART* oldPart = m_my_part;
|
2019-04-22 08:58:06 +00:00
|
|
|
oldPart->SetFlags( UR_TRANSIENT );
|
2020-07-13 11:21:40 +00:00
|
|
|
ITEM_PICKER redoWrapper( GetScreen(), oldPart, undoRedoType );
|
2018-01-19 18:56:01 +00:00
|
|
|
redoCommand->PushItem( redoWrapper );
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToRedoList( redoCommand );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2014-08-26 15:16:30 +00:00
|
|
|
// Do not delete the previous part by calling SetCurPart( part ),
|
|
|
|
// which calls delete <previous part>.
|
|
|
|
// <previous part> is now put in redo list and is owned by this list.
|
|
|
|
// Just set the current part to the part which come from the undo list
|
2019-12-13 21:51:59 +00:00
|
|
|
m_my_part = part;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
2018-01-19 18:56:01 +00:00
|
|
|
{
|
|
|
|
wxString lib = GetCurLib();
|
|
|
|
m_libMgr->UpdatePartAfterRename( part, oldPart->GetName(), lib );
|
|
|
|
|
|
|
|
// Reselect the renamed part
|
2018-07-27 20:47:51 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, part->GetName() ) );
|
2018-01-19 18:56:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
SetShowDeMorgan( part->HasConversion() );
|
2018-10-05 12:55:34 +00:00
|
|
|
updateTitle();
|
2018-10-18 09:50:43 +00:00
|
|
|
|
|
|
|
RebuildView();
|
2010-10-22 12:11:52 +00:00
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
// Load the last undo entry
|
2020-07-13 11:21:40 +00:00
|
|
|
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
|
2020-01-16 14:09:40 +00:00
|
|
|
|
|
|
|
// Check if we were already at the top of the stack
|
|
|
|
if( !undoCommand )
|
|
|
|
return;
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
ITEM_PICKER undoWrapper = undoCommand->PopItem();
|
|
|
|
delete undoCommand;
|
|
|
|
LIB_PART* part = (LIB_PART*) undoWrapper.GetItem();
|
|
|
|
part->ClearFlags( UR_TRANSIENT );
|
2020-12-08 15:27:50 +00:00
|
|
|
SetCurPart( part, false );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
selTool->RebuildSelection();
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
RebuildSymbolUnitsList();
|
|
|
|
SetShowDeMorgan( part->HasConversion() );
|
|
|
|
|
|
|
|
RebuildView();
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|