KiCad PCB EDA Suite
symbol_edit_frame.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6  * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
7  * Copyright (C) 2017 CERN
8  * @author Maciej Suminski <[email protected]>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #ifndef SYMBOL_EDIT_FRAME_H
29 #define SYMBOL_EDIT_FRAME_H
30 
31 #include <sch_base_frame.h>
32 #include <sch_screen.h>
33 #include <lib_item.h>
34 #include <ee_collectors.h>
35 #include <core/optional.h>
36 
37 class SCH_EDIT_FRAME;
38 class SYMBOL_LIB_TABLE;
39 class LIB_SYMBOL;
40 class LIB_FIELD;
42 class SYMBOL_TREE_PANE;
43 class LIB_TREE_NODE;
44 class LIB_ID;
47 
48 
53 {
54 public:
55  SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
56 
57  ~SYMBOL_EDIT_FRAME() override;
58 
62  void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
63 
69  bool IsContentModified() const override;
70 
79  bool HasLibModifications() const;
80 
81  bool CanCloseSymbolFromSchematic( bool doClose );
82 
86  wxString GetCurLib() const;
87 
91  wxString SetCurLib( const wxString& aLibNickname );
92 
94 
98  LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
99 
105  LIB_SYMBOL* GetCurSymbol() const { return m_symbol; }
106 
110  void SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom );
111 
113 
114  SELECTION& GetCurrentSelection() override;
115 
116  void ReCreateMenuBar() override;
117 
118  // See comments for m_SyncPinEdit.
119  bool SynchronizePins();
120 
124  bool AddLibraryFile( bool aCreateNew );
125 
129  void CreateNewSymbol();
130 
131  void ImportSymbol();
132  void ExportSymbol();
133 
137  void Save();
138 
142  void SaveSymbolAs();
143 
147  void SaveLibraryAs();
148 
152  void SaveAll();
153 
157  void Revert( bool aConfirm = true );
158  void RevertAll();
159 
161 
162  void CopySymbolToClipboard();
163 
164  void LoadSymbol( const wxString& aLibrary, const wxString& aSymbol, int Unit );
165 
171  void DuplicateSymbol( bool aFromClipboard );
172 
173  void OnSelectUnit( wxCommandEvent& event );
174 
175  void OnToggleSymbolTree( wxCommandEvent& event );
176 
177  bool IsSymbolTreeShown() const;
178  void FreezeLibraryTree();
179  void ThawLibraryTree();
180 
181  void OnUpdateUnitNumber( wxUpdateUIEvent& event );
182 
183  void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
184  void RebuildSymbolUnitsList();
185 
186  bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
187  void doCloseWindow() override;
188  void OnExitKiCad( wxCommandEvent& event );
189  void ReCreateHToolbar() override;
190  void ReCreateVToolbar() override;
191  void ReCreateOptToolbar() override;
192 
193  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
194  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
195 
197  {
198  return m_settings;
199  }
200 
201  APP_SETTINGS_BASE* config() const override;
202 
203  COLOR_SETTINGS* GetColorSettings() const override;
204 
211  void CloseWindow( wxCommandEvent& event )
212  {
213  // Generate a wxCloseEvent
214  Close( false );
215  }
216 
221  void OnModify() override;
222 
223  int GetUnit() const { return m_unit; }
224  void SetUnit( int aUnit ) { m_unit = aUnit; }
225 
226  int GetConvert() const { return m_convert; }
227  void SetConvert( int aConvert ) { m_convert = aConvert; }
228 
229  bool GetShowDeMorgan() const { return m_showDeMorgan; }
230  void SetShowDeMorgan( bool show ) { m_showDeMorgan = show; }
231 
232  void ClearMsgPanel() override
233  {
235  }
236 
238 
239  bool IsSymbolFromLegacyLibrary() const;
240 
245 
246  // General editing
253  void SaveCopyInUndoList( EDA_ITEM* aItem, UNDO_REDO aUndoType = UNDO_REDO::LIBEDIT,
254  bool aAppend = false );
255 
256  void GetSymbolFromUndoList();
257  void GetSymbolFromRedoList();
258 
259  void RollbackSymbolFromUndo();
260 
273  void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override;
274 
283  bool LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConvert );
284 
288  void PrintPage( const RENDER_SETTINGS* aSettings ) override;
289 
293  void SVGPlotSymbol( const wxString& aFullFileName );
294 
299  void SyncLibraries( bool aShowProgress, bool aPreloadCancelled = false,
300  const wxString& aForceRefresh = wxEmptyString );
301 
307  void RegenerateLibraryTree();
308 
312  void RefreshLibraryTree();
313 
317  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
318 
322  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
323 
324  void ShowChangedLanguage() override;
325 
326  void SetScreen( BASE_SCREEN* aScreen ) override;
327 
328  const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
329 
330  void RebuildView();
331 
335  void HardRedraw() override;
336 
337  void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
338 
344  void LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol );
345 
356  bool IsSymbolEditable() const;
357 
358  bool IsSymbolAlias() const;
359 
361  void emptyScreen();
362 
365  LIB_ID GetTargetLibId() const;
366 
367 protected:
368  void setupUIConditions() override;
369 
370 private:
371  // Set up the tool framework
372  void setupTools();
373 
374  void saveSymbolAs();
375 
386  bool saveLibrary( const wxString& aLibrary, bool aNewFile );
387 
392  void updateTitle();
393 
400  void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
401 
410  wxString SelectLibraryFromList();
411 
421  bool LoadSymbolFromCurrentLib( const wxString& aAliasName, int aUnit = 0, int aConvert = 0 );
422 
433  bool LoadOneLibrarySymbolAux( LIB_SYMBOL* aLibEntry, const wxString& aLibrary, int aUnit,
434  int aConvert );
435 
442  SYMBOL_LIB_TABLE* selectSymLibTable( bool aOptional = false );
443 
445  bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
446 
448  LIB_SYMBOL* getTargetSymbol() const;
449 
452  wxString getTargetLib() const;
453 
454  void centerItemIdleHandler( wxIdleEvent& aEvent );
455 
456  /*
457  * Return true when the operation has succeeded (all requested libraries have been saved
458  * or none was selected and confirmed by OK).
459  *
460  * @param aRequireConfirmation when true, the user must be asked to confirm.
461  */
462  bool saveAllLibraries( bool aRequireConfirmation );
463 
465  bool saveCurrentSymbol();
466 
468  void storeCurrentSymbol();
469 
471  bool isCurrentSymbol( const LIB_ID& aLibId ) const;
472 
474  void ensureUniqueName( LIB_SYMBOL* aSymbol, const wxString& aLibrary );
475 
477  {
480  };
481 
491  bool addLibTableEntry( const wxString& aLibFile, TABLE_SCOPE aScope = GLOBAL_LIB_TABLE );
492 
503  bool replaceLibTableEntry( const wxString& aLibNickname, const wxString& aLibFile );
504 
505  DECLARE_EVENT_TABLE()
506 
507 public:
530 
531 private:
534 
535  LIB_SYMBOL* m_symbol; // a symbol I own, it is not in any library, but a
536  // copy could be.
537  wxComboBox* m_unitSelectBox; // a ComboBox to select a unit to edit (if the
538  // symbol has multiple units)
539  SYMBOL_TREE_PANE* m_treePane; // symbol search tree widget
540  SYMBOL_LIBRARY_MANAGER* m_libMgr; // manager taking care of temporary modifications
541  SYMBOL_EDITOR_SETTINGS* m_settings; // Handle to the settings
542 
544 
545  // The unit number to edit and show
546  int m_unit;
547 
548  // Show the normal shape ( m_convert <= 1 ) or the converted shape ( m_convert > 1 )
550 
554 
556  wxString m_reference;
557 
558  // True to force DeMorgan/normal tools selection enabled.
559  // They are enabled when the loaded symbol has graphic items for converted shape
560  // But under some circumstances (New symbol created) these tools must left enabled
561  static bool m_showDeMorgan;
562 };
563 
564 #endif // SYMBOL_EDIT_FRAME_H
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
void ShowChangedLanguage() override
COLOR_SETTINGS * GetColorSettings() const override
Returns a pointer to the active color theme settings.
int m_convert
Flag if the symbol being edited was loaded directly from a schematic.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:38
void Revert(bool aConfirm=true)
Revert unsaved changes in a symbol, restoring to the last saved state.
void SelectActiveLibrary(const wxString &aLibrary=wxEmptyString)
Set the current active library to aLibrary.
SCH_SCREEN * m_dummyScreen
< Helper screen used when no symbol is loaded
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void OnUpdateUnitNumber(wxUpdateUIEvent &event)
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Return currently edited symbol.
void SetScreen(BASE_SCREEN *aScreen) override
void SetShowDeMorgan(bool show)
SYMBOL_EDITOR_SETTINGS * GetSettings() const
Field object used in symbol libraries.
Definition: lib_field.h:59
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void ensureUniqueName(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
SYMBOL_TREE_PANE * m_treePane
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
Switch currently used canvas ( Cairo / OpenGL).
void Save()
Save the selected symbol or library.
void PrintPage(const RENDER_SETTINGS *aSettings) override
Print a page.
void storeCurrentSymbol()
Return true if aLibId is an alias for the editor screen symbol.
void SaveAll()
Save all modified symbols and libraries.
static bool m_showDeMorgan
Schematic editor (Eeschema) main window.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
bool LoadOneLibrarySymbolAux(LIB_SYMBOL *aLibEntry, const wxString &aLibrary, int aUnit, int aConvert)
Create a copy of aLibEntry into memory.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Define a library symbol object.
Definition: lib_symbol.h:96
LIB_TREE_NODE * GetCurrentTreeNode() const
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
SYMBOL_LIB_TABLE * selectSymLibTable(bool aOptional=false)
Display a dialog asking the user to select a symbol library table.
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
void OnSelectUnit(wxCommandEvent &event)
bool GetShowDeMorgan() const
bool IsSymbolFromSchematic() const
bool IsSymbolTreeShown() const
LIB_SYMBOL * getTargetSymbol() const
Return either the library selected in the symbol tree, if context menu is active or the library that ...
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
Library Editor pane with symbol tree and symbol library table selector.
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
Definition: kiid.h:44
void SetUnit(int aUnit)
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
SYMBOL_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
void updateTitle()
Update the main window title bar with the current library name and read only status of the library.
void SaveSymbolAs()
Save the currently selected symbol to a new name and/or location.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
bool IsSymbolAlias() const
Restore the empty editor screen, without any symbol or library selected.
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
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 ...
void SetConvert(int aConvert)
Class to handle modifications to the symbol libraries.
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
void SaveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT, bool aAppend=false)
Create a copy of the current symbol, and save it in the undo list.
wxString getTargetLib() const
SYMBOL_LIBRARY_MANAGER & GetLibManager()
void HardRedraw() override
Rebuild the GAL and redraw the screen.
bool CanCloseSymbolFromSchematic(bool doClose)
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
void ReCreateHToolbar() override
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
wxString SelectLibraryFromList()
Display a list of loaded libraries in the symbol library and allows the user to select a library.
bool replaceLibTableEntry(const wxString &aLibNickname, const wxString &aLibFile)
Replace the file path of the symbol library table entry aLibNickname with aLibFile.
void DeleteSymbolFromLibrary()
void ClearMsgPanel() override
Clear all messages from the message panel.
bool saveCurrentSymbol()
Store the currently modified symbol in the library manager buffer.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
void OnToggleSymbolTree(wxCommandEvent &event)
bool isCurrentSymbol(const LIB_ID &aLibId) const
Rename LIB_SYMBOL aliases to avoid conflicts before adding a symbol to a library.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow the symbol editor to install its preferences panel into the preferences dialog.
bool HasLibModifications() const
Check if any pending libraries have been modified.
void ReCreateMenuBar() override
Recreates the menu bar.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
bool addLibTableEntry(const wxString &aLibFile, TABLE_SCOPE aScope=GLOBAL_LIB_TABLE)
Add aLibFile to the symbol library table defined by aScope.
void centerItemIdleHandler(wxIdleEvent &aEvent)
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
bool saveLibrary(const wxString &aLibrary, bool aNewFile)
Save the changes to the current library.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
UNDO_REDO_LIST
Specifies whether we are interacting with the undo or redo stacks.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
bool LoadSymbolFromCurrentLib(const wxString &aAliasName, int aUnit=0, int aConvert=0)
Load a symbol from the current active library, optionally setting the selected unit and convert.
void doCloseWindow() override
APP_SETTINGS_BASE * config() const override
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
LIB_ID GetTargetLibId() const
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Receive KIWAY_EXPRESS messages from other players.
bool IsContentModified() const override
Get if any symbols or libraries have been modified but not saved.
void ReCreateOptToolbar() override
void RefreshLibraryTree()
Redisplay the library tree.
SYMBOL_EDITOR_SETTINGS * m_settings
Schematic symbol object.
Definition: sch_symbol.h:78
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
bool saveAllLibraries(bool aRequireConfirmation)
Save the current symbol.
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
void OnExitKiCad(wxCommandEvent &event)
void ReCreateVToolbar() override
Color settings are a bit different than most of the settings objects in that there can be more than o...
SYMBOL_LIBRARY_MANAGER * m_libMgr
bool AddLibraryFile(bool aCreateNew)
Create or add an existing library to the symbol library table.
void SaveLibraryAs()
Save the currently selected library to a new file.
void emptyScreen()
Return either the symbol selected in the symbol tree, if context menu is active or the currently modi...
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
bool IsSymbolFromLegacyLibrary() const
wxString SetCurLib(const wxString &aLibNickname)
Set the current library nickname and returns the old library nickname.
wxComboBox * m_unitSelectBox
KIID m_schematicSymbolUUID
RefDes of the symbol (only valid if symbol was loaded from schematic)
void CreateNewSymbol()
Create a new symbol in the selected library.
void SVGPlotSymbol(const wxString &aFullFileName)
Create the SVG print file for the current edited symbol.
The symbol library editor main window.