9#ifdef WITH_IO_GREASE_PENCIL
46# if defined(WITH_PUGIXML) || defined(WITH_HARU)
50static void grease_pencil_export_common_props_definition(wmOperatorType *ot)
52 using blender::io::grease_pencil::ExportParams;
53 using SelectMode = ExportParams::SelectMode;
54 using FrameMode = ExportParams::FrameMode;
56 static const EnumPropertyItem select_mode_items[] = {
57 {int(SelectMode::Active),
"ACTIVE", 0,
"Active",
"Include only the active object"},
58 {int(SelectMode::Selected),
"SELECTED", 0,
"Selected",
"Include selected objects"},
59 {int(SelectMode::Visible),
"VISIBLE", 0,
"Visible",
"Include all visible objects"},
60 {0,
nullptr, 0,
nullptr,
nullptr},
63 static const EnumPropertyItem frame_mode_items[] = {
64 {int(FrameMode::Active),
"ACTIVE", 0,
"Active",
"Include only active frame"},
65 {int(FrameMode::Selected),
"SELECTED", 0,
"Selected",
"Include selected frames"},
66 {int(FrameMode::Scene),
"SCENE", 0,
"Scene",
"Include all scene frames"},
67 {0,
nullptr, 0,
nullptr,
nullptr},
70 RNA_def_boolean(ot->srna,
"use_fill",
true,
"Fill",
"Export strokes with fill enabled");
72 "selected_object_type",
74 int(SelectMode::Active),
76 "Which objects to include in the export");
80 int(FrameMode::Active),
82 "Which frames to include in the export");
89 "Precision of stroke sampling. Low values mean a more precise result, and zero "
94 ot->srna,
"use_uniform_width",
false,
"Uniform Width",
"Export strokes with uniform width");
102static bool get_invoke_region(bContext *
C,
105 RegionView3D **r_rv3d)
108 if (screen ==
nullptr) {
112 if (area ==
nullptr) {
118 *r_view3d = area->spacedata.first_as<View3D>();
119 *r_rv3d =
static_cast<RegionView3D *
>(region->regiondata);
131static bool grease_pencil_import_svg_check(bContext * , wmOperator *op)
145static wmOperatorStatus grease_pencil_import_svg_exec(bContext *
C, wmOperator *op)
147 using blender::io::grease_pencil::ImportParams;
148 using blender::io::grease_pencil::IOContext;
162 if (!get_invoke_region(
C, ®ion, &v3d, &rv3d)) {
167 const int resolution =
RNA_int_get(op->ptr,
"resolution");
169 const bool use_scene_unit =
RNA_boolean_get(op->ptr,
"use_scene_unit");
170 const bool recenter_bounds =
RNA_boolean_get(op->ptr,
"recenter_bounds");
172 const IOContext io_context(*
C, region, v3d, rv3d, op->reports);
173 const ImportParams params = {
scale, scene->r.cfra, resolution, use_scene_unit, recenter_bounds};
178 for (
const auto &path : paths) {
192static void grease_pencil_import_svg_draw(bContext * , wmOperator *op)
194 ui::Layout &layout = *op->layout;
195 layout.use_property_split_set(
true);
196 layout.use_property_decorate_set(
false);
197 ui::Layout &col = layout.box().column(
false);
198 col.prop(op->ptr,
"resolution",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
199 col.prop(op->ptr,
"scale",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
200 col.prop(op->ptr,
"use_scene_unit",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
201 col.prop(op->ptr,
"recenter_bounds",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
204static bool grease_pencil_import_svg_poll(bContext *
C)
217 ot->name =
"Import SVG as Grease Pencil";
218 ot->description =
"Import SVG into Grease Pencil";
219 ot->idname =
"WM_OT_grease_pencil_import_svg";
222 ot->exec = ed::io::grease_pencil_import_svg_exec;
223 ot->poll = ed::io::grease_pencil_import_svg_poll;
224 ot->ui = ed::io::grease_pencil_import_svg_draw;
225 ot->check = ed::io::grease_pencil_import_svg_check;
244 "Resolution of the generated strokes",
254 "Scale of the final strokes",
262 "Apply current scene's unit (as defined by unit scale) to imported data");
268 "Center the imported SVG on its bounding box");
281static bool grease_pencil_export_svg_check(bContext * , wmOperator *op)
306static wmOperatorStatus grease_pencil_export_svg_exec(bContext *
C, wmOperator *op)
308 using blender::io::grease_pencil::ExportParams;
310 using blender::io::grease_pencil::IOContext;
323 if (!get_invoke_region(
C, ®ion, &v3d, &rv3d)) {
331 const bool export_stroke_materials =
true;
332 const bool export_fill_materials =
RNA_boolean_get(op->ptr,
"use_fill");
333 const bool use_uniform_width =
RNA_boolean_get(op->ptr,
"use_uniform_width");
334 const ExportParams::SelectMode select_mode = ExportParams::SelectMode(
336 const ExportParams::FrameMode frame_mode = ExportParams::FrameMode(
338 const bool use_clip_camera =
RNA_boolean_get(op->ptr,
"use_clip_camera");
339 const float stroke_sample =
RNA_float_get(op->ptr,
"stroke_sample");
341 const IOContext io_context(*
C, region, v3d, rv3d, op->reports);
342 const ExportParams params = {ob,
345 export_stroke_materials,
346 export_fill_materials,
353 io_context, params, *scene, filepath);
357 case ExportStatus::Ok:
359 case ExportStatus::InvalidActiveObjectType:
362 case ExportStatus::NoFramesSelected:
365 case ExportStatus::FileWriteError:
368 case ExportStatus::UnknownError:
376enum class GreasePencilExportFiletype {
386static void ui_gpencil_export_settings(ui::Layout &layout,
388 GreasePencilExportFiletype file_type)
390 layout.use_property_split_set(
true);
391 layout.use_property_decorate_set(
false);
393 ui::Layout *box = &layout.box();
395 ui::Layout *row = &box->row(
false);
396 row->label(
IFACE_(
"Scene Options"), ICON_NONE);
398 row = &box->row(
false);
399 row->prop(ptr,
"selected_object_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
402 row = &box->row(
false);
403 row->label(
IFACE_(
"Export Options"), ICON_NONE);
405 ui::Layout &col = box->column(
false);
406 ui::Layout *sub = &col.column(
false);
409 box->use_property_split_set(
true);
411 sub = &col.column(
true);
412 sub->prop(ptr,
"stroke_sample",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
413 sub->prop(ptr,
"use_fill",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
414 sub->prop(ptr,
"use_uniform_width",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
416 if (file_type == GreasePencilExportFiletype::SVG) {
417 col.prop(ptr,
"use_clip_camera",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
421static void grease_pencil_export_svg_draw(bContext * , wmOperator *op)
423 ui_gpencil_export_settings(*op->layout, op->ptr, GreasePencilExportFiletype::SVG);
426static bool grease_pencil_export_svg_poll(bContext *
C)
439 ot->name =
"Export to SVG";
440 ot->description =
"Export Grease Pencil to SVG";
441 ot->idname =
"WM_OT_grease_pencil_export_svg";
443 ot->invoke = ed::io::grease_pencil_export_svg_invoke;
444 ot->exec = ed::io::grease_pencil_export_svg_exec;
445 ot->poll = ed::io::grease_pencil_export_svg_poll;
446 ot->ui = ed::io::grease_pencil_export_svg_draw;
447 ot->check = ed::io::grease_pencil_export_svg_check;
459 ed::io::grease_pencil_export_common_props_definition(ot);
465 "Clip drawings to camera size when exporting in camera view");
480static bool grease_pencil_export_pdf_check(bContext * , wmOperator *op)
506static wmOperatorStatus grease_pencil_export_pdf_exec(bContext *
C, wmOperator *op)
508 using blender::io::grease_pencil::ExportParams;
509 using blender::io::grease_pencil::IOContext;
522 if (!get_invoke_region(
C, ®ion, &v3d, &rv3d)) {
530 const bool export_stroke_materials =
true;
531 const bool export_fill_materials =
RNA_boolean_get(op->ptr,
"use_fill");
532 const bool use_uniform_width =
RNA_boolean_get(op->ptr,
"use_uniform_width");
533 const ExportParams::SelectMode select_mode = ExportParams::SelectMode(
535 const ExportParams::FrameMode frame_mode = ExportParams::FrameMode(
537 const bool use_clip_camera =
false;
538 const float stroke_sample =
RNA_float_get(op->ptr,
"stroke_sample");
540 const IOContext io_context(*
C, region, v3d, rv3d, op->reports);
541 const ExportParams params = {ob,
544 export_stroke_materials,
545 export_fill_materials,
561static void grease_pencil_export_pdf_draw(bContext * , wmOperator *op)
563 ui_gpencil_export_settings(*op->layout, op->ptr, GreasePencilExportFiletype::PDF);
566static bool grease_pencil_export_pdf_poll(bContext *
C)
579 ot->name =
"Export to PDF";
580 ot->description =
"Export Grease Pencil to PDF";
581 ot->idname =
"WM_OT_grease_pencil_export_pdf";
583 ot->invoke = ed::io::grease_pencil_export_pdf_invoke;
584 ot->exec = ed::io::grease_pencil_export_pdf_exec;
585 ot->poll = ed::io::grease_pencil_export_pdf_poll;
586 ot->ui = ed::io::grease_pencil_export_pdf_draw;
587 ot->check = ed::io::grease_pencil_export_pdf_check;
599 using blender::io::grease_pencil::ExportParams;
601 ed::io::grease_pencil_export_common_props_definition(ot);
612 auto fh = std::make_unique<bke::FileHandlerType>();
614 STRNCPY_UTF8(fh->import_operator,
"WM_OT_grease_pencil_import_svg");
#define STRNCPY_UTF8(dst, src)
#define BLI_assert_unreachable()
float3x3 scale(float3x3 mat, float2 scale)
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
bool poll_file_object_drop(const bContext *C, bke::FileHandlerType *)
void grease_pencil_file_handler_add()
Vector< std::string > paths_from_operator_properties(PointerRNA *ptr)
wmOperatorStatus filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
bool import_svg(const IOContext &context, const ImportParams ¶ms, StringRefNull filepath)
ExportStatus export_svg(const IOContext &context, const ExportParams ¶ms, Scene &scene, StringRefNull filepath)
bool export_pdf(const IOContext &context, const ExportParams ¶ms, Scene &scene, StringRefNull filepath)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmWindow * CTX_wm_window(const bContext *C)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
void BKE_report(ReportList *reports, eReportType type, const char *message)
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
void WM_OT_grease_pencil_import_svg(wmOperatorType *ot)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void WM_cursor_wait(bool val)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
float RNA_float_get(PointerRNA *ptr, const char *name)
void WM_event_add_fileselect(bContext *C, wmOperator *op)