Centralize legacy document image exports

This commit is contained in:
2026-06-04 13:57:32 +02:00
parent ab6223c256
commit 78003923ca
9 changed files with 530 additions and 53 deletions

View File

@@ -56,6 +56,11 @@ enum class DocumentExportMenuAction {
unavailable_no_canvas,
};
enum class DocumentExportCollectionKind {
layers,
animation_frames,
};
struct DocumentExportMenuPlan {
DocumentExportMenuKind kind = DocumentExportMenuKind::jpeg;
DocumentExportMenuAction action = DocumentExportMenuAction::show_jpeg_dialog;
@@ -77,6 +82,20 @@ public:
virtual void show_license_disabled() = 0;
};
class DocumentExportServices {
public:
virtual ~DocumentExportServices() = default;
virtual bool create_directory(std::string_view directory) = 0;
virtual void export_equirectangular(const DocumentExportFileTarget& target) = 0;
virtual void export_layers_to_stem(const DocumentExportStemTarget& target) = 0;
virtual void export_layers_to_collection(const DocumentExportCollectionTarget& target) = 0;
virtual void export_animation_frames_to_stem(const DocumentExportStemTarget& target) = 0;
virtual void export_animation_frames_to_collection(const DocumentExportCollectionTarget& target) = 0;
virtual void export_depth(std::string_view document_name) = 0;
virtual void export_cube_faces(std::string_view document_name) = 0;
};
[[nodiscard]] constexpr DocumentExportStartDecision plan_document_export_start(
bool requires_license,
bool license_valid,
@@ -241,6 +260,88 @@ public:
return pp::foundation::Result<DocumentExportSuggestedName>::success(std::move(target));
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_file(
const DocumentExportFileTarget& target,
DocumentExportServices& services)
{
if (target.path.empty() || target.suggested_name.empty()) {
return pp::foundation::Status::invalid_argument("export file target requires a path and suggested name");
}
services.export_equirectangular(target);
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_stem(
DocumentExportCollectionKind kind,
const DocumentExportStemTarget& target,
DocumentExportServices& services)
{
if (target.stem_path.empty()) {
return pp::foundation::Status::invalid_argument("export stem target requires a stem path");
}
switch (kind) {
case DocumentExportCollectionKind::layers:
services.export_layers_to_stem(target);
return pp::foundation::Status::success();
case DocumentExportCollectionKind::animation_frames:
services.export_animation_frames_to_stem(target);
return pp::foundation::Status::success();
}
return pp::foundation::Status::invalid_argument("unknown document export collection kind");
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_collection(
DocumentExportCollectionKind kind,
const DocumentExportCollectionTarget& target,
DocumentExportServices& services)
{
if (target.directory.empty() || target.stem_path.empty()) {
return pp::foundation::Status::invalid_argument("export collection target requires a directory and stem path");
}
if (!services.create_directory(target.directory)) {
return pp::foundation::Status::success();
}
switch (kind) {
case DocumentExportCollectionKind::layers:
services.export_layers_to_collection(target);
return pp::foundation::Status::success();
case DocumentExportCollectionKind::animation_frames:
services.export_animation_frames_to_collection(target);
return pp::foundation::Status::success();
}
return pp::foundation::Status::invalid_argument("unknown document export collection kind");
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_depth(
std::string_view document_name,
DocumentExportServices& services)
{
if (document_name.empty()) {
return pp::foundation::Status::invalid_argument("document name must not be empty");
}
services.export_depth(document_name);
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_cube_faces(
std::string_view document_name,
DocumentExportServices& services)
{
if (document_name.empty()) {
return pp::foundation::Status::invalid_argument("document name must not be empty");
}
services.export_cube_faces(document_name);
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_document_export_menu_plan(
const DocumentExportMenuPlan& plan,
DocumentExportMenuServices& services)

View File

@@ -5,6 +5,7 @@
#include "app_core/document_export.h"
#include "app_core/document_session.h"
#include "legacy_document_canvas_services.h"
#include "legacy_document_export_services.h"
#include "legacy_document_layer_services.h"
#include "legacy_document_session_services.h"
#include "settings.h"
@@ -356,21 +357,9 @@ void App::dialog_export(std::string ext)
return;
}
canvas->m_canvas->export_equirectangular(target.value().path, [this, target = target.value()]{
#if defined(__IOS__)
message_box("Export Equirectangular", "Image exported to Photos");
#elif defined(__OSX__)
message_box("Export Equirectangular", "Image exported to Pictures/PanoPainter folder");
#elif defined(_WIN32)
message_box("Export Equirectangular", "Image exported to " + work_path);
#elif defined(__QUEST__)
//auto result = ovr_Media_ShareToFacebook("Sharing from PanoPainter on Oculus Quest", path.c_str(), ovrMediaContentType_Photo);
#elif __WEB__
ui_task([=]{
save_prepared_file(target.path, target.suggested_name, [](const std::string&, bool) { });
});
#endif
});
const auto status = pp::panopainter::execute_legacy_document_export_file(*this, target.value());
if (!status.ok())
LOG("Document export file action failed: %s", status.message);
}
void App::dialog_export_layers()
@@ -385,12 +374,12 @@ void App::dialog_export_layers()
return;
}
if (Asset::create_dir(target.value().directory))
{
canvas->m_canvas->export_layers(target.value().stem_path, [this] {
message_box("Export Layers", "Image layers exported to Files/PanoPainter");
});
}
const auto status = pp::panopainter::execute_legacy_document_export_collection(
*this,
pp::app::DocumentExportCollectionKind::layers,
target.value());
if (!status.ok())
LOG("Document layer collection export failed: %s", status.message);
#else
pick_dir([this](std::string path) {
const auto target = pp::app::make_document_export_stem_target(path, doc_name);
@@ -399,9 +388,12 @@ void App::dialog_export_layers()
return;
}
canvas->m_canvas->export_layers(target.value().stem_path, [this, target = target.value()] {
message_box("Export Layers", "Layers exported to: " + target.stem_path);
});
const auto status = pp::panopainter::execute_legacy_document_export_stem(
*this,
pp::app::DocumentExportCollectionKind::layers,
target.value());
if (!status.ok())
LOG("Document layer stem export failed: %s", status.message);
});
#endif
}
@@ -418,12 +410,12 @@ void App::dialog_export_anim_frames()
return;
}
if (Asset::create_dir(target.value().directory))
{
canvas->m_canvas->export_anim_frames(target.value().stem_path, [this] {
message_box("Export Layers", "Image layers exported to Files/PanoPainter");
});
}
const auto status = pp::panopainter::execute_legacy_document_export_collection(
*this,
pp::app::DocumentExportCollectionKind::animation_frames,
target.value());
if (!status.ok())
LOG("Document animation frame collection export failed: %s", status.message);
#else
pick_dir([this](std::string path) {
const auto target = pp::app::make_document_export_stem_target(path, doc_name);
@@ -432,9 +424,12 @@ void App::dialog_export_anim_frames()
return;
}
canvas->m_canvas->export_anim_frames(target.value().stem_path, [this, target = target.value()] {
message_box("Export Layers", "Layers exported to: " + target.stem_path);
});
const auto status = pp::panopainter::execute_legacy_document_export_stem(
*this,
pp::app::DocumentExportCollectionKind::animation_frames,
target.value());
if (!status.ok())
LOG("Document animation frame stem export failed: %s", status.message);
});
#endif
}
@@ -444,16 +439,9 @@ void App::dialog_export_depth()
if (!can_start_document_export(*this, true))
return;
// TODO: use picker
canvas->m_canvas->export_depth(doc_name, [this] {
#if defined(__IOS__)
message_box("Export 3D View + Depth", "Image and depth exported to Files/PanoPainter");
#elif defined(__OSX__)
message_box("Export 3D View + Depth", "Image and depth exported to Pictures/PanoPainter folder");
#elif defined(_WIN32)
message_box("Export 3D View + Depth", "Image and depth exported to " + work_path);
#endif
});
const auto status = pp::panopainter::execute_legacy_document_export_depth(*this, doc_name);
if (!status.ok())
LOG("Document depth export failed: %s", status.message);
}
void App::dialog_resize()
@@ -487,15 +475,9 @@ void App::dialog_export_cube_faces()
if (!can_start_document_export(*this, false))
return;
canvas->m_canvas->export_cube_faces(doc_name, [this] {
#if defined(__IOS__)
message_box("Export Cube Faces", "Image and depth exported to Files/PanoPainter");
#elif defined(__OSX__)
message_box("Export Cube Faces", "Image and depth exported to Pictures/PanoPainter folder");
#elif defined(_WIN32)
message_box("Export Cube Faces", "Image and depth exported to " + work_path);
#endif
});
const auto status = pp::panopainter::execute_legacy_document_export_cube_faces(*this, doc_name);
if (!status.ok())
LOG("Document cube-face export failed: %s", status.message);
}
void App::dialog_layer_rename()

View File

@@ -0,0 +1,152 @@
#include "pch.h"
#include "legacy_document_export_services.h"
#include "app.h"
namespace pp::panopainter {
namespace {
class LegacyDocumentExportServices final : public pp::app::DocumentExportServices {
public:
explicit LegacyDocumentExportServices(App& app) noexcept
: app_(app)
{
}
bool create_directory(std::string_view directory) override
{
return Asset::create_dir(std::string(directory));
}
void export_equirectangular(const pp::app::DocumentExportFileTarget& target) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_equirectangular(target.path, [app, target] {
#if defined(__IOS__)
app->message_box("Export Equirectangular", "Image exported to Photos");
#elif defined(__OSX__)
app->message_box("Export Equirectangular", "Image exported to Pictures/PanoPainter folder");
#elif defined(_WIN32)
app->message_box("Export Equirectangular", "Image exported to " + app->work_path);
#elif defined(__QUEST__)
(void)target;
#elif __WEB__
app->ui_task([app, target] {
app->save_prepared_file(target.path, target.suggested_name, [](const std::string&, bool) { });
});
#else
(void)target;
#endif
});
}
void export_layers_to_stem(const pp::app::DocumentExportStemTarget& target) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_layers(target.stem_path, [app, target] {
app->message_box("Export Layers", "Layers exported to: " + target.stem_path);
});
}
void export_layers_to_collection(const pp::app::DocumentExportCollectionTarget& target) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_layers(target.stem_path, [app] {
app->message_box("Export Layers", "Image layers exported to Files/PanoPainter");
});
}
void export_animation_frames_to_stem(const pp::app::DocumentExportStemTarget& target) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_anim_frames(target.stem_path, [app, target] {
app->message_box("Export Layers", "Layers exported to: " + target.stem_path);
});
}
void export_animation_frames_to_collection(const pp::app::DocumentExportCollectionTarget& target) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_anim_frames(target.stem_path, [app] {
app->message_box("Export Layers", "Image layers exported to Files/PanoPainter");
});
}
void export_depth(std::string_view document_name) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_depth(std::string(document_name), [app] {
#if defined(__IOS__)
app->message_box("Export 3D View + Depth", "Image and depth exported to Files/PanoPainter");
#elif defined(__OSX__)
app->message_box("Export 3D View + Depth", "Image and depth exported to Pictures/PanoPainter folder");
#elif defined(_WIN32)
app->message_box("Export 3D View + Depth", "Image and depth exported to " + app->work_path);
#endif
});
}
void export_cube_faces(std::string_view document_name) override
{
auto* app = &app_;
app_.canvas->m_canvas->export_cube_faces(std::string(document_name), [app] {
#if defined(__IOS__)
app->message_box("Export Cube Faces", "Image and depth exported to Files/PanoPainter");
#elif defined(__OSX__)
app->message_box("Export Cube Faces", "Image and depth exported to Pictures/PanoPainter folder");
#elif defined(_WIN32)
app->message_box("Export Cube Faces", "Image and depth exported to " + app->work_path);
#endif
});
}
private:
App& app_;
};
} // namespace
pp::foundation::Status execute_legacy_document_export_file(
App& app,
const pp::app::DocumentExportFileTarget& target)
{
LegacyDocumentExportServices services(app);
return pp::app::execute_document_export_file(target, services);
}
pp::foundation::Status execute_legacy_document_export_stem(
App& app,
pp::app::DocumentExportCollectionKind kind,
const pp::app::DocumentExportStemTarget& target)
{
LegacyDocumentExportServices services(app);
return pp::app::execute_document_export_stem(kind, target, services);
}
pp::foundation::Status execute_legacy_document_export_collection(
App& app,
pp::app::DocumentExportCollectionKind kind,
const pp::app::DocumentExportCollectionTarget& target)
{
LegacyDocumentExportServices services(app);
return pp::app::execute_document_export_collection(kind, target, services);
}
pp::foundation::Status execute_legacy_document_export_depth(
App& app,
std::string_view document_name)
{
LegacyDocumentExportServices services(app);
return pp::app::execute_document_export_depth(document_name, services);
}
pp::foundation::Status execute_legacy_document_export_cube_faces(
App& app,
std::string_view document_name)
{
LegacyDocumentExportServices services(app);
return pp::app::execute_document_export_cube_faces(document_name, services);
}
} // namespace pp::panopainter

View File

@@ -0,0 +1,32 @@
#pragma once
#include "app_core/document_export.h"
#include "foundation/result.h"
class App;
namespace pp::panopainter {
[[nodiscard]] pp::foundation::Status execute_legacy_document_export_file(
App& app,
const pp::app::DocumentExportFileTarget& target);
[[nodiscard]] pp::foundation::Status execute_legacy_document_export_stem(
App& app,
pp::app::DocumentExportCollectionKind kind,
const pp::app::DocumentExportStemTarget& target);
[[nodiscard]] pp::foundation::Status execute_legacy_document_export_collection(
App& app,
pp::app::DocumentExportCollectionKind kind,
const pp::app::DocumentExportCollectionTarget& target);
[[nodiscard]] pp::foundation::Status execute_legacy_document_export_depth(
App& app,
std::string_view document_name);
[[nodiscard]] pp::foundation::Status execute_legacy_document_export_cube_faces(
App& app,
std::string_view document_name);
} // namespace pp::panopainter