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 <wx/event.h>
45 #include <frame_type.h>
46 #include <hotkeys_basic.h>
47 #include <kiway_holder.h>
48 #include <tool/tools_holder.h>
49 #include <widgets/ui_common.h>
50 #include <undo_redo_container.h>
51 #include <eda_units.h>
52 
53 // Option for main frames
54 #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
55 
56 
57 #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
58 
59 
60 class EDA_ITEM;
61 class EDA_RECT;
62 class EDA_DRAW_PANEL_GAL;
63 class EDA_MSG_PANEL;
64 class BASE_SCREEN;
65 class PARAM_CFG;
66 class PAGE_INFO;
67 class PLOTTER;
68 class TITLE_BLOCK;
69 class MSG_PANEL_ITEM;
70 class TOOL_MANAGER;
71 class TOOL_DISPATCHER;
72 class ACTIONS;
73 class PAGED_DIALOG;
76 class FILE_HISTORY;
77 class SETTINGS_MANAGER;
78 class SEARCH_STACK;
79 class APP_SETTINGS_BASE;
80 class WX_INFOBAR;
81 struct WINDOW_SETTINGS;
82 struct WINDOW_STATE;
83 
84 #define DEFAULT_MAX_UNDO_ITEMS 0
85 #define ABS_MAX_UNDO_ITEMS (INT_MAX / 2)
86 
88 typedef std::function< void( wxUpdateUIEvent& ) > UIUpdateHandler;
89 
90 wxDECLARE_EVENT( UNITS_CHANGED, wxCommandEvent );
91 
92 
105 class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
106 {
117  void windowClosing( wxCloseEvent& event );
118 
119  wxWindow* findQuasiModalDialog();
120 
127  virtual bool IsModal() const { return false; }
128 
129 protected:
130  FRAME_T m_ident; // Id Type (pcb, schematic, library..)
131  wxPoint m_framePos;
132  wxSize m_frameSize;
134 
135  // These contain the frame size and position for when it is not maximized
138 
139  wxString m_aboutTitle; // Name of program displayed in About.
140 
141  wxAuiManager m_auimgr;
142  wxString m_perspective; // wxAuiManager perspective.
143 
144  WX_INFOBAR* m_infoBar; // Infobar for the frame
145 
146  wxString m_configName; // Prefix used to identify some params (frame size...)
147  // and to name some config files (legacy hotkey files)
148 
150 
151  FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
152 
155  int m_autoSaveInterval; // The auto save interval time in seconds.
156  wxTimer* m_autoSaveTimer;
157 
158  int m_undoRedoCountMax; // undo/Redo command Max depth
159 
160  UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
161  UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
162 
163  wxString m_mruPath; // Most recently used path.
164 
166 
167  // Map containing the UI update handlers registered with wx for each action
168  std::map<int, UIUpdateHandler> m_uiUpdateMap;
169  bool m_isClosing; // Set by the close window event handler after frames are asked if they can close
170  // Allows other functions when called to know our state is cleanup
171  bool m_isNonUserClose; // Set by NonUserClose() to indicate that the user did not request the current close
172 
174  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
175 
179  static wxString GetBackupSuffix()
180  {
181  return wxT( "-bak" );
182  }
183 
187  static wxString GetAutoSaveFilePrefix()
188  {
189  return wxT( "_autosave-" );
190  }
191 
195  void onAutoSaveTimer( wxTimerEvent& aEvent );
196 
202  virtual bool isAutoSaveRequired() const { return false; }
203 
209  virtual bool doAutoSave();
210 
211  virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
212  virtual void doCloseWindow() { }
213 
220  virtual void unitsChangeRefresh() { }
221 
225  virtual void setupUIConditions();
226 
227  DECLARE_EVENT_TABLE()
228 
229 public:
230  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
231  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
232  long aStyle, const wxString& aFrameName, KIWAY* aKiway );
233 
234  ~EDA_BASE_FRAME();
235 
240  {
241  return m_userUnits;
242  }
243 
244  void SetUserUnits( EDA_UNITS aUnits )
245  {
246  m_userUnits = aUnits;
247  }
248 
249  void ChangeUserUnits( EDA_UNITS aUnits );
250 
251  virtual void ToggleUserUnits() { }
252 
254 
255  virtual int GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
256 
263  bool ProcessEvent( wxEvent& aEvent ) override;
264 
272  virtual void OnCharHook( wxKeyEvent& event );
273 
278  void OnMenuEvent( wxMenuEvent& event );
279 
286  virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions ) override;
287 
293  virtual void UnregisterUIUpdateHandler( int aID ) override;
294 
303  static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
304  ACTION_CONDITIONS aCond );
305 
306  virtual void OnMove( wxMoveEvent& aEvent )
307  {
308  aEvent.Skip();
309  }
310 
311  void OnMaximize( wxMaximizeEvent& aEvent );
312 
313  void SetAutoSaveInterval( int aInterval );
314 
315  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
316 
317  bool IsType( FRAME_T aType ) const { return m_ident == aType; }
318 
324  virtual const SEARCH_STACK& sys_search();
325 
326  virtual wxString help_name();
327 
328  void OnKicadAbout( wxCommandEvent& event );
329  void OnPreferences( wxCommandEvent& event );
330 
331  void PrintMsg( const wxString& text );
332 
334 
335  void ShowInfoBarError( const wxString& aErrorMsg );
336  void ShowInfoBarWarning( const wxString& aWarningMsg );
337  void ShowInfoBarMsg( const wxString& aMsg );
338 
343  virtual APP_SETTINGS_BASE* config() const;
344 
351 
352 
353  void LoadWindowState( const wxString& aFileName );
359  void LoadWindowSettings( const WINDOW_SETTINGS* aCfg );
360 
366  void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
367 
374  virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
375 
383  virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
384 
391 
395  virtual void LoadWindowState( const WINDOW_STATE& aState );
396 
404  wxString ConfigBaseName() override
405  {
406  wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
407  return baseCfgName;
408  }
409 
417  virtual void SaveProjectSettings() {};
418 
419  // Read/Save and Import/export hotkeys config
420 
428  void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
429  const wxString& aDefaultShortname );
430 
443  wxString GetFileFromHistory( int cmdId, const wxString& type,
444  FILE_HISTORY* aFileHistory = nullptr );
445 
452  void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr );
453 
463  void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr );
464 
471  {
472  return *m_fileHistory;
473  }
474 
475  void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
476 
477  wxString GetMruPath() const { return m_mruPath; }
478 
485  virtual wxString GetCurrentFileName() const { return wxEmptyString; }
486 
492  virtual void ReCreateMenuBar();
493 
497  void AddStandardHelpMenu( wxMenuBar* aMenuBar );
498 
513  bool IsWritable( const wxFileName& aFileName );
514 
527  void CheckForAutoSaveFile( const wxFileName& aFileName );
528 
536  virtual void UpdateStatusBar() { }
537 
541  virtual void ShowChangedLanguage();
542 
547  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
548 
552  virtual void ProjectChanged() {}
553 
554  const wxString& GetAboutTitle() const { return m_aboutTitle; }
555 
561  virtual bool IsContentModified();
562 
571  wxSize GetWindowSize();
572 
573 
574  /* general Undo/Redo command control */
575 
589  virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 )
590  { }
591 
598  virtual void ClearUndoRedoList();
599 
607  virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
608 
616  virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
617 
623 
629 
630  virtual int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
631  virtual int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
632 
633  int GetMaxUndoItems() const { return m_undoRedoCountMax; }
634 
635  bool NonUserClose( bool aForce )
636  {
637  m_isNonUserClose = true;
638  return Close( aForce );
639  }
640 };
641 
642 
664 class EDA_PANE : public wxAuiPaneInfo
665 {
666 public:
668  {
669  Gripper( false );
670  CloseButton( false );
671  PaneBorder( false );
672  }
673 
678  {
679  SetFlag( optionToolbar, true );
680  CaptionVisible( false );
681  TopDockable().BottomDockable();
682  DockFixed( true );
683  Movable( false );
684  Resizable( true ); // expand to fit available space
685  return *this;
686  }
687 
692  {
693  SetFlag( optionToolbar, true );
694  CaptionVisible( false );
695  LeftDockable().RightDockable();
696  DockFixed( true );
697  Movable( false );
698  Resizable( true ); // expand to fit available space
699  return *this;
700  }
701 
706  {
707  CaptionVisible( true );
708  PaneBorder( true );
709  return *this;
710  }
711 
716  {
717  CaptionVisible( false );
718  Layer( 0 );
719  PaneBorder( true );
720  Resizable( true ); // expand to fit available space
721  return *this;
722  }
723 
728  {
729  CaptionVisible( false );
730  BottomDockable( true );
731  DockFixed( true );
732  Movable( false );
733  Resizable( true ); // expand to fit available space
734  return *this;
735  }
736 
741  {
742  CaptionVisible( false );
743  Movable( false );
744  Resizable( true );
745  PaneBorder( false );
746  DockFixed( true );
747  return *this;
748  }
749 };
750 
751 #endif // EDA_BASE_FRAME_H_
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
wxString m_mruPath
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 ...
UNDO_REDO_CONTAINER m_undoList
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 void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToRedoList add a command to redo in redo list delete the very old commands when t...
static void HandleUpdateUIEvent(wxUpdateUIEvent &aEvent, EDA_BASE_FRAME *aFrame, ACTION_CONDITIONS aCond)
Handles events generated when the UI is trying to figure out the current state of the UI controls rel...
virtual bool isAutoSaveRequired() const
Return the auto save status of the application.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void onAutoSaveTimer(wxTimerEvent &aEvent)
Handle the auto save timer event.
virtual void SaveProjectSettings()
Save changes to the project settings to the project (.pro) file.
virtual void doCloseWindow()
void ShowInfoBarMsg(const wxString &aMsg)
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToUndoList add a command to undo in undo list delete the very old commands when t...
virtual bool IsModal() const
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
virtual bool IsContentModified()
Get if the contents of the frame have been modified since the last save.
virtual int GetRedoCommandCount() const
wxPoint m_normalFramePos
void ChangeUserUnits(EDA_UNITS aUnits)
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
PopCommandFromRedoList return the last command to undo and remove it from list nothing is deleted.
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:104
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 LoadWindowState(const wxString &aFileName)
std::function< void(wxUpdateUIEvent &) > UIUpdateHandler
This is the handler functor for the update UI events.
virtual void ClearUndoORRedoList(UNDO_REDO_LIST aList, int aItemCount=-1)
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxString m_perspective
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
UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
wxWindow * findQuasiModalDialog()
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
void ShowInfoBarWarning(const wxString &aWarningMsg)
virtual void OnCharHook(wxKeyEvent &event)
Capture the key event before it is sent to the GUI.
wxSize m_normalFrameSize
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:99
virtual int GetUndoCommandCount() const
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
virtual void unitsChangeRefresh()
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
static wxString GetBackupSuffix()
std::map< int, UIUpdateHandler > m_uiUpdateMap
virtual void UnregisterUIUpdateHandler(int aID) override
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
virtual const SEARCH_STACK & sys_search()
Return a SEARCH_STACK pertaining to entire program.
bool NonUserClose(bool aForce)
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:41
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.
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
PopCommandFromUndoList return the last command to undo and remove it from list nothing is deleted.
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 GetMaxUndoItems() const
int GetAutoSaveInterval() const
void OnKicadAbout(wxCommandEvent &event)
virtual int GetSeverity(int aErrorCode) const
PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void ShowInfoBarError(const wxString &aErrorMsg)
Specialization of the wxAuiPaneInfo class for KiCad panels.
Stores the window positioning/state.
Definition: app_settings.h:68
UNDO_REDO_CONTAINER m_redoList
virtual bool canCloseWindow(wxCloseEvent &aCloseEvent)
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.
UNDO_REDO_LIST
Function ClearUndoORRedoList (virtual).
virtual void OnMove(wxMoveEvent &aEvent)
EDA_UNITS
Definition: eda_units.h:38
static wxString GetAutoSaveFilePrefix()
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:70
EDA_PANE & InfoBar()
Turn *this into a infobar for KiCad.
Base plotter engine class.
Definition: plotter.h:131
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:85
WX_INFOBAR * m_infoBar
wxDECLARE_EVENT(UNITS_CHANGED, wxCommandEvent)
const wxString & GetAboutTitle() const
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
The base frame for deriving all KiCad main window classes.
void LoadWindowSettings(const WINDOW_SETTINGS *aCfg)
Loads window settings from the given settings object Normally called by LoadSettings unless the windo...
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: eda_item.h:148
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 ProjectChanged()
Notification event that the project has changed.
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:54
EDA_PANE & HToolbar()
Turn *this to a horizontal toolbar for KiCad.
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
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_aboutTitle
wxString m_configName
FILE_HISTORY * m_fileHistory
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.