9#ifdef WITH_IO_GREASE_PENCIL
44# if defined(WITH_PUGIXML) || defined(WITH_HARU)
48static void grease_pencil_export_common_props_definition(wmOperatorType *
ot)
50 using blender::io::grease_pencil::ExportParams;
51 using SelectMode = ExportParams::SelectMode;
52 using FrameMode = ExportParams::FrameMode;
54 static const EnumPropertyItem select_mode_items[] = {
55 {int(SelectMode::Active),
"ACTIVE", 0,
"Active",
"Include only the active object"},
56 {int(SelectMode::Selected),
"SELECTED", 0,
"Selected",
"Include selected objects"},
57 {int(SelectMode::Visible),
"VISIBLE", 0,
"Visible",
"Include all visible objects"},
58 {0,
nullptr, 0,
nullptr,
nullptr},
61 static const EnumPropertyItem frame_mode_items[] = {
62 {int(FrameMode::Active),
"ACTIVE", 0,
"Active",
"Include only active frame"},
63 {int(FrameMode::Selected),
"SELECTED", 0,
"Selected",
"Include selected frames"},
64 {int(FrameMode::Scene),
"SCENE", 0,
"Scene",
"Include all scene frames"},
65 {0,
nullptr, 0,
nullptr,
nullptr},
70 "selected_object_type",
72 int(SelectMode::Active),
74 "Which objects to include in the export");
78 int(FrameMode::Active),
80 "Which frames to include in the export");
87 "Precision of stroke sampling. Low values mean a more precise result, and zero "
92 ot->
srna,
"use_uniform_width",
false,
"Uniform Width",
"Export strokes with uniform width");
100static bool get_invoke_region(bContext *
C,
106 if (screen ==
nullptr) {
110 if (area ==
nullptr) {
129static bool grease_pencil_import_svg_check(bContext * ,
wmOperator *op)
145 using blender::io::grease_pencil::ImportParams;
146 using blender::io::grease_pencil::IOContext;
160 if (!get_invoke_region(
C, ®ion, &v3d, &rv3d)) {
168 const bool recenter_bounds =
true;
170 const IOContext io_context(*
C, region, v3d, rv3d, op->
reports);
171 const ImportParams
params = {
scale, scene->
r.
cfra, resolution, use_scene_unit, recenter_bounds};
176 for (
const auto &path : paths) {
190static void grease_pencil_import_svg_draw(bContext * ,
wmOperator *op)
192 uiLayout *layout = op->
layout;
195 uiLayout *box = &layout->
box();
201static bool grease_pencil_import_svg_poll(bContext *
C)
214 ot->name =
"Import SVG as Grease Pencil";
215 ot->description =
"Import SVG into Grease Pencil";
216 ot->idname =
"WM_OT_grease_pencil_import_svg";
219 ot->exec = blender::ed::io::grease_pencil_import_svg_exec;
220 ot->poll = blender::ed::io::grease_pencil_import_svg_poll;
221 ot->ui = blender::ed::io::grease_pencil_import_svg_draw;
222 ot->check = blender::ed::io::grease_pencil_import_svg_check;
239 "Resolution of the generated strokes",
249 "Scale of the final strokes",
257 "Apply current scene's unit (as defined by unit scale) to imported data");
270static bool grease_pencil_export_svg_check(bContext * ,
wmOperator *op)
297 using blender::io::grease_pencil::ExportParams;
299 using blender::io::grease_pencil::IOContext;
312 if (!get_invoke_region(
C, ®ion, &v3d, &rv3d)) {
320 const bool export_stroke_materials =
true;
323 const ExportParams::SelectMode select_mode = ExportParams::SelectMode(
325 const ExportParams::FrameMode frame_mode = ExportParams::FrameMode(
330 const IOContext io_context(*
C, region, v3d, rv3d, op->
reports);
331 const ExportParams
params = {ob,
334 export_stroke_materials,
335 export_fill_materials,
342 io_context,
params, *scene, filepath);
346 case ExportStatus::Ok:
348 case ExportStatus::InvalidActiveObjectType:
351 case ExportStatus::NoFramesSelected:
354 case ExportStatus::FileWriteError:
357 case ExportStatus::UnknownError:
365enum class GreasePencilExportFiletype {
375static void ui_gpencil_export_settings(uiLayout *layout,
377 GreasePencilExportFiletype file_type)
379 uiLayout *box, *row, *
col, *sub;
384 box = &layout->
box();
386 row = &box->
row(
false);
389 row = &box->
row(
false);
392 box = &layout->
box();
393 row = &box->
row(
false);
407 if (file_type == GreasePencilExportFiletype::SVG) {
412static void grease_pencil_export_svg_draw(bContext * ,
wmOperator *op)
414 ui_gpencil_export_settings(op->
layout, op->
ptr, GreasePencilExportFiletype::SVG);
417static bool grease_pencil_export_svg_poll(bContext *
C)
430 ot->name =
"Export to SVG";
431 ot->description =
"Export Grease Pencil to SVG";
432 ot->idname =
"WM_OT_grease_pencil_export_svg";
434 ot->invoke = blender::ed::io::grease_pencil_export_svg_invoke;
435 ot->exec = blender::ed::io::grease_pencil_export_svg_exec;
436 ot->poll = blender::ed::io::grease_pencil_export_svg_poll;
437 ot->ui = blender::ed::io::grease_pencil_export_svg_draw;
438 ot->check = blender::ed::io::grease_pencil_export_svg_check;
448 blender::ed::io::grease_pencil_export_common_props_definition(
ot);
454 "Clip drawings to camera size when exporting in camera view");
469static bool grease_pencil_export_pdf_check(bContext * ,
wmOperator *op)
497 using blender::io::grease_pencil::ExportParams;
498 using blender::io::grease_pencil::IOContext;
511 if (!get_invoke_region(
C, ®ion, &v3d, &rv3d)) {
519 const bool export_stroke_materials =
true;
522 const ExportParams::SelectMode select_mode = ExportParams::SelectMode(
524 const ExportParams::FrameMode frame_mode = ExportParams::FrameMode(
526 const bool use_clip_camera =
false;
529 const IOContext io_context(*
C, region, v3d, rv3d, op->
reports);
530 const ExportParams
params = {ob,
533 export_stroke_materials,
534 export_fill_materials,
550static void grease_pencil_export_pdf_draw(bContext * ,
wmOperator *op)
552 ui_gpencil_export_settings(op->
layout, op->
ptr, GreasePencilExportFiletype::PDF);
555static bool grease_pencil_export_pdf_poll(bContext *
C)
568 ot->name =
"Export to PDF";
569 ot->description =
"Export Grease Pencil to PDF";
570 ot->idname =
"WM_OT_grease_pencil_export_pdf";
572 ot->invoke = blender::ed::io::grease_pencil_export_pdf_invoke;
573 ot->exec = blender::ed::io::grease_pencil_export_pdf_exec;
574 ot->poll = blender::ed::io::grease_pencil_export_pdf_poll;
575 ot->ui = blender::ed::io::grease_pencil_export_pdf_draw;
576 ot->check = blender::ed::io::grease_pencil_export_pdf_check;
588 blender::ed::io::grease_pencil_export_common_props_definition(
ot);
599 auto fh = std::make_unique<blender::bke::FileHandlerType>();
601 STRNCPY_UTF8(fh->import_operator,
"WM_OT_grease_pencil_import_svg");
bScreen * CTX_wm_screen(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
#define BLI_assert_unreachable()
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
#define STRNCPY_UTF8(dst, src)
struct RegionView3D RegionView3D
struct wmOperator wmOperator
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
void WM_OT_grease_pencil_import_svg(wmOperatorType *ot)
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
bool poll_file_object_drop(const bContext *C, blender::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)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
int RNA_int_get(PointerRNA *ptr, const char *name)
float RNA_float_get(PointerRNA *ptr, const char *name)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
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)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
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 use_property_decorate_set(bool is_sep)
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
uiLayout & row(bool align)
void use_property_split_set(bool value)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
struct ReportList * reports
void WM_cursor_wait(bool val)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
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)