[Bf-blender-cvs] [c2d75a0386c] temp-gpencil-io: First round of code cleanup after review

Antonio Vazquez noreply at git.blender.org
Wed Mar 3 13:16:12 CET 2021


Commit: c2d75a0386cb442a712aea18d3f2098f43e9a39c
Author: Antonio Vazquez
Date:   Wed Mar 3 12:05:53 2021 +0100
Branches: temp-gpencil-io
https://developer.blender.org/rBc2d75a0386cb442a712aea18d3f2098f43e9a39c

First round of code cleanup after review

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

M	source/blender/editors/io/io_gpencil_export.c
M	source/blender/editors/io/io_gpencil_import.c
M	source/blender/editors/io/io_gpencil_utils.c
M	source/blender/io/gpencil/gpencil_io.h
M	source/blender/io/gpencil/intern/gpencil_io_base.cc
M	source/blender/io/gpencil/intern/gpencil_io_base.h
M	source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
M	source/blender/io/gpencil/intern/gpencil_io_export_svg.cc

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

diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c
index 9c409ccf3ff..1b8cb1ae0e4 100644
--- a/source/blender/editors/io/io_gpencil_export.c
+++ b/source/blender/editors/io/io_gpencil_export.c
@@ -61,20 +61,17 @@
 
 static void ui_gpencil_export_common_settings(uiLayout *layout, PointerRNA *imfptr)
 {
-  uiLayout *box, *row, *col, *sub;
+  uiLayout *box, *row, *col;
 
   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, "stroke_sample", 0, NULL, ICON_NONE);
-  uiItemR(sub, imfptr, "use_fill", 0, NULL, ICON_NONE);
-  uiItemR(sub, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
-
-  uiItemR(sub, imfptr, "use_clip_camera", 0, NULL, ICON_NONE);
+  uiItemR(col, imfptr, "stroke_sample", 0, NULL, ICON_NONE);
+  uiItemR(col, imfptr, "use_fill", 0, NULL, ICON_NONE);
+  uiItemR(col, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
+  uiItemR(col, imfptr, "use_clip_camera", 0, NULL, ICON_NONE);
 }
 
 /* <-------- SVG single frame export. --------> */
@@ -120,11 +117,6 @@ static void gpencil_export_common_props_svg(wmOperatorType *ot)
                   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",
@@ -185,7 +177,7 @@ static int wm_gpencil_export_svg_exec(bContext *C, wmOperator *op)
 
   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_mode = RNA_enum_get(op->ptr, "selected_object_type");
+  const eGpencilExportSelect select_mode = RNA_enum_get(op->ptr, "selected_object_type");
 
   const bool use_clip_camera = RNA_boolean_get(op->ptr, "use_clip_camera");
 
@@ -211,9 +203,9 @@ static int wm_gpencil_export_svg_exec(bContext *C, wmOperator *op)
                                    .resolution = 1.0f};
 
   /* Do export. */
-  WM_cursor_wait(1);
+  WM_cursor_wait(true);
   bool done = gpencil_io_export(filename, &params);
-  WM_cursor_wait(0);
+  WM_cursor_wait(false);
 
   if (done) {
     BKE_report(op->reports, RPT_INFO, "SVG export file created");
@@ -390,14 +382,11 @@ static int wm_gpencil_export_pdf_exec(bContext *C, wmOperator *op)
                                    .resolution = 1.0f};
 
   /* Do export. */
-  WM_cursor_wait(1);
+  WM_cursor_wait(true);
   bool done = gpencil_io_export(filename, &params);
-  WM_cursor_wait(0);
+  WM_cursor_wait(false);
 
-  if (done) {
-    BKE_report(op->reports, RPT_INFO, "PDF export file created");
-  }
-  else {
+  if (!done) {
     BKE_report(op->reports, RPT_WARNING, "Unable to export PDF");
   }
 
diff --git a/source/blender/editors/io/io_gpencil_import.c b/source/blender/editors/io/io_gpencil_import.c
index 0b0cc1ab228..1a50c2221d6 100644
--- a/source/blender/editors/io/io_gpencil_import.c
+++ b/source/blender/editors/io/io_gpencil_import.c
@@ -78,63 +78,6 @@ bool wm_gpencil_import_svg_common_check(bContext *UNUSED(C), wmOperator *op)
   return false;
 }
 
-static void gpencil_import_common_props(wmOperatorType *ot)
-{
-  PropertyRNA *prop;
-
-  static const EnumPropertyItem target_object_modes[] = {
-      {GP_TARGET_OB_NEW, "NEW", 0, "New Object", ""},
-      {GP_TARGET_OB_SELECTED, "ACTIVE", 0, "Active Object", ""},
-      {0, NULL, 0, NULL, NULL},
-  };
-
-  prop = RNA_def_enum(ot->srna,
-                      "target",
-                      target_object_modes,
-                      GP_TARGET_OB_NEW,
-                      "Target Object",
-                      "Target grease pencil object");
-
-  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-  RNA_def_int(ot->srna,
-              "resolution",
-              10,
-              1,
-              30,
-              "Resolution",
-              "Resolution of the generated curves",
-              1,
-              20);
-
-  RNA_def_float(ot->srna,
-                "scale",
-                10.0f,
-                0.001f,
-                100.0f,
-                "Scale",
-                "Scale of the final stroke",
-                0.001f,
-                100.0f);
-}
-
-static void ui_gpencil_import_common_settings(uiLayout *layout, PointerRNA *imfptr)
-{
-  uiLayout *box, *row, *col, *sub;
-
-  box = uiLayoutBox(layout);
-  row = uiLayoutRow(box, false);
-  uiItemL(row, IFACE_("Import Options"), ICON_SCENE_DATA);
-
-  col = uiLayoutColumn(box, false);
-
-  sub = uiLayoutColumn(col, true);
-  uiItemR(sub, imfptr, "target", 0, NULL, ICON_NONE);
-  sub = uiLayoutColumn(col, true);
-  uiItemR(sub, imfptr, "resolution", 0, NULL, ICON_NONE);
-  sub = uiLayoutColumn(col, true);
-  uiItemR(sub, imfptr, "scale", 0, NULL, ICON_NONE);
-}
-
 static int wm_gpencil_import_svg_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
   UNUSED_VARS(event);
@@ -218,14 +161,19 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
 
 static void ui_gpencil_import_svg_settings(uiLayout *layout, PointerRNA *imfptr)
 {
-  uiLayout *box;
+  uiLayout *box, *row, *col;
 
   uiLayoutSetPropSep(layout, true);
   uiLayoutSetPropDecorate(layout, false);
 
   box = uiLayoutBox(layout);
+  row = uiLayoutRow(box, false);
+  uiItemL(row, IFACE_("Import Options"), ICON_SCENE_DATA);
 
-  ui_gpencil_import_common_settings(layout, imfptr);
+  col = uiLayoutColumn(box, false);
+  uiItemR(col, imfptr, "target", 0, NULL, ICON_NONE);
+  uiItemR(col, imfptr, "resolution", 0, NULL, ICON_NONE);
+  uiItemR(col, imfptr, "scale", 0, NULL, ICON_NONE);
 }
 
 static void wm_gpencil_import_svg_draw(bContext *UNUSED(C), wmOperator *op)
@@ -249,6 +197,14 @@ static bool wm_gpencil_import_svg_poll(bContext *C)
 
 void WM_OT_gpencil_import_svg(wmOperatorType *ot)
 {
+  PropertyRNA *prop;
+
+  static const EnumPropertyItem target_object_modes[] = {
+      {GP_TARGET_OB_NEW, "NEW", 0, "New Object", ""},
+      {GP_TARGET_OB_SELECTED, "ACTIVE", 0, "Active Object", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   ot->name = "Import SVG";
   ot->description = "Import SVG into grease pencil";
   ot->idname = "WM_OT_gpencil_import_svg";
@@ -267,5 +223,31 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot)
                                  FILE_DEFAULTDISPLAY,
                                  FILE_SORT_DEFAULT);
 
-  gpencil_import_common_props(ot);
+  prop = RNA_def_enum(ot->srna,
+                      "target",
+                      target_object_modes,
+                      GP_TARGET_OB_NEW,
+                      "Target Object",
+                      "Target grease pencil object");
+
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+  RNA_def_int(ot->srna,
+              "resolution",
+              10,
+              1,
+              30,
+              "Resolution",
+              "Resolution of the generated curves",
+              1,
+              20);
+
+  RNA_def_float(ot->srna,
+                "scale",
+                10.0f,
+                0.001f,
+                100.0f,
+                "Scale",
+                "Scale of the final stroke",
+                0.001f,
+                100.0f);
 }
diff --git a/source/blender/editors/io/io_gpencil_utils.c b/source/blender/editors/io/io_gpencil_utils.c
index 1939b7bc843..259a669519a 100644
--- a/source/blender/editors/io/io_gpencil_utils.c
+++ b/source/blender/editors/io/io_gpencil_utils.c
@@ -28,6 +28,8 @@
 
 #include "WM_api.h"
 
+#include "io_gpencil.h"
+
 ARegion *get_invoke_region(bContext *C)
 {
   bScreen *screen = CTX_wm_screen(C);
diff --git a/source/blender/io/gpencil/gpencil_io.h b/source/blender/io/gpencil/gpencil_io.h
index 17b44472573..3df99757a8e 100644
--- a/source/blender/io/gpencil/gpencil_io.h
+++ b/source/blender/io/gpencil/gpencil_io.h
@@ -37,25 +37,19 @@ struct GpencilIOParams {
   View3D *v3d;
   /** Grease pencil object. */
   Object *ob;
-  /** Mode.  */
+  /** Mode (see eGpencilIO_Modes). */
   uint16_t mode;
-  /** Start frame. */
   int32_t frame_start;
-  /** End frame.  */
   int32_t frame_end;
-  /* Current frame. */
   int32_t frame_cur;
-  /** Flags. */
   uint32_t flag;
-  /** Scale. */
   float scale;
-  /** Select mode. */
+  /** Select mode (see eGpencilExportSelect). */
   uint16_t select_mode;
-  /** Frame mode. */
+  /** Frame mode (see eGpencilExportFrame). */
   uint16_t frame_mode;
-  /** Stroke sampling. */
+  /** Stroke sampling factor. */
   float stroke_sample;
-  /** Resolution. */
   int32_t resolution;
 };
 
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 554c1a935d0..b08c169a9b1 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -37,6 +37,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+#include "BLI_span.hh"
 
 #include "DNA_gpencil_types.h"
 #include "DNA_layer_types.h"
@@ -54,6 +55,8 @@
 
 #include "gpencil_io_base.h"
 
+using blender::Span;
+
 namespace blender::io::gpencil {
 
 /* Constructor. */
@@ -202,7 +205,6 @@ void GpencilIO::create_object_list(void)
 
 /**
  * Set file input_text full path.
- * \param C: Context.
  * \param filename: Path of the file provided by save dialog.
  */
 void GpencilIO::filename_set(const char *filename)
@@ -211,12 +213,7 @@ void GpencilIO::filename_set(const char *filename)
   BLI_path_abs(filename_, BKE_main_blendfile_path(bmain_));
 }
 
-/**
- * Convert to screenspace
- * \param co: 3D position
- * \param r_co: 2D position
- * \return False if error
- */
+/** Convert to screenspace. */
 bool GpencilIO::gpencil_3d_point_to_screen_space(const float co[3], float r_co[2])
 {
   float parent_co[3];
@@ -257,11 +254,7 @@ bool GpencilIO::gpencil_3d_point_to_screen_space(const float co[3], float r_co[2
   return false;
 }
 
-/**
- * Convert to render space
- * \param co: 3D position
- * \param r_co: 2D positi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list