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 <wxstruct.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...
 
bool Enable (bool enable) override
 
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...
 

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...
 

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...
 

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 112 of file wxstruct.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 basicframe.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(), windowClosing(), wxPoint::x, and wxPoint::y.

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 }
bool m_autoSaveState
Flag to indicate the last auto save state.
Definition: wxstruct.h:145
wxString m_mruPath
Most recently used path.
Definition: wxstruct.h:155
void windowClosing(wxCloseEvent &event)
Function windowClosing (with its unexpected name so it does not collide with the real OnWindowClose()...
Definition: basicframe.cpp:112
void onAutoSaveTimer(wxTimerEvent &aEvent)
Function onAutoSaveTimer handles the auto save timer event.
Definition: basicframe.cpp:224
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
Definition: wxstruct.h:151
FRAME_T m_Ident
Id Type (pcb, schematic, library..)
Definition: wxstruct.h:128
wxPoint m_FramePos
Definition: wxstruct.h:129
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:135
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
Definition: wxstruct.h:142
wxSize m_FrameSize
Definition: wxstruct.h:130
int m_autoSaveInterval
The auto save interval time in seconds.
Definition: wxstruct.h:148
EDA_BASE_FRAME::~EDA_BASE_FRAME ( )

Definition at line 156 of file basicframe.cpp.

References m_autoSaveTimer.

157 {
158  delete m_autoSaveTimer;
159 
160  // This is needed for OSX: avoids further OnDraw processing after this
161  // destructor and before the native window is destroyed
162  this->Freeze();
163 }
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
Definition: wxstruct.h:151

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 671 of file basicframe.cpp.

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

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

672 {
673  wxMenu* menu = NULL;
674  wxMenuItem* item = MasterMenu->FindItem( ID_KICAD_SELECT_ICONS_OPTIONS );
675 
676  if( item ) // This menu exists, do nothing
677  return;
678 
679  menu = new wxMenu;
680 
681  menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICONS_IN_MENUS,
682  _( "Icons in Menus" ), wxEmptyString,
683  wxITEM_CHECK ) );
684  menu->Check( ID_KICAD_SELECT_ICONS_IN_MENUS, Pgm().GetUseIconsInMenus() );
685 
686  AddMenuItem( MasterMenu, menu,
688  _( "Icons Options" ),
689  _( "Select show icons in menus and icons sizes" ),
690  KiBitmap( hammer_xpm ) );
691 }
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:55
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:36
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 576 of file basicframe.cpp.

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

Referenced by SCH_EDIT_FRAME::LoadOneEEFile(), and PCB_EDIT_FRAME::OpenProjectFiles().

578 {
579  wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
580  wxCHECK_RET( !aBackupFileExtension.IsEmpty(), wxT( "Invalid backup file extension!" ) );
581 
582  wxFileName autoSaveFileName = aFileName;
583 
584  // Check for auto save file.
585  autoSaveFileName.SetName( AUTOSAVE_PREFIX_FILENAME + aFileName.GetName() );
586 
587  wxLogTrace( traceAutoSave,
588  wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
589 
590  if( !autoSaveFileName.FileExists() )
591  return;
592 
593  wxString msg = wxString::Format( _(
594  "Well this is potentially embarrassing!\n"
595  "It appears that the last time you were editing the file\n"
596  "'%s'\n"
597  "it was not saved properly. Do you wish to restore the last saved edits you made?" ),
598  GetChars( aFileName.GetFullName() )
599  );
600 
601  int response = wxMessageBox( msg, Pgm().App().GetAppName(), wxYES_NO | wxICON_QUESTION, this );
602 
603  // Make a backup of the current file, delete the file, and rename the auto save file to
604  // the file name.
605  if( response == wxYES )
606  {
607  // Get the backup file name.
608  wxFileName backupFileName = aFileName;
609  backupFileName.SetExt( aBackupFileExtension );
610 
611  // If an old backup file exists, delete it. If an old copy of the file exists, rename
612  // it to the backup file name
613  if( aFileName.FileExists() )
614  {
615  // Remove the old file backup file.
616  if( backupFileName.FileExists() )
617  wxRemoveFile( backupFileName.GetFullPath() );
618 
619  // Rename the old file to the backup file name.
620  if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath() ) )
621  {
622  msg.Printf( _( "Could not create backup file <%s>" ),
623  GetChars( backupFileName.GetFullPath() ) );
624  wxMessageBox( msg );
625  }
626  }
627 
628  if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
629  {
630  wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
631  Pgm().App().GetAppName(), wxOK | wxICON_EXCLAMATION, this );
632  }
633  }
634  else
635  {
636  wxLogTrace( traceAutoSave,
637  wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
638 
639  // Remove the auto save file when using the previous file as is.
640  wxRemoveFile( autoSaveFileName.GetFullPath() );
641  }
642 }
const wxChar traceAutoSave[]
Custom trace mask to enable and disable auto save tracing.
Definition: basicframe.cpp:53
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
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
#define AUTOSAVE_PREFIX_FILENAME
a prefix to create filenames for schematic files or other difile when auto-saved to retrieve a crash ...
Definition: wxstruct.h:70
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 255 of file wxstruct.h.

References m_configFrameName.

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

256  {
257  wxString baseCfgName = m_configFrameName.IsEmpty() ? GetName() : m_configFrameName;
258  return baseCfgName;
259  }
wxString m_configFrameName
prefix used in config to identify some params (frame size...) if empty, the frame name defined in CTO...
Definition: wxstruct.h:132
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 231 of file basicframe.cpp.

Referenced by onAutoSaveTimer().

232 {
233  wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
234 }
bool EDA_BASE_FRAME::Enable ( bool  enable)
override

Definition at line 192 of file basicframe.cpp.

Referenced by FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard(), and KIWAY_PLAYER::ShowModal().

193 {
194  // so we can do logging of this state change:
195 
196 #if defined(DEBUG)
197  const char* type_id = typeid( *this ).name();
198  printf( "wxFrame %-28s: %s\n", type_id, enable ? "enabled" : "disabled" );
199 #endif
200 
201  return wxFrame::Enable( enable );
202 }
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 768 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, EDA_FILE_SELECTOR(), GetMruPath(), Prj(), SetMruPath(), and WriteHotkeyConfig().

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(), and FOOTPRINT_EDIT_FRAME::ProcessPreferences().

770 {
771  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
772  wxString mask = wxT( "*." ) + ext;
773 
774 #if 0
775  wxString path = wxPathOnly( Prj().GetProjectFullName() );
776 #else
777  wxString path = GetMruPath();
778 #endif
779  wxFileName fn( aDefaultShortname );
780  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
781 
782  wxString filename = EDA_FILE_SELECTOR( _( "Write Hotkey Configuration File:" ),
783  path,
784  fn.GetFullPath(),
785  ext,
786  mask,
787  this,
788  wxFD_SAVE,
789  true );
790 
791  if( filename.IsEmpty() )
792  return;
793 
794  WriteHotkeyConfig( aDescList, &filename );
795  SetMruPath( wxFileName( filename ).GetPath() );
796 }
void SetMruPath(const wxString &aPath)
Definition: wxstruct.h:356
PROJECT & Prj()
Definition: kicad.cpp:293
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
Definition: wxstruct.h:358
int EDA_BASE_FRAME::GetAutoSaveInterval ( ) const
inline

Definition at line 214 of file wxstruct.h.

References m_autoSaveInterval.

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

214 { return m_autoSaveInterval; }
int m_autoSaveInterval
The auto save interval time in seconds.
Definition: wxstruct.h:148
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 400 of file basicframe.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(), and GERBVIEW_FRAME::OnZipFileHistory().

402 {
403  wxFileHistory* fileHistory = aFileHistory;
404 
405  if( !fileHistory )
406  fileHistory = &Kiface().GetFileHistory();
407 
408  int baseId = fileHistory->GetBaseId();
409 
410  wxASSERT( cmdId >= baseId && cmdId < baseId + (int) fileHistory->GetCount() );
411 
412  unsigned i = cmdId - baseId;
413 
414  if( i < fileHistory->GetCount() )
415  {
416  wxString fn = fileHistory->GetHistoryFile( i );
417 
418  if( wxFileName::FileExists( fn ) )
419  return fn;
420  else
421  {
422  wxString msg = wxString::Format(
423  wxT( "file '%s' was not found." ),
424  GetChars( fn ) );
425 
426  wxMessageBox( msg );
427 
428  fileHistory->RemoveFileFromHistory( i );
429  }
430  }
431 
432  return wxEmptyString;
433 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:121
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
void EDA_BASE_FRAME::GetKicadAbout ( wxCommandEvent &  event)

Definition at line 525 of file basicframe.cpp.

References ShowAboutDialog().

526 {
527  bool ShowAboutDialog(wxWindow * parent);
528  ShowAboutDialog( this );
529 }
bool ShowAboutDialog(wxWindow *parent)
void EDA_BASE_FRAME::GetKicadContribute ( wxCommandEvent &  event)

Definition at line 514 of file basicframe.cpp.

References URL_GET_INVOLVED.

515 {
516  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
517  {
518  wxString msg = _( "Could not launch the default browser. For information on how to help the KiCad project, visit " );
519  msg.Append( URL_GET_INVOLVED );
520  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, this );
521  }
522 }
#define URL_GET_INVOLVED
Definition: basicframe.cpp:51
void EDA_BASE_FRAME::GetKicadHelp ( wxCommandEvent &  event)

Definition at line 436 of file basicframe.cpp.

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

437 {
438  const SEARCH_STACK& search = sys_search();
439 
440  /* We have to get document for beginners,
441  * or the full specific doc
442  * if event id is wxID_INDEX, we want the document for beginners.
443  * else the specific doc file (its name is in Kiface().GetHelpFileName())
444  * The document for beginners is the same for all KiCad utilities
445  */
446  if( event.GetId() == wxID_INDEX )
447  {
448  // List of possible names for Getting Started in KiCad
449  const wxChar* names[2] = {
450  wxT( "getting_started_in_kicad" ),
451  wxT( "Getting_Started_in_KiCad" )
452  };
453 
454  wxString helpFile;
455  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
456  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
457  for( unsigned ii = 0; ii < DIM( names ); ii++ )
458  {
459  helpFile = SearchHelpFileFullPath( search, names[ii] );
460 
461  if( !helpFile.IsEmpty() )
462  break;
463  }
464 
465  if( !helpFile )
466  {
467  wxString msg = wxString::Format( _(
468  "Html or pdf help file \n'%s'\n or\n'%s' could not be found." ), names[0], names[1] );
469  wxMessageBox( msg );
470  }
471  else
472  {
473  GetAssociatedDocument( this, helpFile );
474  }
475 
476  return;
477  }
478 
479  wxString base_name = help_name();
480  wxString helpFile = SearchHelpFileFullPath( search, base_name );
481 
482  if( !helpFile )
483  {
484  wxString msg = wxString::Format( _(
485  "Help file '%s' could not be found." ),
486  GetChars( base_name )
487  );
488  wxMessageBox( msg );
489  }
490  else
491  {
492  GetAssociatedDocument( this, helpFile );
493  }
494 }
#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...
Definition: basicframe.cpp:370
wxString SearchHelpFileFullPath(const SEARCH_STACK &aSStack, const wxString &aBaseName)
Function SearchHelpFileFullPath returns the help file'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()
Definition: basicframe.cpp:376
wxString EDA_BASE_FRAME::GetMruPath ( ) const
inline

Definition at line 358 of file wxstruct.h.

References m_mruPath.

Referenced by ExportHotkeyConfigToFile(), ImportHotkeyConfigFromFile(), and KICAD_MANAGER_FRAME::OnLoadProject().

358 { return m_mruPath; }
wxString m_mruPath
Most recently used path.
Definition: wxstruct.h:155
wxString EDA_BASE_FRAME::help_name ( )
protectedvirtual

Reimplemented in KICAD_MANAGER_FRAME.

Definition at line 376 of file basicframe.cpp.

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

Referenced by GetKicadHelp().

377 {
378  return Kiface().GetHelpFileName();
379 }
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:119
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 737 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, EDA_FILE_SELECTOR(), GetMruPath(), Prj(), ReadHotkeyConfigFile(), and SetMruPath().

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(), and FOOTPRINT_EDIT_FRAME::ProcessPreferences().

739 {
740  wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
741  wxString mask = wxT( "*." ) + ext;
742 
743 #if 0 // pass in the project dir as an argument
744  wxString path = wxPathOnly( Prj().GetProjectFullName() );
745 #else
746  wxString path = GetMruPath();
747 #endif
748  wxFileName fn( aDefaultShortname );
749  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
750 
751  wxString filename = EDA_FILE_SELECTOR( _( "Read Hotkey Configuration File:" ),
752  path,
753  fn.GetFullPath(),
754  ext,
755  mask,
756  this,
757  wxFD_OPEN,
758  true );
759 
760  if( filename.IsEmpty() )
761  return;
762 
763  ReadHotkeyConfigFile( filename, aDescList );
764  SetMruPath( wxFileName( filename ).GetPath() );
765 }
void SetMruPath(const wxString &aPath)
Definition: wxstruct.h:356
int ReadHotkeyConfigFile(const wxString &aFilename, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfigFile Read an old configuration file (<file>.key) and fill the current ho...
PROJECT & Prj()
Definition: kicad.cpp:293
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
#define DEFAULT_HOTKEY_FILENAME_EXT
Definition: hotkeys_basic.h:34
wxString GetMruPath() const
Definition: wxstruct.h:358
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 168 of file wxstruct.h.

Referenced by ProcessEvent().

168 { return false; }
bool EDA_BASE_FRAME::IsType ( FRAME_T  aType) const
inline
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 532 of file basicframe.cpp.

References GetChars().

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

533 {
534  wxString msg;
535  wxFileName fn = aFileName;
536 
537  // Check for absence of a file path with a file name. Unfortunately KiCad
538  // uses paths relative to the current project path without the ./ part which
539  // confuses wxFileName. Making the file name path absolute may be less than
540  // elegant but it solves the problem.
541  if( fn.GetPath().IsEmpty() && fn.HasName() )
542  fn.MakeAbsolute();
543 
544  wxCHECK_MSG( fn.IsOk(), false,
545  wxT( "File name object is invalid. Bad programmer!" ) );
546  wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
547  wxT( "File name object path <" ) + fn.GetFullPath() +
548  wxT( "> is not set. Bad programmer!" ) );
549 
550  if( fn.IsDir() && !fn.IsDirWritable() )
551  {
552  msg.Printf( _( "You do not have write permissions to folder <%s>." ),
553  GetChars( fn.GetPath() ) );
554  }
555  else if( !fn.FileExists() && !fn.IsDirWritable() )
556  {
557  msg.Printf( _( "You do not have write permissions to save file <%s> to folder <%s>." ),
558  GetChars( fn.GetFullName() ), GetChars( fn.GetPath() ) );
559  }
560  else if( fn.FileExists() && !fn.IsFileWritable() )
561  {
562  msg.Printf( _( "You do not have write permissions to save file <%s>." ),
563  GetChars( fn.GetFullPath() ) );
564  }
565 
566  if( !msg.IsEmpty() )
567  {
568  wxMessageBox( msg );
569  return false;
570  }
571 
572  return true;
573 }
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, SCH_EDIT_FRAME, LIB_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 256 of file basicframe.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 SIM_PLOT_FRAME::LoadSettings(), EDA_3D_VIEWER::LoadSettings(), CVPCB_MAINFRAME::LoadSettings(), KICAD_MANAGER_FRAME::LoadSettings(), and EDA_DRAW_FRAME::LoadSettings().

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

Function onAutoSaveTimer handles the auto save timer event.

Definition at line 224 of file basicframe.cpp.

References doAutoSave(), m_autoSaveInterval, and m_autoSaveTimer.

Referenced by EDA_BASE_FRAME().

225 {
226  if( !doAutoSave() )
227  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
228 }
virtual bool doAutoSave()
Function doAutoSave should be overridden by the derived class to handle the auto save feature...
Definition: basicframe.cpp:231
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
Definition: wxstruct.h:151
int m_autoSaveInterval
The auto save interval time in seconds.
Definition: wxstruct.h:148
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 660 of file basicframe.cpp.

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

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

661 {
662  if( event.GetId() == ID_KICAD_SELECT_ICONS_IN_MENUS )
663  {
664  Pgm().SetUseIconsInMenus( event.IsChecked() );
665  }
666 
667  ReCreateMenuBar();
668 }
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.
Definition: basicframe.cpp:237
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 497 of file basicframe.cpp.

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

498 {
499  // Ask for the current editor and instruct GetEditorName() to not show
500  // unless we pass false as argument.
501  wxString editorname = Pgm().GetEditorName( false );
502 
503  // Ask the user to select a new editor, but suggest the current one as the default.
504  editorname = Pgm().AskUserForPreferredEditor( editorname );
505 
506  // If we have a new editor name request it to be copied to m_editor_name and saved
507  // to the preferences file. If the user cancelled the dialog then the previous
508  // value will be retained.
509  if( !editorname.IsEmpty() )
510  Pgm().SetEditorName( editorname );
511 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:328
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:373
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:336
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 645 of file basicframe.cpp.

Referenced by 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().

646 {
647  if( evt_type != 0 )
648  {
649  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
650  evt.SetEventObject( this );
651  evt.SetId( evt_type );
652  wxPostEvent( this, evt );
653  return true;
654  }
655 
656  return false;
657 }
void EDA_BASE_FRAME::PrintMsg ( const wxString &  text)

Definition at line 382 of file basicframe.cpp.

Referenced by SCH_EDIT_FRAME::LoadOneEEFile(), and EDA_DRAW_PANEL::OnMouseEvent().

383 {
384  SetStatusText( text );
385 }
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 166 of file basicframe.cpp.

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

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

167 {
168  if( !wxFrame::ProcessEvent( aEvent ) )
169  return false;
170 
171  if( IsShown() && m_hasAutoSave &&
173  {
174  if( !m_autoSaveState )
175  {
176  wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
177  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
178  m_autoSaveState = true;
179  }
180  else if( m_autoSaveTimer->IsRunning() )
181  {
182  wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
183  m_autoSaveTimer->Stop();
184  m_autoSaveState = false;
185  }
186  }
187 
188  return true;
189 }
bool m_autoSaveState
Flag to indicate the last auto save state.
Definition: wxstruct.h:145
const wxChar traceAutoSave[]
Custom trace mask to enable and disable auto save tracing.
Definition: basicframe.cpp:53
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
Definition: wxstruct.h:151
virtual bool isAutoSaveRequired() const
Function autoSaveRequired returns the auto save status of the application.
Definition: wxstruct.h:168
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
Definition: wxstruct.h:142
int m_autoSaveInterval
The auto save interval time in seconds.
Definition: wxstruct.h:148
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 658 of file hotkeys_basic.cpp.

659 {
660  ::ReadHotkeyConfig( GetName(), aDescList );
661  return 1;
662 }
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 601 of file hotkeys_basic.cpp.

References DEFAULT_HOTKEY_FILENAME_EXT, and ParseHotkeyConfig().

Referenced by ImportHotkeyConfigFromFile().

603 {
604  wxFileName fn( aFilename );
605  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
606 
607  wxFile cfgfile( fn.GetFullPath() );
608 
609  if( !cfgfile.IsOpened() ) // There is a problem to open file
610  return 0;
611 
612  // get length
613  cfgfile.SeekEnd();
614  wxFileOffset size = cfgfile.Tell();
615  cfgfile.Seek( 0 );
616 
617  // read data
618  char* buffer = new char[size];
619  cfgfile.Read( buffer, size );
620 
621  wxString data( buffer, wxConvUTF8 );
622 
623  // parse
624  ParseHotkeyConfig( data, aDescList );
625 
626  // cleanup
627  delete[] buffer;
628  cfgfile.Close();
629  return 1;
630 }
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, KICAD_MANAGER_FRAME, PCB_BASE_FRAME, LIB_EDIT_FRAME, PL_EDITOR_FRAME, FOOTPRINT_EDIT_FRAME, CVPCB_MAINFRAME, FOOTPRINT_VIEWER_FRAME, and LIB_VIEW_FRAME.

Definition at line 237 of file basicframe.cpp.

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

238 {
239 }
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 269 of file wxstruct.h.

Referenced by DIALOG_PAGES_SETTINGS::OnOkClick().

269 {};
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, SCH_EDIT_FRAME, LIB_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 316 of file basicframe.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 SIM_PLOT_FRAME::SaveSettings(), EDA_3D_VIEWER::SaveSettings(), CVPCB_MAINFRAME::SaveSettings(), KICAD_MANAGER_FRAME::SaveSettings(), EDA_DRAW_FRAME::SaveSettings(), and windowClosing().

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

Definition at line 205 of file basicframe.cpp.

References m_autoSaveInterval, m_autoSaveState, and m_autoSaveTimer.

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

206 {
207  m_autoSaveInterval = aInterval;
208 
209  if( m_autoSaveTimer->IsRunning() )
210  {
211  if( m_autoSaveInterval > 0 )
212  {
213  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
214  }
215  else
216  {
217  m_autoSaveTimer->Stop();
218  m_autoSaveState = false;
219  }
220  }
221 }
bool m_autoSaveState
Flag to indicate the last auto save state.
Definition: wxstruct.h:145
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
Definition: wxstruct.h:151
int m_autoSaveInterval
The auto save interval time in seconds.
Definition: wxstruct.h:148
void EDA_BASE_FRAME::SetMruPath ( const wxString &  aPath)
inline

Definition at line 356 of file wxstruct.h.

Referenced by ExportHotkeyConfigToFile(), ImportHotkeyConfigFromFile(), and KICAD_MANAGER_FRAME::OnLoadProject().

356 { m_mruPath = aPath; }
wxString m_mruPath
Most recently used path.
Definition: wxstruct.h:155
void EDA_BASE_FRAME::ShowChangedIcons ( )
virtual

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

Definition at line 249 of file basicframe.cpp.

References ReCreateMenuBar().

Referenced by KIWAY::ShowChangedIcons().

250 {
251  ReCreateMenuBar();
252  GetMenuBar()->Refresh();
253 }
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
Definition: basicframe.cpp:237
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 242 of file basicframe.cpp.

References ReCreateMenuBar().

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

243 {
244  ReCreateMenuBar();
245  GetMenuBar()->Refresh();
246 }
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
Definition: basicframe.cpp:237
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 370 of file basicframe.cpp.

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

Referenced by GetKicadHelp().

371 {
372  return Kiface().KifaceSearch();
373 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_i.h:125
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 388 of file basicframe.cpp.

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

Referenced by GERBVIEW_FRAME::LoadExcellonFiles(), GERBVIEW_FRAME::LoadGerberFiles(), PL_EDITOR_FRAME::LoadPageLayoutDescrFile(), KICAD_MANAGER_FRAME::OnCloseWindow(), KICAD_MANAGER_FRAME::OnLoadProject(), SCH_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::SavePcbFile(), and GERBVIEW_FRAME::unarchiveFiles().

390 {
391  wxFileHistory* fileHistory = aFileHistory;
392 
393  if( !fileHistory )
394  fileHistory = &Kiface().GetFileHistory();
395 
396  fileHistory->AddFileToHistory( FullFileName );
397 }
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:121
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 112 of file basicframe.cpp.

References config(), DIALOG_SHIM::IsQuasiModal(), and SaveSettings().

Referenced by EDA_BASE_FRAME().

113 {
114  DIALOG_SHIM* dlg = NULL;
115  wxWindowList list = GetChildren();
116 
117  // Quasi modal dialogs create issues (crashes) when closing Kicad.
118  // I am guessing they are delete too late, when deleting main frames.
119  // AFAIK, only these DIALOG_SHIM dialogs create such issues.
120  // The policy is do not allow closing Kicad if a Quasi modal dialog is open.
121  // (Anyway, closing without prompting the user is certainly bad,
122  // because an edit is in preogress)
123  // Therefore, iterate through the child list to find at least
124  // a DIALOG_SHIM opened in quasi modal mode
125  for( wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter )
126  {
127  if( (dlg = dynamic_cast<DIALOG_SHIM*> (*iter) ) != NULL )
128  {
129  if( dlg->IsQuasiModal() )
130  break;
131  else
132  dlg = NULL;
133  }
134  }
135 
136  if( dlg )
137  {
138  // Happens when a quasi modal dialog is currently open.
139  // For example: if the Kicad manager try to close Kicad.
140  wxMessageBox( _(
141  "The program cannot be closed\n"
142  "A quasi-modal dialog window is currently open, please close it first." ) );
143  event.Veto();
144  return;
145  }
146 
147  wxConfigBase* cfg = config();
148 
149  if( cfg )
150  SaveSettings( cfg ); // virtual, wxFrame specific
151 
152  event.Skip(); // we did not "handle" the event, only eavesdropped on it.
153 }
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file. ...
Definition: basicframe.cpp:316
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:60
bool IsQuasiModal()
Definition: dialog_shim.h:93
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 534 of file hotkeys_basic.cpp.

References AddDelimiterString(), config(), 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 ExportHotkeyConfigToFile(), HOTKEYS_EDITOR_DIALOG::TransferDataFromWindow(), and EDA_DRAW_FRAME::WriteHotkeyConfig().

536 {
537  wxString msg;
538  wxString keyname, infokey;
539 
540  msg = wxT( "$hotkey list\n" );
541 
542  // Print the current hotkey list
543  EDA_HOTKEY** list;
544 
545  for( ; aDescList->m_HK_InfoList != NULL; aDescList++ )
546  {
547  if( aDescList->m_Title )
548  {
549  msg += wxT( "# " );
550  msg += *aDescList->m_Title;
551  msg += wxT( "\n" );
552  }
553 
554  msg += *aDescList->m_SectionTag;
555  msg += wxT( "\n" );
556 
557  list = aDescList->m_HK_InfoList;
558 
559  for( ; *list != NULL; list++ )
560  {
561  EDA_HOTKEY* hk_decr = *list;
562  msg += wxT( "shortcut " );
563  keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode );
564  AddDelimiterString( keyname );
565  infokey = hk_decr->m_InfoMsg;
566  AddDelimiterString( infokey );
567  msg += keyname + wxT( ": " ) + infokey + wxT( "\n" );
568  }
569  }
570 
571  msg += wxT( "$Endlist\n" );
572 
573  if( aFullFileName )
574  {
575  FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) );
576 
577  if( file )
578  {
579  fputs( TO_UTF8( msg ), file );
580  fclose( file );
581  }
582  else
583  {
584  msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) );
585  return 0;
586  }
587  }
588  else
589  {
590  wxFileName fn( GetName() );
591  fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT );
592  wxConfigBase* config = GetNewConfig( fn.GetFullPath() );
593  config->Write( HOTKEYS_CONFIG_KEY, msg );
594  delete config;
595  }
596 
597  return 1;
598 }
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...
Definition: basicframe.cpp:361
#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 137 of file wxstruct.h.

int EDA_BASE_FRAME::m_autoSaveInterval
protected

The auto save interval time in seconds.

Definition at line 148 of file wxstruct.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 145 of file wxstruct.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 151 of file wxstruct.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 132 of file wxstruct.h.

Referenced by ConfigBaseName().

bool EDA_BASE_FRAME::m_hasAutoSave
protected

Flag to indicate if this frame supports auto save.

Definition at line 142 of file wxstruct.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 128 of file wxstruct.h.

Referenced by EDA_BASE_FRAME().

wxString EDA_BASE_FRAME::m_perspective
protected

wxAuiManager perspective.

Definition at line 153 of file wxstruct.h.

Referenced by LoadSettings().


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