2011-10-28 13:43:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-02-03 14:29:41 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-05-27 08:13:43 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-28 13:43:37 +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
|
|
|
|
*/
|
|
|
|
|
2022-07-23 18:30:32 +00:00
|
|
|
#include <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2020-12-25 11:55:45 +00:00
|
|
|
#include <kiway.h>
|
2022-12-28 22:03:03 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
2019-05-10 22:25:54 +00:00
|
|
|
#include <tools/ee_actions.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include <tools/symbol_editor_drawing_tools.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <template_fieldnames.h>
|
2012-09-28 17:47:41 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2017-09-15 14:17:44 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2022-09-16 03:06:23 +00:00
|
|
|
#include <lib_symbol_library_manager.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <symbol_tree_pane.h>
|
2022-07-10 02:44:49 +00:00
|
|
|
#include <project/project_file.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <widgets/lib_tree.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_plugin.h>
|
|
|
|
#include <sch_plugins/kicad/sch_sexpr_plugin.h>
|
2021-06-14 18:00:08 +00:00
|
|
|
#include <dialogs/dialog_lib_new_symbol.h>
|
2021-08-03 00:11:11 +00:00
|
|
|
#include <eda_list_dialog.h>
|
2019-04-08 00:11:06 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2022-06-12 02:59:59 +00:00
|
|
|
#include "symbol_saveas_type.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2022-06-12 02:59:59 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 7 )
|
|
|
|
#include <widgets/symbol_filedlg_save_as.h>
|
|
|
|
#else
|
|
|
|
#include <widgets/symbol_legacyfiledlg_save_as.h>
|
|
|
|
SYMBOL_SAVEAS_TYPE SYMBOL_LEGACYFILEDLG_SAVE_AS::m_option = SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
|
|
|
#endif
|
2020-12-29 18:59:48 +00:00
|
|
|
|
|
|
|
|
2023-09-12 15:17:36 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateTitle()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-04-13 20:02:35 +00:00
|
|
|
wxString title;
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2021-12-22 14:27:38 +00:00
|
|
|
if( GetCurSymbol() && IsSymbolFromSchematic() )
|
2020-08-31 15:06:23 +00:00
|
|
|
{
|
2021-06-20 21:46:41 +00:00
|
|
|
if( GetScreen() && GetScreen()->IsContentModified() )
|
|
|
|
title = wxT( "*" );
|
|
|
|
|
|
|
|
title += m_reference;
|
|
|
|
title += wxS( " " ) + _( "[from schematic]" );
|
|
|
|
}
|
|
|
|
else if( GetCurSymbol() )
|
|
|
|
{
|
|
|
|
if( GetScreen() && GetScreen()->IsContentModified() )
|
|
|
|
title = wxT( "*" );
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
title += UnescapeString( GetCurSymbol()->GetLibId().Format() );
|
2021-06-20 21:46:41 +00:00
|
|
|
|
|
|
|
if( m_libMgr && m_libMgr->IsLibraryReadOnly( GetCurLib() ) )
|
|
|
|
title += wxS( " " ) + _( "[Read Only Library]" );
|
2020-08-31 15:06:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-20 21:46:41 +00:00
|
|
|
title = _( "[no symbol loaded]" );
|
2020-08-31 15:06:23 +00:00
|
|
|
}
|
2020-05-16 21:25:13 +00:00
|
|
|
|
2021-06-20 21:46:41 +00:00
|
|
|
title += wxT( " \u2014 " ) + _( "Symbol Editor" );
|
2016-09-26 17:15:33 +00:00
|
|
|
SetTitle( title );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SelectActiveLibrary( const wxString& aLibrary )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString selectedLib = aLibrary;
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( selectedLib.empty() )
|
|
|
|
selectedLib = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !selectedLib.empty() )
|
|
|
|
SetCurLib( selectedLib );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2023-09-12 15:17:36 +00:00
|
|
|
UpdateTitle();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveCurrentSymbol()
|
2011-05-28 18:51:32 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( GetCurSymbol() )
|
2018-07-10 14:33:04 +00:00
|
|
|
{
|
2022-04-11 21:14:54 +00:00
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
|
2018-08-11 20:46:03 +00:00
|
|
|
|
2022-04-11 21:14:54 +00:00
|
|
|
if( !schframe ) // happens when the schematic editor has been closed
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "No schematic currently open." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
schframe->SaveSymbolToSchematic( *m_symbol, m_schematicSymbolUUID );
|
|
|
|
GetScreen()->SetContentModified( false );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-08-11 20:46:03 +00:00
|
|
|
{
|
2023-09-23 11:24:42 +00:00
|
|
|
const wxString& libName = GetCurSymbol()->GetLibId().GetLibNickname();
|
2022-04-11 21:14:54 +00:00
|
|
|
|
2023-09-23 11:24:42 +00:00
|
|
|
if( m_libMgr->IsLibraryReadOnly( libName ) )
|
2022-04-11 21:14:54 +00:00
|
|
|
{
|
2023-09-23 11:24:42 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol library '%s' is not writable." ),
|
|
|
|
libName );
|
|
|
|
wxString msg2 = _( "You must save to a different location." );
|
|
|
|
|
|
|
|
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) == wxID_OK )
|
|
|
|
return saveLibrary( libName, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return saveLibrary( libName, false );
|
2022-04-11 21:14:54 +00:00
|
|
|
}
|
2018-08-11 20:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-10 14:33:04 +00:00
|
|
|
|
2018-08-11 20:46:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-19 20:27:30 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConvert )
|
2018-08-11 20:46:03 +00:00
|
|
|
{
|
2023-01-20 03:45:46 +00:00
|
|
|
LIB_ID libId = aLibId;
|
|
|
|
|
|
|
|
// Database library symbols can't be edited, so load the underlying chosen symbol
|
|
|
|
if( SYMBOL_LIB_TABLE_ROW* lib = m_libMgr->GetLibrary( aLibId.GetLibNickname() ) )
|
|
|
|
{
|
|
|
|
if( lib->SchLibType() == SCH_IO_MGR::SCH_DATABASE )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* dbSym = Prj().SchSymbolLibTable()->LoadSymbol( aLibId );
|
|
|
|
|
|
|
|
if( dbSym && dbSym->GetSourceLibId().IsValid() )
|
|
|
|
libId = dbSym->GetSourceLibId();
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "Error loading symbol %s from library '%s'." ),
|
|
|
|
aLibId.GetUniStringLibId(), aLibId.GetUniStringLibItemName() );
|
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 21:14:54 +00:00
|
|
|
if( GetCurSymbol() && !IsSymbolFromSchematic()
|
2023-01-20 03:45:46 +00:00
|
|
|
&& GetCurSymbol()->GetLibId() == libId
|
2022-04-11 21:14:54 +00:00
|
|
|
&& GetUnit() == aUnit
|
|
|
|
&& GetConvert() == aConvert )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-11 21:14:54 +00:00
|
|
|
if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() )
|
2018-08-11 20:46:03 +00:00
|
|
|
{
|
2021-10-01 20:49:14 +00:00
|
|
|
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ),
|
|
|
|
[&]() -> bool
|
|
|
|
{
|
|
|
|
return saveCurrentSymbol();
|
|
|
|
} ) )
|
2018-08-11 20:46:03 +00:00
|
|
|
{
|
2018-07-10 14:33:04 +00:00
|
|
|
return false;
|
2018-08-11 20:46:03 +00:00
|
|
|
}
|
2018-07-10 14:33:04 +00:00
|
|
|
}
|
2011-05-28 18:51:32 +00:00
|
|
|
|
2023-01-20 03:45:46 +00:00
|
|
|
SelectActiveLibrary( libId.GetLibNickname() );
|
2021-10-01 21:45:49 +00:00
|
|
|
|
2023-01-20 03:45:46 +00:00
|
|
|
if( LoadSymbolFromCurrentLib( libId.GetLibItemName(), aUnit, aConvert ) )
|
2021-10-01 21:45:49 +00:00
|
|
|
{
|
2023-01-20 03:45:46 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( libId );
|
|
|
|
m_treePane->GetLibTree()->ExpandLibId( libId );
|
2021-10-01 21:45:49 +00:00
|
|
|
|
2023-01-20 03:45:46 +00:00
|
|
|
m_centerItemOnIdle = libId;
|
2021-10-01 21:45:49 +00:00
|
|
|
Bind( wxEVT_IDLE, &SYMBOL_EDIT_FRAME::centerItemIdleHandler, this );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_EDIT_FRAME::centerItemIdleHandler( wxIdleEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_treePane->GetLibTree()->CenterLibId( m_centerItemOnIdle );
|
|
|
|
Unbind( wxEVT_IDLE, &SYMBOL_EDIT_FRAME::centerItemIdleHandler, this );
|
2011-05-28 18:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadSymbolFromCurrentLib( const wxString& aAliasName, int aUnit,
|
|
|
|
int aConvert )
|
2011-05-28 18:51:32 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* alias = nullptr;
|
2017-10-06 18:07:43 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-06-26 11:33:37 +00:00
|
|
|
msg.Printf( _( "Error loading symbol %s from library '%s'." ),
|
2021-06-16 22:35:00 +00:00
|
|
|
aAliasName,
|
|
|
|
GetCurLib() );
|
2017-10-06 18:07:43 +00:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( !alias || !LoadOneLibrarySymbolAux( alias, GetCurLib(), aUnit, aConvert ) )
|
2011-05-28 18:51:32 +00:00
|
|
|
return false;
|
|
|
|
|
2018-01-23 11:15:19 +00:00
|
|
|
// Enable synchronized pin edit mode for symbols with interchangeable units
|
2022-04-04 15:56:14 +00:00
|
|
|
m_SyncPinEdit = GetCurSymbol()->IsMulti() && !GetCurSymbol()->UnitsLocked();
|
2011-05-28 18:51:32 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2021-06-15 12:31:28 +00:00
|
|
|
SetShowDeMorgan( GetCurSymbol()->Flatten()->HasConversion() );
|
2011-05-28 18:51:32 +00:00
|
|
|
|
2017-07-19 17:34:55 +00:00
|
|
|
if( aUnit > 0 )
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2017-07-19 17:34:55 +00:00
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux( LIB_SYMBOL* aEntry, const wxString& aLibrary,
|
|
|
|
int aUnit, int aConvert )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-08-31 15:06:23 +00:00
|
|
|
bool rebuildMenuAndToolbar = false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !aEntry || aLibrary.empty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( aEntry->GetName().IsEmpty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
wxLogWarning( "Symbol in library '%s' has empty name field.", aLibrary );
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-03 14:32:35 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
// Symbols from the schematic are edited in place and not managed by the library manager.
|
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
delete m_symbol;
|
|
|
|
m_symbol = nullptr;
|
2020-08-31 15:06:23 +00:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
delete screen;
|
|
|
|
SetScreen( m_dummyScreen );
|
|
|
|
m_isSymbolFromSchematic = false;
|
|
|
|
rebuildMenuAndToolbar = true;
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* lib_symbol = m_libMgr->GetBufferedSymbol( aEntry->GetName(), aLibrary );
|
2021-06-10 18:51:46 +00:00
|
|
|
wxCHECK( lib_symbol, false );
|
2018-09-04 18:49:49 +00:00
|
|
|
|
2018-11-08 21:26:01 +00:00
|
|
|
m_unit = aUnit > 0 ? aUnit : 1;
|
|
|
|
m_convert = aConvert > 0 ? aConvert : 1;
|
2018-09-04 18:49:49 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// The buffered screen for the symbol
|
2021-06-15 12:31:28 +00:00
|
|
|
SCH_SCREEN* symbol_screen = m_libMgr->GetScreen( lib_symbol->GetName(), aLibrary );
|
2019-02-08 14:34:53 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
SetScreen( symbol_screen );
|
|
|
|
SetCurSymbol( new LIB_SYMBOL( *lib_symbol ), true );
|
2017-11-12 17:55:20 +00:00
|
|
|
SetCurLib( aLibrary );
|
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-31 15:06:23 +00:00
|
|
|
if( rebuildMenuAndToolbar )
|
|
|
|
{
|
|
|
|
ReCreateMenuBar();
|
|
|
|
ReCreateHToolbar();
|
|
|
|
GetInfoBar()->Dismiss();
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:17:36 +00:00
|
|
|
UpdateTitle();
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2021-06-15 12:31:28 +00:00
|
|
|
SetShowDeMorgan( GetCurSymbol()->HasConversion() );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2022-01-06 00:50:24 +00:00
|
|
|
ClearUndoRedoList();
|
|
|
|
|
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
|
|
|
// Display the document information based on the entry selected just in
|
|
|
|
// case the entry is an alias.
|
2021-08-20 19:45:57 +00:00
|
|
|
UpdateMsgPanel();
|
2017-11-13 10:38:20 +00:00
|
|
|
Refresh();
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveAll()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2018-02-16 10:27:43 +00:00
|
|
|
saveAllLibraries( false );
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::CreateNewSymbol()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2019-05-10 22:24:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
wxArrayString rootSymbols;
|
2017-11-13 11:30:03 +00:00
|
|
|
wxString lib = getTargetLib();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
{
|
|
|
|
lib = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
return;
|
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_libMgr->GetRootSymbolNames( lib, rootSymbols );
|
|
|
|
|
2020-11-03 23:02:38 +00:00
|
|
|
rootSymbols.Sort();
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
DIALOG_LIB_NEW_SYMBOL dlg( this, &rootSymbols );
|
2017-11-12 17:55:20 +00:00
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( dlg.GetName().IsEmpty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "This new symbol has no name and cannot be created." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString name = dlg.GetName();
|
2021-06-10 18:51:46 +00:00
|
|
|
|
2018-04-15 08:06:53 +00:00
|
|
|
// Currently, symbol names cannot include a space, that breaks libraries:
|
2017-11-12 17:55:20 +00:00
|
|
|
name.Replace( " ", "_" );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Test if there is a symbol with this name already.
|
2021-06-15 12:31:28 +00:00
|
|
|
if( !lib.empty() && m_libMgr->SymbolExists( name, lib ) )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'." ),
|
|
|
|
name,
|
|
|
|
lib );
|
2021-07-28 16:30:25 +00:00
|
|
|
|
|
|
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
|
|
|
errorDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
if( errorDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL new_symbol( name ); // do not create symbol on the heap, it will be buffered soon
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString parentSymbolName = dlg.GetParentSymbolName();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( parentSymbolName.IsEmpty() )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
new_symbol.GetReferenceField().SetText( dlg.GetReference() );
|
|
|
|
new_symbol.SetUnitCount( dlg.GetUnitCount() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Initialize new_symbol.m_TextInside member:
|
2019-11-06 19:15:42 +00:00
|
|
|
// if 0, pin text is outside the body (on the pin)
|
|
|
|
// if > 0, pin text is inside the body
|
|
|
|
if( dlg.GetPinNameInside() )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
new_symbol.SetPinNameOffset( dlg.GetPinTextPosition() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( new_symbol.GetPinNameOffset() == 0 )
|
|
|
|
new_symbol.SetPinNameOffset( 1 );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
new_symbol.SetPinNameOffset( 0 );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
( dlg.GetPowerSymbol() ) ? new_symbol.SetPower() : new_symbol.SetNormal();
|
|
|
|
new_symbol.SetShowPinNumbers( dlg.GetShowPinNumber() );
|
|
|
|
new_symbol.SetShowPinNames( dlg.GetShowPinName() );
|
2022-02-06 13:23:08 +00:00
|
|
|
new_symbol.LockUnits( !dlg.GetUnitsInterchangeable() );
|
2021-06-10 18:51:46 +00:00
|
|
|
new_symbol.SetIncludeInBom( dlg.GetIncludeInBom() );
|
|
|
|
new_symbol.SetIncludeOnBoard( dlg.GetIncludeOnBoard() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
if( dlg.GetUnitCount() < 2 )
|
2021-06-10 18:51:46 +00:00
|
|
|
new_symbol.LockUnits( false );
|
|
|
|
|
|
|
|
new_symbol.SetConversion( dlg.GetAlternateBodyStyle() );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* parent = m_libMgr->GetAlias( parentSymbolName, lib );
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK( parent, /* void */ );
|
2021-06-10 18:51:46 +00:00
|
|
|
new_symbol.SetParent( parent );
|
2020-05-30 14:33:05 +00:00
|
|
|
|
|
|
|
// Inherit the parent mandatory field attributes.
|
2021-02-28 13:28:23 +00:00
|
|
|
for( int id = 0; id < MANDATORY_FIELDS; ++id )
|
2020-05-30 14:33:05 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* field = new_symbol.GetFieldById( id );
|
2020-05-30 14:33:05 +00:00
|
|
|
|
|
|
|
// the MANDATORY_FIELDS are exactly that in RAM.
|
|
|
|
wxCHECK( field, /* void */ );
|
|
|
|
|
2021-02-28 13:28:23 +00:00
|
|
|
LIB_FIELD* parentField = parent->GetFieldById( id );
|
2020-05-30 14:33:05 +00:00
|
|
|
|
|
|
|
wxCHECK( parentField, /* void */ );
|
|
|
|
|
|
|
|
*field = *parentField;
|
|
|
|
|
2020-11-11 17:33:53 +00:00
|
|
|
switch( id )
|
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
case REFERENCE_FIELD:
|
2020-11-11 17:33:53 +00:00
|
|
|
// parent's reference already copied
|
|
|
|
break;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
case VALUE_FIELD:
|
2022-08-20 21:43:20 +00:00
|
|
|
if( parent->IsPower() )
|
|
|
|
field->SetText( name );
|
2020-11-11 17:33:53 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
case FOOTPRINT_FIELD:
|
|
|
|
case DATASHEET_FIELD:
|
2020-11-11 17:33:53 +00:00
|
|
|
// - footprint might be the same as parent, but might not
|
|
|
|
// - datasheet is most likely different
|
|
|
|
// - probably best to play it safe and copy neither
|
|
|
|
field->SetText( wxEmptyString );
|
|
|
|
break;
|
|
|
|
}
|
2020-05-30 14:33:05 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
field->SetParent( &new_symbol );
|
2020-05-30 14:33:05 +00:00
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
m_libMgr->UpdateSymbol( &new_symbol, lib );
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2021-06-15 12:31:28 +00:00
|
|
|
LoadSymbol( name, lib, 1 );
|
2022-04-05 13:37:38 +00:00
|
|
|
|
|
|
|
// must be called after loadSymbol, that calls SetShowDeMorgan, but
|
|
|
|
// because the symbol is empty,it looks like it has no alternate body
|
2023-05-27 08:13:43 +00:00
|
|
|
// and a derived symbol inherits its parent body.
|
|
|
|
if( !new_symbol.GetParent().lock() )
|
|
|
|
SetShowDeMorgan( dlg.GetAlternateBodyStyle() );
|
|
|
|
else
|
|
|
|
SetShowDeMorgan( new_symbol.HasConversion() );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::Save()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2023-04-14 16:12:56 +00:00
|
|
|
wxString libName;
|
2020-12-11 22:44:10 +00:00
|
|
|
|
2023-04-14 16:12:56 +00:00
|
|
|
if( IsSymbolTreeShown() )
|
|
|
|
libName = GetTreeLIBID().GetLibNickname();
|
|
|
|
|
|
|
|
if( libName.empty() )
|
|
|
|
{
|
|
|
|
saveCurrentSymbol();
|
2020-05-16 21:25:13 +00:00
|
|
|
}
|
2023-04-14 16:12:56 +00:00
|
|
|
else if( m_libMgr->IsLibraryReadOnly( libName ) )
|
2018-07-27 10:46:09 +00:00
|
|
|
{
|
2023-04-14 16:12:56 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol library '%s' is not writable." ),
|
|
|
|
libName );
|
|
|
|
wxString msg2 = _( "You must save to a different location." );
|
2020-12-25 11:55:45 +00:00
|
|
|
|
2023-04-14 16:12:56 +00:00
|
|
|
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) == wxID_OK )
|
|
|
|
saveLibrary( libName, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveLibrary( libName, false );
|
2018-07-27 10:46:09 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 16:12:56 +00:00
|
|
|
if( IsSymbolTreeShown() )
|
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
|
|
|
|
2023-09-12 15:17:36 +00:00
|
|
|
UpdateTitle();
|
2018-07-27 10:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-27 16:28:52 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveLibraryAs()
|
2018-07-27 10:46:09 +00:00
|
|
|
{
|
2021-02-07 23:21:38 +00:00
|
|
|
wxCHECK( !GetTargetLibId().GetLibNickname().empty(), /* void */ );
|
2018-07-27 10:46:09 +00:00
|
|
|
|
2021-02-07 23:21:38 +00:00
|
|
|
const wxString& libName = GetTargetLibId().GetLibNickname();
|
2020-12-27 16:28:52 +00:00
|
|
|
|
|
|
|
saveLibrary( libName, true );
|
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
|
|
|
}
|
|
|
|
|
2021-01-31 22:58:34 +00:00
|
|
|
|
2020-12-27 16:28:52 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveSymbolAs()
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
saveSymbolAs();
|
2017-11-13 22:13:10 +00:00
|
|
|
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
static int ID_SAVE_AS_NAME = 4172;
|
|
|
|
static int ID_MAKE_NEW_LIBRARY = 4173;
|
|
|
|
|
|
|
|
|
|
|
|
EDA_LIST_DIALOG* SYMBOL_EDIT_FRAME::buildSaveAsDialog( const wxString& aSymbolName,
|
|
|
|
const wxString& aLibraryPreselect )
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
2022-07-10 02:44:49 +00:00
|
|
|
PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
|
2022-04-19 18:09:19 +00:00
|
|
|
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable();
|
|
|
|
std::vector<wxString> libNicknames = tbl->GetLogicalLibs();
|
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
headers.Add( _( "Nickname" ) );
|
|
|
|
headers.Add( _( "Description" ) );
|
|
|
|
|
|
|
|
for( const wxString& nickname : libNicknames )
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
if( alg::contains( project.m_PinnedSymbolLibs, nickname )
|
|
|
|
|| alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
|
2022-07-10 02:44:49 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const wxString& nickname : libNicknames )
|
|
|
|
{
|
2022-07-23 18:30:32 +00:00
|
|
|
if( !alg::contains( project.m_PinnedSymbolLibs, nickname )
|
|
|
|
&& !alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
|
2022-07-10 02:44:49 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2022-04-19 18:09:19 +00:00
|
|
|
}
|
2020-12-25 11:55:45 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
EDA_LIST_DIALOG* dlg = new EDA_LIST_DIALOG( this, _( "Save Symbol As" ), headers,
|
2022-07-10 02:44:49 +00:00
|
|
|
itemsToDisplay, aLibraryPreselect, false );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
dlg->SetListLabel( _( "Save in library:" ) );
|
|
|
|
dlg->SetOKLabel( _( "Save" ) );
|
2019-12-02 23:33:45 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
wxStaticText* label = new wxStaticText( dlg, wxID_ANY, _( "Name:" ) );
|
|
|
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
|
|
|
|
|
|
|
wxTextCtrl* nameTextCtrl = new wxTextCtrl( dlg, ID_SAVE_AS_NAME, aSymbolName );
|
|
|
|
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton* newLibraryButton = new wxButton( dlg, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
|
|
|
|
dlg->m_ButtonsSizer->Prepend( 80, 20 );
|
|
|
|
dlg->m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
|
|
|
|
|
|
|
|
dlg->GetSizer()->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
|
|
|
|
|
|
|
dlg->Bind( wxEVT_BUTTON,
|
|
|
|
[dlg]( wxCommandEvent& )
|
|
|
|
{
|
|
|
|
dlg->EndModal( ID_MAKE_NEW_LIBRARY );
|
|
|
|
}, ID_MAKE_NEW_LIBRARY );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
// Move nameTextCtrl to the head of the tab-order
|
|
|
|
if( dlg->GetChildren().DeleteObject( nameTextCtrl ) )
|
|
|
|
dlg->GetChildren().Insert( nameTextCtrl );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
dlg->SetInitialFocus( nameTextCtrl );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
dlg->Layout();
|
|
|
|
dlg->GetSizer()->Fit( dlg );
|
|
|
|
|
|
|
|
return dlg;
|
|
|
|
}
|
2018-07-24 21:16:59 +00:00
|
|
|
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::saveSymbolAs()
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = getTargetSymbol();
|
|
|
|
|
|
|
|
if( symbol )
|
|
|
|
{
|
|
|
|
LIB_ID old_lib_id = symbol->GetLibId();
|
|
|
|
wxString symbolName = old_lib_id.GetLibItemName();
|
|
|
|
wxString libraryName = old_lib_id.GetLibNickname();
|
2023-09-14 22:54:04 +00:00
|
|
|
bool valueFollowsName = symbol->GetValueField().GetText() == symbolName;
|
2022-04-19 18:09:19 +00:00
|
|
|
bool done = false;
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
std::unique_ptr<EDA_LIST_DIALOG> dlg;
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
while( !done )
|
|
|
|
{
|
|
|
|
dlg.reset( buildSaveAsDialog( symbolName, libraryName ) );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
int ret = dlg->ShowModal();
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
if( ret == wxID_CANCEL )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( ret == wxID_OK )
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else if( ret == ID_MAKE_NEW_LIBRARY )
|
|
|
|
{
|
|
|
|
wxFileName newLibrary( AddLibraryFile( true ) );
|
|
|
|
libraryName = newLibrary.GetName();
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
libraryName = dlg->GetTextSelection();
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
if( libraryName.IsEmpty() )
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
2019-12-12 15:44:53 +00:00
|
|
|
DisplayError( this, _( "No library specified. Symbol could not be saved." ) );
|
2018-07-24 21:16:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-13 21:51:59 +00:00
|
|
|
// @todo Either check the selecteced library to see if the parent symbol name is in
|
|
|
|
// the new library and/or copy the parent symbol as well. This is the lazy
|
2021-06-10 18:51:46 +00:00
|
|
|
// solution to ensure derived symbols do not get orphaned.
|
2022-04-19 18:09:19 +00:00
|
|
|
if( symbol->IsAlias() && libraryName != old_lib_id.GetLibNickname() )
|
2019-12-13 21:51:59 +00:00
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
DisplayError( this, _( "Derived symbols must be saved in the same library as their "
|
|
|
|
"parent symbol." ) );
|
2019-12-13 21:51:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
symbolName = static_cast<wxTextCtrl*>( dlg->FindWindow( ID_SAVE_AS_NAME ) )->GetValue();
|
|
|
|
symbolName.Trim( true );
|
|
|
|
symbolName.Trim( false );
|
|
|
|
symbolName.Replace( " ", "_" );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
if( symbolName.IsEmpty() )
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
// This is effectively a cancel. No need to nag the user about it.
|
2018-07-24 21:16:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Test if there is a symbol with this name already.
|
2022-04-19 18:09:19 +00:00
|
|
|
if( m_libMgr->SymbolExists( symbolName, libraryName ) )
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'" ),
|
2022-04-19 18:09:19 +00:00
|
|
|
symbolName,
|
|
|
|
libraryName );
|
2021-07-28 16:30:25 +00:00
|
|
|
|
|
|
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
|
|
|
errorDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
if( errorDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2018-07-24 21:16:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL new_symbol( *symbol );
|
2022-04-19 18:09:19 +00:00
|
|
|
new_symbol.SetName( symbolName );
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2023-09-14 22:54:04 +00:00
|
|
|
if( valueFollowsName )
|
|
|
|
new_symbol.GetValueField().SetText( symbolName );
|
|
|
|
|
2022-04-19 18:09:19 +00:00
|
|
|
m_libMgr->UpdateSymbol( &new_symbol, libraryName );
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2022-04-19 18:09:19 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( libraryName, new_symbol.GetName() ) );
|
|
|
|
LoadSymbol( symbolName, libraryName, m_unit );
|
2018-07-24 21:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties( wxString* aOldName )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
wxCHECK( m_symbol, /* void */ );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
wxString lib = GetCurLib();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( !lib.IsEmpty() && aOldName && *aOldName != m_symbol->GetName() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-11 14:38:05 +00:00
|
|
|
// Test the current library for name conflicts
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_libMgr->SymbolExists( m_symbol->GetName(), lib ) )
|
2019-05-11 14:38:05 +00:00
|
|
|
{
|
2021-06-30 10:53:04 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol name '%s' already in use." ),
|
|
|
|
UnescapeString( m_symbol->GetName() ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
2021-06-15 12:31:28 +00:00
|
|
|
m_symbol->SetName( *aOldName );
|
2019-05-11 14:38:05 +00:00
|
|
|
}
|
|
|
|
else
|
2020-07-16 00:08:31 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
m_libMgr->UpdateSymbolAfterRename( m_symbol, *aOldName, lib );
|
2020-07-16 00:08:31 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Reselect the renamed symbol
|
2021-06-15 12:31:28 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, m_symbol->GetName() ) );
|
2020-07-16 00:08:31 +00:00
|
|
|
}
|
2019-05-11 14:38:05 +00:00
|
|
|
|
|
|
|
RebuildSymbolUnitsList();
|
2021-06-15 12:31:28 +00:00
|
|
|
SetShowDeMorgan( GetCurSymbol()->Flatten()->HasConversion() );
|
2023-09-12 15:17:36 +00:00
|
|
|
UpdateTitle();
|
2019-05-11 14:38:05 +00:00
|
|
|
|
2022-04-15 21:56:18 +00:00
|
|
|
// N.B. The view needs to be rebuilt first as the Symbol Properties change may invalidate
|
|
|
|
// the view pointers by rebuilting the field table
|
2019-05-11 14:38:05 +00:00
|
|
|
RebuildView();
|
2022-04-15 21:56:18 +00:00
|
|
|
UpdateMsgPanel();
|
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
OnModify();
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2022-09-09 02:15:44 +00:00
|
|
|
std::vector<LIB_ID> toDelete = GetSelectedLibIds();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
if( toDelete.empty() )
|
|
|
|
toDelete.emplace_back( GetTargetLibId() );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
for( LIB_ID& libId : toDelete )
|
2019-12-12 15:44:53 +00:00
|
|
|
{
|
2022-09-09 02:15:44 +00:00
|
|
|
if( m_libMgr->IsSymbolModified( libId.GetLibItemName(), libId.GetLibNickname() )
|
|
|
|
&& !IsOK( this, wxString::Format( _( "The symbol '%s' has been modified.\n"
|
|
|
|
"Do you want to remove it from the library?" ),
|
|
|
|
libId.GetUniStringLibItemName() ) ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
if( m_libMgr->HasDerivedSymbols( libId.GetLibItemName(), libId.GetLibNickname() ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf(
|
|
|
|
_( "The symbol %s is used to derive other symbols.\n"
|
2019-12-12 15:44:53 +00:00
|
|
|
"Deleting this symbol will delete all of the symbols derived from it.\n\n"
|
2021-06-28 23:44:07 +00:00
|
|
|
"Do you wish to delete this symbol and all of its derivatives?" ),
|
2019-12-12 15:44:53 +00:00
|
|
|
libId.GetLibItemName().wx_str() );
|
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
wxMessageDialog::ButtonLabel yesButtonLabel( _( "Delete Symbol" ) );
|
|
|
|
wxMessageDialog::ButtonLabel noButtonLabel( _( "Keep Symbol" ) );
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
wxMessageDialog dlg( this, msg, _( "Warning" ),
|
|
|
|
wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
|
|
|
|
dlg.SetYesNoLabels( yesButtonLabel, noButtonLabel );
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
if( dlg.ShowModal() == wxID_NO )
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-12 15:44:53 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
if( IsCurrentSymbol( libId ) )
|
|
|
|
emptyScreen();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
m_libMgr->RemoveSymbol( libId.GetLibItemName(), libId.GetLibNickname() );
|
|
|
|
}
|
2018-10-16 15:50:29 +00:00
|
|
|
|
2019-12-02 20:24:16 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::CopySymbolToClipboard()
|
2017-11-13 19:39:36 +00:00
|
|
|
{
|
2022-09-09 02:15:44 +00:00
|
|
|
std::vector<LIB_ID> symbols;
|
2018-08-29 20:53:41 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
if( GetTreeLIBIDs( symbols ) == 0 )
|
2018-08-29 20:53:41 +00:00
|
|
|
return;
|
|
|
|
|
2019-04-08 00:11:06 +00:00
|
|
|
STRING_FORMATTER formatter;
|
2022-09-09 02:15:44 +00:00
|
|
|
|
|
|
|
for( LIB_ID& libId : symbols )
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = m_libMgr->GetBufferedSymbol( libId.GetLibItemName(),
|
|
|
|
libId.GetLibNickname() );
|
|
|
|
|
|
|
|
if( !symbol )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::unique_ptr<LIB_SYMBOL> tmp = symbol->Flatten();
|
|
|
|
SCH_SEXPR_PLUGIN::FormatLibSymbol( tmp.get(), formatter );
|
|
|
|
}
|
2019-04-08 00:11:06 +00:00
|
|
|
|
2021-01-29 19:13:12 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
|
|
|
|
2019-04-08 00:11:06 +00:00
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock || !clipboard->IsOpened() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto data = new wxTextDataObject( wxString( formatter.GetString().c_str(), wxConvUTF8 ) );
|
|
|
|
clipboard->SetData( data );
|
|
|
|
|
|
|
|
clipboard->Flush();
|
2018-08-29 20:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::DuplicateSymbol( bool aFromClipboard )
|
2018-08-29 20:53:41 +00:00
|
|
|
{
|
2022-03-03 23:19:24 +00:00
|
|
|
LIB_ID libId = GetTargetLibId();
|
2017-11-13 19:39:36 +00:00
|
|
|
wxString lib = libId.GetLibNickname();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
return;
|
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
std::vector<LIB_SYMBOL*> newSymbols;
|
|
|
|
|
2019-06-05 22:29:59 +00:00
|
|
|
if( aFromClipboard )
|
2019-04-08 00:11:06 +00:00
|
|
|
{
|
2021-01-29 19:13:12 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
|
|
|
|
2019-04-08 00:11:06 +00:00
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
2022-01-12 09:24:04 +00:00
|
|
|
if( !clipboardLock
|
|
|
|
|| !( clipboard->IsSupported( wxDF_TEXT )
|
|
|
|
|| clipboard->IsSupported( wxDF_UNICODETEXT ) ) )
|
|
|
|
{
|
2019-04-08 00:11:06 +00:00
|
|
|
return;
|
2022-01-12 09:24:04 +00:00
|
|
|
}
|
2019-04-08 00:11:06 +00:00
|
|
|
|
|
|
|
wxTextDataObject data;
|
|
|
|
clipboard->GetData( data );
|
2021-06-15 12:31:28 +00:00
|
|
|
wxString symbolSource = data.GetText();
|
2019-04-08 00:11:06 +00:00
|
|
|
|
2023-01-22 14:41:33 +00:00
|
|
|
std::unique_ptr<STRING_LINE_READER> reader = std::make_unique<STRING_LINE_READER>( TO_UTF8( symbolSource ), wxS( "Clipboard" ) );
|
2022-10-05 16:45:18 +00:00
|
|
|
LIB_SYMBOL* newSymbol = nullptr;
|
2019-04-08 00:11:06 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
do
|
2019-04-08 00:11:06 +00:00
|
|
|
{
|
2022-09-09 02:15:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
newSymbol = SCH_SEXPR_PLUGIN::ParseLibSymbol( *reader );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR& e )
|
|
|
|
{
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogMessage( wxS( "Can not paste: %s" ), e.Problem() );
|
2022-09-09 02:15:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( newSymbol )
|
|
|
|
newSymbols.emplace_back( newSymbol );
|
|
|
|
|
|
|
|
reader.reset( new STRING_LINE_READER( *reader ) );
|
2019-04-08 00:11:06 +00:00
|
|
|
}
|
2022-09-09 02:15:44 +00:00
|
|
|
while( newSymbol );
|
2019-04-08 00:11:06 +00:00
|
|
|
}
|
2018-08-29 20:53:41 +00:00
|
|
|
else
|
2019-06-05 22:29:59 +00:00
|
|
|
{
|
2022-10-05 16:45:18 +00:00
|
|
|
LIB_SYMBOL* srcSymbol = m_libMgr->GetBufferedSymbol( libId.GetLibItemName(), lib );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
wxCHECK( srcSymbol, /* void */ );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
newSymbols.emplace_back( new LIB_SYMBOL( *srcSymbol ) );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Derive from same parent.
|
2021-06-10 18:51:46 +00:00
|
|
|
if( srcSymbol->IsAlias() )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
std::shared_ptr< LIB_SYMBOL > srcParent = srcSymbol->GetParent().lock();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
wxCHECK( srcParent, /* void */ );
|
|
|
|
|
2022-10-05 16:45:18 +00:00
|
|
|
newSymbols.back()->SetParent( srcParent.get() );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2019-06-05 22:29:59 +00:00
|
|
|
}
|
2017-11-13 19:39:36 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
if( newSymbols.empty() )
|
2017-11-13 19:39:36 +00:00
|
|
|
return;
|
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
for( LIB_SYMBOL* symbol : newSymbols )
|
|
|
|
{
|
|
|
|
ensureUniqueName( symbol, lib );
|
|
|
|
m_libMgr->UpdateSymbol( symbol, lib );
|
2020-12-21 17:21:01 +00:00
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
LoadOneLibrarySymbolAux( symbol, lib, GetUnit(), GetConvert() );
|
|
|
|
}
|
2020-12-21 17:21:01 +00:00
|
|
|
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2022-09-09 02:15:44 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newSymbols[0]->GetName() ) );
|
2019-04-08 00:11:06 +00:00
|
|
|
|
2022-10-05 16:45:18 +00:00
|
|
|
for( LIB_SYMBOL* symbol : newSymbols )
|
|
|
|
delete symbol;
|
2017-11-13 19:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::ensureUniqueName( LIB_SYMBOL* aSymbol, const wxString& aLibrary )
|
2017-11-13 19:39:36 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
wxCHECK( aSymbol, /* void */ );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2019-12-17 16:09:59 +00:00
|
|
|
int i = 1;
|
2021-06-10 18:51:46 +00:00
|
|
|
wxString newName = aSymbol->GetName();
|
2017-11-13 19:39:36 +00:00
|
|
|
|
2019-12-16 15:11:06 +00:00
|
|
|
// Append a number to the name until the name is unique in the library.
|
2021-06-15 12:31:28 +00:00
|
|
|
while( m_libMgr->SymbolExists( newName, aLibrary ) )
|
2021-06-10 18:51:46 +00:00
|
|
|
newName.Printf( "%s_%d", aSymbol->GetName(), i++ );
|
2017-11-13 19:39:36 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->SetName( newName );
|
2017-11-13 19:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::Revert( bool aConfirm )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2021-02-07 23:21:38 +00:00
|
|
|
LIB_ID libId = GetTargetLibId();
|
2018-07-27 10:46:09 +00:00
|
|
|
const wxString& libName = libId.GetLibNickname();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Empty if this is the library itself that is selected.
|
2021-06-15 12:31:28 +00:00
|
|
|
const wxString& symbolName = libId.GetLibItemName();
|
2018-07-27 10:46:09 +00:00
|
|
|
|
2021-06-28 23:44:07 +00:00
|
|
|
wxString msg = wxString::Format( _( "Revert '%s' to last version saved?" ),
|
2021-06-15 12:31:28 +00:00
|
|
|
symbolName.IsEmpty() ? libName : symbolName );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2019-06-13 11:44:12 +00:00
|
|
|
if( aConfirm && !ConfirmRevertDialog( this, msg ) )
|
2018-07-27 10:46:09 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
bool reload_currentSymbol = false;
|
|
|
|
wxString curr_symbolName = symbolName;
|
2018-08-19 08:25:12 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( GetCurSymbol() )
|
2018-08-19 08:25:12 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
// the library itself is reverted: the current symbol will be reloaded only if it is
|
2018-11-20 20:14:00 +00:00
|
|
|
// owned by this library
|
2021-06-15 12:31:28 +00:00
|
|
|
if( symbolName.IsEmpty() )
|
2018-11-20 20:14:00 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_ID curr_libId = GetCurSymbol()->GetLibId();
|
|
|
|
reload_currentSymbol = libName == curr_libId.GetLibNickname();
|
2018-08-19 08:25:12 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( reload_currentSymbol )
|
|
|
|
curr_symbolName = curr_libId.GetLibItemName();
|
2018-11-20 20:14:00 +00:00
|
|
|
}
|
|
|
|
else
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2022-04-21 10:57:15 +00:00
|
|
|
reload_currentSymbol = IsCurrentSymbol( libId );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2018-08-19 08:25:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
int unit = m_unit;
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( reload_currentSymbol )
|
2017-11-12 17:55:20 +00:00
|
|
|
emptyScreen();
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( symbolName.IsEmpty() )
|
2018-07-27 10:46:09 +00:00
|
|
|
{
|
|
|
|
m_libMgr->RevertLibrary( libName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
libId = m_libMgr->RevertSymbol( libId.GetLibItemName(), libId.GetLibNickname() );
|
2018-07-27 10:46:09 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( libId );
|
2021-06-15 12:31:28 +00:00
|
|
|
m_libMgr->ClearSymbolModified( libId.GetLibItemName(), libId.GetLibNickname() );
|
2018-07-27 10:46:09 +00:00
|
|
|
}
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( reload_currentSymbol && m_libMgr->SymbolExists( curr_symbolName, libName ) )
|
|
|
|
LoadSymbol( curr_symbolName, libName, unit );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2018-07-27 10:46:09 +00:00
|
|
|
m_treePane->Refresh();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::RevertAll()
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( m_libMgr, "Library manager object not created." );
|
|
|
|
|
|
|
|
Revert( false );
|
|
|
|
m_libMgr->RevertAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::LoadSymbol( const wxString& aAlias, const wxString& aLibrary, int aUnit )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2022-04-11 21:14:54 +00:00
|
|
|
if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() )
|
|
|
|
{
|
|
|
|
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ),
|
|
|
|
[&]() -> bool
|
|
|
|
{
|
|
|
|
return saveCurrentSymbol();
|
|
|
|
} ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* symbol = m_libMgr->GetBufferedSymbol( aAlias, aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( !symbol )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2022-04-11 21:14:54 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "Symbol %s not found in library '%s'." ),
|
|
|
|
aAlias,
|
|
|
|
aLibrary ) );
|
2017-11-12 17:55:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-08 09:48:33 +00:00
|
|
|
// Optimize default edit options for this symbol
|
|
|
|
// Usually if units are locked, graphic items are specific to each unit
|
|
|
|
// and if units are interchangeable, graphic items are common to units
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_DRAWING_TOOLS* tools = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
2021-06-15 12:31:28 +00:00
|
|
|
tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
|
2018-01-08 09:48:33 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LoadOneLibrarySymbolAux( symbol, aLibrary, aUnit, 0 );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-08-27 11:41:56 +00:00
|
|
|
wxString msg;
|
2022-06-12 02:59:59 +00:00
|
|
|
SYMBOL_SAVEAS_TYPE type = SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
2020-04-16 16:43:50 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::SCH_FILE_T::SCH_KICAD;
|
2017-10-06 18:07:43 +00:00
|
|
|
PROJECT& prj = Prj();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2019-05-10 22:24:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2017-11-13 09:55:05 +00:00
|
|
|
if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
ShowInfoBarError( _( "No library specified." ) );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
if( aNewFile )
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
{
|
2017-11-13 09:55:05 +00:00
|
|
|
SEARCH_STACK* search = prj.SchSearchS();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
|
|
|
// Get a new name for the library
|
2014-06-10 15:56:43 +00:00
|
|
|
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
|
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-06-10 15:56:43 +00:00
|
|
|
if( !default_path )
|
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
|
|
|
default_path = search->LastVisitedPath();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
2017-11-13 09:55:05 +00:00
|
|
|
fn.SetName( aLibrary );
|
2020-04-16 16:43:50 +00:00
|
|
|
fn.SetExt( KiCadSymbolLibFileExtension );
|
2017-11-13 09:55:05 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString wildcards = KiCadSymbolLibFileWildcard();
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2021-06-28 23:44:07 +00:00
|
|
|
wxFileDialog dlg( this, wxString::Format( _( "Save Library '%s' As..." ), aLibrary ),
|
2020-02-13 13:39:52 +00:00
|
|
|
default_path, fn.GetFullName(), wildcards,
|
2010-03-18 20:35:29 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2022-06-12 02:59:59 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 7 )
|
|
|
|
SYMBOL_FILEDLG_SAVE_AS saveAsHook( type );
|
|
|
|
dlg.SetCustomizeHook( saveAsHook );
|
|
|
|
#else
|
|
|
|
dlg.SetExtraControlCreator( &SYMBOL_LEGACYFILEDLG_SAVE_AS::Create );
|
|
|
|
#endif
|
2020-12-29 18:59:48 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
fn = dlg.GetPath();
|
|
|
|
|
2020-07-18 14:25:29 +00:00
|
|
|
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
|
|
|
|
|
2020-05-15 13:25:11 +00:00
|
|
|
if( fn.GetExt().IsEmpty() )
|
2020-02-13 13:39:52 +00:00
|
|
|
fn.SetExt( KiCadSymbolLibFileExtension );
|
2020-12-29 18:59:48 +00:00
|
|
|
|
2022-06-12 02:59:59 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 7 )
|
|
|
|
type = saveAsHook.GetOption();
|
|
|
|
#else
|
|
|
|
const SYMBOL_LEGACYFILEDLG_SAVE_AS* sah =
|
|
|
|
dynamic_cast<const SYMBOL_LEGACYFILEDLG_SAVE_AS*>( dlg.GetExtraControl() );
|
2020-12-29 18:59:48 +00:00
|
|
|
wxCHECK( sah, false );
|
|
|
|
|
|
|
|
type = sah->GetOption();
|
2022-06-12 02:59:59 +00:00
|
|
|
#endif
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-13 09:55:05 +00:00
|
|
|
fn = prj.SchSymbolLibTable()->GetFullURI( aLibrary );
|
2020-04-16 16:43:50 +00:00
|
|
|
fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
// Verify the user has write privileges before attempting to save the library file.
|
2020-06-04 17:25:36 +00:00
|
|
|
if( !aNewFile && m_libMgr->IsLibraryReadOnly( aLibrary ) )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-05-16 21:25:13 +00:00
|
|
|
// Copy .kicad_symb file to .bak.
|
2017-11-13 14:15:10 +00:00
|
|
|
if( !backupFile( fn, "bak" ) )
|
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath(), fileType ) )
|
2011-11-11 20:10:24 +00:00
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Failed to save changes to symbol library file '%s'." ),
|
2017-11-13 14:15:10 +00:00
|
|
|
fn.GetFullPath() );
|
2021-06-16 22:35:00 +00:00
|
|
|
DisplayErrorMessage( this, _( "Error Saving Library" ), msg );
|
2017-11-13 13:58:39 +00:00
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 22:13:10 +00:00
|
|
|
if( !aNewFile )
|
2020-12-29 18:59:48 +00:00
|
|
|
{
|
2017-11-13 22:13:10 +00:00
|
|
|
m_libMgr->ClearLibraryModified( aLibrary );
|
2020-12-29 18:59:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool resyncLibTree = false;
|
|
|
|
wxString originalLibNickname = getTargetLib();
|
2021-01-31 22:58:34 +00:00
|
|
|
wxString forceRefresh;
|
2020-12-29 18:59:48 +00:00
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2022-06-12 02:59:59 +00:00
|
|
|
case SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY:
|
2020-12-29 18:59:48 +00:00
|
|
|
resyncLibTree = replaceLibTableEntry( originalLibNickname, fn.GetFullPath() );
|
2021-01-31 22:58:34 +00:00
|
|
|
forceRefresh = originalLibNickname;
|
2020-12-29 18:59:48 +00:00
|
|
|
break;
|
|
|
|
|
2022-06-12 02:59:59 +00:00
|
|
|
case SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY:
|
2020-12-29 18:59:48 +00:00
|
|
|
resyncLibTree = addLibTableEntry( fn.GetFullPath() );
|
|
|
|
break;
|
|
|
|
|
2022-06-12 02:59:59 +00:00
|
|
|
case SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY:
|
2020-12-29 18:59:48 +00:00
|
|
|
resyncLibTree = addLibTableEntry( fn.GetFullPath(), PROJECT_LIB_TABLE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( resyncLibTree )
|
|
|
|
{
|
2021-03-17 14:53:27 +00:00
|
|
|
FreezeLibraryTree();
|
2022-02-27 11:54:12 +00:00
|
|
|
SyncLibraries( true, false, forceRefresh );
|
2021-03-17 14:53:27 +00:00
|
|
|
ThawLibraryTree();
|
2020-12-29 18:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 22:13:10 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
ClearMsgPanel();
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Symbol library file '%s' saved." ), fn.GetFullPath() );
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2017-03-04 19:49:55 +00:00
|
|
|
|
2013-02-07 17:35:37 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation )
|
2017-11-13 09:55:05 +00:00
|
|
|
{
|
2020-12-11 22:44:10 +00:00
|
|
|
wxString msg, msg2;
|
|
|
|
bool doSave = true;
|
|
|
|
int dirtyCount = 0;
|
|
|
|
bool applyToAll = false;
|
|
|
|
bool retv = true;
|
2017-11-13 09:55:05 +00:00
|
|
|
|
2020-12-11 22:44:10 +00:00
|
|
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
2017-11-13 09:55:05 +00:00
|
|
|
{
|
2018-08-01 13:36:42 +00:00
|
|
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
|
|
|
dirtyCount++;
|
|
|
|
}
|
2017-11-13 09:55:05 +00:00
|
|
|
|
2020-12-11 22:44:10 +00:00
|
|
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
2018-08-01 13:36:42 +00:00
|
|
|
{
|
|
|
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
2018-02-16 10:27:43 +00:00
|
|
|
{
|
2018-08-01 13:36:42 +00:00
|
|
|
if( aRequireConfirmation && !applyToAll )
|
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Save changes to '%s' before closing?" ), libNickname );
|
2018-08-01 13:36:42 +00:00
|
|
|
|
2018-08-01 23:06:12 +00:00
|
|
|
switch( UnsavedChangesDialog( this, msg, dirtyCount > 1 ? &applyToAll : nullptr ) )
|
2018-08-01 13:36:42 +00:00
|
|
|
{
|
|
|
|
case wxID_YES: doSave = true; break;
|
|
|
|
case wxID_NO: doSave = false; break;
|
|
|
|
default:
|
|
|
|
case wxID_CANCEL: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( doSave )
|
|
|
|
{
|
2018-08-01 23:06:12 +00:00
|
|
|
// If saving under existing name fails then do a Save As..., and if that
|
|
|
|
// fails then cancel close action.
|
2023-09-23 11:24:42 +00:00
|
|
|
if( m_libMgr->IsLibraryReadOnly( libNickname ) )
|
2020-12-11 22:44:10 +00:00
|
|
|
{
|
2021-11-08 23:42:09 +00:00
|
|
|
msg.Printf( _( "Symbol library '%s' is not writable." ), libNickname );
|
2020-12-11 22:44:10 +00:00
|
|
|
msg2 = _( "You must save to a different location." );
|
|
|
|
|
|
|
|
if( dirtyCount == 1 )
|
|
|
|
{
|
|
|
|
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) != wxID_OK )
|
|
|
|
{
|
|
|
|
retv = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_infoBar->Dismiss();
|
|
|
|
m_infoBar->ShowMessageFor( msg + wxS( " " ) + msg2,
|
|
|
|
2000, wxICON_EXCLAMATION );
|
|
|
|
|
|
|
|
while( m_infoBar->IsShown() )
|
|
|
|
wxSafeYield();
|
|
|
|
|
|
|
|
retv = false;
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-22 11:48:28 +00:00
|
|
|
}
|
2023-09-23 11:24:42 +00:00
|
|
|
else if( saveLibrary( libNickname, false ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-16 21:25:13 +00:00
|
|
|
|
|
|
|
if( !saveLibrary( libNickname, true ) )
|
2020-10-29 12:22:38 +00:00
|
|
|
retv = false;
|
2018-08-01 13:36:42 +00:00
|
|
|
}
|
2017-11-13 09:55:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:17:36 +00:00
|
|
|
UpdateTitle();
|
2020-10-29 12:22:38 +00:00
|
|
|
return retv;
|
2017-11-13 09:55:05 +00:00
|
|
|
}
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
|
2021-08-20 19:45:57 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateSymbolMsgPanelInfo()
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
|
|
|
EDA_DRAW_FRAME::ClearMsgPanel();
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( !m_symbol )
|
2020-10-31 01:27:16 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
wxString msg = m_symbol->GetName();
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
AppendMsgPanel( _( "Name" ), UnescapeString( msg ), 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_symbol->IsAlias() )
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL_SPTR parent = m_symbol->GetParent().lock();
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
msg = parent ? parent->GetName() : _( "Undefined!" );
|
2021-06-30 10:53:04 +00:00
|
|
|
AppendMsgPanel( _( "Parent" ), UnescapeString( msg ), 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
|
|
|
|
msg = UnitLetter[m_unit];
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Unit" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
if( m_convert > 1 )
|
|
|
|
msg = _( "Convert" );
|
|
|
|
else
|
|
|
|
msg = _( "Normal" );
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Body" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_symbol->IsPower() )
|
2020-10-31 01:27:16 +00:00
|
|
|
msg = _( "Power Symbol" );
|
|
|
|
else
|
|
|
|
msg = _( "Symbol" );
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Type" ), msg, 8 );
|
2021-06-15 12:31:28 +00:00
|
|
|
AppendMsgPanel( _( "Description" ), m_symbol->GetDescription(), 8 );
|
|
|
|
AppendMsgPanel( _( "Keywords" ), m_symbol->GetKeyWords() );
|
|
|
|
AppendMsgPanel( _( "Datasheet" ), m_symbol->GetDatasheetField().GetText() );
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|