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 (C) 1992-2023 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, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef PCB_BASE_FRAME_H
28#define PCB_BASE_FRAME_H
29
30#include <eda_units.h>
31#include <eda_draw_frame.h>
32#include <outline_mode.h>
33#include <lib_id.h>
34#include <pcb_display_options.h>
35#include <pcb_draw_panel_gal.h>
37#include <pcb_screen.h>
38#include <vector>
39
40#include <wx/datetime.h>
41#include <wx/timer.h>
42
43/* Forward declarations of classes. */
45class BOARD;
47class COLOR_SETTINGS;
48class EDA_ITEM;
49class FOOTPRINT;
50class PAD;
55class ZONE_SETTINGS;
56class PCB_PLOT_PARAMS;
57class FP_LIB_TABLE;
59class PCBNEW_SETTINGS;
64
65#ifdef wxHAS_INOTIFY
66#define wxFileSystemWatcher wxInotifyFileSystemWatcher
67#elif defined( wxHAS_KQUEUE ) && defined( wxHAVE_FSEVENTS_FILE_NOTIFICATIONS )
68#define wxFileSystemWatcher wxFsEventsFileSystemWatcher
69#elif defined( wxHAS_KQUEUE )
70#define wxFileSystemWatcher wxKqueueFileSystemWatcher
71#elif defined( __WINDOWS__ )
72#define wxFileSystemWatcher wxMSWFileSystemWatcher
73#else
74#define wxFileSystemWatcher wxPollingFileSystemWatcher
75#endif
76
78class wxFileSystemWatcherEvent;
79
80wxDECLARE_EVENT( EDA_EVT_BOARD_CHANGED, wxCommandEvent );
81
86{
87public:
88 PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
89 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
90 long aStyle, const wxString& aFrameName );
91
93
98
106 virtual void Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle = nullptr );
107
115 FOOTPRINT* LoadFootprint( const LIB_ID& aFootprintId );
116
123 BOX2I GetBoardBoundingBox( bool aBoardEdgesOnly = false ) const;
124
125 const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override;
126
127 virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
128 const PAGE_INFO& GetPageSettings() const override;
129 const VECTOR2I GetPageSizeIU() const override;
130
131 const VECTOR2I& GetGridOrigin() const override;
132 void SetGridOrigin( const VECTOR2I& aPoint ) override;
133
134 const VECTOR2I& GetAuxOrigin() const;
135
136 const VECTOR2I GetUserOrigin() const;
137
142
143 wxString MessageTextFromCoord( int aValue, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType ) const
144 {
145 return MessageTextFromValue( m_originTransforms.ToDisplay( aValue, aCoordType ) );
146 }
147
148 const TITLE_BLOCK& GetTitleBlock() const override;
149 void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
150
155
159 virtual COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override
160 {
161 wxFAIL_MSG( wxT( "Color settings requested for a PCB_BASE_FRAME that does not override!" ) );
162 return nullptr;
163 }
164
165 void SetDrawBgColor( const COLOR4D& aColor ) override;
166
172
178 void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh = true );
179
183 virtual const PCB_PLOT_PARAMS& GetPlotSettings() const;
184 virtual void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings );
185
190 virtual void ReloadFootprint( FOOTPRINT* aFootprint )
191 {
192 wxFAIL_MSG( wxT( "Attempted to reload a footprint for PCB_BASE_FRAME that does not override!" ) );
193 }
194
198 virtual void SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
199
201 {
202 wxASSERT( m_pcb );
203 return m_pcb;
204 }
205
209 virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
210
211 EDA_ITEM* GetItem( const KIID& aId ) const override;
212
213 void FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
214 void FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
215
216 void HideSolderMask();
217 void ShowSolderMask();
218
219 // General
220 virtual void ShowChangedLanguage() override;
221 virtual void UpdateStatusBar() override;
222
223 PCB_SCREEN* GetScreen() const override { return (PCB_SCREEN*) EDA_DRAW_FRAME::GetScreen(); }
224
231
236
243 wxString SelectLibrary( const wxString& aNicknameExisting );
244
251
256 void OnModify() override;
257
272 FOOTPRINT* CreateNewFootprint( const wxString& aFootprintName, const wxString& aLibName,
273 bool aQuiet );
274
281 void PlaceFootprint( FOOTPRINT* aFootprint, bool aRecreateRatsnest = true );
282
283 void ShowPadPropertiesDialog( PAD* aPad );
284
291
297 virtual void AddFootprintToBoard( FOOTPRINT* aFootprint );
298
307 void Compile_Ratsnest( bool aDisplayStatus );
308
315 virtual void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand ) {};
316
323 virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
324 UNDO_REDO aTypeCommand ) {};
325
329 virtual void AppendCopyToUndoList( const PICKED_ITEMS_LIST& aItemsList,
330 UNDO_REDO aTypeCommand ) {};
331
332
343 PCB_LAYER_ID SelectOneLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(),
344 wxPoint aDlgPosition = wxDefaultPosition );
345
351 virtual void SwitchLayer( PCB_LAYER_ID aLayer );
352
353 virtual void SetActiveLayer( PCB_LAYER_ID aLayer ) { GetScreen()->m_Active_Layer = aLayer; }
355
356 SEVERITY GetSeverity( int aErrorCode ) const override;
357
358 virtual void OnDisplayOptionsChanged() {}
359
360 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
361 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
362
364
366
368
370
371 void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
372
373 PCB_DRAW_PANEL_GAL* GetCanvas() const override;
374
375 virtual void ActivateGalCanvas() override;
376
386 void AddBoardChangeListener( wxEvtHandler* aListener );
387
391 void RemoveBoardChangeListener( wxEvtHandler* aListener );
392
396 void OnFPChange( wxFileSystemWatcherEvent& aEvent );
397
401 void OnFpChangeDebounceTimer( wxTimerEvent& aEvent );
402
403protected:
404 bool canCloseWindow( wxCloseEvent& aCloseEvent ) override;
405
406 void handleActivateEvent( wxActivateEvent& aEvent ) override;
407
408 void handleIconizeEvent( wxIconizeEvent& aEvent ) override;
409
410 virtual void doReCreateMenuBar() override;
411
421 FOOTPRINT* loadFootprint( const LIB_ID& aFootprintId );
422
423 virtual void unitsChangeRefresh() override;
424
425 void rebuildConnectivity();
426
431 void setFPWatcher( FOOTPRINT* aFootprint );
432
433protected:
437
438private:
440
441 std::unique_ptr<wxFileSystemWatcher> m_watcher;
445
446 std::vector<wxEvtHandler*> m_boardChangeListeners;
447};
448
449#endif // PCB_BASE_FRAME_H
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
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:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
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.
The base class for create windows for drawing purpose.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:323
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:206
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Definition: kiid.h:49
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
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:53
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
SEVERITY GetSeverity(int aErrorCode) const override
std::unique_ptr< wxFileSystemWatcher > m_watcher
virtual void SaveCopyInUndoList(const PICKED_ITEMS_LIST &aItemsList, UNDO_REDO aTypeCommand)
Creates a new entry in undo list of commands.
virtual void ReloadFootprint(FOOTPRINT *aFootprint)
Reload the footprint from the library.
PCB_LAYER_ID SelectOneLayer(PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask=LSET(), wxPoint aDlgPosition=wxDefaultPosition)
Show the dialog box for a layer selection.
Definition: sel_layer.cpp:285
virtual void OnDisplayOptionsChanged()
void FocusOnItems(std::vector< BOARD_ITEM * > aItems, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
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.
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.
FOOTPRINT * GetFootprintFromBoardByReference()
void setFPWatcher(FOOTPRINT *aFootprint)
Creates (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 ...
EDA_ITEM * GetItem(const KIID &aId) const override
Fetch an item by KIID.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox 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...
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual void SwitchLayer(PCB_LAYER_ID aLayer)
Change the active layer in the frame.
virtual PCB_LAYER_ID GetActiveLayer() const
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
FOOTPRINT * loadFootprint(const LIB_ID &aFootprintId)
Attempts to load aFootprintId from the footprint library table.
const VECTOR2I GetUserOrigin() const
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
std::vector< wxEvtHandler * > m_boardChangeListeners
FOOTPRINT * SelectFootprintFromLibrary(LIB_ID aPreselect=LIB_ID())
Open a dialog to select a footprint.
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.
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).
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.
wxString SelectLibrary(const wxString &aNicknameExisting)
Put up a dialog and allows the user to pick a library, for unspecified use.
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 void SetPageSettings(const PAGE_INFO &aPageSettings) override
NL_PCBNEW_PLUGIN * m_spaceMouse
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
Returns 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)
Updates the current display options from the given options struct.
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
void PlaceFootprint(FOOTPRINT *aFootprint, bool aRecreateRatsnest=true)
Places aFootprint at the current cursor position and updates footprint coordinates with the new posit...
wxString MessageTextFromCoord(int aValue, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType) const
PCB_DISPLAY_OPTIONS m_displayOptions
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings() const
void SetGridOrigin(const VECTOR2I &aPoint) override
FOOTPRINT * CreateNewFootprint(const wxString &aFootprintName, const wxString &aLibName, bool aQuiet)
Creates a new footprint, at position 0,0.
PCB_ORIGIN_TRANSFORMS m_originTransforms
EDA_3D_VIEWER_FRAME * CreateAndShow3D_Frame()
Shows the 3D view frame.
wxTimer m_watcherDebounceTimer
EDA_3D_VIEWER_FRAME * Get3DViewerFrame()
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:35
wxFileName m_watcherFileName
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
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.
virtual long long int ToDisplay(long long int aValue, COORD_TYPES_T aCoordType) const override
Parameters and options when plotting/printing a board.
PCB_LAYER_ID m_Active_Layer
Definition: pcb_screen.h:42
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:41
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.
Definition: zone_settings.h:71
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
wxDECLARE_EVENT(EDA_EVT_BOARD_CHANGED, wxCommandEvent)
#define wxFileSystemWatcher
SEVERITY
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...