Plan cube export face targets in app core
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/app_dialog.h"
|
||||
#include "document/document.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
@@ -23,6 +26,16 @@ struct DocumentExportStemTarget {
|
||||
std::string stem_path;
|
||||
};
|
||||
|
||||
struct DocumentCubeFaceExportFileTarget {
|
||||
std::string face_name;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
struct DocumentCubeFaceExportTarget {
|
||||
std::array<DocumentCubeFaceExportFileTarget, pp::document::cube_face_count> faces;
|
||||
std::size_t face_count = 0;
|
||||
};
|
||||
|
||||
struct DocumentExportSuggestedName {
|
||||
std::string name;
|
||||
};
|
||||
@@ -535,6 +548,51 @@ public:
|
||||
return pp::foundation::Result<DocumentExportStemTarget>::success(std::move(target));
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr std::array<std::string_view, pp::document::cube_face_count>
|
||||
document_cube_face_export_names() noexcept
|
||||
{
|
||||
return {
|
||||
"front",
|
||||
"right",
|
||||
"back",
|
||||
"left",
|
||||
"top",
|
||||
"bottom",
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<DocumentCubeFaceExportTarget> make_document_cube_face_export_target(
|
||||
std::string_view work_directory,
|
||||
std::string_view document_name)
|
||||
{
|
||||
if (work_directory.empty()) {
|
||||
return pp::foundation::Result<DocumentCubeFaceExportTarget>::failure(
|
||||
pp::foundation::Status::invalid_argument("work directory must not be empty"));
|
||||
}
|
||||
|
||||
if (document_name.empty()) {
|
||||
return pp::foundation::Result<DocumentCubeFaceExportTarget>::failure(
|
||||
pp::foundation::Status::invalid_argument("document name must not be empty"));
|
||||
}
|
||||
|
||||
DocumentCubeFaceExportTarget target;
|
||||
const auto face_names = document_cube_face_export_names();
|
||||
target.face_count = face_names.size();
|
||||
for (std::size_t face_index = 0; face_index < face_names.size(); ++face_index) {
|
||||
auto& face = target.faces[face_index];
|
||||
face.face_name = face_names[face_index];
|
||||
face.path.reserve(work_directory.size() + document_name.size() + face_names[face_index].size() + 6);
|
||||
face.path += work_directory;
|
||||
face.path += "/";
|
||||
face.path += document_name;
|
||||
face.path += "-";
|
||||
face.path += face_names[face_index];
|
||||
face.path += ".png";
|
||||
}
|
||||
|
||||
return pp::foundation::Result<DocumentCubeFaceExportTarget>::success(std::move(target));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<DocumentExportSuggestedName> make_document_export_suggested_name(
|
||||
std::string_view document_name,
|
||||
std::string_view suffix)
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "legacy_document_canvas_services.h"
|
||||
#include "paint_renderer/compositor.h"
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <span>
|
||||
@@ -142,30 +141,21 @@ pp::foundation::Status export_cube_faces_from_document_snapshot(
|
||||
std::string_view document_name,
|
||||
const LegacyDocumentExportSnapshotReports& reports)
|
||||
{
|
||||
static constexpr std::array<std::string_view, pp::document::cube_face_count> plane_names {
|
||||
"front",
|
||||
"right",
|
||||
"back",
|
||||
"left",
|
||||
"top",
|
||||
"bottom",
|
||||
};
|
||||
|
||||
if (document_name.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("document name must not be empty");
|
||||
const auto target = pp::app::make_document_cube_face_export_target(app.work_path, document_name);
|
||||
if (!target) {
|
||||
return target.status();
|
||||
}
|
||||
if (reports.face_pngs.face_count != pp::document::cube_face_count) {
|
||||
return pp::foundation::Status::invalid_argument("document snapshot did not produce all cube face PNGs");
|
||||
}
|
||||
|
||||
for (std::size_t face_index = 0; face_index < plane_names.size(); ++face_index) {
|
||||
const std::string path = app.work_path + "/" + std::string(document_name) + "-"
|
||||
+ std::string(plane_names[face_index]) + ".png";
|
||||
const auto status = write_binary_file(path, reports.face_pngs.face_pngs[face_index]);
|
||||
for (std::size_t face_index = 0; face_index < target.value().face_count; ++face_index) {
|
||||
const auto& face = target.value().faces[face_index];
|
||||
const auto status = write_binary_file(face.path, reports.face_pngs.face_pngs[face_index]);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
app.publish_exported_image(path);
|
||||
app.publish_exported_image(face.path);
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
|
||||
Reference in New Issue
Block a user