Commit 8580d87e authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Footprint library table improvements.

* Add save table and set project path environment variable code to
  FP_LIB_TABLE object.
* Add code to Pcbnew and CvPcb to set project path environment variable.
* Create empty footprint table in Pcbnew when new board created.
* Save current project specific footprint library table to path on file save
  as or empty project path.
* Fix a bug in Pcbnew in file save function that would silently overwrite
  an existing board file.
* Disable selecting the current library in the module editor when there are
  no libraries defined.
* Catch exceptions and report errors when writing footprint library tables.
* Fix Boost build CMakeFile to fix bug when bootstrapping a Boost build in
  MSys.
parent a8e57e10
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -49,6 +49,11 @@ option( KICAD_SCRIPTING_WXPYTHON

option( USE_FP_LIB_TABLE "Use the new footprint library table implementation. ( default OFF)" )

# BUILD_GITHUB_PLUGIN for MINGW is pretty demanding due to download_openssl.cmake and openssl's
# use of perl to drive its configure step.  You might find it works in a cross builder say on linux.
# Dick is not personally supporting Windows any more with this exotic stuff.  Some other windows
# developer will have to smooth out the build issues.  So enable this for MINGW without my help but
# with my best wishes.
option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." OFF )


+10 −3
Original line number Diff line number Diff line
@@ -93,7 +93,14 @@ if( BUILD_GITHUB_PLUGIN )
    #message( STATUS "REPLACE libs_csv:${boost_libs_list}" )

    if( MINGW )
        set( bootstrap bootstrap.bat mingw )
        if( MSYS )
            # The Boost system does not build properly on MSYS using bootstrap.sh.  Running
            # bootstrap.bat with cmd.exe does.  It's ugly but it works.  At least for Boost
            # version 1.54.
            set( bootstrap cmd.exe /c "bootstrap.bat mingw" )
        else()
            set( bootstrap ./bootstrap.bat mingw )
        endif()

        foreach( lib ${boost_libs_list} )
            set( b2_libs ${b2_libs} --with-${lib} )
@@ -103,7 +110,7 @@ if( BUILD_GITHUB_PLUGIN )
        string( REGEX REPLACE "\\;" "," libs_csv "${boost_libs_list}" )
        #message( STATUS "libs_csv:${libs_csv}" )

        set( bootstrap bootstrap.sh --with-libraries=${libs_csv} )
        set( bootstrap ./bootstrap.sh --with-libraries=${libs_csv} )
        # pass to *both* C and C++ compilers
        set( PIC_STUFF "cflags=${PIC_FLAG}" )
        set( BOOST_INCLUDE "${BOOST_ROOT}/include" )
@@ -125,7 +132,7 @@ if( BUILD_GITHUB_PLUGIN )
        UPDATE_COMMAND  ${CMAKE_COMMAND} -E remove_directory "${BOOST_ROOT}"

        BINARY_DIR      "${PREFIX}/src/boost/"
        CONFIGURE_COMMAND ./${bootstrap}
        CONFIGURE_COMMAND ${bootstrap}

        BUILD_COMMAND   ./b2
                        variant=release
+12 −2
Original line number Diff line number Diff line
@@ -148,12 +148,22 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( FP_LIB_TABLE& aTable )
    {
        const FP_LIB_TABLE::ROW* row = aTable.FindRow( libNickNames[ii] );

        wxCHECK2_MSG( row != NULL, continue,
        wxCHECK2_MSG( row != NULL, retv = false; continue,
                      wxString::Format( wxT( "No library name <%s> found in footprint library "
                                             "table." ), GetChars( libNickNames[ii] ) ) );
        try
        {
            PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::EnumFromStr( row->GetType() ) ) );
            PLUGIN* plugin = IO_MGR::PluginFind( IO_MGR::EnumFromStr( row->GetType() ) );

            if( plugin == NULL )
            {
                m_filesNotFound << wxString::Format( _( "Cannot find plugin type '%s'." ),
                                                     GetChars( row->GetType() ) );
                retv = false;
                continue;
            }

            PLUGIN::RELEASER pi( plugin );

            wxString      path = FP_LIB_TABLE::ExpandSubstitutions( row->GetFullURI() );
            wxArrayString fpnames = pi->FootprintEnumerate( path );
+90 −11
Original line number Diff line number Diff line
@@ -42,6 +42,25 @@
using namespace FP_LIB_TABLE_T;


/**
 * Definition for enabling and disabling footprint library trace output.  See the
 * wxWidgets documentation on using the WXTRACE environment variable.
 */
static const wxString traceFpLibTable( wxT( "KicadFpLibTable" ) );

/// The evinronment variable name for the current project path.  This is used interanally
/// at run time and is not exposed outside of the current process.
static wxString projectPathEnvVariableName( wxT( "KICAD_PRJ_PATH" ) );

/// The footprint library table name used when no project file is passed to Pcbnew or CvPcb.
/// This is used temporarily to store the project specific library table until the project
/// file being edited is save.  It is then moved to the file fp-lib-table in the folder where
/// the project file is saved.
static wxString defaultProjectFileName( wxT( "prj-fp-lib-table" ) );

static wxString defaultFileName( wxT( "fp-lib-table" ) );


void FP_LIB_TABLE::ROW::SetType( const wxString& aType )
{
    type = IO_MGR::EnumFromStr( aType );
@@ -261,6 +280,18 @@ void FP_LIB_TABLE::ROW::Format( OUTPUTFORMATTER* out, int nestLevel ) const
}


void FP_LIB_TABLE::Save( const wxFileName& aPath ) const throw( IO_ERROR )
{
    wxFileName fn = GetProjectFileName( aPath );

    wxLogTrace( traceFpLibTable, wxT( "Saving footprint libary table <%s>." ),
                GetChars( fn.GetFullPath() ) );

    FILE_OUTPUTFORMATTER sf( fn.GetFullPath() );
    Format( &sf, 0 );
}


#define OPT_SEP     '|'         ///< options separator character

PROPERTIES* FP_LIB_TABLE::ParseOptions( const std::string& aOptionsList )
@@ -486,9 +517,9 @@ const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString& aString )
}


bool FP_LIB_TABLE::IsEmpty() const
bool FP_LIB_TABLE::IsEmpty( bool aIncludeFallback )
{
    if( fallBack == NULL )
    if( !aIncludeFallback || (fallBack == NULL) )
        return rows.empty();

    return fallBack->IsEmpty() && rows.empty();
@@ -667,6 +698,55 @@ bool FP_LIB_TABLE::ConvertFromLegacy( NETLIST& aNetList, const wxArrayString& aL
}


void FP_LIB_TABLE::SetProjectPathEnvVariable( const wxFileName& aPath )
{
    wxString path;

    if( !aPath.IsOk() || !aPath.DirExists() )
        path = wxEmptyString;
    else
        path = aPath.GetPath();

    wxLogTrace( traceFpLibTable, wxT( "Setting env %s to <%s>." ),
                GetChars( projectPathEnvVariableName ), GetChars( path ) );
    wxSetEnv( projectPathEnvVariableName, path );
}


const wxString& FP_LIB_TABLE::GetProjectPathEnvVariableName() const
{
    return projectPathEnvVariableName;
}


wxString FP_LIB_TABLE::GetProjectFileName( const wxFileName& aPath )
{
    wxFileName fn = aPath;

    // Set $KICAD_PRJ_PATH to user's configuration path if aPath is not set or does not exist.
    if( !aPath.IsOk() || !aPath.DirExists() )
    {
        fn.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );

#if defined( __WINDOWS__ )
        fn.AppendDir( wxT( "kicad" ) );
#endif

        fn.SetName( defaultProjectFileName );
    }
    else
    {
        fn.AssignDir( aPath.GetPath() );
        fn.SetName( defaultFileName );
    }

    wxLogTrace( traceFpLibTable, wxT( "Project specific footprint library table file <%s>." ),
                GetChars( fn.GetFullPath() ) );

    return fn.GetFullPath();
}


bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR )
{
    bool tableExists = true;
@@ -710,29 +790,28 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()

    fn.SetName( GetFileName() );

    wxLogTrace( traceFpLibTable, wxT( "Global footprint library table file <%s>." ),
                GetChars( fn.GetFullPath() ) );

    return fn.GetFullPath();
}


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


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() )
    // Empty footprint library tables are valid.
    if( aFileName.IsOk() && aFileName.FileExists() )
    {
        FILE_LINE_READER reader( fn.GetFullPath() );
        FILE_LINE_READER reader( aFileName.GetFullPath() );
        FP_LIB_TABLE_LEXER lexer( &reader );
        Parse( &lexer );
    }
+10 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@

#include <cvpcb.h>
#include <cvpcb_mainframe.h>
#include <class_DisplayFootprintsFrame.h>


#define GROUP wxT("/cvpcb")
@@ -94,9 +95,17 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
    // Attempt to load the project footprint library table if it exists.
    m_footprintLibTable = new FP_LIB_TABLE();

    if( m_DisplayFootprintFrame )
        m_DisplayFootprintFrame->SetFootprintLibTable( m_footprintLibTable );

    wxFileName projectFpLibTableFileName;

    projectFpLibTableFileName = FP_LIB_TABLE::GetProjectFileName( fn );

    try
    {
        m_footprintLibTable->Load( fn, m_globalFootprintTable );
        m_footprintLibTable->Load( projectFpLibTableFileName, m_globalFootprintTable );
        FP_LIB_TABLE::SetProjectPathEnvVariable( projectFpLibTableFileName );
    }
    catch( IO_ERROR ioe )
    {
Loading