KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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 <optional>
36
37class SCH_EDIT_FRAME;
39class LIB_SYMBOL;
40class LIB_FIELD;
43class LIB_TREE_NODE;
44class LIB_ID;
47class EDA_LIST_DIALOG;
48
49
54{
55public:
56 SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
57
58 ~SYMBOL_EDIT_FRAME() override;
59
63 void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
64
70 bool IsContentModified() const override;
71
80 bool HasLibModifications() const;
81
82 bool CanCloseSymbolFromSchematic( bool doClose );
83
87 wxString GetCurLib() const;
88
92 wxString SetCurLib( const wxString& aLibNickname );
93
95
99 LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
100
101 int GetTreeSelectionCount() const;
102
103 int GetTreeLIBIDs( std::vector<LIB_ID>& aSelection ) const;
104
110 LIB_SYMBOL* GetCurSymbol() const { return m_symbol; }
111
115 void SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom );
116
118
119 SELECTION& GetCurrentSelection() override;
120
121 // See comments for m_SyncPinEdit.
122 bool SynchronizePins();
123
127 wxString AddLibraryFile( bool aCreateNew );
128
132 void DdAddLibrary( wxString aLibFile );
133
140 void CreateNewSymbol( const wxString& newName = wxEmptyString );
141
142 void ImportSymbol();
143 void ExportSymbol();
144
148 void Save();
149
153 void SaveSymbolCopyAs();
154
158 void SaveLibraryAs();
159
163 void SaveAll();
164
168 void Revert( bool aConfirm = true );
169 void RevertAll();
170
172
174
175 void LoadSymbol( const wxString& aLibrary, const wxString& aSymbol, int Unit );
176
182 void DuplicateSymbol( bool aFromClipboard );
183
184 void OnSelectUnit( wxCommandEvent& event );
185
186 void OnToggleSymbolTree( wxCommandEvent& event );
187
188 void ToggleProperties() override;
189
190 bool IsSymbolTreeShown() const;
191 void FreezeLibraryTree();
192 void ThawLibraryTree();
193
194 void OnUpdateUnitNumber( wxUpdateUIEvent& event );
195
196 void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
198
199 bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
200 void doCloseWindow() override;
201 void OnExitKiCad( wxCommandEvent& event );
202 void ReCreateHToolbar() override;
203 void ReCreateVToolbar() override;
204 void ReCreateOptToolbar() override;
205
206 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
207 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
208
210 {
211 return m_settings;
212 }
213
214 APP_SETTINGS_BASE* config() const override;
215
216 COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override;
217
224 void CloseWindow( wxCommandEvent& event )
225 {
226 // Generate a wxCloseEvent
227 Close( false );
228 }
229
234 void OnModify() override;
235
236 int GetUnit() const { return m_unit; }
237 void SetUnit( int aUnit ) { m_unit = aUnit; }
238
239 int GetBodyStyle() const { return m_bodyStyle; }
240 void SetBodyStyle( int aBodyStyle ) { m_bodyStyle = aBodyStyle; }
241
242 bool GetShowDeMorgan() const { return m_showDeMorgan; }
243 void SetShowDeMorgan( bool show ) { m_showDeMorgan = show; }
244
247
248 void ClearMsgPanel() override
249 {
251 }
252
253 void UpdateMsgPanel() override
254 {
256 }
257
262 void UpdateTitle();
263
265 {
266 // If we've already vetted closing this window, then we have no symbol anymore
267 if( m_isClosing )
268 return false;
269
271 }
272
273 bool IsSymbolFromLegacyLibrary() const;
274
279
280 // General editing
287 void SaveCopyInUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbol,
288 UNDO_REDO aUndoType = UNDO_REDO::LIBEDIT );
289
290 void PushSymbolToUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbolCopy,
291 UNDO_REDO aUndoType = UNDO_REDO::LIBEDIT );
292
295
308 void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override;
309
318 bool LoadSymbol( const LIB_ID& aLibId, int aUnit, int aBodyStyle );
319
323 void PrintPage( const RENDER_SETTINGS* aSettings ) override;
324
330 void SVGPlotSymbol( const wxString& aFullFileName, VECTOR2I aOffset );
331
336 void SyncLibraries( bool aShowProgress, bool aPreloadCancelled = false,
337 const wxString& aForceRefresh = wxEmptyString );
338
345
349 void RefreshLibraryTree();
350
354 void UpdateLibraryTree( const wxDataViewItem& aTreeItem, LIB_SYMBOL* aSymbol );
355
360 LIB_ID GetTargetLibId() const;
361
365 std::vector<LIB_ID> GetSelectedLibIds() const;
366
367 void FocusOnLibId( const LIB_ID& aLibID );
368
372 void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
373
374 void ShowChangedLanguage() override;
375
376 void SetScreen( BASE_SCREEN* aScreen ) override;
377
378 const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
379
380 void RebuildView();
381
382 void UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete = false,
383 bool aUpdateRtree = false ) override;
384
388 void HardRedraw() override;
389
390 void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
391
392 void FocusOnItem( LIB_ITEM* aItem );
393
399 void LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol );
400
411 bool IsSymbolEditable() const;
412
413 bool IsSymbolAlias() const;
414
416 bool IsCurrentSymbol( const LIB_ID& aLibId ) const;
417
419 void emptyScreen();
420
421protected:
422 void setupUIConditions() override;
423
424 void doReCreateMenuBar() override;
425
426 void updateSelectionFilterVisbility() override;
427
428private:
429 // Set up the tool framework
430 void setupTools();
431
432 void saveSymbolCopyAs();
433
444 bool saveLibrary( const wxString& aLibrary, bool aNewFile );
445
452 void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
453
463 bool LoadSymbolFromCurrentLib( const wxString& aAliasName, int aUnit = 0, int aBodyStyle = 0 );
464
475 bool LoadOneLibrarySymbolAux( LIB_SYMBOL* aLibEntry, const wxString& aLibrary, int aUnit,
476 int aBodyStyle );
477
479 bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
480
483
486 wxString getTargetLib() const;
487
488 void centerItemIdleHandler( wxIdleEvent& aEvent );
489
490 /*
491 * Return true when the operation has succeeded (all requested libraries have been saved
492 * or none was selected and confirmed by OK).
493 *
494 * @param aRequireConfirmation when true, the user must be asked to confirm.
495 */
496 bool saveAllLibraries( bool aRequireConfirmation );
497
499 bool saveCurrentSymbol();
500
502 void storeCurrentSymbol();
503
505 void ensureUniqueName( LIB_SYMBOL* aSymbol, const wxString& aLibrary );
506
508 {
511 };
512
522 bool addLibTableEntry( const wxString& aLibFile, TABLE_SCOPE aScope = GLOBAL_LIB_TABLE );
523
534 bool replaceLibTableEntry( const wxString& aLibNickname, const wxString& aLibFile );
535
536 DECLARE_EVENT_TABLE()
537
538public:
561
562private:
565
566 LIB_SYMBOL* m_symbol; // a symbol I own, it is not in any library, but a
567 // copy could be.
568 wxComboBox* m_unitSelectBox; // a ComboBox to select a unit to edit (if the
569 // symbol has multiple units)
570 SYMBOL_TREE_PANE* m_treePane; // symbol search tree widget
571 LIB_SYMBOL_LIBRARY_MANAGER* m_libMgr; // manager taking care of temporary modifications
572 SYMBOL_EDITOR_SETTINGS* m_settings; // Handle to the settings
573
575
576 // The unit number to edit and show
578
579 // Show the normal shape (m_bodyStyle <= 1) or the DeMorgan converted shape (m_bodyStyle > 1)
581
585
587 wxString m_reference;
588
589 // True to force DeMorgan/normal tools selection enabled.
590 // They are enabled when the loaded symbol has graphic items for converted shape
591 // But under some circumstances (New symbol created) these tools must left enabled
592 static bool m_showDeMorgan;
593};
594
595#endif // SYMBOL_EDIT_FRAME_H
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
Color settings are a bit different than most of the settings objects in that there can be more than o...
UNDO_REDO_LIST
Specifies whether we are interacting with the undo or redo stacks.
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
A dialog which shows:
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Definition: kiid.h:49
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
Field object used in symbol libraries.
Definition: lib_field.h:62
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Symbol library management helper that is specific to the symbol library editor frame.
Define a library symbol object.
Definition: lib_symbol.h:99
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Schematic editor (Eeschema) main window.
Schematic symbol object.
Definition: sch_symbol.h:109
The symbol library editor main window.
void ClearMsgPanel() override
Clear all messages from the message panel.
void OnExitKiCad(wxCommandEvent &event)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
void SaveAll()
Save all modified symbols and libraries.
void FocusOnItem(LIB_ITEM *aItem)
void DeleteSymbolFromLibrary()
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
APP_SETTINGS_BASE * config() const override
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
bool addLibTableEntry(const wxString &aLibFile, TABLE_SCOPE aScope=GLOBAL_LIB_TABLE)
Add aLibFile to the symbol library table defined by aScope.
void storeCurrentSymbol()
Rename LIB_SYMBOL aliases to avoid conflicts before adding a symbol to a library.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
wxString getTargetLib() const
bool IsCurrentSymbol(const LIB_ID &aLibId) const
Restore the empty editor screen, without any symbol or library selected.
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Return currently edited symbol.
void RefreshLibraryTree()
Redisplay the library tree.
void updateSelectionFilterVisbility() override
Selection filter panel doesn't have a dedicated visibility control, so show it if any other AUI panel...
void ReCreateVToolbar() override
wxComboBox * m_unitSelectBox
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
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
LIB_ID GetTargetLibId() const
Return either the symbol selected in the symbol tree (if context menu is active) or the symbol on the...
void FocusOnLibId(const LIB_ID &aLibID)
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
void PrintPage(const RENDER_SETTINGS *aSettings) override
Print a page.
void ToggleProperties() override
void Save()
Save the selected symbol or library.
SYMBOL_EDITOR_SETTINGS * m_settings
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
int GetBodyStyle() const
void HardRedraw() override
Rebuild the GAL and redraw the screen.
bool GetShowDeMorgan() const
bool IsSymbolTreeShown() const
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
int GetTreeSelectionCount() const
void PushSymbolToUndoList(const wxString &aDescription, LIB_SYMBOL *aSymbolCopy, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT)
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
bool CanCloseSymbolFromSchematic(bool doClose)
void Revert(bool aConfirm=true)
Revert unsaved changes in a symbol, restoring to the last saved state.
bool IsSymbolFromLegacyLibrary() const
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
void OnToggleSymbolTree(wxCommandEvent &event)
static bool m_showDeMorgan
void SetScreen(BASE_SCREEN *aScreen) override
void SaveSymbolCopyAs()
Save the currently selected symbol to a new name and/or location.
void SaveCopyInUndoList(const wxString &aDescription, LIB_SYMBOL *aSymbol, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT)
Create a copy of the current symbol, and save it in the undo list.
SYMBOL_EDITOR_SETTINGS * GetSettings() const
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
SCH_SCREEN * m_dummyScreen
< Helper screen used when no symbol is loaded
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Receive KIWAY_EXPRESS messages from other players.
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
KIID m_schematicSymbolUUID
RefDes of the symbol (only valid if symbol was loaded from schematic)
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
std::vector< LIB_ID > GetSelectedLibIds() const
LIB_TREE_NODE * GetCurrentTreeNode() 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 ...
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
void OnSelectUnit(wxCommandEvent &event)
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void SetBodyStyle(int aBodyStyle)
bool saveLibrary(const wxString &aLibrary, bool aNewFile)
Save the changes to the current library.
void SelectActiveLibrary(const wxString &aLibrary=wxEmptyString)
Set the current active library to aLibrary.
int m_bodyStyle
Flag if the symbol being edited was loaded directly from a schematic.
bool saveAllLibraries(bool aRequireConfirmation)
Save the current symbol.
void SetUnit(int aUnit)
void UpdateMsgPanel() override
Redraw the message panel.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
void CreateNewSymbol(const wxString &newName=wxEmptyString)
Create a new symbol in the selected library.
wxString SetCurLib(const wxString &aLibNickname)
Set the current library nickname and returns the old library nickname.
void UpdateTitle()
Update the main window title bar with the current library name and read only status of the library.
void ReCreateHToolbar() override
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void SVGPlotSymbol(const wxString &aFullFileName, VECTOR2I aOffset)
Create the SVG print file for the current edited symbol.
bool HasLibModifications() const
Check if any pending libraries have been modified.
SYMBOL_TREE_PANE * m_treePane
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
bool LoadOneLibrarySymbolAux(LIB_SYMBOL *aLibEntry, const wxString &aLibrary, int aUnit, int aBodyStyle)
Create a copy of aLibEntry into memory.
bool LoadSymbolFromCurrentLib(const wxString &aAliasName, int aUnit=0, int aBodyStyle=0)
Load a symbol from the current active library, optionally setting the selected unit and convert.
bool saveCurrentSymbol()
Store the currently modified symbol in the library manager buffer.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
Switch currently used canvas ( Cairo / OpenGL).
void doCloseWindow() override
void DdAddLibrary(wxString aLibFile)
Add a library dropped file to the symbol library table.
wxString AddLibraryFile(bool aCreateNew)
Create or add an existing library to the symbol library table.
void ReCreateOptToolbar() override
void ensureUniqueName(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
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 SetShowDeMorgan(bool show)
void ShowChangedLanguage() override
void SaveLibraryAs()
Save the currently selected library to a new file.
bool IsContentModified() const override
Get if any symbols or libraries have been modified but not saved.
void doReCreateMenuBar() override
LIB_SYMBOL * getTargetSymbol() const
Return either the library selected in the symbol tree, if context menu is active or the library that ...
void OnUpdateUnitNumber(wxUpdateUIEvent &event)
Library Editor pane with symbol tree and symbol library table selector.
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...