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>
44 #include <fctsys.h>
45 #include <common.h>
47 #include <frame_type.h>
48 #include <hotkeys_basic.h>
49 #include <kiway_holder.h>
50 #include <tool/tools_holder.h>
51 #include <widgets/ui_common.h>
52 #include <undo_redo_container.h>
53 
54 // Option for main frames
55 #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
56 
57 
58 #define KICAD_MANAGER_FRAME_NAME wxT( "KicadFrame" )
59 
60 
61 class EDA_ITEM;
62 class EDA_RECT;
63 class EDA_DRAW_PANEL_GAL;
64 class EDA_MSG_PANEL;
65 class BASE_SCREEN;
66 class PARAM_CFG;
67 class PAGE_INFO;
68 class PLOTTER;
69 class TITLE_BLOCK;
70 class MSG_PANEL_ITEM;
71 class TOOL_MANAGER;
72 class TOOL_DISPATCHER;
73 class ACTIONS;
74 class PAGED_DIALOG;
77 class FILE_HISTORY;
78 class SETTINGS_MANAGER;
79 class APP_SETTINGS_BASE;
80 class WX_INFOBAR;
81 struct WINDOW_SETTINGS;
82 struct WINDOW_STATE;
83 
89 };
90 
91 #define DEFAULT_MAX_UNDO_ITEMS 0
92 #define ABS_MAX_UNDO_ITEMS (INT_MAX / 2)
93 
95 typedef std::function< void( wxUpdateUIEvent& ) > UIUpdateHandler;
96 
97 wxDECLARE_EVENT( UNITS_CHANGED, wxCommandEvent );
98 
99 
112 class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
113 {
124  void windowClosing( wxCloseEvent& event );
125 
126  wxWindow* findQuasiModalDialog();
127 
134  virtual bool IsModal() const { return false; }
135 
136 protected:
137  FRAME_T m_Ident; // Id Type (pcb, schematic, library..)
139  wxSize m_FrameSize;
140 
141  // These contain the frame size and position for when it is not maximized
144 
145  wxString m_AboutTitle; // Name of program displayed in About.
146 
147  wxAuiManager m_auimgr;
148  wxString m_perspective; // wxAuiManager perspective.
149 
150  WX_INFOBAR* m_infoBar; // Infobar for the frame
151 
152  wxString m_configName; // Prefix used to identify some params (frame size...)
153  // and to name some config files (legacy hotkey files)
154 
156 
157  FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
158 
161  int m_autoSaveInterval; // The auto save interval time in seconds.
162  wxTimer* m_autoSaveTimer;
163 
164  bool m_FlagModified; // Indicates current drawing has been modified.
165  bool m_FlagSave; // Indicates automatic file save.
166  int m_UndoRedoCountMax; // undo/Redo command Max depth
167 
168  UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
169  UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
170 
171  wxString m_mruPath; // Most recently used path.
172 
174 
175  // Map containing the UI update handlers registered with wx for each action
176  std::map<int, UIUpdateHandler> m_uiUpdateMap;
177  bool m_isClosing; // Set by the close window event handler after frames are asked if they can close
178  // Allows other functions when called to know our state is cleanup
179  bool m_isNonUserClose; // Set by NonUserClose() to indicate that the user did not request the current close
180 
182  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
183 
187  static wxString GetBackupSuffix()
188  {
189  return wxT( "-bak" );
190  }
191 
195  static wxString GetAutoSaveFilePrefix()
196  {
197  return wxT( "_autosave-" );
198  }
199 
203  void onAutoSaveTimer( wxTimerEvent& aEvent );
204 
210  virtual bool isAutoSaveRequired() const { return false; }
211 
217  virtual bool doAutoSave();
218 
219  virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
220  virtual void doCloseWindow() { }
221 
228  virtual void unitsChangeRefresh() { }
229 
233  virtual void setupUIConditions();
234 
235  DECLARE_EVENT_TABLE()
236 
237 public:
238  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
239  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
240  long aStyle, const wxString& aFrameName, KIWAY* aKiway );
241 
242  ~EDA_BASE_FRAME();
243 
248  {
249  return m_userUnits;
250  }
251 
252  void SetUserUnits( EDA_UNITS aUnits )
253  {
254  m_userUnits = aUnits;
255  }
256 
257  void ChangeUserUnits( EDA_UNITS aUnits );
258 
259  virtual void ToggleUserUnits() { }
260 
262 
263  virtual int GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
264 
271  bool ProcessEvent( wxEvent& aEvent ) override;
272 
280  virtual void OnCharHook( wxKeyEvent& event );
281 
286  void OnMenuEvent( wxMenuEvent& event );
287 
288  virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
289  const ACTION_CONDITIONS& aConditions ) override
290  {
291  RegisterUIUpdateHandler( aAction.GetUIId(), aConditions );
292  }
293 
300  virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions );
301 
302  virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction ) override
303  {
304  UnregisterUIUpdateHandler( aAction.GetUIId() );
305  }
306 
312  virtual void UnregisterUIUpdateHandler( int aID );
313 
322  static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
323  ACTION_CONDITIONS aCond );
324 
325  virtual void OnMove( wxMoveEvent& aEvent )
326  {
327  aEvent.Skip();
328  }
329 
330  void OnMaximize( wxMaximizeEvent& aEvent );
331 
332  void SetAutoSaveInterval( int aInterval );
333 
334  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
335 
336  bool IsType( FRAME_T aType ) const { return m_Ident == aType; }
337 
343  virtual const SEARCH_STACK& sys_search();
344 
345  virtual wxString help_name();
346 
347  void OnKicadAbout( wxCommandEvent& event );
348  void OnPreferences( wxCommandEvent& event );
349 
350  void PrintMsg( const wxString& text );
351 
353 
354  void ShowInfoBarError( const wxString& aErrorMsg );
355  void ShowInfoBarWarning( const wxString& aWarningMsg );
356  void ShowInfoBarMsg( const wxString& aMsg );
357 
362  virtual APP_SETTINGS_BASE* config() const;
363 
370 
371 
372  void LoadWindowState( const wxString& aFileName );
378  void LoadWindowSettings( const WINDOW_SETTINGS* aCfg );
379 
385  void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
386 
393  virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
394 
402  virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
403 
410 
414  virtual void LoadWindowState( const WINDOW_STATE& aState );
415 
423  wxString ConfigBaseName() override
424  {
425  wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
426  return baseCfgName;
427  }
428 
436  virtual void SaveProjectSettings() {};
437 
438  // Read/Save and Import/export hotkeys config
439 
447  void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
448  const wxString& aDefaultShortname );
449 
462  wxString GetFileFromHistory( int cmdId, const wxString& type,
463  FILE_HISTORY* aFileHistory = nullptr );
464 
471  void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr );
472 
482  void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr );
483 
490  {
491  return *m_fileHistory;
492  }
493 
494  void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
495 
496  wxString GetMruPath() const { return m_mruPath; }
497 
504  virtual wxString GetCurrentFileName() const { return wxEmptyString; }
505 
511  virtual void ReCreateMenuBar();
512 
516  void AddStandardHelpMenu( wxMenuBar* aMenuBar );
517 
532  bool IsWritable( const wxFileName& aFileName );
533 
546  void CheckForAutoSaveFile( const wxFileName& aFileName );
547 
555  virtual void UpdateStatusBar() { }
556 
560  virtual void ShowChangedLanguage();
561 
566  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
567 
571  virtual void ProjectChanged() {}
572 
573  const wxString& GetAboutTitle() const { return m_AboutTitle; }
574 
580  virtual bool IsContentModified();
581 
590  wxSize GetWindowSize();
591 
592 
593  /* general Undo/Redo command control */
594 
608  virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 )
609  { }
610 
617  virtual void ClearUndoRedoList();
618 
626  virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
627 
635  virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
636 
642 
648 
649  virtual int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
650  virtual int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
651 
652  int GetMaxUndoItems() const { return m_UndoRedoCountMax; }
653 
654  bool NonUserClose( bool aForce )
655  {
656  m_isNonUserClose = true;
657  return Close( aForce );
658  }
659 };
660 
661 
683 class EDA_PANE : public wxAuiPaneInfo
684 {
685 public:
687  {
688  Gripper( false );
689  CloseButton( false );
690  PaneBorder( false );
691  }
692 
697  {
698  SetFlag( optionToolbar, true );
699  CaptionVisible( false );
700  TopDockable().BottomDockable();
701  DockFixed( true );
702  Movable( false );
703  Resizable( true ); // expand to fit available space
704  return *this;
705  }
706 
711  {
712  SetFlag( optionToolbar, true );
713  CaptionVisible( false );
714  LeftDockable().RightDockable();
715  DockFixed( true );
716  Movable( false );
717  Resizable( true ); // expand to fit available space
718  return *this;
719  }
720 
725  {
726  CaptionVisible( true );
727  PaneBorder( true );
728  return *this;
729  }
730 
735  {
736  CaptionVisible( false );
737  Layer( 0 );
738  PaneBorder( true );
739  Resizable( true ); // expand to fit available space
740  return *this;
741  }
742 
747  {
748  CaptionVisible( false );
749  BottomDockable( true );
750  DockFixed( true );
751  Movable( false );
752  Resizable( true ); // expand to fit available space
753  return *this;
754  }
755 
760  {
761  CaptionVisible( false );
762  Movable( false );
763  Resizable( true );
764  PaneBorder( false );
765  DockFixed( true );
766  return *this;
767  }
768 };
769 
770 #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
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 UnregisterUIUpdateHandler(const TOOL_ACTION &aAction) override
Unregister a UI handler for an action that was registered using RegisterUIUpdateHandler.
int GetUIId() const
Definition: tool_action.h:102
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)
wxString m_AboutTitle
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 void RegisterUIUpdateHandler(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions) override
Register an action's update conditions with the UI layer to allow the UI to appropriately display the...
virtual bool IsContentModified()
Get if the contents of the frame have been modified since the last save.
virtual int GetRedoCommandCount() const
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: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 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
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
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.
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 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:43
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)
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: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
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...
Represents a single user action.
Definition: tool_action.h:44
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.
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: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 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_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.