Commit 9ab7c18f authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Footprint library table ground work.

* Remove defined CMAKE_INSTALL_PREFIX for Windows from main CMakeList.txt.
* Move footprint library path detection code from pcbnew.cpp to EDA_APP
  object.
* Add CMAKE_INSTALL_PREFIX to config.h.cmake.
* Simplify and fix search path list code.
* Add CMAKE_INSTALL_PREFIX to the list of search paths in case KiCad was
  installed using `make install`.
* Add default global footprint library table to CMake install.
* Add method to set footprint library table to PCB_BASE_FRAME object.
* Remove unused function EDA_APP::GetLibraryFile().
* Minor FP_LIB_TABLE object improvements.
parent 36ae78ff
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -197,10 +197,14 @@ else()
    endif()
    endif()
endif()
endif()


#================================================
# Locations for install targets.
# Locations for install targets.
set( KICAD_BIN bin
set( KICAD_BIN bin
    CACHE PATH "Location of KiCad binaries." )
    CACHE PATH "Location of KiCad binaries." )


set( KICAD_FP_LIB_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}"
     CACHE PATH "Default path where footprint libraries are installed." )

if( UNIX )
if( UNIX )
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    set( KICAD_PLUGINS lib/kicad/plugins
    set( KICAD_PLUGINS lib/kicad/plugins
@@ -209,12 +213,10 @@ if( UNIX )
        CACHE PATH "Location of KiCad data files." )
        CACHE PATH "Location of KiCad data files." )
    set( KICAD_DOCS share/doc/kicad
    set( KICAD_DOCS share/doc/kicad
        CACHE PATH "Location of KiCad documentation files." )
        CACHE PATH "Location of KiCad documentation files." )
    set( KICAD_FP_LIB_INSTALL_PATH "${KICAD_FP_LIB_INSTALL_PATH}/share/kicad/modules" )
endif()
endif()


if( MINGW )
if( MINGW )
    # Like all variables, CMAKE_INSTALL_PREFIX can be over-ridden on the command line.
    set( CMAKE_INSTALL_PREFIX c:/kicad
        CACHE PATH "" )
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    set( KICAD_PLUGINS ${KICAD_BIN}/plugins
    set( KICAD_PLUGINS ${KICAD_BIN}/plugins
        CACHE PATH "Location of KiCad plugins." )
        CACHE PATH "Location of KiCad plugins." )
@@ -222,6 +224,7 @@ if( MINGW )
        CACHE PATH "Location of KiCad data files." )
        CACHE PATH "Location of KiCad data files." )
    set( KICAD_DOCS doc
    set( KICAD_DOCS doc
        CACHE PATH "Location of KiCad documentation files." )
        CACHE PATH "Location of KiCad documentation files." )
    set( KICAD_FP_LIB_INSTALL_PATH "${KICAD_FP_LIB_INSTALL_PATH}/modules" )
endif()
endif()


set( KICAD_DEMOS ${KICAD_DATA}/demos
set( KICAD_DEMOS ${KICAD_DATA}/demos
+6 −0
Original line number Original line Diff line number Diff line
@@ -81,6 +81,12 @@
/// Definition to compile with Pcbnew footprint library table implementation.
/// Definition to compile with Pcbnew footprint library table implementation.
#cmakedefine USE_FP_LIB_TABLE
#cmakedefine USE_FP_LIB_TABLE


/// The install prefix defined in CMAKE_INSTALL_PREFIX.
#define DEFAULT_INSTALL_PATH               "@CMAKE_INSTALL_PREFIX"

/// Default footprint library install path when installed with `make install`.
#define DEFAULT_FP_LIB_PATH                "@KICAD_FP_LIB_INSTALL_PATH@"

/// When defined, build the GITHUB_PLUGIN for pcbnew.
/// When defined, build the GITHUB_PLUGIN for pcbnew.
#cmakedefine BUILD_GITHUB_PLUGIN
#cmakedefine BUILD_GITHUB_PLUGIN


+76 −33
Original line number Original line Diff line number Diff line
@@ -64,18 +64,16 @@ static const wxChar* CommonConfigPath = wxT( "kicad_common" );
 * the size of the array. */
 * the size of the array. */
#define LANGUAGE_DESCR_COUNT ( sizeof( s_Language_List ) / sizeof( struct LANGUAGE_DESCR ) )
#define LANGUAGE_DESCR_COUNT ( sizeof( s_Language_List ) / sizeof( struct LANGUAGE_DESCR ) )


// Default font size
#define FONT_DEFAULT_SIZE 10    // Default font size.


// some key strings used to store parameters in config
// some key strings used to store parameters in config
static wxString backgroundColorKey( wxT( "BackgroundColor" ) );
static wxString backgroundColorKey( wxT( "BackgroundColor" ) );
static wxString showPageLimitsKey( wxT( "ShowPageLimits" ) );
static wxString showPageLimitsKey( wxT( "ShowPageLimits" ) );
static wxString workingDirKey( wxT( "WorkingDir" ) ) ;
static wxString workingDirKey( wxT( "WorkingDir" ) ) ;
static wxString languageCfgKey( wxT( "LanguageID" ) );
static wxString languageCfgKey( wxT( "LanguageID" ) );
static wxString kicadFpLibPath( wxT( "KicadFootprintLibraryPath" ) );




/**
/**
 * The real font size will be computed at run time
 *   A small class to handle the list on existing translations.
 *   A small class to handle the list on existing translations.
 *   the locale translation is automatic.
 *   the locale translation is automatic.
 *   the selection of languages is mainly for maintainer's convenience
 *   the selection of languages is mainly for maintainer's convenience
@@ -354,7 +352,7 @@ void EDA_APP::InitEDA_Appl( const wxString& aName, EDA_APP_T aId )
    wxImage::AddHandler( new wxJPEGHandler );
    wxImage::AddHandler( new wxJPEGHandler );
    wxFileSystem::AddHandler( new wxZipFSHandler );
    wxFileSystem::AddHandler( new wxZipFSHandler );


    // Analise the command line & init binary path
    // Analyze the command line & init binary path
    SetBinDir();
    SetBinDir();
    SetDefaultSearchPaths();
    SetDefaultSearchPaths();
    SetLanguagePath();
    SetLanguagePath();
@@ -496,24 +494,20 @@ void EDA_APP::SetDefaultSearchPaths( void )
     * if the user is savvy enough to set an environment variable they know
     * if the user is savvy enough to set an environment variable they know
     * what they are doing. */
     * what they are doing. */
    if( ::wxGetEnv( wxT( "KICAD" ), NULL ) )
    if( ::wxGetEnv( wxT( "KICAD" ), NULL ) )
        m_searchPaths.AddEnvList( wxT( "KICAD" ) );
        tmp.AddEnvList( wxT( "KICAD" ) );


    // Add the user's home path.
    // Add the user's home path.
    m_searchPaths.Add( GetTraits()->GetStandardPaths().GetUserDataDir() );
    tmp.Add( GetTraits()->GetStandardPaths().GetUserDataDir() );


    // Standard application data path if it is different from the binary path.
    // Standard application data path if it is different from the binary path.
    if( fn.GetPath() != GetTraits()->GetStandardPaths().GetDataDir() )
    if( fn.GetPath() != GetTraits()->GetStandardPaths().GetDataDir() )
    {
    {
        m_searchPaths.Add( GetTraits()->GetStandardPaths().GetDataDir() );
        tmp.Add( GetTraits()->GetStandardPaths().GetDataDir() );
    }
    }


    // Up one level relative to binary path with "share" appended for Windows.
    // Up one level relative to binary path with "share" appended for Windows.
    fn.RemoveLastDir();
    fn.RemoveLastDir();
    m_searchPaths.Add( fn.GetPath() );
    tmp.Add( fn.GetPath() );
    fn.AppendDir( wxT( "share" ) );
    m_searchPaths.Add( fn.GetPath() );
    fn.AppendDir( wxT( "kicad" ) );
    m_searchPaths.Add( fn.GetPath() );


    /* The normal OS program file install paths allow for binary to be
    /* The normal OS program file install paths allow for binary to be
     * installed in a different path from the library files.  This is
     * installed in a different path from the library files.  This is
@@ -524,13 +518,16 @@ void EDA_APP::SetDefaultSearchPaths( void )
#ifdef __WXMSW__
#ifdef __WXMSW__
    tmp.AddEnvList( wxT( "PROGRAMFILES" ) );
    tmp.AddEnvList( wxT( "PROGRAMFILES" ) );
#elif __WXMAC__
#elif __WXMAC__
    m_searchPaths.Add( wxT( "/Library/Application Support/kicad" ) );
    tmp.Add( wxT( "/Library/Application Support" ) );
    m_searchPaths.Add( wxString( wxGetenv( wxT( "HOME" ) ) ) +
    tmp.Add( wxString( wxGetenv( wxT( "HOME" ) ) ) + wxT( "/Library/Application Support" ) );
                       wxT("/Library/Application Support/kicad") );
#else
#else
    tmp.AddEnvList( wxT( "PATH" ) );
    tmp.AddEnvList( wxT( "PATH" ) );
#endif
#endif


    // This is the equivalent of CMAKE_INSTALL_PREFIX.  Useful when installed by `make install`.
    tmp.Add( wxT( DEFAULT_INSTALL_PATH ) );

    // Add kicad, kicad/share, share, and share/kicad to each possible base path.
    for( i = 0; i < tmp.GetCount(); i++ )
    for( i = 0; i < tmp.GetCount(); i++ )
    {
    {
        fn = wxFileName( tmp[i], wxEmptyString );
        fn = wxFileName( tmp[i], wxEmptyString );
@@ -621,6 +618,13 @@ void EDA_APP::SetDefaultSearchPaths( void )
            fn.RemoveLastDir();
            fn.RemoveLastDir();
        }
        }
    }
    }

#if 1 && defined( DEBUG )
    wxLogDebug( wxT( "Library search paths:" ) );

    for( unsigned i = 0;  i < m_libSearchPaths.GetCount();  i++ )
        wxLogDebug( wxT( "    %s" ), GetChars( m_libSearchPaths[i] ) );
#endif
}
}




@@ -662,11 +666,14 @@ void EDA_APP::GetSettings( bool aReopenLastUsedDirectory )
    }
    }


    // FIXME OSX Mountain Lion (10.8)
    // FIXME OSX Mountain Lion (10.8)
    // Seems that Read doesn't found anything and ColorFromInt Asserts - I'm unable to reproduce on 10.7
    // Seems that Read doesn't found anything and ColorFromInt Asserts - I'm unable to reproduce
    // In general terms i think is better have a failsafe default than an uninit variable
    // on 10.7
    // In general terms I think is better have a failsafe default than an uninit variable
    int draw_bg_color = (int)BLACK;      // Default for all apps but Eeschema
    int draw_bg_color = (int)BLACK;      // Default for all apps but Eeschema

    if( m_Id == APP_EESCHEMA_T )
    if( m_Id == APP_EESCHEMA_T )
        draw_bg_color = (int)WHITE;      // Default for Eeschema
        draw_bg_color = (int)WHITE;      // Default for Eeschema

    m_settings->Read( backgroundColorKey, &draw_bg_color );
    m_settings->Read( backgroundColorKey, &draw_bg_color );
    g_DrawBgColor = ColorFromInt( draw_bg_color );
    g_DrawBgColor = ColorFromInt( draw_bg_color );


@@ -979,21 +986,6 @@ wxString EDA_APP::GetHelpFile( void )
}
}




wxString EDA_APP::GetLibraryFile( const wxString& filename )
{
    wxArrayString subdirs;

    subdirs.Add( wxT( "share" ) );
#ifndef __WXMSW__

    /* Up on level relative to binary path with "share/kicad" appended for
     * all other platforms. */
    subdirs.Add( wxT( "kicad" ) );
#endif
    return FindFileInSearchPaths( filename, &subdirs );
}


wxString EDA_APP::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch )
wxString EDA_APP::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch )
{
{
    if( !m_LastVisitedLibPath.IsEmpty() )
    if( !m_LastVisitedLibPath.IsEmpty() )
@@ -1164,3 +1156,54 @@ bool EDA_APP::LockFile( const wxString& fileName )


    return true;
    return true;
}
}


bool EDA_APP::SetFootprintLibTablePath()
{
    wxString path;

    // Set the KISYSMOD environment variable for the current process if it is not already
    // defined in the user's environment.  This is required to expand the global footprint
    // library table paths.
    if( wxGetEnv( wxT( "KISYSMOD" ), &path ) && wxFileName::DirExists( path ) )
        return true;

    // Set the KISYSMOD environment variable to the path defined in the user's configuration
    // if it is defined and the path exists.
    if( m_commonSettings->Read( kicadFpLibPath, &path ) && wxFileName::DirExists( path ) )
    {
        wxSetEnv( wxT( "KISYSMOD" ), path );
        wxLogDebug( wxT( "Setting $KISYSMOD=\"%s\"." ), GetChars( path ) );
        return true;
    }

    // Attempt to determine where the footprint libraries were installed using the legacy
    // library search paths.
    if( !GetLibraryPathList().IsEmpty() )
    {
        unsigned      modFileCount = 0;
        wxString      bestPath;
        wxArrayString tmp;

        for( unsigned i = 0;  i < GetLibraryPathList().GetCount();  i++ )
        {
            unsigned cnt = wxDir::GetAllFiles( GetLibraryPathList()[i], &tmp, wxT( "*.mod" ),
                                               wxDIR_DEFAULT & ~wxDIR_HIDDEN );

            if( cnt > modFileCount )
            {
                modFileCount = cnt;
                bestPath = GetLibraryPathList()[i];
            }
        }

        if( modFileCount != 0 )
        {
            wxLogDebug( wxT( "Setting $KISYSMOD=\"%s\"." ), GetChars( bestPath ) );
            wxSetEnv( wxT( "KISYSMOD" ), bestPath );
            return true;
        }
    }

    return false;
}
+44 −9
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@


#include <set>
#include <set>


#include <appl_wxstruct.h>
#include <fp_lib_table_lexer.h>
#include <fp_lib_table_lexer.h>
#include <fp_lib_table.h>
#include <fp_lib_table.h>


@@ -319,23 +320,38 @@ bool FP_LIB_TABLE::IsEmpty() const
}
}




void FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR )
bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR )
{
{
    bool tableExists = true;
    wxFileName fn = GetGlobalTableFileName();
    wxFileName fn = GetGlobalTableFileName();


    wxLogDebug( wxT( "Loading global footprint table file: %s" ), GetChars( fn.GetFullPath() ) );
    wxLogDebug( wxT( "Loading global footprint table file: %s" ), GetChars( fn.GetFullPath() ) );


    if( !fn.FileExists() )
    if( !fn.FileExists() )
    {
    {
        /// @todo call some script to create initial global footprint table.
        tableExists = false;
    }

    else
        // Attempt to copy the default global file table from the KiCad template folder to
        // the users home configuration path.
        wxString fileName( wxT( "fp_global_table" ) );
        fileName = wxGetApp().FindLibraryPath( fileName );

        wxLogDebug( wxT( "Copying global footprint table from <%s>." ), GetChars( fileName ) );

        // The fallback is to create an empty global footprint table for the user to populate.
        if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
        {
        {
            FP_LIB_TABLE emptyTable;
            FILE_OUTPUTFORMATTER sf( fn.GetFullPath() );
            emptyTable.Format( &sf, 0 );
        }
    }

    FILE_LINE_READER reader( fn.GetFullPath() );
    FILE_LINE_READER reader( fn.GetFullPath() );
    FP_LIB_TABLE_LEXER lexer( &reader );
    FP_LIB_TABLE_LEXER lexer( &reader );


    aTable.Parse( &lexer );
    aTable.Parse( &lexer );
    }
    return tableExists;
}
}




@@ -357,7 +373,26 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()


wxString FP_LIB_TABLE::GetFileName()
wxString FP_LIB_TABLE::GetFileName()
{
{
    return wxString( wxT( ".fp-lib-table" ) );
    return wxString( wxT( "fp-lib-table" ) );
}


void FP_LIB_TABLE::Load( const wxFileName& aFileName, FP_LIB_TABLE* aFallBackTable )
    throw( IO_ERROR )
{
    wxFileName fn = aFileName;

    fallBack = aFallBackTable;

    fn.SetName( FP_LIB_TABLE::GetFileName() );
    fn.SetExt( wxEmptyString );

    if( fn.FileExists() )
    {
        FILE_LINE_READER reader( fn.GetFullPath() );
        FP_LIB_TABLE_LEXER lexer( &reader );
        Parse( &lexer );
    }
}
}




+35 −11
Original line number Original line Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
/**
 * @file cvpcb.cpp
 * @file cvpcb.cpp
 */
 */
@@ -22,7 +46,7 @@
// Colors for layers and items
// Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings;
COLORS_DESIGN_SETTINGS g_ColorsSettings;


/* Constant string definitions for CvPcb */
// Constant string definitions for CvPcb
const wxString RetroFileExtension( wxT( "stf" ) );
const wxString RetroFileExtension( wxT( "stf" ) );
const wxString FootprintAliasFileExtension( wxT( "equ" ) );
const wxString FootprintAliasFileExtension( wxT( "equ" ) );


@@ -48,7 +72,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName)
    if( frame->m_NetlistFileName.DirExists() )
    if( frame->m_NetlistFileName.DirExists() )
        oldPath = frame->m_NetlistFileName.GetPath();
        oldPath = frame->m_NetlistFileName.GetPath();


    /* Update the library search path list. */
    // Update the library search path list.
    if( wxGetApp().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND )
    if( wxGetApp().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND )
        wxGetApp().GetLibraryPathList().Remove( oldPath );
        wxGetApp().GetLibraryPathList().Remove( oldPath );


@@ -58,6 +82,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName)
    frame->ReadNetListAndLinkFiles();
    frame->ReadNetListAndLinkFiles();
}
}



// Create a new application object
// Create a new application object
IMPLEMENT_APP( EDA_APP )
IMPLEMENT_APP( EDA_APP )


@@ -74,6 +99,10 @@ bool EDA_APP::OnInit()


    InitEDA_Appl( wxT( "CvPcb" ), APP_CVPCB_T );
    InitEDA_Appl( wxT( "CvPcb" ), APP_CVPCB_T );


#if defined( USE_FP_LIB_TABLE )
    SetFootprintLibTablePath();
#endif

    if( m_Checker && m_Checker->IsAnotherRunning() )
    if( m_Checker && m_Checker->IsAnotherRunning() )
    {
    {
        if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) )
        if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) )
@@ -97,15 +126,13 @@ bool EDA_APP::OnInit()


    // Show the frame
    // Show the frame
    SetTopWindow( frame );
    SetTopWindow( frame );

    frame->LoadProjectFile( filename.GetFullPath() );
    frame->Show( true );
    frame->Show( true );
    frame->BuildFOOTPRINTS_LISTBOX();
    frame->m_NetlistFileExtension = wxT( "net" );
    frame->BuildLIBRARY_LISTBOX();


    if( filename.IsOk() && filename.FileExists() )
    if( filename.IsOk() && filename.FileExists() )
    {
    {
        frame->m_NetlistFileName = filename;
        frame->m_NetlistFileName = filename;
        frame->LoadProjectFile( filename.GetFullPath() );


        if( frame->ReadNetListAndLinkFiles() )
        if( frame->ReadNetListAndLinkFiles() )
        {
        {
@@ -114,9 +141,6 @@ bool EDA_APP::OnInit()
        }
        }
    }
    }


    frame->LoadFootprintFiles();
    frame->m_NetlistFileExtension = wxT( "net" );
    frame->m_NetlistFileName.Clear();
    frame->UpdateTitle();
    frame->UpdateTitle();


    return true;
    return true;
Loading