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-2020 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 
102 class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
103 {
104 public:
105  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
106  const wxPoint& aPos, const wxSize& aSize, long aStyle,
107  const wxString& aFrameName, KIWAY* aKiway );
108 
109  ~EDA_BASE_FRAME();
110 
115  {
116  return m_userUnits;
117  }
118 
119  void SetUserUnits( EDA_UNITS aUnits )
120  {
121  m_userUnits = aUnits;
122  }
123 
124  void ChangeUserUnits( EDA_UNITS aUnits );
125 
126  virtual void ToggleUserUnits() { }
127 
129 
130  virtual SEVERITY GetSeverity( int aErrorCode ) const { return RPT_SEVERITY_UNDEFINED; }
131 
138  bool ProcessEvent( wxEvent& aEvent ) override;
139 
147  virtual void OnCharHook( wxKeyEvent& event );
148 
153  void OnMenuEvent( wxMenuEvent& event );
154 
161  virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions ) override;
162 
168  virtual void UnregisterUIUpdateHandler( int aID ) override;
169 
178  static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
179  ACTION_CONDITIONS aCond );
180 
181  virtual void OnMove( wxMoveEvent& aEvent )
182  {
183  aEvent.Skip();
184  }
185 
186  void OnMaximize( wxMaximizeEvent& aEvent );
187 
188  void SetAutoSaveInterval( int aInterval );
189 
190  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
191 
192  bool IsType( FRAME_T aType ) const { return m_ident == aType; }
193 
199  virtual const SEARCH_STACK& sys_search();
200 
201  virtual wxString help_name();
202 
203  void OnKicadAbout( wxCommandEvent& event );
204  void OnPreferences( wxCommandEvent& event );
205 
206  void PrintMsg( const wxString& text );
207 
208  void CreateInfoBar();
209 
211 
216 
226  void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false );
227 
242  void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
243  std::function<void(void)> aCallback );
244 
254  void ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton = false );
255 
265  void ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton = false );
266 
271  virtual APP_SETTINGS_BASE* config() const;
272 
279 
280 
281  void LoadWindowState( const wxString& aFileName );
288  void LoadWindowSettings( const WINDOW_SETTINGS* aCfg );
289 
296  void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
297 
304  virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
305 
312  virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
313 
322 
326  virtual void LoadWindowState( const WINDOW_STATE& aState );
327 
338  wxString ConfigBaseName() override
339  {
340  wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
341  return baseCfgName;
342  }
343 
352  virtual void SaveProjectSettings() {};
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 
419  virtual wxString GetCurrentFileName() const { return wxEmptyString; }
420 
426  virtual void ReCreateMenuBar();
427 
431  void AddStandardHelpMenu( wxMenuBar* aMenuBar );
432 
447  bool IsWritable( const wxFileName& aFileName );
448 
461  void CheckForAutoSaveFile( const wxFileName& aFileName );
462 
470  virtual void UpdateStatusBar() { }
471 
475  virtual void ShowChangedLanguage();
476 
481  void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
482 
486  virtual void ProjectChanged() {}
487 
488  const wxString& GetAboutTitle() const { return m_aboutTitle; }
489 
495  virtual bool IsContentModified();
496 
505  wxSize GetWindowSize();
506 
520  virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 )
521  { }
522 
528  virtual void ClearUndoRedoList();
529 
535  virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
536 
542  virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
543 
548 
553 
554  virtual int GetUndoCommandCount() const { return m_undoList.m_CommandsList.size(); }
555  virtual int GetRedoCommandCount() const { return m_redoList.m_CommandsList.size(); }
556 
557  int GetMaxUndoItems() const { return m_undoRedoCountMax; }
558 
559  bool NonUserClose( bool aForce )
560  {
561  m_isNonUserClose = true;
562  return Close( aForce );
563  }
564 
565 protected:
567  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
568 
572  static wxString GetAutoSaveFilePrefix()
573  {
574  return wxT( "_autosave-" );
575  }
576 
580  void onAutoSaveTimer( wxTimerEvent& aEvent );
581 
587  virtual bool isAutoSaveRequired() const { return false; }
588 
594  virtual bool doAutoSave();
595 
596  virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
597  virtual void doCloseWindow() { }
598 
606  virtual void unitsChangeRefresh() { }
607 
611  virtual void setupUIConditions();
612 
619  void initExitKey();
620 
621  DECLARE_EVENT_TABLE()
622 
623 private:
634  void windowClosing( wxCloseEvent& event );
635 
636  wxWindow* findQuasiModalDialog();
637 
645  virtual bool IsModal() const { return false; }
646 
647 protected:
648  FRAME_T m_ident; // Id Type (pcb, schematic, library..)
649  wxPoint m_framePos;
650  wxSize m_frameSize;
652 
653  // These contain the frame size and position for when it is not maximized
656 
657  wxString m_aboutTitle; // Name of program displayed in About.
658 
659  wxAuiManager m_auimgr;
660  wxString m_perspective; // wxAuiManager perspective.
661 
662  WX_INFOBAR* m_infoBar; // Infobar for the frame
663 
664  wxString m_configName; // Prefix used to identify some params (frame size...)
665  // and to name some config files (legacy hotkey files)
666 
668 
669  FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
670 
673  int m_autoSaveInterval; // The auto save interval time in seconds.
674  wxTimer* m_autoSaveTimer;
675 
676  int m_undoRedoCountMax; // undo/Redo command Max depth
677 
678  UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
679  UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
680 
681  wxString m_mruPath; // Most recently used path.
682 
684 
686  std::map<int, UIUpdateHandler> m_uiUpdateMap;
687 
691 
694 
695 };
696 
697 
719 class EDA_PANE : public wxAuiPaneInfo
720 {
721 public:
723  {
724  Gripper( false );
725  CloseButton( false );
726  PaneBorder( false );
727  }
728 
733  {
734  SetFlag( optionToolbar, true );
735  CaptionVisible( false );
736  TopDockable().BottomDockable();
737  DockFixed( true );
738  Movable( false );
739  Resizable( true ); // expand to fit available space
740  return *this;
741  }
742 
747  {
748  SetFlag( optionToolbar, true );
749  CaptionVisible( false );
750  LeftDockable().RightDockable();
751  DockFixed( true );
752  Movable( false );
753  Resizable( true ); // expand to fit available space
754  return *this;
755  }
756 
761  {
762  CaptionVisible( true );
763  PaneBorder( true );
764  return *this;
765  }
766 
771  {
772  CaptionVisible( false );
773  Layer( 0 );
774  PaneBorder( true );
775  Resizable( true ); // expand to fit available space
776  return *this;
777  }
778 
783  {
784  CaptionVisible( false );
785  BottomDockable( true );
786  DockFixed( true );
787  Movable( false );
788  Resizable( true ); // expand to fit available space
789  return *this;
790  }
791 
796  {
797  CaptionVisible( false );
798  Movable( false );
799  Resizable( true );
800  PaneBorder( false );
801  DockFixed( true );
802  return *this;
803  }
804 };
805 
806 #endif // EDA_BASE_FRAME_H_
void PrintMsg(const wxString &text)
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)
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
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)
Save common frame parameters to a configuration data file.
void SaveWindowSettings(WINDOW_SETTINGS *aCfg)
Save window settings to the given settings object.
SEVERITY
Definition: ui_common.h:83
UNDO_REDO_CONTAINER m_undoList
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
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)
Add a command to redo in the redo list.
static void HandleUpdateUIEvent(wxUpdateUIEvent &aEvent, EDA_BASE_FRAME *aFrame, ACTION_CONDITIONS aCond)
Handle events generated when the UI is trying to figure out the current state of the UI controls rela...
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()
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)
Add a command to undo in the undo list.
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)
Look for files in a number of paths.
Definition: search_stack.h:41
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual SEVERITY GetSeverity(int aErrorCode) const
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.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
wxTimer * m_autoSaveTimer
void LoadWindowState(const wxString &aFileName)
void ShowInfoBarWarning(const wxString &aWarningMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and a warning icon on the left ...
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.
void initExitKey()
Sets the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
Master controller class:
Definition: tool_manager.h:52
wxString GetMruPath() const
A holder to handle a list of undo (or redo) commands.
wxWindow * findQuasiModalDialog()
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
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 ...
std::map< int, UIUpdateHandler > m_uiUpdateMap
Set by the close window event handler after frames are asked if they can close.
virtual void UnregisterUIUpdateHandler(int aID) override
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
EDA_BASE_FRAME(wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, KIWAY *aKiway)
void FinishAUIInitialization()
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.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Return a pointer to the window settings for this frame.
virtual PICKED_ITEMS_LIST * 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.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
int GetMaxUndoItems() const
int GetAutoSaveInterval() const
void OnKicadAbout(wxCommandEvent &event)
A holder to handle information on schematic or board items.
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
Remove the aItemCount of old commands from aList and delete commands, pickers and picked items if nee...
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:71
EDA_PANE & InfoBar()
Turn *this into a infobar for KiCad.
Base plotter engine class.
Definition: plotter.h:121
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
Get the configuration base name.
EDA_PANE & Palette()
Turn *this into a captioned palette suitable for a symbol tree, layers manager, etc.
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
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)
Load window settings from the given settings object.
Handle the component boundary box.
Definition: eda_rect.h:42
SETTINGS_MANAGER * m_settingsManager
EDA_UNITS m_userUnits
Map containing the UI update handlers registered with wx for each action.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
virtual wxString help_name()
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
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)
Gather all the actions that are shared by tools.
Definition: actions.h:43
WX_INFOBAR * GetInfoBar()
void SetUserUnits(EDA_UNITS aUnits)
virtual void InstallPreferences(PAGED_DIALOG *, PANEL_HOTKEYS_EDITOR *)
Allow a frame to load its preference panels (if any) into the preferences dialog.
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()
Clear the undo and redo list using ClearUndoORRedoList()
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.