25#include <wx/stdpaths.h>
69 for(
unsigned i = 0; i <
m_elems.size(); ++i )
84 if( aToken->IsSameAs( wxT(
"PROJECTNAME" ) ) )
89 else if( aToken->IsSameAs( wxT(
"CURRENT_DATE" ) ) )
94 else if( aToken->IsSameAs( wxT(
"VCSHASH" ) ) )
99 else if( aToken->IsSameAs( wxT(
"VCSSHORTHASH" ) ) )
122 if( aVarsMap.size() == 0 )
125 std::map<wxString, wxString>& existingVarsMap =
GetTextVars();
127 for(
const auto& var : aVarsMap )
130 existingVarsMap[var.first] = var.second;
139 wxFileName candidate_path( aFullPathAndName );
143 if(
m_project_name.GetFullPath() != candidate_path.GetFullPath() )
210 std::vector<wxString>* pinnedLibsCfg =
nullptr;
211 std::vector<wxString>* pinnedLibsFile =
nullptr;
228 wxFAIL_MSG(
"Cannot pin library: invalid library type" );
233 pinnedLibsFile->push_back( aLibrary );
238 pinnedLibsCfg->push_back( aLibrary );
247 std::vector<wxString>* pinnedLibsCfg =
nullptr;
248 std::vector<wxString>* pinnedLibsFile =
nullptr;
265 wxFAIL_MSG(
"Cannot unpin library: invalid library type" );
269 std::erase( *pinnedLibsFile, aLibrary );
272 std::erase( *pinnedLibsCfg, aLibrary );
280 wxString
path = fn.GetPath();
284 if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable(
path ) )
296 fn.AssignDir( wxStandardPaths::Get().GetTempDir() );
299#if defined( __WINDOWS__ )
300 fn.AppendDir( wxT(
"kicad" ) );
309 fn.SetName( wxS(
"prj-" ) + aLibTableName );
313 fn.SetName( aLibTableName );
318 return fn.GetFullPath();
326 for(
const std::pair<KIID, wxString>& pair :
GetProjectFile().GetSheets() )
339 unsigned ndx = unsigned( aIndex );
350 unsigned ndx = unsigned( aIndex );
358 static wxString no_cookie_for_you;
362 return no_cookie_for_you;
371 if(
static_cast<unsigned>( aIndex ) <
m_elems.size() )
372 return m_elems[
static_cast<unsigned>( aIndex )];
381 if(
static_cast<unsigned>( aIndex ) <
m_elems.size() )
383 delete m_elems[
static_cast<unsigned>(aIndex)];
384 m_elems[
static_cast<unsigned>( aIndex )] = aElem;
391 wxFileName fn = aFileName;
395 if( aFileName.StartsWith( wxT(
"${" ) ) )
398 if( !fn.IsAbsolute() )
404 return fn.GetFullPath();
458 std::make_unique<DESIGN_BLOCK_LIBRARY_ADAPTER>( mgr ) );
486 if( projectFile.IsEmpty() )
489 wxFileName projectFn( projectFile );
490 wxFileName requestedFn( aProjectPath );
492 if( !projectFn.Normalize( wxPATH_NORM_ALL ) || !requestedFn.Normalize( wxPATH_NORM_ALL ) )
495 if( projectFn.GetFullPath() != requestedFn.GetFullPath() )
498 wxFileName historyDir( projectFn.GetPath(), wxS(
".history" ) );
500 if( !historyDir.DirExists() )
502 if( !historyDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
507 wxFileName historyProFile( historyDir.GetFullPath(), projectFn.GetName(),
508 projectFn.GetExt() );
509 wxCopyFile( projectFile, historyProFile.GetFullPath(),
true );
510 aFiles.push_back( historyProFile.GetFullPath() );
515 if( prlFile.FileExists() )
517 wxFileName historyPrlFile( historyDir.GetFullPath(), prlFile.GetName(),
519 wxCopyFile( prlFile.GetFullPath(), historyPrlFile.GetFullPath(),
true );
520 aFiles.push_back( historyPrlFile.GetFullPath() );
PROJECT::ELEM ProjectElementType() override
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
static wxString GetCurrentHash(const wxString &aProjectFile, bool aShort)
Return the current HEAD commit hash for the repository containing aProjectFile.
wxString AsString() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
std::optional< LIBRARY_MANAGER_ADAPTER * > Adapter(LIBRARY_TABLE_TYPE aType) const
void RegisterAdapter(LIBRARY_TABLE_TYPE aType, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > &&aAdapter)
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
std::map< wxString, wxString > m_TextVars
PROJECT_FILE * m_projectFile
Backing store for project data – owned by SETTINGS_MANAGER.
void SetProjectLock(LOCKFILE *aLockFile)
LOCKFILE * GetProjectLock() const
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
virtual const wxString DesignBlockLibTblName() const
Return the path and file name of this projects design block library table.
void PinLibrary(const wxString &aLibrary, enum LIB_TYPE_T aLibType)
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
std::map< KIID, wxString > m_sheetNames
std::unique_ptr< LOCKFILE > m_project_lock
Lock.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
int m_netclassesTicker
Update counter on netclasses.
virtual const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
virtual _ELEM * GetElem(PROJECT::ELEM aIndex)
Get and set the elements for this project.
void SaveToHistory(const wxString &aProjectPath, std::vector< wxString > &aFiles)
Save project files (.kicad_pro and .kicad_prl) to the .history directory.
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
virtual DESIGN_BLOCK_LIBRARY_ADAPTER * DesignBlockLibs()
Return the table of design block libraries.
virtual bool TextVarResolver(wxString *aToken) const
virtual PROJECT_FILE & GetProjectFile() const
virtual const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
std::mutex m_designBlockLibsMutex
Synchronise access to DesignBlockLibs()
std::array< _ELEM *, static_cast< unsigned int >(PROJECT::ELEM::COUNT)> m_elems
virtual void elemsClear()
Delete all the _ELEMs and set their pointers to NULL.
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
wxFileName m_project_name
<fullpath>/<basename>.pro
void Clear()
Clear the _ELEMs and RSTRINGs.
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
int m_textVarsTicker
Update counter on text vars.
void UnpinLibrary(const wxString &aLibrary, enum LIB_TYPE_T aLibType)
std::array< wxString, RSTRING_COUNT > m_rstrings
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
bool m_readOnly
No project files will be written to disk.
virtual const wxString GetProjectDirectory() const
Return the full path of the project DIRECTORY.
virtual std::map< wxString, wxString > & GetTextVars() const
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
ELEM
The set of #_ELEMs that a PROJECT can hold.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
static wxString GetCurrentDate()
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static const std::string SymbolLibraryTableFileName
static const std::string ProjectFileExtension
static const std::string ProjectLocalSettingsFileExtension
static const std::string DesignBlockLibraryTableFileName
static const std::string FootprintLibraryTableFileName
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
@ KIFACE_NEW_FOOTPRINT_TABLE
Return a new FP_LIB_TABLE with the global table installed as a fallback.
This file contains miscellaneous commonly used macros and functions.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global program "get" accessor.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::vector< wxString > pinned_design_block_libs
std::vector< wxString > pinned_fp_libs
std::vector< wxString > pinned_symbol_libs
Implement a participant in the KIWAY alchemy.
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().