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  static int m_textPinNumDefaultSize; // The default pin num text size setting.
74  static int m_textPinNameDefaultSize; // The default pin name text size setting.
75  static int m_defaultPinLength; // Default pin length
76 
79 
81 
82 public:
102 
105 
113 
114  static int g_LastTextSize;
115  static double g_LastTextAngle;
117  static int g_LastLineWidth;
118 
119 public:
120  LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
121 
122  ~LIB_EDIT_FRAME() override;
123 
127  void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
128 
134  bool IsContentModified() override;
135 
144  bool HasLibModifications() const;
145 
147  wxString GetCurLib() const;
148 
150  wxString SetCurLib( const wxString& aLibNickname );
151 
153 
157  LIB_ID GetTreeLIBID( int* aUnit = nullptr ) const;
158 
165 
169  void SetCurPart( LIB_PART* aPart );
170 
172 
174  static void SetPinNumDefaultSize( int aSize ) { m_textPinNumDefaultSize = aSize; }
175 
177  static void SetPinNameDefaultSize( int aSize ) { m_textPinNameDefaultSize = aSize; }
178 
179  static int GetDefaultPinLength() { return m_defaultPinLength; }
180  static void SetDefaultPinLength( int aLength ) { m_defaultPinLength = aLength; }
181 
185  int GetRepeatPinStep() const { return m_repeatPinStep; }
186  void SetRepeatPinStep( int aStep) { m_repeatPinStep = aStep; }
187 
188  void ReCreateMenuBar() override;
189 
190  // See comments for m_SyncPinEdit.
191  bool SynchronizePins();
192 
193  void OnImportBody( wxCommandEvent& aEvent );
194  void OnExportBody( wxCommandEvent& aEvent );
195 
199  bool AddLibraryFile( bool aCreateNew );
200 
204  void CreateNewPart();
205 
206  void ImportPart();
207  void ExportPart();
208 
212  void Save();
213 
217  void SaveAs();
218 
222  void SaveAll();
223 
227  void Revert( bool aConfirm = true );
228  void RevertAll();
229 
230  void DeletePartFromLibrary();
231 
232  void CopyPartToClipboard();
233 
234  void LoadPart( const wxString& aLibrary, const wxString& aPart, int Unit );
235 
239  void DuplicatePart( bool aFromClipboard );
240 
241  void OnSelectUnit( wxCommandEvent& event );
242 
243  void OnToggleSearchTree( wxCommandEvent& event );
244 
245  bool IsSearchTreeShown();
246  void FreezeSearchTree();
247  void ThawSearchTree();
248 
249  void OnUpdatePartNumber( wxUpdateUIEvent& event );
250 
251  void UpdateAfterSymbolProperties( wxString* aOldName = nullptr );
252  void RebuildSymbolUnitsList();
253 
254  void OnCloseWindow( wxCloseEvent& Event );
255  void OnExitKiCad( wxCommandEvent& event );
256  void ReCreateHToolbar() override;
257  void ReCreateVToolbar() override;
258  void ReCreateOptToolbar() override;
259 
260  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
261  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
262 
264  {
265  return m_settings;
266  }
267 
268  COLOR_SETTINGS* GetColorSettings() override;
269 
276  void CloseWindow( wxCommandEvent& event )
277  {
278  // Generate a wxCloseEvent
279  Close( false );
280  }
281 
286  void OnModify() override;
287 
288  int GetUnit() const { return m_unit; }
289  void SetUnit( int aUnit ) { m_unit = aUnit; }
290 
291  int GetConvert() const { return m_convert; }
292  void SetConvert( int aConvert ) { m_convert = aConvert; }
293 
294  bool GetShowDeMorgan() const { return m_showDeMorgan; }
295  void SetShowDeMorgan( bool show ) { m_showDeMorgan = show; }
296 
297  void ClearMsgPanel() override { DisplayCmpDoc(); }
298 
299 private:
300  // Sets up the tool framework
301  void setupTools();
302 
303  void savePartAs();
304 
314  bool saveLibrary( const wxString& aLibrary, bool aNewFile );
315 
320  void updateTitle();
321 
328  void SelectActiveLibrary( const wxString& aLibrary = wxEmptyString );
329 
338  wxString SelectLibraryFromList();
339 
349  bool LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit = 0, int aConvert = 0 );
350 
361  bool LoadOneLibraryPartAux( LIB_PART* aLibEntry, const wxString& aLibrary, int aUnit,
362  int aConvert );
363 
367  void DisplayCmpDoc();
368 
369  // General editing
370 public:
377  void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, UNDO_REDO_T undoType = UR_LIBEDIT,
378  bool aAppend = false );
379 
382 
383  void RollbackPartFromUndo();
384 
385 private:
391  void LoadOneSymbol();
392 
399  void SaveOneSymbol();
400 
401  void refreshSchematic();
402 
403 public:
412  bool LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert );
413 
419  void PrintPage( wxDC* aDC ) override;
420 
424  void SVG_PlotComponent( const wxString& aFullFileName );
425 
430  void SyncLibraries( bool aShowProgress );
431 
436  void RegenerateLibraryTree();
437 
441  void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
442 
446  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
447 
448  void ShowChangedLanguage() override;
449 
450  void SyncToolbars() override;
451 
452  void SetScreen( BASE_SCREEN* aScreen ) override;
453 
454  const BOX2I GetDocumentExtents() const override;
455 
456  void RebuildView();
457 
461  void HardRedraw() override;
462 
463  void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
464 
466  void emptyScreen();
467 
468 private:
471 
477  SYMBOL_LIB_TABLE* selectSymLibTable( bool aOptional = false );
478 
480  bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
481 
483  LIB_PART* getTargetPart() const;
484 
487  LIB_ID getTargetLibId() const;
488 
491  wxString getTargetLib() const;
492 
493  /* Returns true when the operation has succeeded (all requested libraries have been saved or
494  * none was selected and confirmed by OK).
495  * @param aRequireConfirmation when true, the user must be asked to confirm.
496  */
497  bool saveAllLibraries( bool aRequireConfirmation );
498 
500  bool saveCurrentPart();
501 
503  void storeCurrentPart();
504 
506  bool isCurrentPart( const LIB_ID& aLibId ) const;
507 
509  void fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibrary );
510 
511  DECLARE_EVENT_TABLE()
512 };
513 
514 #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.
LIBEDIT_SETTINGS * m_settings
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.
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.
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 RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
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.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
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: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:273
static int m_textPinNumDefaultSize
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 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: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)
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:166
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.
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.
COLOR_SETTINGS * GetColorSettings() override
Returns a pointer to the active color theme settings.
static bool m_showDeMorgan
wxComboBox * m_unitSelectBox
int GetRepeatPinStep() const
static void SetDefaultPinLength(int aLength)
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