KiCad PCB EDA Suite
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 <stambaughw@verizon.net>
6  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef PCB_BASE_FRAME_H
32 #define PCB_BASE_FRAME_H
33 
34 
35 #include <eda_item.h>
36 #include <board.h>
37 #include <eda_draw_frame.h>
38 #include <outline_mode.h>
39 #include <lib_id.h>
40 #include <pcb_display_options.h>
41 #include <pcb_draw_panel_gal.h>
42 #include <pcb_origin_transforms.h>
43 #include <pcb_screen.h>
44 #include <richio.h>
45 #include <vector>
46 
47 
48 /* Forward declarations of classes. */
49 class APP_SETTINGS_BASE;
50 class BOARD;
52 class COLOR_SETTINGS;
53 class FOOTPRINT;
54 class TRACK;
55 class PAD;
56 class EDA_3D_VIEWER;
57 class GENERAL_COLLECTOR;
60 class ZONE_SETTINGS;
61 class PCB_PLOT_PARAMS;
62 class FP_LIB_TABLE;
63 class PCBNEW_SETTINGS;
65 struct MAGNETIC_SETTINGS;
66 
67 
68 wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent );
69 
74 {
75 public:
76  PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
77  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
78  long aStyle, const wxString& aFrameName );
79 
81 
86 
95  virtual void Update3DView( bool aMarkDirty, bool aRefresh,
96  const wxString* aTitle = nullptr );
97 
105  FOOTPRINT* LoadFootprint( const LIB_ID& aFootprintId );
106 
113  EDA_RECT GetBoardBoundingBox( bool aBoardEdgesOnly = false ) const;
114 
115  const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override
116  {
117  /* "Zoom to Fit" calls this with "aIncludeAllVisible" as true. Since that feature
118  * always ignored the page and border, this function returns a bbox without them
119  * as well when passed true. This technically is not all things visible, but it
120  * keeps behavior consistent.
121  *
122  * When passed false, this function returns a bbox of just the board edge. This
123  * allows things like fabrication text or anything else outside the board edge to
124  * be ignored, and just zooms up to the board itself.
125  *
126  * Calling "GetBoardBoundingBox(true)" when edge cuts are turned off will return
127  * the entire page and border, so we call "GetBoardBoundingBox(false)" instead.
128  */
129  if( aIncludeAllVisible || !m_pcb->IsLayerVisible( Edge_Cuts ) )
130  return GetBoardBoundingBox( false );
131  else
132  return GetBoardBoundingBox( true );
133  }
134 
135  virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
136  const PAGE_INFO& GetPageSettings() const override;
137  const wxSize GetPageSizeIU() const override;
138 
139  const wxPoint& GetGridOrigin() const override;
140  void SetGridOrigin( const wxPoint& aPoint ) override;
141 
142  const wxPoint& GetAuxOrigin() const;
143 
144  const wxPoint GetUserOrigin() const;
145 
150 
151  const TITLE_BLOCK& GetTitleBlock() const override;
152  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
153 
159  virtual BOARD_DESIGN_SETTINGS& GetDesignSettings() const;
160 
166  virtual COLOR_SETTINGS* GetColorSettings() const override
167  {
168  wxFAIL_MSG( "Color settings requested for a PCB_BASE_FRAME that does not override!" );
169  return nullptr;
170  }
171 
173 
174  void SetDrawBgColor( COLOR4D aColor ) override;
175 
181 
187  void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh = true );
188 
189  const ZONE_SETTINGS& GetZoneSettings() const;
190  void SetZoneSettings( const ZONE_SETTINGS& aSettings );
191 
197  virtual const PCB_PLOT_PARAMS& GetPlotSettings() const;
198  virtual void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings );
199 
205  virtual void SetBoard( BOARD* aBoard );
206 
207  BOARD* GetBoard() const
208  {
209  wxASSERT( m_pcb );
210  return m_pcb;
211  }
212 
216  virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
217 
218  EDA_ITEM* GetItem( const KIID& aId ) const override;
219 
220  void FocusOnItem( BOARD_ITEM* aItem );
221 
222  // General
223  virtual void ReCreateOptToolbar() override { }
224  virtual void ShowChangedLanguage() override;
225  virtual void ReCreateMenuBar() override;
226  virtual void UpdateStatusBar() override;
227 
228  PCB_SCREEN* GetScreen() const override { return (PCB_SCREEN*) EDA_DRAW_FRAME::GetScreen(); }
229 
236 
241 
248  wxString SelectLibrary( const wxString& aNicknameExisting );
249 
256 
264  virtual void OnModify();
265 
278  FOOTPRINT* CreateNewFootprint( const wxString& aFootprintName );
279 
286  void PlaceFootprint( FOOTPRINT* aFootprint, bool aRecreateRatsnest = true );
287 
288  void ShowPadPropertiesDialog( PAD* aPad );
289 
296 
302  virtual void AddFootprintToBoard( FOOTPRINT* aFootprint );
303 
310 
320  void Compile_Ratsnest( bool aDisplayStatus );
321 
328  virtual void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand ) = 0;
329 
336  virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO aTypeCommand ) = 0;
337 
338 
349  PCB_LAYER_ID SelectOneLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(),
350  wxPoint aDlgPosition = wxDefaultPosition );
351 
352  virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer );
353 
354  virtual void SetActiveLayer( PCB_LAYER_ID aLayer )
355  {
356  GetScreen()->m_Active_Layer = aLayer;
357  }
358 
359  virtual PCB_LAYER_ID GetActiveLayer() const
360  {
361  return GetScreen()->m_Active_Layer;
362  }
363 
364  SEVERITY GetSeverity( int aErrorCode ) const override;
365 
366  virtual void OnDisplayOptionsChanged() {}
367 
368  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
369  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
370 
372 
374 
376 
377  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
378 
382  void DisplayGridMsg() override;
383 
384  PCB_DRAW_PANEL_GAL* GetCanvas() const override;
385 
386  virtual void ActivateGalCanvas() override;
387 
391  virtual void SetAutoZoom( bool aAutoZoom ) {}
392 
396  virtual bool GetAutoZoom() { return false; }
397 
398 protected:
399 
409  FOOTPRINT* loadFootprint( const LIB_ID& aFootprintId );
410 
414  PCBNEW_SETTINGS* m_settings; // No ownership, just a shortcut
415 
416  virtual void unitsChangeRefresh() override;
417 };
418 
419 #endif // PCB_BASE_FRAME_H
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:225
wxString SelectFootprintFromLibBrowser()
Launch the footprint viewer to select the name of a footprint to load.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
virtual void SetBoard(BOARD *aBoard)
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
virtual void ShowChangedLanguage() override
Redraw the menus and what not in current language.
void DisplayGridMsg() override
Display the current grid pane on the status bar.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void SetGridOrigin(const wxPoint &aPoint) override
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:41
virtual void OnDisplayOptionsChanged()
FOOTPRINT * SelectFootprintFromLibTree(LIB_ID aPreselect=LIB_ID())
Open a dialog to select a footprint.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
SEVERITY
Definition: ui_common.h:83
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings() const
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
const wxPoint & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
const wxPoint GetUserOrigin() const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
void SetDrawBgColor(COLOR4D aColor) override
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
PCB_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
The base class for create windows for drawing purpose.
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Return the PCB_PLOT_PARAMS for the BOARD owned by this frame.
PCBNEW_SETTINGS * m_settings
PCB_LAYER_ID m_Active_Layer
Definition: pcb_screen.h:42
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
void PlaceFootprint(FOOTPRINT *aFootprint, bool aRecreateRatsnest=true)
Places aFootprint at the current cursor position and updates footprint coordinates with the new posit...
SEVERITY GetSeverity(int aErrorCode) const override
virtual bool GetAutoZoom()
Always returns false.
virtual COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DISPLAY_OPTIONS m_displayOptions
Definition: kiid.h:44
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Updates the current display options from the given options struct.
Container for display options like enable/disable some optional drawings.
PCB_LAYER_ID
A quick note on layer IDs:
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
LSET is a set of PCB_LAYER_IDs.
FOOTPRINT * loadFootprint(const LIB_ID &aFootprintId)
Attempts to load aFootprintId from the footprint library table.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
virtual void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
EDA_3D_VIEWER * CreateAndShow3D_Frame()
Shows the 3D view frame.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
EDA_ITEM * GetItem(const KIID &aId) const override
Fetch an item by KIID.
const ZONE_SETTINGS & GetZoneSettings() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
EDA_RECT 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.
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
A holder to handle information on schematic or board items.
virtual void ReCreateMenuBar() override
Recreates the menu bar.
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
virtual void SwitchLayer(wxDC *DC, PCB_LAYER_ID layer)
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
FOOTPRINT * CreateNewFootprint(const wxString &aFootprintName)
Creates a new footprint, at position 0,0.
const TITLE_BLOCK & GetTitleBlock() const override
virtual void OnModify()
Must be called after a change in order to set the "modify" flag of the current screen and update the ...
virtual void UpdateStatusBar() override
Update the status bar information.
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:453
wxDECLARE_EVENT(BOARD_CHANGED, wxCommandEvent)
A class to perform either relative or absolute display origin transforms for a single axis of a point...
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
ORIGIN_TRANSFORMS & GetOriginTransforms() override
Return a reference to the default ORIGIN_TRANSFORMS object.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
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 SetAutoZoom(bool aAutoZoom)
Does nothing.
Handle the component boundary box.
Definition: eda_rect.h:42
PCBNEW_SETTINGS & Settings()
PCBNEW_SETTINGS * GetPcbNewSettings() const
const PAGE_INFO & GetPageSettings() const override
virtual void AddFootprintToBoard(FOOTPRINT *aFootprint)
Add the given footprint to the board.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand)=0
Create a new entry in undo list of commands.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings) override
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Definition: eda_3d_viewer.h:66
wxString SelectLibrary(const wxString &aNicknameExisting)
Put up a dialog and allows the user to pick a library, for unspecified use.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD * GetBoard() const
virtual void ReCreateOptToolbar() override
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:381
Definition: pad.h:60
void ShowPadPropertiesDialog(PAD *aPad)
EDA_3D_VIEWER * Get3DViewerFrame()
Definition of PCB_DISPLAY_OPTIONS class.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
void FocusOnItem(BOARD_ITEM *aItem)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Definition: track.h:83
FOOTPRINT * GetFootprintFromBoardByReference()
PCB_ORIGIN_TRANSFORMS m_originTransforms
Container for design settings for a BOARD object.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
const wxPoint & GetAuxOrigin() const