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 <widgets/ui_common.h>
50 
51 // Option for main frames
52 #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
53 
54 
55 #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
56 
57 
58 // Readability helper definitions for creating backup files.
59 #define CREATE_BACKUP_FILE true
60 #define NO_BACKUP_FILE false
61 
62 class EDA_ITEM;
63 class EDA_RECT;
64 class EDA_DRAW_PANEL_GAL;
65 class EDA_MSG_PANEL;
66 class BASE_SCREEN;
67 class PARAM_CFG;
68 class PAGE_INFO;
69 class PLOTTER;
70 class TITLE_BLOCK;
71 class MSG_PANEL_ITEM;
72 class TOOL_MANAGER;
73 class TOOL_DISPATCHER;
74 class ACTIONS;
75 class PAGED_DIALOG;
78 class FILE_HISTORY;
79 class SETTINGS_MANAGER;
80 class APP_SETTINGS_BASE;
81 struct WINDOW_SETTINGS;
82 
88 };
89 
90 
103 class EDA_BASE_FRAME : public wxFrame, 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  wxString m_AboutTitle; // Name of program displayed in About.
125 
126  wxAuiManager m_auimgr;
127 
128  wxString m_configName; // Prefix used to identify some params (frame size...)
129  // and to name some config files (legacy hotkey files)
130 
132 
135 
136  std::vector<std::string> m_toolStack; // Stack of user-level "tools". Not to be confused
137  // with TOOL_BASE-derived instances, many of which
138  // implement multiple user-level "tools". The user-
139  // level "tools" are TOOL_ACTIONSs internally.
140 
141  bool m_immediateActions; // Preference for immediate actions. If false, the
142  // first invocation of a hotkey will just select the
143  // relevant tool.
144  bool m_dragSelects; // Prefer selection to dragging.
145  bool m_moveWarpsCursor; // cursor is warped to move/drag origin
148  int m_autoSaveInterval; // The auto save interval time in seconds.
149  wxTimer* m_autoSaveTimer;
150 
151  wxString m_perspective; // wxAuiManager perspective.
152 
153  wxString m_mruPath; // Most recently used path.
154 
156 
158  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
159 
163  static wxString GetBackupSuffix()
164  {
165  return wxT( "-bak" );
166  }
167 
171  static wxString GetAutoSaveFilePrefix()
172  {
173  return wxT( "_autosave-" );
174  }
175 
179  void onAutoSaveTimer( wxTimerEvent& aEvent );
180 
186  virtual bool isAutoSaveRequired() const { return false; }
187 
193  virtual bool doAutoSave();
194 
201  virtual void unitsChangeRefresh() { }
202 
203  DECLARE_EVENT_TABLE()
204 
205 public:
206  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
207  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
208  long aStyle, const wxString& aFrameName, KIWAY* aKiway );
209 
210  ~EDA_BASE_FRAME();
211 
216  {
217  return m_userUnits;
218  }
219 
220  void SetUserUnits( EDA_UNITS aUnits )
221  {
222  m_userUnits = aUnits;
223  }
224 
225  void ChangeUserUnits( EDA_UNITS aUnits )
226  {
227  SetUserUnits( aUnits );
229  }
230 
232 
233  virtual int GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
234 
239 
245  virtual void PushTool( const std::string& actionName );
246  virtual void PopTool( const std::string& actionName );
247 
248  bool ToolStackIsEmpty() { return m_toolStack.empty(); }
249 
250  std::string CurrentToolName() const;
251  bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
252 
253  virtual void DisplayToolMsg( const wxString& msg ) {};
254 
259  bool GetDoImmediateActions() const { return m_immediateActions; }
260 
265  bool GetDragSelects() const { return m_dragSelects; }
266 
271  bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
272 
279  bool ProcessEvent( wxEvent& aEvent ) override;
280 
288  virtual void OnCharHook( wxKeyEvent& event );
289 
294  void OnMenuOpen( wxMenuEvent& event );
295 
296  virtual void OnMove( wxMoveEvent& aEvent )
297  {
298  aEvent.Skip();
299  }
300 
301  void SetAutoSaveInterval( int aInterval );
302 
303  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
304 
305  bool IsType( FRAME_T aType ) const { return m_Ident == aType; }
306 
312  virtual const SEARCH_STACK& sys_search();
313 
314  virtual wxString help_name();
315 
316  void OnKicadAbout( wxCommandEvent& event );
317  void OnPreferences( wxCommandEvent& event );
318 
319  void PrintMsg( const wxString& text );
320 
325  virtual APP_SETTINGS_BASE* config();
326 
333 
339  void LoadWindowSettings( WINDOW_SETTINGS* aCfg );
340 
346  void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
347 
354  virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
355 
363  virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
364 
371 
379  wxString ConfigBaseName()
380  {
381  wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
382  return baseCfgName;
383  }
384 
392  virtual void SaveProjectSettings() {};
393 
394  // Read/Save and Import/export hotkeys config
395 
403  void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
404  const wxString& aDefaultShortname );
405 
418  wxString GetFileFromHistory( int cmdId, const wxString& type,
419  FILE_HISTORY* aFileHistory = NULL );
420 
427  void ClearFileHistory( FILE_HISTORY* aFileHistory = NULL );
428 
438  void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = NULL );
439 
440  void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
441 
442  wxString GetMruPath() const { return m_mruPath; }
443 
449  virtual void ReCreateMenuBar();
450 
454  void AddStandardHelpMenu( wxMenuBar* aMenuBar );
455 
470  bool IsWritable( const wxFileName& aFileName );
471 
484  void CheckForAutoSaveFile( const wxFileName& aFileName );
485 
493  virtual void UpdateStatusBar() { }
494 
499  virtual void SyncToolbars() { };
500 
504  virtual void ShowChangedLanguage();
505 
510  virtual void CommonSettingsChanged( bool aEnvVarsChanged );
511 
515  virtual void RefreshCanvas() { };
516 
517  const wxString& GetAboutTitle() const { return m_AboutTitle; }
518 
525  void SetShutdownBlockReason( const wxString& reason );
526 
531 
536 
542  virtual bool IsContentModified();
543 };
544 
545 
567 class EDA_PANE : public wxAuiPaneInfo
568 {
569 public:
571  {
572  Gripper( false );
573  CloseButton( false );
574  PaneBorder( false );
575  }
576 
581  {
582  SetFlag( optionToolbar, true );
583  CaptionVisible( false );
584  TopDockable().BottomDockable();
585  DockFixed( true );
586  Movable( false );
587  Resizable( true ); // expand to fit available space
588  return *this;
589  }
590 
595  {
596  SetFlag( optionToolbar, true );
597  CaptionVisible( false );
598  LeftDockable().RightDockable();
599  DockFixed( true );
600  Movable( false );
601  Resizable( true ); // expand to fit available space
602  return *this;
603  }
604 
609  {
610  CaptionVisible( true );
611  PaneBorder( true );
612  return *this;
613  }
614 
619  {
620  CaptionVisible( false );
621  Layer( 0 );
622  PaneBorder( true );
623  Resizable( true ); // expand to fit available space
624  return *this;
625  }
626 
631  {
632  CaptionVisible( false );
633  BottomDockable( true );
634  DockFixed( true );
635  Movable( false );
636  Resizable( true ); // expand to fit available space
637  return *this;
638  }
639 };
640 
641 #endif // EDA_BASE_FRAME_H_
EDA_UNITS
Definition: common.h:184
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
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
id_librarytype
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
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 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 ...
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.
ACTIONS * m_actions
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 ConfigBaseName()
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 ClearFileHistory(FILE_HISTORY *aFileHistory=NULL)
Removes all files from the file history.
virtual void SyncToolbars()
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
wxString m_perspective
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=NULL)
Update the list of recently opened files.
virtual void UpdateStatusBar()
Update the status bar information.
TOOL_MANAGER.
Definition: tool_manager.h:50
wxString GetMruPath() const
wxWindow * findQuasiModalDialog()
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:52
virtual void OnCharHook(wxKeyEvent &event)
Capture the key event before it is sent to the GUI.
bool GetDoImmediateActions() const
Indicates that hotkeys should perform an immediate action even if another tool is currently active.
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:75
#define NULL
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.
virtual void DisplayToolMsg(const wxString &msg)
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:74
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...
void OnMenuOpen(wxMenuEvent &event)
Workaround some issues in wxWidgets where the menu events aren't captured by the menus themselves.
Specialization of the wxAuiPaneInfo class for KiCad panels.
TOOL_DISPATCHER.
EDA_PANE & Canvas()
Turn *this into an undecorated pane suitable for a drawing canvas.
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)
virtual void CommonSettingsChanged(bool aEnvVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
static wxString GetAutoSaveFilePrefix()
Base plotter engine class.
Definition: plotter.h:104
void SetAutoSaveInterval(int aInterval)
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=NULL)
Fetches the file name from the file history list.
Board layer functions and definitions.
std::vector< std::string > m_toolStack
bool ToolStackIsEmpty()
bool IsType(FRAME_T aType) const
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:98
const wxString & GetAboutTitle() const
The base frame for deriving all KiCad main window classes.
TOOL_ACTION.
Definition: tool_action.h:46
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:166
bool GetMoveWarpsCursor() const
Indicates that a move operation should warp the mouse pointer to the origin of the move object.
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.
virtual void PopTool(const std::string &actionName)
void OnPreferences(wxCommandEvent &event)
ACTIONS.
Definition: actions.h:43
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...
TOOL_MANAGER * m_toolManager
std::string CurrentToolName() const
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
virtual APP_SETTINGS_BASE * config()
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
EDA_PANE & HToolbar()
Turn *this to a horizontal toolbar for KiCad.
bool IsCurrentTool(const TOOL_ACTION &aAction) const
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
bool GetDragSelects() const
Indicates that a drag should draw a selection rectangle, even when started over an item.
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
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void RefreshCanvas()
Notification to refresh the drawing canvas (if any).
virtual void ReCreateMenuBar()
Recreates the menu bar.