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 The 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 <symbol_tree_pane.h>
34#include <optional>
35
36class SCH_EDIT_FRAME;
37class LIB_SYMBOL;
38class LIB_TREE_NODE;
39class LIB_ID;
42class EDA_LIST_DIALOG;
43
44
45#define UNITS_ALL _HKI( "ALL" )
46#define DEMORGAN_ALL _HKI( "ALL" )
47#define DEMORGAN_STD _HKI( "Standard" )
48#define DEMORGAN_ALT _HKI( "Alternate" )
49
50
55{
56public:
57 SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
58
59 ~SYMBOL_EDIT_FRAME() override;
60
61 std::unique_ptr<GRID_HELPER> MakeGridHelper() override;
62
66 void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
67
73 bool IsContentModified() const override;
74
83 bool HasLibModifications() const;
84
85 bool CanCloseSymbolFromSchematic( bool doClose );
86
90 wxString GetCurLib() const;
91
95 wxString SetCurLib( const wxString& aLibNickname );
96
97 LIB_TREE* GetLibTree() const override { return m_treePane->GetLibTree(); }
98
102 LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
103
104 int GetTreeSelectionCount() const;
105
106 int GetTreeLIBIDs( std::vector<LIB_ID>& aSelection ) const;
107
113 LIB_SYMBOL* GetCurSymbol() const { return m_symbol; }
114
118 void SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom );
119
121
122 SELECTION& GetCurrentSelection() override;
123
124 // See comments for m_SyncPinEdit.
125 bool SynchronizePins();
126
130 wxString AddLibraryFile( bool aCreateNew );
131
135 void DdAddLibrary( wxString aLibFile );
136
143 void CreateNewSymbol( const wxString& newName = wxEmptyString );
144
145 void ImportSymbol();
146 void ExportSymbol();
147
151 void Save();
152
156 void SaveSymbolCopyAs( bool aOpenCopy );
157
161 void SaveLibraryAs();
162
166 void SaveAll();
167
171 void Revert( bool aConfirm = true );
172 void RevertAll();
173
175
177
178 void LoadSymbol( const wxString& aLibrary, const wxString& aSymbol, int Unit );
179
185 void DuplicateSymbol( bool aFromClipboard );
186
187 void OnSelectUnit( wxCommandEvent& event );
188 void OnSelectBodyStyle( wxCommandEvent& event );
189
190 void ToggleProperties() override;
191
192 void ToggleLibraryTree() override;
193 bool IsLibraryTreeShown() const override;
194 void FocusLibraryTreeInput() override;
195 void FreezeLibraryTree();
196 void ThawLibraryTree();
197
198 void OnUpdateUnitNumber( wxUpdateUIEvent& event );
199 void OnUpdateBodyStyle( wxUpdateUIEvent& event );
200
201 void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
203
204 bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
205 void doCloseWindow() override;
206 void OnExitKiCad( wxCommandEvent& event );
207
208 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
209 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
210
212 {
213 return m_settings;
214 }
215
216 APP_SETTINGS_BASE* config() const override;
217
218 COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override;
219
226 void CloseWindow( wxCommandEvent& event )
227 {
228 // Generate a wxCloseEvent
229 Close( false );
230 }
231
236 void OnModify() override;
237
238 int GetUnit() const { return m_unit; }
239 void SetUnit( int aUnit );
240
241 int GetBodyStyle() const { return m_bodyStyle; }
242 void SetBodyStyle( int aBodyStyle );
243
246
247 void ClearMsgPanel() override
248 {
250 }
251
252 void UpdateMsgPanel() override
253 {
255 }
256
261 void UpdateTitle();
262
264 {
265 // If we've already vetted closing this window, then we have no symbol anymore
266 if( m_isClosing )
267 return false;
268
270 }
271
272 bool IsSymbolFromLegacyLibrary() const;
273
278
279 // General editing
286 void SaveCopyInUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbol,
287 UNDO_REDO aUndoType = UNDO_REDO::LIBEDIT );
288
289 void PushSymbolToUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbolCopy,
290 UNDO_REDO aUndoType = UNDO_REDO::LIBEDIT );
291
294
307 void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override;
308
317 bool LoadSymbol( const LIB_ID& aLibId, int aUnit, int aBodyStyle );
318
324 void SVGPlotSymbol( const wxString& aFullFileName, const VECTOR2I& aOffset );
325
330 void SyncLibraries( bool aShowProgress, bool aPreloadCancelled = false,
331 const wxString& aForceRefresh = wxEmptyString );
332
336 void RefreshLibraryTree();
337
341 void UpdateLibraryTree( const wxDataViewItem& aTreeItem, LIB_SYMBOL* aSymbol );
342
347 LIB_ID GetTargetLibId() const override;
348
352 std::vector<LIB_ID> GetSelectedLibIds() const;
353
354 void FocusOnLibId( const LIB_ID& aLibID );
355
359 void CommonSettingsChanged( int aFlags ) override;
360
361 void ShowChangedLanguage() override;
362
363 void SetScreen( BASE_SCREEN* aScreen ) override;
364
365 const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
366
367 void RebuildView();
368
369 void UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete = false,
370 bool aUpdateRtree = false ) override;
371
375 void HardRedraw() override;
376
377 void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
378
379 void FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll = true ) override;
380
386 void LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol );
387
398 bool IsSymbolEditable() const;
399
400 bool IsSymbolAlias() const;
401
403 bool IsCurrentSymbol( const LIB_ID& aLibId ) const;
404
406 void emptyScreen();
407
408protected:
409 void configureToolbars() override;
410 void setupUIConditions() override;
411
412 void doReCreateMenuBar() override;
413
414 void updateSelectionFilterVisbility() override;
415
416private:
417 // Set up the tool framework
418 void setupTools();
419
420 void saveSymbolCopyAs( bool aOpenCopy );
421
432 bool saveLibrary( const wxString& aLibrary, bool aNewFile );
433
440 void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
441
451 bool LoadSymbolFromCurrentLib( const wxString& aSymbolName, int aUnit = 0, int aBodyStyle = 0 );
452
463 bool LoadOneLibrarySymbolAux( LIB_SYMBOL* aLibEntry, const wxString& aLibrary, int aUnit,
464 int aBodyStyle );
465
467 bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
468
471
474 wxString getTargetLib() const;
475
476 void centerItemIdleHandler( wxIdleEvent& aEvent );
477
478 /*
479 * Return true when the operation has succeeded (all requested libraries have been saved
480 * or none was selected and confirmed by OK).
481 *
482 * @param aRequireConfirmation when true, the user must be asked to confirm.
483 */
484 bool saveAllLibraries( bool aRequireConfirmation );
485
487 bool saveCurrentSymbol();
488
490 void storeCurrentSymbol();
491
493 void ensureUniqueName( LIB_SYMBOL* aSymbol, const wxString& aLibrary );
494
504 bool addLibTableEntry( const wxString& aLibFile,
506
517 bool replaceLibTableEntry( const wxString& aLibNickname, const wxString& aLibFile );
518
519 DECLARE_EVENT_TABLE()
520
521public:
544
545private:
548
549 LIB_SYMBOL* m_symbol; // a symbol I own, it is not in any library, but a copy could be.
550 wxComboBox* m_unitSelectBox; // a ComboBox to select a unit to edit (if the
551 // symbol has multiple units)
552 wxComboBox* m_bodyStyleSelectBox; // a ComboBox to select a body style to edit (if the symbol has
553 // multiple body styles)
554 SYMBOL_TREE_PANE* m_treePane; // symbol search tree widget
555 LIB_SYMBOL_LIBRARY_MANAGER* m_libMgr; // manager taking care of temporary modifications
556 SYMBOL_EDITOR_SETTINGS* m_settings; // Handle to the settings
557
559
560 // The unit number to edit and show
562
563 // Show the normal shape (m_bodyStyle <= 1) or the DeMorgan converted shape (m_bodyStyle > 1)
565
569
571 wxString m_reference;
572
573 // True to force DeMorgan/normal tools selection enabled.
574 // They are enabled when the loaded symbol has graphic items for converted shape
575 // But under some circumstances (New symbol created) these tools must left enabled
576 static bool m_showDeMorgan;
577};
578
579#endif // SYMBOL_EDIT_FRAME_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
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
Specify whether we are interacting with the undo or redo stacks.
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
A dialog which shows:
Definition kiid.h:49
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:291
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
Symbol library management helper that is specific to the symbol library editor frame.
Define a library symbol object.
Definition lib_symbol.h:87
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
Widget displaying a tree of symbols with optional search text control and description panel.
Definition lib_tree.h:48
SCH_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aWindowType, const wxString &aTitle, const wxPoint &aPosition, const wxSize &aSize, long aStyle, const wxString &aFrameName)
Schematic editor (Eeschema) main window.
Schematic symbol object.
Definition sch_symbol.h:75
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.
std::unique_ptr< GRID_HELPER > MakeGridHelper() override
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 setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
APP_SETTINGS_BASE * config() const override
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void storeCurrentSymbol()
Rename LIB_SYMBOL aliases to avoid conflicts before adding a symbol to a library.
bool IsLibraryTreeShown() const override
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box 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.
void OnSelectBodyStyle(wxCommandEvent &event)
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 CommonSettingsChanged(int aFlags) override
Called after the preferences dialog is run.
void FocusLibraryTreeInput() override
wxComboBox * m_unitSelectBox
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
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
void FocusOnLibId(const LIB_ID &aLibID)
void SVGPlotSymbol(const wxString &aFullFileName, const VECTOR2I &aOffset)
Create the SVG print file for the current edited symbol.
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
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)
void HardRedraw() override
Rebuild the GAL and redraw the screen.
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 addLibTableEntry(const wxString &aLibFile, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::GLOBAL)
Add aLibFile to the symbol library table defined by aScope.
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 SetScreen(BASE_SCREEN *aScreen) override
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 saveSymbolCopyAs(bool aOpenCopy)
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)
SYMBOL_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
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 ...
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
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 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 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.
LIB_TREE * GetLibTree() const override
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.
bool LoadSymbolFromCurrentLib(const wxString &aSymbolName, int aUnit=0, int aBodyStyle=0)
Load a symbol from the current active library, optionally setting the selected unit and convert.
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 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 OnUpdateBodyStyle(wxUpdateUIEvent &event)
void SaveSymbolCopyAs(bool aOpenCopy)
Save the currently selected symbol to a new name and/or location.
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 FocusOnItem(EDA_ITEM *aItem, bool aAllowScroll=true) override
Focus on a particular canvas item.
void configureToolbars() 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:
wxComboBox * m_bodyStyleSelectBox
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 ShowChangedLanguage() override
Redraw the menus and what not in current language.
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 ToggleLibraryTree() override
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.
LIBRARY_TABLE_SCOPE
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695