48#include <wx/filedlg.h> 
   62        auto libSelectedCondition =
 
   67                        LIB_ID sel = editFrame->GetTreeLIBID();
 
   77        auto libInferredCondition =
 
   82                        LIB_ID sel = editFrame->GetTreeLIBID();
 
   89        auto symbolSelectedCondition =
 
   94                        LIB_ID sel = editFrame->GetTargetLibId();
 
  101        auto derivedSymbolSelectedCondition =
 
  106                        LIB_ID sel = editFrame->GetTargetLibId();
 
  120        auto multiSymbolSelectedCondition =
 
  158        auto canOpenExternally =
 
  165                        wxString                    libName = editFrame->GetTargetLibId().GetLibNickname();
 
  177        ctxMenu.AddSeparator( 10 );
 
  178        ctxMenu.AddItem( 
ACTIONS::save,                   symbolSelectedCondition || libInferredCondition, 10 );
 
  182        ctxMenu.AddItem( 
ACTIONS::revert,                 symbolSelectedCondition || libInferredCondition, 10 );
 
  184        ctxMenu.AddSeparator( 10 );
 
  192        ctxMenu.AddSeparator( 20 );
 
  195        ctxMenu.AddSeparator( 100 );
 
  202            ctxMenu.AddSeparator( 200 );
 
  208            ctxMenu.AddSeparator( 200 );
 
  209            ctxMenu.AddItem( 
ACTIONS::openDirectory,      canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
 
 
  236    wxString libFile = *aEvent.
Parameter<wxString*>();
 
 
  283                      wxString::Format( 
_( 
"Failed to load symbol %s from " 
 
  301    if( libName.IsEmpty() )
 
  303        msg.Printf( 
_( 
"No symbol library selected." ) );
 
  304        m_frame->ShowInfoBarError( msg );
 
  310        msg.Printf( 
_( 
"Symbol library '%s' not found." ), libName );
 
  311        m_frame->ShowInfoBarError( msg );
 
  317        msg.Printf( 
_( 
"Symbol library '%s' is not writable." ), libName );
 
  318        m_frame->ShowInfoBarError( msg );
 
 
  375    std::optional<wxString> libItemName =
 
  378    wxCHECK( libItemName, 0 );
 
  380    wxFileName fileName( *libItemName );
 
  382    wxString filePath = wxEmptyString;
 
  383    wxString explorerCommand;
 
  386        explorerCommand = cfg->m_System.file_explorer;
 
  388    if( explorerCommand.IsEmpty() )
 
  390        filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
 
  392        if( !filePath.IsEmpty() && wxDirExists( filePath ) )
 
  398    if( !explorerCommand.EndsWith( 
"%F" ) )
 
  400        wxMessageBox( 
_( 
"Missing/malformed file explorer argument '%F' in common settings." ) );
 
  404    filePath = fileName.GetFullPath();
 
  405    filePath.Replace( wxS( 
"\"" ), wxS( 
"_" ) );
 
  407    wxString fileArg = 
'"' + filePath + 
'"';
 
  409    explorerCommand.Replace( wxT( 
"%F" ), fileArg );
 
  411    if( !explorerCommand.IsEmpty() )
 
  412        wxExecute( explorerCommand );
 
 
  426    if( textEditorName.IsEmpty() )
 
  428        wxMessageBox( 
_( 
"No text editor selected in KiCad. Please choose one." ) );
 
  437    std::optional<wxString> optUri =
 
  440    wxCHECK( optUri, 0 );
 
  442    wxString tempFName = ( *optUri ).wc_str();
 
  444    if( !tempFName.IsEmpty() )
 
  445        ExecuteFile( textEditorName, tempFName, 
nullptr, 
false );
 
 
  463        bool hasWritableLibs = 
false;
 
  468            const wxString& libName = sel.GetLibNickname();
 
  471                msg.Printf( 
_( 
"Symbol library '%s' not found." ), libName );
 
  473                msg.Printf( 
_( 
"Symbol library '%s' is not writable." ), libName );
 
  475                hasWritableLibs = 
true;
 
  479            m_frame->ShowInfoBarError( msg );
 
  481        if( !hasWritableLibs )
 
 
  503    if( !sel.
IsValid() && !isPasteAction )
 
  506        msg.Printf( 
_( 
"No symbol selected" ) );
 
  507        m_frame->ShowInfoBarError( msg );
 
  515        msg.Printf( 
_( 
"Symbol library '%s' not found." ), libName );
 
  516        m_frame->ShowInfoBarError( msg );
 
  522        msg.Printf( 
_( 
"Symbol library '%s' is not writable." ), libName );
 
  523        m_frame->ShowInfoBarError( msg );
 
 
  543    wxString oldName = libId.GetLibItemName();
 
  551            [&]( 
const wxString& aNewName )
 
  555                if( newName.IsEmpty() )
 
  557                    wxMessageBox( 
_( 
"Symbol must have a name." ) );
 
  564                    msg.Printf( 
_( 
"Symbol '%s' already exists in library '%s'." ),
 
  569                                       wxOK | wxCANCEL | wxICON_WARNING );
 
  571                    errorDlg.SetOKLabel( 
_( 
"Overwrite" ) );
 
  582    if( newName == oldName )
 
  592    bool       overwritingCurrentSymbol = 
false;
 
  610    if( overwritingCurrentSymbol )
 
  635    wxDataViewItem treeItem = libMgr.
GetAdapter()->FindItem( libId );
 
 
  658    m_frame->GetCanvas()->Refresh();
 
 
  671    m_frame->GetCanvas()->Refresh();
 
 
  701    m_frame->GetCanvas()->Refresh();
 
 
  719    m_frame->GetCanvas()->Refresh();
 
 
  735    m_frame->GetCanvas()->Refresh();
 
 
  750        wxMessageBox( 
_( 
"No symbol to export" ) );
 
  754    wxFileName fn( symbol->
GetName() );
 
  757    wxString projectPath = wxPathOnly( 
m_frame->Prj().GetProjectFullName() );
 
  759    wxFileDialog dlg( editFrame, 
_( 
"Export View as PNG" ), projectPath, fn.GetFullName(),
 
  762    if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
 
  770            wxMessageBox( wxString::Format( 
_( 
"Can't save file '%s'." ), dlg.GetPath() ) );
 
 
  797        wxMessageBox( 
_( 
"No symbol to export" ) );
 
  801    wxFileName fn( symbol->
GetName() );
 
  804    wxString pro_dir = wxPathOnly( 
m_frame->Prj().GetProjectFullName() );
 
  806    wxString fullFileName = wxFileSelector( 
_( 
"SVG File Name" ), pro_dir, fn.GetFullName(),
 
  811    if( !fullFileName.IsEmpty() )
 
 
  848        wxMessageBox( 
_( 
"No symbol to flatten" ) );
 
  853    std::unique_ptr<LIB_SYMBOL> flatSymbol = symbol->
Flatten();
 
  854    wxCHECK_MSG( flatSymbol, 0, 
_( 
"Failed to flatten symbol" ) );
 
  858        wxMessageBox( 
_( 
"Failed to update library with flattened symbol" ) );
 
  862    wxDataViewItem treeItem = libMgr.
GetAdapter()->FindItem( symId );
 
 
  910        if( blocking_dialog )
 
  912            blocking_dialog->Raise();
 
 
  943    const int          deltaUnit = aEvent.
Parameter<
int>();
 
  946    const int newUnit = ( ( editFrame->
GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
 
 
constexpr EDA_IU_SCALE schIUScale
 
static TOOL_ACTION showLibraryFieldsTable
 
static TOOL_ACTION openWithTextEditor
 
static TOOL_ACTION revert
 
static TOOL_ACTION addLibrary
 
static TOOL_ACTION openDirectory
 
static TOOL_ACTION showRelatedLibraryFieldsTable
 
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.
 
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
 
constexpr const Vec & GetOrigin() const
 
constexpr const SizeVec & GetSize() const
 
bool SaveCanvasImageToFile(const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
 
virtual void ToggleProperties()
 
virtual void SetParent(EDA_ITEM *aParent)
 
virtual const wxString & GetText() const
Return the string associated with the text object.
 
AUTOPLACE_FIELDS m_AutoplaceFields
 
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) const
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
 
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true, bool aIgnoreLabelsOnInvisiblePins=true) const
Get the bounding box for the symbol.
 
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)
 
Describe the page size and margins of a paper page on which to eventually print or plot.
 
void SetHeightMils(double aHeightInMils)
 
void SetWidthMils(double aWidthInMils)
 
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 editLibSymbolWithLibEdit
 
static TOOL_ACTION pasteSymbol
 
static TOOL_ACTION exportSymbolAsSVG
 
static TOOL_ACTION renameSymbol
 
static TOOL_ACTION duplicateSymbol
 
static TOOL_ACTION cutSymbol
 
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 showHiddenPins
 
static TOOL_ACTION showPinNumbers
 
static TOOL_ACTION exportSymbolView
 
static TOOL_ACTION copySymbol
 
static TOOL_ACTION toggleSyncedPinsMode
 
static TOOL_ACTION deleteSymbol
 
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()
 
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
 
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
 
void SetText(const wxString &aText) override
 
bool m_ShowPinsElectricalType
 
const PAGE_INFO & GetPageSettings() const
 
void SetPageSettings(const PAGE_INFO &aPageSettings)
 
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Automatically orient all the fields in the symbol.
 
int ToggleSyncedPinsMode(const TOOL_EVENT &aEvent)
 
int Save(const TOOL_EVENT &aEvt)
 
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 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)
 
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 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)
 
bool m_ShowPinAltIcons
When true, dragging an outline edge will drag pins rooted on it.
 
The symbol library editor main window.
 
void SaveAll()
Save all modified symbols and libraries.
 
void DeleteSymbolFromLibrary()
 
bool IsLibraryTreeShown() const override
 
bool IsCurrentSymbol(const LIB_ID &aLibId) const
Restore the empty editor screen, without any symbol or library selected.
 
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 SVGPlotSymbol(const wxString &aFullFileName, const VECTOR2I &aOffset)
Create the SVG print file for the current edited symbol.
 
void Save()
Save the selected symbol or library.
 
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
 
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
 
int GetTreeSelectionCount() const
 
bool IsSymbolFromSchematic() 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 UpdateTitle()
Update the main window title bar with the current library name and read only status of the 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)
 
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.
 
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.
 
@ 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 SVGFileExtension
 
static wxString PngFileWildcard()
 
static wxString SVGFileWildcard()
 
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
 
@ 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:...
 
VECTOR2< int32_t > VECTOR2I
 
Definition of file extensions used in Kicad.