wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList,
        const wxString& aGroupName, const wxString& aProjectFileName )
{
    wxConfigBase*   cfg = 0;
    wxString        cur_pro_fn = !aProjectFileName ? GetProjectFullName() : aProjectFileName;

    if( wxFileName( cur_pro_fn ).IsFileReadable() )
    {
        // Note: currently, aGroupName is not used.
        // Previoulsy, the version of aGroupName was tested, but it
        // was useless, and if the version is important,
        // this is not the right place here, because configCreate does know anything
        // about info stored in this config file.
        cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
        return cfg;
    }

    // No suitable pro file was found, either does not exist, or not readable.
    // Use the template kicad.pro file.  Find it by using caller's SEARCH_STACK.
    copy_pro_file_template( aSList, cur_pro_fn );

    cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );

    return cfg;
}
void PROJECT::SetProjectFullName( const wxString& aFullPathAndName )
{
    // Compare paths, rather than inodes, to be less surprising to the user.
    // Create a temporary wxFileName to normalize the path
    wxFileName candidate_path( aFullPathAndName );

    // Edge transitions only.  This is what clears the project
    // data using the Clear() function.
    if( m_project_name.GetFullPath() != candidate_path.GetFullPath() )
    {
        Clear();            // clear the data when the project changes.

        wxLogTrace( tracePathsAndFiles, "%s: old:'%s' new:'%s'", __func__,
                    TO_UTF8( GetProjectFullName() ), TO_UTF8( aFullPathAndName ) );

        m_project_name = aFullPathAndName;

        wxASSERT( m_project_name.IsAbsolute() );

        wxASSERT( m_project_name.GetExt() == ProjectFileExtension );

        // until multiple projects are in play, set an environment variable for the
        // the project pointer.
        {
            wxString path = m_project_name.GetPath();

            wxSetEnv( PROJECT_VAR_NAME, path );
        }
    }
}
const wxString PROJECT::AbsolutePath( const wxString& aFileName ) const
{
    wxFileName fn = aFileName;

    if( !fn.IsAbsolute() )
    {
        wxString pro_dir = wxPathOnly( GetProjectFullName() );
        fn.Normalize( wxPATH_NORM_ALL, pro_dir );
    }

    return fn.GetFullPath();
}
Beispiel #4
0
void PROJECT::SetProjectFullName( const wxString& aFullPathAndName )
{
    // Compare paths, rather than inodes, to be less surprising to the user.
    // Create a temporary wxFileName to normalize the path
    wxFileName candidate_path( aFullPathAndName );

    // Edge transitions only.  This is what clears the project
    // data using the Clear() function.
    if( m_project_name.GetFullPath() != candidate_path.GetFullPath() )
    {
        Clear();            // clear the data when the project changes.

        DBG(printf( "%s: old:'%s' new:'%s'\n", __func__, TO_UTF8( GetProjectFullName() ), TO_UTF8( aFullPathAndName ) );)
const wxString PROJECT::libTableName( const wxString& aLibTableName ) const
{
    wxFileName  fn = GetProjectFullName();
    wxString    path = fn.GetPath();

    // if there's no path to the project name, or the name as a whole is bogus or its not
    // write-able then use a template file.
    if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable( path ) )
    {
        // return a template filename now.

        // this next line is likely a problem now, since it relies on an
        // application title which is no longer constant or known.  This next line needs
        // to be re-thought out.

#ifndef __WXMAC__
        fn.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
#else
        // don't pollute home folder, temp folder seems to be more appropriate
        fn.AssignDir( wxStandardPaths::Get().GetTempDir() );
#endif

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

        /*
         * The library table name used when no project file is passed to the appropriate
         * code.  This is used temporarily to store the project specific library table
         * until the project file being edited is saved.  It is then moved to the correct
         * file in the folder where the project file is saved.
         */
        fn.SetName( "prj-" + aLibTableName );
    }
    else    // normal path.
    {
        fn.SetName( aLibTableName );
    }

    fn.ClearExt();

    return fn.GetFullPath();
}
const wxString PROJECT::FootprintLibTblName() const
{
    wxFileName  fn = GetProjectFullName();
    wxString    path = fn.GetPath();

    // DBG(printf( "path:'%s'  fn:'%s'\n", TO_UTF8(path), TO_UTF8(fn.GetFullPath()) );)

    // if there's no path to the project name, or the name as a whole is bogus or its not
    // write-able then use a template file.
    if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable( path ) )
    {
        // return a template filename now.

        // this next line is likely a problem now, since it relies on an
        // application title which is no longer constant or known.  This next line needs
        // to be re-thought out.

        fn.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );

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

        /*
            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 saved.
            It is then moved to the file fp-lib-table in the folder where the
            project file is saved.
        */
        fn.SetName( wxT( "prj-fp-lib-table" ) );
    }
    else    // normal path.
    {
        fn.SetName( wxT( "fp-lib-table" ) );
    }

    fn.ClearExt();

    return fn.GetFullPath();
}
#include <common.h>         // NAMELESS_PROJECT
#include <confirm.h>
#include <kicad_string.h>
#include <config_params.h>
#include <wildcards_and_files_ext.h>


PROJECT::PROJECT()
{
    memset( m_elems, 0, sizeof(m_elems) );
}


void PROJECT::ElemsClear()
{
    DBG( printf( "%s: clearing all _ELEMS for project %s\n", __func__, TO_UTF8( GetProjectFullName() ) );)

    // careful here, this should work, but the virtual destructor may not
    // be in the same link image as PROJECT.
    for( unsigned i = 0;  i < DIM( m_elems );  ++i )
    {
        SetElem( ELEM_T( i ), NULL );
    }
}


PROJECT::~PROJECT()
{
    ElemsClear();
}