21#include <wx/stdpaths.h>
71 for(
unsigned i = 0; i <
m_elems.size(); ++i )
98 if( common->GetRepo() )
110 wxString projectDir = fn.GetPath();
111 wxString attachError;
112 wxString trustCommand;
116 common->SetAttachError( attachError, trustCommand );
123 if( !git_repository_workdir( repo ) )
125 git_repository_free( repo );
126 common->SetAttachError(
_(
"The git repository holding this project has no working folder, so "
127 "KiCad cannot use it. Clone the repository normally and open the "
128 "project from the clone." ) );
132 common->SetRepo( repo );
133 common->SetShuttingDown(
false );
135 const char* canonicalWorkDir = git_repository_workdir( repo );
137 if( canonicalWorkDir )
140 projectDir, wxString::FromUTF8( canonicalWorkDir ) );
141 common->SetProjectDir( symlinkWorkDir );
144 common->UpdateCurrentBranchInfo();
146 wxString remote = common->GetRemote();
171 std::shared_ptr<KIGIT_COMMON> old = std::move(
m_gitCommon );
183 if( aToken->IsSameAs( wxT(
"PROJECTNAME" ) ) )
188 else if( aToken->IsSameAs( wxT(
"CURRENT_DATE" ) ) )
193 else if( aToken->IsSameAs( wxT(
"CURRENT_TIME_HH_MM_SS" ) ) )
198 else if( aToken->IsSameAs( wxT(
"CURRENT_TIME_LOCALE" ) ) )
203 else if( aToken->IsSameAs( wxT(
"VCSHASH" ) ) )
208 else if( aToken->IsSameAs( wxT(
"VCSSHORTHASH" ) ) )
231 if( aVarsMap.size() == 0 )
234 std::map<wxString, wxString>& existingVarsMap =
GetTextVars();
236 for(
const auto& var : aVarsMap )
239 existingVarsMap[var.first] = var.second;
248 wxFileName candidate_path( aFullPathAndName );
252 if(
m_project_name.GetFullPath() != candidate_path.GetFullPath() )
322 std::vector<wxString>* pinnedLibsCfg =
nullptr;
323 std::vector<wxString>* pinnedLibsFile =
nullptr;
340 wxFAIL_MSG(
"Cannot pin library: invalid library type" );
345 pinnedLibsFile->push_back( aLibrary );
350 pinnedLibsCfg->push_back( aLibrary );
352 cfg->
SaveToFile(
Pgm().GetSettingsManager().GetPathForSettingsFile( cfg ) );
359 std::vector<wxString>* pinnedLibsCfg =
nullptr;
360 std::vector<wxString>* pinnedLibsFile =
nullptr;
377 wxFAIL_MSG(
"Cannot unpin library: invalid library type" );
381 std::erase( *pinnedLibsFile, aLibrary );
384 std::erase( *pinnedLibsCfg, aLibrary );
385 cfg->
SaveToFile(
Pgm().GetSettingsManager().GetPathForSettingsFile( cfg ) );
392 wxString
path = fn.GetPath();
396 if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable(
path ) )
408 fn.AssignDir( wxStandardPaths::Get().GetTempDir() );
411#if defined( __WINDOWS__ )
412 fn.AppendDir( wxT(
"kicad" ) );
421 fn.SetName( wxS(
"prj-" ) + aLibTableName );
425 fn.SetName( aLibTableName );
430 return fn.GetFullPath();
438 for(
const std::pair<KIID, wxString>& pair :
GetProjectFile().GetSheets() )
451 unsigned ndx = unsigned( aIndex );
462 unsigned ndx = unsigned( aIndex );
470 static wxString no_cookie_for_you;
474 return no_cookie_for_you;
483 if(
static_cast<unsigned>( aIndex ) <
m_elems.size() )
484 return m_elems[
static_cast<unsigned>( aIndex )];
493 if(
static_cast<unsigned>( aIndex ) <
m_elems.size() )
495 delete m_elems[
static_cast<unsigned>(aIndex)];
496 m_elems[
static_cast<unsigned>( aIndex )] = aElem;
503 wxFileName fn = aFileName;
507 if( aFileName.StartsWith( wxT(
"${" ) ) )
510 if( !fn.IsAbsolute() )
516 return fn.GetFullPath();
537 std::make_unique<DESIGN_BLOCK_LIBRARY_ADAPTER>( mgr ) );
565 if( projectFile.IsEmpty() )
568 wxFileName projectFn( projectFile );
569 wxFileName requestedDir = wxFileName::DirName( aProjectPath );
572 int norm_opt = wxPATH_NORM_ENV_VARS|wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_ABSOLUTE
573 |wxPATH_NORM_LONG|wxPATH_NORM_SHORTCUT;
575 if( !projectFn.Normalize( norm_opt ) || !requestedDir.Normalize( norm_opt ) )
579 if( projectFn.GetPath() != requestedDir.GetPath() )
592 aFileData.push_back( std::move( proEntry ) );
595 const wxString dir = projectFn.GetPath();
596 const wxString
name = projectFn.GetName();
606 if( file.FileExists() )
611 aFileData.push_back( std::move( entry ) );
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
static const std::string DesignRulesFileExtension
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
Service::Type GetKifaceService(KIFACE *aKiface)
Look up a service exported by a KIFACE.
This file contains miscellaneous commonly used macros and functions.
APIEXPORT wxString PrivateKeyPath(const wxString &aPicked)
The private key for a path picked in a file dialog, which may be the key's .pub file.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
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
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)
bool removed
The file no longer exists and leaves the snapshot.
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().