From 1693988926fefdbbd8c4e544a677c68cb726ceab Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 24 May 2013 11:19:57 +0000 Subject: Changes for masks API Made it more consistent with blender convensions and now it's very familiar to curve's python api. - Made it spline.points.add(count) wich is more efficient in cases lots of points are adding. (points.new was removed tho). - Removed mask_layer.splines.add(), now it's only mask_layer.splines.new(), which is how splines are adding for curves. --- source/blender/makesrna/intern/rna_mask.c | 60 +++++++++++++------------------ 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_mask.c b/source/blender/makesrna/intern/rna_mask.c index 8fff90310a3..65e6b15d676 100644 --- a/source/blender/makesrna/intern/rna_mask.c +++ b/source/blender/makesrna/intern/rna_mask.c @@ -340,17 +340,6 @@ static void rna_Mask_layers_clear(Mask *mask) WM_main_add_notifier(NC_MASK | NA_EDITED, mask); } -static void rna_MaskLayer_spline_add(ID *id, MaskLayer *masklay, int number) -{ - Mask *mask = (Mask *) id; - int i; - - for (i = 0; i < number; i++) - BKE_mask_spline_add(masklay); - - WM_main_add_notifier(NC_MASK | NA_EDITED, mask); -} - static MaskSpline *rna_MaskLayer_spline_new(ID *id, MaskLayer *mask_layer) { Mask *mask = (Mask *) id; @@ -401,13 +390,16 @@ static void rna_Mask_end_frame_set(PointerRNA *ptr, int value) } } -static MaskSplinePoint *rna_MaskSpline_point_new(ID *id, MaskSpline *spline) +static void rna_MaskSpline_points_add(ID *id, MaskSpline *spline, int count) { Mask *mask = (Mask *) id; - MaskSplinePoint *new_point; MaskLayer *layer; int active_point_index = -1; - int point_index; + int i, spline_shape_index; + + if (count <= 0) { + return; + } for (layer = mask->masklayers.first; layer; layer = layer->next) { if (BLI_findindex(&layer->splines, spline) != -1) { @@ -418,32 +410,35 @@ static MaskSplinePoint *rna_MaskSpline_point_new(ID *id, MaskSpline *spline) if (!layer) { /* Shall not happen actually */ BLI_assert(!"No layer found for the spline"); - return NULL; + return; } if (layer->act_spline == spline) { active_point_index = layer->act_point - spline->points; } - spline->points = MEM_recallocN(spline->points, sizeof(MaskSplinePoint) * (spline->tot_point + 1)); - spline->tot_point++; + spline->points = MEM_recallocN(spline->points, sizeof(MaskSplinePoint) * (spline->tot_point + count)); + spline->tot_point += count; if (active_point_index >= 0) { layer->act_point = spline->points + active_point_index; } - point_index = spline->tot_point - 1; - new_point = spline->points + point_index; - new_point->bezt.h1 = new_point->bezt.h2 = HD_ALIGN; - BKE_mask_calc_handle_point_auto(spline, new_point, TRUE); - BKE_mask_parent_init(&new_point->parent); + spline_shape_index = BKE_mask_layer_shape_spline_to_index(layer, spline); - BKE_mask_layer_shape_changed_add(layer, BKE_mask_layer_shape_spline_to_index(layer, spline) + point_index, TRUE, TRUE); + for (i = 0; i < count; i++) { + int point_index = spline->tot_point - count + i; + MaskSplinePoint *new_point = spline->points + point_index; + new_point->bezt.h1 = new_point->bezt.h2 = HD_ALIGN; + BKE_mask_calc_handle_point_auto(spline, new_point, TRUE); + BKE_mask_parent_init(&new_point->parent); - WM_main_add_notifier(NC_MASK | ND_DATA, mask); - DAG_id_tag_update(&mask->id, OB_RECALC_DATA); + /* Not efficient, but there's no other way for now */ + BKE_mask_layer_shape_changed_add(layer, spline_shape_index + point_index, TRUE, TRUE); + } - return new_point; + WM_main_add_notifier(NC_MASK | ND_DATA, mask); + DAG_id_tag_update(&mask->id, 0); } static void rna_MaskSpline_point_remove(ID *id, MaskSpline *spline, ReportList *reports, PointerRNA *point_ptr) @@ -652,12 +647,6 @@ static void rna_def_mask_splines(BlenderRNA *brna) RNA_def_struct_sdna(srna, "MaskLayer"); RNA_def_struct_ui_text(srna, "Mask Splines", "Collection of masking splines"); - /* Add the splines */ - func = RNA_def_function(srna, "add", "rna_MaskLayer_spline_add"); - RNA_def_function_flag(func, FUNC_USE_SELF_ID); - RNA_def_function_ui_description(func, "Add a number of splines to mask layer"); - RNA_def_int(func, "count", 1, 0, INT_MAX, "Number", "Number of splines to add to the layer", 0, INT_MAX); - /* Create new spline */ func = RNA_def_function(srna, "new", "rna_MaskLayer_spline_new"); RNA_def_function_flag(func, FUNC_USE_SELF_ID); @@ -700,11 +689,10 @@ static void rna_def_maskSplinePoints(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "Mask Spline Points", "Collection of masking spline points"); /* Create new point */ - func = RNA_def_function(srna, "new", "rna_MaskSpline_point_new"); + func = RNA_def_function(srna, "add", "rna_MaskSpline_points_add"); RNA_def_function_flag(func, FUNC_USE_SELF_ID); - RNA_def_function_ui_description(func, "Add a new point to the spline"); - parm = RNA_def_pointer(func, "point", "MaskSplinePoint", "", "The newly created point"); - RNA_def_function_return(func, parm); + RNA_def_function_ui_description(func, "Add a number of point to this spline"); + RNA_def_int(func, "count", 1, 0, INT_MAX, "Number", "Number of points to add to the spline", 0, INT_MAX); /* Remove the point */ func = RNA_def_function(srna, "remove", "rna_MaskSpline_point_remove"); -- cgit v1.2.3