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
|
2023-06-09 21:41:33 +00:00
|
|
|
* Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.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>
|
2022-09-16 03:06:23 +00:00
|
|
|
#include <lib_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
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::PushSymbolToUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbolCopy,
|
|
|
|
UNDO_REDO aUndoType )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2023-12-22 17:30:14 +00:00
|
|
|
if( !aSymbolCopy )
|
2020-01-12 19:47:13 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-08 16:32:56 +00:00
|
|
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-05-20 18:29:35 +00:00
|
|
|
// Clear current flags (which can be temporary set by a current edit command).
|
2023-12-22 17:30:14 +00:00
|
|
|
aSymbolCopy->ClearTempFlags();
|
|
|
|
aSymbolCopy->ClearEditFlags();
|
|
|
|
aSymbolCopy->SetFlags( UR_TRANSIENT );
|
2009-07-23 15:37:00 +00:00
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
ITEM_PICKER wrapper( GetScreen(), aSymbolCopy, aUndoType );
|
2017-11-08 16:32:56 +00:00
|
|
|
lastcmd->PushItem( wrapper );
|
2023-06-09 21:41:33 +00:00
|
|
|
lastcmd->SetDescription( aDescription );
|
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
|
|
|
|
2023-12-22 17:30:14 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveCopyInUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbol,
|
|
|
|
UNDO_REDO aUndoType )
|
|
|
|
{
|
|
|
|
if( aSymbol )
|
|
|
|
PushSymbolToUndoList( aDescription, new LIB_SYMBOL( *aSymbol ), aUndoType );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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();
|
2023-06-09 21:41:33 +00:00
|
|
|
ITEM_PICKER redoWrapper = redoCommand->PopItem();
|
|
|
|
wxString description = redoCommand->GetDescription();
|
|
|
|
|
2018-01-19 18:56:01 +00:00
|
|
|
delete redoCommand;
|
2023-06-09 21:41:33 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* symbol = (LIB_SYMBOL*) redoWrapper.GetItem();
|
2023-06-09 21:41:33 +00:00
|
|
|
UNDO_REDO undoRedoType = redoWrapper.GetStatus();
|
2021-06-10 18:51:46 +00:00
|
|
|
wxCHECK( symbol, /* void */ );
|
|
|
|
symbol->ClearFlags( UR_TRANSIENT );
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Store the current symbol in the undo buffer
|
2018-01-19 18:56:01 +00:00
|
|
|
PICKED_ITEMS_LIST* undoCommand = new PICKED_ITEMS_LIST();
|
2023-06-09 21:41:33 +00:00
|
|
|
LIB_SYMBOL* oldSymbol = m_symbol;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
oldSymbol->SetFlags( UR_TRANSIENT );
|
|
|
|
ITEM_PICKER undoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
2023-06-09 21:41:33 +00:00
|
|
|
undoCommand->SetDescription( description );
|
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
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
// Do not delete the previous symbol by calling SetCurSymbol( symbol )
|
2021-06-10 18:51:46 +00:00
|
|
|
// which calls delete <previous symbol>.
|
|
|
|
// <previous symbol> is now put in undo list and is owned by this list
|
|
|
|
// Just set the current symbol to the symbol which come from the redo list
|
2021-06-15 12:31:28 +00:00
|
|
|
m_symbol = symbol;
|
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();
|
2021-06-15 12:31:28 +00:00
|
|
|
m_libMgr->UpdateSymbolAfterRename( symbol, oldSymbol->GetName(), lib );
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Reselect the renamed symbol
|
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, symbol->GetName() ) );
|
2018-01-19 18:56:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2024-01-26 16:16:13 +00:00
|
|
|
SetShowDeMorgan( symbol->HasAlternateBodyStyle() );
|
2023-09-12 15:17:36 +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
|
|
|
|
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();
|
2023-06-09 21:41:33 +00:00
|
|
|
wxString description = undoCommand->GetDescription();
|
|
|
|
ITEM_PICKER undoWrapper = undoCommand->PopItem();
|
|
|
|
|
2018-01-19 18:56:01 +00:00
|
|
|
delete undoCommand;
|
2023-06-09 21:41:33 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* symbol = (LIB_SYMBOL*) undoWrapper.GetItem();
|
2023-06-09 21:41:33 +00:00
|
|
|
UNDO_REDO undoRedoType = undoWrapper.GetStatus();
|
2021-06-10 18:51:46 +00:00
|
|
|
wxCHECK( symbol, /* void */ );
|
|
|
|
symbol->ClearFlags( UR_TRANSIENT );
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Store the current symbol in the redo buffer
|
2018-01-19 18:56:01 +00:00
|
|
|
PICKED_ITEMS_LIST* redoCommand = new PICKED_ITEMS_LIST();
|
2023-06-09 21:41:33 +00:00
|
|
|
LIB_SYMBOL* oldSymbol = m_symbol;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
oldSymbol->SetFlags( UR_TRANSIENT );
|
|
|
|
ITEM_PICKER redoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
2018-01-19 18:56:01 +00:00
|
|
|
redoCommand->PushItem( redoWrapper );
|
2023-06-09 21:41:33 +00:00
|
|
|
redoCommand->SetDescription( description );
|
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
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
// Do not delete the previous symbol by calling SetCurSymbol( symbol ),
|
2021-06-10 18:51:46 +00:00
|
|
|
// which calls delete <previous symbol>.
|
|
|
|
// <previous symbol> is now put in redo list and is owned by this list.
|
|
|
|
// Just set the current symbol to the symbol which come from the undo list
|
2021-06-15 12:31:28 +00:00
|
|
|
m_symbol = symbol;
|
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();
|
2021-06-15 12:31:28 +00:00
|
|
|
m_libMgr->UpdateSymbolAfterRename( symbol, oldSymbol->GetName(), lib );
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Reselect the renamed symbol
|
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, symbol->GetName() ) );
|
2018-01-19 18:56:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2024-01-26 16:16:13 +00:00
|
|
|
SetShowDeMorgan( symbol->HasAlternateBodyStyle() );
|
2023-09-12 15:17:36 +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
|
|
|
|
|
|
|
|