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::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; }
void Plot::saveManipulator() const { if (hasManipulator() && !storageUuid_.empty()) saveManipulator(storageUuid_); }