KiCad PCB EDA Suite
lib_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 <stambaughw@gmail.com>
6  * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  * Copyright (C) 2017 CERN
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 LIB_EDIT_FRAME_H
29 #define LIB_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_PART;
40 class LIB_FIELD;
42 class SYMBOL_TREE_PANE;
43 class LIB_TREE_NODE;
44 class LIB_ID;
45 class LIB_MANAGER;
46 class LIBEDIT_SETTINGS;
47 
48 
53 {
54  LIB_PART* m_my_part; // a part I own, it is not in any library, but a copy
55  // could be.
56  wxComboBox* m_unitSelectBox; // a ComboBox to select a unit to edit (if the part
57  // has multiple units)
58  SYMBOL_TREE_PANE* m_treePane; // component search tree widget
59  LIB_MANAGER* m_libMgr; // manager taking care of temporary modifications
60  LIBEDIT_SETTINGS* m_settings; // Handle to the settings
61 
62  // The unit number to edit and show
63  int m_unit;
64 
65  // Show the normal shape ( m_convert <= 1 ) or the converted shape ( m_convert > 1 )
66  int m_convert;
67 
70 
76  wxString m_reference;
77 
78  // True to force DeMorgan/normal tools selection enabled.
79  // They are enabled when the loaded component has graphic items for converted shape
80  // But under some circumstances (New component created) these tools must left enabled
81  static bool m_showDeMorgan;
82 
83 public:
103 
104 public:
105  LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
106 
107  ~LIB_EDIT_FRAME() override;
108 
112  void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
113 
119  bool IsContentModified() override;
120 
129  bool HasLibModifications() const;
130 
132  wxString GetCurLib() const;
133 
135  wxString SetCurLib( const wxString& aLibNickname );
136 
138 
142  LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
143 
150 
154  void SetCurPart( LIB_PART* aPart );
155 
157 
158  SELECTION& GetCurrentSelection() override;
159 
160  void ReCreateMenuBar() override;
161 
162  // See comments for m_SyncPinEdit.
163  bool SynchronizePins();
164 
165  void OnImportBody( wxCommandEvent& aEvent );
166  void OnExportBody( wxCommandEvent& aEvent );
167 
171  bool AddLibraryFile( bool aCreateNew );
172 
176  void CreateNewPart();
177 
178  void ImportPart();
179  void ExportPart();
180 
184  void Save();
185 
189  void SaveAs();
190 
194  void SaveAll();
195 
199  void Revert( bool aConfirm = true );
200  void RevertAll();
201 
202  void DeletePartFromLibrary();
203 
204  void CopyPartToClipboard();
205 
206  void LoadPart( const wxString& aLibrary, const wxString& aPart, int Unit );
207 
211  void DuplicatePart( bool aFromClipboard );
212 
213  void OnSelectUnit( wxCommandEvent& event );
214 
215  void OnToggleSearchTree( wxCommandEvent& event );
216 
217  bool IsSearchTreeShown();
218  void FreezeSearchTree();
219  void ThawSearchTree();
220 
221  void OnUpdatePartNumber( wxUpdateUIEvent& event );
222 
223  void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
224  void RebuildSymbolUnitsList();
225 
226  bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
227  void doCloseWindow() override;
228  void OnExitKiCad( wxCommandEvent& event );
229  void ReCreateHToolbar() override;
230  void ReCreateVToolbar() override;
231  void ReCreateOptToolbar() override;
232 
233  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
234  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
235 
237  {
238  return m_settings;
239  }
240 
241  COLOR_SETTINGS* GetColorSettings() override;
242 
249  void CloseWindow( wxCommandEvent& event )
250  {
251  // Generate a wxCloseEvent
252  Close( false );
253  }
254 
259  void OnModify() override;
260 
261  int GetUnit() const { return m_unit; }
262  void SetUnit( int aUnit ) { m_unit = aUnit; }
263 
264  int GetConvert() const { return m_convert; }
265  void SetConvert( int aConvert ) { m_convert = aConvert; }
266 
267  bool GetShowDeMorgan() const { return m_showDeMorgan; }
268  void SetShowDeMorgan( bool show ) { m_showDeMorgan = show; }
269 
270  void ClearMsgPanel() override { DisplayCmpDoc(); }
271 
273 
274 protected:
275  void setupUIConditions() override;
276 
277 private:
278  // Sets up the tool framework
279  void setupTools();
280 
281  void savePartAs();
282 
292  bool saveLibrary( const wxString& aLibrary, bool aNewFile );
293 
298  void updateTitle();
299 
306  void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
307 
316  wxString SelectLibraryFromList();
317 
327  bool LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit = 0, int aConvert = 0 );
328 
339  bool LoadOneLibraryPartAux( LIB_PART* aLibEntry, const wxString& aLibrary, int aUnit,
340  int aConvert );
341 
342 public:
346  void DisplayCmpDoc();
347 
348  // General editing
355  void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO undoType = UNDO_REDO::LIBEDIT,
356  bool aAppend = false );
357 
360 
361  void RollbackPartFromUndo();
362 
375  void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override;
376 
377 private:
383  void LoadOneSymbol();
384 
391  void SaveOneSymbol();
392 
393  void refreshSchematic();
394 
395 public:
404  bool LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert );
405 
411  void PrintPage( RENDER_SETTINGS* aSettings ) override;
412 
416  void SVG_PlotComponent( const wxString& aFullFileName );
417 
422  void SyncLibraries( bool aShowProgress );
423 
428  void RegenerateLibraryTree();
429 
433  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
434 
438  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
439 
440  void ShowChangedLanguage() override;
441 
442  void SetScreen( BASE_SCREEN* aScreen ) override;
443 
444  const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
445 
446  void RebuildView();
447 
451  void HardRedraw() override;
452 
453  void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
454 
463  void LoadSymbolFromSchematic( const std::unique_ptr<LIB_PART>& aSymbol,
464  const wxString& aReference, int aUnit, int aConvert );
465 
467  void emptyScreen();
468 
469 private:
472 
478  SYMBOL_LIB_TABLE* selectSymLibTable( bool aOptional = false );
479 
481  bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
482 
484  LIB_PART* getTargetPart() const;
485 
488  LIB_ID getTargetLibId() const;
489 
492  wxString getTargetLib() const;
493 
494  /* Returns true when the operation has succeeded (all requested libraries have been saved or
495  * none was selected and confirmed by OK).
496  * @param aRequireConfirmation when true, the user must be asked to confirm.
497  */
498  bool saveAllLibraries( bool aRequireConfirmation );
499 
501  bool saveCurrentPart();
502 
504  void storeCurrentPart();
505 
507  bool isCurrentPart( const LIB_ID& aLibId ) const;
508 
510  void ensureUniqueName( LIB_PART* aPart, const wxString& aLibrary );
511 
512  DECLARE_EVENT_TABLE()
513 };
514 
515 #endif // LIB_EDIT_FRAME_H
void doCloseWindow() override
void SVG_PlotComponent(const wxString &aFullFileName)
Creates the SVG print file for the current edited component.
void OnToggleSearchTree(wxCommandEvent &event)
void DuplicatePart(bool aFromClipboard)
Inserts a duplicate part.
void OnUpdatePartNumber(wxUpdateUIEvent &event)
void SaveOneSymbol()
Saves the current symbol to a symbol file.
Definition: symbedit.cpp:142
KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
bool LoadComponentFromCurrentLib(const wxString &aAliasName, int aUnit=0, int aConvert=0)
Loads a symbol from the current active library, optionally setting the selected unit and convert.
int m_convert
Flag if the symbol being edited was loaded directly from a schematic.
void HardRedraw() override
Rebuild the GAL and redraw the screen.
int GetConvert() const
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allows Libedit to install its preferences panel into the preferences dialog.
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy, UNDO_REDO undoType=UNDO_REDO::LIBEDIT, bool aAppend=false)
Create a copy of the current component, and save it in the undo list.
LIBEDIT_SETTINGS * m_settings
void LoadPart(const wxString &aLibrary, const wxString &aPart, int Unit)
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
void OnImportBody(wxCommandEvent &aEvent)
Field object used in symbol libraries.
Definition: lib_field.h:59
LIB_MANAGER * m_libMgr
void SelectActiveLibrary(const wxString &aLibrary=wxEmptyString)
Set the current active library to aLibrary.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
wxString SelectLibraryFromList()
Display a list of loaded libraries in the symbol library and allows the user to select a library.
bool LoadOneLibraryPartAux(LIB_PART *aLibEntry, const wxString &aLibrary, int aUnit, int aConvert)
Create a copy of aLibEntry into memory.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void LoadSymbolFromSchematic(const std::unique_ptr< LIB_PART > &aSymbol, const wxString &aReference, int aUnit, int aConvert)
Load a symbol from the schematic to edit in place.
void LoadOneSymbol()
Read a component symbol file (*.sym ) and add graphic items to the current component.
Definition: symbedit.cpp:42
Schematic editor (Eeschema) main window.
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
switches currently used canvas ( Cairo / OpenGL).
LIB_PART * GetCurPart()
Return the current part being edited or NULL if none selected.
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if aLibId is an alias for the editor screen part.
wxString m_reference
The reference of the symbol.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
LIB_PART * m_my_part
void PrintPage(RENDER_SETTINGS *aSettings) override
Print a page.
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
void SetShowDeMorgan(bool show)
void Save()
Saves the selected part or library.
Library Editor pane with component tree and symbol library table selector.
void OnExportBody(wxCommandEvent &aEvent)
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
bool AddLibraryFile(bool aCreateNew)
Creates or adds an existing library to the symbol library table.
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
void SaveAs()
Saves the selected part or library to a new name and/or location.
int GetUnit() const
LIB_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
bool saveLibrary(const wxString &aLibrary, bool aNewFile)
Saves the changes to the current library.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
bool GetShowDeMorgan() const
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
void ReCreateMenuBar() override
Recreates the menu bar.
void SaveAll()
Saves all modified parts and libraries.
void SetUnit(int aUnit)
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
bool IsSymbolFromSchematic() const
Define a library symbol object.
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
void ReCreateOptToolbar() override
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
void GetComponentFromRedoList()
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
bool LoadComponentAndSelectLib(const LIB_ID &aLibId, int aUnit, int aConvert)
Selects the currently active library and loads the symbol from aLibId.
void RebuildSymbolUnitsList()
void emptyScreen()
Restores the empty editor screen, without any part or library selected.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void DisplayCmpDoc()
Display the documentation of the selected component.
Definition: symbedit.cpp:203
void updateTitle()
Updates the main window title bar with the current library name and read only status of the library.
void ImportPart()
Definition: lib_export.cpp:36
bool IsContentModified() override
Get if any parts or libraries have been modified but not saved.
void ensureUniqueName(LIB_PART *aPart, const wxString &aLibrary)
Renames LIB_PART aliases to avoid conflicts before adding a component to a library
UNDO_REDO_LIST
Function ClearUndoORRedoList (virtual).
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:99
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void storeCurrentPart()
Stores the currently modified part in the library manager buffer.
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Creates a backup copy of a file with requested extension
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
The symbol library editor main window.
void ReCreateHToolbar() override
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
bool HasLibModifications() const
Check if any pending libraries have been modified.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
bool saveCurrentPart()
Saves the current part.
bool saveAllLibraries(bool aRequireConfirmation)
void SetCurPart(LIB_PART *aPart)
Take ownership of aPart and notes that it is the one currently being edited.
bool m_isSymbolFromSchematic
void SetScreen(BASE_SCREEN *aScreen) override
void CreateNewPart()
Creates a new part in the selected library.
void SetConvert(int aConvert)
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
LIBEDIT_SETTINGS * GetSettings()
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
void OnSelectUnit(wxCommandEvent &event)
LIB_PART * getTargetPart() const
Returns currently edited part.
Color settings are a bit different than most of the settings objects in that there can be more than o...
SCH_SCREEN * m_dummyScreen
Helper screen used when no part is loaded
wxString SetCurLib(const wxString &aLibNickname)
Sets the current library nickname and returns the old library nickname.
SYMBOL_LIB_TABLE * selectSymLibTable(bool aOptional=false)
Displays a dialog asking the user to select a symbol library table.
void ClearMsgPanel() override
Clear all messages from the message panel.
COLOR_SETTINGS * GetColorSettings() override
Returns a pointer to the active color theme settings.
static bool m_showDeMorgan
wxComboBox * m_unitSelectBox
SYMBOL_TREE_PANE * m_treePane
LIB_MANAGER & GetLibManager()
LIB_TREE_NODE * GetCurrentTreeNode() const
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void Revert(bool aConfirm=true)
Reverts unsaved changes in a part, restoring to the last saved state.
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
~LIB_EDIT_FRAME() override
wxString getTargetLib() const
Returns either the library selected in the component tree, if context menu is active or the library t...
void OnExitKiCad(wxCommandEvent &event)
void ReCreateVToolbar() override