From 5b3c5861bdfe18fedfbde409a8cab6ebc36432b3 Mon Sep 17 00:00:00 2001 From: stambaughw Date: Mon, 6 Apr 2009 18:54:57 +0000 Subject: [PATCH] More search path, compiler warning, and bug fixes. Added template subdirectory to library search path list. Removed PARAM_CFG_BASE empty destructor to prevent GCC warning. Set timeout to 0 on DisplayInfo call to prevent debug assertion in eeschema/files-io.cpp. Declare PARAM_CFG_ARRAY for future project file object implementation. Removed unnecessary COMMON_GLOBL definition in gr_basic.h and param_config.h. --- common/confirm.cpp | 3 ++- common/edaappl.cpp | 21 +++++++++++---- common/gestfich.cpp | 42 ----------------------------- common/hotkeys_basic.cpp | 14 ++++++++-- common/projet_config.cpp | 22 ++++++++++++--- cvpcb/cvpcb.cpp | 1 - cvpcb/menucfg.cpp | 1 - eeschema/dialog_eeschema_config.cpp | 3 +-- eeschema/files-io.cpp | 24 ++++++++--------- include/gestfich.h | 8 ------ include/gr_basic.h | 4 --- include/param_config.h | 7 ++--- kicad/prjconfig.cpp | 13 ++++----- 13 files changed, 68 insertions(+), 95 deletions(-) diff --git a/common/confirm.cpp b/common/confirm.cpp index 7739982517..0320c55dbb 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -105,7 +105,8 @@ void DisplayInfo( wxWindow* parent, const wxString& text, int displaytime ) dialog = new WinEDA_MessageDialog( parent, text, _( "Info:" ), wxOK | wxICON_INFORMATION, displaytime ); - dialog->ShowModal(); dialog->Destroy(); + dialog->ShowModal(); + dialog->Destroy(); } diff --git a/common/edaappl.cpp b/common/edaappl.cpp index f5e2a39e11..25958492f8 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -528,21 +528,30 @@ void WinEDA_App::SetDefaultSearchPaths( void ) } else { - /* Build schematic, PCB, and 3D module library file search path - * list based on the known existing default search paths. */ + /* Add schematic library file path to search path list. */ fn.Clear(); fn.SetPath( m_searchPaths[i] ); fn.AppendDir( wxT( "library") ); - wxLogDebug( wxT( "Checking if search path <%s> exists." ), - fn.GetPath().c_str() ); - if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to library search path list" ), fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } + + /* Add kicad template file path to search path list. */ + fn.RemoveLastDir(); + fn.AppendDir( wxT( "template" ) ); + + if( fn.IsDirReadable() ) + { + wxLogDebug( wxT( "Adding <%s> to library search path list" ), + fn.GetPath().c_str() ); + m_libSearchPaths.Add( fn.GetPath() ); + } + + /* Add PCB library file path to search path list. */ fn.RemoveLastDir(); fn.AppendDir( wxT( "modules" ) ); @@ -552,6 +561,8 @@ void WinEDA_App::SetDefaultSearchPaths( void ) fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } + + /* Add 3D module library file path to search path list. */ fn.AppendDir( wxT( "packages3d" ) ); if( fn.IsDirReadable() ) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 6680a91171..86720e08e4 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -447,48 +447,6 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, } -/****************************************************/ -void SetRealLibraryPath( const wxString& shortlibname ) -/****************************************************/ - -/* met a jour le chemin des librairies g_RealLibDirBuffer (global) - * a partir de UserLibDirBuffer (global): - * Si UserLibDirBuffer non vide g_RealLibDirBuffer = g_UserLibDirBuffer. - * Sinon si variable d'environnement KICAD definie (KICAD = chemin pour kicad), - * g_UserLibDirBuffer = /shortlibname; - * Sinon g_UserLibDirBuffer = ../shortlibname/ - * Sinon g_UserLibDirBuffer = /usr/share/kicad/shortlibname/ - * - * Remarque: - * Les \ sont remplaces par / (a la mode Unix) - */ -{ - bool PathFound = FALSE; - - if( !g_UserLibDirBuffer.IsEmpty() ) // Chemin impose par la configuration - { - g_RealLibDirBuffer = g_UserLibDirBuffer; - PathFound = TRUE; - } - else - { - g_RealLibDirBuffer = ReturnKicadDatasPath(); - if( wxGetApp().m_Env_Defined ) // Chemin impose par la variable d'environnement - { - PathFound = TRUE; - } - g_RealLibDirBuffer += shortlibname; - if( wxDirExists( g_RealLibDirBuffer ) ) - PathFound = TRUE; - } - - - g_RealLibDirBuffer.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); - if( g_RealLibDirBuffer.Last() != '/' ) - g_RealLibDirBuffer += UNIX_STRING_DIR_SEP; -} - - /***********************************/ wxString ReturnKicadDatasPath() /***********************************/ diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index 29bfe68b47..06f8fe2129 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -17,6 +17,9 @@ #include "gestfich.h" #include "wxstruct.h" +#include +#include + wxString g_CommonSectionTag( wxT( "[common]" ) ); wxString g_SchematicSectionTag( wxT( "[eeschema]" ) ); @@ -597,14 +600,21 @@ wxString ReturnHotkeyConfigFilePath( int choice ) */ { wxString path; + wxAppTraits* traits = wxGetApp().GetTraits(); switch( choice ) { case 0: - path = wxGetHomeDir() + wxT( "/" ); - break; + path = traits->GetStandardPaths().GetUserConfigDir() + + wxFileName::GetPathSeparator(); case 1: + /* TODO: This is broken under a normal Poxis system. Users + * generally do no have write permissions to this path + * and there is no provision for prompting for the root + * password. Suggest we remove this unless someone has + * a workable solution (Wayne). + */ path = ReturnKicadDatasPath() + wxT( "template/" ); break; diff --git a/common/projet_config.cpp b/common/projet_config.cpp index bb5eb10ec5..ebb6920c25 100644 --- a/common/projet_config.cpp +++ b/common/projet_config.cpp @@ -11,12 +11,19 @@ #include "wxstruct.h" #include "param_config.h" +#include +#include + #define CONFIG_VERSION 1 #define FORCE_LOCAL_CONFIG true +#include +WX_DEFINE_OBJARRAY( PARAM_CFG_ARRAY ); + + /** * Cree ou recree la configuration locale de kicad (filename.pro) * initialise: @@ -93,13 +100,22 @@ bool WinEDA_App::ReCreatePrjConfig( const wxString& fileName, } } + defaultFileName = m_libSearchPaths.FindValidPath( wxT( "kicad.pro" ) ); - defaultFileName = ReturnKicadDatasPath() + wxT( "template/kicad" ) + - wxT( "." ) + ProjectFileExtension; + if( !defaultFileName ) + { + wxLogDebug( wxT( "Template file not found." ) ); + fn = wxFileName( GetTraits()->GetStandardPaths().GetDocumentsDir(), + wxT( "kicad" ), ProjectFileExtension ); + } + else + { + fn = defaultFileName; + } // Create new project file using the default name. m_ProjectConfig = new wxFileConfig( wxEmptyString, wxEmptyString, - wxEmptyString, defaultFileName ); + wxEmptyString, fn.GetFullPath() ); m_ProjectConfig->DontCreateOnDemand(); return false; diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index be93ad4c5f..a0ebbf8c7f 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -75,7 +75,6 @@ bool WinEDA_App::OnInit() GetSettings(); // read current setup wxSetWorkingDirectory( currCWD ); // mofifie par GetSetting - SetRealLibraryPath( wxT( "modules" ) ); if( argc > 1 ) { diff --git a/cvpcb/menucfg.cpp b/cvpcb/menucfg.cpp index d69dc9ab78..247173222a 100644 --- a/cvpcb/menucfg.cpp +++ b/cvpcb/menucfg.cpp @@ -124,7 +124,6 @@ void KiConfigCvpcbFrame::Update() if( msg != g_UserLibDirBuffer ) { g_UserLibDirBuffer = m_LibDirCtrl->GetValue(); - SetRealLibraryPath( wxT( "modules" ) ); listlib(); m_Parent->BuildFootprintListBox(); } diff --git a/eeschema/dialog_eeschema_config.cpp b/eeschema/dialog_eeschema_config.cpp index 54911d7acc..7cfa803d78 100644 --- a/eeschema/dialog_eeschema_config.cpp +++ b/eeschema/dialog_eeschema_config.cpp @@ -146,7 +146,6 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event ) // Set new default path lib g_UserLibDirBuffer = m_LibDirCtrl->GetValue(); - SetRealLibraryPath( wxT( "library" ) ); // set real path lib // Set new active lib list if( m_LibListChanged ) @@ -155,7 +154,7 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event ) g_LibName_List.Clear(); for ( unsigned ii = 0; ii < m_ListLibr->GetCount(); ii ++ ) g_LibName_List.Add(m_ListLibr->GetString(ii) ); - + // take new list in account LoadLibraries( m_Parent ); if( m_Parent->m_ViewlibFrame ) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index a59febbdec..eb5d5e7446 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -80,19 +80,16 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, FullFileName = FileName; if( ( FullFileName.IsEmpty() ) && !IsNew ) { - wxString mask = wxT( "*." ) + SchematicFileExtension; - FullFileName = EDA_FileSelector( _( "Schematic files:" ), - wxEmptyString, /* Chemin par defaut */ - wxEmptyString, /* nom fichier par defaut */ - SchematicFileExtension, /* extension par defaut */ - mask, /* Masque d'affichage */ - this, - wxFD_OPEN, - TRUE - ); - if( FullFileName.IsEmpty() ) + wxFileDialog dlg( this, _( "Open Schematic" ), wxEmptyString, + wxEmptyString, SchematicFileWildcard, + wxFD_OPEN | wxFD_FILE_MUST_EXIST ); + + if( dlg.ShowModal() == wxID_CANCEL ) return 0; + + FullFileName = dlg.GetPath(); } + if( g_RootSheet ) { SAFE_DELETE( g_RootSheet ); @@ -175,12 +172,13 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, LibCacheExist = TRUE; } - if( !wxFileExists( g_RootSheet->m_AssociatedScreen->m_FileName ) && !LibCacheExist ) // Nouveau projet prpbablement + if( !wxFileExists( g_RootSheet->m_AssociatedScreen->m_FileName ) + && !LibCacheExist ) { Zoom_Automatique( FALSE ); msg.Printf( _( "File <%s> not found." ), g_RootSheet->m_AssociatedScreen->m_FileName.GetData() ); - DisplayInfo( this, msg, 20 ); + DisplayInfo( this, msg, 0 ); return -1; } diff --git a/include/gestfich.h b/include/gestfich.h index 837bf02c43..30ae08b5b3 100644 --- a/include/gestfich.h +++ b/include/gestfich.h @@ -80,14 +80,6 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param = wxEmptyString ); void AddDelimiterString( wxString& string ); -void SetRealLibraryPath( const wxString& shortlibname ); /* met a jour - * le chemin des librairies RealLibDirBuffer (global) - * a partir de UserLibDirBuffer (global): - * Si UserLibDirBuffer non vide RealLibDirBuffer = UserLibDirBuffer. - * Sinon si variable d'environnement KICAD definie (KICAD = chemin pour kicad), - * UserLibDirBuffer = /shortlibname; - * Sinon UserLibDirBuffer = ../shortlibname/ - */ wxString FindKicadHelpPath(); /* Find absolute path for kicad/help (or kicad/help/) */ diff --git a/include/gr_basic.h b/include/gr_basic.h index 2f35b9d8d1..9ade97e319 100644 --- a/include/gr_basic.h +++ b/include/gr_basic.h @@ -5,10 +5,6 @@ #ifndef GR_BASIC #define GR_BASIC -#ifndef COMMON_GLOBL -#define COMMON_GLOBL extern -#endif - #include "colors.h" diff --git a/include/param_config.h b/include/param_config.h index 93e0a31f53..cd4e19fc20 100644 --- a/include/param_config.h +++ b/include/param_config.h @@ -8,10 +8,7 @@ #include "wx/confbase.h" #include "wx/fileconf.h" - -#ifndef COMMON_GLOBL -# define COMMON_GLOBL extern -#endif +#include /* definifition des types de parametre des files de configuration */ @@ -40,7 +37,6 @@ public: public: PARAM_CFG_BASE( const wxChar* ident, const paramcfg_id type, const wxChar* group = NULL ); - ~PARAM_CFG_BASE() { }; /** ReadParam * read the value of parameter thi stored in aConfig @@ -209,5 +205,6 @@ public: virtual void SaveParam( wxConfigBase* aConfig ); }; +WX_DECLARE_OBJARRAY( PARAM_CFG_BASE, PARAM_CFG_ARRAY ); #endif /* __PARAM_CONFIG_H__ */ diff --git a/kicad/prjconfig.cpp b/kicad/prjconfig.cpp index 2c00fa8cce..766f4382b7 100644 --- a/kicad/prjconfig.cpp +++ b/kicad/prjconfig.cpp @@ -25,23 +25,20 @@ static const wxString BoardFileNameEntry( wxT( "BoardNm" ) ); void WinEDA_MainFrame::CreateNewProject( const wxString PrjFullFileName ) { - wxFileName fn; + wxString tmp; wxFileName newProjectName = PrjFullFileName; // Init default config filename - fn.SetPath( ReturnKicadDatasPath() ); - fn.AppendDir( wxT( "template" ) ); - fn.SetName( wxT( "kicad" ) ); - fn.SetExt( ProjectFileExtension ); + tmp = wxGetApp().GetLibraryPathList().FindValidPath( wxT( "kicad.pro" ) ); - if( !fn.FileExists() ) + if( !wxFileName::FileExists( tmp ) ) { - DisplayInfo( NULL, _( "Template file not found " ) + fn.GetFullPath() ); + DisplayInfo( NULL, _( "Project template file not found " ) ); return; } else { - wxCopyFile( fn.GetFullPath(), PrjFullFileName ); + wxCopyFile( tmp, PrjFullFileName ); } m_SchematicRootFileName = wxFileName( newProjectName.GetName(),