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 WXSTRUCT_H_
32 #define WXSTRUCT_H_
33 
34 
35 #include <vector>
36 
37 #include <wx/socket.h>
38 #include <wx/log.h>
39 #include <wx/config.h>
40 #include <wx/wxhtml.h>
41 #include <wx/laywin.h>
42 #include <wx/aui/aui.h>
43 #include <wx/docview.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 
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_BASE;
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 
80 
86 };
87 
88 
101 class EDA_BASE_FRAME : public wxFrame, public KIWAY_HOLDER
102 {
113  void windowClosing( wxCloseEvent& event );
114 
115  wxWindow* findQuasiModalDialog();
116 
117 protected:
118  FRAME_T m_Ident; // Id Type (pcb, schematic, library..)
119  wxPoint m_FramePos;
120  wxSize m_FrameSize;
121 
122  wxString m_AboutTitle; // Name of program displayed in About.
123 
124  wxAuiManager m_auimgr;
125 
126  wxString m_configName; // Prefix used to identify some params (frame size...)
127  // and to name some config files (legacy hotkey files)
128 
131 
132  std::vector<std::string> m_toolStack; // Stack of user-level "tools". Not to be confused
133  // with TOOL_BASE-derived instances, many of which
134  // implement multiple user-level "tools". The user-
135  // level "tools" are TOOL_ACTIONSs internally.
136 
137  bool m_immediateActions; // Preference for immediate actions. If false, the
138  // first invocation of a hotkey will just select the
139  // relevant tool.
140  bool m_dragSelects; // Prefer selection to dragging.
141  bool m_moveWarpsCursor; // cursor is warped to move/drag origin
144  int m_autoSaveInterval; // The auto save interval time in seconds.
145  wxTimer* m_autoSaveTimer;
146 
147  wxString m_perspective; // wxAuiManager perspective.
148 
149  wxString m_mruPath; // Most recently used path.
150 
152 
154  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
155 
159  static wxString GetBackupSuffix()
160  {
161  return wxT( "-bak" );
162  }
163 
167  static wxString GetAutoSaveFilePrefix()
168  {
169  return wxT( "_autosave-" );
170  }
171 
175  void onAutoSaveTimer( wxTimerEvent& aEvent );
176 
182  virtual bool isAutoSaveRequired() const { return false; }
183 
189  virtual bool doAutoSave();
190 
197  virtual void unitsChangeRefresh() { }
198 
199  DECLARE_EVENT_TABLE()
200 
201 public:
202  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
203  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
204  long aStyle, const wxString& aFrameName, KIWAY* aKiway );
205 
206  ~EDA_BASE_FRAME();
207 
212  void SetUserUnits( EDA_UNITS_T aUnits ) { m_userUnits = aUnits; }
213 
215  {
216  SetUserUnits( aUnits );
218  }
219 
224 
230  virtual void PushTool( const std::string& actionName );
231  virtual void PopTool( const std::string& actionName );
232 
233  bool ToolStackIsEmpty() { return m_toolStack.empty(); }
234 
235  std::string CurrentToolName() const;
236  bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
237 
238  virtual void DisplayToolMsg( const wxString& msg ) {};
239 
244  bool GetDoImmediateActions() const { return m_immediateActions; }
245 
250  bool GetDragSelects() const { return m_dragSelects; }
251 
256  bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
257 
264  bool ProcessEvent( wxEvent& aEvent ) override;
265 
273  virtual void OnCharHook( wxKeyEvent& event );
274 
279  void OnMenuOpen( wxMenuEvent& event );
280 
281  void SetAutoSaveInterval( int aInterval );
282 
283  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
284 
285  bool IsType( FRAME_T aType ) const { return m_Ident == aType; }
286 
292  virtual const SEARCH_STACK& sys_search();
293 
294  virtual wxString help_name();
295 
296  void OnKicadAbout( wxCommandEvent& event );
297  void OnPreferences( wxCommandEvent& event );
298 
299  void PrintMsg( const wxString& text );
300 
305  virtual wxConfigBase* config();
306 
313 
320  virtual void LoadSettings( wxConfigBase* aCfg );
321 
329  virtual void SaveSettings( wxConfigBase* aCfg );
330 
338  wxString ConfigBaseName()
339  {
340  wxString baseCfgName = m_configName.IsEmpty() ? GetName() : m_configName;
341  return baseCfgName;
342  }
343 
351  virtual void SaveProjectSettings( bool aAskForSave ) {};
352 
353  // Read/Save and Import/export hotkeys config
354 
362  void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
363  const wxString& aDefaultShortname );
364 
377  wxString GetFileFromHistory( int cmdId, const wxString& type,
378  FILE_HISTORY* aFileHistory = NULL );
379 
389  void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = NULL );
390 
391  void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
392 
393  wxString GetMruPath() const { return m_mruPath; }
394 
400  virtual void ReCreateMenuBar();
401 
405  void AddStandardHelpMenu( wxMenuBar* aMenuBar );
406 
421  bool IsWritable( const wxFileName& aFileName );
422 
435  void CheckForAutoSaveFile( const wxFileName& aFileName );
436 
444  virtual void UpdateStatusBar() { }
445 
450  virtual void SyncToolbars() { };
451 
455  virtual void ShowChangedLanguage();
456 
461  virtual void CommonSettingsChanged( bool aEnvVarsChanged );
462 
466  virtual void RefreshCanvas() { };
467 
468  const wxString& GetAboutTitle() const { return m_AboutTitle; }
469 };
470 
471 
493 class EDA_PANE : public wxAuiPaneInfo
494 {
495 public:
497  {
498  Gripper( false );
499  CloseButton( false );
500  PaneBorder( false );
501  }
502 
507  {
508  SetFlag( optionToolbar, true );
509  CaptionVisible( false );
510  TopDockable().BottomDockable();
511  DockFixed( true );
512  Movable( false );
513  Resizable( true ); // expand to fit available space
514  return *this;
515  }
516 
521  {
522  SetFlag( optionToolbar, true );
523  CaptionVisible( false );
524  LeftDockable().RightDockable();
525  DockFixed( true );
526  Movable( false );
527  Resizable( true ); // expand to fit available space
528  return *this;
529  }
530 
535  {
536  CaptionVisible( true );
537  PaneBorder( true );
538  return *this;
539  }
540 
545  {
546  CaptionVisible( false );
547  Layer( 0 );
548  PaneBorder( true );
549  Resizable( true ); // expand to fit available space
550  return *this;
551  }
552 
557  {
558  CaptionVisible( false );
559  BottomDockable( true );
560  DockFixed( true );
561  Movable( false );
562  Resizable( true ); // expand to fit available space
563  return *this;
564  }
565 };
566 
567 #endif // WXSTRUCT_H_
void PrintMsg(const wxString &text)
Class 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.
void SetUserUnits(EDA_UNITS_T aUnits)
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)
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 SaveSettings(wxConfigBase *aCfg)
Saves common frame parameters to a configuration data file.
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.
wxString ConfigBaseName()
wxString m_AboutTitle
virtual wxConfigBase * config()
Returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
Class 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.
class 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:40
void ImportHotkeyConfigFromFile(std::map< std::string, TOOL_ACTION * > aActionMap, const wxString &aDefaultShortname)
Prompt the user for a hotkey file to read, and read it.
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
wxTimer * m_autoSaveTimer
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.
Class TOOL_MANAGER.
Definition: tool_manager.h:50
wxString GetMruPath() const
wxWindow * findQuasiModalDialog()
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...
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)
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
virtual void LoadSettings(wxConfigBase *aCfg)
Load common frame parameters from a configuration file.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:274
int GetAutoSaveInterval() const
void OnKicadAbout(wxCommandEvent &event)
Class PARAM_CFG_BASE is a base class which establishes the interface functions ReadParam and SavePara...
Definition: config_params.h:99
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.
Class TOOL_DISPATCHER.
EDA_PANE & Canvas()
Turn *this into an undecorated pane suitable for a drawing canvas.
virtual void SaveProjectSettings(bool aAskForSave)
Save changes to the project settings to the project (.pro) file.
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:97
void SetAutoSaveInterval(int aInterval)
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=NULL)
Fetches the file name from the file history list.
EDA_UNITS_T m_userUnits
Board layer functions and definitions.
std::vector< std::string > m_toolStack
bool ToolStackIsEmpty()
bool IsType(FRAME_T aType) const
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
EDA_PANE & Palette()
Turn *this into a captioned palette suitable for a symbol tree, layers manager, etc.
const wxString & GetAboutTitle() const
The base frame for deriving all KiCad main window classes.
Class TOOL_ACTION.
Definition: tool_action.h:46
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
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
void ChangeUserUnits(EDA_UNITS_T aUnits)
EDA_PANE & Messages()
Turn *this into a messages pane for KiCad.
virtual void PopTool(const std::string &actionName)
void OnPreferences(wxCommandEvent &event)
Class ACTIONS.
Definition: actions.h:43
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
Class 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.
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_T
Definition: common.h:133
wxString m_configName
virtual void RefreshCanvas()
Notification to refresh the drawing canvas (if any).
virtual void ReCreateMenuBar()
Recreates the menu bar.