Commit: cd6edde235d5a9b4acb34449dea17c8b5024b1d4
Author: Antonio Vazquez
Date:   Wed Aug 5 11:24:09 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBcd6edde235d5a9b4acb34449dea17c8b5024b1d4

GPencil: Split SVG modes in two operators

===================================================================

M       release/scripts/startup/bl_ui/space_topbar.py
M       source/blender/editors/io/io_gpencil.c
M       source/blender/editors/io/io_gpencil.h
M       source/blender/editors/io/io_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_topbar.py 
b/release/scripts/startup/bl_ui/space_topbar.py
index 6a830db135f..2648fc0f9e0 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -443,6 +443,16 @@ class TOPBAR_MT_file_import(Menu):
             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
 
 
+class TOPBAR_MT_file_gpencil_export(Menu):
+    bl_idname = "TOPBAR_MT_file_gpencil_export"
+    bl_label = "Grease Pencil"
+    bl_owner_use_filter = False
+
+    def draw(self, context):
+        self.layout.operator("wm.gpencil_export_svg", text="Scalable Vector 
Graphics (.svg)")
+        self.layout.operator("wm.gpencil_export_storyboard", text="Storyboard 
(.svg)")
+
+
 class TOPBAR_MT_file_export(Menu):
     bl_idname = "TOPBAR_MT_file_export"
     bl_label = "Export"
@@ -457,7 +467,8 @@ class TOPBAR_MT_file_export(Menu):
         if bpy.app.build_options.usd:
             self.layout.operator(
                 "wm.usd_export", text="Universal Scene Description (.usd, 
.usdc, .usda)")
-        self.layout.operator("wm.gpencil_export", text="Grease Pencil (.svg)")
+
+        self.layout.menu("TOPBAR_MT_file_gpencil_export")
 
 
 class TOPBAR_MT_file_external_data(Menu):
@@ -818,6 +829,7 @@ classes = (
     TOPBAR_MT_file_defaults,
     TOPBAR_MT_templates_more,
     TOPBAR_MT_file_import,
+    TOPBAR_MT_file_gpencil_export,
     TOPBAR_MT_file_export,
     TOPBAR_MT_file_external_data,
     TOPBAR_MT_file_cleanup,
diff --git a/source/blender/editors/io/io_gpencil.c 
b/source/blender/editors/io/io_gpencil.c
index 9a963ed191b..5692b1f04a4 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -66,30 +66,46 @@
 
 #include "gpencil_io_exporter.h"
 
-static int wm_gpencil_export_invoke(bContext *C, wmOperator *op, const wmEvent 
*event)
+static void gpencil_export_common_props(wmOperatorType *ot)
 {
-  UNUSED_VARS(event);
-
-  RNA_boolean_set(op->ptr, "init_scene_frame_range", true);
-
-  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
-    Main *bmain = CTX_data_main(C);
-    char filepath[FILE_MAX];
-
-    if (BKE_main_blendfile_path(bmain)[0] == '\0') {
-      BLI_strncpy(filepath, "untitled", sizeof(filepath));
-    }
-    else {
-      BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
-    }
-
-    BLI_path_extension_replace(filepath, sizeof(filepath), ".svg");
-    RNA_string_set(op->ptr, "filepath", filepath);
-  }
-
-  WM_event_add_fileselect(C, op);
+  static const EnumPropertyItem gpencil_export_select_items[] = {
+      {GP_EXPORT_ACTIVE, "ACTIVE", 0, "Active", "Include only active object"},
+      {GP_EXPORT_SELECTED, "SELECTED", 0, "Selected", "Include selected 
objects"},
+      {GP_EXPORT_VISIBLE, "VISIBLE", 0, "Visible", "Include visible objects"},
+      {0, NULL, 0, NULL, NULL},
+  };
+  RNA_def_boolean(ot->srna, "use_fill", true, "Fill", "Export filled areas");
+  RNA_def_boolean(ot->srna,
+                  "use_normalized_thickness",
+                  false,
+                  "Normalize",
+                  "Export strokes with constant thickness along the stroke");
+  ot->prop = RNA_def_enum(ot->srna,
+                          "selected_object_type",
+                          gpencil_export_select_items,
+                          0,
+                          "Object",
+                          "Objects included in the export");
 
-  return OPERATOR_RUNNING_MODAL;
+  RNA_def_boolean(ot->srna,
+                  "use_clip_camera",
+                  false,
+                  "Clip Camera",
+                  "Clip drawings to camera size when export in camera view");
+  RNA_def_boolean(ot->srna,
+                  "use_gray_scale",
+                  false,
+                  "Gray Scale",
+                  "Export in gray scale instead of full color");
+  RNA_def_float(ot->srna,
+                "stroke_sample",
+                0.0f,
+                0.0f,
+                100.0f,
+                "Sampling",
+                "Precision of sampling stroke, set to zero to disable",
+                0.0f,
+                100.0f);
 }
 
 static ARegion *get_invoke_region(bContext *C)
@@ -125,8 +141,71 @@ static View3D *get_invoke_view3d(bContext *C)
   return NULL;
 }
 
-static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
+static void ui_gpencil_export_common_settings(uiLayout *layout,
+                                              PointerRNA *imfptr,
+                                              const bool story)
+{
+  uiLayout *box, *row, *col, *sub;
+
+  box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("Export Options"), ICON_SCENE_DATA);
+
+  col = uiLayoutColumn(box, false);
+
+  sub = uiLayoutColumn(col, true);
+  uiItemR(sub, imfptr, "use_fill", 0, NULL, ICON_NONE);
+  uiItemR(sub, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
+  uiItemR(sub, imfptr, "use_gray_scale", 0, NULL, ICON_NONE);
+  if (!story) {
+    uiItemR(sub, imfptr, "use_clip_camera", 0, NULL, ICON_NONE);
+  }
+  uiItemR(sub, imfptr, "stroke_sample", 0, NULL, ICON_NONE);
+}
+
+static bool wm_gpencil_export_common_check(bContext *UNUSED(C), wmOperator *op)
+{
+
+  char filepath[FILE_MAX];
+  RNA_string_get(op->ptr, "filepath", filepath);
+
+  if (!BLI_path_extension_check(filepath, ".svg")) {
+    BLI_path_extension_ensure(filepath, FILE_MAX, ".svg");
+    RNA_string_set(op->ptr, "filepath", filepath);
+    return true;
+  }
+
+  return false;
+}
+
+/* <-------- SVG single frame export. --------> */
+static int wm_gpencil_export_svg_invoke(bContext *C, wmOperator *op, const 
wmEvent *event)
 {
+  UNUSED_VARS(event);
+
+  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+    Main *bmain = CTX_data_main(C);
+    char filepath[FILE_MAX];
+
+    if (BKE_main_blendfile_path(bmain)[0] == '\0') {
+      BLI_strncpy(filepath, "untitled", sizeof(filepath));
+    }
+    else {
+      BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
+    }
+
+    BLI_path_extension_replace(filepath, sizeof(filepath), ".svg");
+    RNA_string_set(op->ptr, "filepath", filepath);
+  }
+
+  WM_event_add_fileselect(C, op);
+
+  return OPERATOR_RUNNING_MODAL;
+}
+
+static int wm_gpencil_export_svg_exec(bContext *C, wmOperator *op)
+{
+  Scene *scene = CTX_data_scene(C);
   Object *ob = CTX_data_active_object(C);
 
   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -146,22 +225,184 @@ static int wm_gpencil_export_exec(bContext *C, 
wmOperator *op)
   char filename[FILE_MAX];
   RNA_string_get(op->ptr, "filepath", filename);
 
-  const bool use_storyboard = RNA_boolean_get(op->ptr, "use_storyboard");
   const bool use_fill = RNA_boolean_get(op->ptr, "use_fill");
   const bool use_norm_thickness = RNA_boolean_get(op->ptr, 
"use_normalized_thickness");
   const short select = RNA_enum_get(op->ptr, "selected_object_type");
 
   const bool use_clip_camera = RNA_boolean_get(op->ptr, "use_clip_camera");
   const bool use_gray_scale = RNA_boolean_get(op->ptr, "use_gray_scale");
-  const bool use_markers = RNA_boolean_get(op->ptr, "use_markers");
 
   /* Set flags. */
   int flag = 0;
-  SET_FLAG_FROM_TEST(flag, use_storyboard, GP_EXPORT_STORYBOARD_MODE);
   SET_FLAG_FROM_TEST(flag, use_fill, GP_EXPORT_FILL);
   SET_FLAG_FROM_TEST(flag, use_norm_thickness, GP_EXPORT_NORM_THICKNESS);
   SET_FLAG_FROM_TEST(flag, use_clip_camera, GP_EXPORT_CLIP_CAMERA);
   SET_FLAG_FROM_TEST(flag, use_gray_scale, GP_EXPORT_GRAY_SCALE);
+
+  struct GpencilExportParams params = {
+      .C = C,
+      .region = region,
+      .v3d = v3d,
+      .obact = ob,
+      .filename = filename,
+      .mode = GP_EXPORT_TO_SVG,
+      .frame_start = CFRA,
+      .frame_end = CFRA,
+      .flag = flag,
+      .select = select,
+      .stroke_sample = RNA_float_get(op->ptr, "stroke_sample"),
+      .page_layout = {0.0f, 0.0f},
+      .page_type = 0,
+      .paper_size = {0.0f, 0.0f},
+      .text_type = 0,
+
+  };
+
+  /* Do export. */
+  WM_cursor_wait(1);
+  bool done = gpencil_io_export(&params);
+  WM_cursor_wait(0);
+
+  if (done) {
+    BKE_report(op->reports, RPT_INFO, "SVG export file created");
+  }
+  else {
+    BKE_report(op->reports, RPT_WARNING, "Unable to export SVG");
+  }
+
+  return OPERATOR_FINISHED;
+}
+
+static void ui_gpencil_export_svg_settings(uiLayout *layout, PointerRNA 
*imfptr)
+{
+  uiLayout *box, *row;
+
+  uiLayoutSetPropSep(layout, true);
+  uiLayoutSetPropDecorate(layout, false);
+
+  box = uiLayoutBox(layout);
+
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("Scene Options"), ICON_SCENE_DATA);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "selected_object_type", 0, NULL, ICON_NONE);
+
+  ui_gpencil_export_common_settings(layout, imfptr, false);
+}
+
+static void wm_gpencil_export_svg_draw(bContext *C, wmOperator *op)
+{
+
+  PointerRNA ptr;
+
+  RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+
+  ui_gpencil_export_svg_settings(op->layout, &ptr);
+}
+
+static bool wm_gpencil_export_svg_poll(bContext *C)
+{
+  if (CTX_wm_window(C) == NULL) {
+    return false;
+  }
+  Object *ob = CTX_data_active_object(C);
+  if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
+    return false;
+  }
+
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
+
+  if (gpl == NULL) {
+    return false;
+  }
+
+  return true;
+}
+
+void WM_OT_gpencil_export_svg(wmOperatorType *ot)
+{
+  ot->name = "Export to SVG";
+  ot->description = "Export grease pencil";
+  ot->idname = "WM_OT_gpencil_export_svg";
+
+  ot->invoke = wm_gpencil_export_svg_invoke;
+  ot->exec = wm_gpencil_export_svg_exec;
+  ot->poll = wm_gpencil_export_svg_poll;
+  ot->ui = wm_gpencil_export_svg_draw;
+  ot->check = wm_gpencil_export_common_check;
+
+  WM_operator_properties_filesel(ot,
+                                 FILE_TYPE_OBJECT_IO,
+                                 FILE_BLENDER,
+                                 FILE_SAVE,
+                                 WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
+                                 FILE_DEFAULTDISPLAY,
+                                 FILE_SORT_ALPHA);
+
+  gpenci

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to