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-2018 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 
45 #include <fctsys.h>
46 #include <common.h>
48 #include <frame_type.h>
49 #include "hotkeys_basic.h"
50 
51 #ifdef USE_WX_OVERLAY
52 #include <wx/overlay.h>
53 #endif
54 
55 // Option for main frames
56 #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
57 
58 
59 // Readability helper definitions for creating backup files.
60 #define CREATE_BACKUP_FILE true
61 #define NO_BACKUP_FILE false
62 
72 #define AUTOSAVE_PREFIX_FILENAME wxT( "_saved_" )
73 
74 
75 class EDA_ITEM;
76 class EDA_RECT;
77 class EDA_DRAW_PANEL;
78 class EDA_DRAW_PANEL_GAL;
79 class EDA_MSG_PANEL;
80 class BASE_SCREEN;
81 class PARAM_CFG_BASE;
82 class PAGE_INFO;
83 class PLOTTER;
84 class TITLE_BLOCK;
85 class MSG_PANEL_ITEM;
86 class TOOL_MANAGER;
87 class TOOL_DISPATCHER;
88 class ACTIONS;
89 class PAGED_DIALOG;
91 
92 
98 };
99 
100 
112 class EDA_BASE_FRAME : public wxFrame
113 {
125  void windowClosing( wxCloseEvent& event );
126 
127  wxWindow* findQuasiModalDialog();
128 
129 protected:
132  wxSize m_FrameSize;
133 
134  wxString m_configFrameName;
135 
137  wxAuiToolBar* m_mainToolBar;
138 
139  wxString m_AboutTitle;
140 
141  wxAuiManager m_auimgr;
142 
145 
148 
151 
153  wxTimer* m_autoSaveTimer;
154 
155  wxString m_perspective;
156 
157  wxString m_mruPath;
158 
160  static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
161 
166  void onAutoSaveTimer( wxTimerEvent& aEvent );
167 
173  virtual bool isAutoSaveRequired() const { return false; }
174 
181  virtual bool doAutoSave();
182 
188  virtual wxConfigBase* config();
189 
195  virtual const SEARCH_STACK& sys_search();
196 
197  virtual wxString help_name();
198 
199 public:
200  EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
201  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
202  long aStyle, const wxString& aFrameName );
203 
204  ~EDA_BASE_FRAME();
205 
213  bool ProcessEvent( wxEvent& aEvent ) override;
214 
215  void SetAutoSaveInterval( int aInterval );
216 
217  int GetAutoSaveInterval() const { return m_autoSaveInterval; }
218 
219  bool IsType( FRAME_T aType ) const { return m_Ident == aType; }
220 
221  void GetKicadHelp( wxCommandEvent& event );
222 
223  void GetKicadContribute( wxCommandEvent& event );
224 
225  void GetKicadAbout( wxCommandEvent& event );
226 
227  bool ShowPreferences( EDA_HOTKEY_CONFIG* aHotkeys, EDA_HOTKEY_CONFIG* aShowHotkeys,
228  const wxString& aHotkeysNickname );
229 
230  void PrintMsg( const wxString& text );
231 
238  virtual void InstallPreferences( PAGED_DIALOG* aParent ) { }
239 
247  virtual void LoadSettings( wxConfigBase* aCfg );
248 
257  virtual void SaveSettings( wxConfigBase* aCfg );
258 
269  wxString ConfigBaseName()
270  {
271  wxString baseCfgName = m_configFrameName.IsEmpty() ? GetName() : m_configFrameName;
272  return baseCfgName;
273  }
274 
275 
283  virtual void SaveProjectSettings( bool aAskForSave ) {};
284 
285  // Read/Save and Import/export hotkeys config
286 
298  virtual int WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, wxString* aFullFileName = NULL );
299 
308  const wxString& aDefaultShortname );
309 
318  const wxString& aDefaultShortname );
319 
332  wxString GetFileFromHistory( int cmdId, const wxString& type,
333  wxFileHistory* aFileHistory = NULL );
334 
344  void UpdateFileHistory( const wxString& FullFileName, wxFileHistory * aFileHistory = NULL );
345 
346  void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }
347 
348  wxString GetMruPath() const { return m_mruPath; }
349 
355  virtual void ReCreateMenuBar();
356 
374  bool IsWritable( const wxFileName& aFileName );
375 
392  void CheckForAutoSaveFile( const wxFileName& aFileName, const wxString& aBackupFileExtension );
393 
398  virtual void ShowChangedLanguage();
399 
405  virtual void CommonSettingsChanged();
406 
413  bool PostCommandMenuEvent( int evt_type );
414 };
415 
416 
438 class EDA_PANE : public wxAuiPaneInfo
439 {
440 public:
442  {
443  Gripper( false );
444  CloseButton( false );
445  PaneBorder( false );
446  }
447 
453  {
454  SetFlag( optionToolbar, true );
455  CaptionVisible( false );
456  TopDockable().BottomDockable();
457  DockFixed( true );
458  Movable( false );
459  Resizable( true ); // expand to fit available space
460  return *this;
461  }
462 
468  {
469  SetFlag( optionToolbar, true );
470  CaptionVisible( false );
471  LeftDockable().RightDockable();
472  DockFixed( true );
473  Movable( false );
474  Resizable( true ); // expand to fit available space
475  return *this;
476  }
477 
483  {
484  CaptionVisible( true );
485  PaneBorder( true );
486  return *this;
487  }
488 
494  {
495  CaptionVisible( false );
496  Layer( 0 );
497  PaneBorder( true );
498  Resizable( true ); // expand to fit available space
499  return *this;
500  }
501 
507  {
508  CaptionVisible( false );
509  BottomDockable( true );
510  DockFixed( true );
511  Movable( false );
512  Resizable( true ); // expand to fit available space
513  return *this;
514  }
515 };
516 
517 #endif // WXSTRUCT_H_
void CheckForAutoSaveFile(const wxFileName &aFileName, const wxString &aBackupFileExtension)
Function CheckForAutoSaveFile checks if an auto save file exists for aFileName and takes the appropri...
bool m_autoSaveState
Flag to indicate the last auto save state.
void PrintMsg(const wxString &text)
id_librarytype
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
wxString m_mruPath
Most recently used path.
virtual bool doAutoSave()
Function doAutoSave 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)
Function windowClosing (with its unexpected name so it does not collide with the real OnWindowClose()...
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file. ...
void ExportHotkeyConfigToFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it...
void onAutoSaveTimer(wxTimerEvent &aEvent)
Function onAutoSaveTimer handles the auto save timer event.
wxString ConfigBaseName()
Function ConfigBaseName.
wxString m_AboutTitle
Name of program displayed in About.
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
wxAuiManager m_auimgr
bool IsWritable(const wxFileName &aFileName)
Function IsWritable checks if aFileName can be written.
class EDA_MSG_PANEL is a panel to display various information messages.
Definition: msgpanel.h:111
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
void UpdateFileHistory(const wxString &FullFileName, wxFileHistory *aFileHistory=NULL)
Function UpdateFileHistory Updates the list of recently opened files.
wxString m_perspective
wxAuiManager perspective.
void GetKicadHelp(wxCommandEvent &event)
Class TOOL_MANAGER.
Definition: tool_manager.h:49
wxWindow * findQuasiModalDialog()
virtual const SEARCH_STACK & sys_search()
Function sys_search returns a SEARCH_STACK pertaining to entire program, and is overloaded in KICAD_M...
EDA_PANE & VToolbar()
Function VToolbar Turn *this into a vertical toolbar for KiCad.
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:76
FRAME_T m_Ident
Id Type (pcb, schematic, library..)
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
void GetKicadAbout(wxCommandEvent &event)
wxString m_configFrameName
prefix used in config to identify some params (frame size...) if empty, the frame name defined in CTO...
bool PostCommandMenuEvent(int evt_type)
Function PostCommandMenuEvent.
Class PARAM_CFG_BASE is a base class which establishes the interface functions ReadParam and SavePara...
Definition: config_params.h:99
Specialization of the wxAuiPaneInfo class for KiCad panels.
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Class TOOL_DISPATCHER.
EDA_PANE & Canvas()
Function Canvas Turn *this into an undecorated pane suitable for a drawing canvas.
virtual void SaveProjectSettings(bool aAskForSave)
Function SaveProjectSettings saves changes to the project settings to the project (...
Base plotter engine class.
Definition: plotter.h:97
void SetAutoSaveInterval(int aInterval)
Board layer functions and definitions.
void GetKicadContribute(wxCommandEvent &event)
EDA_PANE & Palette()
Function Palette Turn *this into a captioned palette suitable for a symbol tree, layers manager...
virtual int WriteHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList, wxString *aFullFileName=NULL)
Function WriteHotkeyConfig Store the current hotkey list It is stored using the standard wxConfig mec...
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
wxString GetFileFromHistory(int cmdId, const wxString &type, wxFileHistory *aFileHistory=NULL)
Function GetFileFromHistory fetches the file name from the file history list.
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:154
The common library.
virtual wxString help_name()
virtual void InstallPreferences(PAGED_DIALOG *aParent)
Function InstallPreferences allows a Frame to load its preference panels (if any) into the preference...
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
EDA_PANE & Messages()
Function Messages Turn *this into a messages pane for KiCad.
Class ACTIONS.
Definition: actions.h:41
virtual void CommonSettingsChanged()
Function CommonSettingsChanged Notification event that some of the common (suite-wide) settings have ...
virtual bool isAutoSaveRequired() const
Function autoSaveRequired returns the auto save status of the application.
Some functions to handle hotkeys in KiCad.
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
bool IsType(FRAME_T aType) const
bool ShowPreferences(EDA_HOTKEY_CONFIG *aHotkeys, EDA_HOTKEY_CONFIG *aShowHotkeys, const wxString &aHotkeysNickname)
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
EDA_PANE & HToolbar()
Function HToolbar Turn *this to a horizontal toolbar for KiCad.
void ImportHotkeyConfigFromFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it.
wxString GetMruPath() const
int m_autoSaveInterval
The auto save interval time in seconds.
virtual void ShowChangedLanguage()
Function ShowChangedLanguage redraws the menus and what not in current language.
bool ProcessEvent(wxEvent &aEvent) override
Function ProcessEvent overrides the default process event handler to implement the auto save feature...
int GetAutoSaveInterval() const
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
EDA_BASE_FRAME(wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)