[Bf-blender-cvs] [a0d6bc6af03] greasepencil-object: Fix undo modes and mode changes

Antonio Vazquez noreply at git.blender.org
Tue Feb 13 11:48:41 CET 2018


Commit: a0d6bc6af035d1dbcb1ba8f9bcd4c2bc2aab64fb
Author: Antonio Vazquez
Date:   Tue Feb 13 11:48:31 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBa0d6bc6af035d1dbcb1ba8f9bcd4c2bc2aab64fb

Fix undo modes and mode changes

Now the Ctrl+Z does not undo the mode.

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

M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_select.c
M	source/blender/editors/util/undo.c

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

diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index af2deab2e50..9e1c2cc1c18 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -98,6 +98,7 @@
 #include "ED_screen.h"
 #include "ED_util.h"
 #include "ED_image.h"
+#include "ED_gpencil.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -1592,9 +1593,34 @@ static int object_mode_set_exec(bContext *C, wmOperator *op)
 	const bool toggle = RNA_boolean_get(op->ptr, "toggle");
 
 	/* if type is OB_GPENCIL, select mode for grease pencil strokes */
-	// XXX: Review this behaviour... something seems sketchy here (Aligorith)	
 	if ((ob) && (ob->type == OB_GPENCIL)) {
 		if ((ob->data) && (ob->data == gpd)) {
+			/* restore status */
+			if ((workspace->object_mode == OB_MODE_OBJECT) && 
+				((workspace->object_mode != mode) || (mode == OB_MODE_OBJECT)))
+			{
+				if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
+					workspace->object_mode = OB_MODE_GPENCIL_EDIT;
+					ED_gpencil_setup_modes(C, gpd, workspace->object_mode);
+					return OPERATOR_FINISHED;
+				}
+				else if (gpd->flag & GP_DATA_STROKE_PAINTMODE) {
+					workspace->object_mode = OB_MODE_GPENCIL_PAINT;
+					ED_gpencil_setup_modes(C, gpd, workspace->object_mode);
+					return OPERATOR_FINISHED;
+				}
+				else if (gpd->flag & GP_DATA_STROKE_SCULPTMODE) {
+					workspace->object_mode = OB_MODE_GPENCIL_SCULPT;
+					ED_gpencil_setup_modes(C, gpd, workspace->object_mode);
+					return OPERATOR_FINISHED;
+				}
+				else if (gpd->flag & GP_DATA_STROKE_WEIGHTMODE) {
+					workspace->object_mode = OB_MODE_GPENCIL_WEIGHT;
+					ED_gpencil_setup_modes(C, gpd, workspace->object_mode);
+					return OPERATOR_FINISHED;
+				}
+			}
+
 			if (ELEM(mode, OB_MODE_OBJECT, OB_MODE_EDIT, OB_MODE_POSE)) {
 				workspace->object_mode_restore = OB_MODE_OBJECT;
 				if (ELEM(workspace->object_mode, OB_MODE_EDIT, OB_MODE_GPENCIL_EDIT)) {
diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c
index 3441e42bc16..776cd266abb 100644
--- a/source/blender/editors/object/object_select.c
+++ b/source/blender/editors/object/object_select.c
@@ -73,7 +73,6 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_keyframing.h"
-#include "ED_gpencil.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -90,8 +89,8 @@
  * this takes into account the 'restrict selection in 3d view' flag.
  * deselect works always, the restriction just prevents selection */
 
-/* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! (or 
- * or a NC_SCENE|ND_OB_VISIBLE in case of visibility toggling */
+ /* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! (or
+  * or a NC_SCENE|ND_OB_VISIBLE in case of visibility toggling */
 
 void ED_object_base_select(Base *base, eObjectSelect_Mode mode)
 {
@@ -101,17 +100,17 @@ void ED_object_base_select(Base *base, eObjectSelect_Mode mode)
 
 	if (base) {
 		switch (mode) {
-			case BA_SELECT:
-				if ((base->flag & BASE_SELECTABLED) != 0) {
-					base->flag |= BASE_SELECTED;
-				}
-				break;
-			case BA_DESELECT:
-				base->flag &= ~BASE_SELECTED;
-				break;
-			case BA_INVERT:
-				/* Never happens. */
-				break;
+		case BA_SELECT:
+			if ((base->flag & BASE_SELECTABLED) != 0) {
+				base->flag |= BASE_SELECTED;
+			}
+			break;
+		case BA_DESELECT:
+			base->flag &= ~BASE_SELECTED;
+			break;
+		case BA_INVERT:
+			/* Never happens. */
+			break;
 		}
 		BKE_scene_object_base_flag_sync_from_base(base);
 	}
@@ -131,7 +130,7 @@ void ED_object_base_activate(bContext *C, Base *base)
 		Object *ob_prev = OBACT(view_layer);
 		Object *ob_curr = base->object;
 		if (ob_prev != NULL) {
-			if (ob_prev->type == ob_curr->type) {
+			if ((ob_prev->type == ob_curr->type) || (ob_curr->type == OB_GPENCIL)) {
 				reset = false;
 			}
 		}
@@ -142,32 +141,6 @@ void ED_object_base_activate(bContext *C, Base *base)
 	
 	view_layer->basact = base;
 
-	/* grease pencil modes */
-	if ((base) && (base->object)) {
-		Object *ob = base->object;
-		if ((ob->type == OB_GPENCIL) && (ob->data)) {
-			bGPdata *gpd = (bGPdata *)ob->data;
-			reset = true;
-
-			if (gpd->flag & GP_DATA_STROKE_EDITMODE) { 
-				workspace->object_mode = OB_MODE_GPENCIL_EDIT;
-			}
-			else if (gpd->flag & GP_DATA_STROKE_PAINTMODE) { 
-				workspace->object_mode = OB_MODE_GPENCIL_PAINT;
-			}
-			else if (gpd->flag & GP_DATA_STROKE_SCULPTMODE) { 
-				workspace->object_mode = OB_MODE_GPENCIL_SCULPT;
-			}
-			else if (gpd->flag & GP_DATA_STROKE_WEIGHTMODE){ 
-				workspace->object_mode = OB_MODE_GPENCIL_WEIGHT;
-			}
-			else { 
-				workspace->object_mode = OB_MODE_OBJECT; 
-			}
-			ED_gpencil_setup_modes(C, gpd, workspace->object_mode);
-		}
-	}
-
 	if (reset == false) {
 		wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_mode_set", false);
 		PointerRNA ptr;
diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c
index 4e598155f05..b349a450001 100644
--- a/source/blender/editors/util/undo.c
+++ b/source/blender/editors/util/undo.c
@@ -243,8 +243,8 @@ static int ed_undo_step(bContext *C, int step, const char *undoname)
 				ED_gpencil_toggle_brush_cursor(C, false, NULL);
 			}
 			/* set workspace mode */
-			//workspace->object_mode = workspace->object_mode;
-			ED_object_base_activate(C, view_layer->basact); // XXX
+			Base *basact = CTX_data_active_base(C);
+			ED_object_base_activate(C, basact);
 		}
 	}



More information about the Bf-blender-cvs mailing list