KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef FOOTPRINT_EDIT_FRAME_H
21#define FOOTPRINT_EDIT_FRAME_H
22
23#include <functional>
24#include <memory>
25#include <vector>
26
27#include <pcb_base_frame.h>
28#include <pcb_base_edit_frame.h>
29#include <pcb_io/pcb_io_mgr.h>
30#include <widgets/lib_tree.h>
31#include <footprint_tree_pane.h>
33
35class FP_LIB_TABLE;
39class EDA_LIST_DIALOG;
43
47
48namespace PCB { struct IFACE; } // A KIFACE coded in pcbnew.cpp
49
50
52{
53public:
55
60 static const wxChar* GetFootprintEditorFrameName();
61
74 std::vector<std::unique_ptr<FOOTPRINT_EDITOR_TAB_CONTEXT>>& aContexts, int aSlot,
75 std::unique_ptr<FOOTPRINT_EDITOR_TAB_CONTEXT> aNew,
76 const std::function<void( const FOOTPRINT_EDITOR_TAB_CONTEXT& )>& aInstallSuccessor );
77
90 static bool prepareFootprintTabHandoff( FOOTPRINT* aFootprint, bool aHasTabs );
91
101
114 static EDIT_NOTICE editNoticeFor( const FOOTPRINT* aFootprint, bool aIsFromBoard,
115 const std::function<bool( const wxString& )>& aIsLibWritable );
116
118 BOARD_ITEM_CONTAINER* GetModel() const override;
119 SELECTION& GetCurrentSelection() override;
120
126 bool IsContentModified() const override;
127
128 bool IsCurrentFPFromBoard() const;
129
134 bool HandleUnsavedChanges( bool aFromBoardOnly );
135
137
141 EDA_ANGLE GetRotationAngle() const override;
142
143 APP_SETTINGS_BASE* config() const override;
144
146
147 const PCB_PLOT_PARAMS& GetPlotSettings() const override;
148 void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings ) override;
149
151
152 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
153 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
154
155 COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override;
156
157 std::unique_ptr<GRID_HELPER> MakeGridHelper() override;
158
159 const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
160
161 bool canCloseWindow( wxCloseEvent& Event ) override;
162 void doCloseWindow() override;
163 void CloseFootprintEditor( wxCommandEvent& Event );
164 void OnExitKiCad( wxCommandEvent& aEvent );
165
171 void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
172
177 void UpdateUserInterface();
178
180 void UpdateMsgPanel() override;
181
185 void HardRedraw() override;
186
195 void ReCreateLayerBox( bool aForceResizeToolbar = true );
196
197 void configureToolbars() override;
198
203
204 // The Tool Framework initialization, for GAL mode
205 void setupTools();
206
207 void OnSaveFootprintAsPng( wxCommandEvent& event );
208
209 bool IsLibraryTreeShown() const override;
210 void ToggleLibraryTree() override;
211 void FocusLibraryTreeInput() override;
212
213 void ToggleLayersManager();
214
222 bool SaveLibraryAs( const wxString& aLibraryPath );
223
225 void OnEditItemRequest( BOARD_ITEM* aItem ) override;
226
227 void LoadFootprintFromLibrary( LIB_ID aFPID );
228
235 bool BeginNewFootprint( const wxString& aLibrary );
236
241 void CloseFootprintTab( const LIB_ID& aFPID );
242
251
256 void RenameFootprintTab( const LIB_ID& aOldId, const LIB_ID& aNewId );
257
261 bool HasModifiedFootprintTabs() const;
262
266 void RefreshLibraryFootprintTab( const FOOTPRINT& aFootprint );
267
271 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& GetLibTreeAdapter() { return m_adapter; }
272
279 bool SaveFootprint( FOOTPRINT* aFootprint );
280 bool DuplicateFootprint( FOOTPRINT* aFootprint );
281 bool SaveFootprintAs( FOOTPRINT* aFootprint );
282 bool SaveFootprintToBoard( bool aAddNew );
283 bool SaveFootprintInLibrary( FOOTPRINT* aFootprint, const wxString& aLibraryName );
284 bool RevertFootprint( bool aSkipConfirmation = false );
285
292 void OnModify() override;
293
297 void Clear_Pcb();
298
300 LIB_ID GetLoadedFPID() const;
301
304 LIB_ID GetTargetFPID() const;
305
306 void ClearModify();
307
311 void ExportFootprint( FOOTPRINT* aFootprint );
312
319 FOOTPRINT* ImportFootprint( const wxString& aName = wxT( "" ) );
320
328 bool LoadFootprintFromBoard( FOOTPRINT* aFootprint );
329
336
340 bool DeleteFootprintFromLibrary( const LIB_ID& aFPID, bool aConfirm );
341
345 COLOR4D GetGridColor() override;
346
348 void SetActiveLayer( PCB_LAYER_ID aLayer ) override;
349
350 void OnDisplayOptionsChanged() override;
351
352 void ActivateGalCanvas() override;
353
363 bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl = 0 ) override;
364
369 void AddFootprintToBoard( FOOTPRINT* aFootprint ) override;
370
375 void ReloadFootprint( FOOTPRINT* aFootprint ) override;
376
380 void ShowChangedLanguage() override;
381
385 void CommonSettingsChanged( int aFlags ) override;
386
387 LIB_TREE* GetLibTree() const override
388 {
389 return m_treePane->GetLibTree();
390 }
391
396 void SyncLibraryTree( [[maybe_unused]] bool aProgress );
397
401 void RefreshLibraryTree();
402
406 void UpdateLibraryTree( const wxDataViewItem& treeItem, FOOTPRINT* aFootprint );
407
409 void UpdateView();
410
411 void UpdateTitle();
412
413 void FocusOnLibID( const LIB_ID& aLibID );
414
415 void KiwayMailIn( KIWAY_MAIL_EVENT& mail ) override;
416
421
425 void AdvanceFootprintTab( bool aForward );
426
431
432 DECLARE_EVENT_TABLE()
433
434protected:
436 FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
437
441 void resolveCanvasType() override;
442
447 void initLibraryTree();
448
450 void retainLastFootprint();
451
452 void updateEnabledLayers();
453
457 void updateInfoBar();
458
462 void doReCreateMenuBar() override;
463
467 void editFootprintProperties( FOOTPRINT* aFootprint );
468
469 void setupUIConditions() override;
470
471 void onPluginAvailabilityChanged( wxCommandEvent& aEvt );
472
473 void centerItemIdleHandler( wxIdleEvent& aEvent );
474
481 void OnTabCharHook( wxKeyEvent& aEvent );
482
483protected:
485
486private:
487 friend struct PCB::IFACE;
488
492 FOOTPRINT_EDITOR_TAB_CONTEXT* findOrCreateFootprintTab( const LIB_ID& aLibId, bool aAsPreview );
493
503
510 void installFootprintOnActiveBoard( FOOTPRINT* aFootprint );
511
516
525
533
538 void borrowBoardNonDestructive( BOARD* aBoard );
539
543 bool promptAndCloseFootprintTab( int aIdx );
544
549 bool hasDirtyInactiveTabs() const;
550
556
564
569
577 void detachTabsForFullClear( BOARD* aReplacement );
578
582 bool activeBoardOwnedByTab() const;
583
586
588
590
594
598
602
605
608
612};
613
614#endif // FOOTPRINT_EDIT_FRAME_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
Base class for API handlers related to library management.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Container for design settings for a BOARD object.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
Color settings are a bit different than most of the settings objects in that there can be more than o...
A dialog which shows:
The tab strip plus the single shared GAL canvas.
One open footprint tab owning its fp-holder board, lent to the frame by raw pointer while active.
EDITOR_TABS_PANEL * GetTabsPanel() const
Return the tabbed-document strip, or nullptr if the tabs UI is not mounted.
void CloseFootprintEditor(wxCommandEvent &Event)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Return the BOARD_DESIGN_SETTINGS for the open project.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
void editFootprintProperties(FOOTPRINT *aFootprint)
Run the Footprint Properties dialog and handle changes made in it.
void detachTabsForFullClear(BOARD *aReplacement)
Install aReplacement as the active document non-destructively, then drop every tab context and free t...
void onPluginAvailabilityChanged(wxCommandEvent &aEvt)
void Clear_Pcb()
Delete all and reinitialize the current board.
Definition initpcb.cpp:107
void HardRedraw() override
Refresh the library tree and redraw the window.
void UpdateLibraryTree(const wxDataViewItem &treeItem, FOOTPRINT *aFootprint)
Update a single node in the library tree.
void updateInfoBar()
Update the infobar for the currently-active tab.
static const wxChar * GetFootprintEditorFrameName()
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table.
BOARD * m_protectedBorrowedBoard
Board still owned by a displaced preview context while AddTab() synchronously installs its successor.
EDIT_NOTICE
The infobar notice that applies to the footprint being edited.
@ READ_ONLY_LIB
Editing a footprint whose library cannot be written.
@ FROM_BOARD
Editing a footprint pulled off a board, so saving updates the board only.
@ NONE
Nothing to report, so any existing notice is dismissed.
static EDIT_NOTICE editNoticeFor(const FOOTPRINT *aFootprint, bool aIsFromBoard, const std::function< bool(const wxString &)> &aIsLibWritable)
Decide which infobar notice applies to aFootprint.
bool SaveFootprintInLibrary(FOOTPRINT *aFootprint, const wxString &aLibraryName)
FOOTPRINT_EDITOR_TAB_CONTEXT * CreateUnsavedFootprintTab()
Open a session-only tab over a fresh fp-holder board and make it the active tab.
FOOTPRINT_EDITOR_TAB_CONTEXT * m_activeTab
bool SaveLibraryAs(const wxString &aLibraryPath)
Save a library to a new name and/or library type.
void OnSaveFootprintAsPng(wxCommandEvent &event)
bool SaveFootprintAs(FOOTPRINT *aFootprint)
bool DuplicateFootprint(FOOTPRINT *aFootprint)
void FocusLibraryTreeInput() override
BOARD_ITEM_CONTAINER * GetModel() const override
void ReCreateLayerBox(bool aForceResizeToolbar=true)
Re create the layer Box by clearing the old list, and building a new one from the new layers names an...
LIB_TREE * GetLibTree() const override
bool canCloseWindow(wxCloseEvent &Event) override
void UpdateMsgPanel() override
Redraw the message panel.
void ExportFootprint(FOOTPRINT *aFootprint)
Create a file containing only one footprint.
LIB_ID GetTargetFPID() const
Return the LIB_ID of the part selected in the footprint tree, or the loaded part if there is no selec...
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
APP_SETTINGS_BASE * config() const override
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void refreshFootprintTabState()
Re-query and re-render the tab labels from the active context's modified state.
std::unique_ptr< API_HANDLER_LIBRARIES > m_apiHandlerFpLibs
bool SaveFootprintToBoard(bool aAddNew)
EDITOR_TABS_PANEL * m_tabsPanel
FOOTPRINT_EDITOR_TAB_CONTEXT * findOrCreateFootprintInstanceTab(FOOTPRINT *aBoardFootprint)
Find or create the instance tab for a placed board footprint and make it the active tab.
void detachActiveFootprintTab()
Snapshot the active tab's view/selection, fold the dirty state back into it, and clear m_activeTab.
void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings) override
bool SaveFootprint(FOOTPRINT *aFootprint)
Save in an existing library a given footprint.
void OnTabCharHook(wxKeyEvent &aEvent)
Cycle footprint tabs from the CHAR_HOOK stream, since GTK cannot register WXK_TAB as a menu accelerat...
void CloseFootprintTab(const LIB_ID &aFPID)
Close the open tab for aFPID, if any, without prompting and leaving the other tabs open.
std::unique_ptr< API_HANDLER_FOOTPRINT > m_apiHandler
void initLibraryTree()
Make sure the footprint info list is loaded (with a progress dialog) and then initialize the footprin...
void LoadFootprintFromLibrary(LIB_ID aFPID)
bool BeginNewFootprint(const wxString &aLibrary)
Prepare the editor for a new footprint, returning false if the user cancels.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetLibTreeAdapter()
Return the adapter object that provides the stored data.
bool m_silentFootprintTabClose
While true, promptAndCloseFootprintTab() skips the unsaved-changes dialog.
FOOTPRINT * ImportFootprint(const wxString &aName=wxT(""))
Read a file containing only one footprint.
std::map< KIID, KIID > m_boardFootprintUuids
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
FOOTPRINT * SelectFootprintFromBoard(BOARD *aPcb)
Display the list of footprints currently existing on the BOARD.
std::unique_ptr< API_HANDLER_COMMON > m_apiHandlerCommon
PLUGIN_ACTION_SCOPE PluginActionScope() const override
void ShowChangedLanguage() override
Update visible items after a language change.
void resolveCanvasType() override
Determines the Canvas type to load (with prompt if required) and initializes m_canvasType.
void CommonSettingsChanged(int aFlags) override
Called after the preferences dialog is run.
bool IsContentModified() const override
Get if any footprints or libraries have been modified but not saved.
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
bool IsLibraryTreeShown() const override
FOOTPRINT_EDITOR_SETTINGS * m_editorSettings
void centerItemIdleHandler(wxIdleEvent &aEvent)
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box of document with option to not include some items.
bool HasModifiedFootprintTabs() const
Return true if any footprint editor tab has unsaved changes.
void RenameFootprintTab(const LIB_ID &aOldId, const LIB_ID &aNewId)
Update the open tab for aOldId, if any, to the renamed footprint aNewId so its label and key track th...
static FOOTPRINT_EDITOR_TAB_CONTEXT * placeReusedTabContext(std::vector< std::unique_ptr< FOOTPRINT_EDITOR_TAB_CONTEXT > > &aContexts, int aSlot, std::unique_ptr< FOOTPRINT_EDITOR_TAB_CONTEXT > aNew, const std::function< void(const FOOTPRINT_EDITOR_TAB_CONTEXT &)> &aInstallSuccessor)
Replace the tab context at aSlot with aNew, running aInstallSuccessor before the displaced context is...
bool HandleUnsavedChanges(bool aFromBoardOnly)
Prompt to save each dirty tab that meets the requirements.
void borrowBoardNonDestructive(BOARD *aBoard)
Swap the frame's borrowed board pointer to aBoard without deleting the previous board,...
FOOTPRINT_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
protected so only friend PCB::IFACE::CreateWindow() can act as sole factory.
void KiwayMailIn(KIWAY_MAIL_EVENT &mail) override
Receive KIWAY_MAIL_EVENT messages from other players.
bool hasDirtyInactiveTabs() const
True if any non-active tab has unsaved edits.
void RefreshLibraryFootprintTab(const FOOTPRINT &aFootprint)
Replace the clean open editor tab matching aFootprint, if any, with the saved footprint.
void OnEditItemRequest(BOARD_ITEM *aItem) override
Install the corresponding dialog editor for the given item.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void UpdateView()
Reload displayed items and sets view.
void AdvanceFootprintTab(bool aForward)
Advance the active tab forward or backward in MRU order.
void activateFootprintTab(FOOTPRINT_EDITOR_TAB_CONTEXT *aCtx)
Make aCtx the active tab, borrowing its board without deleting the outgoing one.
void freeFootprintTabUndoRedo(FOOTPRINT_EDITOR_TAB_CONTEXT &aCtx)
Free the transient board items a detached context's lists own before it is destroyed,...
void SetActiveLayer(PCB_LAYER_ID aLayer) override
void AddFootprintToBoard(FOOTPRINT *aFootprint) override
Override from PCB_BASE_EDIT_FRAME which adds a footprint to the editor's dummy board,...
bool DeleteFootprintFromLibrary(const LIB_ID &aFPID, bool aConfirm)
Delete the given footprint from its library.
bool activeBoardOwnedByTab() const
True when a tab context owns the frame's borrowed board, so the frame must not delete it.
void OnModify() override
Must be called after a footprint change in order to set the "modify" flag of the current screen and p...
std::vector< std::unique_ptr< FOOTPRINT_EDITOR_TAB_CONTEXT > > m_tabContexts
void CloseActiveFootprintTab()
Request closing the active tab, prompting to save if it is modified.
bool RevertFootprint(bool aSkipConfirmation=false)
FOOTPRINT_TREE_PANE * m_treePane
std::unique_ptr< GRID_HELPER > MakeGridHelper() override
void OnDisplayOptionsChanged() override
void doReCreateMenuBar() override
(Re)Create the menubar for the Footprint Editor frame
void FocusOnLibID(const LIB_ID &aLibID)
const PCB_PLOT_PARAMS & GetPlotSettings() const override
Return the PCB_PLOT_PARAMS for the BOARD owned by this frame.
bool m_suppressTabActivation
Set while a full clear tears the tab strip down so the panel's close-driven re-activation does not re...
static bool prepareFootprintTabHandoff(FOOTPRINT *aFootprint, bool aHasTabs)
Decide whether aFootprint opens in its own tab and, if so, detach it from the board it arrived parent...
std::unique_ptr< FOOTPRINT > m_originalFootprintCopy
void ReloadFootprint(FOOTPRINT *aFootprint) override
Override from PCB_BASE_FRAME which reloads the footprint from the library without setting the footpri...
EDA_ANGLE GetRotationAngle() const override
Return the angle used for rotate operations.
void RefreshLibraryTree()
Redisplay the library tree.
void installFootprintTabBoard(FOOTPRINT_EDITOR_TAB_CONTEXT *aCtx, BOARD *aBoard)
Install aBoard as the active document non-destructively, wiring the tool environment and resetting th...
void OnExitKiCad(wxCommandEvent &aEvent)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Load a KiCad board (.kicad_pcb) from aFileName.
bool promptAndCloseFootprintTab(int aIdx)
Prompt to save if needed, then drop the tab context at aIdx.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
MAGNETIC_SETTINGS * GetMagneticItemsSettings() override
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
FOOTPRINT_EDITOR_TAB_CONTEXT * findOrCreateFootprintTab(const LIB_ID &aLibId, bool aAsPreview)
Find or create the tab for aLibId over its own fp-holder board and make it the active tab.
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
Switch the currently used canvas (Cairo / OpenGL).
void freeUndoRedoCommandsWithItems(UNDO_REDO_CONTAINER &aUndo, UNDO_REDO_CONTAINER &aRedo)
Free both the transient board items and the command wrappers in the given lists.
void installFootprintOnActiveBoard(FOOTPRINT *aFootprint)
Replace the active board's footprint with aFootprint and re-point the file watcher at it.
bool LoadFootprintFromBoard(FOOTPRINT *aFootprint)
Load a footprint from the main board into the Footprint Editor.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
Footprint Editor pane with footprint library tree.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Definition kiid.h:46
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition kiway_mail.h:34
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Widget displaying a tree of symbols with optional search text control and description panel.
Definition lib_tree.h:44
PCB_BASE_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
Class to display a pcb layer list in a wxBitmapComboBox.
Parameters and options when plotting/printing a board.
Class to handle modifications to the symbol libraries.
A holder to handle a list of undo (or redo) commands.
STL class.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
STL namespace.
PLUGIN_ACTION_SCOPE