KiCad PCB EDA Suite
EDA_BASE_FRAME Class Reference

Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes. More...

#include <eda_base_frame.h>

Inheritance diagram for EDA_BASE_FRAME:
KICAD_MANAGER_FRAME KIWAY_PLAYER CVPCB_MAINFRAME EDA_3D_VIEWER EDA_DRAW_FRAME SIM_PLOT_FRAME_BASE GERBVIEW_FRAME PCB_BASE_FRAME PL_EDITOR_FRAME SCH_BASE_FRAME SIM_PLOT_FRAME DISPLAY_FOOTPRINTS_FRAME FOOTPRINT_VIEWER_FRAME FOOTPRINT_WIZARD_FRAME PCB_BASE_EDIT_FRAME LIB_EDIT_FRAME LIB_VIEW_FRAME SCH_EDIT_FRAME FOOTPRINT_EDIT_FRAME PCB_EDIT_FRAME

Public Member Functions

 EDA_BASE_FRAME (wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
 
 ~EDA_BASE_FRAME ()
 
bool ProcessEvent (wxEvent &aEvent) override
 Function ProcessEvent overrides the default process event handler to implement the auto save feature. More...
 
void SetAutoSaveInterval (int aInterval)
 
int GetAutoSaveInterval () const
 
bool IsType (FRAME_T aType) const
 
void GetKicadHelp (wxCommandEvent &event)
 
void GetKicadContribute (wxCommandEvent &event)
 
void GetKicadAbout (wxCommandEvent &event)
 
void PrintMsg (const wxString &text)
 
virtual void LoadSettings (wxConfigBase *aCfg)
 Function LoadSettings loads common frame parameters from a configuration file. More...
 
virtual void SaveSettings (wxConfigBase *aCfg)
 Function SaveSettings saves common frame parameters to a configuration data file. More...
 
wxString ConfigBaseName ()
 Function ConfigBaseName. More...
 
virtual void SaveProjectSettings (bool aAskForSave)
 Function SaveProjectSettings saves changes to the project settings to the project (.pro) file. More...
 
virtual void OnSelectPreferredEditor (wxCommandEvent &event)
 Function OnSelectPreferredEditor Open a dialog to select the editor that will used in KiCad to edit or display files (reports ... More...
 
int ReadHotkeyConfig (struct EDA_HOTKEY_CONFIG *aDescList)
 Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys. More...
 
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 mechanism or a file. More...
 
int ReadHotkeyConfigFile (const wxString &aFilename, struct EDA_HOTKEY_CONFIG *aDescList)
 Function ReadHotkeyConfigFile Read an old configuration file (&ltfile&gt.key) and fill the current hotkey list with hotkeys. More...
 
void ImportHotkeyConfigFromFile (EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
 Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it. More...
 
void ExportHotkeyConfigToFile (EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
 Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it. More...
 
wxString GetFileFromHistory (int cmdId, const wxString &type, wxFileHistory *aFileHistory=NULL)
 Function GetFileFromHistory fetches the file name from the file history list. More...
 
void UpdateFileHistory (const wxString &FullFileName, wxFileHistory *aFileHistory=NULL)
 Function UpdateFileHistory Updates the list of recently opened files. More...
 
void SetMruPath (const wxString &aPath)
 
wxString GetMruPath () const
 
virtual void ReCreateMenuBar ()
 Function ReCreateMenuBar Creates recreates the menu bar. More...
 
bool IsWritable (const wxFileName &aFileName)
 Function IsWritable checks if aFileName can be written. More...
 
void CheckForAutoSaveFile (const wxFileName &aFileName, const wxString &aBackupFileExtension)
 Function CheckForAutoSaveFile checks if an auto save file exists for aFileName and takes the appropriate action depending on the user input. More...
 
virtual void ShowChangedLanguage ()
 Function ShowChangedLanguage redraws the menus and what not in current language. More...
 
virtual void OnChangeIconsOptions (wxCommandEvent &event)
 Function OnChangeIconsOptions Selects the current icons options in menus (or toolbars) in Kicad (the default for toolbars/menus is 26x26 pixels, and shows icons in menus). More...
 
virtual void ShowChangedIcons ()
 Function ShowChangedIcons redraws items menus after a icon was changed option. More...
 
void AddMenuIconsOptions (wxMenu *MasterMenu)
 Function AddMenuIconsOptions creates a menu list for icons in menu and icon sizes choice, and add it as submenu to MasterMenu. More...
 
bool PostCommandMenuEvent (int evt_type)
 Function PostCommandMenuEvent. More...
 
virtual int GetIconScale ()
 Function GetIconScale. More...
 
virtual void SetIconScale (int aScale)
 Function SetIconScale. More...
 

Protected Member Functions

void onAutoSaveTimer (wxTimerEvent &aEvent)
 Function onAutoSaveTimer handles the auto save timer event. More...
 
virtual bool isAutoSaveRequired () const
 Function autoSaveRequired returns the auto save status of the application. More...
 
virtual bool doAutoSave ()
 Function doAutoSave should be overridden by the derived class to handle the auto save feature. More...
 
virtual wxConfigBase * config ()
 Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME. More...
 
virtual const SEARCH_STACKsys_search ()
 Function sys_search returns a SEARCH_STACK pertaining to entire program, and is overloaded in KICAD_MANAGER_FRAME. More...
 
virtual wxString help_name ()
 

Protected Attributes

FRAME_T m_Ident
 Id Type (pcb, schematic, library..) More...
 
wxPoint m_FramePos
 
wxSize m_FrameSize
 
wxString m_configFrameName
 prefix used in config to identify some params (frame size...) if empty, the frame name defined in CTOR is used More...
 
wxAuiToolBar * m_mainToolBar
 Standard horizontal Toolbar. More...
 
wxString m_AboutTitle
 Name of program displayed in About. More...
 
wxAuiManager m_auimgr
 
bool m_hasAutoSave
 Flag to indicate if this frame supports auto save. More...
 
bool m_autoSaveState
 Flag to indicate the last auto save state. More...
 
int m_autoSaveInterval
 The auto save interval time in seconds. More...
 
wxTimer * m_autoSaveTimer
 The timer used to implement the auto save feature;. More...
 
wxString m_perspective
 wxAuiManager perspective. More...
 
wxString m_mruPath
 Most recently used path. More...
 

Static Protected Attributes

static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND
 

Default style flags used for wxAUI toolbars

More...
 

Private Member Functions

void windowClosing (wxCloseEvent &event)
 Function windowClosing (with its unexpected name so it does not collide with the real OnWindowClose() function provided in derived classes) is called just before a window closing, and is used to call a derivation specific SaveSettings(). More...
 
void removePaneBorder (wxShowEvent &event)
 Removes border from wxAui panes. More...
 

Detailed Description

Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.

This class is not intended to be used directly. It provides support for automatic calls to a SaveSettings() function. SaveSettings() for a derived class can choose to do nothing, or rely on basic SaveSettings() support in this base class to do most of the work by calling it from the derived class's SaveSettings().

This class is not a KIWAY_PLAYER because KICAD_MANAGER_FRAME is derived from it and that class is not a player.

Definition at line 117 of file eda_base_frame.h.

Constructor & Destructor Documentation

EDA_BASE_FRAME::EDA_BASE_FRAME ( wxWindow *  aParent,
FRAME_T  aFrameType,
const wxString &  aTitle,
const wxPoint aPos,
const wxSize &  aSize,
long  aStyle,
const wxString &  aFrameName 
)

Definition at line 74 of file eda_base_frame.cpp.

References ID_AUTO_SAVE_TIMER, m_autoSaveInterval, m_autoSaveState, m_autoSaveTimer, m_FramePos, m_FrameSize, m_hasAutoSave, m_Ident, m_mainToolBar, m_mruPath, onAutoSaveTimer(), removePaneBorder(), windowClosing(), wxPoint::x, and wxPoint::y.

Referenced by isAutoSaveRequired().

76  :
77  wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName )
78 {
79  wxSize minsize;
80 
81  m_Ident = aFrameType;
82  m_mainToolBar = NULL;
83  m_hasAutoSave = false;
84  m_autoSaveState = false;
85  m_autoSaveInterval = -1;
86  m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
87  m_mruPath = wxStandardPaths::Get().GetDocumentsDir();
88  minsize.x = 470;
89  minsize.y = 350;
90 
91  SetSizeHints( minsize.x, minsize.y, -1, -1, -1, -1 );
92 
93  if( ( aSize.x < minsize.x ) || ( aSize.y < minsize.y ) )
94  SetSize( 0, 0, minsize.x, minsize.y );
95 
96  // Create child subwindows.
97 
98  // Dimensions of the user area of the main window.
99  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
100 
101  m_FramePos.x = m_FramePos.y = 0;
102 
103  Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
104  wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
105 
106  // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
107  // to be called before any other hook for wxCloseEvent, which is necessary.
108  Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
109 
110  // remove border from wxAui panes for all derived classes
111  Connect( wxEVT_SHOW, wxShowEventHandler( EDA_BASE_FRAME::removePaneBorder ) );
112 }
bool m_autoSaveState
Flag to indicate the last auto save state.
wxString m_mruPath
Most recently used path.
void windowClosing(wxCloseEvent &event)
Function windowClosing (with its unexpected name so it does not collide with the real OnWindowClose()...
void onAutoSaveTimer(wxTimerEvent &aEvent)
Function onAutoSaveTimer handles the auto save timer event.
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
void removePaneBorder(wxShowEvent &event)
Removes border from wxAui panes.
FRAME_T m_Ident
Id Type (pcb, schematic, library..)
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
int m_autoSaveInterval
The auto save interval time in seconds.
EDA_BASE_FRAME::~EDA_BASE_FRAME ( )

Definition at line 166 of file eda_base_frame.cpp.

References m_autoSaveTimer.

Referenced by isAutoSaveRequired().

167 {
168  delete m_autoSaveTimer;
169 
170  // This is needed for OSX: avoids further OnDraw processing after this
171  // destructor and before the native window is destroyed
172  this->Freeze();
173 }
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.

Member Function Documentation

void EDA_BASE_FRAME::AddMenuIconsOptions ( wxMenu *  MasterMenu)

Function AddMenuIconsOptions creates a menu list for icons in menu and icon sizes choice, and add it as submenu to MasterMenu.

Parameters
MasterMenuThe main menu. The sub menu list will be accessible from the menu item with id ID_KICAD_SELECT_ICONS_OPTIONS

Definition at line 677 of file eda_base_frame.cpp.

References AddMenuItem(), ID_KICAD_SELECT_ICONS_IN_MENUS, ID_KICAD_SELECT_ICONS_OPTIONS, KiBitmap(), and Pgm().

Referenced by GetMruPath(), preparePreferencesMenu(), PL_EDITOR_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), and GERBVIEW_FRAME::ReCreateMenuBar().

678 {
679  wxMenu* menu = NULL;
680  wxMenuItem* item = MasterMenu->FindItem( ID_KICAD_SELECT_ICONS_OPTIONS );
681 
682  if( item ) // This menu exists, do nothing
683  return;
684 
685  menu = new wxMenu;
686 
687  menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICONS_IN_MENUS,
688  _( "Icons in Menus" ), wxEmptyString,
689  wxITEM_CHECK ) );
690  menu->Check( ID_KICAD_SELECT_ICONS_IN_MENUS, Pgm().GetUseIconsInMenus() );
691 
692  AddMenuItem( MasterMenu, menu,
694  _( "Icons Options" ),
695  _( "Select show icons in menus and icons sizes" ),
696  KiBitmap( icon_xpm ) );
697 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:174
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
void EDA_BASE_FRAME::CheckForAutoSaveFile ( const wxFileName &  aFileName,
const wxString &  aBackupFileExtension 
)

Function CheckForAutoSaveFile checks if an auto save file exists for aFileName and takes the appropriate action depending on the user input.

If an auto save file exists for aFileName, the user is prompted if they wish to replace file aFileName with the auto saved file. If the user chooses to replace the file, the backup file of aFileName is removed, aFileName is renamed to the backup file name, and the auto save file is renamed to aFileName. If user chooses to keep the existing version of aFileName, the auto save file is removed.

Parameters
aFileNameA wxFileName object containing the file name to check.
aBackupFileExtensionA wxString object containing the backup file extension used to create the backup file name.

Definition at line 582 of file eda_base_frame.cpp.

References AUTOSAVE_PREFIX_FILENAME, Format(), GetChars(), Pgm(), and traceAutoSave.

Referenced by GetMruPath(), and PCB_EDIT_FRAME::OpenProjectFiles().

584 {
585  wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
586  wxCHECK_RET( !aBackupFileExtension.IsEmpty(), wxT( "Invalid backup file extension!" ) );
587 
588  wxFileName autoSaveFileName = aFileName;
589 
590  // Check for auto save file.
591  autoSaveFileName.SetName( AUTOSAVE_PREFIX_FILENAME + aFileName.GetName() );
592 
593  wxLogTrace( traceAutoSave,
594  wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
595 
596  if( !autoSaveFileName.FileExists() )
597  return;
598 
599  wxString msg = wxString::Format( _(
600  "Well this is potentially embarrassing!\n"
601  "It appears that the last time you were editing the file\n"
602  "\"%s\"\n"
603  "it was not saved properly. Do you wish to restore the last saved edits you made?" ),
604  GetChars( aFileName.GetFullName() )
605  );
606 
607  int response = wxMessageBox( msg, Pgm().App().GetAppName(), wxYES_NO | wxICON_QUESTION, this );
608 
609  // Make a backup of the current file, delete the file, and rename the auto save file to
610  // the file name.
611  if( response == wxYES )
612  {
613  // Get the backup file name.
614  wxFileName backupFileName = aFileName;
615  backupFileName.SetExt( aBackupFileExtension );
616 
617  // If an old backup file exists, delete it. If an old copy of the file exists, rename
618  // it to the backup file name
619  if( aFileName.FileExists() )
620  {
621  // Remove the old file backup file.
622  if( backupFileName.FileExists() )
623  wxRemoveFile( backupFileName.GetFullPath() );
624 
625  // Rename the old file to the backup file name.
626  if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath() ) )
627  {
628  msg.Printf( _( "Could not create backup file \"%s\"" ),
629  GetChars( backupFileName.GetFullPath() ) );
630  wxMessageBox( msg );
631  }
632  }
633 
634  if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
635  {
636  wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
637  Pgm().App().GetAppName(), wxOK | wxICON_EXCLAMATION, this );
638  }
639  }
640  else
641  {
642  wxLogTrace( traceAutoSave,
643  wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
644 
645  // Remove the auto save file when using the previous file as is.
646  wxRemoveFile( autoSaveFileName.GetFullPath() );
647  }
648 }
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
#define AUTOSAVE_PREFIX_FILENAME
Prefix to create filenames for schematic files or other difile when auto-saved to retrieve a crash...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
const wxChar traceAutoSave[]
Flag to enable auto save feature debug tracing.
wxConfigBase * EDA_BASE_FRAME::config ( )
protectedvirtual
wxString EDA_BASE_FRAME::ConfigBaseName ( )
inline

Function ConfigBaseName.

Returns
a base name prefix used in Load/Save settings to build the full name of keys used in config. This is usually the name of the frame set by CTOR, unless m_configFrameName contains a base name. this is the case of frames which can be shown in normal or modal mode. This is needed because we want only one base name prefix, regardless the mode used.

Definition at line 266 of file eda_base_frame.h.

References m_configFrameName.

Referenced by LoadSettings(), EDA_DRAW_FRAME::LoadSettings(), SaveSettings(), and EDA_DRAW_FRAME::SaveSettings().

267  {
268  wxString baseCfgName = m_configFrameName.IsEmpty() ? GetName() : m_configFrameName;
269  return baseCfgName;
270  }
wxString m_configFrameName
prefix used in config to identify some params (frame size...) if empty, the frame name defined in CTO...
bool EDA_BASE_FRAME::doAutoSave ( )
protectedvirtual

Function doAutoSave should be overridden by the derived class to handle the auto save feature.

Returns
true if the auto save was successful otherwise false.

Reimplemented in PCB_EDIT_FRAME, and SCH_EDIT_FRAME.

Definition at line 235 of file eda_base_frame.cpp.

Referenced by isAutoSaveRequired(), and onAutoSaveTimer().

236 {
237  wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
238 }
void EDA_BASE_FRAME::ExportHotkeyConfigToFile ( EDA_HOTKEY_CONFIG aDescList,
const wxString &  aDefaultShortname 
)

Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it.

Parameters
aDescList= current hotkey list descr. to initialize.
aDefaultShortname= a default short name (extention not needed) like eechema, kicad...

Definition at line 757 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, EDA_FILE_SELECTOR(), and Prj().

Referenced by KICAD_MANAGER_FRAME::Process_Config(), LIB_EDIT_FRAME::Process_Config(), SCH_EDIT_FRAME::Process_Config(), PL_EDITOR_FRAME::Process_Config(), PCB_EDIT_FRAME::Process_Config(), GERBVIEW_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), and SaveProjectSettings().

759 {
760  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
761  wxString mask = wxT( "*." ) + ext;
762 
763 #if 0
764  wxString path = wxPathOnly( Prj().GetProjectFullName() );
765 #else
766  wxString path = GetMruPath();
767 #endif
768  wxFileName fn( aDefaultShortname );
769  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
770 
771  wxString filename = EDA_FILE_SELECTOR( _( "Write Hotkey Configuration File:" ),
772  path,
773  fn.GetFullPath(),
774  ext,
775  mask,
776  this,
777  wxFD_SAVE,
778  true );
779 
780  if( filename.IsEmpty() )
781  return;
782 
783  WriteHotkeyConfig( aDescList, &filename );
784  SetMruPath( wxFileName( filename ).GetPath() );
785 }
void SetMruPath(const wxString &aPath)
PROJECT & Prj()
Definition: kicad.cpp:270
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
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...
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34
wxString GetMruPath() const
int EDA_BASE_FRAME::GetAutoSaveInterval ( ) const
inline

Definition at line 225 of file eda_base_frame.h.

References m_autoSaveInterval.

Referenced by DIALOG_GENERALOPTIONS::init(), and SCH_EDIT_FRAME::OnPreferencesOptions().

225 { return m_autoSaveInterval; }
int m_autoSaveInterval
The auto save interval time in seconds.
wxString EDA_BASE_FRAME::GetFileFromHistory ( int  cmdId,
const wxString &  type,
wxFileHistory *  aFileHistory = NULL 
)

Function GetFileFromHistory fetches the file name from the file history list.

and removes the selected file, if this file does not exists Note also the menu is updated, if wxFileHistory::UseMenu was called at init time

Parameters
cmdIdThe command ID associated with the aFileHistory object.
typePlease document me!
aFileHistoryThe wxFileHistory in use. If null, the main application file history is used
Returns
a wxString containing the selected filename

Definition at line 404 of file eda_base_frame.cpp.

References Format(), GetChars(), KIFACE_I::GetFileHistory(), and Kiface().

Referenced by GERBVIEW_FRAME::OnDrlFileHistory(), KICAD_MANAGER_FRAME::OnFileHistory(), PL_EDITOR_FRAME::OnFileHistory(), PCB_EDIT_FRAME::OnFileHistory(), GERBVIEW_FRAME::OnGbrFileHistory(), GERBVIEW_FRAME::OnJobFileHistory(), GERBVIEW_FRAME::OnZipFileHistory(), and SaveProjectSettings().

406 {
407  wxFileHistory* fileHistory = aFileHistory;
408 
409  if( !fileHistory )
410  fileHistory = &Kiface().GetFileHistory();
411 
412  int baseId = fileHistory->GetBaseId();
413 
414  wxASSERT( cmdId >= baseId && cmdId < baseId + (int) fileHistory->GetCount() );
415 
416  unsigned i = cmdId - baseId;
417 
418  if( i < fileHistory->GetCount() )
419  {
420  wxString fn = fileHistory->GetHistoryFile( i );
421 
422  if( wxFileName::FileExists( fn ) )
423  return fn;
424  else
425  {
426  wxString msg = wxString::Format(
427  _( "File \"%s\" was not found." ),
428  GetChars( fn ) );
429 
430  wxMessageBox( msg );
431 
432  fileHistory->RemoveFileFromHistory( i );
433  }
434  }
435 
436  return wxEmptyString;
437 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:123
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual int EDA_BASE_FRAME::GetIconScale ( )
inlinevirtual

Function GetIconScale.

Return the desired scaling for toolbar/menubar icons in fourths (e.g. 4 is unity). A negative number indicates autoscale based on font size.

Reimplemented in PCB_EDIT_FRAME, SCH_EDIT_FRAME, GERBVIEW_FRAME, LIB_EDIT_FRAME, and FOOTPRINT_EDIT_FRAME.

Definition at line 459 of file eda_base_frame.h.

Referenced by get_scale_factor(), and FOOTPRINT_EDIT_FRAME::GetIconScale().

459 { return -1; }
void EDA_BASE_FRAME::GetKicadAbout ( wxCommandEvent &  event)

Definition at line 531 of file eda_base_frame.cpp.

References ShowAboutDialog().

Referenced by add_search_paths(), and IsType().

532 {
533  void ShowAboutDialog(EDA_BASE_FRAME * aParent); // See AboutDialog_main.cpp
534  ShowAboutDialog( this );
535 }
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
void EDA_BASE_FRAME::GetKicadContribute ( wxCommandEvent &  event)

Definition at line 518 of file eda_base_frame.cpp.

References URL_GET_INVOLVED.

Referenced by add_search_paths(), and IsType().

519 {
520  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
521  {
522  wxString msg;
523  msg.Printf( _( "Could not launch the default browser.\n"
524  "For information on how to help the KiCad project, visit %s" ),
526  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, this );
527  }
528 }
#define URL_GET_INVOLVED
void EDA_BASE_FRAME::GetKicadHelp ( wxCommandEvent &  event)

Definition at line 440 of file eda_base_frame.cpp.

References DIM, Format(), GetAssociatedDocument(), GetChars(), help_name(), SearchHelpFileFullPath(), and sys_search().

Referenced by add_search_paths(), and IsType().

441 {
442  const SEARCH_STACK& search = sys_search();
443 
444  /* We have to get document for beginners,
445  * or the full specific doc
446  * if event id is wxID_INDEX, we want the document for beginners.
447  * else the specific doc file (its name is in Kiface().GetHelpFileName())
448  * The document for beginners is the same for all KiCad utilities
449  */
450  if( event.GetId() == wxID_INDEX )
451  {
452  // List of possible names for Getting Started in KiCad
453  const wxChar* names[2] = {
454  wxT( "getting_started_in_kicad" ),
455  wxT( "Getting_Started_in_KiCad" )
456  };
457 
458  wxString helpFile;
459  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
460  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
461  for( unsigned ii = 0; ii < DIM( names ); ii++ )
462  {
463  helpFile = SearchHelpFileFullPath( search, names[ii] );
464 
465  if( !helpFile.IsEmpty() )
466  break;
467  }
468 
469  if( !helpFile )
470  {
471  wxString msg = wxString::Format( _(
472  "Html or pdf help file \n\"%s\"\n or\n\"%s\" could not be found." ), names[0], names[1] );
473  wxMessageBox( msg );
474  }
475  else
476  {
477  GetAssociatedDocument( this, helpFile );
478  }
479 
480  return;
481  }
482 
483  wxString base_name = help_name();
484  wxString helpFile = SearchHelpFileFullPath( search, base_name );
485 
486  if( !helpFile )
487  {
488  wxString msg = wxString::Format( _(
489  "Help file \"%s\" could not be found." ),
490  GetChars( base_name )
491  );
492  wxMessageBox( msg );
493  }
494  else
495  {
496  GetAssociatedDocument( this, helpFile );
497  }
498 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:86
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
virtual const SEARCH_STACK & sys_search()
Function sys_search returns a SEARCH_STACK pertaining to entire program, and is overloaded in KICAD_M...
wxString SearchHelpFileFullPath(const SEARCH_STACK &aSStack, const wxString &aBaseName)
Function SearchHelpFileFullPath returns the help file&#39;s full path.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual wxString help_name()
wxString EDA_BASE_FRAME::help_name ( )
protectedvirtual

Reimplemented in KICAD_MANAGER_FRAME.

Definition at line 380 of file eda_base_frame.cpp.

References KIFACE_I::GetHelpFileName(), and Kiface().

Referenced by GetKicadHelp(), and isAutoSaveRequired().

381 {
382  return Kiface().GetHelpFileName();
383 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
const wxString & GetHelpFileName() const
Function GetHelpFileName returns just the basename portion of the current help file.
Definition: kiface_i.h:121
void EDA_BASE_FRAME::ImportHotkeyConfigFromFile ( EDA_HOTKEY_CONFIG aDescList,
const wxString &  aDefaultShortname 
)

Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it.

Parameters
aDescList= current hotkey list descr. to initialize.
aDefaultShortname= a default short name (extention not needed) like eechema, kicad...

Definition at line 728 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, and EDA_FILE_SELECTOR().

Referenced by KICAD_MANAGER_FRAME::Process_Config(), LIB_EDIT_FRAME::Process_Config(), SCH_EDIT_FRAME::Process_Config(), PL_EDITOR_FRAME::Process_Config(), PCB_EDIT_FRAME::Process_Config(), GERBVIEW_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), and SaveProjectSettings().

730 {
731  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
732  wxString mask = wxT( "*." ) + ext;
733 
734 
735  wxString path = GetMruPath();
736  wxFileName fn( aDefaultShortname );
737  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
738 
739  wxString filename = EDA_FILE_SELECTOR( _( "Read Hotkey Configuration File:" ),
740  path,
741  fn.GetFullPath(),
742  ext,
743  mask,
744  this,
745  wxFD_OPEN,
746  true );
747 
748  if( filename.IsEmpty() )
749  return;
750 
751  ReadHotkeyConfigFile( filename, aDescList );
752  WriteHotkeyConfig( aDescList );
753  SetMruPath( wxFileName( filename ).GetPath() );
754 }
void SetMruPath(const wxString &aPath)
int ReadHotkeyConfigFile(const wxString &aFilename, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfigFile Read an old configuration file (&ltfile&gt.key) and fill the current ho...
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
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...
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34
wxString GetMruPath() const
virtual bool EDA_BASE_FRAME::isAutoSaveRequired ( ) const
inlineprotectedvirtual

Function autoSaveRequired returns the auto save status of the application.

Override this function if your derived frame supports automatic file saving.

Reimplemented in PCB_EDIT_FRAME, and SCH_EDIT_FRAME.

Definition at line 181 of file eda_base_frame.h.

References config(), doAutoSave(), EDA_BASE_FRAME(), help_name(), ProcessEvent(), SetAutoSaveInterval(), sys_search(), and ~EDA_BASE_FRAME().

Referenced by ProcessEvent().

181 { return false; }
bool EDA_BASE_FRAME::IsWritable ( const wxFileName &  aFileName)

Function IsWritable checks if aFileName can be written.

The function performs a number of tests on aFileName to verify that it can be saved. If aFileName defines a path with no file name, them the path is tested for user write permission. If aFileName defines a file name that does not exist in the path, the path is tested for user write permission. If aFileName defines a file that already exits, the file name is tested for user write permissions.

Note
The file name path must be set or an assertion will be raised on debug builds and return false on release builds.
Parameters
aFileNameThe full path and/or file name of the file to test.
Returns
False if aFileName cannot be written.

Definition at line 538 of file eda_base_frame.cpp.

References GetChars().

Referenced by SCH_EDIT_FRAME::doAutoSave(), GetMruPath(), SCH_EDIT_FRAME::SaveEEFile(), LIB_EDIT_FRAME::saveLibrary(), PCB_EDIT_FRAME::SavePcbCopy(), PCB_EDIT_FRAME::SavePcbFile(), CVPCB_MAINFRAME::SaveProjectFile(), and SCH_EDIT_FRAME::SaveProjectSettings().

539 {
540  wxString msg;
541  wxFileName fn = aFileName;
542 
543  // Check for absence of a file path with a file name. Unfortunately KiCad
544  // uses paths relative to the current project path without the ./ part which
545  // confuses wxFileName. Making the file name path absolute may be less than
546  // elegant but it solves the problem.
547  if( fn.GetPath().IsEmpty() && fn.HasName() )
548  fn.MakeAbsolute();
549 
550  wxCHECK_MSG( fn.IsOk(), false,
551  wxT( "File name object is invalid. Bad programmer!" ) );
552  wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
553  wxT( "File name object path <" ) + fn.GetFullPath() +
554  wxT( "> is not set. Bad programmer!" ) );
555 
556  if( fn.IsDir() && !fn.IsDirWritable() )
557  {
558  msg.Printf( _( "You do not have write permissions to folder \"%s\"." ),
559  GetChars( fn.GetPath() ) );
560  }
561  else if( !fn.FileExists() && !fn.IsDirWritable() )
562  {
563  msg.Printf( _( "You do not have write permissions to save file \"%s\" to folder \"%s\"." ),
564  GetChars( fn.GetFullName() ), GetChars( fn.GetPath() ) );
565  }
566  else if( fn.FileExists() && !fn.IsFileWritable() )
567  {
568  msg.Printf( _( "You do not have write permissions to save file \"%s\"." ),
569  GetChars( fn.GetFullPath() ) );
570  }
571 
572  if( !msg.IsEmpty() )
573  {
574  wxMessageBox( msg );
575  return false;
576  }
577 
578  return true;
579 }
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void EDA_BASE_FRAME::LoadSettings ( wxConfigBase *  aCfg)
virtual

Function LoadSettings loads common frame parameters from a configuration file.

Don't forget to call the base method or your frames won't remember their positions and sizes.

Reimplemented in EDA_DRAW_FRAME, PCB_BASE_FRAME, GERBVIEW_FRAME, PCB_EDIT_FRAME, LIB_EDIT_FRAME, SCH_EDIT_FRAME, KICAD_MANAGER_FRAME, CVPCB_MAINFRAME, PL_EDITOR_FRAME, EDA_3D_VIEWER, FOOTPRINT_WIZARD_FRAME, SIM_PLOT_FRAME, FOOTPRINT_VIEWER_FRAME, LIB_VIEW_FRAME, and FOOTPRINT_EDIT_FRAME.

Definition at line 260 of file eda_base_frame.cpp.

References ConfigBaseName(), DEFAULT_AUTO_SAVE_INTERVAL, entryAutoSaveInterval, entryMaximized, entryMruPath, entryPerspective, entryPosX, entryPosY, entrySizeX, entrySizeY, m_autoSaveInterval, m_FramePos, m_FrameSize, m_hasAutoSave, m_mruPath, m_perspective, wxPoint::x, and wxPoint::y.

Referenced by IsType(), SIM_PLOT_FRAME::LoadSettings(), EDA_3D_VIEWER::LoadSettings(), CVPCB_MAINFRAME::LoadSettings(), KICAD_MANAGER_FRAME::LoadSettings(), and EDA_DRAW_FRAME::LoadSettings().

261 {
262  int maximized = 0;
263 
264  wxString baseCfgName = ConfigBaseName();
265 
266  wxString text = baseCfgName + entryPosX;
267  aCfg->Read( text, &m_FramePos.x );
268 
269  text = baseCfgName + entryPosY;
270  aCfg->Read( text, &m_FramePos.y );
271 
272  text = baseCfgName + entrySizeX;
273  aCfg->Read( text, &m_FrameSize.x, wxDefaultSize.x );
274 
275  text = baseCfgName + entrySizeY;
276  aCfg->Read( text, &m_FrameSize.y, wxDefaultSize.x );
277 
278  text = baseCfgName + entryMaximized;
279  aCfg->Read( text, &maximized, 0 );
280 
281  if( m_hasAutoSave )
282  {
283  text = baseCfgName + entryAutoSaveInterval;
284  aCfg->Read( text, &m_autoSaveInterval, DEFAULT_AUTO_SAVE_INTERVAL );
285  }
286 
287  // Ensure the window is on a connected display, and is visible.
288  // (at least a corner of the frame must be visible on screen)
289  // Sometimes, if a window was moved on an auxiliary display, and when this
290  // display is no more available, it is not the case.
291  wxRect rect( m_FramePos, m_FrameSize );
292 
293  if( wxDisplay::GetFromPoint( rect.GetTopLeft() ) == wxNOT_FOUND &&
294  wxDisplay::GetFromPoint( rect.GetTopRight() ) == wxNOT_FOUND &&
295  wxDisplay::GetFromPoint( rect.GetBottomLeft() ) == wxNOT_FOUND &&
296  wxDisplay::GetFromPoint( rect.GetBottomRight() ) == wxNOT_FOUND )
297  {
298  m_FramePos = wxDefaultPosition;
299  }
300 
301  // Ensure Window title bar is visible
302 #if defined( __WXMAC__ )
303  // for macOSX, the window must be below system (macOSX) toolbar
304  // Ypos_min = GetMBarHeight(); seems no more exist in new API (subject to change)
305  int Ypos_min = 20;
306 #else
307  int Ypos_min = 0;
308 #endif
309  if( m_FramePos.y < Ypos_min )
310  m_FramePos.y = Ypos_min;
311 
312  if( maximized )
313  Maximize();
314 
315  aCfg->Read( baseCfgName + entryPerspective, &m_perspective );
316  aCfg->Read( baseCfgName + entryMruPath, &m_mruPath );
317 }
wxString m_mruPath
Most recently used path.
wxString ConfigBaseName()
Function ConfigBaseName.
static const wxString entryPosX
X position of frame, in pixels (suffix)
wxString m_perspective
wxAuiManager perspective.
static const wxString entryPerspective
Configuration file entry for wxAuiManger perspective.
#define DEFAULT_AUTO_SAVE_INTERVAL
The default auto save interval is 10 minutes.
static const wxString entrySizeX
Width of frame, in pixels (suffix)
static const wxString entrySizeY
Height of frame, in pixels (suffix)
static const wxString entryPosY
Y position of frame, in pixels (suffix)
static const wxString entryAutoSaveInterval
Configuration file entry name for auto save interval.
static const wxString entryMaximized
Nonzero iff frame is maximized (suffix)
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
static const wxString entryMruPath
Configuration file entry for most recently used path.
int m_autoSaveInterval
The auto save interval time in seconds.
void EDA_BASE_FRAME::onAutoSaveTimer ( wxTimerEvent &  aEvent)
protected

Function onAutoSaveTimer handles the auto save timer event.

Definition at line 228 of file eda_base_frame.cpp.

References doAutoSave(), m_autoSaveInterval, and m_autoSaveTimer.

Referenced by EDA_BASE_FRAME().

229 {
230  if( !doAutoSave() )
231  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
232 }
virtual bool doAutoSave()
Function doAutoSave should be overridden by the derived class to handle the auto save feature...
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
int m_autoSaveInterval
The auto save interval time in seconds.
void EDA_BASE_FRAME::OnChangeIconsOptions ( wxCommandEvent &  event)
virtual

Function OnChangeIconsOptions Selects the current icons options in menus (or toolbars) in Kicad (the default for toolbars/menus is 26x26 pixels, and shows icons in menus).

Reimplemented in KIWAY_PLAYER, and KICAD_MANAGER_FRAME.

Definition at line 666 of file eda_base_frame.cpp.

References ID_KICAD_SELECT_ICONS_IN_MENUS, Pgm(), ReCreateMenuBar(), and PGM_BASE::SetUseIconsInMenus().

Referenced by GetMruPath(), KICAD_MANAGER_FRAME::OnChangeIconsOptions(), and KIWAY_PLAYER::OnChangeIconsOptions().

667 {
668  if( event.GetId() == ID_KICAD_SELECT_ICONS_IN_MENUS )
669  {
670  Pgm().SetUseIconsInMenus( event.IsChecked() );
671  }
672 
673  ReCreateMenuBar();
674 }
void SetUseIconsInMenus(bool aUseIcons)
True to use menu icons.
Definition: pgm_base.h:327
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
void EDA_BASE_FRAME::OnSelectPreferredEditor ( wxCommandEvent &  event)
virtual

Function OnSelectPreferredEditor Open a dialog to select the editor that will used in KiCad to edit or display files (reports ...

) The full filename editor is saved in configuration (global params)

Definition at line 501 of file eda_base_frame.cpp.

References PGM_BASE::AskUserForPreferredEditor(), PGM_BASE::GetEditorName(), Pgm(), and PGM_BASE::SetEditorName().

Referenced by SaveProjectSettings().

502 {
503  // Ask for the current editor and instruct GetEditorName() to not show
504  // unless we pass false as argument.
505  wxString editorname = Pgm().GetEditorName( false );
506 
507  // Ask the user to select a new editor, but suggest the current one as the default.
508  editorname = Pgm().AskUserForPreferredEditor( editorname );
509 
510  // If we have a new editor name request it to be copied to m_editor_name and saved
511  // to the preferences file. If the user cancelled the dialog then the previous
512  // value will be retained.
513  if( !editorname.IsEmpty() )
514  Pgm().SetEditorName( editorname );
515 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:330
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
VTBL_ENTRY const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:375
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:338
bool EDA_BASE_FRAME::PostCommandMenuEvent ( int  evt_type)

Function PostCommandMenuEvent.

Post a menu event to the frame, which can be used to trigger actions bound to menu items.

Definition at line 651 of file eda_base_frame.cpp.

Referenced by GetMruPath(), FOOTPRINT_EDIT_FRAME::OnHotKey(), FOOTPRINT_EDIT_FRAME::OnHotkeyDeleteItem(), FOOTPRINT_EDIT_FRAME::OnHotkeyDuplicateItem(), PCB_EDIT_FRAME::OnHotkeyDuplicateOrArrayItem(), FOOTPRINT_EDIT_FRAME::OnHotkeyEditItem(), FOOTPRINT_EDIT_FRAME::OnHotkeyMoveItem(), FOOTPRINT_EDIT_FRAME::OnHotkeyMoveItemExact(), and FOOTPRINT_EDIT_FRAME::OnHotkeyRotateItem().

652 {
653  if( evt_type != 0 )
654  {
655  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
656  evt.SetEventObject( this );
657  evt.SetId( evt_type );
658  wxPostEvent( this, evt );
659  return true;
660  }
661 
662  return false;
663 }
void EDA_BASE_FRAME::PrintMsg ( const wxString &  text)

Definition at line 386 of file eda_base_frame.cpp.

Referenced by IsType().

387 {
388  SetStatusText( text );
389 }
bool EDA_BASE_FRAME::ProcessEvent ( wxEvent &  aEvent)
override

Function ProcessEvent overrides the default process event handler to implement the auto save feature.

Warning
If you override this function in a derived class, make sure you call down to this or the auto save feature will be disabled.

Definition at line 176 of file eda_base_frame.cpp.

References findQuasiModalDialog(), isAutoSaveRequired(), m_autoSaveInterval, m_autoSaveState, m_autoSaveTimer, m_hasAutoSave, and traceAutoSave.

Referenced by isAutoSaveRequired(), LIB_VIEW_FRAME::onSelectNextSymbol(), LIB_VIEW_FRAME::onSelectPreviousSymbol(), KIWAY::ProcessEvent(), LIB_VIEW_FRAME::ReCreateListCmp(), and PCBNEW_CONTROL::SwitchUnits().

177 {
178  if( !IsEnabled() && IsActive() )
179  {
180  DIALOG_SHIM* dlg = findQuasiModalDialog( GetChildren() );
181  if( dlg )
182  dlg->Raise();
183  }
184 
185  if( !wxFrame::ProcessEvent( aEvent ) )
186  return false;
187 
188  if( IsShown() && m_hasAutoSave && IsActive() &&
190  {
191  if( !m_autoSaveState )
192  {
193  wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
194  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
195  m_autoSaveState = true;
196  }
197  else if( m_autoSaveTimer->IsRunning() )
198  {
199  wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
200  m_autoSaveTimer->Stop();
201  m_autoSaveState = false;
202  }
203  }
204 
205  return true;
206 }
bool m_autoSaveState
Flag to indicate the last auto save state.
DIALOG_SHIM * findQuasiModalDialog(wxWindowList &aList)
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:70
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
virtual bool isAutoSaveRequired() const
Function autoSaveRequired returns the auto save status of the application.
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
int m_autoSaveInterval
The auto save interval time in seconds.
const wxChar traceAutoSave[]
Flag to enable auto save feature debug tracing.
int EDA_BASE_FRAME::ReadHotkeyConfig ( struct EDA_HOTKEY_CONFIG aDescList)

Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys.

Parameters
aDescList= current hotkey list descr. to initialize.

Definition at line 649 of file hotkeys_basic.cpp.

References ReadHotkeyConfig().

Referenced by SaveProjectSettings().

650 {
651  ::ReadHotkeyConfig( GetName(), aDescList );
652  return 1;
653 }
int ReadHotkeyConfig(struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read configuration data and fill the current hotkey list with hotkeys...
int EDA_BASE_FRAME::ReadHotkeyConfigFile ( const wxString &  aFilename,
struct EDA_HOTKEY_CONFIG aDescList 
)

Function ReadHotkeyConfigFile Read an old configuration file (&ltfile&gt.key) and fill the current hotkey list with hotkeys.

Parameters
aFilename= file name to read.
aDescList= current hotkey list descr. to initialize.

Definition at line 594 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, and ParseHotkeyConfig().

Referenced by SaveProjectSettings().

596 {
597  wxFileName fn( aFilename );
598  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
599 
600  wxFile cfgfile( fn.GetFullPath() );
601 
602  if( !cfgfile.IsOpened() ) // There is a problem to open file
603  return 0;
604 
605  // get length
606  cfgfile.SeekEnd();
607  wxFileOffset size = cfgfile.Tell();
608  cfgfile.Seek( 0 );
609 
610  // read data
611  std::vector<char> buffer( size );
612  cfgfile.Read( buffer.data(), size );
613  wxString data( buffer.data(), wxConvUTF8 );
614 
615  // parse
616  ParseHotkeyConfig( data, aDescList );
617 
618  // cleanup
619  cfgfile.Close();
620  return 1;
621 }
void ParseHotkeyConfig(const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList)
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34
void EDA_BASE_FRAME::ReCreateMenuBar ( void  )
virtual

Function ReCreateMenuBar Creates recreates the menu bar.

Needed when the language is changed

Reimplemented in PCB_EDIT_FRAME, EDA_DRAW_FRAME, SCH_EDIT_FRAME, GERBVIEW_FRAME, LIB_EDIT_FRAME, KICAD_MANAGER_FRAME, PCB_BASE_FRAME, PL_EDITOR_FRAME, FOOTPRINT_EDIT_FRAME, CVPCB_MAINFRAME, FOOTPRINT_VIEWER_FRAME, and LIB_VIEW_FRAME.

Definition at line 241 of file eda_base_frame.cpp.

Referenced by GetMruPath(), InstallHotkeyFrame(), OnChangeIconsOptions(), ShowChangedIcons(), and ShowChangedLanguage().

242 {
243 }
void EDA_BASE_FRAME::removePaneBorder ( wxShowEvent &  event)
private

Removes border from wxAui panes.

Definition at line 150 of file eda_base_frame.cpp.

References m_auimgr.

Referenced by EDA_BASE_FRAME().

151 {
152  // nothing to be set
153  if( !m_auimgr.GetManagedWindow() )
154  return;
155 
156  // remove the ugly 1-pixel white border on AUI panes
157  wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
158 
159  for( size_t i = 0; i < panes.GetCount(); i++ )
160  m_auimgr.GetPane( panes.Item( i ).name ).PaneBorder( false );
161 
162  m_auimgr.Update();
163 }
wxAuiManager m_auimgr
virtual void EDA_BASE_FRAME::SaveProjectSettings ( bool  aAskForSave)
inlinevirtual

Function SaveProjectSettings saves changes to the project settings to the project (.pro) file.

The method is virtual so you can override it to call the suitable save method. The base method do nothing

Parameters
aAskForSave= true to open a dialog before saving the settings

Reimplemented in PCB_EDIT_FRAME, and SCH_EDIT_FRAME.

Definition at line 280 of file eda_base_frame.h.

References ExportHotkeyConfigToFile(), GetFileFromHistory(), ImportHotkeyConfigFromFile(), OnSelectPreferredEditor(), ReadHotkeyConfig(), ReadHotkeyConfigFile(), UpdateFileHistory(), and WriteHotkeyConfig().

Referenced by DIALOG_PAGES_SETTINGS::OnOkClick(), SCH_EDIT_FRAME::OnPreferencesOptions(), and SCH_EDIT_FRAME::Process_Config().

280 {};
void EDA_BASE_FRAME::SaveSettings ( wxConfigBase *  aCfg)
virtual

Function SaveSettings saves common frame parameters to a configuration data file.

Don't forget to call the base class's SaveSettings() from your derived SaveSettings() otherwise the frames won't remember their positions and sizes.

Reimplemented in EDA_DRAW_FRAME, PCB_BASE_FRAME, GERBVIEW_FRAME, PCB_EDIT_FRAME, LIB_EDIT_FRAME, SCH_EDIT_FRAME, KICAD_MANAGER_FRAME, CVPCB_MAINFRAME, PL_EDITOR_FRAME, EDA_3D_VIEWER, FOOTPRINT_WIZARD_FRAME, SIM_PLOT_FRAME, FOOTPRINT_VIEWER_FRAME, LIB_VIEW_FRAME, and FOOTPRINT_EDIT_FRAME.

Definition at line 320 of file eda_base_frame.cpp.

References ConfigBaseName(), entryAutoSaveInterval, entryMruPath, entryPerspective, m_auimgr, m_autoSaveInterval, m_FramePos, m_FrameSize, m_hasAutoSave, m_mruPath, wxPoint::x, and wxPoint::y.

Referenced by IsType(), SIM_PLOT_FRAME::SaveSettings(), EDA_3D_VIEWER::SaveSettings(), CVPCB_MAINFRAME::SaveSettings(), KICAD_MANAGER_FRAME::SaveSettings(), EDA_DRAW_FRAME::SaveSettings(), and windowClosing().

321 {
322  wxString text;
323 
324  if( IsIconized() )
325  return;
326 
327  wxString baseCfgName = ConfigBaseName();
328 
329  m_FrameSize = GetSize();
330  m_FramePos = GetPosition();
331 
332  text = baseCfgName + wxT( "Pos_x" );
333  aCfg->Write( text, (long) m_FramePos.x );
334 
335  text = baseCfgName + wxT( "Pos_y" );
336  aCfg->Write( text, (long) m_FramePos.y );
337 
338  text = baseCfgName + wxT( "Size_x" );
339  aCfg->Write( text, (long) m_FrameSize.x );
340 
341  text = baseCfgName + wxT( "Size_y" );
342  aCfg->Write( text, (long) m_FrameSize.y );
343 
344  text = baseCfgName + wxT( "Maximized" );
345  aCfg->Write( text, IsMaximized() );
346 
347  if( m_hasAutoSave )
348  {
349  text = baseCfgName + entryAutoSaveInterval;
350  aCfg->Write( text, m_autoSaveInterval );
351  }
352 
353  // Once this is fully implemented, wxAuiManager will be used to maintain
354  // the persistance of the main frame and all it's managed windows and
355  // all of the legacy frame persistence position code can be removed.
356  wxString perspective = m_auimgr.SavePerspective();
357 
358  // printf( "perspective(%s): %s\n",
359  // TO_UTF8( m_FrameName + entryPerspective ), TO_UTF8( perspective ) );
360  aCfg->Write( baseCfgName + entryPerspective, perspective );
361  aCfg->Write( baseCfgName + entryMruPath, m_mruPath );
362 }
wxString m_mruPath
Most recently used path.
wxString ConfigBaseName()
Function ConfigBaseName.
wxAuiManager m_auimgr
static const wxString entryPerspective
Configuration file entry for wxAuiManger perspective.
static const wxString entryAutoSaveInterval
Configuration file entry name for auto save interval.
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
static const wxString entryMruPath
Configuration file entry for most recently used path.
int m_autoSaveInterval
The auto save interval time in seconds.
void EDA_BASE_FRAME::SetAutoSaveInterval ( int  aInterval)

Definition at line 209 of file eda_base_frame.cpp.

References m_autoSaveInterval, m_autoSaveState, and m_autoSaveTimer.

Referenced by isAutoSaveRequired(), DIALOG_GENERALOPTIONS::OnOkClick(), and SCH_EDIT_FRAME::OnPreferencesOptions().

210 {
211  m_autoSaveInterval = aInterval;
212 
213  if( m_autoSaveTimer->IsRunning() )
214  {
215  if( m_autoSaveInterval > 0 )
216  {
217  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
218  }
219  else
220  {
221  m_autoSaveTimer->Stop();
222  m_autoSaveState = false;
223  }
224  }
225 }
bool m_autoSaveState
Flag to indicate the last auto save state.
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
int m_autoSaveInterval
The auto save interval time in seconds.
virtual void EDA_BASE_FRAME::SetIconScale ( int  aScale)
inlinevirtual

Function SetIconScale.

Modify the scale of icons in the window; should refresh them and save the setting.

Reimplemented in PCB_EDIT_FRAME, SCH_EDIT_FRAME, GERBVIEW_FRAME, and LIB_EDIT_FRAME.

Definition at line 466 of file eda_base_frame.h.

466 {}
void EDA_BASE_FRAME::SetMruPath ( const wxString &  aPath)
inline

Definition at line 367 of file eda_base_frame.h.

Referenced by KICAD_MANAGER_FRAME::LoadProject().

367 { m_mruPath = aPath; }
wxString m_mruPath
Most recently used path.
void EDA_BASE_FRAME::ShowChangedIcons ( )
virtual

Function ShowChangedIcons redraws items menus after a icon was changed option.

Definition at line 253 of file eda_base_frame.cpp.

References ReCreateMenuBar().

Referenced by GetMruPath(), and KIWAY::ShowChangedIcons().

254 {
255  ReCreateMenuBar();
256  GetMenuBar()->Refresh();
257 }
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
void EDA_BASE_FRAME::ShowChangedLanguage ( )
virtual

Function ShowChangedLanguage redraws the menus and what not in current language.

Reimplemented in PCB_EDIT_FRAME, and GERBVIEW_FRAME.

Definition at line 246 of file eda_base_frame.cpp.

References ReCreateMenuBar().

Referenced by GetMruPath(), KIWAY::SetLanguage(), GERBVIEW_FRAME::ShowChangedLanguage(), and PCB_EDIT_FRAME::ShowChangedLanguage().

247 {
248  ReCreateMenuBar();
249  GetMenuBar()->Refresh();
250 }
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
const SEARCH_STACK & EDA_BASE_FRAME::sys_search ( )
protectedvirtual

Function sys_search returns a SEARCH_STACK pertaining to entire program, and is overloaded in KICAD_MANAGER_FRAME.

Reimplemented in KICAD_MANAGER_FRAME.

Definition at line 374 of file eda_base_frame.cpp.

References Kiface(), and KIFACE_I::KifaceSearch().

Referenced by GetKicadHelp(), and isAutoSaveRequired().

375 {
376  return Kiface().KifaceSearch();
377 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
SEARCH_STACK & KifaceSearch()
Only for DSO specific &#39;non-library&#39; files.
Definition: kiface_i.h:127
void EDA_BASE_FRAME::UpdateFileHistory ( const wxString &  FullFileName,
wxFileHistory *  aFileHistory = NULL 
)

Function UpdateFileHistory Updates the list of recently opened files.

Note also the menu is updated, if wxFileHistory::UseMenu was called at init time

Parameters
FullFileNameThe full file name including the path.
aFileHistoryThe wxFileHistory in use. If NULL, the main application file history is used.

Definition at line 392 of file eda_base_frame.cpp.

References KIFACE_I::GetFileHistory(), and Kiface().

Referenced by SCH_EDIT_FRAME::ImportFile(), GERBVIEW_FRAME::LoadExcellonFiles(), GERBVIEW_FRAME::loadListOfGerberFiles(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), KICAD_MANAGER_FRAME::LoadProject(), KICAD_MANAGER_FRAME::OnCloseWindow(), SCH_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::SavePcbFile(), SaveProjectSettings(), and GERBVIEW_FRAME::unarchiveFiles().

394 {
395  wxFileHistory* fileHistory = aFileHistory;
396 
397  if( !fileHistory )
398  fileHistory = &Kiface().GetFileHistory();
399 
400  fileHistory->AddFileToHistory( FullFileName );
401 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:123
void EDA_BASE_FRAME::windowClosing ( wxCloseEvent &  event)
private

Function windowClosing (with its unexpected name so it does not collide with the real OnWindowClose() function provided in derived classes) is called just before a window closing, and is used to call a derivation specific SaveSettings().

SaveSettings() is called for all derived wxFrames in this base class overload. (Calling it from a destructor is deprecated since the wxFrame's position is not available in the destructor on linux.) In other words, you should not need to call SaveSettings() anywhere, except in this one function found only in this class.

Definition at line 127 of file eda_base_frame.cpp.

References config(), findQuasiModalDialog(), and SaveSettings().

Referenced by EDA_BASE_FRAME().

128 {
129  DIALOG_SHIM* dlg = findQuasiModalDialog( GetChildren() );
130  if( dlg )
131  {
132  // Happens when a quasi modal dialog is currently open.
133  // For example: if the Kicad manager try to close Kicad.
134  wxMessageBox( _(
135  "The program cannot be closed\n"
136  "A quasi-modal dialog window is currently open, please close it first." ) );
137  event.Veto();
138  return;
139  }
140 
141  wxConfigBase* cfg = config();
142 
143  if( cfg )
144  SaveSettings( cfg ); // virtual, wxFrame specific
145 
146  event.Skip(); // we did not "handle" the event, only eavesdropped on it.
147 }
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file. ...
DIALOG_SHIM * findQuasiModalDialog(wxWindowList &aList)
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:70
int EDA_BASE_FRAME::WriteHotkeyConfig ( struct EDA_HOTKEY_CONFIG aDescList,
wxString *  aFullFileName = NULL 
)
virtual

Function WriteHotkeyConfig Store the current hotkey list It is stored using the standard wxConfig mechanism or a file.

Parameters
aDescList= pointer to the current hotkey list.
aFullFileName= a wxString pointer to a full file name. if NULL, use the standard wxConfig mechanism (default) the output format is: shortcut "key" "function" lines starting with # are comments

Reimplemented in EDA_DRAW_FRAME.

Definition at line 528 of file hotkeys_basic.cpp.

References AddDelimiterString(), DEFAULT_HOTKEY_FILENAME_EXT, GetChars(), GetNewConfig(), HOTKEYS_CONFIG_KEY, KeyNameFromKeyCode(), EDA_HOTKEY_CONFIG::m_HK_InfoList, EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, EDA_HOTKEY_CONFIG::m_SectionTag, EDA_HOTKEY_CONFIG::m_Title, and TO_UTF8.

Referenced by SaveProjectSettings(), HOTKEYS_EDITOR_DIALOG::TransferDataFromWindow(), and EDA_DRAW_FRAME::WriteHotkeyConfig().

530 {
531  wxString msg;
532  wxString keyname, infokey;
533 
534  msg = wxT( "$hotkey list\n" );
535 
536  // Print the current hotkey list
537  EDA_HOTKEY** list;
538 
539  for( ; aDescList->m_HK_InfoList != nullptr; aDescList++ )
540  {
541  if( aDescList->m_Title )
542  {
543  msg += wxT( "# " );
544  msg += *aDescList->m_Title;
545  msg += wxT( "\n" );
546  }
547 
548  msg += *aDescList->m_SectionTag;
549  msg += wxT( "\n" );
550 
551  list = aDescList->m_HK_InfoList;
552 
553  for( ; *list != nullptr; list++ )
554  {
555  EDA_HOTKEY* hk_decr = *list;
556  msg += wxT( "shortcut " );
557  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
558  AddDelimiterString( keyname );
559  infokey = hk_decr->m_InfoMsg;
560  AddDelimiterString( infokey );
561  msg += keyname + wxT( ": " ) + infokey + wxT( "\n" );
562  }
563  }
564 
565  msg += wxT( "$Endlist\n" );
566 
567  if( aFullFileName )
568  {
569  FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) );
570 
571  if( file )
572  {
573  fputs( TO_UTF8( msg ), file );
574  fclose( file );
575  }
576  else
577  {
578  msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
579  return 0;
580  }
581  }
582  else
583  {
584  wxFileName fn( GetName() );
585  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
586  std::unique_ptr<wxConfigBase> config( GetNewConfig( fn.GetFullPath() ) );
587  config->Write( HOTKEYS_CONFIG_KEY, msg );
588  }
589 
590  return 1;
591 }
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
wxConfigBase * GetNewConfig(const wxString &aProgName)
Function GetNewConfig.
Definition: common.cpp:205
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
#define HOTKEYS_CONFIG_KEY
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done)...
Definition: gestfich.cpp:44
wxString * m_SectionTag
Definition: hotkeys_basic.h:90
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
wxString * m_Title
Definition: hotkeys_basic.h:92
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34

Member Data Documentation

wxString EDA_BASE_FRAME::m_AboutTitle
protected

Name of program displayed in About.

Definition at line 147 of file eda_base_frame.h.

int EDA_BASE_FRAME::m_autoSaveInterval
protected

The auto save interval time in seconds.

Definition at line 158 of file eda_base_frame.h.

Referenced by EDA_BASE_FRAME(), GetAutoSaveInterval(), LoadSettings(), onAutoSaveTimer(), ProcessEvent(), SaveSettings(), and SetAutoSaveInterval().

bool EDA_BASE_FRAME::m_autoSaveState
protected

Flag to indicate the last auto save state.

Definition at line 155 of file eda_base_frame.h.

Referenced by SCH_EDIT_FRAME::doAutoSave(), PCB_EDIT_FRAME::doAutoSave(), EDA_BASE_FRAME(), ProcessEvent(), and SetAutoSaveInterval().

wxTimer* EDA_BASE_FRAME::m_autoSaveTimer
protected

The timer used to implement the auto save feature;.

Definition at line 161 of file eda_base_frame.h.

Referenced by EDA_BASE_FRAME(), onAutoSaveTimer(), ProcessEvent(), SetAutoSaveInterval(), and ~EDA_BASE_FRAME().

wxString EDA_BASE_FRAME::m_configFrameName
protected

prefix used in config to identify some params (frame size...) if empty, the frame name defined in CTOR is used

Definition at line 142 of file eda_base_frame.h.

Referenced by ConfigBaseName(), and LIB_VIEW_FRAME::LIB_VIEW_FRAME().

bool EDA_BASE_FRAME::m_hasAutoSave
protected

Flag to indicate if this frame supports auto save.

Definition at line 152 of file eda_base_frame.h.

Referenced by EDA_BASE_FRAME(), LoadSettings(), ProcessEvent(), and SaveSettings().

FRAME_T EDA_BASE_FRAME::m_Ident
protected

Id Type (pcb, schematic, library..)

Definition at line 138 of file eda_base_frame.h.

Referenced by EDA_BASE_FRAME().

wxString EDA_BASE_FRAME::m_perspective
protected

wxAuiManager perspective.

Definition at line 163 of file eda_base_frame.h.

Referenced by LoadSettings().


The documentation for this class was generated from the following files: