[Bf-blender-cvs] [890b9249d42] greasepencil-object: New Information Panel

Antonio Vazquez noreply at git.blender.org
Sun Sep 10 12:16:17 CEST 2017


Commit: 890b9249d422e9f1994ead13a5a57374f787e599
Author: Antonio Vazquez
Date:   Sun Sep 10 12:16:04 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB890b9249d422e9f1994ead13a5a57374f787e599

New Information Panel

This panel shows information about number of layers, frames, strokes, points and palettes used.

Notes: The number of frames in the internal data, not the number of different keyframes number.

The panel is not updated automatically to avoid performace issues. Close and reopen panel to refresh. Maybe, this could be changed, but need to be checked before.

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index cd946d3ade8..dae6db283ad 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -25,6 +25,7 @@ from bl_ui.properties_grease_pencil_common import (
         GreasePencilOnionPanel,
         GreasePencilParentLayerPanel,
         GreasePencilVertexGroupPanel,
+        GreasePencilInfoPanel,
         )
 
 
@@ -97,6 +98,14 @@ class DATA_PT_gpencilvertexpanel(GreasePencilVertexGroupPanel, Panel):
     bl_label = "Vertex Groups"
     bl_options = {'DEFAULT_CLOSED'}
 
+class DATA_PT_gpencil_infopanel(GreasePencilInfoPanel, Panel):
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "data"
+    bl_label = "Information"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    # NOTE: this is just a wrapper around th
 class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
     bl_label = "Display"
     bl_options = {'DEFAULT_CLOSED'}
@@ -136,6 +145,7 @@ classes = (
     DATA_PT_gpencilvertexpanel,
     DATA_PT_gpencilparentpanel,
     DATA_PT_gpencil_display,
+    DATA_PT_gpencil_infopanel,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 5ad4c91594a..d6e3b1eaf12 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -1363,6 +1363,54 @@ class GreasePencilVertexGroupPanel:
             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
 
 
+class GreasePencilInfoPanel:
+    bl_label = "Information"
+    bl_region_type = 'UI'
+    bl_options = {'DEFAULT_CLOSED'}
+
+    @classmethod
+    def poll(cls, context):
+        ts = context.scene.tool_settings
+
+        if context.gpencil_data is None:
+            return False
+
+        if context.space_data.type in ('VIEW_3D', 'PROPERTIES'):
+            if ts.grease_pencil_source == 'OBJECT':
+                if context.space_data.context != 'DATA':
+                    return False
+
+            if context.space_data.context == 'DATA':
+                if context.object.type != 'GPENCIL':
+                    return False
+                else:
+                    if context.object.grease_pencil != context.gpencil_data:
+                        return False
+
+        return True
+
+    @staticmethod
+    def draw(self, context):
+        layout = self.layout
+        gpd = context.gpencil_data
+
+        split = layout.split(percentage=0.5)
+
+        col = split.column(align=True)
+        col.label("Layers:", icon="LAYER_ACTIVE")
+        col.label("Frames:", icon="LAYER_ACTIVE")
+        col.label("Strokes:", icon="LAYER_ACTIVE")
+        col.label("Points:", icon="LAYER_ACTIVE")
+        col.label("Palettes:", icon="LAYER_ACTIVE")
+
+        col = split.column(align=True)
+        col.label(str(gpd.info_total_layers))
+        col.label(str(gpd.info_total_frames))
+        col.label(str(gpd.info_total_strokes))
+        col.label(str(gpd.info_total_points))
+        col.label(str(gpd.info_total_palettes))
+
+
 class GreasePencilPaletteColorPanel:
     # subclass must set
     bl_label = "Grease Pencil Colors"
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index b4041f1b9b5..d92608ed2a1 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -73,6 +73,7 @@ static EnumPropertyItem rna_enum_gpencil_onion_modes_items[] = {
 #ifdef RNA_RUNTIME
 
 #include "BLI_math.h"
+#include "BLI_ghash.h"
 
 #include "WM_api.h"
 
@@ -616,6 +617,75 @@ static void rna_GPencil_clear(bGPdata *gpd)
 	WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 }
 
+/* info functions */
+static int rna_GPencil_info_total_layers(PointerRNA *ptr)
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+
+	return BLI_listbase_count(&gpd->layers);
+}
+
+static int rna_GPencil_info_total_frames(PointerRNA *ptr)
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+	int tot = 0;
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		tot += BLI_listbase_count(&gpl->frames);
+	}
+
+	return tot;
+}
+
+static int rna_GPencil_info_total_strokes(PointerRNA *ptr)
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+	int tot = 0;
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+			tot += BLI_listbase_count(&gpf->strokes);
+		}
+	}
+
+	return tot;
+}
+
+static int rna_GPencil_info_total_points(PointerRNA *ptr)
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+	int tot = 0;
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+			for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+				tot += gps->totpoints;
+			}
+		}
+	}
+
+	return tot;
+}
+
+static int rna_GPencil_info_total_palettes(PointerRNA *ptr)
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+	GHash *data = BLI_ghash_str_new("GP count palettes");
+	int tot = 0;
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+			for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+				Palette *palette = (Palette *)BLI_ghash_lookup(data, gps->palette->id.name);
+				if (palette == NULL) {
+					tot += 1;
+					BLI_ghash_insert(data, gps->palette->id.name, gps->palette);
+				}
+			}
+		}
+	}
+	BLI_ghash_free(data, NULL, NULL);
+	data = NULL;
+
+	return tot;
+}
+
 #else
 
 /* information of vertex groups by point */
@@ -1293,6 +1363,32 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Lines Only", "Show only edit lines for additional frames");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
+	/* info properties */
+	prop = RNA_def_property(srna, "info_total_layers", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_int_funcs(prop, "rna_GPencil_info_total_layers", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Total Layers", "Number of Layers");
+
+	prop = RNA_def_property(srna, "info_total_frames", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_int_funcs(prop, "rna_GPencil_info_total_frames", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Total Frames", "Number of Frames");
+
+	prop = RNA_def_property(srna, "info_total_strokes", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_int_funcs(prop, "rna_GPencil_info_total_strokes", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Total Strokes", "Number of Strokes");
+
+	prop = RNA_def_property(srna, "info_total_points", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_int_funcs(prop, "rna_GPencil_info_total_points", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Total Points", "Number of Points");
+
+	prop = RNA_def_property(srna, "info_total_palettes", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_int_funcs(prop, "rna_GPencil_info_total_palettes", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Total Palettes", "Number of Palettes");
+
 	/* API Functions */
 	func = RNA_def_function(srna, "clear", "rna_GPencil_clear");
 	RNA_def_function_ui_description(func, "Remove all the grease pencil data");



More information about the Bf-blender-cvs mailing list