[Bf-blender-cvs] [7b65016444e] greasepencil-object: GPencil: Basic structure of layers

Antonio Vazquez noreply at git.blender.org
Sat Jul 25 16:33:28 CEST 2020


Commit: 7b65016444e512fa2146eae95d53c24790cd05a3
Author: Antonio Vazquez
Date:   Fri Jul 24 21:07:17 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB7b65016444e512fa2146eae95d53c24790cd05a3

GPencil: Basic structure of layers

The problem was the Region was NULL, but now using a function the region is right.

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

M	source/blender/editors/io/io_gpencil.c
M	source/blender/io/gpencil/gpencil_io_exporter.h
M	source/blender/io/gpencil/intern/gpencil_io_svg.cc

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

diff --git a/source/blender/editors/io/io_gpencil.c b/source/blender/editors/io/io_gpencil.c
index 7c586ff4787..04d93cfc9aa 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -40,6 +40,7 @@
 #include "BKE_gpencil.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
+#include "BKE_screen.h"
 
 #include "BLI_listbase.h"
 #include "BLI_path_util.h"
@@ -65,12 +66,6 @@ static int wm_gpencil_export_invoke(bContext *C, wmOperator *op, const wmEvent *
 {
   UNUSED_VARS(event);
 
-  RegionView3D *rv3d = CTX_wm_region_view3d(C);
-
-  // if (!RNA_struct_property_is_set(op->ptr, "as_background_job")) {
-  //  RNA_boolean_set(op->ptr, "as_background_job", true);
-  //}
-
   RNA_boolean_set(op->ptr, "init_scene_frame_range", true);
 
   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -93,6 +88,21 @@ static int wm_gpencil_export_invoke(bContext *C, wmOperator *op, const wmEvent *
   return OPERATOR_RUNNING_MODAL;
 }
 
+static ARegion *get_invoke_region(bContext *C)
+{
+  bScreen *screen = CTX_wm_screen(C);
+  if (screen == NULL) {
+    return NULL;
+  }
+  ScrArea *area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
+  if (area == NULL) {
+    return NULL;
+  }
+  ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
+
+  return region;
+}
+
 static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
 {
   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -100,12 +110,21 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
+  /*For some reason the region cannot be retrieved from the context.
+   * If a better solution is found in the future, remove this function. */
+  ARegion *region = get_invoke_region(C);
+  if (region == NULL) {
+    BKE_report(op->reports, RPT_ERROR, "Unable to find valid 3D View area");
+    return OPERATOR_CANCELLED;
+  }
+
   char filename[FILE_MAX];
   RNA_string_get(op->ptr, "filepath", filename);
   Object *ob = CTX_data_active_object(C);
 
   struct GpencilExportParams params = {
       .C = C,
+      .region = region,
       .ob = ob,
       .filename = filename,
       .mode = GP_EXPORT_TO_SVG,
@@ -180,7 +199,7 @@ static bool wm_gpencil_export_check(bContext *UNUSED(C), wmOperator *op)
   return false;
 }
 
-bool wm_gpencil_export_poll(bContext *C)
+static bool wm_gpencil_export_poll(bContext *C)
 {
   if (CTX_wm_window(C) == NULL) {
     return false;
@@ -213,7 +232,7 @@ void WM_OT_gpencil_export(wmOperatorType *ot)
   ot->check = wm_gpencil_export_check;
 
   WM_operator_properties_filesel(ot,
-                                 FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC,
+                                 FILE_TYPE_FOLDER | FILE_TYPE_OBJECT_IO,
                                  FILE_BLENDER,
                                  FILE_SAVE,
                                  WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/gpencil_io_exporter.h
index d71cf505a79..c409d289253 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -25,6 +25,7 @@ extern "C" {
 
 struct Scene;
 struct bContext;
+struct ARegion;
 
 typedef enum eGpencilExport_Modes {
   GP_EXPORT_TO_SVG = 0,
@@ -32,6 +33,7 @@ typedef enum eGpencilExport_Modes {
 
 struct GpencilExportParams {
   bContext *C;
+  ARegion *region;
   /** Grease pencil object. */
   struct Object *ob;
   /** Output filename.  */
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 42693946a8a..0bd689c2426 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -62,39 +62,19 @@ void GpencilExporter::set_out_filename(struct bContext *C, char *filename)
   //#endif
 }
 
-static ARegion *get_3d_region(struct bContext *C)
-{
-  bScreen *screen = CTX_wm_screen(C);
-  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-    LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
-      if (region->regiontype == RGN_TYPE_WINDOW) {
-        return region;
-      }
-    }
-    // LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
-    //  if (sl->spacetype == SPACE_VIEW3D) {
-    //    return (ARegion *)sl->regionbase.first;
-    //  }
-    //}
-  }
-
-  return CTX_wm_region(C);
-}
-
 /* Constructor. */
 GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams *params)
 {
   this->params.frame_start = params->frame_start;
   this->params.frame_end = params->frame_end;
   this->params.ob = params->ob;
+  this->region = params->region;
   this->params.C = params->C;
   this->params.filename = params->filename;
   this->params.mode = params->mode;
 
   /* Prepare output filename with full path. */
   set_out_filename(params->C, params->filename);
-
-  this->region = get_3d_region(params->C);
 }
 
 /* Convert to screen space.



More information about the Bf-blender-cvs mailing list