47#include <wx/filedlg.h>
71 auto libSelectedCondition =
76 LIB_ID sel = editFrame->GetTreeLIBID();
86 auto libInferredCondition =
91 LIB_ID sel = editFrame->GetTreeLIBID();
98 auto symbolSelectedCondition =
103 LIB_ID sel = editFrame->GetTargetLibId();
110 auto derivedSymbolSelectedCondition =
115 LIB_ID sel = editFrame->GetTargetLibId();
129 auto relatedSymbolSelectedCondition =
134 LIB_ID sel = editFrame->GetTargetLibId();
150 auto multiSymbolSelectedCondition =
188 auto canOpenExternally =
195 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
207 ctxMenu.AddSeparator( 10 );
208 ctxMenu.AddItem(
ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
212 ctxMenu.AddItem(
ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
214 ctxMenu.AddSeparator( 20 );
218 ctxMenu.AddSeparator( 100 );
225 ctxMenu.AddSeparator( 120 );
231 ctxMenu.AddSeparator( 200 );
237 ctxMenu.AddItem(
ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
239 ctxMenu.AddSeparator( 300 );
264 wxString libFile = *aEvent.
Parameter<wxString*>();
311 wxString::Format(
_(
"Failed to load symbol %s from "
329 if( libName.IsEmpty() )
331 msg.Printf(
_(
"No symbol library selected." ) );
332 m_frame->ShowInfoBarError( msg );
338 msg.Printf(
_(
"Symbol library '%s' not found." ), libName );
339 m_frame->ShowInfoBarError( msg );
345 msg.Printf(
_(
"Symbol library '%s' is not writable." ), libName );
346 m_frame->ShowInfoBarError( msg );
403 std::optional<wxString> libItemName =
406 wxCHECK( libItemName, 0 );
408 wxFileName fileName( *libItemName );
410 wxString filePath = wxEmptyString;
411 wxString explorerCommand;
414 explorerCommand = cfg->m_System.file_explorer;
416 if( explorerCommand.IsEmpty() )
418 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
420 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
426 if( !explorerCommand.EndsWith(
"%F" ) )
428 wxMessageBox(
_(
"Missing/malformed file explorer argument '%F' in common settings." ) );
432 filePath = fileName.GetFullPath();
433 filePath.Replace( wxS(
"\"" ), wxS(
"_" ) );
435 wxString fileArg =
'"' + filePath +
'"';
437 explorerCommand.Replace( wxT(
"%F" ), fileArg );
439 if( !explorerCommand.IsEmpty() )
440 wxExecute( explorerCommand );
454 if( textEditorName.IsEmpty() )
456 wxMessageBox(
_(
"No text editor selected in KiCad. Please choose one." ) );
465 std::optional<wxString> optUri =
468 wxCHECK( optUri, 0 );
470 wxString tempFName = ( *optUri ).wc_str();
472 if( !tempFName.IsEmpty() )
473 ExecuteFile( textEditorName, tempFName,
nullptr,
false );
491 bool hasWritableLibs =
false;
496 const wxString& libName = sel.GetLibNickname();
499 msg.Printf(
_(
"Symbol library '%s' not found." ), libName );
501 msg.Printf(
_(
"Symbol library '%s' is not writable." ), libName );
503 hasWritableLibs =
true;
507 m_frame->ShowInfoBarError( msg );
509 if( !hasWritableLibs )
531 if( !sel.
IsValid() && !isPasteAction )
534 msg.Printf(
_(
"No symbol selected" ) );
535 m_frame->ShowInfoBarError( msg );
543 msg.Printf(
_(
"Symbol library '%s' not found." ), libName );
544 m_frame->ShowInfoBarError( msg );
550 msg.Printf(
_(
"Symbol library '%s' is not writable." ), libName );
551 m_frame->ShowInfoBarError( msg );
571 wxString oldName = libId.GetLibItemName();
579 [&](
const wxString& aNewName )
583 if( newName.IsEmpty() )
585 wxMessageBox(
_(
"Symbol must have a name." ) );
592 msg.Printf(
_(
"Symbol '%s' already exists in library '%s'." ),
597 wxOK | wxCANCEL | wxICON_WARNING );
599 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
610 if( newName == oldName )
620 bool overwritingCurrentSymbol =
false;
638 if( overwritingCurrentSymbol )
664 wxDataViewItem treeItem = libMgr.
GetAdapter()->FindItem( libId );
687 m_frame->GetCanvas()->Refresh();
700 m_frame->GetCanvas()->Refresh();
714 cfg->m_SyncPinEdit = !cfg->m_SyncPinEdit;
732 m_frame->GetCanvas()->Refresh();
748 m_frame->GetCanvas()->Refresh();
764 m_frame->GetCanvas()->Refresh();
779 wxMessageBox(
_(
"No symbol to export" ) );
783 wxFileName fn( symbol->
GetName() );
786 wxString projectPath = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
788 wxFileDialog dlg( editFrame,
_(
"Export View as PNG" ), projectPath, fn.GetFullName(),
793 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
801 wxMessageBox( wxString::Format(
_(
"Can't save file '%s'." ), dlg.GetPath() ) );
828 wxMessageBox(
_(
"No symbol to export" ) );
832 wxFileName fn( symbol->
GetName() );
835 wxString pro_dir = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
837 wxString fullFileName = wxFileSelector(
_(
"SVG File Name" ), pro_dir, fn.GetFullName(),
842 if( !fullFileName.IsEmpty() )
863 wxMessageBox(
_(
"No symbol to flatten" ) );
868 std::unique_ptr<LIB_SYMBOL> flatSymbol = symbol->
Flatten();
869 wxCHECK_MSG( flatSymbol, 0,
_(
"Failed to flatten symbol" ) );
873 wxMessageBox(
_(
"Failed to update library with flattened symbol" ) );
877 wxDataViewItem treeItem = libMgr.
GetAdapter()->FindItem( symId );
925 if( blocking_dialog )
927 blocking_dialog->Raise();
958 const int deltaUnit = aEvent.
Parameter<
int>();
961 const int newUnit = ( ( editFrame->
GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
972 viewerFrame->SelectPreviousSymbol();
981 viewerFrame->SelectNextSymbol();
991 SCOPE scope = SCOPE::SCOPE_LIBRARY;
994 scope = SCOPE::SCOPE_RELATED_SYMBOLS;
1018 wxArrayString labels;
1021 labels.Add( entry.key.AfterFirst(
':' ) );
1023 const int count =
static_cast<int>( labels.GetCount() );
1025 const int next = aForward ? ( active + 1 ) % count : ( active - 1 + count ) % count;
1027 popup->
Popup(
_(
"Switch to Tab" ), labels,
next );
1074 wxCHECK( editFrame, 0 );
1078 if( currentLib.IsEmpty() )
1080 editFrame->
ShowInfoBarError(
_(
"Select a library to compare against a file." ) );
1084 wxFileDialog dlg( editFrame,
_(
"Choose Library to Compare With" ), wxEmptyString,
1086 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1088 if( dlg.ShowModal() != wxID_OK )
1091 wxFileName otherFn( dlg.GetPath() );
1092 otherFn.MakeAbsolute();
1097 _(
"Select a KiCad symbol library file (.kicad_sym)." ) );
1101 const wxString otherPath = otherFn.GetFullPath();
1106 wxArrayString names;
1111 for(
const wxString&
name : names )
1114 beforeMap.emplace( sym->GetName(), sym );
1117 std::vector<std::unique_ptr<LIB_SYMBOL>> afterStorage;
1123 afterStorage = std::move( loaded.first );
1124 afterMap = std::move( loaded.second );
1129 otherPath, ioe.
What() ) );
1132 catch(
const std::exception& e )
1136 wxString::FromUTF8( e.what() ) ) );
1143 auto cloneHolder = std::make_shared<std::vector<std::unique_ptr<LIB_SYMBOL>>>();
1147 std::map<KIID_PATH, const KICAD_DIFF::ITEM_CHANGE*> changesById;
1150 changesById[c.
id] = &c;
1152 dlgDiff.SetChangeSelectedHandler(
1153 [&, cloneHolder](
const KIID_PATH& aId )
1160 auto it = changesById.find( aId );
1162 if( it == changesById.end() || !it->second->refdes )
1165 cloneHolder->clear();
1169 const wxString&
name = *it->second->refdes;
1170 auto beforeIt = beforeMap.find(
name );
1171 auto afterIt = afterMap.find(
name );
1173 std::unique_ptr<LIB_SYMBOL> beforeClone =
1174 beforeIt != beforeMap.end() ? beforeIt->second->Flatten() :
nullptr;
1175 std::unique_ptr<LIB_SYMBOL> afterClone =
1176 afterIt != afterMap.end() ? afterIt->second->Flatten() :
nullptr;
1180 cloneHolder->clear();
1183 cloneHolder->push_back( std::move( beforeClone ) );
1186 cloneHolder->push_back( std::move( afterClone ) );
1189 dlgDiff.ShowModal();
static TOOL_ACTION openWithTextEditor
static TOOL_ACTION revert
static TOOL_ACTION addLibrary
static TOOL_ACTION openDirectory
static TOOL_ACTION saveAll
static TOOL_ACTION showProperties
static TOOL_ACTION newLibrary
static TOOL_ACTION ddAddLibrary
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
File-compare dialog (Phase 7).
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...
HOTKEY_CYCLE_POPUP * GetHotkeyPopup()
bool SaveCanvasImageToFile(const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
virtual void CreateHotkeyPopup()
virtual void ToggleProperties()
virtual void SetParent(EDA_ITEM *aParent)
const std::vector< ENTRY > & Entries() const
The tab strip plus the single shared GAL canvas.
void AdvanceTab(bool aForward)
const EDITOR_TABS_MODEL & Model() const
AUTOPLACE_FIELDS m_AutoplaceFields
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()
Diff two .kicad_sym symbol libraries.
DOCUMENT_DIFF Diff() override
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
static std::pair< std::vector< std::unique_ptr< LIB_SYMBOL > >, SYMBOL_MAP > LoadLibrary(const wxString &aPath)
Convenience: load a .kicad_sym path into a SYMBOL_MAP using SCH_IO_KICAD_SEXPR::EnumerateSymbolLib.
std::map< wxString, const LIB_SYMBOL * > SYMBOL_MAP
Library content is a map of (canonical_name -> LIB_SYMBOL*).
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Module editor specific tools.
bool RenameLibrary(const wxString &aTitle, const wxString &aName, std::function< bool(const wxString &aNewName)> aValidator)
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
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...
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
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.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetAdapter()
Return the adapter object that provides the stored data.
Define a library symbol object.
const LIB_ID & GetLibId() const override
wxString GetName() const override
SCH_FIELD & GetValueField()
Return reference to the value field.
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
virtual void SetName(const wxString &aName)
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
virtual LIBRARY_MANAGER & GetLibraryManager() const
static TOOL_ACTION editSymbol
static TOOL_ACTION importSymbol
static TOOL_ACTION newSymbol
static TOOL_ACTION saveLibraryAs
static TOOL_ACTION previousSymbol
static TOOL_ACTION showRelatedLibFieldsTable
static TOOL_ACTION editLibSymbolWithLibEdit
static TOOL_ACTION pasteSymbol
static TOOL_ACTION exportSymbolAsSVG
static TOOL_ACTION renameSymbol
static TOOL_ACTION duplicateSymbol
static TOOL_ACTION closeSymbolTab
static TOOL_ACTION cutSymbol
static TOOL_ACTION compareLibraryWithFile
static TOOL_ACTION saveSymbolCopyAs
static TOOL_ACTION nextUnit
static TOOL_ACTION showElectricalTypes
static TOOL_ACTION flattenSymbol
static TOOL_ACTION placeSymbol
static TOOL_ACTION showHiddenFields
static TOOL_ACTION nextSymbol
static TOOL_ACTION prevSymbolTab
static TOOL_ACTION showHiddenPins
static TOOL_ACTION showPinNumbers
static TOOL_ACTION exportSymbolView
static TOOL_ACTION showLibFieldsTable
static TOOL_ACTION copySymbol
static TOOL_ACTION symbolProperties
static TOOL_ACTION toggleSyncedPinsMode
static TOOL_ACTION deleteSymbol
static TOOL_ACTION nextSymbolTab
static TOOL_ACTION togglePinAltIcons
static TOOL_ACTION exportSymbol
static TOOL_ACTION previousUnit
static TOOL_ACTION deriveFromExistingSymbol
static TOOL_ACTION addSymbolToSchematic
static TOOL_ACTION saveSymbolAs
SCH_RENDER_SETTINGS * GetRenderSettings()
EESCHEMA_SETTINGS * eeconfig() const
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetText(const wxString &aText) override
bool m_ShowPinsElectricalType
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Automatically orient all the fields in the symbol.
int PreviousSymbol(const TOOL_EVENT &aEvent)
int ToggleSyncedPinsMode(const TOOL_EVENT &aEvent)
int Save(const TOOL_EVENT &aEvt)
int PrevTab(const TOOL_EVENT &aEvent)
int EditSymbol(const TOOL_EVENT &aEvent)
int ExportView(const TOOL_EVENT &aEvent)
int ShowElectricalTypes(const TOOL_EVENT &aEvent)
int FlattenSymbol(const TOOL_EVENT &aEvent)
int OpenDirectory(const TOOL_EVENT &aEvent)
int RenameSymbol(const TOOL_EVENT &newName)
int DuplicateSymbol(const TOOL_EVENT &aEvent)
int ToggleHiddenPins(const TOOL_EVENT &aEvent)
int ShowLibraryTable(const TOOL_EVENT &aEvent)
int AddLibrary(const TOOL_EVENT &aEvent)
int AddSymbol(const TOOL_EVENT &aEvent)
int CloseTab(const TOOL_EVENT &aEvent)
int TogglePinAltIcons(const TOOL_EVENT &aEvent)
int ChangeUnit(const TOOL_EVENT &aEvent)
int Revert(const TOOL_EVENT &aEvent)
int ToggleHiddenFields(const TOOL_EVENT &aEvent)
int OpenWithTextEditor(const TOOL_EVENT &aEvent)
int ExportSymbol(const TOOL_EVENT &aEvent)
int NextTab(const TOOL_EVENT &aEvent)
int NextSymbol(const TOOL_EVENT &aEvent)
void setTransitions() override
< Set up handlers for various events.
int ToggleProperties(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
int EditLibrarySymbol(const TOOL_EVENT &aEvent)
int CompareLibraryWithFile(const TOOL_EVENT &aEvent)
Diff the currently-open symbol library against another .kicad_sym file.
int ExportSymbolAsSVG(const TOOL_EVENT &aEvent)
int ShowPinNumbers(const TOOL_EVENT &aEvent)
int DdAddLibrary(const TOOL_EVENT &aEvent)
int AddSymbolToSchematic(const TOOL_EVENT &aEvent)
int CutCopyDelete(const TOOL_EVENT &aEvent)
The symbol library editor main window.
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...
bool IsCurrentSymbol(const LIB_ID &aLibId) const
Restore the empty editor screen, without any symbol or library selected.
void SVGPlotSymbol(const wxString &aFullFileName)
Create the SVG print file for the current edited symbol.
EDITOR_TABS_PANEL * GetTabsPanel() const
The tab strip fronting the shared canvas, or nullptr before it is mounted.
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
void FocusOnLibId(const LIB_ID &aLibID)
void Save()
Save the selected symbol or library.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
int GetTreeSelectionCount() const
bool IsSymbolFromSchematic() const
SYMBOL_EDITOR_SETTINGS * GetSettings() const
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
std::vector< LIB_ID > GetSelectedLibIds() const
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
LIB_ID GetTargetLibId() const override
Return either the symbol selected in the symbol tree (if context menu is active) or the symbol on the...
void UpdateMsgPanel() override
Redraw the message panel.
void CreateNewSymbol(const wxString &newName=wxEmptyString)
Create a new symbol in the selected library.
void CopySymbolToClipboard()
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SaveSymbolCopyAs(bool aOpenCopy)
Save the currently selected symbol to a new name and/or location.
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.
void SaveLibraryAs()
Save the currently selected library to a new file.
void ToggleLibraryTree() override
bool IsLibraryReadOnly(const wxString &aLibrary) const
Return true if the library is stored in a read-only file.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
LIB_SYMBOL * GetBufferedSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool SymbolNameInUse(const wxString &aName, const wxString &aLibrary)
Return true if the symbol name is already in use in the specified library.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
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...
bool RemoveSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Remove the symbol from the symbol buffer.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &aOldSymbolName, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
void SetSymbolModified(const wxString &aSymbolName, const wxString &aLibrary)
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
bool SymbolExists(const wxString &aSymbolName, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
bool HasDerivedSymbols(const wxString &aSymbolName, const wxString &aLibraryName)
Check whether any symbol inherits from aSymbolName, without building the list of names.
Symbol library viewer main window.
LIB_SYMBOL * GetSelectedSymbol() const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
@ FRAME_SCH_SYMBOL_EDITOR
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
static const std::string KiCadSymbolLibFileExtension
static const std::string SVGFileExtension
static wxString PngFileWildcard()
static wxString SVGFileWildcard()
static wxString KiCadSymbolLibFileWildcard()
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
void ConfigureSymDiffCanvasContext(WIDGET_DIFF_CANVAS &aCanvas, LIB_SYMBOL *aBefore, LIB_SYMBOL *aAfter)
@ REPAINT
Item needs to be redrawn.
PGM_BASE & Pgm()
The global program "get" accessor.
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:...
The full set of changes between two parsed documents of one type.
One change record on a single item.
static void showTabSwitcher(SYMBOL_EDIT_FRAME *aFrame, bool aForward)
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.