GP: New Python update API functions (WIP)
authorAntonioya <blendergit@gmail.com>
Thu, 20 Dec 2018 11:35:06 +0000 (12:35 +0100)
committerAntonioya <blendergit@gmail.com>
Thu, 20 Dec 2018 11:37:12 +0000 (12:37 +0100)
For strokes:

myframe.strokes.update(mystroke)

For datablock:

gpencil = bpy.data.grease_pencil['gpencil']
gpencil.update()

Still need a manual refresh of viewport.

source/blender/makesrna/intern/rna_gpencil.c

index 9c90628f2620416a9079fafd39721fc812605721..5acfa6c1b47bd807bc6749909556780627e75583 100644 (file)
@@ -596,6 +596,18 @@ static void rna_GPencil_stroke_remove(bGPDframe *frame, ReportList *reports, Poi
        WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
 }
 
+static void rna_GPencil_stroke_update(bGPDframe *frame, ReportList *reports, PointerRNA *stroke_ptr)
+{
+       bGPDstroke *stroke = stroke_ptr->data;
+       if (BLI_findindex(&frame->strokes, stroke) == -1) {
+               BKE_report(reports, RPT_ERROR, "Stroke not found in grease pencil frame");
+               return;
+       }
+       stroke->flag |= GP_STROKE_RECALC_CACHES;
+
+       WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+}
+
 static void rna_GPencil_stroke_select_set(PointerRNA *ptr, const bool value)
 {
        bGPDstroke *gps = ptr->data;
@@ -725,6 +737,14 @@ static void rna_GPencil_clear(bGPdata *gpd)
        WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 }
 
+static void rna_GPencil_update_data(bGPdata *gpd)
+{
+       DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+       DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
+
+       WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
+}
+
 static void rna_GpencilVertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        bGPDstroke *gps = ptr->data;
@@ -992,6 +1012,13 @@ static void rna_def_gpencil_strokes_api(BlenderRNA *brna, PropertyRNA *cprop)
        parm = RNA_def_pointer(func, "stroke", "GPencilStroke", "Stroke", "The stroke to remove");
        RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
        RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+
+       func = RNA_def_function(srna, "update", "rna_GPencil_stroke_update");
+       RNA_def_function_ui_description(func, "Update stroke geometry");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       parm = RNA_def_pointer(func, "stroke", "GPencilStroke", "Stroke", "The stroke to remove");
+       RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+       RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
 }
 
 static void rna_def_gpencil_frame(BlenderRNA *brna)
@@ -1628,6 +1655,9 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
        /* API Functions */
        func = RNA_def_function(srna, "clear", "rna_GPencil_clear");
        RNA_def_function_ui_description(func, "Remove all the Grease Pencil data");
+
+       func = RNA_def_function(srna, "update", "rna_GPencil_update_data");
+       RNA_def_function_ui_description(func, "Force internal data update");
 }
 
 /* --- */