[Bf-blender-cvs] [69665bc7f06] master: RNA: move cursor into own struct

Campbell Barton noreply at git.blender.org
Fri Mar 1 02:42:33 CET 2019


Commit: 69665bc7f06d727499596c87f1c08c1fc064efba
Author: Campbell Barton
Date:   Fri Mar 1 12:35:48 2019 +1100
Branches: master
https://developer.blender.org/rB69665bc7f06d727499596c87f1c08c1fc064efba

RNA: move cursor into own struct

Without this it's impractical to subscribe to any change to the cursor.

Fixes T61969 by having gizmos update on any change to the cursor.

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

M	release/scripts/modules/bpy_extras/object_utils.py
M	release/scripts/startup/bl_operators/object.py
M	release/scripts/startup/bl_operators/object_align.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	release/scripts/templates_py/gizmo_operator.py
M	release/scripts/templates_py/operator_modal_view3d_raycast.py
M	source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py
index df6feff4591..5f3d6fbc50f 100644
--- a/release/scripts/modules/bpy_extras/object_utils.py
+++ b/release/scripts/modules/bpy_extras/object_utils.py
@@ -61,7 +61,7 @@ def add_object_align_init(context, operator):
     if operator and properties.is_property_set("location"):
         location = Matrix.Translation(Vector(properties.location))
     else:
-        location = Matrix.Translation(context.scene.cursor_location)
+        location = Matrix.Translation(context.scene.cursor.location)
 
         if operator:
             properties.location = location.to_translation()
diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index 42db2ca337d..bef3fef952a 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -873,7 +873,7 @@ class DupliOffsetFromCursor(Operator):
         scene = context.scene
         collection = context.collection
 
-        collection.instance_offset = scene.cursor_location
+        collection.instance_offset = scene.cursor.location
 
         return {'FINISHED'}
 
@@ -904,7 +904,7 @@ class LoadImageAsEmpty:
     def execute(self, context):
         scene = context.scene
         space = context.space_data
-        cursor = scene.cursor_location
+        cursor = scene.cursor.location
 
         try:
             image = bpy.data.images.load(self.filepath, check_existing=True)
diff --git a/release/scripts/startup/bl_operators/object_align.py b/release/scripts/startup/bl_operators/object_align.py
index cf6d796798b..b18f49e614c 100644
--- a/release/scripts/startup/bl_operators/object_align.py
+++ b/release/scripts/startup/bl_operators/object_align.py
@@ -130,7 +130,7 @@ def align_objects(context,
     depsgraph = context.depsgraph
     scene = context.scene
 
-    cursor = scene.cursor_location
+    cursor = scene.cursor.location
 
     # We are accessing runtime data such as evaluated bounding box, so we need to
     # be sure it is properly updated and valid (bounding box might be lost on operator
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 65e4ea03fad..178a91ba7e3 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4359,17 +4359,17 @@ class VIEW3D_PT_view3d_cursor(Panel):
     def draw(self, context):
         layout = self.layout
 
-        scene = context.scene
+        cursor = context.scene.cursor
 
-        layout.column().prop(scene, "cursor_location", text="Location")
-        rotation_mode = scene.cursor_rotation_mode
+        layout.column().prop(cursor, "location", text="Location")
+        rotation_mode = cursor.rotation_mode
         if rotation_mode == 'QUATERNION':
-            layout.column().prop(scene, "cursor_rotation_quaternion", text="Rotation")
+            layout.column().prop(cursor, "rotation_quaternion", text="Rotation")
         elif rotation_mode == 'AXIS_ANGLE':
-            layout.column().prop(scene, "cursor_rotation_axis_angle", text="Rotation")
+            layout.column().prop(cursor, "rotation_axis_angle", text="Rotation")
         else:
-            layout.column().prop(scene, "cursor_rotation_euler", text="Rotation")
-        layout.prop(scene, "cursor_rotation_mode", text="")
+            layout.column().prop(cursor, "rotation_euler", text="Rotation")
+        layout.prop(cursor, "rotation_mode", text="")
 
 
 class VIEW3D_PT_collections(Panel):
diff --git a/release/scripts/templates_py/gizmo_operator.py b/release/scripts/templates_py/gizmo_operator.py
index 96f4f4de940..7ab694c1619 100644
--- a/release/scripts/templates_py/gizmo_operator.py
+++ b/release/scripts/templates_py/gizmo_operator.py
@@ -55,7 +55,7 @@ class SelectSideOfPlane(Operator):
     def invoke(self, context, event):
 
         if not self.properties.is_property_set("plane_co"):
-            self.plane_co = context.scene.cursor_location
+            self.plane_co = context.scene.cursor.location
 
         if not self.properties.is_property_set("plane_no"):
             if context.space_data.type == 'VIEW_3D':
diff --git a/release/scripts/templates_py/operator_modal_view3d_raycast.py b/release/scripts/templates_py/operator_modal_view3d_raycast.py
index e5467228dfa..2c596b3b356 100644
--- a/release/scripts/templates_py/operator_modal_view3d_raycast.py
+++ b/release/scripts/templates_py/operator_modal_view3d_raycast.py
@@ -58,7 +58,7 @@ def main(context, event):
             hit, normal, face_index = obj_ray_cast(obj, matrix)
             if hit is not None:
                 hit_world = matrix @ hit
-                scene.cursor_location = hit_world
+                scene.cursor.location = hit_world
                 length_squared = (hit_world - ray_origin).length_squared
                 if best_obj is None or length_squared < best_length_squared:
                     best_length_squared = length_squared
diff --git a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
index 52b011cf83e..9884ded4f0a 100644
--- a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
@@ -438,18 +438,10 @@ static void gizmo_mesh_spin_init_message_subscribe(
 		.notify = WM_gizmo_do_msg_notify_tag_refresh,
 	};
 
-	PointerRNA scene_ptr;
-	RNA_id_pointer_create(&scene->id, &scene_ptr);
-
-	{
-		extern PropertyRNA rna_Scene_cursor_location;
-		const PropertyRNA *props[] = {
-			&rna_Scene_cursor_location,
-		};
-		for (int i = 0; i < ARRAY_SIZE(props); i++) {
-			WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
-		}
-	}
+	PointerRNA cursor_ptr;
+	RNA_pointer_create(&scene->id, &RNA_View3DCursor, &scene->cursor, &cursor_ptr);
+	/* All cursor properties. */
+	WM_msg_subscribe_rna(mbus, &cursor_ptr, NULL, &msg_sub_value_gz_tag_refresh, __func__);
 
 	WM_msg_subscribe_rna_params(
 	        mbus,
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index eeb34bde66d..82d7e4eac4c 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -4819,8 +4819,9 @@ void ED_view3d_cursor3d_update(
 
 	{
 		struct wmMsgBus *mbus = CTX_wm_message_bus(C);
-		WM_msg_publish_rna_prop(
-		        mbus, &scene->id, scene, Scene, cursor_location);
+		wmMsgParams_RNA msg_key_params = {{{0}}};
+		RNA_pointer_create(&scene->id, &RNA_View3DCursor, &scene->cursor, &msg_key_params.ptr);
+		WM_msg_publish_rna_params(mbus, &msg_key_params);
 	}
 
 	DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index e1066315508..2e6a399d0ea 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -1227,25 +1227,29 @@ static void gizmo_xform_message_subscribe(
 	TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, orient_flag);
 	PointerRNA orient_ref_ptr;
 	RNA_pointer_create(&scene->id, &RNA_TransformOrientationSlot, orient_slot, &orient_ref_ptr);
+	const ToolSettings *ts = scene->toolsettings;
 
 	PointerRNA scene_ptr;
 	RNA_id_pointer_create(&scene->id, &scene_ptr);
 	{
-		const ToolSettings *ts = scene->toolsettings;
 		extern PropertyRNA rna_Scene_transform_orientation_slots;
-		extern PropertyRNA rna_Scene_cursor_location;
 		const PropertyRNA *props[] = {
 			&rna_Scene_transform_orientation_slots,
-			((ts->transform_pivot_point == V3D_AROUND_CURSOR) || (orient_slot->type == V3D_ORIENT_CURSOR)) ?
-			&rna_Scene_cursor_location : NULL,
 		};
 		for (int i = 0; i < ARRAY_SIZE(props); i++) {
-			if (props[i]) {
-				WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
-			}
+			WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
 		}
 	}
 
+	if ((ts->transform_pivot_point == V3D_AROUND_CURSOR) ||
+	    (orient_slot->type == V3D_ORIENT_CURSOR))
+	{
+		/* We could be more specific here, for now subscribe to any cursor change. */
+		PointerRNA cursor_ptr;
+		RNA_pointer_create(&scene->id, &RNA_View3DCursor, &scene->cursor, &cursor_ptr);
+		WM_msg_subscribe_rna(mbus, &cursor_ptr, NULL, &msg_sub_value_gz_tag_refresh, __func__);
+	}
+
 	{
 		extern PropertyRNA rna_TransformOrientationSlot_type;
 		extern PropertyRNA rna_TransformOrientationSlot_use;
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index e0d3331c773..5866302a852 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -720,6 +720,7 @@ extern StructRNA RNA_VertexPaint;
 extern StructRNA RNA_VertexWeightEditModifier;
 extern StructRNA RNA_VertexWeightMixModifier;
 extern StructRNA RNA_VertexWeightProximityModifier;
+extern StructRNA RNA_View3DCursor;
 extern StructRNA RNA_View3DOverlay;
 extern StructRNA RNA_View3DShading;
 extern StructRNA RNA_ViewLayer;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 301f7cfd5ea..ecf09837c0a 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -1635,10 +1635,9 @@ static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
 	}
 }
 
-static void rna_Scene_cursor_rotation_mode_set(PointerRNA *ptr, int value)
+static void rna_View3DCursor_rotation_mode_set(PointerRNA *ptr, int value)
 {
-	Scene *scene = ptr->id.data;
-	View3DCursor *cursor = &scene->cursor;
+	View3DCursor *cursor = ptr->data;
 
 	/* use API Method for conversions... */
 	BKE_rotMode_change_values(
@@ -1650,18 +1649,16 @@ static void rna_Scene_cursor_rotation_mode_set(PointerRNA *ptr, int value)
 	cursor->rotation_mode = value;
 }
 
-static void rna_Scene_cursor_rotation_axis_angle_get(PointerRNA *ptr, float *value)
+static void rna_View3DCursor_rotation_axis_angle_get(PointerRNA *p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list