[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47407] branches/soc-2011-tomato: operator to switch direction

Campbell Barton ideasman42 at gmail.com
Mon Jun 4 15:24:12 CEST 2012


Revision: 47407
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47407
Author:   campbellbarton
Date:     2012-06-04 13:24:10 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
operator to switch direction

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
    branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c
    branches/soc-2011-tomato/source/blender/editors/mask/mask_intern.h
    branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-06-04 13:19:17 UTC (rev 47406)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-06-04 13:24:10 UTC (rev 47407)
@@ -394,6 +394,7 @@
         col.label(text="Spline:")
         col.operator("mask.delete")
         col.operator("mask.cyclic_toggle")
+        col.operator("mask.switch_direction")
 
         col = layout.column(align=True)
         col.label(text="Parenting:")
@@ -1196,6 +1197,7 @@
 
         layout.separator()
         layout.operator("mask.cyclic_toggle")
+        layout.operator("mask.switch_direction")
 
         layout.separator()
         layout.operator("mask.parent_clear")

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-06-04 13:19:17 UTC (rev 47406)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h	2012-06-04 13:24:10 UTC (rev 47407)
@@ -63,10 +63,13 @@
 
 float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline, int width, int height, int *tot_diff_point))[2];
 float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline,
-			 int width, int height, int *tot_feather_point))[2];
+                                                                      int width, int height, int *tot_feather_point))[2];
 
 float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2];
 
+void BKE_mask_point_direction_switch(struct MaskSplinePoint *point);
+void BKE_mask_spline_direction_switch(struct MaskLayer *masklay, struct MaskSpline *spline);
+
 /* point */
 int BKE_mask_point_has_handle(struct MaskSplinePoint *point);
 void BKE_mask_point_handle(struct MaskSplinePoint *point, float handle[2]);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-06-04 13:19:17 UTC (rev 47406)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c	2012-06-04 13:24:10 UTC (rev 47407)
@@ -377,6 +377,84 @@
 	return feather;
 }
 
+void BKE_mask_point_direction_switch(MaskSplinePoint *point)
+{
+	const int tot_uw = point->tot_uw;
+	const int tot_uw_half = tot_uw / 2;
+	int i;
+
+	if (tot_uw < 2) {
+		return;
+	}
+
+	/* count */
+	for (i = 0; i < tot_uw_half; i++) {
+		MaskSplinePointUW *uw_a = &point->uw[i];
+		MaskSplinePointUW *uw_b = &point->uw[tot_uw - (i + 1)];
+		SWAP(MaskSplinePointUW, *uw_a, *uw_b);
+	}
+	for (i = 0; i < tot_uw; i++) {
+		MaskSplinePointUW *uw = &point->uw[i];
+		uw->u = 1.0f - uw->u;
+	}
+}
+
+//typedef (float)[MASK_OBJECT_SHAPE_ELEM_SIZE] MaskLayerShapeElem;
+
+typedef struct MaskLayerShapeElem {
+	float value[MASK_OBJECT_SHAPE_ELEM_SIZE];
+} MaskLayerShapeElem;
+
+void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline)
+{
+	const int tot_point = spline->tot_point;
+	const int tot_point_half = tot_point / 2;
+	int i, i_prev;
+
+	if (tot_point < 2) {
+		return;
+	}
+
+	/* count */
+	for (i = 0; i < tot_point_half; i++) {
+		MaskSplinePoint *point_a = &spline->points[i];
+		MaskSplinePoint *point_b = &spline->points[tot_point - (i + 1)];
+		SWAP(MaskSplinePoint, *point_a, *point_b);
+	}
+
+	/* correct UW's */
+	i_prev = tot_point - 1;
+	for (i = 0; i < tot_point; i++) {
+
+		BKE_mask_point_direction_switch(&spline->points[i]);
+
+		SWAP(MaskSplinePointUW *, spline->points[i].uw,     spline->points[i_prev].uw);
+		SWAP(int,                 spline->points[i].tot_uw, spline->points[i_prev].tot_uw);
+
+		i_prev = i;
+	}
+
+	/* correct animation */
+	if (masklay->splines_shapes.first) {
+		MaskLayerShape *masklay_shape;
+
+		const int spline_index = BKE_mask_layer_shape_spline_to_index(masklay, spline);
+
+		for (masklay_shape = masklay->splines_shapes.first;
+		     masklay_shape;
+		     masklay_shape = masklay_shape->next)
+		{
+			MaskLayerShapeElem *fp_arr = (MaskLayerShapeElem *)masklay_shape->data;
+
+			for (i = 0; i < tot_point_half; i++) {
+				MaskLayerShapeElem *fp_a = &fp_arr[spline_index +              (i)     ];
+				MaskLayerShapeElem *fp_b = &fp_arr[spline_index + (tot_point - (i + 1))];
+				SWAP(MaskLayerShapeElem, *fp_a, *fp_b);
+			}
+		}
+	}
+}
+
 /* point */
 
 int BKE_mask_point_has_handle(MaskSplinePoint *point)

Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c	2012-06-04 13:19:17 UTC (rev 47406)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_editor.c	2012-06-04 13:24:10 UTC (rev 47407)
@@ -196,6 +196,7 @@
 	/* geometry */
 	WM_operatortype_append(MASK_OT_add_vertex);
 	WM_operatortype_append(MASK_OT_add_feather_vertex);
+	WM_operatortype_append(MASK_OT_switch_direction);
 	WM_operatortype_append(MASK_OT_delete);
 
 	/* select */

Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_intern.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_intern.h	2012-06-04 13:19:17 UTC (rev 47406)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_intern.h	2012-06-04 13:24:10 UTC (rev 47407)
@@ -53,6 +53,7 @@
 
 void MASK_OT_hide_view_clear(struct wmOperatorType *ot);
 void MASK_OT_hide_view_set(struct wmOperatorType *ot);
+void MASK_OT_switch_direction(struct wmOperatorType *ot);
 
 void MASK_OT_handle_type_set(struct wmOperatorType *ot);
 

Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c	2012-06-04 13:19:17 UTC (rev 47406)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c	2012-06-04 13:24:10 UTC (rev 47407)
@@ -1657,6 +1657,58 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* *** switch direction *** */
+static int mask_switch_direction_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Mask *mask = CTX_data_edit_mask(C);
+	MaskLayer *masklay;
+
+	int change = FALSE;
+
+	/* do actual selection */
+	for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+		MaskSpline *spline;
+
+		if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+			continue;
+		}
+
+		for (spline = masklay->splines.first; spline; spline = spline->next) {
+			if (ED_mask_spline_select_check(spline)) {
+				BKE_mask_spline_direction_switch(masklay, spline);
+				change = TRUE;
+			}
+		}
+	}
+
+	if (change) {
+		/* TODO: only update this spline */
+		BKE_mask_update_display(mask, CTX_data_scene(C)->r.cfra);
+
+		WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
+
+		return OPERATOR_FINISHED;
+	}
+
+	return OPERATOR_CANCELLED;
+}
+
+void MASK_OT_switch_direction(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Switch Direction";
+	ot->description = "Switch direction of selected splines";
+	ot->idname = "MASK_OT_switch_direction";
+
+	/* api callbacks */
+	ot->exec = mask_switch_direction_exec;
+	ot->poll = ED_maskediting_mask_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+
 /******************** set handle type *********************/
 
 static int set_handle_type_exec(bContext *C, wmOperator *op)




More information about the Bf-blender-cvs mailing list