SEARCH_STACK* PROJECT::SchSearchS() { SEARCH_STACK* ss = (SEARCH_STACK*) GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ); wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ) ) ); if( !ss ) { ss = new SEARCH_STACK(); // Make PROJECT the new SEARCH_STACK owner. SetElem( PROJECT::ELEM_SCH_SEARCH_STACK, ss ); // to the empty SEARCH_STACK for SchSearchS(), add project dir as first ss->AddPaths( m_project_name.GetPath() ); // next add the paths found in *.pro, variable "LibDir" wxString libDir; try { PART_LIBS::LibNamesAndPaths( this, false, &libDir ); } catch( const IO_ERROR& DBG( ioe ) ) { DBG(printf( "%s: %s\n", __func__, TO_UTF8( ioe.What() ) );) } if( !!libDir ) { wxArrayString paths; SEARCH_STACK::Split( &paths, libDir ); for( unsigned i =0; i<paths.GetCount(); ++i ) { wxString path = AbsolutePath( paths[i] ); ss->AddPaths( path ); // at the end } } // append all paths from aSList add_search_paths( ss, Kiface().KifaceSearch(), -1 ); // addLibrarySearchPaths( SEARCH_STACK* aSP, wxConfigBase* aCfg ) // This is undocumented, but somebody wanted to store !schematic! // library search paths in the .kicad_common file? add_search_paths( ss, Pgm().CommonSettings(), -1 ); }
wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& aFileName, const wxString& aGroupName, bool aForceUseLocalConfig ) { wxConfigBase* cfg = 0; wxFileName fn = aFileName; fn.SetExt( ProjectFileExtension ); wxString cur_pro_fn = fn.GetFullPath(); // is there an edge transition, a change in m_project_filename? if( m_project_name != cur_pro_fn ) { m_sch_search.Clear(); // to the empty lists, add project dir as first m_sch_search.AddPaths( fn.GetPath() ); // append all paths from aSList add_search_paths( &m_sch_search, aSList, -1 ); // addLibrarySearchPaths( SEARCH_STACK* aSP, wxConfigBase* aCfg ) // This is undocumented, but somebody wanted to store !schematic! // library search paths in the .kicad_common file? add_search_paths( &m_sch_search, Pgm().CommonSettings(), -1 ); #if 1 && defined(DEBUG) m_sch_search.Show( __func__ ); #endif } // Init local config filename if( aForceUseLocalConfig || fn.FileExists() ) { cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString ); cfg->DontCreateOnDemand(); if( aForceUseLocalConfig ) { SetProjectFullName( cur_pro_fn ); return cfg; } /* Check the application version against the version saved in the * project file. * * TODO: Push the version test up the stack so that when one of the * KiCad application version changes, the other applications * settings do not get updated. Practically, this can go away. * It isn't used anywhere as far as I know (WLS). */ cfg->SetPath( aGroupName ); int def_version = 0; int version = cfg->Read( wxT( "version" ), def_version ); if( version > 0 ) { cfg->SetPath( wxCONFIG_PATH_SEPARATOR ); SetProjectFullName( cur_pro_fn ); return cfg; } else // Version incorrect { wxLogDebug( wxT( "Project file version is zero, not using this old project file, going with template." ) ); delete cfg; cfg = 0; } } // No suitable pro file was found, either does not exist, or is too old. // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK. wxString templateFile = wxT( "kicad." ) + ProjectFileExtension; wxString kicad_pro_template = aSList.FindValidPath( templateFile ); if( !kicad_pro_template ) { wxLogDebug( wxT( "Template file <%s> not found using search paths." ), GetChars( templateFile ) ); wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(), wxT( "kicad" ), ProjectFileExtension ); if( !templ.IsFileReadable() ) { wxString msg = wxString::Format( _( "Unable to find %s template config file." ), GetChars( templateFile ) ); DisplayError( NULL, msg ); return NULL; } kicad_pro_template = templ.GetFullPath(); } // The project config file is not found (happens for new projects, // or if the schematic editor is run outside an existing project // In this case the default template (kicad.pro) is used cur_pro_fn = kicad_pro_template; wxLogDebug( wxT( "Use template file '%s' as project file." ), GetChars( cur_pro_fn ) ); cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString ); cfg->DontCreateOnDemand(); SetProjectFullName( cur_pro_fn ); return cfg; }