[Bf-blender-cvs] [9be05560c49] temp-gpencil-io: First round of code cleanup

Antonio Vazquez noreply at git.blender.org
Mon Mar 22 20:16:10 CET 2021


Commit: 9be05560c49937b62777e64293179c49d78113aa
Author: Antonio Vazquez
Date:   Mon Mar 22 20:16:04 2021 +0100
Branches: temp-gpencil-io
https://developer.blender.org/rB9be05560c49937b62777e64293179c49d78113aa

First round of code cleanup

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

M	source/blender/blenkernel/BKE_gpencil_geom.h
M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/io/io_gpencil_export.c
M	source/blender/editors/io/io_gpencil_import.c
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/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index 9e094f3adf5..c5bebfc4504 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -27,9 +27,6 @@
 extern "C" {
 #endif
 
-struct ARegion;
-struct bContext;
-struct BoundBox;
 struct Depsgraph;
 struct Main;
 struct Object;
@@ -186,10 +183,10 @@ struct bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *r
                                                           struct bGPdata *gpd,
                                                           const struct bGPDlayer *gpl,
                                                           struct bGPDstroke *gps,
-                                                          int subdivisions,
-                                                          float diff_mat[4][4]);
+                                                          const int subdivisions,
+                                                          const float diff_mat[4][4]);
 float BKE_gpencil_stroke_average_pressure_get(struct bGPDstroke *gps);
-bool BKE_gpencil_stroke_is_thickness_constant(struct bGPDstroke *gps);
+bool BKE_gpencil_stroke_is_pressure_constant(struct bGPDstroke *gps);
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index fc145956836..2f80e355005 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -3468,7 +3468,9 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
  * back to 3D.
  * Note: also takes care of parent space transform
  */
-void BKE_gpencil_stroke_to_view_space(RegionView3D *rv3d, bGPDstroke *gps, float diff_mat[4][4])
+void BKE_gpencil_stroke_to_view_space(RegionView3D *rv3d,
+                                      bGPDstroke *gps,
+                                      const float diff_mat[4][4])
 {
   for (int i = 0; i < gps->totpoints; i++) {
     bGPDspoint *pt = &gps->points[i];
@@ -3544,11 +3546,11 @@ static int generate_arc_from_point_to_point(ListBase *list,
     tPerimeterPoint *last_point;
     if (clockwise) {
       last_point = to;
-      copy_v3_v3(vec_t, vec_to);
+      copy_v2_v2(vec_t, vec_to);
     }
     else {
       last_point = from;
-      copy_v3_v3(vec_t, vec_from);
+      copy_v2_v2(vec_t, vec_from);
     }
 
     for (int i = 0; i < num_points - 1; i++) {
@@ -3913,8 +3915,8 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
                                                    bGPdata *gpd,
                                                    const bGPDlayer *gpl,
                                                    bGPDstroke *gps,
-                                                   int subdivisions,
-                                                   float diff_mat[4][4])
+                                                   const int subdivisions,
+                                                   const float diff_mat[4][4])
 {
   if (gps->totpoints == 0) {
     return NULL;
@@ -3976,17 +3978,16 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
 }
 
 /** Get average pressure. */
-float BKE_gpencil_stroke_average_pressure_get(struct bGPDstroke *gps)
+float BKE_gpencil_stroke_average_pressure_get(bGPDstroke *gps)
 {
 
   if (gps->totpoints == 1) {
     return gps->points[0].pressure;
   }
 
-  const bGPDspoint *pt;
-  int i;
   float tot = 0.0f;
-  for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+  for (int i = 0; i < gps->totpoints; i++) {
+    const bGPDspoint *pt = &gps->points[i];
     tot += pt->pressure;
   }
 
@@ -3994,18 +3995,16 @@ float BKE_gpencil_stroke_average_pressure_get(struct bGPDstroke *gps)
 }
 
 /** Check if the thickness of the stroke is constant. */
-bool BKE_gpencil_stroke_is_thickness_constant(struct bGPDstroke *gps)
+bool BKE_gpencil_stroke_is_pressure_constant(bGPDstroke *gps)
 {
   if (gps->totpoints == 1) {
     return true;
   }
 
-  const bGPDspoint *pt;
-  int i;
-
-  float prv_pressure = gps->points[0].pressure;
-  for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
-    if (pt->pressure != prv_pressure) {
+  const float first_pressure = gps->points[0].pressure;
+  for (int i = 0; i < gps->totpoints; i++) {
+    const bGPDspoint *pt = &gps->points[i];
+    if (pt->pressure != first_pressure) {
       return false;
     }
   }
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 9dfee6ee09d..574670de7ca 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -597,7 +597,7 @@ bool ED_gpencil_stroke_material_editable(Object *ob, const bGPDlayer *gpl, const
 }
 
 /* Check whether given stroke is visible for the current material. */
-bool ED_gpencil_stroke_material_visible(Object *ob, const bGPDlayer *gpl, const bGPDstroke *gps)
+bool ED_gpencil_stroke_material_visible(Object *ob, const bGPDstroke *gps)
 {
   /* check if the color is editable */
   MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1);
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 9ac3936258c..e9ac21f60cf 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -150,9 +150,7 @@ bool ED_gpencil_stroke_can_use(const struct bContext *C, const struct bGPDstroke
 bool ED_gpencil_stroke_material_editable(struct Object *ob,
                                          const struct bGPDlayer *gpl,
                                          const struct bGPDstroke *gps);
-bool ED_gpencil_stroke_material_visible(struct Object *ob,
-                                        const struct bGPDlayer *gpl,
-                                        const struct bGPDstroke *gps);
+bool ED_gpencil_stroke_material_visible(struct Object *ob, const struct bGPDstroke *gps);
 
 /* ----------- Grease Pencil Operators ----------------- */
 
diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c
index aae65fecfff..9203441e5cb 100644
--- a/source/blender/editors/io/io_gpencil_export.c
+++ b/source/blender/editors/io/io_gpencil_export.c
@@ -125,16 +125,6 @@ static bool wm_gpencil_export_svg_common_check(bContext *UNUSED(C), wmOperator *
   return false;
 }
 
-static void gpencil_export_common_props_svg(wmOperatorType *ot)
-{
-  gpencil_export_common_props_definition(ot);
-  RNA_def_boolean(ot->srna,
-                  "use_clip_camera",
-                  false,
-                  "Clip Camera",
-                  "Clip drawings to camera size when export in camera view");
-}
-
 static int wm_gpencil_export_svg_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -273,7 +263,13 @@ void WM_OT_gpencil_export_svg(wmOperatorType *ot)
                                  FILE_DEFAULTDISPLAY,
                                  FILE_SORT_ALPHA);
 
-  gpencil_export_common_props_svg(ot);
+  gpencil_export_common_props_definition(ot);
+
+  RNA_def_boolean(ot->srna,
+                  "use_clip_camera",
+                  false,
+                  "Clip Camera",
+                  "Clip drawings to camera size when export in camera view");
 }
 #endif
 
@@ -294,10 +290,8 @@ static bool wm_gpencil_export_pdf_common_check(bContext *UNUSED(C), wmOperator *
   return false;
 }
 
-static int wm_gpencil_export_pdf_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+static int wm_gpencil_export_pdf_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
-  UNUSED_VARS(event);
-
   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
     Main *bmain = CTX_data_main(C);
     char filepath[FILE_MAX];
@@ -406,7 +400,7 @@ static void ui_gpencil_export_pdf_settings(uiLayout *layout, PointerRNA *imfptr)
   uiItemR(sub, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
 }
 
-static void wm_gpencil_export_pdf_draw(bContext *C, wmOperator *op)
+static void wm_gpencil_export_pdf_draw(bContext *UNUSED(C), wmOperator *op)
 {
   PointerRNA ptr;
 
diff --git a/source/blender/editors/io/io_gpencil_import.c b/source/blender/editors/io/io_gpencil_import.c
index d25861dac39..2a876271dbf 100644
--- a/source/blender/editors/io/io_gpencil_import.c
+++ b/source/blender/editors/io/io_gpencil_import.c
@@ -63,7 +63,7 @@
 #include "gpencil_io.h"
 
 /* <-------- SVG single frame import. --------> */
-bool wm_gpencil_import_svg_common_check(bContext *UNUSED(C), wmOperator *op)
+static bool wm_gpencil_import_svg_common_check(bContext *UNUSED(C), wmOperator *op)
 {
 
   char filepath[FILE_MAX];
@@ -78,10 +78,8 @@ bool wm_gpencil_import_svg_common_check(bContext *UNUSED(C), wmOperator *op)
   return false;
 }
 
-static int wm_gpencil_import_svg_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+static int wm_gpencil_import_svg_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
-  UNUSED_VARS(event);
-
   WM_event_add_fileselect(C, op);
 
   return OPERATOR_RUNNING_MODAL;
@@ -178,14 +176,6 @@ 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";
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index f0960e62866..e67d742b44a 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -60,7 +60,7 @@ using blender::Span;
 namespace blender::io::gpencil {
 
 /* Constructor. */
-GpencilIO::GpencilIO(const struct GpencilIOParams *iparams)
+GpencilIO::GpencilIO(const 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list