21#include <wx/stdpaths.h>
70 for(
unsigned i = 0; i <
m_elems.size(); ++i )
97 if( common->GetRepo() )
109 wxString projectDir = fn.GetPath();
110 wxString attachError;
111 wxString trustCommand;
115 common->SetAttachError( attachError, trustCommand );
122 if( !git_repository_workdir( repo ) )
124 git_repository_free( repo );
125 common->SetAttachError(
_(
"The git repository holding this project has no working folder, so "
126 "KiCad cannot use it. Clone the repository normally and open the "
127 "project from the clone." ) );
131 common->SetRepo( repo );
132 common->SetShuttingDown(
false );
134 const char* canonicalWorkDir = git_repository_workdir( repo );
136 if( canonicalWorkDir )
139 projectDir, wxString::FromUTF8( canonicalWorkDir ) );
140 common->SetProjectDir( symlinkWorkDir );
143 common->UpdateCurrentBranchInfo();
145 wxString remote = common->GetRemote();
170 std::shared_ptr<KIGIT_COMMON> old = std::move(
m_gitCommon );
182 if( aToken->IsSameAs( wxT(
"PROJECTNAME" ) ) )
187 else if( aToken->IsSameAs( wxT(
"CURRENT_DATE" ) ) )
192 else if( aToken->IsSameAs( wxT(
"CURRENT_TIME_HH_MM_SS" ) ) )
197 else if( aToken->IsSameAs( wxT(
"CURRENT_TIME_LOCALE" ) ) )
202 else if( aToken->IsSameAs( wxT(
"VCSHASH" ) ) )
207 else if( aToken->IsSameAs( wxT(
"VCSSHORTHASH" ) ) )
230 if( aVarsMap.size() == 0 )
233 std::map<wxString, wxString>& existingVarsMap =
GetTextVars();
235 for(
const auto& var : aVarsMap )
238 existingVarsMap[var.first] = var.second;
247 wxFileName candidate_path( aFullPathAndName );
251 if(
m_project_name.GetFullPath() != candidate_path.GetFullPath() )
321 std::vector<wxString>* pinnedLibsCfg =
nullptr;
322 std::vector<wxString>* pinnedLibsFile =
nullptr;
339 wxFAIL_MSG(
"Cannot pin library: invalid library type" );
344 pinnedLibsFile->push_back( aLibrary );
349 pinnedLibsCfg->push_back( aLibrary );
351 cfg->
SaveToFile(
Pgm().GetSettingsManager().GetPathForSettingsFile( cfg ) );
358 std::vector<wxString>* pinnedLibsCfg =
nullptr;
359 std::vector<wxString>* pinnedLibsFile =
nullptr;
376 wxFAIL_MSG(
"Cannot unpin library: invalid library type" );
380 std::erase( *pinnedLibsFile, aLibrary );
383 std::erase( *pinnedLibsCfg, aLibrary );
384 cfg->
SaveToFile(
Pgm().GetSettingsManager().GetPathForSettingsFile( cfg ) );
391 wxString
path = fn.GetPath();
395 if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable(
path ) )
407 fn.AssignDir( wxStandardPaths::Get().GetTempDir() );
410#if defined( __WINDOWS__ )
411 fn.AppendDir( wxT(
"kicad" ) );
420 fn.SetName( wxS(
"prj-" ) + aLibTableName );
424 fn.SetName( aLibTableName );
429 return fn.GetFullPath();
437 for(
const std::pair<KIID, wxString>& pair :
GetProjectFile().GetSheets() )
450 unsigned ndx = unsigned( aIndex );
461 unsigned ndx = unsigned( aIndex );
469 static wxString no_cookie_for_you;
473 return no_cookie_for_you;
482 if(
static_cast<unsigned>( aIndex ) <
m_elems.size() )
483 return m_elems[
static_cast<unsigned>( aIndex )];
492 if(
static_cast<unsigned>( aIndex ) <
m_elems.size() )
494 delete m_elems[
static_cast<unsigned>(aIndex)];
495 m_elems[
static_cast<unsigned>( aIndex )] = aElem;
502 wxFileName fn = aFileName;
506 if( aFileName.StartsWith( wxT(
"${" ) ) )
509 if( !fn.IsAbsolute() )
515 return fn.GetFullPath();
536 std::make_unique<DESIGN_BLOCK_LIBRARY_ADAPTER>( mgr ) );
564 if( projectFile.IsEmpty() )
567 wxFileName projectFn( projectFile );
568 wxFileName requestedFn( aProjectPath );
571 int norm_opt = wxPATH_NORM_ENV_VARS|wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_ABSOLUTE
572 |wxPATH_NORM_LONG|wxPATH_NORM_SHORTCUT;
574 if( !projectFn.Normalize( norm_opt ) || !requestedFn.Normalize( norm_opt ) )
577 if( projectFn.GetFullPath() != requestedFn.GetFullPath() )
590 aFileData.push_back( std::move( proEntry ) );
592 wxFileName prlFile( projectFn.GetPath(), projectFn.GetName(),
595 if( prlFile.FileExists() )
600 aFileData.push_back( std::move( prlEntry ) );
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.
static git_repository * GetRepositoryForFile(const char *aFilename, wxString *aError=nullptr, wxString *aTrustCommand=nullptr)
Discover and open the repository that contains the given file.
static void SafeFreeRepository(std::shared_ptr< KIGIT_COMMON > aCommon, const std::string &aLabel)
Free the session's repository handle without pulling it out from under a running operation.
static wxString ComputeSymlinkPreservingWorkDir(const wxString &aUserProjectPath, const wxString &aCanonicalWorkDir)
Compute a working directory path that preserves symlinks from the user's project path.
static REMOTE_URL ParseRemoteURL(const wxString &aURL)
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)
Advisory lock over a file, taken by writing a sibling lock file and holding an exclusive lock on it f...
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)
bool m_lockOverrideGranted
User granted override at project level.
virtual std::shared_ptr< KIGIT_COMMON > GetGitCommon() const
This project's Git session, created empty on first use.
LOCKFILE * GetProjectLock() const
std::shared_ptr< KIGIT_COMMON > m_gitCommon
Git session for the repository containing this project, created on first use.
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.
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
virtual bool AttachGitRepository()
Find the Git repository containing the project directory and bind it to the session.
virtual void ReleaseGitCommon()
Safely release the session's repository handle and drop the session.
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.
virtual FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(KIWAY &aKiway)
Fetches the footprint library adapter from the PCB editor instance.
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.
void SaveToHistory(const wxString &aProjectPath, std::vector< HISTORY_FILE_DATA > &aFileData)
Produce HISTORY_FILE_DATA entries for project files (.kicad_pro and .kicad_prl).
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 _ELEM objects that a PROJECT can hold.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
static wxString GetCurrentTimeLocale()
static wxString GetCurrentTimeHHMMSS()
static wxString GetCurrentDate()
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.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ KIFACE_FOOTPRINT_LIBRARY_ADAPTER
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.
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< wxString > pinned_design_block_libs
std::vector< wxString > pinned_fp_libs
std::vector< wxString > pinned_symbol_libs
Data produced by a registered saver on the UI thread, consumed by either the background local-history...
wxString sourcePath
For file-copy savers (small files like .kicad_pro)
std::string content
Serialized content (mutually exclusive with sourcePath)
wxString relativePath
Destination path relative to the project root.
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().