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-2019 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 <vector>
36 
37 #include <eda_draw_frame.h>
38 #include <base_struct.h>
39 #include <eda_text.h> // EDA_DRAW_MODE_T
40 #include <richio.h>
41 #include <pcb_screen.h>
42 #include <pcb_display_options.h>
43 #include <pcb_draw_panel_gal.h>
44 #include <lib_id.h>
45 
46 /* Forward declarations of classes. */
47 class APP_SETTINGS_BASE;
48 class BOARD;
50 class COLOR_SETTINGS;
51 class MODULE;
52 class TRACK;
53 class D_PAD;
54 class TEXTE_MODULE;
55 class EDA_3D_VIEWER;
56 class GENERAL_COLLECTOR;
59 class ZONE_SETTINGS;
60 class PCB_PLOT_PARAMS;
61 class FP_LIB_TABLE;
62 class PCBNEW_SETTINGS;
63 
69 {
70 public:
72 
73  int m_FastGrid1; // 1st fast grid setting (index in EDA_DRAW_FRAME::m_gridSelectBox)
74  int m_FastGrid2; // 2nd fast grid setting (index in EDA_DRAW_FRAME::m_gridSelectBox)
75 
76 protected:
78 
80 
81  PCBNEW_SETTINGS* m_Settings; // No ownership, just a shortcut
82 
83  void updateZoomSelectBox();
84  virtual void unitsChangeRefresh() override;
85 
96  MODULE* loadFootprint( const LIB_ID& aFootprintId );
97 
98 public:
99  PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
100  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
101  long aStyle, const wxString& aFrameName );
102 
103  ~PCB_BASE_FRAME();
104 
109 
117  virtual void Update3DView( bool aForceReload, const wxString* aTitle = nullptr );
118 
127  MODULE* LoadFootprint( const LIB_ID& aFootprintId );
128 
135  EDA_RECT GetBoardBoundingBox( bool aBoardEdgesOnly = false ) const;
136 
137  const BOX2I GetDocumentExtents() const override
138  {
139  return GetBoardBoundingBox( false );
140  }
141 
142  virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
143  const PAGE_INFO& GetPageSettings() const override;
144  const wxSize GetPageSizeIU() const override;
145 
146  const wxPoint& GetAuxOrigin() const override;
147  void SetAuxOrigin( const wxPoint& aPoint ) override;
148 
149  const wxPoint& GetGridOrigin() const override;
150  void SetGridOrigin( const wxPoint& aPoint ) override;
151 
152  const TITLE_BLOCK& GetTitleBlock() const override;
153  void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
154 
160  virtual BOARD_DESIGN_SETTINGS& GetDesignSettings() const;
161  virtual void SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings );
162 
168 
170 
171  void SetDrawBgColor( COLOR4D aColor ) override;
172 
180  {
181  return m_DisplayOptions;
182  }
183 
184  void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
185  {
186  m_DisplayOptions = aOptions;
187  }
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 
206  virtual void SetBoard( BOARD* aBoard );
207 
208  BOARD* GetBoard() const
209  {
210  wxASSERT( m_Pcb );
211  return m_Pcb;
212  }
213 
214  void FocusOnItem( BOARD_ITEM* aItem );
215 
216  // General
217  virtual void OnCloseWindow( wxCloseEvent& Event ) = 0;
218  virtual void ReCreateOptToolbar() override { }
219  virtual void ShowChangedLanguage() override;
220  virtual void ReCreateMenuBar() override;
221  virtual void UpdateStatusBar() override;
222 
223  PCB_SCREEN* GetScreen() const override { return (PCB_SCREEN*) EDA_DRAW_FRAME::GetScreen(); }
224 
225  void UpdateGridSelectBox();
226 
233  const wxString GetZoomLevelIndicator() const override;
234 
241 
248 
256  wxString SelectLibrary( const wxString& aNicknameExisting );
257 
265 
275  virtual void OnModify();
276 
277  // Modules (footprints)
278 
290  MODULE* CreateNewModule( const wxString& aModuleName );
291 
292  void Edit_Module( MODULE* module, wxDC* DC );
293 
302  void PlaceModule( MODULE* aModule, bool aRecreateRatsnest = true );
303 
304  void InstallPadOptionsFrame( D_PAD* pad );
305 
312  MODULE* SelectFootprintFromLibTree( LIB_ID aPreselect = LIB_ID() );
313 
319  virtual void AddModuleToBoard( MODULE* module );
320 
328 
329  // ratsnest functions
338  void Compile_Ratsnest( bool aDisplayStatus );
339 
340  /* Functions relative to Undo/redo commands: */
341 
351  virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy,
352  UNDO_REDO_T aTypeCommand,
353  const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
354 
364  virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
365  UNDO_REDO_T aTypeCommand,
366  const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
367 
368 
376  PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer,
377  LSET aNotAllowedLayersMask = LSET(),
378  wxPoint aDlgPosition = wxDefaultPosition );
379 
380  virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer );
381 
386  virtual void SetActiveLayer( PCB_LAYER_ID aLayer )
387  {
388  GetScreen()->m_Active_Layer = aLayer;
389  }
390 
395  virtual PCB_LAYER_ID GetActiveLayer() const
396  {
397  return GetScreen()->m_Active_Layer;
398  }
399 
400  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
401  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
402 
404 
405  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
406 
407  void OnTogglePadDrawMode( wxCommandEvent& aEvent );
408  void OnToggleGraphicDrawMode( wxCommandEvent& aEvent );
409  void OnToggleEdgeDrawMode( wxCommandEvent& aEvent );
410  void OnToggleTextDrawMode( wxCommandEvent& aEvent );
411 
412  // User interface update event handlers.
413  void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent );
414 
415  virtual void OnUpdateLayerAlpha( wxUpdateUIEvent& aEvent ) {}
416 
422  void SetFastGrid1();
423 
429  void SetFastGrid2();
430 
436  virtual bool IsGridVisible() const override;
437 
446  virtual void SetGridVisibility( bool aVisible ) override;
447 
453  void DisplayGridMsg();
454 
455  PCB_DRAW_PANEL_GAL* GetCanvas() const override;
456 
458  virtual void ActivateGalCanvas() override;
459 
460  DECLARE_EVENT_TABLE()
461 };
462 
463 #endif // PCB_BASE_FRAME_H
wxString SelectFootprintFromLibBrowser()
Function SelectFootprintFromLibBrowser launches the footprint viewer to select the name of a footprin...
virtual void SetBoard(BOARD *aBoard)
Function SetBoard sets 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 OnTogglePadDrawMode(wxCommandEvent &aEvent)
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
virtual void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void OnToggleTextDrawMode(wxCommandEvent &aEvent)
virtual bool IsGridVisible() const override
Function IsGridVisible()
void SetGridOrigin(const wxPoint &aPoint) override
virtual void AddModuleToBoard(MODULE *module)
Adds the given module to the board.
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
void OnToggleEdgeDrawMode(wxCommandEvent &aEvent)
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
void SetFastGrid2()
Function SetFastGrid2()
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
const wxPoint & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
void OnToggleGraphicDrawMode(wxCommandEvent &aEvent)
MODULE * SelectFootprintFromLibTree(LIB_ID aPreselect=LIB_ID())
Function SelectFootprintFromLibTree opens a dialog to select a footprint.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
void SetDrawBgColor(COLOR4D aColor) override
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.
MODULE * CreateNewModule(const wxString &aModuleName)
Function CreateNewModule Creates a new module or footprint, at position 0,0 The new module contains o...
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
PCB_LAYER_ID m_Active_Layer
Definition: pcb_screen.h:44
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
const wxPoint & GetAuxOrigin() const override
Return the origin of the axis used for plotting and various exports.
void SetFastGrid1()
Function SetFastGrid1()
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
PCB_LAYER_ID
A quick note on layer IDs:
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Function GetCollectorsGuide.
LSET is a set of PCB_LAYER_IDs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
virtual void ActivateGalCanvas() override
EDA_3D_VIEWER * CreateAndShow3D_Frame()
Shows the 3D view frame.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
COLOR_SETTINGS * ColorSettings()
Helper to retrieve the current color settings.
const ZONE_SETTINGS & GetZoneSettings() const
virtual void OnUpdateLayerAlpha(wxUpdateUIEvent &aEvent)
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
EDA_RECT GetBoardBoundingBox(bool aBoardEdgesOnly=false) const
Function GetBoardBoundingBox calculates the bounding box containing all board items (or board edge se...
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
Function SetActiveLayer will change the currently active layer to aLayer.
PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
wxPoint m_UserGridSize
virtual void ReCreateMenuBar() override
Recreates the menu bar.
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
PCB_DISPLAY_OPTIONS m_DisplayOptions
void UpdateGridSelectBox()
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves 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:58
virtual void OnCloseWindow(wxCloseEvent &Event)=0
PCBNEW_SETTINGS * m_Settings
void DisplayGridMsg()
Function DisplayGridMsg()
const TITLE_BLOCK & GetTitleBlock() const override
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
virtual void UpdateStatusBar() override
Update the status bar information.
MODULE * LoadFootprint(const LIB_ID &aFootprintId)
Function LoadFootprint attempts to load aFootprintId from the footprint library table.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
virtual void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings)
virtual void SetGridVisibility(bool aVisible) override
Function SetGridVisibility() Turn the display of the canvas grid on/off.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
PCBNEW_SETTINGS & Settings()
const PAGE_INFO & GetPageSettings() const override
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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...
void SetZoneSettings(const ZONE_SETTINGS &aSettings)
void SetAuxOrigin(const wxPoint &aPoint) override
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Definition: eda_3d_viewer.h:65
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use.
void InstallPadOptionsFrame(D_PAD *pad)
MODULE * GetFootprintFromBoardByReference()
Function GetFootprintFromBoardByReference.
void Edit_Module(MODULE *module, wxDC *DC)
BOARD * GetBoard() const
void updateZoomSelectBox()
void PlaceModule(MODULE *aModule, bool aRecreateRatsnest=true)
Function PlaceModule places aModule at the current cursor position and updates module coordinates wit...
virtual void ReCreateOptToolbar() override
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:385
virtual void Update3DView(bool aForceReload, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
EDA_3D_VIEWER * Get3DViewerFrame()
Definition of PCB_DISPLAY_OPTIONS class.
PCB_LAYER_ID SelectLayer(PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask=LSET(), wxPoint aDlgPosition=wxDefaultPosition)
Install the dialog box for layer selection.
Definition: sel_layer.cpp:206
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
MODULE * loadFootprint(const LIB_ID &aFootprintId)
Function loadFootprint attempts to load aFootprintId from the footprint library table.
void FocusOnItem(BOARD_ITEM *aItem)
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
const BOX2I GetDocumentExtents() const override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
PCBNEW_SETTINGS * GetSettings()
const wxString GetZoomLevelIndicator() const override
Function GetZoomLevelIndicator returns a human readable value which can be displayed as zoom level in...
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40