KiCad PCB EDA Suite
eda_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) 2009-2015 Jean-Pierre Charras, jp.charras wanadoo.fr
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
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 EDA_BASE_FRAME_H_
32 #define EDA_BASE_FRAME_H_
33 
34 
35 #include <vector>
36 
37 #include <wx/socket.h>
38 #include <wx/log.h>
39 #include <wx/wxhtml.h>
40 #include <wx/laywin.h>
41 #include <wx/aui/aui.h>
42 #include <wx/docview.h>
43 #include <fctsys.h>
44 #include <common.h>
46 #include <frame_type.h>
47 #include <hotkeys_basic.h>
48 #include <kiway_holder.h>
49 #include <tool/tools_holder.h>
50 #include <widgets/ui_common.h>
51 
52 // Option for main frames
53 #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
54 
55 
56 #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
57 
58 
59 class EDA_ITEM;
60 class EDA_RECT;
61 class EDA_DRAW_PANEL_GAL;
62 class EDA_MSG_PANEL;
63 class BASE_SCREEN;
64 class PARAM_CFG;
65 class PAGE_INFO;
66 class PLOTTER;
67 class TITLE_BLOCK;
68 class MSG_PANEL_ITEM;
69 class TOOL_MANAGER;
70 class TOOL_DISPATCHER;
71 class ACTIONS;
72 class PAGED_DIALOG;
75 class FILE_HISTORY;
76 class SETTINGS_MANAGER;
77 class APP_SETTINGS_BASE;
78 class WX_INFOBAR;
79 struct WINDOW_SETTINGS;
80 
86 };
87 
88 wxDECLARE_EVENT( UNITS_CHANGED, wxCommandEvent );
89 
90 
103 class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
104 {
115  void windowClosing( wxCloseEvent& event );
116 
117  wxWindow* findQuasiModalDialog();
118 
119 protected:
120  FRAME_T m_Ident; // Id Type (pcb, schematic, library..)
122  wxSize m_FrameSize;
123 
124  // These contain the frame size and position for when it is not maximized
127 
128  wxString m_AboutTitle; // Name of program displayed in About.
129 
130  wxAuiManager m_auimgr;
131  wxString m_perspective; // wxAuiManager perspective.
132 
133  WX_INFOBAR* m_infoBar; // Infobar for the frame
134 
135  wxString m_configName; // Prefix used to identify some params (frame size...)
136  // and to name some config files (legacy hotkey files)
137 
139 
140  FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
141 
144  int m_autoSaveInterval; // The auto save interval time in seconds.
145  wxTimer* m_autoSaveTimer;
146 
147  wxString m_mruPath; // Most recently used path.
148 
150 
152  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
153 
157  static wxString GetBackupSuffix()
158  {
159  return wxT( "-bak" );
160  }
161 
165  static wxString GetAutoSaveFilePrefix()
166  {
167  return wxT( "_autosave-" );
168  }
169 
173  void onAutoSaveTimer( wxTimerEvent& aEvent );
174 
180  virtual bool isAutoSaveRequired() const { return false; }
181 
187  virtual bool doAutoSave();
188 
195  virtual void unitsChangeRefresh() { }
196 
197  DECLARE_EVENT_TABLE()
198 
199 public:
200  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
201  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
202  long aStyle, const wxString& aFrameName, KIWAY* aKiway );
203 
204  ~EDA_BASE_FRAME();
205 
210  {
211  return m_userUnits;
212  }
213 
214  void SetUserUnits( EDA_UNITS aUnits )
215  {
216  m_userUnits = aUnits;
217  }
218 
219  void ChangeUserUnits( EDA_UNITS aUnits );
220 
221  virtual void ToggleUserUnits() { }
222 
224 
225  virtual int GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
226 
233  bool ProcessEvent( wxEvent& aEvent ) override;
234 
242  virtual void OnCharHook( wxKeyEvent& event );
243 
248  void OnMenuEvent( wxMenuEvent& event );
249 
250  virtual void OnMove( wxMoveEvent& aEvent )
251  {
252  aEvent.Skip();
253  }
254 
255  void OnMaximize( wxMaximizeEvent& aEvent );
256 
257  void SetAutoSaveInterval( int aInterval );
258 
259  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
260 
261  bool IsType( FRAME_T aType ) const { return m_Ident == aType; }
262 
268  virtual const SEARCH_STACK& sys_search();
269 
270  virtual wxString help_name();
271 
272  void OnKicadAbout( wxCommandEvent& event );
273  void OnPreferences( wxCommandEvent& event );
274 
275  void PrintMsg( const wxString& text );
276 
278 
283  virtual APP_SETTINGS_BASE* config() const;
284 
291 
297  void LoadWindowSettings( WINDOW_SETTINGS* aCfg );
298 
304  void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
305 
312  virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
313 
321  virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
322 
329 
337  wxString ConfigBaseName() override
338  {
339  wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
340  return baseCfgName;
341  }
342 
350  virtual void SaveProjectSettings() {};
351 
352  // Read/Save and Import/export hotkeys config
353 
361  void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
362  const wxString& aDefaultShortname );
363 
376  wxString GetFileFromHistory( int cmdId, const wxString& type,
377  FILE_HISTORY* aFileHistory = nullptr );
378 
385  void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr );
386 
396  void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr );
397 
404  {
405  return *m_fileHistory;
406  }
407 
408  void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
409 
410  wxString GetMruPath() const { return m_mruPath; }
411 
418  virtual wxString GetCurrentFileName() const { return wxEmptyString; }
419 
425  virtual void ReCreateMenuBar();
426 
430  void AddStandardHelpMenu( wxMenuBar* aMenuBar );
431 
446  bool IsWritable( const wxFileName& aFileName );
447 
460  void CheckForAutoSaveFile( const wxFileName& aFileName );
461 
469  virtual void UpdateStatusBar() { }
470 
475  virtual void SyncToolbars() { };
476 
480  virtual void ShowChangedLanguage();
481 
486  void CommonSettingsChanged( bool aEnvVarsChanged ) override;
487 
488  const wxString& GetAboutTitle() const { return m_AboutTitle; }
489 
496  void SetShutdownBlockReason( const wxString& reason );
497 
502 
507 
513  virtual bool IsContentModified();
514 
523  wxSize GetWindowSize();
524 };
525 
526 
548 class EDA_PANE : public wxAuiPaneInfo
549 {
550 public:
552  {
553  Gripper( false );
554  CloseButton( false );
555  PaneBorder( false );
556  }
557 
562  {
563  SetFlag( optionToolbar, true );
564  CaptionVisible( false );
565  TopDockable().BottomDockable();
566  DockFixed( true );
567  Movable( false );
568  Resizable( true ); // expand to fit available space
569  return *this;
570  }
571 
576  {
577  SetFlag( optionToolbar, true );
578  CaptionVisible( false );
579  LeftDockable().RightDockable();
580  DockFixed( true );
581  Movable( false );
582  Resizable( true ); // expand to fit available space
583  return *this;
584  }
585 
590  {
591  CaptionVisible( true );
592  PaneBorder( true );
593  return *this;
594  }
595 
600  {
601  CaptionVisible( false );
602  Layer( 0 );
603  PaneBorder( true );
604  Resizable( true ); // expand to fit available space
605  return *this;
606  }
607 
612  {
613  CaptionVisible( false );
614  BottomDockable( true );
615  DockFixed( true );
616  Movable( false );
617  Resizable( true ); // expand to fit available space
618  return *this;
619  }
620 
625  {
626  CaptionVisible( false );
627  Movable( false );
628  Resizable( true );
629  PaneBorder( false );
630  DockFixed( true );
631  return *this;
632  }
633 };
634 
635 #endif // EDA_BASE_FRAME_H_
EDA_UNITS
Definition: common.h:198
void PrintMsg(const wxString &text)
KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
id_librarytype
wxString m_mruPath
void SetShutdownBlockReason(const wxString &reason)
Sets the block reason why the window/application is preventing OS shutdown.
virtual bool doAutoSave()
This should be overridden by the derived class to handle the auto save feature.
void SetMruPath(const wxString &aPath)
SETTINGS_MANAGER * GetSettingsManager() const
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Saves common frame parameters to a configuration data file.
void SaveWindowSettings(WINDOW_SETTINGS *aCfg)
Saves window settings to the given settings object Normally called by SaveSettings unless the window ...
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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 windowClosing(wxCloseEvent &event)
(with its unexpected name so it does not collide with the real OnWindowClose() function provided in d...
virtual bool isAutoSaveRequired() const
Return the auto save status of the application.
void onAutoSaveTimer(wxTimerEvent &aEvent)
Handle the auto save timer event.
virtual void SaveProjectSettings()
Save changes to the project settings to the project (.pro) file.
wxString m_AboutTitle
virtual bool IsContentModified()
Get if the contents of the frame have been modified since the last save.
void ChangeUserUnits(EDA_UNITS aUnits)
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
wxAuiManager m_auimgr
bool IsWritable(const wxFileName &aFileName)
Checks if aFileName can be written.
EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
void ImportHotkeyConfigFromFile(std::map< std::string, TOOL_ACTION * > aActionMap, const wxString &aDefaultShortname)
Prompt the user for a hotkey file to read, and read it.
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
wxTimer * m_autoSaveTimer
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
virtual void SyncToolbars()
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
wxString m_perspective
wxSize m_NormalFrameSize
virtual void UpdateStatusBar()
Update the status bar information.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
TOOL_MANAGER.
Definition: tool_manager.h:51
wxString GetMruPath() const
wxWindow * findQuasiModalDialog()
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:68
virtual void OnCharHook(wxKeyEvent &event)
Capture the key event before it is sent to the GUI.
void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:91
virtual void unitsChangeRefresh()
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
static wxString GetBackupSuffix()
virtual const SEARCH_STACK & sys_search()
Return a SEARCH_STACK pertaining to entire program.
EDA_PANE & VToolbar()
Turn *this into a vertical toolbar for KiCad.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:44
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Returns a pointer to the window settings for this frame.
Functions to provide common constants and other functions to assist in making a consistent UI.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
int GetAutoSaveInterval() const
void OnKicadAbout(wxCommandEvent &event)
virtual int GetSeverity(int aErrorCode) const
void LoadWindowSettings(WINDOW_SETTINGS *aCfg)
Loads window settings from the given settings object Normally called by LoadSettings unless the windo...
Specialization of the wxAuiPaneInfo class for KiCad panels.
TOOL_DISPATCHER.
EDA_PANE & Canvas()
Turn *this into an undecorated pane suitable for a drawing canvas.
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
void RemoveShutdownBlockReason()
Removes any shutdown block reason set.
virtual void OnMove(wxMoveEvent &aEvent)
static wxString GetAutoSaveFilePrefix()
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:68
EDA_PANE & InfoBar()
Turn *this into a infobar for KiCad.
Base plotter engine class.
Definition: plotter.h:114
void OnMaximize(wxMaximizeEvent &aEvent)
void SetAutoSaveInterval(int aInterval)
virtual void ToggleUserUnits()
wxSize GetWindowSize()
Get the undecorated window size that can be used for restoring the window size.
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
Board layer functions and definitions.
bool IsType(FRAME_T aType) const
wxString ConfigBaseName() override
EDA_PANE & Palette()
Turn *this into a captioned palette suitable for a symbol tree, layers manager, etc.
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:81
WX_INFOBAR * m_infoBar
wxDECLARE_EVENT(UNITS_CHANGED, wxCommandEvent)
const wxString & GetAboutTitle() const
The base frame for deriving all KiCad main window classes.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
SETTINGS_MANAGER * m_settingsManager
EDA_UNITS m_userUnits
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
The common library.
virtual wxString help_name()
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
EDA_PANE & Messages()
Turn *this into a messages pane for KiCad.
void OnPreferences(wxCommandEvent &event)
ACTIONS.
Definition: actions.h:43
WX_INFOBAR * GetInfoBar()
void SetUserUnits(EDA_UNITS aUnits)
virtual void InstallPreferences(PAGED_DIALOG *, PANEL_HOTKEYS_EDITOR *)
Function InstallPreferences Allow a frame to load its preference panels (if any) into the preferences...
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
EDA_PANE & HToolbar()
Turn *this to a horizontal toolbar for KiCad.
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
virtual wxString GetCurrentFileName() const
Get the full filename + path of the currently opened file in the frame.
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
wxString m_configName
FILE_HISTORY * m_fileHistory
wxPoint m_NormalFramePos
void OnMenuEvent(wxMenuEvent &event)
The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu events aren't ...
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void ReCreateMenuBar()
Recreates the menu bar.