2011-10-28 09:43:37 -04:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-02-03 15:29:41 +01:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 14:07:43 -04:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-28 09:43:37 -04: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 19:30:32 +01:00
|
|
|
#include <pgm_base.h>
|
2024-10-13 16:32:20 +08:00
|
|
|
#include <clipboard.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <confirm.h>
|
2024-04-27 22:57:24 +03:00
|
|
|
#include <kidialog.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 23:25:54 +01: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 09:24:55 -04:00
|
|
|
#include <symbol_library.h>
|
2012-01-22 22:33:36 -06:00
|
|
|
#include <template_fieldnames.h>
|
2012-09-28 19:47:41 +02:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2017-09-15 10:17:44 -04:00
|
|
|
#include <symbol_lib_table.h>
|
2022-09-15 23:06:23 -04:00
|
|
|
#include <lib_symbol_library_manager.h>
|
2018-07-27 21:47:51 +01:00
|
|
|
#include <symbol_tree_pane.h>
|
2022-07-09 20:44:49 -06:00
|
|
|
#include <project/project_file.h>
|
2018-07-27 21:47:51 +01:00
|
|
|
#include <widgets/lib_tree.h>
|
2023-12-24 00:31:24 +00:00
|
|
|
#include <sch_io/kicad_legacy/sch_io_kicad_legacy.h>
|
|
|
|
#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>
|
2021-06-14 14:00:08 -04:00
|
|
|
#include <dialogs/dialog_lib_new_symbol.h>
|
2021-08-03 01:11:11 +01:00
|
|
|
#include <eda_list_dialog.h>
|
2019-04-08 01:11:06 +01:00
|
|
|
#include <wx/clipbrd.h>
|
2021-05-01 09:50:29 +02:00
|
|
|
#include <wx/filedlg.h>
|
2021-06-03 08:11:15 -04:00
|
|
|
#include <wx/log.h>
|
2023-09-27 23:04:53 -04:00
|
|
|
#include <project_sch.h>
|
2021-07-29 10:56:22 +01:00
|
|
|
#include <string_utils.h>
|
2022-06-11 22:59:59 -04:00
|
|
|
#include "symbol_saveas_type.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2022-06-11 22:59:59 -04:00
|
|
|
#include <widgets/symbol_filedlg_save_as.h>
|
2024-11-26 12:48:36 +00:00
|
|
|
#include <io/kicad/kicad_io_utils.h>
|
2020-12-29 13:59:48 -05:00
|
|
|
|
|
|
|
|
2023-09-12 16:17:36 +01:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateTitle()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-04-13 21:02:35 +01:00
|
|
|
wxString title;
|
2017-10-06 14:07:43 -04:00
|
|
|
|
2021-12-22 14:27:38 +00:00
|
|
|
if( GetCurSymbol() && IsSymbolFromSchematic() )
|
2020-08-31 11:06:23 -04:00
|
|
|
{
|
2021-06-20 22:46:41 +01: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 16:39:40 +01:00
|
|
|
title += UnescapeString( GetCurSymbol()->GetLibId().Format() );
|
2021-06-20 22:46:41 +01:00
|
|
|
|
|
|
|
if( m_libMgr && m_libMgr->IsLibraryReadOnly( GetCurLib() ) )
|
|
|
|
title += wxS( " " ) + _( "[Read Only Library]" );
|
2020-08-31 11:06:23 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-20 22:46:41 +01:00
|
|
|
title = _( "[no symbol loaded]" );
|
2020-08-31 11:06:23 -04:00
|
|
|
}
|
2020-05-16 17:25:13 -04:00
|
|
|
|
2021-06-20 22:46:41 +01:00
|
|
|
title += wxT( " \u2014 " ) + _( "Symbol Editor" );
|
2016-09-26 13:15:33 -04: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 14:07:43 -04:00
|
|
|
wxString selectedLib = aLibrary;
|
2011-08-12 13:43:16 -04:00
|
|
|
|
2017-10-06 14:07:43 -04:00
|
|
|
if( selectedLib.empty() )
|
|
|
|
selectedLib = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !selectedLib.empty() )
|
|
|
|
SetCurLib( selectedLib );
|
2011-08-12 13:43:16 -04:00
|
|
|
|
2023-09-12 16:17:36 +01:00
|
|
|
UpdateTitle();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 13:43:16 -04:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveCurrentSymbol()
|
2011-05-28 20:51:32 +02:00
|
|
|
{
|
2021-06-15 08:31:28 -04:00
|
|
|
if( GetCurSymbol() )
|
2018-07-10 15:33:04 +01:00
|
|
|
{
|
2022-04-11 22:14:54 +01:00
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
|
2018-08-11 21:46:03 +01:00
|
|
|
|
2022-04-11 22:14:54 +01: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 21:46:03 +01:00
|
|
|
{
|
2023-09-23 12:24:42 +01:00
|
|
|
const wxString& libName = GetCurSymbol()->GetLibId().GetLibNickname();
|
2022-04-11 22:14:54 +01:00
|
|
|
|
2023-09-23 12:24:42 +01:00
|
|
|
if( m_libMgr->IsLibraryReadOnly( libName ) )
|
2022-04-11 22:14:54 +01:00
|
|
|
{
|
2023-09-23 12:24:42 +01: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 22:14:54 +01:00
|
|
|
}
|
2018-08-11 21:46:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-10 15:33:04 +01:00
|
|
|
|
2018-08-11 21:46:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aBodyStyle )
|
2018-08-11 21:46:03 +01:00
|
|
|
{
|
2023-01-19 22:45:46 -05:00
|
|
|
LIB_ID libId = aLibId;
|
|
|
|
|
2023-02-26 23:37:05 +01:00
|
|
|
// Some libraries can't be edited, so load the underlying chosen symbol
|
2023-01-19 22:45:46 -05:00
|
|
|
if( SYMBOL_LIB_TABLE_ROW* lib = m_libMgr->GetLibrary( aLibId.GetLibNickname() ) )
|
|
|
|
{
|
2023-02-26 23:37:05 +01:00
|
|
|
if( lib->SchLibType() == SCH_IO_MGR::SCH_DATABASE
|
2023-10-01 09:23:24 +11:00
|
|
|
|| lib->SchLibType() == SCH_IO_MGR::SCH_CADSTAR_ARCHIVE
|
|
|
|
|| lib->SchLibType() == SCH_IO_MGR::SCH_HTTP )
|
|
|
|
|
2023-01-19 22:45:46 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-09-27 23:04:53 -04:00
|
|
|
LIB_SYMBOL* readOnlySym = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( aLibId );
|
2023-01-19 22:45:46 -05:00
|
|
|
|
2023-02-26 23:37:05 +01:00
|
|
|
if( readOnlySym && readOnlySym->GetSourceLibId().IsValid() )
|
|
|
|
libId = readOnlySym->GetSourceLibId();
|
2023-01-19 22:45:46 -05:00
|
|
|
}
|
|
|
|
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 22:14:54 +01:00
|
|
|
if( GetCurSymbol() && !IsSymbolFromSchematic()
|
2023-01-19 22:45:46 -05:00
|
|
|
&& GetCurSymbol()->GetLibId() == libId
|
2022-04-11 22:14:54 +01:00
|
|
|
&& GetUnit() == aUnit
|
2024-01-26 16:16:13 +00:00
|
|
|
&& GetBodyStyle() == aBodyStyle )
|
2019-05-08 19:56:03 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-11 22:14:54 +01:00
|
|
|
if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() )
|
2018-08-11 21:46:03 +01:00
|
|
|
{
|
2021-10-01 21:49:14 +01:00
|
|
|
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ),
|
|
|
|
[&]() -> bool
|
|
|
|
{
|
|
|
|
return saveCurrentSymbol();
|
|
|
|
} ) )
|
2018-08-11 21:46:03 +01:00
|
|
|
{
|
2018-07-10 15:33:04 +01:00
|
|
|
return false;
|
2018-08-11 21:46:03 +01:00
|
|
|
}
|
2018-07-10 15:33:04 +01:00
|
|
|
}
|
2011-05-28 20:51:32 +02:00
|
|
|
|
2023-01-19 22:45:46 -05:00
|
|
|
SelectActiveLibrary( libId.GetLibNickname() );
|
2021-10-01 22:45:49 +01:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( LoadSymbolFromCurrentLib( libId.GetLibItemName(), aUnit, aBodyStyle ) )
|
2021-10-01 22:45:49 +01:00
|
|
|
{
|
2023-01-19 22:45:46 -05:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( libId );
|
|
|
|
m_treePane->GetLibTree()->ExpandLibId( libId );
|
2021-10-01 22:45:49 +01:00
|
|
|
|
2023-01-19 22:45:46 -05:00
|
|
|
m_centerItemOnIdle = libId;
|
2021-10-01 22:45:49 +01:00
|
|
|
Bind( wxEVT_IDLE, &SYMBOL_EDIT_FRAME::centerItemIdleHandler, this );
|
2023-05-31 13:37:58 -07:00
|
|
|
setSymWatcher( &libId );
|
2021-10-01 22:45:49 +01:00
|
|
|
|
|
|
|
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 20:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-25 20:06:08 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadSymbolFromCurrentLib( const wxString& aSymbolName, int aUnit,
|
2024-01-26 16:16:13 +00:00
|
|
|
int aBodyStyle )
|
2011-05-28 20:51:32 +02:00
|
|
|
{
|
2025-01-25 20:06:08 +00:00
|
|
|
LIB_SYMBOL* symbol = nullptr;
|
2017-10-06 14:07:43 -04:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2025-01-25 20:06:08 +00:00
|
|
|
symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( GetCurLib(), aSymbolName );
|
2017-10-06 14:07:43 -04:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-06-26 12:33:37 +01:00
|
|
|
msg.Printf( _( "Error loading symbol %s from library '%s'." ),
|
2025-01-25 20:06:08 +00:00
|
|
|
aSymbolName,
|
2021-06-16 23:35:00 +01:00
|
|
|
GetCurLib() );
|
2017-10-06 14:07:43 -04:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-01-25 20:06:08 +00:00
|
|
|
if( !symbol || !LoadOneLibrarySymbolAux( symbol, GetCurLib(), aUnit, aBodyStyle ) )
|
2011-05-28 20:51:32 +02:00
|
|
|
return false;
|
|
|
|
|
2018-01-23 12:15:19 +01:00
|
|
|
// Enable synchronized pin edit mode for symbols with interchangeable units
|
2022-04-04 16:56:14 +01:00
|
|
|
m_SyncPinEdit = GetCurSymbol()->IsMulti() && !GetCurSymbol()->UnitsLocked();
|
2011-05-28 20:51:32 +02:00
|
|
|
|
2020-07-13 12:21:40 +01:00
|
|
|
ClearUndoRedoList();
|
2023-06-26 23:16:51 +01:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen );
|
2024-01-26 16:16:13 +00:00
|
|
|
SetShowDeMorgan( GetCurSymbol()->Flatten()->HasAlternateBodyStyle() );
|
2011-05-28 20:51:32 +02:00
|
|
|
|
2017-07-19 11:34:55 -06:00
|
|
|
if( aUnit > 0 )
|
2019-05-06 13:32:51 +01:00
|
|
|
RebuildSymbolUnitsList();
|
2017-07-19 11:34:55 -06:00
|
|
|
|
2011-05-28 20:51:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-08-31 11:06:23 -04:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux( LIB_SYMBOL* aEntry, const wxString& aLibrary,
|
2024-01-26 16:16:13 +00:00
|
|
|
int aUnit, int aBodyStyle )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-08-31 11:06:23 -04:00
|
|
|
bool rebuildMenuAndToolbar = false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2017-10-06 14:07:43 -04: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 14:54:14 -04:00
|
|
|
if( aEntry->GetName().IsEmpty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2021-06-29 00:44:07 +01:00
|
|
|
wxLogWarning( "Symbol in library '%s' has empty name field.", aLibrary );
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-26 23:16:51 +01:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive );
|
2020-11-03 09:32:35 -05:00
|
|
|
|
2020-08-31 11:06:23 -04:00
|
|
|
// Symbols from the schematic are edited in place and not managed by the library manager.
|
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
2021-06-15 08:31:28 -04:00
|
|
|
delete m_symbol;
|
|
|
|
m_symbol = nullptr;
|
2020-08-31 11:06:23 -04:00
|
|
|
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
delete screen;
|
|
|
|
SetScreen( m_dummyScreen );
|
|
|
|
m_isSymbolFromSchematic = false;
|
|
|
|
rebuildMenuAndToolbar = true;
|
|
|
|
}
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
LIB_SYMBOL* lib_symbol = m_libMgr->GetBufferedSymbol( aEntry->GetName(), aLibrary );
|
2021-06-10 14:51:46 -04:00
|
|
|
wxCHECK( lib_symbol, false );
|
2018-09-04 19:49:49 +01:00
|
|
|
|
2018-11-08 21:26:01 +00:00
|
|
|
m_unit = aUnit > 0 ? aUnit : 1;
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle = aBodyStyle > 0 ? aBodyStyle : 1;
|
2018-09-04 19:49:49 +01:00
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
// The buffered screen for the symbol
|
2021-06-15 08:31:28 -04:00
|
|
|
SCH_SCREEN* symbol_screen = m_libMgr->GetScreen( lib_symbol->GetName(), aLibrary );
|
2019-02-08 14:34:53 +00:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
SetScreen( symbol_screen );
|
|
|
|
SetCurSymbol( new LIB_SYMBOL( *lib_symbol ), true );
|
2017-11-12 18:55:20 +01: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 15:28:54 -05:00
|
|
|
|
2020-08-31 11:06:23 -04:00
|
|
|
if( rebuildMenuAndToolbar )
|
|
|
|
{
|
|
|
|
ReCreateMenuBar();
|
2025-02-20 02:53:15 +00:00
|
|
|
RecreateToolbars();
|
2020-08-31 11:06:23 -04:00
|
|
|
GetInfoBar()->Dismiss();
|
|
|
|
}
|
|
|
|
|
2023-09-12 16:17:36 +01:00
|
|
|
UpdateTitle();
|
2019-05-06 13:32:51 +01:00
|
|
|
RebuildSymbolUnitsList();
|
2024-01-26 16:16:13 +00:00
|
|
|
SetShowDeMorgan( GetCurSymbol()->HasAlternateBodyStyle() );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2022-01-05 16:50:24 -08:00
|
|
|
ClearUndoRedoList();
|
|
|
|
|
2023-05-31 13:37:58 -07:00
|
|
|
if( !IsSymbolFromSchematic() )
|
|
|
|
{
|
|
|
|
LIB_ID libId = GetCurSymbol()->GetLibId();
|
|
|
|
setSymWatcher( &libId );
|
|
|
|
}
|
2023-02-16 08:17:00 -05:00
|
|
|
|
2023-06-18 17:17:16 +02:00
|
|
|
// Let tools add things to the view if necessary
|
|
|
|
if( m_toolManager )
|
|
|
|
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
|
|
|
|
|
|
|
|
GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
|
|
|
|
|
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 15:28:54 -05:00
|
|
|
// Display the document information based on the entry selected just in
|
|
|
|
// case the entry is an alias.
|
2021-08-20 15:45:57 -04:00
|
|
|
UpdateMsgPanel();
|
2017-11-13 11:38:20 +01: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 18:55:20 +01:00
|
|
|
{
|
2018-02-16 11:27:43 +01:00
|
|
|
saveAllLibraries( false );
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-20 12:05:31 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::CreateNewSymbol( const wxString& aInheritFrom )
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2023-06-26 23:16:51 +01:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2023-08-20 12:05:31 -04:00
|
|
|
wxArrayString symbolNames;
|
2017-11-13 12:30:03 +01:00
|
|
|
wxString lib = getTargetLib();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
{
|
|
|
|
lib = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
return;
|
|
|
|
}
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2025-01-25 18:50:09 +00:00
|
|
|
const auto validator =
|
|
|
|
[&]( wxString newName ) -> bool
|
2023-09-05 22:07:51 +01:00
|
|
|
{
|
|
|
|
if( newName.IsEmpty() )
|
|
|
|
{
|
2024-01-12 14:51:32 -08:00
|
|
|
wxMessageBox( _( "Symbol must have a name." ) );
|
2023-09-05 22:07:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2025-01-25 18:50:09 +00:00
|
|
|
if( !lib.empty() && m_libMgr->SymbolNameInUse( newName, lib ) )
|
2023-09-05 22:07:51 +01:00
|
|
|
{
|
2025-01-25 18:50:09 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "Symbol '%s' already exists in library '%s'." ),
|
|
|
|
UnescapeString( newName ),
|
|
|
|
lib );
|
|
|
|
|
|
|
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ),
|
|
|
|
wxOK | wxCANCEL | wxICON_WARNING );
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
return errorDlg.ShowModal() == wxID_OK;
|
|
|
|
}
|
2021-06-10 14:51:46 -04:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
return true;
|
2024-12-18 22:43:55 +08:00
|
|
|
};
|
|
|
|
|
2024-12-18 23:49:40 +08:00
|
|
|
wxArrayString symbolNamesInLib;
|
|
|
|
m_libMgr->GetSymbolNames( lib, symbolNamesInLib );
|
|
|
|
|
|
|
|
DIALOG_LIB_NEW_SYMBOL dlg( this, symbolNamesInLib, aInheritFrom, validator );
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
2021-07-28 09:30:25 -07:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2021-07-28 09:30:25 -07:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
wxString name = dlg.GetName();
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
LIB_SYMBOL new_symbol( name ); // do not create symbol on the heap, it will be buffered soon
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2019-11-06 14:15:42 -05:00
|
|
|
wxString parentSymbolName = dlg.GetParentSymbolName();
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2019-11-06 14:15:42 -05:00
|
|
|
if( parentSymbolName.IsEmpty() )
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2021-06-10 14:51:46 -04:00
|
|
|
new_symbol.GetReferenceField().SetText( dlg.GetReference() );
|
|
|
|
new_symbol.SetUnitCount( dlg.GetUnitCount() );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
// Initialize new_symbol.m_TextInside member:
|
2019-11-06 14:15:42 -05: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 14:51:46 -04:00
|
|
|
new_symbol.SetPinNameOffset( dlg.GetPinTextPosition() );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
if( new_symbol.GetPinNameOffset() == 0 )
|
|
|
|
new_symbol.SetPinNameOffset( 1 );
|
2019-11-06 14:15:42 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 14:51:46 -04:00
|
|
|
new_symbol.SetPinNameOffset( 0 );
|
2019-11-06 14:15:42 -05:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:51:46 -04: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() );
|
2023-06-24 22:03:06 -04:00
|
|
|
new_symbol.SetExcludedFromBOM( !dlg.GetIncludeInBom() );
|
|
|
|
new_symbol.SetExcludedFromBoard( !dlg.GetIncludeOnBoard() );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
|
|
|
if( dlg.GetUnitCount() < 2 )
|
2021-06-10 14:51:46 -04:00
|
|
|
new_symbol.LockUnits( false );
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
new_symbol.SetHasAlternateBodyStyle( dlg.GetAlternateBodyStyle() );
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-01-25 20:06:08 +00:00
|
|
|
LIB_SYMBOL* parent = m_libMgr->GetSymbol( parentSymbolName, lib );
|
2019-11-06 14:15:42 -05:00
|
|
|
wxCHECK( parent, /* void */ );
|
2021-06-10 14:51:46 -04:00
|
|
|
new_symbol.SetParent( parent );
|
2020-05-30 10:33:05 -04:00
|
|
|
|
|
|
|
// Inherit the parent mandatory field attributes.
|
2025-02-08 13:45:57 +00:00
|
|
|
for( FIELD_T fieldId : MANDATORY_FIELDS )
|
2020-05-30 10:33:05 -04:00
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
SCH_FIELD* field = new_symbol.GetField( fieldId );
|
|
|
|
SCH_FIELD* parentField = parent->GetField( fieldId );
|
2020-05-30 10:33:05 -04:00
|
|
|
|
|
|
|
*field = *parentField;
|
|
|
|
|
2025-01-22 14:26:57 +00:00
|
|
|
switch( fieldId )
|
2020-11-11 17:33:53 +00:00
|
|
|
{
|
2025-02-08 13:45:57 +00:00
|
|
|
case FIELD_T::REFERENCE:
|
2020-11-11 17:33:53 +00:00
|
|
|
// parent's reference already copied
|
|
|
|
break;
|
|
|
|
|
2025-02-08 13:45:57 +00:00
|
|
|
case FIELD_T::VALUE:
|
2022-08-20 17:43:20 -04:00
|
|
|
if( parent->IsPower() )
|
|
|
|
field->SetText( name );
|
2020-11-11 17:33:53 +00:00
|
|
|
break;
|
|
|
|
|
2025-02-08 13:45:57 +00:00
|
|
|
case FIELD_T::FOOTPRINT:
|
|
|
|
case FIELD_T::DATASHEET:
|
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;
|
2025-02-08 13:45:57 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2020-11-11 17:33:53 +00:00
|
|
|
}
|
2020-05-30 10:33:05 -04:00
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
field->SetParent( &new_symbol );
|
2020-05-30 10:33:05 -04:00
|
|
|
}
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
m_libMgr->UpdateSymbol( &new_symbol, lib );
|
2018-08-25 13:21:09 +01:00
|
|
|
SyncLibraries( false );
|
2021-06-15 08:31:28 -04:00
|
|
|
LoadSymbol( name, lib, 1 );
|
2022-04-05 14:37:38 +01: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 10:13:43 +02:00
|
|
|
// and a derived symbol inherits its parent body.
|
|
|
|
if( !new_symbol.GetParent().lock() )
|
|
|
|
SetShowDeMorgan( dlg.GetAlternateBodyStyle() );
|
|
|
|
else
|
2024-01-26 16:16:13 +00:00
|
|
|
SetShowDeMorgan( new_symbol.HasAlternateBodyStyle() );
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::Save()
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2023-04-14 17:12:56 +01:00
|
|
|
wxString libName;
|
2020-12-11 22:44:10 +00:00
|
|
|
|
2024-06-08 14:00:18 +01:00
|
|
|
if( IsLibraryTreeShown() )
|
2023-09-14 18:35:19 +03:00
|
|
|
libName = GetTreeLIBID().GetUniStringLibNickname();
|
2023-04-14 17:12:56 +01:00
|
|
|
|
|
|
|
if( libName.empty() )
|
|
|
|
{
|
|
|
|
saveCurrentSymbol();
|
2020-05-16 17:25:13 -04:00
|
|
|
}
|
2023-04-14 17:12:56 +01:00
|
|
|
else if( m_libMgr->IsLibraryReadOnly( libName ) )
|
2018-07-27 11:46:09 +01:00
|
|
|
{
|
2023-04-14 17:12:56 +01: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 17:12:56 +01:00
|
|
|
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) == wxID_OK )
|
|
|
|
saveLibrary( libName, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveLibrary( libName, false );
|
2018-07-27 11:46:09 +01:00
|
|
|
}
|
|
|
|
|
2024-06-08 14:00:18 +01:00
|
|
|
if( IsLibraryTreeShown() )
|
2023-04-14 17:12:56 +01:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
|
|
|
|
2023-09-12 16:17:36 +01:00
|
|
|
UpdateTitle();
|
2018-07-27 11:46:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-27 11:28:52 -05:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveLibraryAs()
|
2018-07-27 11:46:09 +01:00
|
|
|
{
|
2021-02-07 18:21:38 -05:00
|
|
|
const wxString& libName = GetTargetLibId().GetLibNickname();
|
2020-12-27 11:28:52 -05:00
|
|
|
|
2024-07-19 22:11:23 +01:00
|
|
|
if( !libName.IsEmpty() )
|
|
|
|
{
|
|
|
|
saveLibrary( libName, true );
|
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
|
|
|
}
|
2020-12-27 11:28:52 -05:00
|
|
|
}
|
|
|
|
|
2021-01-31 22:58:34 +00:00
|
|
|
|
2024-10-12 21:27:57 -06:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveSymbolCopyAs( bool aOpenCopy )
|
2020-12-27 11:28:52 -05:00
|
|
|
{
|
2024-10-12 21:27:57 -06:00
|
|
|
saveSymbolCopyAs( aOpenCopy );
|
2017-11-13 23:13:10 +01:00
|
|
|
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
/**
|
|
|
|
* Get a list of all the symbols in the parental chain of a symbol,
|
|
|
|
* with the "leaf" symbol at the start and the "rootiest" symbol at the end.
|
|
|
|
*
|
|
|
|
* If the symbol is not an alias, the list will contain only the symbol itself.
|
|
|
|
*/
|
|
|
|
static std::vector<LIB_SYMBOL_SPTR> GetParentChain( const LIB_SYMBOL& aSymbol )
|
|
|
|
{
|
|
|
|
std::vector<LIB_SYMBOL_SPTR> chain( { aSymbol.SharedPtr() } );
|
|
|
|
|
2025-01-25 20:06:08 +00:00
|
|
|
while( chain.back()->IsDerived() )
|
2024-10-13 08:49:22 +08:00
|
|
|
{
|
|
|
|
LIB_SYMBOL_SPTR parent = chain.back()->GetParent().lock();
|
|
|
|
chain.push_back( parent );
|
|
|
|
}
|
|
|
|
|
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-13 09:22:39 +08:00
|
|
|
/**
|
|
|
|
* Check if a planned overwrite would put a symbol into it's own inheritance chain.
|
|
|
|
* This causes infinite loops and other unpleasantness and makes not sense - inheritance
|
|
|
|
* must be acyclic.
|
|
|
|
*
|
|
|
|
* Returns a pair of bools:
|
|
|
|
* - first: true if the symbol would be saved into it's own ancestry
|
|
|
|
* - second: true if the symbol would be saved into it's own descendents
|
|
|
|
*/
|
|
|
|
static std::pair<bool, bool> CheckSavingIntoOwnInheritance( LIB_SYMBOL_LIBRARY_MANAGER& aLibMgr,
|
|
|
|
LIB_SYMBOL& aSymbol,
|
|
|
|
const wxString& aNewSymbolName,
|
|
|
|
const wxString& aNewLibraryName )
|
|
|
|
{
|
|
|
|
const wxString& oldLibraryName = aSymbol.GetLibId().GetLibNickname();
|
|
|
|
|
|
|
|
// Cannot be intersecting if in different libs
|
|
|
|
if( aNewLibraryName != oldLibraryName )
|
|
|
|
return { false, false };
|
|
|
|
|
|
|
|
// Or if the target symbol doesn't exist
|
2025-01-25 18:50:09 +00:00
|
|
|
if( !aLibMgr.SymbolNameInUse( aNewSymbolName, aNewLibraryName ) )
|
2024-10-13 09:22:39 +08:00
|
|
|
return { false, false };
|
|
|
|
|
|
|
|
bool inAncestry = false;
|
|
|
|
bool inDescendents = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
const std::vector<LIB_SYMBOL_SPTR> parentChainFromUs = GetParentChain( aSymbol );
|
|
|
|
|
|
|
|
// Ignore the leaf symbol (0) - that must match
|
|
|
|
for( size_t i = 1; i < parentChainFromUs.size(); ++i )
|
|
|
|
{
|
|
|
|
// Attempting to overwrite a symbol in the parental chain
|
|
|
|
if( parentChainFromUs[i]->GetName() == aNewSymbolName )
|
|
|
|
{
|
|
|
|
inAncestry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2025-01-25 20:06:08 +00:00
|
|
|
LIB_SYMBOL* targetSymbol = aLibMgr.GetSymbol( aNewSymbolName, aNewLibraryName );
|
2024-10-13 09:22:39 +08:00
|
|
|
const std::vector<LIB_SYMBOL_SPTR> parentChainFromTarget = GetParentChain( *targetSymbol );
|
|
|
|
const wxString oldSymbolName = aSymbol.GetName();
|
|
|
|
|
|
|
|
// Ignore the leaf symbol - it'll match if we're saving the symbol
|
|
|
|
// to the same name, and that would be OK
|
|
|
|
for( size_t i = 1; i < parentChainFromTarget.size(); ++i )
|
|
|
|
{
|
|
|
|
if( parentChainFromTarget[i]->GetName() == oldSymbolName )
|
|
|
|
{
|
|
|
|
inDescendents = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { inAncestry, inDescendents };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
/**
|
|
|
|
* Get a list of all the symbols in the parental chain of a symbol that have conflicts
|
2024-10-13 09:22:39 +08:00
|
|
|
* when transposed to a different library.
|
|
|
|
*
|
|
|
|
* This doesn't check for dangerous conflicts like saving into a symbol's own inheritance,
|
|
|
|
* this is just about which symbols will get overwritten if saved with these names.
|
2024-10-13 08:49:22 +08:00
|
|
|
*/
|
|
|
|
static std::vector<wxString> CheckForParentalChainConflicts( LIB_SYMBOL_LIBRARY_MANAGER& aLibMgr,
|
|
|
|
LIB_SYMBOL& aSymbol,
|
|
|
|
const wxString& newSymbolName,
|
|
|
|
const wxString& newLibraryName )
|
|
|
|
{
|
|
|
|
std::vector<wxString> conflicts;
|
2024-10-13 09:22:39 +08:00
|
|
|
const wxString& oldLibraryName = aSymbol.GetLibId().GetLibNickname();
|
2024-10-13 08:49:22 +08:00
|
|
|
|
|
|
|
if( newLibraryName == oldLibraryName )
|
|
|
|
{
|
|
|
|
// Saving into the same library - the only conflict could be the symbol itself
|
2025-01-25 18:50:09 +00:00
|
|
|
if( aLibMgr.SymbolNameInUse( newSymbolName, newLibraryName ) )
|
2024-10-13 08:49:22 +08:00
|
|
|
conflicts.push_back( newSymbolName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// In a different library, check the whole chain
|
|
|
|
const std::vector<LIB_SYMBOL_SPTR> parentChain = GetParentChain( aSymbol );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < parentChain.size(); ++i )
|
|
|
|
{
|
|
|
|
if( i == 0 )
|
|
|
|
{
|
|
|
|
// This is the leaf symbol which the user actually named
|
2025-01-25 18:50:09 +00:00
|
|
|
if( aLibMgr.SymbolNameInUse( newSymbolName, newLibraryName ) )
|
2024-10-13 08:49:22 +08:00
|
|
|
conflicts.push_back( newSymbolName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LIB_SYMBOL_SPTR chainSymbol = parentChain[i];
|
2025-01-25 18:50:09 +00:00
|
|
|
|
|
|
|
if( aLibMgr.SymbolNameInUse( chainSymbol->GetName(), newLibraryName ) )
|
2024-10-13 08:49:22 +08:00
|
|
|
conflicts.push_back( chainSymbol->GetName() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return conflicts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a class that handles state involved in saving a symbol copy as a new symbol.
|
|
|
|
*
|
|
|
|
* This isn't as simple as it sounds, because you also have to copy all the parent symbols
|
|
|
|
* (which is a chain affair).
|
|
|
|
*/
|
|
|
|
class SYMBOL_SAVE_AS_HANDLER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class CONFLICT_STRATEGY
|
|
|
|
{
|
|
|
|
// Just overwrite any existing symbols in the target library
|
|
|
|
OVERWRITE,
|
|
|
|
// Add a suffix until we find a name that doesn't conflict
|
|
|
|
RENAME,
|
|
|
|
// Could have a mode that asks for every one, be then we'll need a fancier
|
|
|
|
// SAVE_AS_DIALOG subdialog with Overwrite/Rename/Prompt/Cancel
|
|
|
|
// PROMPT
|
|
|
|
};
|
|
|
|
|
|
|
|
SYMBOL_SAVE_AS_HANDLER( LIB_SYMBOL_LIBRARY_MANAGER& aLibMgr, CONFLICT_STRATEGY aStrategy,
|
|
|
|
bool aValueFollowsName ) :
|
|
|
|
m_libMgr( aLibMgr ), m_strategy( aStrategy ), m_valueFollowsName( aValueFollowsName )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DoSave( LIB_SYMBOL& symbol, const wxString& aNewSymName, const wxString& aNewLibName )
|
|
|
|
{
|
|
|
|
std::vector<LIB_SYMBOL_SPTR> parentChain;
|
|
|
|
// If we're saving into the same library, we don't need to check the parental chain
|
|
|
|
// because we can just keep the same parent symbol
|
|
|
|
if( aNewLibName == symbol.GetLibId().GetLibNickname().wx_str() )
|
|
|
|
parentChain.push_back( symbol.SharedPtr() );
|
|
|
|
else
|
|
|
|
parentChain = GetParentChain( symbol );
|
|
|
|
|
|
|
|
std::vector<wxString> newNames;
|
|
|
|
|
|
|
|
// Iterate backwards (i.e. from the root down)
|
|
|
|
for( int i = (int) parentChain.size() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
LIB_SYMBOL_SPTR& oldSymbol = parentChain[i];
|
|
|
|
|
|
|
|
LIB_SYMBOL new_symbol( *oldSymbol );
|
|
|
|
|
|
|
|
wxString newName;
|
|
|
|
if( i == 0 )
|
|
|
|
{
|
|
|
|
// This is the leaf symbol which the user actually named
|
|
|
|
newName = aNewSymName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Somewhere in the inheritance chain, use the conflict resolution strategy
|
|
|
|
newName = oldSymbol->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
newName = resolveConflict( newName, aNewLibName );
|
|
|
|
new_symbol.SetName( newName );
|
|
|
|
|
|
|
|
if( m_valueFollowsName )
|
|
|
|
new_symbol.GetValueField().SetText( newName );
|
|
|
|
|
|
|
|
if( i == (int) parentChain.size() - 1 )
|
|
|
|
{
|
|
|
|
// This is the root symbol
|
|
|
|
// Nothing extra to do, it's just a simple symbol with no parents
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get the buffered new copy in the new library (with the name we gave it)
|
2025-01-25 20:06:08 +00:00
|
|
|
LIB_SYMBOL* newParent = m_libMgr.GetSymbol( newNames.back(), aNewLibName );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
|
|
|
// We should have stored this already, why didn't we get it back?
|
|
|
|
wxASSERT( newParent );
|
|
|
|
new_symbol.SetParent( newParent );
|
|
|
|
}
|
|
|
|
|
|
|
|
newNames.push_back( newName );
|
|
|
|
m_libMgr.UpdateSymbol( &new_symbol, aNewLibName );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxString resolveConflict( const wxString& proposed, const wxString& aNewLibName ) const
|
|
|
|
{
|
|
|
|
switch( m_strategy )
|
|
|
|
{
|
|
|
|
case CONFLICT_STRATEGY::OVERWRITE:
|
|
|
|
{
|
|
|
|
// In an overwrite strategy, we don't care about conflicts
|
|
|
|
return proposed;
|
|
|
|
}
|
|
|
|
case CONFLICT_STRATEGY::RENAME:
|
|
|
|
{
|
|
|
|
// In a rename strategy, we need to find a name that doesn't conflict
|
|
|
|
int suffix = 1;
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
wxString newName = wxString::Format( "%s_%d", proposed, suffix );
|
|
|
|
|
2025-01-25 18:50:09 +00:00
|
|
|
if( !m_libMgr.SymbolNameInUse( newName, aNewLibName ) )
|
2024-10-13 08:49:22 +08:00
|
|
|
return newName;
|
|
|
|
|
|
|
|
++suffix;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// No default
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFAIL_MSG( "Invalid conflict strategy" );
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_SYMBOL_LIBRARY_MANAGER& m_libMgr;
|
|
|
|
CONFLICT_STRATEGY m_strategy;
|
|
|
|
bool m_valueFollowsName;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum SAVE_AS_IDS
|
|
|
|
{
|
|
|
|
ID_MAKE_NEW_LIBRARY = wxID_HIGHEST + 1,
|
|
|
|
ID_OVERWRITE_CONFLICTS,
|
|
|
|
ID_RENAME_CONFLICTS,
|
|
|
|
};
|
2022-04-19 19:09:19 +01:00
|
|
|
|
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
class SAVE_AS_DIALOG : public EDA_LIST_DIALOG
|
2018-07-24 22:16:59 +01:00
|
|
|
{
|
2023-09-05 22:07:51 +01:00
|
|
|
public:
|
2024-10-13 08:49:22 +08:00
|
|
|
using SymLibNameValidator =
|
|
|
|
std::function<int( const wxString& libName, const wxString& symbolName )>;
|
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
SAVE_AS_DIALOG( SYMBOL_EDIT_FRAME* aParent, const wxString& aSymbolName,
|
2024-10-13 08:49:22 +08:00
|
|
|
const wxString& aLibraryPreselect, SymLibNameValidator aValidator,
|
|
|
|
SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY& aConflictStrategy ) :
|
2023-09-05 22:07:51 +01:00
|
|
|
EDA_LIST_DIALOG( aParent, _( "Save Symbol As" ), false ),
|
2024-10-13 08:49:22 +08:00
|
|
|
m_validator( std::move( aValidator ) ), m_conflictStrategy( aConflictStrategy )
|
2023-09-05 22:07:51 +01:00
|
|
|
{
|
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
|
|
|
PROJECT_FILE& project = aParent->Prj().GetProjectFile();
|
2023-09-27 23:04:53 -04:00
|
|
|
SYMBOL_LIB_TABLE* tbl = PROJECT_SCH::SchSymbolLibTable( &Prj() );
|
2023-09-05 22:07:51 +01:00
|
|
|
std::vector<wxString> libNicknames = tbl->GetLogicalLibs();
|
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
headers.Add( _( "Nickname" ) );
|
|
|
|
headers.Add( _( "Description" ) );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
for( const wxString& nickname : libNicknames )
|
2022-07-09 20:44:49 -06:00
|
|
|
{
|
2023-09-05 22:07:51 +01:00
|
|
|
if( alg::contains( project.m_PinnedSymbolLibs, nickname )
|
2024-10-13 08:49:22 +08:00
|
|
|
|| alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
|
2023-09-05 22:07:51 +01:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2022-07-09 20:44:49 -06:00
|
|
|
}
|
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
for( const wxString& nickname : libNicknames )
|
2022-07-09 20:44:49 -06:00
|
|
|
{
|
2023-09-05 22:07:51 +01:00
|
|
|
if( !alg::contains( project.m_PinnedSymbolLibs, nickname )
|
|
|
|
&& !alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( nickname );
|
|
|
|
item.Add( tbl->GetDescription( nickname ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2022-07-09 20:44:49 -06:00
|
|
|
}
|
2020-12-25 11:55:45 +00:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
initDialog( headers, itemsToDisplay, aLibraryPreselect );
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
SetListLabel( _( "Save in library:" ) );
|
|
|
|
SetOKLabel( _( "Save" ) );
|
2019-12-02 23:33:45 +00:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
wxStaticText* label = new wxStaticText( this, wxID_ANY, _( "Name:" ) );
|
|
|
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
m_symbolNameCtrl = new wxTextCtrl( this, wxID_ANY, aSymbolName );
|
|
|
|
bNameSizer->Add( m_symbolNameCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
wxButton* newLibraryButton = new wxButton( this, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
|
|
|
|
m_ButtonsSizer->Prepend( 80, 20 );
|
|
|
|
m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
GetSizer()->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
Bind( wxEVT_BUTTON,
|
|
|
|
[this]( wxCommandEvent& )
|
|
|
|
{
|
|
|
|
EndModal( ID_MAKE_NEW_LIBRARY );
|
|
|
|
}, ID_MAKE_NEW_LIBRARY );
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
// Move nameTextCtrl to the head of the tab-order
|
|
|
|
if( GetChildren().DeleteObject( m_symbolNameCtrl ) )
|
|
|
|
GetChildren().Insert( m_symbolNameCtrl );
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
SetInitialFocus( m_symbolNameCtrl );
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
SetupStandardButtons();
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
Layout();
|
|
|
|
GetSizer()->Fit( this );
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
Centre();
|
|
|
|
}
|
2022-04-19 19:09:19 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
wxString GetSymbolName()
|
2022-04-19 19:09:19 +01:00
|
|
|
{
|
2023-09-05 22:07:51 +01:00
|
|
|
wxString symbolName = m_symbolNameCtrl->GetValue();
|
|
|
|
symbolName.Trim( true );
|
|
|
|
symbolName.Trim( false );
|
|
|
|
symbolName.Replace( " ", "_" );
|
|
|
|
return symbolName;
|
|
|
|
}
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
protected:
|
|
|
|
bool TransferDataFromWindow() override
|
|
|
|
{
|
2024-10-13 08:49:22 +08:00
|
|
|
int ret = m_validator( GetTextSelection(), GetSymbolName() );
|
|
|
|
|
|
|
|
if( ret == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( ret == ID_OVERWRITE_CONFLICTS )
|
|
|
|
m_conflictStrategy = SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY::OVERWRITE;
|
|
|
|
else if( ret == ID_RENAME_CONFLICTS )
|
|
|
|
m_conflictStrategy = SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY::RENAME;
|
|
|
|
|
|
|
|
return true;
|
2023-09-05 22:07:51 +01:00
|
|
|
}
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
private:
|
2024-10-13 08:49:22 +08:00
|
|
|
wxTextCtrl* m_symbolNameCtrl;
|
|
|
|
SymLibNameValidator m_validator;
|
|
|
|
SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY& m_conflictStrategy;
|
2023-09-05 22:07:51 +01:00
|
|
|
};
|
2018-07-24 22:16:59 +01:00
|
|
|
|
|
|
|
|
2024-10-12 21:27:57 -06:00
|
|
|
void SYMBOL_EDIT_FRAME::saveSymbolCopyAs( bool aOpenCopy )
|
2023-09-05 22:07:51 +01:00
|
|
|
{
|
|
|
|
LIB_SYMBOL* symbol = getTargetSymbol();
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
if( !symbol )
|
|
|
|
return;
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
LIB_ID old_lib_id = symbol->GetLibId();
|
|
|
|
wxString symbolName = old_lib_id.GetLibItemName();
|
|
|
|
wxString libraryName = old_lib_id.GetLibNickname();
|
2023-09-14 23:54:04 +01:00
|
|
|
bool valueFollowsName = symbol->GetValueField().GetText() == symbolName;
|
2023-09-05 22:07:51 +01:00
|
|
|
wxString msg;
|
|
|
|
bool done = false;
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
// This is the function that will be called when the user clicks OK in the dialog and checks
|
|
|
|
// if the proposed name has problems, and asks for clarification.
|
|
|
|
const auto dialogValidatorFunc =
|
|
|
|
[&]( const wxString& newLib, const wxString& newName ) -> int
|
|
|
|
{
|
|
|
|
if( newLib.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "A library must be specified." ) );
|
|
|
|
return wxID_CANCEL;
|
|
|
|
}
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
if( newName.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Symbol must have a name." ) );
|
|
|
|
return wxID_CANCEL;
|
|
|
|
}
|
2024-10-14 01:55:16 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
if( m_libMgr->IsLibraryReadOnly( newLib ) )
|
|
|
|
{
|
|
|
|
msg = wxString::Format( _( "Library '%s' is read-only. Choose a "
|
|
|
|
"different library to save the symbol '%s' to." ),
|
|
|
|
newLib, newName );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
return wxID_CANCEL;
|
|
|
|
}
|
2024-10-13 09:22:39 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
/**
|
|
|
|
* If we save over a symbol that is in the inheritance chain of the symbol we're
|
|
|
|
* saving, we'll end up with a circular inheritance chain, which is bad.
|
|
|
|
*/
|
|
|
|
const auto& [inAncestry, inDescendents] =
|
|
|
|
CheckSavingIntoOwnInheritance( *m_libMgr, *symbol, newName, newLib );
|
2024-10-13 09:22:39 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
if( inAncestry )
|
|
|
|
{
|
|
|
|
msg = wxString::Format( _( "Symbol '%s' cannot replace another symbol '%s' "
|
|
|
|
"that it descends from" ),
|
|
|
|
symbolName, newName );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
return wxID_CANCEL;
|
|
|
|
}
|
2024-10-13 09:22:39 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
if( inDescendents )
|
|
|
|
{
|
|
|
|
msg = wxString::Format( _( "Symbol '%s' cannot replace another symbol '%s' "
|
|
|
|
"that is a descendent of it." ),
|
|
|
|
symbolName, newName );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
return wxID_CANCEL;
|
|
|
|
}
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
const std::vector<wxString> conflicts =
|
|
|
|
CheckForParentalChainConflicts( *m_libMgr, *symbol, newName, newLib );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
if( conflicts.size() == 1 && conflicts.front() == newName )
|
|
|
|
{
|
|
|
|
// The simplest case is when the symbol itself has a conflict
|
|
|
|
msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'."
|
|
|
|
"Do you want to overwrite it?" ),
|
|
|
|
newName, newLib );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ),
|
|
|
|
wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
return errorDlg.ShowModal() == wxID_OK ? ID_OVERWRITE_CONFLICTS
|
|
|
|
: (int) wxID_CANCEL;
|
|
|
|
}
|
|
|
|
else if( !conflicts.empty() )
|
|
|
|
{
|
|
|
|
// If there are conflicts in the parental chain, we need to ask the user
|
|
|
|
// if they want to overwrite all of them.
|
|
|
|
// A more complex UI might allow the user to re-parent the symbol to an
|
|
|
|
// existing symbol in the target lib, or rename all the parents somehow.
|
|
|
|
msg = wxString::Format( _( "The following symbols in the inheritance chain of "
|
|
|
|
"'%s' already exist in library '%s':\n" ),
|
|
|
|
symbolName, newLib );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
for( const wxString& conflict : conflicts )
|
|
|
|
msg += wxString::Format( " %s\n", conflict );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
msg += _( "\nDo you want to overwrite all of them, or rename the new symbols?" );
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ),
|
|
|
|
wxYES_NO | wxCANCEL | wxICON_WARNING );
|
|
|
|
errorDlg.SetYesNoCancelLabels( _( "Overwrite All" ), _( "Rename All" ),
|
|
|
|
_( "Cancel" ) );
|
|
|
|
|
|
|
|
switch( errorDlg.ShowModal() )
|
|
|
|
{
|
|
|
|
case wxID_YES: return ID_OVERWRITE_CONFLICTS;
|
|
|
|
case wxID_NO: return ID_RENAME_CONFLICTS;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return wxID_CANCEL;
|
|
|
|
}
|
2024-10-13 08:49:22 +08:00
|
|
|
|
2025-03-03 12:05:03 +00:00
|
|
|
return wxID_OK;
|
|
|
|
};
|
2024-10-13 08:49:22 +08:00
|
|
|
|
|
|
|
auto strategy = SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY::OVERWRITE;
|
|
|
|
|
|
|
|
// Keep asking the user for a new name until they give a valid one or cancel the operation
|
2023-09-05 22:07:51 +01:00
|
|
|
while( !done )
|
|
|
|
{
|
2024-10-13 08:49:22 +08:00
|
|
|
SAVE_AS_DIALOG dlg( this, symbolName, libraryName, dialogValidatorFunc, strategy );
|
2023-09-05 22:07:51 +01:00
|
|
|
|
|
|
|
int ret = dlg.ShowModal();
|
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
switch( ret )
|
|
|
|
{
|
|
|
|
case wxID_CANCEL:
|
2019-12-13 16:51:59 -05:00
|
|
|
return;
|
2024-10-13 20:13:34 +01:00
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
case wxID_OK: // No conflicts
|
|
|
|
case ID_OVERWRITE_CONFLICTS:
|
|
|
|
case ID_RENAME_CONFLICTS:
|
2023-09-05 22:07:51 +01:00
|
|
|
symbolName = dlg.GetSymbolName();
|
|
|
|
libraryName = dlg.GetTextSelection();
|
2024-10-13 08:49:22 +08:00
|
|
|
|
|
|
|
if( ret == ID_RENAME_CONFLICTS )
|
|
|
|
strategy = SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY::RENAME;
|
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
done = true;
|
2024-10-13 08:49:22 +08:00
|
|
|
break;
|
2024-10-13 20:13:34 +01:00
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
case ID_MAKE_NEW_LIBRARY:
|
2018-07-24 22:16:59 +01:00
|
|
|
{
|
2023-09-05 22:07:51 +01:00
|
|
|
wxFileName newLibrary( AddLibraryFile( true ) );
|
|
|
|
libraryName = newLibrary.GetName();
|
2024-10-13 20:13:34 +01:00
|
|
|
break;
|
2018-07-24 22:16:59 +01:00
|
|
|
}
|
2024-10-13 20:13:34 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2024-10-13 08:49:22 +08:00
|
|
|
}
|
2023-09-05 22:07:51 +01:00
|
|
|
}
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
SYMBOL_SAVE_AS_HANDLER saver( *m_libMgr, strategy, valueFollowsName );
|
2018-07-24 22:16:59 +01:00
|
|
|
|
2024-10-13 08:49:22 +08:00
|
|
|
saver.DoSave( *symbol, symbolName, libraryName );
|
2023-09-14 23:54:04 +01:00
|
|
|
|
2023-09-05 22:07:51 +01:00
|
|
|
SyncLibraries( false );
|
2024-10-12 21:27:57 -06:00
|
|
|
|
|
|
|
if( aOpenCopy )
|
|
|
|
LoadSymbol( symbolName, libraryName, 1 );
|
2018-07-24 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties( wxString* aOldName )
|
2019-05-08 19:56:03 +01:00
|
|
|
{
|
2021-06-15 08:31:28 -04:00
|
|
|
wxCHECK( m_symbol, /* void */ );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
2021-06-30 11:53:04 +01:00
|
|
|
wxString lib = GetCurLib();
|
2019-05-08 19:56:03 +01:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( !lib.IsEmpty() && aOldName && *aOldName != m_symbol->GetName() )
|
2019-05-08 19:56:03 +01:00
|
|
|
{
|
2019-05-11 15:38:05 +01:00
|
|
|
// Test the current library for name conflicts
|
2025-01-25 18:50:09 +00:00
|
|
|
if( m_libMgr->SymbolNameInUse( m_symbol->GetName(), lib ) )
|
2019-05-11 15:38:05 +01:00
|
|
|
{
|
2021-06-30 11:53:04 +01:00
|
|
|
wxString msg = wxString::Format( _( "Symbol name '%s' already in use." ),
|
|
|
|
UnescapeString( m_symbol->GetName() ) );
|
2019-05-08 19:56:03 +01:00
|
|
|
|
2019-05-11 15:38:05 +01:00
|
|
|
DisplayErrorMessage( this, msg );
|
2021-06-15 08:31:28 -04:00
|
|
|
m_symbol->SetName( *aOldName );
|
2019-05-11 15:38:05 +01:00
|
|
|
}
|
|
|
|
else
|
2020-07-16 01:08:31 +01:00
|
|
|
{
|
2021-06-15 08:31:28 -04:00
|
|
|
m_libMgr->UpdateSymbolAfterRename( m_symbol, *aOldName, lib );
|
2020-07-16 01:08:31 +01:00
|
|
|
}
|
2019-05-08 19:56:03 +01:00
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
// Reselect the renamed symbol
|
2021-06-15 08:31:28 -04:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, m_symbol->GetName() ) );
|
2020-07-16 01:08:31 +01:00
|
|
|
}
|
2019-05-11 15:38:05 +01:00
|
|
|
|
|
|
|
RebuildSymbolUnitsList();
|
2024-01-26 16:16:13 +00:00
|
|
|
SetShowDeMorgan( GetCurSymbol()->Flatten()->HasAlternateBodyStyle() );
|
2023-09-12 16:17:36 +01:00
|
|
|
UpdateTitle();
|
2019-05-11 15:38:05 +01:00
|
|
|
|
2022-04-15 14:56:18 -07: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 15:38:05 +01:00
|
|
|
RebuildView();
|
2022-04-15 14:56:18 -07:00
|
|
|
UpdateMsgPanel();
|
|
|
|
|
2019-05-11 15:38:05 +01:00
|
|
|
OnModify();
|
2019-05-08 19:56:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::DeleteSymbolFromLibrary()
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2022-09-08 22:15:44 -04:00
|
|
|
std::vector<LIB_ID> toDelete = GetSelectedLibIds();
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
if( toDelete.empty() )
|
|
|
|
toDelete.emplace_back( GetTargetLibId() );
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
for( LIB_ID& libId : toDelete )
|
2019-12-12 10:44:53 -05:00
|
|
|
{
|
2022-09-08 22:15:44 -04: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 10:44:53 -05:00
|
|
|
|
2022-09-08 22:15:44 -04: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 10:44:53 -05:00
|
|
|
"Deleting this symbol will delete all of the symbols derived from it.\n\n"
|
2021-06-29 00:44:07 +01:00
|
|
|
"Do you wish to delete this symbol and all of its derivatives?" ),
|
2019-12-12 10:44:53 -05:00
|
|
|
libId.GetLibItemName().wx_str() );
|
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
wxMessageDialog::ButtonLabel yesButtonLabel( _( "Delete Symbol" ) );
|
|
|
|
wxMessageDialog::ButtonLabel noButtonLabel( _( "Keep Symbol" ) );
|
2019-12-12 10:44:53 -05:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
wxMessageDialog dlg( this, msg, _( "Warning" ),
|
|
|
|
wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
|
|
|
|
dlg.SetYesNoLabels( yesButtonLabel, noButtonLabel );
|
2019-12-12 10:44:53 -05:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
if( dlg.ShowModal() == wxID_NO )
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-12 10:44:53 -05:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
if( IsCurrentSymbol( libId ) )
|
|
|
|
emptyScreen();
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
m_libMgr->RemoveSymbol( libId.GetLibItemName(), libId.GetLibNickname() );
|
|
|
|
}
|
2018-10-16 16:50:29 +01:00
|
|
|
|
2019-12-02 20:24:16 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::CopySymbolToClipboard()
|
2017-11-13 20:39:36 +01:00
|
|
|
{
|
2022-09-08 22:15:44 -04:00
|
|
|
std::vector<LIB_ID> symbols;
|
2018-08-29 21:53:41 +01:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
if( GetTreeLIBIDs( symbols ) == 0 )
|
2018-08-29 21:53:41 +01:00
|
|
|
return;
|
|
|
|
|
2019-04-08 01:11:06 +01:00
|
|
|
STRING_FORMATTER formatter;
|
2022-09-08 22:15:44 -04: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();
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_KICAD_SEXPR::FormatLibSymbol( tmp.get(), formatter );
|
2022-09-08 22:15:44 -04:00
|
|
|
}
|
2019-04-08 01:11:06 +01:00
|
|
|
|
2024-11-26 12:48:36 +00:00
|
|
|
std::string prettyData = formatter.GetString();
|
2024-11-27 18:12:53 +00:00
|
|
|
KICAD_FORMAT::Prettify( prettyData, true );
|
2024-11-26 12:48:36 +00:00
|
|
|
|
2021-01-29 19:13:12 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
|
|
|
|
2019-04-08 01:11:06 +01:00
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock || !clipboard->IsOpened() )
|
|
|
|
return;
|
|
|
|
|
2024-11-26 12:48:36 +00:00
|
|
|
auto data = new wxTextDataObject( wxString( prettyData.c_str(), wxConvUTF8 ) );
|
2019-04-08 01:11:06 +01:00
|
|
|
clipboard->SetData( data );
|
|
|
|
|
|
|
|
clipboard->Flush();
|
2018-08-29 21:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::DuplicateSymbol( bool aFromClipboard )
|
2018-08-29 21:53:41 +01:00
|
|
|
{
|
2022-03-03 15:19:24 -08:00
|
|
|
LIB_ID libId = GetTargetLibId();
|
2017-11-13 20:39:36 +01:00
|
|
|
wxString lib = libId.GetLibNickname();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
return;
|
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
std::vector<LIB_SYMBOL*> newSymbols;
|
|
|
|
|
2019-06-05 23:29:59 +01:00
|
|
|
if( aFromClipboard )
|
2019-04-08 01:11:06 +01:00
|
|
|
{
|
2024-10-13 16:32:20 +08:00
|
|
|
std::string clipboardData = GetClipboardUTF8();
|
2021-01-29 19:13:12 +00:00
|
|
|
|
2023-06-12 23:13:23 +01:00
|
|
|
try
|
2022-01-12 03:24:04 -06:00
|
|
|
{
|
2023-12-24 00:31:24 +00:00
|
|
|
newSymbols = SCH_IO_KICAD_SEXPR::ParseLibSymbols( clipboardData, "Clipboard" );
|
2022-01-12 03:24:04 -06:00
|
|
|
}
|
2023-06-12 23:13:23 +01:00
|
|
|
catch( IO_ERROR& e )
|
2019-04-08 01:11:06 +01:00
|
|
|
{
|
2023-06-12 23:13:23 +01:00
|
|
|
wxLogMessage( wxS( "Can not paste: %s" ), e.Problem() );
|
2019-04-08 01:11:06 +01:00
|
|
|
}
|
|
|
|
}
|
2024-07-19 22:11:23 +01:00
|
|
|
else if( LIB_SYMBOL* srcSymbol = m_libMgr->GetBufferedSymbol( libId.GetLibItemName(), lib ) )
|
2019-06-05 23:29:59 +01:00
|
|
|
{
|
2022-09-08 22:15:44 -04:00
|
|
|
newSymbols.emplace_back( new LIB_SYMBOL( *srcSymbol ) );
|
2019-11-06 14:15:42 -05:00
|
|
|
|
|
|
|
// Derive from same parent.
|
2025-01-25 20:06:08 +00:00
|
|
|
if( srcSymbol->IsDerived() )
|
2019-11-06 14:15:42 -05:00
|
|
|
{
|
2024-07-19 22:11:23 +01:00
|
|
|
if( std::shared_ptr<LIB_SYMBOL> srcParent = srcSymbol->GetParent().lock() )
|
|
|
|
newSymbols.back()->SetParent( srcParent.get() );
|
2019-11-06 14:15:42 -05:00
|
|
|
}
|
2019-06-05 23:29:59 +01:00
|
|
|
}
|
2017-11-13 20:39:36 +01:00
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
if( newSymbols.empty() )
|
2017-11-13 20:39:36 +01:00
|
|
|
return;
|
|
|
|
|
2022-09-08 22:15:44 -04:00
|
|
|
for( LIB_SYMBOL* symbol : newSymbols )
|
|
|
|
{
|
|
|
|
ensureUniqueName( symbol, lib );
|
|
|
|
m_libMgr->UpdateSymbol( symbol, lib );
|
2020-12-21 17:21:01 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
LoadOneLibrarySymbolAux( symbol, lib, GetUnit(), GetBodyStyle() );
|
2022-09-08 22:15:44 -04:00
|
|
|
}
|
2020-12-21 17:21:01 +00:00
|
|
|
|
2018-08-25 13:21:09 +01:00
|
|
|
SyncLibraries( false );
|
2022-09-08 22:15:44 -04:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newSymbols[0]->GetName() ) );
|
2019-04-08 01:11:06 +01:00
|
|
|
|
2022-10-05 09:45:18 -07:00
|
|
|
for( LIB_SYMBOL* symbol : newSymbols )
|
|
|
|
delete symbol;
|
2017-11-13 20:39:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:51:46 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::ensureUniqueName( LIB_SYMBOL* aSymbol, const wxString& aLibrary )
|
2017-11-13 20:39:36 +01:00
|
|
|
{
|
2024-07-19 22:11:23 +01:00
|
|
|
if( aSymbol )
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
wxString newName = aSymbol->GetName();
|
2017-11-13 20:39:36 +01:00
|
|
|
|
2024-07-19 22:11:23 +01:00
|
|
|
// Append a number to the name until the name is unique in the library.
|
2025-01-25 18:50:09 +00:00
|
|
|
while( m_libMgr->SymbolNameInUse( newName, aLibrary ) )
|
2024-07-19 22:11:23 +01:00
|
|
|
newName.Printf( "%s_%d", aSymbol->GetName(), i++ );
|
2017-11-13 20:39:36 +01:00
|
|
|
|
2024-07-19 22:11:23 +01:00
|
|
|
aSymbol->SetName( newName );
|
|
|
|
}
|
2017-11-13 20:39:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::Revert( bool aConfirm )
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2021-02-07 18:21:38 -05:00
|
|
|
LIB_ID libId = GetTargetLibId();
|
2018-07-27 11:46:09 +01:00
|
|
|
const wxString& libName = libId.GetLibNickname();
|
2019-11-06 14:15:42 -05:00
|
|
|
|
|
|
|
// Empty if this is the library itself that is selected.
|
2021-06-15 08:31:28 -04:00
|
|
|
const wxString& symbolName = libId.GetLibItemName();
|
2018-07-27 11:46:09 +01:00
|
|
|
|
2021-06-29 00:44:07 +01:00
|
|
|
wxString msg = wxString::Format( _( "Revert '%s' to last version saved?" ),
|
2021-06-15 08:31:28 -04:00
|
|
|
symbolName.IsEmpty() ? libName : symbolName );
|
2018-10-03 22:44:17 +01:00
|
|
|
|
2019-06-13 07:44:12 -04:00
|
|
|
if( aConfirm && !ConfirmRevertDialog( this, msg ) )
|
2018-07-27 11:46:09 +01:00
|
|
|
return;
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
bool reload_currentSymbol = false;
|
|
|
|
wxString curr_symbolName = symbolName;
|
2018-08-19 10:25:12 +02:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( GetCurSymbol() )
|
2018-08-19 10:25:12 +02:00
|
|
|
{
|
2021-06-15 08:31:28 -04: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 08:31:28 -04:00
|
|
|
if( symbolName.IsEmpty() )
|
2018-11-20 20:14:00 +00:00
|
|
|
{
|
2021-06-15 08:31:28 -04:00
|
|
|
LIB_ID curr_libId = GetCurSymbol()->GetLibId();
|
2024-04-12 22:38:38 -04:00
|
|
|
reload_currentSymbol = libName == curr_libId.GetLibNickname().wx_str();
|
2018-08-19 10:25:12 +02:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( reload_currentSymbol )
|
2023-09-14 18:35:19 +03:00
|
|
|
curr_symbolName = curr_libId.GetUniStringLibItemName();
|
2018-11-20 20:14:00 +00:00
|
|
|
}
|
|
|
|
else
|
2019-11-06 14:15:42 -05:00
|
|
|
{
|
2022-04-21 11:57:15 +01:00
|
|
|
reload_currentSymbol = IsCurrentSymbol( libId );
|
2019-11-06 14:15:42 -05:00
|
|
|
}
|
2018-08-19 10:25:12 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 18:55:20 +01:00
|
|
|
int unit = m_unit;
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( reload_currentSymbol )
|
2017-11-12 18:55:20 +01:00
|
|
|
emptyScreen();
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( symbolName.IsEmpty() )
|
2018-07-27 11:46:09 +01:00
|
|
|
{
|
|
|
|
m_libMgr->RevertLibrary( libName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-15 08:31:28 -04:00
|
|
|
libId = m_libMgr->RevertSymbol( libId.GetLibItemName(), libId.GetLibNickname() );
|
2018-07-27 11:46:09 +01:00
|
|
|
|
2018-07-27 21:47:51 +01:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( libId );
|
2021-06-15 08:31:28 -04:00
|
|
|
m_libMgr->ClearSymbolModified( libId.GetLibItemName(), libId.GetLibNickname() );
|
2018-07-27 11:46:09 +01:00
|
|
|
}
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( reload_currentSymbol && m_libMgr->SymbolExists( curr_symbolName, libName ) )
|
|
|
|
LoadSymbol( curr_symbolName, libName, unit );
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2018-07-27 11:46:09 +01:00
|
|
|
m_treePane->Refresh();
|
2017-11-12 18:55:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::RevertAll()
|
2019-06-13 07:44:12 -04:00
|
|
|
{
|
|
|
|
wxCHECK_RET( m_libMgr, "Library manager object not created." );
|
|
|
|
|
|
|
|
Revert( false );
|
|
|
|
m_libMgr->RevertAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::LoadSymbol( const wxString& aAlias, const wxString& aLibrary, int aUnit )
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2022-04-11 22:14:54 +01:00
|
|
|
if( GetCurSymbol() && IsSymbolFromSchematic() && GetScreen()->IsContentModified() )
|
|
|
|
{
|
|
|
|
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ),
|
|
|
|
[&]() -> bool
|
|
|
|
{
|
|
|
|
return saveCurrentSymbol();
|
|
|
|
} ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
LIB_SYMBOL* symbol = m_libMgr->GetBufferedSymbol( aAlias, aLibrary );
|
2017-11-12 18:55:20 +01:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( !symbol )
|
2017-11-12 18:55:20 +01:00
|
|
|
{
|
2022-04-11 22:14:54 +01:00
|
|
|
DisplayError( this, wxString::Format( _( "Symbol %s not found in library '%s'." ),
|
|
|
|
aAlias,
|
|
|
|
aLibrary ) );
|
2023-08-20 12:05:31 -04:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 18:55:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-08 10:48:33 +01: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 08:31:28 -04:00
|
|
|
tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
|
2018-01-08 10:48:33 +01:00
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
LoadOneLibrarySymbolAux( symbol, aLibrary, aUnit, 0 );
|
2017-11-12 18:55:20 +01: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-11 22:59:59 -04:00
|
|
|
SYMBOL_SAVEAS_TYPE type = SYMBOL_SAVEAS_TYPE::NORMAL_SAVE_AS;
|
2020-04-16 12:43:50 -04:00
|
|
|
SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::SCH_FILE_T::SCH_KICAD;
|
2017-10-06 14:07:43 -04:00
|
|
|
PROJECT& prj = Prj();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2023-06-26 23:16:51 +01:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2023-09-27 23:04:53 -04:00
|
|
|
if( !aNewFile && ( aLibrary.empty() || !PROJECT_SCH::SchSymbolLibTable( &prj )->HasLibrary( aLibrary ) ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2020-08-31 14:19:57 +01:00
|
|
|
ShowInfoBarError( _( "No library specified." ) );
|
2013-02-07 18:35:37 +01:00
|
|
|
return false;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 18:55:20 +01: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-19 19:42:08 -05:00
|
|
|
{
|
2023-09-27 23:04:53 -04:00
|
|
|
SEARCH_STACK* search = PROJECT_SCH::SchSearchS( &prj );
|
* 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-19 19:42:08 -05:00
|
|
|
|
|
|
|
// Get a new name for the library
|
2014-06-10 10:56:43 -05: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 15:28:54 -05:00
|
|
|
|
2014-06-10 10:56:43 -05: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 15:28:54 -05: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-19 19:42:08 -05:00
|
|
|
|
2017-11-13 10:55:05 +01:00
|
|
|
fn.SetName( aLibrary );
|
2023-12-27 21:10:01 -05:00
|
|
|
fn.SetExt( FILEEXT::KiCadSymbolLibFileExtension );
|
2017-11-13 10:55:05 +01:00
|
|
|
|
2023-12-27 21:10:01 -05:00
|
|
|
wxString wildcards = FILEEXT::KiCadSymbolLibFileWildcard();
|
2020-02-13 08:39:52 -05:00
|
|
|
|
2021-06-29 00:44:07 +01:00
|
|
|
wxFileDialog dlg( this, wxString::Format( _( "Save Library '%s' As..." ), aLibrary ),
|
2020-02-13 08:39:52 -05: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-11 22:59:59 -04:00
|
|
|
SYMBOL_FILEDLG_SAVE_AS saveAsHook( type );
|
|
|
|
dlg.SetCustomizeHook( saveAsHook );
|
2020-12-29 13:59:48 -05:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2013-02-07 18:35:37 +01: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 15:25:29 +01:00
|
|
|
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
|
|
|
|
|
2020-05-15 09:25:11 -04:00
|
|
|
if( fn.GetExt().IsEmpty() )
|
2023-12-27 21:10:01 -05:00
|
|
|
fn.SetExt( FILEEXT::KiCadSymbolLibFileExtension );
|
2020-12-29 13:59:48 -05:00
|
|
|
|
2022-06-11 22:59:59 -04:00
|
|
|
type = saveAsHook.GetOption();
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-27 23:04:53 -04:00
|
|
|
fn = PROJECT_SCH::SchSymbolLibTable( &prj )->GetFullURI( aLibrary );
|
2020-04-16 12:43:50 -04:00
|
|
|
fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
|
2023-08-26 22:28:53 +03:00
|
|
|
|
|
|
|
if( fileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
|
|
|
|
fileType = SCH_IO_MGR::SCH_KICAD;
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2017-01-27 10:56:36 -05:00
|
|
|
// Verify the user has write privileges before attempting to save the library file.
|
2020-06-04 13:25:36 -04:00
|
|
|
if( !aNewFile && m_libMgr->IsLibraryReadOnly( aLibrary ) )
|
2013-02-07 18:35:37 +01:00
|
|
|
return false;
|
2011-08-12 13:43:16 -04:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-05-16 17:25:13 -04:00
|
|
|
// Copy .kicad_symb file to .bak.
|
2017-11-13 15:15:10 +01:00
|
|
|
if( !backupFile( fn, "bak" ) )
|
|
|
|
return false;
|
2011-11-11 15:10:24 -05:00
|
|
|
|
2020-04-16 12:43:50 -04:00
|
|
|
if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath(), fileType ) )
|
2011-11-11 15:10:24 -05:00
|
|
|
{
|
2021-06-16 23:35:00 +01:00
|
|
|
msg.Printf( _( "Failed to save changes to symbol library file '%s'." ),
|
2017-11-13 15:15:10 +01:00
|
|
|
fn.GetFullPath() );
|
2021-06-16 23:35:00 +01:00
|
|
|
DisplayErrorMessage( this, _( "Error Saving Library" ), msg );
|
2017-11-13 14:58:39 +01:00
|
|
|
return false;
|
2011-11-11 15:10:24 -05:00
|
|
|
}
|
|
|
|
|
2017-11-13 23:13:10 +01:00
|
|
|
if( !aNewFile )
|
2020-12-29 13:59:48 -05:00
|
|
|
{
|
2017-11-13 23:13:10 +01:00
|
|
|
m_libMgr->ClearLibraryModified( aLibrary );
|
2024-01-11 19:00:47 -08:00
|
|
|
|
|
|
|
// Update the library modification time so that we don't reload based on the watcher
|
|
|
|
if( aLibrary == getTargetLib() )
|
|
|
|
SetSymModificationTime( fn.GetModificationTime() );
|
2020-12-29 13:59:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool resyncLibTree = false;
|
|
|
|
wxString originalLibNickname = getTargetLib();
|
2021-01-31 22:58:34 +00:00
|
|
|
wxString forceRefresh;
|
2020-12-29 13:59:48 -05:00
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2022-06-11 22:59:59 -04:00
|
|
|
case SYMBOL_SAVEAS_TYPE::REPLACE_TABLE_ENTRY:
|
2020-12-29 13:59:48 -05:00
|
|
|
resyncLibTree = replaceLibTableEntry( originalLibNickname, fn.GetFullPath() );
|
2021-01-31 22:58:34 +00:00
|
|
|
forceRefresh = originalLibNickname;
|
2020-12-29 13:59:48 -05:00
|
|
|
break;
|
|
|
|
|
2022-06-11 22:59:59 -04:00
|
|
|
case SYMBOL_SAVEAS_TYPE::ADD_GLOBAL_TABLE_ENTRY:
|
2020-12-29 13:59:48 -05:00
|
|
|
resyncLibTree = addLibTableEntry( fn.GetFullPath() );
|
|
|
|
break;
|
|
|
|
|
2022-06-11 22:59:59 -04:00
|
|
|
case SYMBOL_SAVEAS_TYPE::ADD_PROJECT_TABLE_ENTRY:
|
2020-12-29 13:59:48 -05: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 13:59:48 -05:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 23:13:10 +01:00
|
|
|
|
2019-11-06 14:15:42 -05:00
|
|
|
ClearMsgPanel();
|
2021-06-16 23:35:00 +01:00
|
|
|
msg.Printf( _( "Symbol library file '%s' saved." ), fn.GetFullPath() );
|
2019-05-06 13:32:51 +01:00
|
|
|
RebuildSymbolUnitsList();
|
2017-03-04 14:49:55 -05:00
|
|
|
|
2013-02-07 18:35:37 +01: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 10:55:05 +01: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 10:55:05 +01:00
|
|
|
|
2020-12-11 22:44:10 +00:00
|
|
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
2017-11-13 10:55:05 +01:00
|
|
|
{
|
2018-08-01 14:36:42 +01:00
|
|
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
|
|
|
dirtyCount++;
|
|
|
|
}
|
2017-11-13 10:55:05 +01:00
|
|
|
|
2020-12-11 22:44:10 +00:00
|
|
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
2018-08-01 14:36:42 +01:00
|
|
|
{
|
|
|
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
2018-02-16 11:27:43 +01:00
|
|
|
{
|
2018-08-01 14:36:42 +01:00
|
|
|
if( aRequireConfirmation && !applyToAll )
|
|
|
|
{
|
2021-06-16 23:35:00 +01:00
|
|
|
msg.Printf( _( "Save changes to '%s' before closing?" ), libNickname );
|
2018-08-01 14:36:42 +01:00
|
|
|
|
2018-08-02 00:06:12 +01:00
|
|
|
switch( UnsavedChangesDialog( this, msg, dirtyCount > 1 ? &applyToAll : nullptr ) )
|
2018-08-01 14:36:42 +01:00
|
|
|
{
|
|
|
|
case wxID_YES: doSave = true; break;
|
|
|
|
case wxID_NO: doSave = false; break;
|
|
|
|
default:
|
|
|
|
case wxID_CANCEL: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( doSave )
|
|
|
|
{
|
2018-08-02 00:06:12 +01:00
|
|
|
// If saving under existing name fails then do a Save As..., and if that
|
|
|
|
// fails then cancel close action.
|
2023-09-23 12:24:42 +01:00
|
|
|
if( m_libMgr->IsLibraryReadOnly( libNickname ) )
|
2020-12-11 22:44:10 +00:00
|
|
|
{
|
2021-11-08 15:42:09 -08: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 );
|
|
|
|
|
2021-08-19 22:28:54 +01:00
|
|
|
while( m_infoBar->IsShownOnScreen() )
|
2020-12-11 22:44:10 +00:00
|
|
|
wxSafeYield();
|
|
|
|
|
|
|
|
retv = false;
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-22 07:48:28 -04:00
|
|
|
}
|
2023-09-23 12:24:42 +01:00
|
|
|
else if( saveLibrary( libNickname, false ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-16 17:25:13 -04:00
|
|
|
|
|
|
|
if( !saveLibrary( libNickname, true ) )
|
2020-10-29 08:22:38 -04:00
|
|
|
retv = false;
|
2018-08-01 14:36:42 +01:00
|
|
|
}
|
2017-11-13 10:55:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-12 16:17:36 +01:00
|
|
|
UpdateTitle();
|
2020-10-29 08:22:38 -04:00
|
|
|
return retv;
|
2017-11-13 10:55:05 +01:00
|
|
|
}
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
|
2021-08-20 15:45:57 -04:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateSymbolMsgPanelInfo()
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
|
|
|
EDA_DRAW_FRAME::ClearMsgPanel();
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
if( !m_symbol )
|
2020-10-31 01:27:16 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-15 08:31:28 -04:00
|
|
|
wxString msg = m_symbol->GetName();
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2021-06-30 11:53:04 +01:00
|
|
|
AppendMsgPanel( _( "Name" ), UnescapeString( msg ), 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2025-01-25 20:06:08 +00:00
|
|
|
if( m_symbol->IsDerived() )
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
2021-06-15 08:31:28 -04: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 11:53:04 +01: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
|
|
|
|
2024-04-06 14:14:44 +01:00
|
|
|
if( m_bodyStyle == BODY_STYLE::DEMORGAN )
|
2024-01-26 16:16:13 +00:00
|
|
|
msg = _( "Alternate" );
|
2024-04-06 14:14:44 +01:00
|
|
|
else if( m_bodyStyle == BODY_STYLE::BASE )
|
2024-01-26 16:16:13 +00:00
|
|
|
msg = _( "Standard" );
|
2024-01-26 18:11:10 +00:00
|
|
|
else
|
2024-03-08 07:05:57 +00:00
|
|
|
msg = wxT( "?" );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Body" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
2021-06-15 08:31:28 -04: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 08:31:28 -04: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
|
|
|
}
|