Extract image import route planning
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "app_core/document_animation.h"
|
||||
#include "app_core/document_canvas.h"
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_import.h"
|
||||
#include "app_core/document_cloud.h"
|
||||
#include "app_core/document_layer.h"
|
||||
#include "app_core/document_platform_io.h"
|
||||
@@ -235,6 +236,11 @@ struct PlanCanvasClearArgs {
|
||||
float a = 0.0F;
|
||||
};
|
||||
|
||||
struct PlanImageImportArgs {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
struct PlanLayerRenameArgs {
|
||||
std::string old_name = "Layer 1";
|
||||
std::string new_name;
|
||||
@@ -488,6 +494,18 @@ const char* document_open_plan_action_name(pp::app::DocumentOpenPlanAction actio
|
||||
return "open-project-now";
|
||||
}
|
||||
|
||||
const char* document_image_import_action_name(pp::app::DocumentImageImportAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
case pp::app::DocumentImageImportAction::import_equirectangular:
|
||||
return "import-equirectangular";
|
||||
case pp::app::DocumentImageImportAction::place_transform:
|
||||
return "place-transform";
|
||||
}
|
||||
|
||||
return "place-transform";
|
||||
}
|
||||
|
||||
const char* close_request_decision_name(pp::app::CloseRequestDecision decision) noexcept
|
||||
{
|
||||
switch (decision) {
|
||||
@@ -1015,6 +1033,7 @@ void print_help()
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N]\n"
|
||||
<< " plan-canvas-clear [--no-canvas] [--r N] [--g N] [--b N] [--a N]\n"
|
||||
<< " plan-image-import --width N --height N\n"
|
||||
<< " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n"
|
||||
<< " plan-layer-rename --old-name NAME --new-name NAME\n"
|
||||
<< " plan-layer-operation --kind add|duplicate|select|reorder|remove|opacity|visibility|alpha-lock|blend-mode|highlight [--layer-count N] [--index N] [--from-index N] [--to-index N] [--source-index N] [--name NAME] [--opacity N] [--blend-mode N] [--enabled]\n"
|
||||
@@ -2692,6 +2711,62 @@ int plan_canvas_clear(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_image_import_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanImageImportArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--width" || key == "--height") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_i32_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
if (key == "--width") {
|
||||
args.width = value.value();
|
||||
} else {
|
||||
args.height = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_image_import(int argc, char** argv)
|
||||
{
|
||||
PlanImageImportArgs args;
|
||||
const auto status = parse_plan_image_import_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-image-import", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto plan = pp::app::plan_document_image_import(args.width, args.height);
|
||||
if (!plan) {
|
||||
print_error("plan-image-import", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-image-import\""
|
||||
<< ",\"state\":{\"width\":" << args.width
|
||||
<< ",\"height\":" << args.height
|
||||
<< "},\"plan\":{\"width\":" << value.width
|
||||
<< ",\"height\":" << value.height
|
||||
<< ",\"action\":\"" << document_image_import_action_name(value.action)
|
||||
<< "\",\"importsEquirectangular\":" << json_bool(value.imports_equirectangular)
|
||||
<< ",\"entersTransformMode\":" << json_bool(value.enters_transform_mode)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_layer_rename_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -6086,6 +6161,10 @@ int main(int argc, char** argv)
|
||||
return plan_canvas_clear(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-image-import") {
|
||||
return plan_image_import(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-layer-rename") {
|
||||
return plan_layer_rename(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user