diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ef1bfb0627..e4901c6605 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,23 @@ KiCad ChangeLog 2009 Please add newer entries at the top, list the date and your name with email address. +2009-apr-12 UPDATE Jean-Pierre Charras +================================================================================ +++eeschema: + Default libraries path are now differents for pcbnew and eeschema (as it do) + Fixed: bad library search path for schematic component docs (docs were not found) + Added: display actual lib paths in eeschema lib config dialog. + + These next fix give the same behavior than "old" version + Use relative paths in libraries and doc filenames when possible + i.e when a file is found in a sub path in a default path + (very important for Windows/linux/mac compatibility of projects and their configs) + + TODO: allows user to add paths in list. Currently the user path for lib is broken + (but the new code could allow the user to add more than one user path) + + TODO: do the same for pcbnew and cvpcb + 2009-apr-10 UPDATE Jean-Pierre Charras ================================================================================ ++eeschema: diff --git a/common/eda_doc.cpp b/common/eda_doc.cpp index a8c556fed4..23b44d4cf6 100644 --- a/common/eda_doc.cpp +++ b/common/eda_doc.cpp @@ -78,13 +78,13 @@ static const wxFileTypeInfo EDAfallbacks[] = * @param aDocName = filename of file to open (Full filename or short filename) * @param aPaths = a wxPathList to explore. * if NULL or aDocName is a full filename, aPath is not used. -*/ -bool GetAssociatedDocument( wxFrame* aFrame, +*/ +bool GetAssociatedDocument( wxFrame* aFrame, const wxString& aDocName, const wxPathList* aPaths) { - wxString fullfilename, file_ext; + wxString docname, fullfilename, file_ext; wxString msg; wxString command; bool success = FALSE; @@ -101,6 +101,14 @@ bool GetAssociatedDocument( wxFrame* aFrame, } } + docname = aDocName; + #ifdef __WINDOWS__ + docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP ); +#else + docname.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); +#endif + + /* Compute the full file name */ if( wxIsAbsolutePath( aDocName ) || aPaths == NULL) fullfilename = aDocName; @@ -109,12 +117,6 @@ bool GetAssociatedDocument( wxFrame* aFrame, fullfilename = aPaths->FindValidPath( aDocName ); } -#ifdef __WINDOWS__ - fullfilename.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP ); -#else - fullfilename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); -#endif - wxString mask( wxT( "*" ) ), extension; #ifdef __WINDOWS__ diff --git a/common/edaappl.cpp b/common/edaappl.cpp index a557338fc8..31e507c9a9 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -258,14 +258,20 @@ WinEDA_App::~WinEDA_App() } -/** - * TODO brief +/** Function InitEDA_Appl + * initialise some general parameters + * - Default paths (help, libs, bin)and configuration flies names + * - Language and locale + * - fonts + * @param aName : used as paths in configuration files + * @param aId = flag : APP_TYPE_EESCHEMA, APP_TYPE_PCBNEW.. + * used to choose what default library path must be used */ -void WinEDA_App::InitEDA_Appl( const wxString& name ) +void WinEDA_App::InitEDA_Appl( const wxString& aName, id_app_type aId ) { wxString EnvLang; - - m_Checker = new wxSingleInstanceChecker( name.Lower() + wxT( "-" ) + + m_Id = aId; + m_Checker = new wxSingleInstanceChecker( aName.Lower() + wxT( "-" ) + wxGetUserId() ); /* Init kicad environment @@ -283,17 +289,17 @@ void WinEDA_App::InitEDA_Appl( const wxString& name ) /* Prepare On Line Help. Use only lower case for help filenames, in order to * avoid problems with upper/lower case filenames under windows and unix */ #if defined ONLINE_HELP_FILES_FORMAT_IS_HTML - m_HelpFileName = name.Lower() + wxT( ".html" ); + m_HelpFileName = aName.Lower() + wxT( ".html" ); #elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF - m_HelpFileName = name.Lower() + wxT( ".pdf" ); + m_HelpFileName = aName.Lower() + wxT( ".pdf" ); #else #error Help files format not defined #endif /* Init parameters for configuration */ SetVendorName( wxT( "kicad" ) ); - SetAppName( name.Lower() ); - SetTitle( name ); + SetAppName( aName.Lower() ); + SetTitle( aName ); m_EDA_Config = new wxConfig( ); wxASSERT( m_EDA_Config != NULL ); m_EDA_CommonConfig = new wxConfig( CommonConfigPath ); @@ -320,7 +326,7 @@ void WinEDA_App::InitEDA_Appl( const wxString& name ) g_FixedFont = new wxFont( g_FixedFontPointSize, wxFONTFAMILY_MODERN, wxNORMAL, wxNORMAL ); - /* TODO installation des gestionnaires de visu d'images (pour help) TODO*/ + /* Install some image handlers, mainly for help */ wxImage::AddHandler( new wxPNGHandler ); wxImage::AddHandler( new wxGIFHandler ); wxImage::AddHandler( new wxJPEGHandler ); @@ -478,6 +484,8 @@ void WinEDA_App::SetDefaultSearchPaths( void ) size_t i; wxString path = m_BinDir; + m_searchPaths.Clear(); + #ifdef __WINDOWS__ /* m_BinDir path is in unix notation. * But wxFileName expect (to work fine) native notation @@ -528,31 +536,34 @@ void WinEDA_App::SetDefaultSearchPaths( void ) } else { - /* Add schematic library file path to search path list. */ fn.Clear(); fn.SetPath( m_searchPaths[i] ); - fn.AppendDir( wxT( "library") ); - - if( fn.IsDirReadable() ) + /* Add schematic library file path to search path list. + * we must add /library and /library/doc + */ + if ( m_Id == APP_TYPE_EESCHEMA ) { - wxLogDebug( wxT( "Adding <%s> to library search path list" ), - fn.GetPath().c_str() ); - m_libSearchPaths.Add( fn.GetPath() ); - } + fn.AppendDir( wxT( "library") ); + if( fn.IsDirReadable() ) + { + wxLogDebug( wxT( "Adding <%s> to library search path list" ), + fn.GetPath().c_str() ); + m_libSearchPaths.Add( fn.GetPath() ); + } - /* Add schematic doc file path (library/doc)to search path list. */ - fn.RemoveLastDir(); - fn.AppendDir( wxT( "doc") ); - - if( fn.IsDirReadable() ) - { - wxLogDebug( wxT( "Adding <%s> to library search path list" ), - fn.GetPath().c_str() ); - m_libSearchPaths.Add( fn.GetPath() ); + /* Add schematic doc file path (library/doc)to search path list. */ + fn.AppendDir( wxT( "doc") ); + if( fn.IsDirReadable() ) + { + wxLogDebug( wxT( "Adding <%s> to library search path list" ), + fn.GetPath().c_str() ); + m_libSearchPaths.Add( fn.GetPath() ); + } + fn.RemoveLastDir(); + fn.RemoveLastDir(); // point to } /* Add kicad template file path to search path list. */ - fn.RemoveLastDir(); fn.AppendDir( wxT( "template" ) ); if( fn.IsDirReadable() ) @@ -561,26 +572,29 @@ void WinEDA_App::SetDefaultSearchPaths( void ) fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } + fn.RemoveLastDir(); /* Add PCB library file path to search path list. */ - fn.RemoveLastDir(); - fn.AppendDir( wxT( "modules" ) ); - - if( fn.IsDirReadable() ) + if ( (m_Id == APP_TYPE_PCBNEW) || (m_Id == APP_TYPE_CVPCB) ) { - wxLogDebug( wxT( "Adding <%s> to library search path list" ), - fn.GetPath().c_str() ); - m_libSearchPaths.Add( fn.GetPath() ); - } + fn.AppendDir( wxT( "modules" ) ); - /* Add 3D module library file path to search path list. */ - fn.AppendDir( wxT( "packages3d" ) ); + if( fn.IsDirReadable() ) + { + wxLogDebug( wxT( "Adding <%s> to library search path list" ), + fn.GetPath().c_str() ); + m_libSearchPaths.Add( fn.GetPath() ); + } - if( fn.IsDirReadable() ) - { - wxLogDebug( wxT( "Adding <%s> to library search path list" ), - 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() ) + { + wxLogDebug( wxT( "Adding <%s> to library search path list" ), + fn.GetPath().c_str() ); + m_libSearchPaths.Add( fn.GetPath() ); + } } } } diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index a0ebbf8c7f..9839e75704 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -4,6 +4,7 @@ #include "fctsys.h" #include "appl_wxstruct.h" +#include "wxstruct.h" #include "common.h" #include "confirm.h" #include "gestfich.h" @@ -64,7 +65,7 @@ bool WinEDA_App::OnInit() wxString currCWD = wxGetCwd(); WinEDA_CvpcbFrame* frame = NULL; - InitEDA_Appl( wxT( "CVpcb" ) ); + InitEDA_Appl( wxT( "CVpcb" ), APP_TYPE_CVPCB ); if( m_Checker && m_Checker->IsAnotherRunning() ) { diff --git a/eeschema/dialog_eeschema_config.cpp b/eeschema/dialog_eeschema_config.cpp index 76a1f3176f..a085ca44a2 100644 --- a/eeschema/dialog_eeschema_config.cpp +++ b/eeschema/dialog_eeschema_config.cpp @@ -54,9 +54,9 @@ public: void WinEDA_SchematicFrame::InstallConfigFrame( const wxPoint& pos ) /******************************************************************/ { - DIALOG_EESCHEMA_CONFIG* CfgFrame = new DIALOG_EESCHEMA_CONFIG( this ); + DIALOG_EESCHEMA_CONFIG CfgFrame( this ); - CfgFrame->ShowModal(); CfgFrame->Destroy(); + CfgFrame.ShowModal(); } @@ -126,6 +126,13 @@ void DIALOG_EESCHEMA_CONFIG::Init() m_ListLibr->InsertItems( g_LibName_List, 0 ); m_LibDirCtrl->SetValue( g_UserLibDirBuffer ); + + // Display actual libraries paths: + wxPathList libpaths = wxGetApp().GetLibraryPathList(); + for( unsigned ii = 0; ii < libpaths.GetCount(); ii++ ) + { + m_DefaultLibraryPathslistBox->Append( libpaths[ii]); + } } @@ -148,6 +155,7 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event ) if ( g_UserLibDirBuffer != m_LibDirCtrl->GetValue() ) { g_UserLibDirBuffer = m_LibDirCtrl->GetValue(); + wxGetApp().SetDefaultSearchPaths( ); m_LibListChanged = true; } @@ -206,7 +214,7 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) */ { int ii; - wxString tmp; + wxString libfilename; wxFileName fn; ii = m_ListLibr->GetSelection(); @@ -233,24 +241,38 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) /* If the library path is already in the library search paths * list, just add the library name to the list. Otherwise, add - * the library name with the full path. */ - if( wxGetApp().GetLibraryPathList().Index( fn.GetPath() ) == wxNOT_FOUND ) - tmp = fn.GetPathWithSep() + fn.GetName(); - else - tmp = fn.GetName(); + * the library name with the full or relative path. + * the relative path, when possible is preferable, + * because it preserve use of default libraries paths, when the path is a sub path of these default paths + * + */ + if( wxGetApp().GetLibraryPathList().Index( fn.GetPath() ) != wxNOT_FOUND ) // Ok, trivial case + libfilename = fn.GetName(); + else // not in the default, : see if this file is in a subpath: + { + libfilename = fn.GetPathWithSep() + fn.GetName(); + for ( unsigned kk = 0; kk < wxGetApp().GetLibraryPathList().GetCount(); kk ++ ) + { + if( fn.MakeRelativeTo(wxGetApp().GetLibraryPathList()[kk] ) ) + { + libfilename = fn.GetPathWithSep() + fn.GetName(); + break; + } + } + } //Add or insert new library name, if not already in list - if( m_ListLibr->FindString( tmp, fn.IsCaseSensitive() ) == wxNOT_FOUND ) + if( m_ListLibr->FindString( libfilename, fn.IsCaseSensitive() ) == wxNOT_FOUND ) { m_LibListChanged = TRUE; if( event.GetId() == ID_ADD_LIB ) - m_ListLibr->Append( tmp ); + m_ListLibr->Append( libfilename ); else - m_ListLibr->Insert( tmp, ii++ ); + m_ListLibr->Insert( libfilename, ii++ ); } else { - wxString msg = wxT( "<" ) + tmp + wxT( "> : " ) + + wxString msg = wxT( "<" ) + libfilename + wxT( "> : " ) + _( "Library already in use" ); DisplayError( this, msg ); } diff --git a/eeschema/dialog_eeschema_config_fbp.cpp b/eeschema/dialog_eeschema_config_fbp.cpp index 8a72ebf016..ee27395872 100644 --- a/eeschema/dialog_eeschema_config_fbp.cpp +++ b/eeschema/dialog_eeschema_config_fbp.cpp @@ -124,15 +124,29 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind bMainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); wxStaticBoxSizer* sbLibPathSizer; - sbLibPathSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Default library file path:") ), wxHORIZONTAL ); + sbLibPathSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Libraries Files Main Default Path:") ), wxVERTICAL ); + + wxBoxSizer* bUserLibPathSizer; + bUserLibPathSizer = new wxBoxSizer( wxHORIZONTAL ); m_LibDirCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); m_LibDirCtrl->SetToolTip( _("Default path to search libraries which have no absolute path in name,\nor a name which does not start by ./ or ../\nIf void, the default path is kicad/share/library") ); - sbLibPathSizer->Add( m_LibDirCtrl, 1, wxALL, 5 ); + bUserLibPathSizer->Add( m_LibDirCtrl, 1, wxALL, 5 ); m_buttonBrowse = new wxButton( this, ID_LIB_PATH_SEL, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 ); - sbLibPathSizer->Add( m_buttonBrowse, 0, wxALL, 5 ); + bUserLibPathSizer->Add( m_buttonBrowse, 0, wxALL, 5 ); + + sbLibPathSizer->Add( bUserLibPathSizer, 1, wxEXPAND, 5 ); + + m_staticTextcurrenpaths = new wxStaticText( this, wxID_ANY, _("Current Libraries Full Paths in Use:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextcurrenpaths->Wrap( -1 ); + sbLibPathSizer->Add( m_staticTextcurrenpaths, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + + m_DefaultLibraryPathslistBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_NEEDED_SB ); + m_DefaultLibraryPathslistBox->SetMinSize( wxSize( -1,70 ) ); + + sbLibPathSizer->Add( m_DefaultLibraryPathslistBox, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); bMainSizer->Add( sbLibPathSizer, 0, wxEXPAND, 5 ); diff --git a/eeschema/dialog_eeschema_config_fbp.fbp b/eeschema/dialog_eeschema_config_fbp.fbp index 4c32f09361..f76d66fc4e 100644 --- a/eeschema/dialog_eeschema_config_fbp.fbp +++ b/eeschema/dialog_eeschema_config_fbp.fbp @@ -32,7 +32,7 @@ DIALOG_EESCHEMA_CONFIG_FBP - 593,400 + 593,445 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER @@ -995,17 +995,135 @@ 0 wxID_ANY - Default library file path: + Libraries Files Main Default Path: sbLibPathSizer - wxHORIZONTAL + wxVERTICAL none 5 - wxALL + wxEXPAND 1 - + + + bUserLibPathSizer + wxHORIZONTAL + none + + 5 + wxALL + 1 + + + + 1 + + + 0 + wxID_ANY + + 0 + + m_LibDirCtrl + protected + + + + + Default path to search libraries which have no absolute path in name, or a name which does not start by ./ or ../ If void, the default path is kicad/share/library + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL + 0 + + + + 0 + 1 + + + 0 + ID_LIB_PATH_SEL + Browse + + + m_buttonBrowse + protected + + + + + + + + + OnLibPathSelClick + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxTOP|wxRIGHT|wxLEFT + 0 + 1 @@ -1013,20 +1131,20 @@ 0 wxID_ANY + Current Libraries Full Paths in Use: - 0 - m_LibDirCtrl + m_staticTextcurrenpaths protected - Default path to search libraries which have no absolute path in name, or a name which does not start by ./ or ../ If void, the default path is kicad/share/library - + + -1 @@ -1049,40 +1167,34 @@ - - - - 5 - wxALL + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 0 - + + - 0 1 0 - ID_LIB_PATH_SEL - Browse + wxID_ANY - - m_buttonBrowse + -1,70 + m_DefaultLibraryPathslistBox protected - + wxLB_NEEDED_SB - OnLibPathSelClick @@ -1093,6 +1205,8 @@ + + diff --git a/eeschema/dialog_eeschema_config_fbp.h b/eeschema/dialog_eeschema_config_fbp.h index d0b99cf69d..83d81dbf9a 100644 --- a/eeschema/dialog_eeschema_config_fbp.h +++ b/eeschema/dialog_eeschema_config_fbp.h @@ -62,6 +62,8 @@ class DIALOG_EESCHEMA_CONFIG_FBP : public wxDialog wxStaticLine* m_staticline1; wxTextCtrl* m_LibDirCtrl; wxButton* m_buttonBrowse; + wxStaticText* m_staticTextcurrenpaths; + wxListBox* m_DefaultLibraryPathslistBox; // Virtual event handlers, overide them in your derived class virtual void OnCloseWindow( wxCloseEvent& event ){ event.Skip(); } @@ -74,7 +76,7 @@ class DIALOG_EESCHEMA_CONFIG_FBP : public wxDialog public: - DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 593,400 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 593,445 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_EESCHEMA_CONFIG_FBP(); }; diff --git a/eeschema/edit_component_in_lib.cpp b/eeschema/edit_component_in_lib.cpp index f61e80db2e..558a72cb10 100644 --- a/eeschema/edit_component_in_lib.cpp +++ b/eeschema/edit_component_in_lib.cpp @@ -4,6 +4,7 @@ #include "fctsys.h" #include "gr_basic.h" +#include "appl_wxstruct.h" #include "common.h" #include "confirm.h" #include "gestfich.h" @@ -198,7 +199,7 @@ void WinEDA_PartPropertiesFrame::BuildPanelFootprintFilter() PanelFpFilterBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); wxButton* Button = new wxButton( m_PanelFootprintFilter, - ID_ADD_FOOTPRINT_FILTER, _( + ID_ADD_FOOTPRINT_FILTER, _( "Add" ) ); Button->SetForegroundColour( *wxBLUE ); @@ -380,8 +381,8 @@ void WinEDA_PartPropertiesFrame::PartPropertiesAccept( wxCommandEvent& event ) } else { - CurrentLibEntry->m_AliasList[m_AliasLocation + ALIAS_DOC] = m_Doc->GetValue(); - CurrentLibEntry->m_AliasList[m_AliasLocation + ALIAS_KEYWORD] = m_Keywords->GetValue(); + CurrentLibEntry->m_AliasList[m_AliasLocation + ALIAS_DOC] = m_Doc->GetValue(); + CurrentLibEntry->m_AliasList[m_AliasLocation + ALIAS_KEYWORD] = m_Keywords->GetValue(); CurrentLibEntry->m_AliasList[m_AliasLocation + ALIAS_DOC_FILENAME] = m_Docfile->GetValue(); } @@ -391,7 +392,8 @@ void WinEDA_PartPropertiesFrame::PartPropertiesAccept( wxCommandEvent& event ) for( ii = 0; ii < jj; ii++ ) { if( LocateAlias( CurrentLibEntry->m_AliasList, m_PartAliasList->GetString( ii ) ) < 0 ) - { // new alias must be created + { + // new alias must be created CurrentLibEntry->m_AliasList.Add( m_PartAliasList->GetString( ii ) ); CurrentLibEntry->m_AliasList.Add( wxEmptyString ); // Add a void doc string CurrentLibEntry->m_AliasList.Add( wxEmptyString ); // Add a void keyword list string @@ -528,7 +530,7 @@ void WinEDA_PartPropertiesFrame::AddAliasOfPart( wxCommandEvent& WXUNUSED (event if( CurrentLibEntry == NULL ) return; - if( Get_Message( _( "New alias:" ), _("Component Alias"), Line, this ) != 0 ) + if( Get_Message( _( "New alias:" ), _( "Component Alias" ), Line, this ) != 0 ) return; Line.Replace( wxT( " " ), wxT( "_" ) ); @@ -706,7 +708,7 @@ bool WinEDA_PartPropertiesFrame::SetUnsetConvert() NextDrawItem = CopyDrawEntryStruct( this, DrawItem ); NextDrawItem->SetNext( CurrentLibEntry->m_Drawings ); CurrentLibEntry->m_Drawings = NextDrawItem; - NextDrawItem->m_Convert = 2; + NextDrawItem->m_Convert = 2; } } } @@ -756,7 +758,7 @@ void WinEDA_PartPropertiesFrame::BrowseAndSelectDocFile( wxCommandEvent& event ) docpath += wxT( "doc" ); docpath += STRING_DIR_SEP; - mask = wxT( "*" ); + mask = wxT( "*" ); FullFileName = EDA_FileSelector( _( "Doc Files" ), docpath, /* Chemin par defaut */ wxEmptyString, /* nom fichier par defaut */ @@ -770,7 +772,35 @@ void WinEDA_PartPropertiesFrame::BrowseAndSelectDocFile( wxCommandEvent& event ) return; // Suppression du chemin par defaut pour le fichier de doc: - filename = MakeReducedFileName( FullFileName, docpath, wxEmptyString ); + + /* If the library path is already in the library search paths + * list, just add the library name to the list. Otherwise, add + * the library name with the full or relative path. + * the relative path, when possible is preferable, + * because it preserve use of default libraries paths, when the path is a sub path of these default paths + * + */ + wxFileName fn = FullFileName; + int pathlen = -1; // path len, used to find the better subpath within defualts paths + if( wxGetApp().GetLibraryPathList().Index( fn.GetPath() ) != wxNOT_FOUND ) // Ok, trivial case + filename = fn.GetName(); + else // not in the default, : see if this file is in a subpath: + { + filename = fn.GetPathWithSep() + fn.GetName(); + for( unsigned kk = 0; kk < wxGetApp().GetLibraryPathList().GetCount(); kk++ ) + { + if( fn.MakeRelativeTo( wxGetApp().GetLibraryPathList()[kk] ) ) + { + if( pathlen < 0 // a subpath is found + || pathlen > (int) fn.GetPath().Len() ) // a better subpath if found + { + filename = fn.GetPathWithSep() + fn.GetName(); + pathlen = fn.GetPath().Len(); + } + fn = FullFileName; //Try to find a better subpath + } + } + } m_Docfile->SetValue( filename ); } @@ -802,7 +832,7 @@ void WinEDA_PartPropertiesFrame::AddFootprintFilter( wxCommandEvent& WXUNUSED (e if( CurrentLibEntry == NULL ) return; - if( Get_Message( _( "New FootprintFilter:" ), _("Footprint Filter"), Line, this ) != 0 ) + if( Get_Message( _( "New FootprintFilter:" ), _( "Footprint Filter" ), Line, this ) != 0 ) return; Line.Replace( wxT( " " ), wxT( "_" ) ); diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index a4e809ee59..c8bbaca441 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -148,7 +148,7 @@ bool WinEDA_App::OnInit() g_DebugLevel = 0; // Debug level */ - InitEDA_Appl( wxT( "EESchema" ) ); + InitEDA_Appl( wxT( "EESchema" ), APP_TYPE_EESCHEMA ); if( m_Checker && m_Checker->IsAnotherRunning() ) { diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index e15829cca0..9628dc5214 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -39,7 +39,7 @@ bool WinEDA_App::OnInit() wxFileName fn; WinEDA_GerberFrame* frame = NULL; - InitEDA_Appl( wxT( "GerbView" ) ); + InitEDA_Appl( wxT( "GerbView" ), APP_TYPE_GERBVIEW ); ScreenPcb = new PCB_SCREEN(); ScreenPcb->m_CurrentSheetDesc = &g_Sheet_GERBER; diff --git a/include/appl_wxstruct.h b/include/appl_wxstruct.h index e7f66eef8f..6ac16a57bf 100644 --- a/include/appl_wxstruct.h +++ b/include/appl_wxstruct.h @@ -15,6 +15,14 @@ #include #include +enum id_app_type { + APP_TYPE_UNKOWN, + APP_TYPE_EESCHEMA, + APP_TYPE_PCBNEW, + APP_TYPE_CVPCB, + APP_TYPE_GERBVIEW, + APP_TYPE_KICAD, +}; class wxConfigBase; class wxFileConfig; @@ -30,6 +38,9 @@ class wxHtmlHelpController; class WinEDA_App : public wxApp { public: + id_app_type m_Id; /* Used mainly to handle default paths libs + * m_Id = APP_TYPE_EESCHEMA, APP_TYPE_PCBNEW ... + */ wxString m_Project; wxSingleInstanceChecker* m_Checker; @@ -50,30 +61,41 @@ public: * variable d'environnement KICAD, * typiquement /usr/local/kicad ou * c:\kicad */ - bool m_Env_Defined; // TRUE si variable d'environnement KICAD definie + bool m_Env_Defined; // TRUE si variable d'environnement KICAD definie - wxLocale* m_Locale; // Gestion de la localisation - int m_LanguageId; // indicateur de choix du langage ( 0 = defaut) - wxString m_PdfBrowser; // Name of the selected browser, for browsing pdf datasheets - bool m_PdfBrowserIsDefault; // True if the pdf browser is the default (m_PdfBrowser not used) - wxPathList m_searchPaths; - wxFileHistory m_fileHistory; + wxLocale* m_Locale; // Gestion de la localisation + int m_LanguageId; // indicateur de choix du langage ( 0 = defaut) + wxString m_PdfBrowser; // Name of the selected browser, for browsing pdf datasheets + bool m_PdfBrowserIsDefault; // True if the pdf browser is the default (m_PdfBrowser not used) + wxPathList m_searchPaths; + wxFileHistory m_fileHistory; protected: - wxString m_Title; - wxPathList m_libSearchPaths; - wxFileName m_projectFileName; + wxString m_Title; + wxPathList m_libSearchPaths; + wxFileName m_projectFileName; public: WinEDA_App(); ~WinEDA_App(); - bool OnInit(); - int OnRun(); + bool OnInit(); + int OnRun(); - bool SetBinDir(); - void SetDefaultSearchPaths( void ); - void InitEDA_Appl( const wxString& name ); - bool SetLanguage( bool first_time = FALSE ); + bool SetBinDir(); + void SetDefaultSearchPaths( void ); + + /** Function InitEDA_Appl + * initialise some general parameters + * - Default paths (help, libs, bin)and configuration flies names + * - Language and locale + * - fonts + * @param aName : used as paths in configuration files + * @param aId = flag : LIBRARY_TYPE_EESCHEMA or LIBRARY_TYPE_PCBNEW + * used to choose what default library path must be used + */ + void InitEDA_Appl( const wxString& aName, id_app_type aId = APP_TYPE_UNKOWN); + + bool SetLanguage( bool first_time = FALSE ); /** Function AddMenuLanguageList * @@ -85,47 +107,48 @@ public: * * @return the sub menu Language list */ - void AddMenuLanguageList( wxMenu* MasterMenu ); - void SetLanguageIdentifier( int menu_id ); - void SetLanguagePath( void ); - void InitOnLineHelp(); + void AddMenuLanguageList( wxMenu* MasterMenu ); + void SetLanguageIdentifier( int menu_id ); + void SetLanguagePath( void ); + void InitOnLineHelp(); // Sauvegarde de configurations et options: - void GetSettings(); - void SaveSettings(); + void GetSettings(); + void SaveSettings(); + + void WriteProjectConfig( const wxString& local_config_filename, + const wxString& GroupName, + PARAM_CFG_BASE** List ); - void WriteProjectConfig( const wxString& local_config_filename, - const wxString& GroupName, - PARAM_CFG_BASE** List ); /** Function SaveCurrentSetupValues() * Save the current setup values in m_EDA_Config * saved parameters are parameters that have the .m_Setup member set to true * @param aList = array of PARAM_CFG_BASE pointers - */ - void SaveCurrentSetupValues( PARAM_CFG_BASE** aList ); + */ + void SaveCurrentSetupValues( PARAM_CFG_BASE** aList ); /** Function ReadCurrentSetupValues() * Raed the current setup values previously saved, from m_EDA_Config * saved parameters are parameters that have the .m_Setup member set to true * @param aList = array of PARAM_CFG_BASE pointers */ - void ReadCurrentSetupValues( PARAM_CFG_BASE** aList ); + void ReadCurrentSetupValues( PARAM_CFG_BASE** aList ); - bool ReadProjectConfig( const wxString& local_config_filename, - const wxString& GroupName, PARAM_CFG_BASE** List, - bool Load_Only_if_New ); - bool ReCreatePrjConfig( const wxString& local_config_filename, - const wxString& GroupName, - bool ForceUseLocalConfig ); + bool ReadProjectConfig( const wxString& local_config_filename, + const wxString& GroupName, PARAM_CFG_BASE** List, + bool Load_Only_if_New ); + bool ReCreatePrjConfig( const wxString& local_config_filename, + const wxString& GroupName, + bool ForceUseLocalConfig ); - void ReadPdfBrowserInfos(); - void WritePdfBrowserInfos(); + void ReadPdfBrowserInfos(); + void WritePdfBrowserInfos(); - wxString FindFileInSearchPaths( const wxString& filename, - const wxArrayString* subdirs = NULL ); + wxString FindFileInSearchPaths( const wxString& filename, + const wxArrayString* subdirs = NULL ); - wxString GetHelpFile( void ); - wxString GetLibraryFile( const wxString& filename ); + wxString GetHelpFile( void ); + wxString GetLibraryFile( const wxString& filename ); wxString& GetEditorName(); const wxString& GetTitle() { return m_Title; } @@ -133,10 +156,13 @@ public: wxPathList& GetLibraryPathList() { return m_libSearchPaths; } wxString FindLibraryPath( const wxString& fileName ); + wxString FindLibraryPath( const wxFileName& fileName ) { return FindLibraryPath( fileName.GetFullPath() ); } + + void RemoveLibraryPath( const wxString& path ); void InsertLibraryPath( const wxString& path, size_t index ); }; @@ -146,6 +172,6 @@ public: * of the application pointer all over the place or worse yet in a global * variable. */ -DECLARE_APP(WinEDA_App); +DECLARE_APP( WinEDA_App ); #endif /* APPL_WXSTRUCT_H */ diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 5b2744a39e..5d1db75266 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -369,7 +369,7 @@ bool WinEDA_App::OnInit() { WinEDA_MainFrame* frame; - InitEDA_Appl( wxT( "KiCad" ) ); + InitEDA_Appl( wxT( "KiCad" ), APP_TYPE_KICAD ); /* init kicad */ GetSettings(); // read current setup diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 37bf5c9f87..01b91d542a 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -96,7 +96,7 @@ bool WinEDA_App::OnInit() wxFileName fn; WinEDA_PcbFrame* frame = NULL; - InitEDA_Appl( wxT( "PCBnew" ) ); + InitEDA_Appl( wxT( "PCBnew" ), APP_TYPE_PCBNEW ); if( m_Checker && m_Checker->IsAnotherRunning() ) {