24#ifndef KICAD_SCRATCH_DOC_H
25#define KICAD_SCRATCH_DOC_H
36#include <wx/filename.h>
61 bool aRequireProjectFile =
false ) :
64 wxFileName pro( aDocOrProjectPath );
68 const wxString projectPath = pro.GetFullPath();
69 const bool fileMissing = !pro.FileExists();
74 if( aRequireProjectFile && fileMissing )
86 const bool loadOk = aMgr.
LoadProject( projectPath,
false );
96 if( !loadOk && !fileMissing )
112 if(
this != &aOther )
116 m_mgr = std::exchange( aOther.m_mgr,
nullptr );
117 m_project = std::exchange( aOther.m_project,
nullptr );
118 m_owned = std::exchange( aOther.m_owned,
false );
164template<
typename DOC>
191 if(
this != &aOther )
195 mgr = std::exchange( aOther.mgr,
nullptr );
196 doc = std::move( aOther.doc );
197 project = std::exchange( aOther.project,
nullptr );
198 ownsProject = std::exchange( aOther.ownsProject,
false );
231template<
typename DOC,
typename Loader,
typename ClearFn>
233 Loader aLoader, ClearFn aClearFn )
239 if( aDocPath.IsEmpty() )
242 wxFileName pro( aDocPath );
250 pro = wxFileName( wxFileName::GetTempDir(), wxS(
"kicad_scratch_" ) +
KIID().AsString() );
259 const bool projectAlreadyLoaded = ( aMgr.
GetProject( pro.GetFullPath() ) !=
nullptr );
265 const bool projectLoadOk = aMgr.
LoadProject( pro.GetFullPath(),
false );
273 if( !projectLoadOk && pro.FileExists() )
Container for project specific data.
SCRATCH_PROJECT(SCRATCH_PROJECT &&aOther) noexcept
SCRATCH_PROJECT()=default
bool IsValid() const
True iff the project loaded (or was already loaded).
SCRATCH_PROJECT(SETTINGS_MANAGER &aMgr, const wxString &aDocOrProjectPath, bool aRequireProjectFile=false)
PROJECT * GetProject() const
SCRATCH_PROJECT(const SCRATCH_PROJECT &)=delete
SCRATCH_PROJECT & operator=(const SCRATCH_PROJECT &)=delete
SCRATCH_PROJECT & operator=(SCRATCH_PROJECT &&aOther) noexcept
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
static const std::string ProjectFileExtension
SCRATCH_DOC< DOC > LoadScratchDoc(SETTINGS_MANAGER &aMgr, const wxString &aDocPath, Loader aLoader, ClearFn aClearFn)
Construct a SCRATCH_DOC by loading a project non-active and then handing it to the caller's document ...
Move-only RAII wrapper for "load a KiCad document into a non-active scratch PROJECT and clean up afte...
SCRATCH_DOC(SCRATCH_DOC &&aOther) noexcept
bool ownsProject
True when this load created the project (LoadScratchDoc found the path not yet in the SettingsManager...
std::function< void(DOC *)> CLEAR_FN
SCRATCH_DOC & operator=(SCRATCH_DOC &&aOther) noexcept
SCRATCH_DOC(const SCRATCH_DOC &)=delete
SCRATCH_DOC & operator=(const SCRATCH_DOC &)=delete
std::unique_ptr< DOC > doc
Definition of file extensions used in Kicad.