KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_base_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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008-2016 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2023 CERN
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef PCB_BASE_FRAME_H
24#define PCB_BASE_FRAME_H
25
26#include <eda_units.h>
27#include <eda_draw_frame.h>
28#include <lib_id.h>
29#include <pcb_display_options.h>
30#include <pcb_draw_panel_gal.h>
32#include <pcb_screen.h>
33#include <vector>
34
35#include <wx/datetime.h>
36#include <wx/filename.h>
37#include <wx/timer.h>
38
39/* Forward declarations of classes. */
41class BOARD;
43class COLOR_SETTINGS;
44class EDA_ITEM;
45class FOOTPRINT;
46class PAD;
51class LSET;
52class ZONE_SETTINGS;
53class PCB_PLOT_PARAMS;
54class FP_LIB_TABLE;
56class PCBNEW_SETTINGS;
61
62#if defined(__linux__) || defined(__FreeBSD__)
63class SPNAV_2D_PLUGIN;
64#else
66#endif
67
68#ifdef wxHAS_INOTIFY
69#define wxFileSystemWatcher wxInotifyFileSystemWatcher
70#elif defined( wxHAS_KQUEUE ) && defined( wxHAVE_FSEVENTS_FILE_NOTIFICATIONS )
71#define wxFileSystemWatcher wxFsEventsFileSystemWatcher
72#elif defined( wxHAS_KQUEUE )
73#define wxFileSystemWatcher wxKqueueFileSystemWatcher
74#elif defined( __WINDOWS__ )
75#define wxFileSystemWatcher wxMSWFileSystemWatcher
76#else
77#define wxFileSystemWatcher wxPollingFileSystemWatcher
78#endif
79
81class wxFileSystemWatcherEvent;
82
83wxDECLARE_EVENT( EDA_EVT_BOARD_CHANGING, wxCommandEvent );
84wxDECLARE_EVENT( EDA_EVT_BOARD_CHANGED, wxCommandEvent );
85
90{
91public:
92 PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
93 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
94 long aStyle, const wxString& aFrameName );
95
97
102
110 virtual void Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle = nullptr );
111
119 FOOTPRINT* LoadFootprint( const LIB_ID& aFootprintId );
120
127 BOX2I GetBoardBoundingBox( bool aBoardEdgesOnly = false ) const;
128
129 const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
130
131 virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
132 const PAGE_INFO& GetPageSettings() const override;
133 const VECTOR2I GetPageSizeIU() const override;
134
135 const VECTOR2I& GetGridOrigin() const override;
136 void SetGridOrigin( const VECTOR2I& aPoint ) override;
137
138 const VECTOR2I& GetAuxOrigin() const;
139
140 const VECTOR2I GetUserOrigin() const;
141
146
147 wxString MessageTextFromCoord( int aValue, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType ) const
148 {
149 return MessageTextFromValue( m_originTransforms.ToDisplay( aValue, aCoordType ) );
150 }
151
152 const TITLE_BLOCK& GetTitleBlock() const override;
153 void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
154
159
163 virtual COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override
164 {
165 wxFAIL_MSG( wxT( "Color settings requested for a PCB_BASE_FRAME that does not "
166 "override!" ) );
167 return nullptr;
168 }
169
170 void SetDrawBgColor( const COLOR4D& aColor ) override;
171
177
184 void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh = true );
185
189 virtual const PCB_PLOT_PARAMS& GetPlotSettings() const;
190 virtual void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings );
191
197 virtual void ReloadFootprint( FOOTPRINT* aFootprint )
198 {
199 wxFAIL_MSG( wxT( "Attempted to reload a footprint for PCB_BASE_FRAME that does not "
200 "override!" ) );
201 }
202
206 virtual void SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
207
209 {
210 return m_pcb;
211 }
212
216 virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
217
218 EDA_ITEM* ResolveItem( const KIID& aId, bool aAllowNullptrReturn = false ) const override;
219
220 void FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll = true ) override;
221 void FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer = UNDEFINED_LAYER, bool aAllowScroll = true );
222 void FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
223 bool aAllowScroll = true );
224
225 void HideSolderMask();
226 void ShowSolderMask();
227
228 // General
229 virtual void ShowChangedLanguage() override;
230 virtual void UpdateStatusBar() override;
231
232 PCB_SCREEN* GetScreen() const override;
233
240
245
250 void OnModify() override;
251
265 FOOTPRINT* CreateNewFootprint( wxString aFootprintName, const wxString& aLibName );
266
273 void PlaceFootprint( FOOTPRINT* aFootprint, bool aRecreateRatsnest = true, std::optional<VECTOR2I> aPosition = std::nullopt );
274
275 void ShowPadPropertiesDialog( PAD* aPad );
276
283
289 virtual void AddFootprintToBoard( FOOTPRINT* aFootprint );
290
297 virtual void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand ) {};
298
305 virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
306 UNDO_REDO aTypeCommand ) {};
307
311 virtual void AppendCopyToUndoList( const PICKED_ITEMS_LIST& aItemsList,
312 UNDO_REDO aTypeCommand ) {};
313
314
326 const LSET& aNotAllowedLayersMask = LSET(),
327 wxPoint aDlgPosition = wxDefaultPosition );
328
334 virtual void SwitchLayer( PCB_LAYER_ID aLayer );
335
336 virtual void SetActiveLayer( PCB_LAYER_ID aLayer );
337 virtual PCB_LAYER_ID GetActiveLayer() const;
338
339 SEVERITY GetSeverity( int aErrorCode ) const override;
340
341 virtual void OnDisplayOptionsChanged() {}
342
343 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
344 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
345
347
349
351
353
354 void CommonSettingsChanged( int aFlags ) override;
355
356 PCB_DRAW_PANEL_GAL* GetCanvas() const override;
357
358 virtual void ActivateGalCanvas() override;
359
369 void AddBoardChangeListener( wxEvtHandler* aListener );
370
374 void RemoveBoardChangeListener( wxEvtHandler* aListener );
375
379 void OnFPChange( wxFileSystemWatcherEvent& aEvent );
380
384 void OnFpChangeDebounceTimer( wxTimerEvent& aEvent );
385
386 void GetLibraryItemsForListDialog( wxArrayString& aHeaders,
387 std::vector<wxArrayString>& aItemsToDisplay );
388
389protected:
390 bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
391
392 void handleActivateEvent( wxActivateEvent& aEvent ) override;
393
394 void handleIconizeEvent( wxIconizeEvent& aEvent ) override;
395
396 virtual void doReCreateMenuBar() override;
397
398 virtual void unitsChangeRefresh() override;
399
400 void rebuildConnectivity();
401
407 void setFPWatcher( FOOTPRINT* aFootprint );
408
409protected:
413
414private:
415#if defined(__linux__) || defined(__FreeBSD__)
416 std::unique_ptr<SPNAV_2D_PLUGIN> m_spaceMouse;
417#else
418 std::unique_ptr<NL_PCBNEW_PLUGIN> m_spaceMouse;
419#endif
420
421 std::unique_ptr<wxFileSystemWatcher> m_watcher;
426};
427
428#endif // PCB_BASE_FRAME_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
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:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
Color settings are a bit different than most of the settings objects in that there can be more than o...
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Definition kiid.h:44
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
The class that implements the public interface to the SpaceMouse plug-in.
A class to perform either relative or absolute display origin transforms for a single axis of a point...
COORD_TYPES_T
The supported Display Origin Transform types.
Definition pad.h:61
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
SEVERITY GetSeverity(int aErrorCode) const override
std::unique_ptr< wxFileSystemWatcher > m_watcher
virtual void SaveCopyInUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aTypeCommand)
Create a new entry in undo list of commands.
virtual void ReloadFootprint(FOOTPRINT *aFootprint)
Reload the footprint from the library.
virtual void OnDisplayOptionsChanged()
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
ORIGIN_TRANSFORMS & GetOriginTransforms() override
Return a reference to the default ORIGIN_TRANSFORMS object.
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Return the PCB_PLOT_PARAMS for the BOARD owned by this frame.
std::unique_ptr< NL_PCBNEW_PLUGIN > m_spaceMouse
void ShowPadPropertiesDialog(PAD *aPad)
wxDateTime m_watcherLastModified
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void RemoveBoardChangeListener(wxEvtHandler *aListener)
Remove aListener to from the board changed listener list.
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
void setFPWatcher(FOOTPRINT *aFootprint)
Create or removes a watcher on the specified footprint.
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box of document with option to not include some items.
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
FOOTPRINT * CreateNewFootprint(wxString aFootprintName, const wxString &aLibName)
Create a new footprint at position 0,0.
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual void SwitchLayer(PCB_LAYER_ID aLayer)
Change the active layer in the frame.
PCB_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
void OnModify() override
Must be called after a change in order to set the "modify" flag and update other data structures and ...
const VECTOR2I & GetAuxOrigin() const
virtual void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand)
Create a new entry in undo list of commands.
virtual PCB_VIEWERS_SETTINGS_BASE * GetViewerSettingsBase() const
const VECTOR2I GetUserOrigin() const
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
FOOTPRINT * SelectFootprintFromLibrary(LIB_ID aPreselect=LIB_ID())
Open a dialog to select a footprint.
void FocusOnItems(std::vector< BOARD_ITEM * > aItems, PCB_LAYER_ID aLayer=UNDEFINED_LAYER, bool aAllowScroll=true)
void GetLibraryItemsForListDialog(wxArrayString &aHeaders, std::vector< wxArrayString > &aItemsToDisplay)
void OnFPChange(wxFileSystemWatcherEvent &aEvent)
Handler for FP change events.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
const VECTOR2I & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
const TITLE_BLOCK & GetTitleBlock() const override
const PAGE_INFO & GetPageSettings() const override
BOX2I GetBoardBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
EDA_ITEM * ResolveItem(const KIID &aId, bool aAllowNullptrReturn=false) const override
Fetch an item by KIID.
FOOTPRINT * LoadFootprint(const LIB_ID &aFootprintId)
Attempt to load aFootprintId from the footprint library table.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
void SetDrawBgColor(const COLOR4D &aColor) override
void OnFpChangeDebounceTimer(wxTimerEvent &aEvent)
Handler for the filesystem watcher debounce timer.
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
virtual PCB_LAYER_ID GetActiveLayer() const
virtual void SetPageSettings(const PAGE_INFO &aPageSettings) override
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
virtual void ShowChangedLanguage() override
Redraw the menus and what not in current language.
void AddBoardChangeListener(wxEvtHandler *aListener)
Add aListener to post #EDA_EVT_BOARD_CHANGED command events to.
virtual void AddFootprintToBoard(FOOTPRINT *aFootprint)
Add the given footprint to the board.
virtual void doReCreateMenuBar() override
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Update the current display options.
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
wxString MessageTextFromCoord(int aValue, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType) const
void FocusOnItem(EDA_ITEM *aItem, bool aAllowScroll=true) override
Focus on a particular canvas item.
PCB_DISPLAY_OPTIONS m_displayOptions
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings() const
PCB_LAYER_ID SelectOneLayer(PCB_LAYER_ID aDefaultLayer, const LSET &aNotAllowedLayersMask=LSET(), wxPoint aDlgPosition=wxDefaultPosition)
Show the dialog box for a layer selection.
void SetGridOrigin(const VECTOR2I &aPoint) override
PCB_ORIGIN_TRANSFORMS m_originTransforms
EDA_3D_VIEWER_FRAME * CreateAndShow3D_Frame()
Show the 3D view frame.
wxTimer m_watcherDebounceTimer
void PlaceFootprint(FOOTPRINT *aFootprint, bool aRecreateRatsnest=true, std::optional< VECTOR2I > aPosition=std::nullopt)
Place aFootprint at the current cursor position (or provided one) and updates footprint coordinates w...
EDA_3D_VIEWER_FRAME * Get3DViewerFrame()
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
wxFileName m_watcherFileName
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
virtual void UpdateStatusBar() override
Update the status bar information.
virtual void AppendCopyToUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aTypeCommand)
As SaveCopyInUndoList, but appends the changes to the last undo item on the stack.
Class to display a pcb layer list in a wxBitmapComboBox.
Parameters and options when plotting/printing a board.
A holder to handle information on schematic or board items.
A progress reporter interface for use in multi-threaded environments.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:37
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
ZONE_SETTINGS handles zones parameters.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
wxDECLARE_EVENT(EDA_EVT_BOARD_CHANGING, wxCommandEvent)
SEVERITY
#define wxFileSystemWatcher
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683