24#ifndef KICAD_SCRATCH_DOC_H
25#define KICAD_SCRATCH_DOC_H
35#include <wx/filename.h>
60 bool aRequireProjectFile =
false ) :
63 wxFileName pro( aDocOrProjectPath );
67 const wxString projectPath = pro.GetFullPath();
68 const bool fileMissing = !pro.FileExists();
73 if( aRequireProjectFile && fileMissing )
85 const bool loadOk = aMgr.
LoadProject( projectPath,
false );
95 if( !loadOk && !fileMissing )
111 if(
this != &aOther )
115 m_mgr = std::exchange( aOther.m_mgr,
nullptr );
116 m_project = std::exchange( aOther.m_project,
nullptr );
117 m_owned = std::exchange( aOther.m_owned,
false );
163template<
typename DOC>
190 if(
this != &aOther )
194 mgr = std::exchange( aOther.mgr,
nullptr );
195 doc = std::move( aOther.doc );
196 project = std::exchange( aOther.project,
nullptr );
197 ownsProject = std::exchange( aOther.ownsProject,
false );
230template<
typename DOC,
typename Loader,
typename ClearFn>
232 Loader aLoader, ClearFn aClearFn )
238 if( aDocPath.IsEmpty() )
241 wxFileName pro( aDocPath );
250 const bool projectAlreadyLoaded = ( aMgr.
GetProject( pro.GetFullPath() ) !=
nullptr );
256 const bool projectLoadOk = aMgr.
LoadProject( pro.GetFullPath(),
false );
264 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.