コード例 #1
0
bool S3D_FILENAME_RESOLVER::createPathList( void )
{
    if( !m_Paths.empty() )
        return true;

    wxString kmod;

    // add an entry for the default search path; at this point
    // we cannot set a sensible default so we use an empty string.
    // the user may change this later with a call to SetProjectDir()

    S3D_ALIAS lpath;
    lpath.m_alias = "${KIPRJMOD}";
    lpath.m_pathvar = "${KIPRJMOD}";
    lpath.m_pathexp = m_curProjDir;
    m_Paths.push_back( lpath );
    wxFileName fndummy;
    wxUniChar psep = fndummy.GetPathSeparator();
    std::list< wxString > epaths;

    if( GetKicadPaths( epaths ) )
    {
        for( auto i : epaths )
        {
            wxString pathVal = ExpandEnvVarSubstitutions( i );

            if( pathVal.empty() )
            {
                lpath.m_pathexp.clear();
            }
            else
            {
                fndummy.Assign( pathVal, "" );
                fndummy.Normalize();
                lpath.m_pathexp = fndummy.GetFullPath();
            }

            lpath.m_alias =  i;
            lpath.m_pathvar = i;

            if( !lpath.m_pathexp.empty() && psep == *lpath.m_pathexp.rbegin() )
                lpath.m_pathexp.erase( --lpath.m_pathexp.end() );

            m_Paths.push_back( lpath );
        }
    }

    if( !m_ConfigDir.empty() )
        readPathList();

    if( m_Paths.empty() )
        return false;

#ifdef DEBUG
    wxLogTrace( MASK_3D_RESOLVER, " * [3D model] search paths:\n" );
    std::list< S3D_ALIAS >::const_iterator sPL = m_Paths.begin();
    std::list< S3D_ALIAS >::const_iterator ePL = m_Paths.end();

    while( sPL != ePL )
    {
        wxLogTrace( MASK_3D_RESOLVER, "   + %s : '%s'\n", (*sPL).m_alias.GetData(),
            (*sPL).m_pathexp.GetData() );
        ++sPL;
    }
#endif

    return true;
}
コード例 #2
0
bool S3D_FILENAME_RESOLVER::createPathList( void )
{
    if( !m_Paths.empty() )
        return true;

    wxString kmod;

    // add an entry for the default search path; at this point
    // we cannot set a sensible default so we use an empty string.
    // the user may change this later with a call to SetProjectDir()

    S3D_ALIAS lpath;
    lpath.m_alias = _( "${KIPRJMOD}" );
    lpath.m_pathvar = _( "${KIPRJMOD}" );
    lpath.m_pathexp = m_curProjDir;
    m_Paths.push_back( lpath );
    wxFileName fndummy;
    wxUniChar psep = fndummy.GetPathSeparator();

    // iterate over the list of internally defined ENV VARs
    // and add existing paths to the resolver
    if( m_pgm )
    {
        ENV_VAR_MAP_CITER mS = m_pgm->GetLocalEnvVariables().begin();
        ENV_VAR_MAP_CITER mE = m_pgm->GetLocalEnvVariables().end();

        while( mS != mE )
        {
            // filter out URLs, template directories, and known system paths
            if( mS->first == wxString( "KICAD_PTEMPLATES" )
                || mS->first == wxString( "KIGITHUB" )
                || mS->first == wxString( "KISYSMOD" ) )
            {
                ++mS;
                continue;
            }

            if( wxString::npos != mS->second.GetValue().find( wxString( "://" ) ) )
            {
                ++mS;
                continue;
            }

            fndummy.Assign( mS->second.GetValue(), "" );

            if( !fndummy.DirExists() )
            {
                ++mS;
                continue;
            }

            wxString tmp( "${" );
            tmp.Append( mS->first );
            tmp.Append( "}" );

            lpath.m_alias =  tmp;
            lpath.m_pathvar = tmp;
            lpath.m_pathexp = mS->second.GetValue();

            if( !lpath.m_pathexp.empty() && psep == *lpath.m_pathexp.rbegin() )
                lpath.m_pathexp.erase( --lpath.m_pathexp.end() );

            m_Paths.push_back( lpath );

            ++mS;
        }
    }

    if( !m_ConfigDir.empty() )
        readPathList();

    if( m_Paths.empty() )
        return false;

#ifdef DEBUG
    wxLogTrace( MASK_3D_RESOLVER, " * [3D model] search paths:\n" );
    std::list< S3D_ALIAS >::const_iterator sPL = m_Paths.begin();
    std::list< S3D_ALIAS >::const_iterator ePL = m_Paths.end();

    while( sPL != ePL )
    {
        wxLogTrace( MASK_3D_RESOLVER, "   + '%s'\n", (*sPL).m_pathexp.ToUTF8() );
        ++sPL;
    }
#endif

    return true;
}