[Bf-blender-cvs] [3b13303] GPencil_Editing_Stage3: GPencil Stroke Editing: Stroke Editmode now behaves like other editing modes for objects

Joshua Leung noreply at git.blender.org
Sat Sep 19 14:10:48 CEST 2015


Commit: 3b1330396ebe2cea8479c26b7c34aa2c217a4e1a
Author: Joshua Leung
Date:   Sat Sep 19 18:54:19 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB3b1330396ebe2cea8479c26b7c34aa2c217a4e1a

GPencil Stroke Editing: Stroke Editmode now behaves like other editing modes for objects

You can now enter stroke editmode from the usual mode dropdown in the 3D View
header. While this isn't strictly correct (data-wise, GPencil datablocks can
belong to stuff other than the active object), for the most common use case
of usage in the 3D view, this is appropriate.

Notes:
* This still needs more careful checking to ensure correctness/consistency of
  behaviour in all edge cases (e.g. gpencil datablock in a different editor,
  or user manually changed the mode toggle, etc.)

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/object/object_edit.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index cfa8a92..766044d 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -226,7 +226,7 @@ class GPENCIL_PIE_tool_palette(Menu):
         if gpd:
             if gpd.use_stroke_edit_mode and context.editable_gpencil_strokes:
                 # S - Exit Edit Mode
-                pie.prop(gpd, "use_stroke_edit_mode", text="Exit Edit Mode", icon='EDIT')
+                pie.operator("gpencil.editmode_toggle", text="Exit Edit Mode", icon='EDIT')
 
                 # N - Transforms
                 col = pie.column()
@@ -260,7 +260,7 @@ class GPENCIL_PIE_tool_palette(Menu):
                 pie.operator("wm.call_menu_pie", text="More...").name = "GPENCIL_PIE_tools_more"
             else:
                 # Toggle Edit Mode
-                pie.prop(gpd, "use_stroke_edit_mode", text="Enable Stroke Editing", icon='EDIT')
+                pie.operator("gpencil.editmode_toggle", text="Enable Stroke Editing", icon='EDIT')
 
 
 class GPENCIL_PIE_settings_palette(Menu):
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 38cc1f5..9bf175c 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -37,6 +37,7 @@
 #include "BKE_context.h"
 
 #include "DNA_gpencil_types.h"
+#include "DNA_object_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -50,6 +51,61 @@
 #include "gpencil_intern.h"
 
 /* ****************************************** */
+// XXX: move this
+
+static int gpencil_editmode_toggle_poll(bContext *C)
+{
+	return ED_gpencil_data_get_active(C) != NULL;
+}
+
+static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Object *ob = CTX_data_active_object(C);
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	
+	/* Toggle editmode flag... */
+	if (gpd == NULL)
+		return OPERATOR_CANCELLED;
+	
+	gpd->flag ^= GP_DATA_STROKE_EDITMODE;
+	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | ND_GPENCIL_EDITMODE, NULL);
+	
+	
+	/* Update active object's mode setting,
+	 * as it now needs to reflect GPencil status... 
+	 */
+	if (ob) {
+		ob->restore_mode = ob->mode;
+		
+		if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
+			ob->mode |= OB_MODE_GPENCIL;
+		}
+		else {
+			ob->mode &= ~OB_MODE_GPENCIL;
+		}
+		
+		WM_event_add_notifier(C, NC_SCENE | ND_MODE, NULL);
+	}
+	
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_editmode_toggle(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Strokes Edit Mode Toggle";
+	ot->idname = "GPENCIL_OT_editmode_toggle";
+	ot->description = "Enter/Exit edit mode for Grease Pencil strokes";
+	
+	/* callbacks */
+	ot->exec = gpencil_editmode_toggle_exec;
+	ot->poll = gpencil_editmode_toggle_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
+}
+
+/* ****************************************** */
 /* Grease Pencil Keymaps */
 
 /* Generic Drawing Keymap */
@@ -97,8 +153,7 @@ static void ed_keymap_gpencil_general(wmKeyConfig *keyconf)
 	/* Viewport Tools ------------------------------- */
 	
 	/* Enter EditMode */
-	kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, 0, DKEY);
-	RNA_string_set(kmi->ptr, "data_path", "gpencil_data.use_stroke_edit_mode");
+	WM_keymap_add_item(keymap, "GPENCIL_OT_editmode_toggle", TABKEY, KM_PRESS, 0, DKEY);
 	
 	/* Pie Menu - For standard tools */
 	WM_keymap_add_menu_pie(keymap, "GPENCIL_PIE_tool_palette", QKEY, KM_PRESS, 0, DKEY);
@@ -126,8 +181,7 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
 	/* ----------------------------------------------- */
 	
 	/* Exit EditMode */
-	kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, 0, 0);
-	RNA_string_set(kmi->ptr, "data_path", "gpencil_data.use_stroke_edit_mode");
+	WM_keymap_add_item(keymap, "GPENCIL_OT_editmode_toggle", TABKEY, KM_PRESS, 0, 0);
 	
 	/* Pie Menu - For settings/tools easy access */
 	WM_keymap_add_menu_pie(keymap, "GPENCIL_PIE_sculpt", EKEY, KM_PRESS, 0, DKEY);
@@ -279,6 +333,8 @@ void ED_operatortypes_gpencil(void)
 	
 	/* Editing (Strokes) ------------ */
 	
+	WM_operatortype_append(GPENCIL_OT_editmode_toggle);
+	
 	WM_operatortype_append(GPENCIL_OT_select);
 	WM_operatortype_append(GPENCIL_OT_select_all);
 	WM_operatortype_append(GPENCIL_OT_select_circle);
@@ -322,12 +378,14 @@ void ED_operatormacros_gpencil(void)
 	wmOperatorType *ot;
 	wmOperatorTypeMacro *otmacro;
 	
+	/* Duplicate + Move = Interactively place newly duplicated strokes */
 	ot = WM_operatortype_append_macro("GPENCIL_OT_duplicate_move", "Duplicate Strokes",
 	                                  "Make copies of the selected Grease Pencil strokes and move them",
 	                                  OPTYPE_UNDO | OPTYPE_REGISTER);
 	WM_operatortype_macro_define(ot, "GPENCIL_OT_duplicate");
 	otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
 	RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true);
+
 }
 
 /* ****************************************** */
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index c87eeae..e797605 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -46,6 +46,7 @@
 
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_gpencil_types.h"
 #include "DNA_group_types.h"
 #include "DNA_material_types.h"
 #include "DNA_meta_types.h"
@@ -1505,6 +1506,7 @@ static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(
 	EnumPropertyItem *input = object_mode_items;
 	EnumPropertyItem *item = NULL;
 	Object *ob;
+	bGPdata *gpd;
 	int totitem = 0;
 
 	if (!C) /* needed for docs */
@@ -1532,6 +1534,14 @@ static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(
 		/* We need at least this one! */
 		RNA_enum_items_add_value(&item, &totitem, input, OB_MODE_OBJECT);
 	}
+	
+	/* On top of all the rest, GPencil Stroke Edit Mode
+	 * is available if there's a valid gp datablock...
+	 */
+	gpd = CTX_data_gpencil_data(C);
+	if (gpd) {
+		RNA_enum_items_add_value(&item, &totitem, object_mode_items, OB_MODE_GPENCIL);
+	}
 
 	RNA_enum_item_end(&item, &totitem);
 
@@ -1556,6 +1566,8 @@ static const char *object_mode_op_string(int mode)
 		return "PARTICLE_OT_particle_edit_toggle";
 	if (mode == OB_MODE_POSE)
 		return "OBJECT_OT_posemode_toggle";
+	if (mode == OB_MODE_GPENCIL)
+		return "GPENCIL_OT_editmode_toggle";
 	return NULL;
 }
 
@@ -1567,6 +1579,8 @@ static bool object_mode_compat_test(Object *ob, ObjectMode mode)
 	if (ob) {
 		if (mode == OB_MODE_OBJECT)
 			return true;
+		else if (mode == OB_MODE_GPENCIL)
+			return true; /* XXX: assume this is the case for now... */
 
 		switch (ob->type) {
 			case OB_MESH:
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index faae78a..8b6fc61 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -673,6 +673,7 @@ typedef enum ObjectMode {
 	OB_MODE_TEXTURE_PAINT = 1 << 4,
 	OB_MODE_PARTICLE_EDIT = 1 << 5,
 	OB_MODE_POSE          = 1 << 6,
+	OB_MODE_GPENCIL       = 1 << 7,  /* NOTE: Just a dummy to make the UI nicer */
 } ObjectMode;
 
 /* any mode where the brush system is used */
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 54f1798..ff52eba 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -69,6 +69,7 @@ EnumPropertyItem object_mode_items[] = {
 	{OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
 	{OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
 	{OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", ICON_PARTICLEMODE, "Particle Edit", ""},
+	{OB_MODE_GPENCIL, "GPENCIL_EDIT", ICON_GREASEPENCIL, "Edit Strokes", "Edit Grease Pencil Strokes"},
 	{0, NULL, 0, NULL, NULL}
 };




More information about the Bf-blender-cvs mailing list