[Bf-blender-cvs] [96a7ed8a159] blender2.8: Tool System: store operator properties in the tool

Campbell Barton noreply at git.blender.org
Tue May 22 15:31:39 CEST 2018


Commit: 96a7ed8a159fec97ab19a6d19ffe6201a4ee2b35
Author: Campbell Barton
Date:   Tue May 22 14:00:44 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB96a7ed8a159fec97ab19a6d19ffe6201a4ee2b35

Tool System: store operator properties in the tool

This replaces last-used property use which wasn't reliable since
properties were not considered 'set' - causing them to be ignored.

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

M	release/scripts/startup/bl_ui/space_toolsystem_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/makesrna/intern/rna_workspace_api.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_toolsystem.c
M	source/blender/windowmanager/wm_event_system.h

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index 717beac1289..8a494369cf5 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -237,14 +237,11 @@ class ToolSelectPanelHelper:
         """
         Return the active Python tool definition and icon name.
         """
-
         workspace = context.workspace
         cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
         if cls is not None:
-            tool_active_text = getattr(
-                ToolSelectPanelHelper._tool_active_from_context(context, space_type, mode),
-                "name", None)
-
+            tool_active = ToolSelectPanelHelper._tool_active_from_context(context, space_type, mode)
+            tool_active_text = getattr(tool_active, "name", None)
             for item in ToolSelectPanelHelper._tools_flatten(cls.tools_from_context(context, mode)):
                 if item is not None:
                     if item.text == tool_active_text:
@@ -252,8 +249,8 @@ class ToolSelectPanelHelper:
                             icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(item.icon)
                         else:
                             icon_value = 0
-                        return (item, icon_value)
-        return None, 0
+                        return (item, tool_active, icon_value)
+        return None, None, 0
 
     @staticmethod
     def _tool_get_by_name(context, space_type, text):
@@ -517,14 +514,14 @@ class ToolSelectPanelHelper:
         workspace = context.workspace
         space_type = workspace.tools_space_type
         mode = workspace.tools_mode
-        item, icon_value = ToolSelectPanelHelper._tool_get_active(context, space_type, mode, with_icon=True)
+        item, tool, icon_value = ToolSelectPanelHelper._tool_get_active(context, space_type, mode, with_icon=True)
         if item is None:
             return
         # Note: we could show 'item.text' here but it makes the layout jitter when switcuing tools.
         layout.label(" ", icon_value=icon_value)
         draw_settings = item.draw_settings
         if draw_settings is not None:
-            draw_settings(context, layout)
+            draw_settings(context, layout, tool)
 
 
 # The purpose of this menu is to be a generic popup to select between tools
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 137ca779065..8bcd56ce561 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -293,9 +293,9 @@ class _defs_edit_mesh:
 
     @ToolDef.from_fn
     def rip_region():
-        def draw_settings(context, layout):
+        def draw_settings(context, layout, tool):
             wm = context.window_manager
-            props = wm.operator_properties_last("mesh.rip_move")
+            props = tool.operator_properties("mesh.rip_move")
             props_macro = props.MESH_OT_rip
             layout.prop(props_macro, "use_fill")
 
@@ -393,9 +393,9 @@ class _defs_edit_mesh:
 
     @ToolDef.from_fn
     def inset():
-        def draw_settings(context, layout):
+        def draw_settings(context, layout, tool):
             wm = context.window_manager
-            props = wm.operator_properties_last("mesh.inset")
+            props = tool.operator_properties("mesh.inset")
             layout.prop(props, "use_outset")
             layout.prop(props, "use_individual")
             layout.prop(props, "use_even_offset")
@@ -507,9 +507,9 @@ class _defs_edit_mesh:
 
     @ToolDef.from_fn
     def shrink_fatten():
-        def draw_settings(context, layout):
+        def draw_settings(context, layout, tool):
             wm = context.window_manager
-            props = wm.operator_properties_last("transform.shrink_fatten")
+            props = tool.operator_properties("transform.shrink_fatten")
             layout.prop(props, "use_even_offset")
 
         return dict(
@@ -537,9 +537,9 @@ class _defs_edit_mesh:
 
     @ToolDef.from_fn
     def knife():
-        def draw_settings(context, layout):
+        def draw_settings(context, layout, tool):
             wm = context.window_manager
-            props = wm.operator_properties_last("mesh.knife_tool")
+            props = tool.operator_properties("mesh.knife_tool")
             layout.prop(props, "use_occlude_geometry")
             layout.prop(props, "only_selected")
 
@@ -573,7 +573,7 @@ class _defs_edit_curve:
 
     @ToolDef.from_fn
     def draw():
-        def draw_settings(context, layout):
+        def draw_settings(context, layout, tool):
             # Tool settings initialize operator options.
             tool_settings = context.tool_settings
             cps = tool_settings.curve_paint_settings
@@ -765,9 +765,9 @@ class _defs_weight_paint:
 
     @ToolDef.from_fn
     def gradient():
-        def draw_settings(context, layout):
+        def draw_settings(context, layout, tool):
             wm = context.window_manager
-            props = wm.operator_properties_last("paint.weight_gradient")
+            props = tool.operator_properties("paint.weight_gradient")
             layout.prop(props, "type")
 
         return dict(
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index fd316cb9d82..7fc0d814089 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -34,6 +34,7 @@
 #include "BLI_listbase.h"
 
 #include "BKE_global.h"
+#include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_scene.h"
@@ -176,6 +177,10 @@ void BKE_workspace_free(WorkSpace *workspace)
 		tref_next = tref->next;
 		if (tref->runtime) {
 			MEM_freeN(tref->runtime);
+			if (tref->properties) {
+				IDP_FreeProperty(tref->properties);
+				MEM_freeN(tref->properties);
+			}
 		}
 	}
 	BLI_freelistN(&workspace->tools);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a8181f1e043..c92b27bdb1c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2941,6 +2941,7 @@ static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main
 
 	for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) {
 		tref->runtime = NULL;
+		tref->properties = newdataadr(fd, tref->properties);
 	}
 }
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 8ea1205be38..a3cac39f609 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3602,6 +3602,11 @@ static void write_workspace(WriteData *wd, WorkSpace *workspace)
 	writelist(wd, DATA, WorkSpaceDataRelation, &workspace->scene_viewlayer_relations);
 	writelist(wd, DATA, wmOwnerID, &workspace->owner_ids);
 	writelist(wd, DATA, bToolRef, &workspace->tools);
+	for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) {
+		if (tref->properties) {
+			IDP_WriteProperty(tref->properties, wd);
+		}
+	}
 }
 
 /* Keep it last of write_foodata functions. */
diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h
index 24fa0e06d90..ca9186e16bf 100644
--- a/source/blender/makesdna/DNA_workspace_types.h
+++ b/source/blender/makesdna/DNA_workspace_types.h
@@ -56,11 +56,13 @@
 #
 #
 typedef struct bToolRef_Runtime {
-	/* One of these must be defined. */
 	int cursor;
+
+	/* One of these 3 must be defined. */
 	char keymap[64];
 	char manipulator_group[64];
 	char data_block[64];
+
 	/* index when a tool is a member of a group */
 	int index;
 } bToolRef_Runtime;
@@ -82,6 +84,15 @@ typedef struct bToolRef {
 	 */
 	int mode;
 
+	/**
+	 * Use for tool options, each group's name must match a tool name:
+	 *
+	 *    {"Tool Name": {"SOME_OT_operator": {...}, ..}, ..}
+	 *
+	 * This is done since different tools may call the same operators with their own options.
+	 */
+	IDProperty *properties;
+
 	/** Variables needed to operate the tool. */
 	bToolRef_Runtime *runtime;
 } bToolRef;
diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c
index 4c6949cc33d..e56d9a0bc33 100644
--- a/source/blender/makesrna/intern/rna_workspace_api.c
+++ b/source/blender/makesrna/intern/rna_workspace_api.c
@@ -64,6 +64,20 @@ static void rna_WorkspaceTool_setup(
 	WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, name);
 }
 
+static PointerRNA rna_WorkspaceTool_operator_properties(
+        bToolRef *tref,
+        const char *idname)
+{
+	wmOperatorType *ot = WM_operatortype_find(idname, true);
+
+	if (ot != NULL) {
+		PointerRNA ptr;
+		WM_toolsystem_ref_properties_ensure(tref, ot, &ptr);
+		return ptr;
+	}
+	return PointerRNA_NULL;
+}
+
 #else
 
 void RNA_api_workspace(StructRNA *UNUSED(srna))
@@ -91,6 +105,16 @@ void RNA_api_workspace_tool(StructRNA *srna)
 	RNA_def_string(func, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", "");
 	RNA_def_string(func, "data_block", NULL, MAX_NAME, "Data Block", "");
 	RNA_def_int(func, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX);
+
+	/* Access tool operator options (optionally create). */
+	func = RNA_def_function(srna, "operator_properties", "rna_WorkspaceTool_operator_properties");
+	parm = RNA_def_string(func, "operator", NULL, 0, "", "");
+	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+	/* return */
+	parm = RNA_def_pointer(func, "result", "OperatorProperties", "", "");
+	RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
+	RNA_def_function_return(func, parm);
+	
 }
 
 #endif
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 050edb980e9..33222b2f1f1 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -646,6 +646,12 @@ bool WM_toolsystem_active_tool_is_brush(const struct bContext *C);
 void WM_toolsystem_do_msg_notify_tag

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list