[Bf-blender-cvs] [ea1174bde9e] master: Annotations: Use flag to determine if the layer is a Ruler

Antonio Vazquez noreply at git.blender.org
Thu Oct 10 08:13:42 CEST 2019


Commit: ea1174bde9edff7639b1b3de4989084987a29f1e
Author: Antonio Vazquez
Date:   Thu Oct 10 08:11:47 2019 +0200
Branches: master
https://developer.blender.org/rBea1174bde9edff7639b1b3de4989084987a29f1e

Annotations: Use flag to determine if the  layer is a Ruler

Proposed fix for T70141.

Before, the ruler was using the name of the layer as key, but this is very weak because if the layer name changes, the layer gets an annotation layer.

Now, the layer is marked using a flag and now it's possible to rename it.

Reviewed By: dfelinto

Differential Revision: https://developer.blender.org/D6028

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

M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 5d73ffe26d5..58643e34922 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1272,6 +1272,22 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
         ma->blend_method = MA_BM_BLEND;
       }
     }
+
+    {
+      /* Update all ruler layers to set new flag. */
+      LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+        bGPdata *gpd = scene->gpd;
+        if (gpd == NULL) {
+          continue;
+        }
+        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+          if (STREQ(gpl->info, "RulerData3D")) {
+            gpl->flag |= GP_LAYER_IS_RULER;
+            break;
+          }
+        }
+      }
+    }
   }
 }
 
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 5625333d837..a5b7fac624d 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -407,6 +407,17 @@ static bool view3d_ruler_item_mousemove(RulerInfo *ruler_info,
 /** \name Ruler/Grease Pencil Conversion
  * \{ */
 
+/* Helper: Find the layer created as ruler. */
+static bGPDlayer *view3d_ruler_layer_get(bGPdata *gpd)
+{
+  for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+    if (gpl->flag & GP_LAYER_IS_RULER) {
+      return gpl;
+    }
+  }
+  return NULL;
+}
+
 #define RULER_ID "RulerData3D"
 static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
 {
@@ -427,12 +438,12 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
   }
   gpd = scene->gpd;
 
-  gpl = BLI_findstring(&gpd->layers, ruler_name, offsetof(bGPDlayer, info));
+  gpl = view3d_ruler_layer_get(gpd);
   if (gpl == NULL) {
     gpl = BKE_gpencil_layer_addnew(gpd, ruler_name, false);
     copy_v4_v4(gpl->color, U.gpencil_new_layer_col);
     gpl->thickness = 1;
-    gpl->flag |= GP_LAYER_HIDE;
+    gpl->flag |= GP_LAYER_HIDE | GP_LAYER_IS_RULER;
   }
 
   gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW);
@@ -485,8 +496,7 @@ static bool view3d_ruler_from_gpencil(const bContext *C, wmGizmoGroup *gzgroup)
 
   if (scene->gpd) {
     bGPDlayer *gpl;
-    const char *ruler_name = RULER_ID;
-    gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info));
+    gpl = view3d_ruler_layer_get(scene->gpd);
     if (gpl) {
       bGPDframe *gpf;
       gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV);
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 2dffdf82688..1435d0a64b4 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -401,6 +401,8 @@ typedef enum eGPDlayer_Flag {
   GP_LAYER_USE_MASK = (1 << 13),
   /* Flag used to display in Paint mode only layers with keyframe */
   GP_LAYER_SOLO_MODE = (1 << 4),
+  /* Ruler Layer */
+  GP_LAYER_IS_RULER = (1 << 14),
 } eGPDlayer_Flag;
 
 /* bGPDlayer->onion_flag */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 3ad18fcc7a3..2601600c6ee 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1457,6 +1457,12 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
       prop, "Solo Mode", "In Paint mode display only layers with keyframe in current frame");
   RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
+  /* Layer is used as Ruler. */
+  prop = RNA_def_property(srna, "is_ruler", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_IS_RULER);
+  RNA_def_property_ui_text(prop, "Ruler", "This is a special ruler layer");
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
   /* exposed as layers.active */
 #  if 0
   prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);



More information about the Bf-blender-cvs mailing list