Error Plot::renderFromDisplay() { // we can use our cached representation if we don't need an update and our // rendered size is the same as the current graphics device size if ( !needsUpdate_ && (renderedSize() == graphicsDevice_.displaySize()) ) { return Success(); } // generate a new storage uuid std::string storageUuid = core::system::generateUuid(); // generate snapshot and image files Error error = graphicsDevice_.saveSnapshot(snapshotFilePath(storageUuid), imageFilePath(storageUuid)); if (error) return Error(errc::PlotRenderingError, error, ERROR_LOCATION); // save rendered size renderedSize_ = graphicsDevice_.displaySize(); // save manipulator (if any) saveManipulator(storageUuid); // delete existing files (if any) Error removeError = removeFiles(); // update state storageUuid_ = storageUuid; needsUpdate_ = false; // return error status return removeError; }
Error Plot::renderToDisplay() { Error error = graphicsDevice_.restoreSnapshot(snapshotFilePath()); if (error) { Error graphicsError(errc::PlotRenderingError, error, ERROR_LOCATION); DisplaySize deviceSize = graphicsDevice_.displaySize(); graphicsError.addProperty("device-width", deviceSize.width); graphicsError.addProperty("device-height", deviceSize.height); return graphicsError; } else return Success(); }
Error Plot::removeFiles() { // bail if we don't have any storage if (storageUuid_.empty()) return Success(); Error snapshotError = snapshotFilePath(storageUuid_).removeIfExists(); Error imageError = imageFilePath(storageUuid_).removeIfExists(); Error manipulatorError = manipulatorFilePath(storageUuid_).removeIfExists(); if (snapshotError) return Error(errc::PlotFileError, snapshotError, ERROR_LOCATION); else if (imageError) return Error(errc::PlotFileError, imageError, ERROR_LOCATION); else if (manipulatorError) return Error(errc::PlotFileError, manipulatorError, ERROR_LOCATION); else return Success(); }
Error Plot::renderFromDisplaySnapshot(SEXP snapshot) { // generate a new storage uuid std::string storageUuid = core::system::generateUuid(); // generate snapshot file FilePath snapshotFile = snapshotFilePath(storageUuid); Error error = r::exec::RFunction(".rs.saveGraphicsSnapshot", snapshot, snapshotFile.absolutePath()).call(); if (error) return error ; // // we can't generate an image file by calling graphicsDevice_.saveAsImageFile // because the GraphicsDevice has already moved on to the next page. this is // OK though because we simply set needsUpdate_ = true below and the next // time renderFromDisplay is called it will be rendered // // save rendered size renderedSize_ = graphicsDevice_.displaySize(); // save manipulator (if any) saveManipulator(storageUuid); // delete existing files (if any) Error removeError = removeFiles(); // update state storageUuid_ = storageUuid; needsUpdate_ = true; // return error status return removeError; }
FilePath Plot::snapshotFilePath() const { return snapshotFilePath(storageUuid()); }
bool Plot::hasValidStorage() const { return hasStorage() && snapshotFilePath().exists(); }