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_ID;
44 class LIB_MANAGER;
45 
46 
51 {
52  LIB_PART* m_my_part; // a part I own, it is not in any library, but a copy
53  // could be.
54  wxComboBox* m_unitSelectBox; // a ComboBox to select a unit to edit (if the part
55  // has multiple units)
56  SYMBOL_TREE_PANE* m_treePane; // component search tree widget
57  LIB_MANAGER* m_libMgr; // manager taking care of temporary modifications
58 
59  // The unit number to edit and show
60  int m_unit;
61 
62  // Show the normal shape ( m_convert <= 1 ) or the converted shape ( m_convert > 1 )
63  int m_convert;
64 
65  // True to force DeMorgan/normal tools selection enabled.
66  // They are enabled when the loaded component has graphic items for converted shape
67  // But under some circumstances (New component created) these tools must left enabled
68  static bool m_showDeMorgan;
69 
70  static int m_textPinNumDefaultSize; // The default pin num text size setting.
71  static int m_textPinNameDefaultSize; // The default pin name text size setting.
72  static int m_defaultPinLength; // Default pin length
73 
76 
78 
79 public:
99 
102 
110 
111  static int g_LastTextSize;
112  static double g_LastTextAngle;
114  static int g_LastLineWidth;
115 
116 public:
117  LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
118 
119  ~LIB_EDIT_FRAME() override;
120 
124  void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
125 
131  bool IsContentModified() override;
132 
141  bool HasLibModifications() const;
142 
144  wxString GetCurLib() const;
145 
147  wxString SetCurLib( const wxString& aLibNickname );
148 
152  LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
153 
160 
164  void SetCurPart( LIB_PART* aPart );
165 
167 
169  static void SetPinNumDefaultSize( int aSize ) { m_textPinNumDefaultSize = aSize; }
170 
172  static void SetPinNameDefaultSize( int aSize ) { m_textPinNameDefaultSize = aSize; }
173 
174  static int GetDefaultPinLength() { return m_defaultPinLength; }
175  static void SetDefaultPinLength( int aLength ) { m_defaultPinLength = aLength; }
176 
180  int GetRepeatPinStep() const { return m_repeatPinStep; }
181  void SetRepeatPinStep( int aStep) { m_repeatPinStep = aStep; }
182 
183  void ReCreateMenuBar() override;
184 
185  // See comments for m_SyncPinEdit.
186  bool SynchronizePins();
187 
188  void OnImportBody( wxCommandEvent& aEvent );
189  void OnExportBody( wxCommandEvent& aEvent );
190 
194  bool AddLibraryFile( bool aCreateNew );
195 
199  void CreateNewPart();
200 
201  void ImportPart();
202  void ExportPart();
203 
207  void Save();
208 
212  void SaveAs();
213 
217  void SaveAll();
218 
222  void Revert( bool aConfirm = true );
223  void RevertAll();
224 
225  void DeletePartFromLibrary();
226 
227  void CopyPartToClipboard();
228 
229  void LoadPart( const wxString& aLibrary, const wxString& aPart, int Unit );
230 
234  void DuplicatePart( bool aFromClipboard );
235 
236  void OnSelectUnit( wxCommandEvent& event );
237 
238  void OnToggleSearchTree( wxCommandEvent& event );
239 
240  bool IsSearchTreeShown();
241  void FreezeSearchTree();
242  void ThawSearchTree();
243 
244  void OnUpdatePartNumber( wxUpdateUIEvent& event );
245 
246  void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
247  void RebuildSymbolUnitsList();
248 
249  void OnCloseWindow( wxCloseEvent& Event );
250  void OnExitKiCad( wxCommandEvent& event );
251  void ReCreateHToolbar() override;
252  void ReCreateVToolbar() override;
253  void ReCreateOptToolbar() override;
254 
255  void LoadSettings( wxConfigBase* aCfg ) override;
256  void SaveSettings( wxConfigBase* aCfg ) override;
257 
264  void CloseWindow( wxCommandEvent& event )
265  {
266  // Generate a wxCloseEvent
267  Close( false );
268  }
269 
274  void OnModify() override;
275 
276  int GetUnit() const { return m_unit; }
277  void SetUnit( int aUnit ) { m_unit = aUnit; }
278 
279  int GetConvert() const { return m_convert; }
280  void SetConvert( int aConvert ) { m_convert = aConvert; }
281 
282  bool GetShowDeMorgan() const { return m_showDeMorgan; }
283  void SetShowDeMorgan( bool show ) { m_showDeMorgan = show; }
284 
285  void ClearMsgPanel() override { DisplayCmpDoc(); }
286 
287 private:
288  // Sets up the tool framework
289  void setupTools();
290 
291  void savePartAs();
292 
302  bool saveLibrary( const wxString& aLibrary, bool aNewFile );
303 
308  void updateTitle();
309 
316  void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
317 
326  wxString SelectLibraryFromList();
327 
337  bool LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit = 0, int aConvert = 0 );
338 
349  bool LoadOneLibraryPartAux( LIB_PART* aLibEntry, const wxString& aLibrary, int aUnit,
350  int aConvert );
351 
355  void DisplayCmpDoc();
356 
357  // General editing
358 public:
365  void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO_T undoType = UR_LIBEDIT,
366  bool aAppend = false );
367 
370 
371  void RollbackPartFromUndo();
372 
373 private:
379  void LoadOneSymbol();
380 
387  void SaveOneSymbol();
388 
389  void refreshSchematic();
390 
391 public:
400  bool LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert );
401 
407  void PrintPage( wxDC* aDC ) override;
408 
412  void SVG_PlotComponent( const wxString& aFullFileName );
413 
418  void SyncLibraries( bool aShowProgress );
419 
423  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
424 
428  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
429 
430  void ShowChangedLanguage() override;
431 
432  void SyncToolbars() override;
433 
434  void SetScreen( BASE_SCREEN* aScreen ) override;
435 
436  const BOX2I GetDocumentExtents() const override;
437 
438  void RebuildView();
439 
443  void HardRedraw() override;
444 
445  void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
446 
448  void emptyScreen();
449 
450 private:
453 
459  SYMBOL_LIB_TABLE* selectSymLibTable( bool aOptional = false );
460 
462  bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
463 
465  LIB_PART* getTargetPart() const;
466 
469  LIB_ID getTargetLibId() const;
470 
473  wxString getTargetLib() const;
474 
475  /* Returns true when the operation has succeeded (all requested libraries have been saved or
476  * none was selected and confirmed by OK).
477  * @param aRequireConfirmation when true, the user must be asked to confirm.
478  */
479  bool saveAllLibraries( bool aRequireConfirmation );
480 
482  bool saveCurrentPart();
483 
485  void storeCurrentPart();
486 
488  bool isCurrentPart( const LIB_ID& aLibId ) const;
489 
491  void fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibrary );
492 
493  DECLARE_EVENT_TABLE()
494 };
495 
496 #endif // LIB_EDIT_FRAME_H
void SVG_PlotComponent(const wxString &aFullFileName)
Creates the SVG print file for the current edited component.
bool m_DrawSpecificUnit
Specify which component parts the current draw item applies to.
void OnToggleSearchTree(wxCommandEvent &event)
static void SetPinNameDefaultSize(int aSize)
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
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allows Libedit to install its preferences panel into the preferences dialog.
void SetRepeatPinStep(int aStep)
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)
static FILL_T g_LastFillStyle
LIB_MANAGER * m_libMgr
static int GetDefaultPinLength()
void SelectActiveLibrary(const wxString &aLibrary=wxEmptyString)
Set the current active library to aLibrary.
wxString SelectLibraryFromList()
Display a list of loaded libraries in the symbol library and allows the user to select a library.
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
bool LoadOneLibraryPartAux(LIB_PART *aLibEntry, const wxString &aLibrary, int aUnit, int aConvert)
Create a copy of aLibEntry into memory.
static int g_LastLineWidth
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 fixDuplicateAliases(LIB_PART *aPart, const wxString &aLibrary)
Renames LIB_PART aliases to avoid conflicts before adding a component to a library
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
LIB_PART * m_my_part
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
void SetShowDeMorgan(bool show)
bool m_DrawSpecificConvert
Convert of the item currently being drawn.
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.
static int GetPinNumDefaultSize()
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 PrintPage(wxDC *aDC) override
Print a page.
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.
const BOX2I GetDocumentExtents() const override
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
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:74
static double g_LastTextAngle
static void SetPinNumDefaultSize(int aSize)
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:274
static int m_textPinNumDefaultSize
void CommonSettingsChanged(bool aEnvVarsChanged) override
Called after the preferences dialog is run.
void GetComponentFromRedoList()
bool LoadComponentAndSelectLib(const LIB_ID &aLibId, int aUnit, int aConvert)
Selects the currently active library and loads the symbol from aLibId.
void ExportPart()
Definition: lib_export.cpp:97
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.
static int m_textPinNameDefaultSize
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:98
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)
static int GetPinNameDefaultSize()
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)
static int g_LastTextSize
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
static int m_defaultPinLength
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
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.
int m_repeatPinStep
Default repeat offset for pins in repeat place pin.
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
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.
static bool m_showDeMorgan
wxComboBox * m_unitSelectBox
int GetRepeatPinStep() const
static void SetDefaultPinLength(int aLength)
SYMBOL_TREE_PANE * m_treePane
LIB_MANAGER & GetLibManager()
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