[Bf-blender-cvs] [0da05bb4] GPencil_Editing_Stage3: GP EditMode: Simplify the way that this is handled

Joshua Leung noreply at git.blender.org
Fri Oct 23 05:57:52 CEST 2015


Commit: 0da05bb4dcf6a19493d6740068914e3baa04ceda
Author: Joshua Leung
Date:   Fri Oct 23 13:22:26 2015 +1300
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB0da05bb4dcf6a19493d6740068914e3baa04ceda

GP EditMode: Simplify the way that this is handled

Now, instead of actually altering the ob->mode flag, we just make the
object mode setter operator (and the header) delegate to the appropriate
GPencil things to do their thing if they wish first.

As a result, we don't have to worry about version patching or issues with
changing selected/active objects.

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

M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/object/object_edit.c
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index cf77956..d09c36a 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -87,52 +87,16 @@ static int gpencil_editmode_toggle_poll(bContext *C)
 static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
 {
 	bGPdata *gpd = ED_gpencil_data_get_active(C);
-	Scene *scene = CTX_data_scene(C);
-	Object *ob = OBACT;
-	ScrArea *sa = CTX_wm_area(C);
 	
-	/* Toggle editmode flag... */
 	if (gpd == NULL)
 		return OPERATOR_CANCELLED;
 	
-	/* Grease Pencil in the 3D view should be synced with the active object's
-	 * mode setting (ob->mode) which now reflects GPencil status...
-	 *
-	 * Other editors though can just toggle the mode
-	 */
-	if (((sa == NULL) || (sa->spacetype == SPACE_VIEW3D)) && 
-	    (ob != NULL)) 
-	{
-		const int mode_flag = OB_MODE_GPENCIL;
-		const bool is_mode_set = (ob->mode & mode_flag) != 0;
-		
-		if (!is_mode_set) {
-			if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
-				return OPERATOR_CANCELLED;
-			}
-		}
-		
-		/* Toggle editmode and sync with object mode */
-		ob->restore_mode = ob->mode;
-		
-		if (is_mode_set) {
-			gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
-			ob->mode &= ~mode_flag;
-		}
-		else {
-			gpd->flag |= GP_DATA_STROKE_EDITMODE;
-			ob->mode |= mode_flag;
-		}
-		
-		WM_event_add_notifier(C, NC_SCENE | ND_MODE, NULL);
-	}
-	else {
-		/* Just toggle editmode */
-		gpd->flag ^= GP_DATA_STROKE_EDITMODE;
-	}
+	/* Just toggle editmode flag... */
+	gpd->flag ^= GP_DATA_STROKE_EDITMODE;
 	
-	/* GP editmode should have changed if we reach this point... */
 	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | ND_GPENCIL_EDITMODE, NULL);
+	WM_event_add_notifier(C, NC_SCENE | ND_MODE, NULL);
+	
 	return OPERATOR_FINISHED;
 }
 
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 1203bc9..29cb5a7 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1656,12 +1656,22 @@ static int object_mode_set_exec(bContext *C, wmOperator *op)
 	ObjectMode restore_mode = (ob) ? ob->mode : OB_MODE_OBJECT;
 	const bool toggle = RNA_boolean_get(op->ptr, "toggle");
 	
-	if (!ob && gpd) {
-		/* HACK: Just toggle GPencil editmode anyway if there's no object,
-		 *       since GPencil editing can still work... Just don't go any
-		 *       further, or else the rest of the code will break.
+	if (gpd) {
+		/* GP Mode is not bound to a specific object. Therefore,
+		 * we don't want it to be actually saved on any objects,
+		 * as weirdness can happen if you select other objects,
+		 * or load old files.
+		 *
+		 * Instead, we use the following 2 rules to ensure that
+		 * the mode selector works as expected:
+		 *  1) If there's no object, we want to enter editmode.
+		 *     (i.e. with no object, we're in object mode)
+		 *  2) Otherwise, exit stroke editmode, so that we can
+		 *     enter another mode...
 		 */
-		return WM_operator_name_call(C, "GPENCIL_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+		if (!ob || (gpd->flag & GP_DATA_STROKE_EDITMODE)) {
+			WM_operator_name_call(C, "GPENCIL_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+		}
 	}
 	
 	if (!ob || !object_mode_compat_test(ob, mode))
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 23e7be3..d037873 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -60,31 +60,9 @@ static void rna_GPencil_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointe
 
 static void rna_GPencil_editmode_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
 {
-	bGPdata *gpd = (bGPdata *)ptr->id.data;
-	Object *ob = OBACT;
-	
 	/* Notify all places where GPencil data lives that the editing state is different */
 	WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
-	
-	/* If this datablock is used as the scene or active object's GP data,
-	 * we're going to have to update the object's mode to keep those in sync,
-	 * since the normal mode selector can now be used for changing these modes
-	 * too when using the datablock in the 3D View.
-	 */
-	if (gpd && ob) {
-		if ((scene->gpd == gpd) || (ob->gpd == gpd)) {
-			ob->restore_mode = ob->mode;
-			
-			if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
-				ob->mode |= OB_MODE_GPENCIL;
-			}
-			else {
-				ob->mode &= ~OB_MODE_GPENCIL;
-			}
-			
-			WM_main_add_notifier(NC_SCENE | ND_MODE, NULL);
-		}
-	}
+	WM_main_add_notifier(NC_SCENE | ND_MODE, NULL);
 }
 
 static char *rna_GPencilLayer_path(PointerRNA *ptr)




More information about the Bf-blender-cvs mailing list