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-2019 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 
68  // True to force DeMorgan/normal tools selection enabled.
69  // They are enabled when the loaded component has graphic items for converted shape
70  // But under some circumstances (New component created) these tools must left enabled
71  static bool m_showDeMorgan;
72 
73 public:
93 
94 public:
95  LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
96 
97  ~LIB_EDIT_FRAME() override;
98 
102  void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
103 
109  bool IsContentModified() override;
110 
119  bool HasLibModifications() const;
120 
122  wxString GetCurLib() const;
123 
125  wxString SetCurLib( const wxString& aLibNickname );
126 
128 
132  LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
133 
140 
144  void SetCurPart( LIB_PART* aPart );
145 
147 
148  void ReCreateMenuBar() override;
149 
150  // See comments for m_SyncPinEdit.
151  bool SynchronizePins();
152 
153  void OnImportBody( wxCommandEvent& aEvent );
154  void OnExportBody( wxCommandEvent& aEvent );
155 
159  bool AddLibraryFile( bool aCreateNew );
160 
164  void CreateNewPart();
165 
166  void ImportPart();
167  void ExportPart();
168 
172  void Save();
173 
177  void SaveAs();
178 
182  void SaveAll();
183 
187  void Revert( bool aConfirm = true );
188  void RevertAll();
189 
190  void DeletePartFromLibrary();
191 
192  void CopyPartToClipboard();
193 
194  void LoadPart( const wxString& aLibrary, const wxString& aPart, int Unit );
195 
199  void DuplicatePart( bool aFromClipboard );
200 
201  void OnSelectUnit( wxCommandEvent& event );
202 
203  void OnToggleSearchTree( wxCommandEvent& event );
204 
205  bool IsSearchTreeShown();
206  void FreezeSearchTree();
207  void ThawSearchTree();
208 
209  void OnUpdatePartNumber( wxUpdateUIEvent& event );
210 
211  void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
212  void RebuildSymbolUnitsList();
213 
214  void OnCloseWindow( wxCloseEvent& Event );
215  void OnExitKiCad( wxCommandEvent& event );
216  void ReCreateHToolbar() override;
217  void ReCreateVToolbar() override;
218  void ReCreateOptToolbar() override;
219 
220  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
221  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
222 
224  {
225  return m_settings;
226  }
227 
228  COLOR_SETTINGS* GetColorSettings() override;
229 
236  void CloseWindow( wxCommandEvent& event )
237  {
238  // Generate a wxCloseEvent
239  Close( false );
240  }
241 
246  void OnModify() override;
247 
248  int GetUnit() const { return m_unit; }
249  void SetUnit( int aUnit ) { m_unit = aUnit; }
250 
251  int GetConvert() const { return m_convert; }
252  void SetConvert( int aConvert ) { m_convert = aConvert; }
253 
254  bool GetShowDeMorgan() const { return m_showDeMorgan; }
255  void SetShowDeMorgan( bool show ) { m_showDeMorgan = show; }
256 
257  void ClearMsgPanel() override { DisplayCmpDoc(); }
258 
259 private:
260  // Sets up the tool framework
261  void setupTools();
262 
263  void savePartAs();
264 
274  bool saveLibrary( const wxString& aLibrary, bool aNewFile );
275 
280  void updateTitle();
281 
288  void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
289 
298  wxString SelectLibraryFromList();
299 
309  bool LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit = 0, int aConvert = 0 );
310 
321  bool LoadOneLibraryPartAux( LIB_PART* aLibEntry, const wxString& aLibrary, int aUnit,
322  int aConvert );
323 
327  void DisplayCmpDoc();
328 
329  // General editing
330 public:
337  void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO_T undoType = UR_LIBEDIT,
338  bool aAppend = false );
339 
342 
343  void RollbackPartFromUndo();
344 
345 private:
351  void LoadOneSymbol();
352 
359  void SaveOneSymbol();
360 
361  void refreshSchematic();
362 
363 public:
372  bool LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert );
373 
379  void PrintPage( RENDER_SETTINGS* aSettings ) override;
380 
384  void SVG_PlotComponent( const wxString& aFullFileName );
385 
390  void SyncLibraries( bool aShowProgress );
391 
396  void RegenerateLibraryTree();
397 
401  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
402 
406  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
407 
408  void ShowChangedLanguage() override;
409 
410  void SyncToolbars() override;
411 
412  void SetScreen( BASE_SCREEN* aScreen ) override;
413 
414  const BOX2I GetDocumentExtents() const override;
415 
416  void RebuildView();
417 
421  void HardRedraw() override;
422 
423  void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
424 
426  void emptyScreen();
427 
428 private:
431 
437  SYMBOL_LIB_TABLE* selectSymLibTable( bool aOptional = false );
438 
440  bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
441 
443  LIB_PART* getTargetPart() const;
444 
447  LIB_ID getTargetLibId() const;
448 
451  wxString getTargetLib() const;
452 
453  /* Returns true when the operation has succeeded (all requested libraries have been saved or
454  * none was selected and confirmed by OK).
455  * @param aRequireConfirmation when true, the user must be asked to confirm.
456  */
457  bool saveAllLibraries( bool aRequireConfirmation );
458 
460  bool saveCurrentPart();
461 
463  void storeCurrentPart();
464 
466  bool isCurrentPart( const LIB_ID& aLibId ) const;
467 
469  void ensureUniqueName( LIB_PART* aPart, const wxString& aLibrary );
470 
471  DECLARE_EVENT_TABLE()
472 };
473 
474 #endif // LIB_EDIT_FRAME_H
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:143
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.
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.
LIBEDIT_SETTINGS * m_settings
void LoadPart(const wxString &aLibrary, const wxString &aPart, int Unit)
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
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
void OnCloseWindow(wxCloseEvent &Event)
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.
void LoadOneSymbol()
Read a component symbol file (*.sym ) and add graphic items to the current component.
Definition: symbedit.cpp:43
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.
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:
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)
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.
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
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:91
const BOX2I GetDocumentExtents() const override
bool GetShowDeMorgan() const
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:44
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 CommonSettingsChanged(bool aEnvVarsChanged) override
Called after the preferences dialog is run.
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 DisplayCmpDoc()
Display the documentation of the selected component.
Definition: symbedit.cpp:204
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:37
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
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.
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: base_struct.h:159
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
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
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy, UNDO_REDO_T undoType=UR_LIBEDIT, bool aAppend=false)
Create a copy of the current component, and save it in the undo list.
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