46#include <wx/clipbrd.h>
48#include <wx/filedlg.h>
62 SetTitle(
_(
"Symbol Editor" ) );
92 if( libName.IsEmpty() )
98 if(
m_libMgr->IsLibraryReadOnly( libName ) )
100 wxString msg = wxString::Format(
_(
"Symbol library '%s' is not writable." ),
102 wxString msg2 =
_(
"You must save to a different location." );
130 if( type == SCH_IO_MGR::SCH_DATABASE
131 || type == SCH_IO_MGR::SCH_CADSTAR_ARCHIVE
132 || type == SCH_IO_MGR::SCH_HTTP )
145 msg.Printf(
_(
"Error loading symbol %s from library '%s'." ),
177 m_treePane->GetLibTree()->SelectLibId( libId );
178 m_treePane->GetLibTree()->ExpandLibId( libId );
211 msg.Printf(
_(
"Error loading symbol %s from library '%s'." ),
231 bool rebuildMenuAndToolbar =
false;
233 if( !aEntry || aLibrary.empty() )
236 if( aEntry->
GetName().IsEmpty() )
238 wxLogWarning(
"Symbol in library '%s' has empty name field.", aLibrary );
247 rebuildMenuAndToolbar =
true;
250 wxCHECK( lib_symbol,
false );
253 const int unit = aUnit > 0 ? aUnit : 1;
254 const int bodyStyle = aBodyStyle > 0 ? aBodyStyle : 1;
257 bool wasCreated =
false;
259 unit, bodyStyle,
true,
261 wxCHECK( ctx,
false );
263 if( rebuildMenuAndToolbar )
307 wxArrayString symbolNamesInLib;
308 wxArrayString derivedSymbols;
319 [&]( wxString newName ) ->
bool
321 if( newName.IsEmpty() )
323 wxMessageBox(
_(
"Symbol must have a name." ) );
327 if( !lib.empty() &&
m_libMgr->SymbolNameInUse( newName, lib ) )
331 msg.Printf(
_(
"Symbol '%s' already exists in library '%s'." ),
335 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ),
336 wxOK | wxCANCEL | wxICON_WARNING );
338 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
347 [&](
const wxString& aItem ) ->
int
349 for( wxString& candidate : derivedSymbols )
351 if( candidate.CmpNoCase( aItem ) == 0 )
360 dlg.SetMinSize( dlg.GetSize() );
401 m_libMgr->CreateNewSymbol( lib, props );
420 if( libName.empty() )
424 else if(
m_libMgr->IsLibraryReadOnly( libName ) )
426 wxString msg = wxString::Format(
_(
"Symbol library '%s' is not writable." ),
428 wxString msg2 =
_(
"You must save to a different location." );
448 if( !libName.IsEmpty() )
475 std::vector<std::shared_ptr<LIB_SYMBOL>>
chain;
476 std::shared_ptr<LIB_SYMBOL> sym = aSymbol.
SharedPtr();
479 chain.push_back( sym );
481 while( sym->IsDerived() )
483 std::shared_ptr<LIB_SYMBOL> parent = sym->GetParent().lock();
490 chain.push_back( parent );
509 const wxString& aNewSymbolName,
510 const wxString& aNewLibraryName )
515 if( aNewLibraryName != oldLibraryName )
516 return {
false,
false };
520 return {
false,
false };
522 bool inAncestry =
false;
523 bool inDescendents =
false;
526 const std::vector<std::shared_ptr<LIB_SYMBOL>> parentChainFromUs =
GetParentChain( aSymbol,
true );
529 for(
size_t i = 1; i < parentChainFromUs.size(); ++i )
532 if( parentChainFromUs[i]->GetName() == aNewSymbolName )
542 const std::vector<std::shared_ptr<LIB_SYMBOL>> parentChainFromTarget =
GetParentChain( *targetSymbol,
true );
543 const wxString oldSymbolName = aSymbol.
GetName();
547 for(
size_t i = 1; i < parentChainFromTarget.size(); ++i )
549 if( parentChainFromTarget[i]->GetName() == oldSymbolName )
551 inDescendents =
true;
557 return { inAncestry, inDescendents };
571 const wxString& newSymbolName,
572 const wxString& newLibraryName )
574 std::vector<wxString> conflicts;
577 if( newLibraryName == oldLibraryName || aFlattenSymbol )
582 conflicts.push_back( newSymbolName );
587 const std::vector<std::shared_ptr<LIB_SYMBOL>> parentChain =
GetParentChain( aSymbol,
true );
589 for(
size_t i = 0; i < parentChain.size(); ++i )
595 conflicts.push_back( newSymbolName );
599 std::shared_ptr<LIB_SYMBOL> chainSymbol = parentChain[i];
601 if( aLibMgr.
SymbolNameInUse( chainSymbol->GetName(), newLibraryName ) )
602 conflicts.push_back( chainSymbol->GetName() );
638 bool DoSave(
LIB_SYMBOL& symbol,
const wxString& aNewSymName,
const wxString& aNewLibName,
bool aFlattenSymbol )
640 std::unique_ptr<LIB_SYMBOL> flattenedSymbol;
641 std::vector<std::shared_ptr<LIB_SYMBOL>> parentChain;
649 flattenedSymbol = symbol.
Flatten();
650 wxCHECK( flattenedSymbol,
false );
652 parentChain.push_back( flattenedSymbol->SharedPtr() );
658 parentChain.push_back( symbol.
SharedPtr() );
666 std::vector<wxString> newNames;
669 for(
int i = (
int) parentChain.size() - 1; i >= 0; --i )
671 std::shared_ptr<LIB_SYMBOL>& oldSymbol = parentChain[i];
678 newName = aNewSymName;
683 newName = oldSymbol->GetName();
692 if( i == (
int) parentChain.size() - 1 )
703 wxASSERT( newParent );
712 newNames.push_back( newName );
713 m_libMgr.UpdateSymbol( &new_symbol, aNewLibName );
720 wxString
resolveConflict(
const wxString& proposed,
const wxString& aNewLibName )
const
736 wxString newName = wxString::Format(
"%s_%d", proposed, suffix );
738 if( !
m_libMgr.SymbolNameInUse( newName, aNewLibName ) )
748 wxFAIL_MSG(
"Invalid conflict strategy" );
782 const std::vector<wxString>& aParentSymbolNames ) :
787 wxArrayString headers;
788 std::vector<wxArrayString> itemsToDisplay;
790 if( aParentSymbolNames.size() )
794 const wxString aParentNames = AccumulateDescriptions( aParentSymbolNames );
796 wxString::Format(
"Flatten/remove symbol inheritance (current parent symbols: %s)", aParentNames ),
797 &m_params.m_FlattenSymbol );
806 wxBoxSizer* bNameSizer =
new wxBoxSizer( wxHORIZONTAL );
808 wxStaticText* label =
new wxStaticText(
this, wxID_ANY,
_(
"Name:" ) );
809 bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
816 m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
818 GetSizer()->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
821 [
this]( wxCommandEvent& )
835 GetSizer()->Fit(
this );
844 symbolName.Trim(
true );
845 symbolName.Trim(
false );
846 symbolName.Replace(
" ",
"_" );
867 if( ret == wxID_CANCEL )
900 bool flattenSymbol =
false;
904 const auto dialogValidatorFunc =
905 [&](
const wxString& newLib,
const wxString& newName ) ->
int
907 if( newLib.IsEmpty() )
909 wxMessageBox(
_(
"A library must be specified." ) );
913 if( newName.IsEmpty() )
915 wxMessageBox(
_(
"Symbol must have a name." ) );
919 if(
m_libMgr->IsLibraryReadOnly( newLib ) )
921 msg = wxString::Format(
_(
"Library '%s' is read-only. Choose a "
922 "different library to save the symbol '%s' to." ),
938 msg = wxString::Format(
_(
"Symbol '%s' cannot replace another symbol '%s' "
939 "that it descends from" ),
948 msg = wxString::Format(
_(
"Symbol '%s' cannot replace another symbol '%s' "
949 "that is a descendent of it." ),
956 const std::vector<wxString> conflicts =
959 if( conflicts.size() == 1 && conflicts.front() == newName )
962 msg = wxString::Format(
_(
"Symbol '%s' already exists in library '%s'. "
963 "Do you want to overwrite it?" ),
967 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
968 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
972 else if( !conflicts.empty() )
978 msg = wxString::Format(
_(
"The following symbols in the inheritance chain of "
979 "'%s' already exist in library '%s':\n" ),
983 for(
const wxString& conflict : conflicts )
984 msg += wxString::Format(
" %s\n", conflict );
986 msg +=
_(
"\nDo you want to overwrite all of them, or rename the new symbols?" );
988 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ), wxYES_NO | wxCANCEL | wxICON_WARNING );
989 errorDlg.SetYesNoCancelLabels(
_(
"Overwrite All" ),
_(
"Rename All" ),
_(
"Cancel" ) );
995 default:
return wxID_CANCEL;
1004 std::vector<wxString> parentSymbolNames;
1009 std::vector<std::shared_ptr<LIB_SYMBOL>> parentChain =
GetParentChain( *symbol,
false );
1011 for(
const std::shared_ptr<LIB_SYMBOL>& parent : parentChain )
1012 parentSymbolNames.push_back( parent->GetName() );
1045 params.m_LibraryName = newLibrary.GetName();
1058 saver.
DoSave( *symbol, params.m_SymbolName, params.m_LibraryName, params.m_FlattenSymbol );
1062 if( savingUnsavedTab )
1064 symbol->
SetLibId(
LIB_ID( params.m_LibraryName, params.m_SymbolName ) );
1079 LoadSymbol( params.m_SymbolName, params.m_LibraryName, 1 );
1096 fn.SetName( symbol->
GetName().Lower() );
1099 wxFileDialog dlg(
this,
_(
"Export Symbol" ),
m_mruPath, fn.GetFullName(),
1104 if( dlg.ShowModal() == wxID_CANCEL )
1114 wxString libraryName;
1115 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = symbol->
Flatten();
1117 for(
const wxString& candidate :
m_libMgr->GetLibraryNames() )
1121 if( *uri == fn.GetFullPath() )
1122 libraryName = candidate;
1126 if( !libraryName.IsEmpty() )
1130 if(
m_libMgr->IsLibraryReadOnly( libraryName ) )
1132 msg = wxString::Format(
_(
"Library '%s' is read-only." ), libraryName );
1139 msg = wxString::Format(
_(
"Symbol '%s' already exists in library '%s'." ),
1140 symbol->
GetName(), libraryName );
1142 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
1143 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
1146 if( errorDlg.
ShowModal() == wxID_CANCEL )
1150 saver.
DoSave( *flattenedSymbol, symbol->
GetName(), libraryName,
false );
1159 if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
1160 pluginType = SCH_IO_MGR::SCH_KICAD;
1164 if( fn.FileExists() )
1168 old_symbol = pi->LoadSymbol( fn.GetFullPath(), symbol->
GetName() );
1172 msg.Printf(
_(
"Error occurred attempting to load symbol library file '%s'." ),
1180 msg.Printf(
_(
"Symbol %s already exists in library '%s'." ),
1184 KIDIALOG errorDlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
1185 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
1188 if( errorDlg.
ShowModal() == wxID_CANCEL )
1193 if( !fn.IsDirWritable() )
1195 msg.Printf(
_(
"Insufficient permissions to save library '%s'." ), fn.GetFullPath() );
1202 if( !fn.FileExists() )
1203 pi->CreateLibrary( fn.GetFullPath() );
1208 pi->SaveSymbol( fn.GetFullPath(), std::move( flattenedSymbol ) );
1212 msg.Printf(
_(
"Failed to create symbol library file '%s'." ), fn.GetFullPath() );
1214 msg.Printf(
_(
"Error creating symbol library '%s'." ), fn.GetFullName() );
1215 SetStatusText( msg );
1221 msg.Printf(
_(
"Symbol %s saved to library '%s'." ),
1224 SetStatusText( msg );
1237 if( !lib.IsEmpty() && aOldName && *aOldName !=
m_symbol->GetName() )
1242 wxString msg = wxString::Format(
_(
"Symbol name '%s' already in use." ),
1259 if( treeItem.IsOk() )
1280 if( toDelete.empty() )
1284 std::set<LIB_ID> removedWithBase;
1286 for(
LIB_ID& libId : toDelete )
1288 if( removedWithBase.count( libId ) )
1291 if(
m_libMgr->IsSymbolModified( libId.GetLibItemName(), libId.GetLibNickname() )
1292 && !
IsOK(
this, wxString::Format(
_(
"The symbol '%s' has been modified.\n"
1293 "Do you want to remove it from the library?" ),
1294 libId.GetUniStringLibItemName() ) ) )
1299 wxArrayString derived;
1301 if(
m_libMgr->GetDerivedSymbolNames( libId.GetLibItemName(), libId.GetLibNickname(), derived ) > 0 )
1303 wxString msg =
_(
"Deleting a base symbol will delete all symbols derived from it.\n\n" );
1305 msg += libId.GetLibItemName().wx_str() +
_(
" (base)\n" );
1307 for(
const wxString&
name : derived )
1308 msg +=
name + wxT(
"\n" );
1311 dlg.SetExtendedMessage( wxT(
" " ) );
1312 dlg.SetYesNoLabels(
_(
"Delete All Listed Symbols" ),
_(
"Cancel" ) );
1314 if( dlg.ShowModal() == wxID_NO )
1322 for(
const wxString& derivedName : derived )
1325 m_libMgr->RemoveSymbol( libId.GetLibItemName(), libId.GetLibNickname() );
1327 for(
const wxString& derivedName : derived )
1328 removedWithBase.emplace( libId.GetLibNickname().wx_str(), derivedName );
1337 std::vector<LIB_ID> symbols;
1344 for(
LIB_ID& libId : symbols )
1347 libId.GetLibNickname() );
1352 std::unique_ptr<LIB_SYMBOL> tmp = symbol->
Flatten();
1356 std::string prettyData = formatter.
GetString();
1361 auto clipboard = wxTheClipboard;
1362 wxClipboardLocker clipboardLock( clipboard );
1364 if( !clipboardLock || !clipboard->IsOpened() )
1367 auto data =
new wxTextDataObject( wxString( prettyData.c_str(), wxConvUTF8 ) );
1368 clipboard->SetData( data );
1379 if( !
m_libMgr->LibraryExists( lib ) )
1382 std::vector<LIB_SYMBOL*> newSymbols;
1384 if( aFromClipboard )
1394 wxLogMessage( wxS(
"Can not paste: %s" ), e.
Problem() );
1399 newSymbols.emplace_back(
new LIB_SYMBOL( *srcSymbol ) );
1402 if( srcSymbol->IsDerived() )
1404 if( std::shared_ptr<LIB_SYMBOL> srcParent = srcSymbol->GetParent().lock() )
1405 newSymbols.back()->SetParent( srcParent.get() );
1409 if( newSymbols.empty() )
1415 m_libMgr->UpdateSymbol( symbol, lib );
1421 m_treePane->GetLibTree()->SelectLibId(
LIB_ID( lib, newSymbols[0]->GetName() ) );
1433 wxString newName = aSymbol->
GetName();
1436 while(
m_libMgr->SymbolNameInUse( newName, aLibrary ) )
1437 newName.Printf(
"%s_%d", aSymbol->
GetName(), i++ );
1451 if( libName.IsEmpty() )
1454 wxString msg = wxString::Format(
_(
"Revert '%s' to last version saved?" ),
1455 symbolName.IsEmpty() ? libName : symbolName );
1464 if( symbolName.IsEmpty() )
1466 m_libMgr->RevertLibrary( libName );
1470 aTarget =
m_libMgr->RevertSymbol( aTarget );
1472 m_treePane->GetLibTree()->SelectLibId( aTarget );
1496 wxCHECK_RET(
m_libMgr,
"Library manager object not created." );
1514 std::vector<LIB_ID> tabs;
1524 for(
const std::unique_ptr<SYMBOL_EDITOR_TAB_CONTEXT>& ctx :
m_tabContexts )
1526 if( ctx->IsTransient() )
1529 if( !aLibrary.IsEmpty() && ctx->GetLibrary() != aLibrary )
1532 if( !aSymbol.IsEmpty() && ctx->GetName() != aSymbol )
1535 tabs.emplace_back( ctx->GetLibrary(), ctx->GetName() );
1538 active = tabs.back();
1541 for(
const LIB_ID& tab : tabs )
1545 if(
int activeIdx =
m_tabsPanel->FindTab( activeKey ); activeIdx >= 0 )
1570 DisplayError(
this, wxString::Format(
_(
"Symbol %s not found in library '%s'." ),
1591 SCH_IO_MGR::SCH_FILE_T
fileType = SCH_IO_MGR::SCH_FILE_T::SCH_KICAD;
1598 wxCHECK( adapter,
false );
1612 if( newPackedLibrary )
1622 fn.SetName( aLibrary );
1629 dlgPrompt.Printf(
_(
"Save Library '%s' As..." ), aLibrary );
1631 dlgPrompt.Printf(
_(
"Save Library '%s' As Packed Library..." ), aLibrary );
1633 wxFileDialog dlg(
this, dlgPrompt, default_path, fn.GetFullName(), wildcards,
1634 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1637 dlg.SetCustomizeHook( saveAsHook );
1641 if( dlg.ShowModal() == wxID_CANCEL )
1648 if( fn.GetExt().IsEmpty() )
1653 else if( newUnpackedLibrary )
1666 dlgPrompt.Printf(
_(
"Save Library '%s' As..." ), aLibrary );
1668 dlgPrompt.Printf(
_(
"Save Library '%s' As Unpacked Library..." ), aLibrary );
1670 wxDirDialog dlg(
this, dlgPrompt, default_path );
1674 if( dlg.ShowModal() == wxID_CANCEL )
1677 fn.SetPath( dlg.GetPath() );
1681 std::optional<LIBRARY_TABLE_ROW*> optRow = adapter->
GetRow( aLibrary );
1682 wxCHECK( optRow,
false );
1690 if( wxFileName::DirExists( libFileName ) )
1691 fn.SetPath( libFileName );
1697 if(
fileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
1721 msg.Printf(
_(
"Failed to save changes to symbol library file '%s'." ),
1729 m_libMgr->ClearLibraryModified( aLibrary );
1736 if( wxFileName::DirExists( fn.GetFullPath() ) )
1742 else if( fn.FileExists() )
1751 bool resyncLibTree =
false;
1753 wxString forceRefresh;
1759 forceRefresh = originalLibNickname;
1783 msg.Printf(
_(
"Symbol library file '%s' saved." ), fn.GetFullPath() );
1801 bool applyToAll =
false;
1804 for(
const wxString& libNickname :
m_libMgr->GetLibraryNames() )
1806 if(
m_libMgr->IsLibraryModified( libNickname ) )
1810 for(
const wxString& libNickname :
m_libMgr->GetLibraryNames() )
1812 if(
m_libMgr->IsLibraryModified( libNickname ) )
1814 if( aRequireConfirmation && !applyToAll )
1816 msg.Printf(
_(
"Save changes to '%s' before closing?" ), libNickname );
1820 case wxID_YES: doSave =
true;
break;
1821 case wxID_NO: doSave =
false;
break;
1823 case wxID_CANCEL:
return false;
1831 if(
m_libMgr->IsLibraryReadOnly( libNickname ) )
1833 msg.Printf(
_(
"Symbol library '%s' is not writable." ), libNickname );
1834 msg2 =
_(
"You must save to a different location." );
1836 if( dirtyCount == 1 )
1847 m_infoBar->ShowMessageFor( msg + wxS(
" " ) + msg2, 5000, wxICON_EXCLAMATION );
1878 wxString msg =
m_symbol->GetName();
1884 std::shared_ptr<LIB_SYMBOL> parent =
m_symbol->GetParent().lock();
1886 msg = parent ? parent->GetName() :
_(
"Undefined!" );
1891 msg =
_(
"Power Symbol" );
1892 else if(
m_symbol->IsLocalPower() )
1893 msg =
_(
"Power Symbol (Local)" );
1895 msg =
_(
"Symbol" );
static TOOL_ACTION cancelInteractive
static TOOL_ACTION zoomFitScreen
bool IsContentModified() const
void SetContentModified(bool aModified=true)
wxString GetParentSymbolName() const
bool GetIncludeOnBoard() const
wxString GetName() const override
bool GetUnitsInterchangeable()
bool GetTransferUserFields()
bool GetKeepContentUserFields()
bool GetAlternateBodyStyle()
bool GetIncludeInBom() const
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=INFOBAR_MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
virtual void RecreateToolbars()
void ReCreateMenuBar()
Recreate the menu bar.
WX_INFOBAR * GetInfoBar()
virtual void ClearMsgPanel()
Clear all messages from the message panel.
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
wxBoxSizer * m_ButtonsSizer
void SetOKLabel(const wxString &aLabel)
void initDialog(const wxArrayString &aItemHeaders, const std::vector< wxArrayString > &aItemList, const wxString &aPreselectText)
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
void GetExtraCheckboxValues()
Fills in the value pointers from the checkboxes after the dialog has run.
EDA_LIST_DIALOG(wxWindow *aParent, const wxString &aTitle, const wxArrayString &aItemHeaders, const std::vector< wxArrayString > &aItemList, const wxString &aPreselectText=wxEmptyString, bool aSortList=true)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const wxString Problem() const
what was the problem?
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
std::optional< LIBRARY_TABLE_ROW * > GetRow(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
const wxString & Type() const
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
wxString GetUniStringLibId() const
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const wxString GetUniStringLibNickname() const
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Symbol library management helper that is specific to the symbol library editor frame.
static std::unique_ptr< LIB_SYMBOL > CreateSymbol(const NEW_SYMBOL_PROPERTIES &aProps, LIB_SYMBOL *aParent)
Define a library symbol object.
const LIB_ID & GetLibId() const override
bool UnitsLocked() const
Check whether symbol units are interchangeable.
LIB_ID GetSourceLibId() const
void SetParent(LIB_SYMBOL *aParent=nullptr)
wxString GetName() const override
SCH_FIELD & GetValueField()
std::shared_ptr< LIB_SYMBOL > SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
void SetParentName(const wxString &aParentName)
void SetLibId(const LIB_ID &aLibId)
virtual void SetName(const wxString &aName)
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static SEARCH_STACK * SchSearchS(PROJECT *aProject)
Accessor for Eeschema search stack.
Container for project specific data.
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
bool TransferDataFromWindow() override
std::function< int(const wxString &libName, const wxString &symbolName)> SymLibNameValidator
bool TransferDataToWindow() override
SymLibNameValidator m_validator
SAVE_SYMBOL_AS_DIALOG(SYMBOL_EDIT_FRAME *aParent, PARAMS &aParams, SymLibNameValidator aValidator, const std::vector< wxString > &aParentSymbolNames)
wxString getSymbolName() const
wxTextCtrl * m_symbolNameCtrl
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void GetLibraryItemsForListDialog(wxArrayString &aHeaders, std::vector< wxArrayString > &aItemsToDisplay)
void setSymWatcher(const LIB_ID *aSymbol)
Creates (or removes) a watcher on the specified symbol library.
void SetSymModificationTime(long long aTimestamp)
Set the modification timestamp of the watched symbol library.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
Schematic editor (Eeschema) main window.
bool SaveSymbolToSchematic(const LIB_SYMBOL &aSymbol, const KIID &aSchematicSymbolUUID)
Update a schematic symbol from a LIB_SYMBOL.
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetText(const wxString &aText) override
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
static std::vector< LIB_SYMBOL * > ParseLibSymbols(std::string &aSymbolText, std::string aSource, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the file type from the corresponding plugin type name: "kicad", "legacy", etc.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Look for files in a number of paths.
const wxString LastVisitedPath(const wxString &aSubPathToSearch=wxEmptyString)
A quirky function inherited from old code that seems to serve particular needs in the UI.
One open symbol tab owning a working LIB_SYMBOL and screen lent to the frame while active.
The symbol library editor main window.
std::vector< std::unique_ptr< SYMBOL_EDITOR_TAB_CONTEXT > > m_tabContexts
bool SaveLibraryHeadless(const wxString &aLibrary)
Save the given library (including buffered changes) without user interaction.
void ClearMsgPanel() override
Clear all messages from the message panel.
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
void SaveAll()
Save all modified symbols and libraries.
void DeleteSymbolFromLibrary()
bool IsLibraryTreeShown() const override
void RenameSymbolTab(const LIB_ID &aOldId, const LIB_ID &aNewId)
Update the open tab for aOldId, if any, to the renamed symbol aNewId so its label and key track the r...
wxString getTargetLib() const
Return either the library selected in the symbol tree, if context menu is active or the library that ...
bool LoadSymbolFromLib(const wxString &aLibName, const wxString &aSymbolName, int aUnit=0, int aBodyStyle=0)
Load a symbol from a library, optionally setting the selected unit and body style.
bool backupLibrary(const wxFileName &aOriginalFile, wxString &aErrorMsg)
Create a backup copy of a symbol library.
EDITOR_TABS_PANEL * m_tabsPanel
bool saveLibrary(const wxString &aLibrary, SAVE_LIBRARY_AS aSaveType=SAVE_LIBRARY_AS::ORIGINAL)
Save the changes to the current library.
void RebuildSymbolUnitAndBodyStyleLists()
int GetTreeLIBIDs(std::vector< LIB_ID > &aSelection) const
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
LIB_SYMBOL_LIBRARY_MANAGER * m_libMgr
void SaveLibraryAs(SAVE_LIBRARY_AS aSaveType=SAVE_LIBRARY_AS::NEW)
Save the currently selected library to a new file.
void Save()
Save the selected symbol or library.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
bool addLibTableEntry(const wxString &aLibFile, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::GLOBAL)
Add aLibFile to the symbol library table defined by aScope.
int m_unit
The unit number to edit and show.
bool LoadOneLibrarySymbol(LIB_SYMBOL *aLibEntry, const wxString &aLibrary, int aUnit, int aBodyStyle)
Create a copy of aLibEntry into memory.
void centerItemIdleHandler(wxIdleEvent &aEvent)
bool replaceLibTableEntry(const wxString &aLibNickname, const wxString &aLibFile)
Replace the file path of the symbol library table entry aLibNickname with aLibFile.
bool IsSymbolFromSchematic() const
LIB_ID closeLibraryTabs(const wxString &aLibrary, const wxString &aSymbol)
Close the library tabs of aLibrary, or of every library when it is empty, limited to aSymbol when giv...
SYMBOL_EDITOR_TAB_CONTEXT * m_activeTab
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
LIB_ID m_centerItemOnIdle
void saveSymbolCopyAs(bool aOpenCopy)
KIID m_schematicSymbolUUID
std::vector< LIB_ID > GetSelectedLibIds() const
void SyncLibraries(bool aShowProgress, bool aPreloadCancelled=false, const wxString &aForceRefresh=wxEmptyString)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
SYMBOL_EDITOR_TAB_CONTEXT * findOrCreateSymbolTab(const wxString &aLib, const wxString &aName, int aUnit, int aBodyStyle, bool aAsPreview, bool *aWasCreated=nullptr)
Open aName from aLib in a tab, creating it when absent, and return the activated context.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
LIB_ID GetTargetLibId() const override
Return either the symbol selected in the symbol tree (if context menu is active) or the symbol on the...
int m_bodyStyle
Show the normal shape (m_bodyStyle <= 1) or the DeMorgan converted shape (m_bodyStyle > 1)
bool saveAllLibraries(bool aRequireConfirmation)
Return true when the operation has succeeded (all requested libraries have been saved or none was sel...
void UpdateMsgPanel() override
Redraw the message panel.
void CreateNewSymbol(const wxString &newName=wxEmptyString)
Create a new symbol in the selected library.
void UpdateTitle()
Update the main window title bar with the current library name and read only status of the library.
SYMBOL_EDITOR_TAB_CONTEXT * CreateUnsavedSymbolTab(LIB_SYMBOL *aSymbol, SCH_SCREEN *aScreen)
Open a new tab over a transient working symbol and screen and make it active.
SYMBOL_TREE_PANE * m_treePane
void SetDrawSpecificUnit(bool aSpecific)
void closeSymbolTab(const LIB_ID &aLibId)
Close the open tab for aLibId, if any, without prompting and leaving the other tabs open.
bool saveCurrentSymbol()
Save the current symbol.
void CopySymbolToClipboard()
void SaveSymbolCopyAs(bool aOpenCopy)
Save the currently selected symbol to a new name and/or location.
void clearSymbolTabsModifiedForLibrary(const wxString &aLibrary)
Clear the unsaved-edits flag on every tab in a saved library so its dirty indicator clears.
wxString AddLibraryFile(bool aCreateNew)
Create or add an existing library to the symbol library table.
void Revert(LIB_ID &aTarget, bool aConfirm=true)
Revert unsaved changes in a symbol, restoring to the last saved state.
void ensureUniqueName(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Rename LIB_SYMBOL aliases to avoid conflicts before adding a symbol to a library.
void UpdateLibraryTree(const wxDataViewItem &aTreeItem, LIB_SYMBOL *aSymbol)
Update a symbol node in the library tree.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
bool IsContentModified() const override
Get if any symbols or libraries have been modified but not saved.
LIB_SYMBOL * getTargetSymbol() const
Return currently edited symbol.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
bool SymbolNameInUse(const wxString &aName, const wxString &aLibrary)
Return true if the symbol name is already in use in the specified library.
LIB_SYMBOL * GetSymbol(const wxString &aSymbolName, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
SYMBOL_SAVEAS_TYPE GetOption() const
This is a class that handles state involved in saving a symbol copy as a new symbol.
CONFLICT_STRATEGY m_strategy
wxString resolveConflict(const wxString &proposed, const wxString &aNewLibName) const
SYMBOL_SAVE_AS_HANDLER(LIB_SYMBOL_LIBRARY_MANAGER &aLibMgr, CONFLICT_STRATEGY aStrategy, bool aValueFollowsName)
LIB_SYMBOL_LIBRARY_MANAGER & m_libMgr
bool DoSave(LIB_SYMBOL &symbol, const wxString &aNewSymName, const wxString &aNewLibName, bool aFlattenSymbol)
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
int UnsavedChangesDialog(wxWindow *parent, const wxString &aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
bool ConfirmRevertDialog(wxWindow *parent, const wxString &aMessage)
Display a confirmation dialog for a revert action.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
static const std::string KiCadSymbolLibFileExtension
static wxString KiCadSymbolLibFileWildcard()
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
@ ALL
All except INITIAL_ADD.
PGM_BASE & Pgm()
The global program "get" accessor.
KIWAY Kiway(KFCTL_STANDALONE)
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString parentSymbolName
bool keepContentUserFields
bool unitsInterchangeable
SYMBOL_SAVE_AS_HANDLER::CONFLICT_STRATEGY m_ConflictStrategy
SAVE_LIBRARY_AS
Types of KiCad symbol library save actions.
@ NEW
Save to a new library in the original symbol library format.
@ UNPACKED
Save a packed symbol library to the unpacked format.
@ PACKED
Save an unpacked symbol library to the packed format.
@ ORIGINAL
Save to the original symbol library format.
static std::vector< wxString > CheckForParentalChainConflicts(LIB_SYMBOL_LIBRARY_MANAGER &aLibMgr, LIB_SYMBOL &aSymbol, bool aFlattenSymbol, const wxString &newSymbolName, const wxString &newLibraryName)
Get a list of all the symbols in the parental chain of a symbol that have conflicts when transposed t...
static std::vector< std::shared_ptr< LIB_SYMBOL > > GetParentChain(const LIB_SYMBOL &aSymbol, bool aIncludeLeaf=true)
Get a list of all the symbols in the parental chain of a symbol, with the "leaf" symbol at the start ...
static std::pair< bool, bool > CheckSavingIntoOwnInheritance(LIB_SYMBOL_LIBRARY_MANAGER &aLibMgr, LIB_SYMBOL &aSymbol, const wxString &aNewSymbolName, const wxString &aNewLibraryName)
Check if a planned overwrite would put a symbol into it's own inheritance chain.
@ ADD_PROJECT_TABLE_ENTRY
JSON_SCHEMA_VALIDATOR validator(schema)
const SHAPE_LINE_CHAIN chain
Definition of file extensions used in Kicad.