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.
This commit is contained in:
Campbell Barton
2019-03-01 12:35:48 +11:00
parent 795effcbc8
commit 69665bc7f0
11 changed files with 96 additions and 84 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -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

View File

@@ -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):

View File

@@ -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':

View File

@@ -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

View File

@@ -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,

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 *ptr, float *value)
{
Scene *scene = ptr->id.data;
View3DCursor *cursor = &scene->cursor;
View3DCursor *cursor = ptr->data;
value[0] = cursor->rotation_angle;
copy_v3_v3(&value[1], cursor->rotation_axis);
}
static void rna_Scene_cursor_rotation_axis_angle_set(PointerRNA *ptr, const float *value)
static void rna_View3DCursor_rotation_axis_angle_set(PointerRNA *ptr, const float *value)
{
Scene *scene = ptr->id.data;
View3DCursor *cursor = &scene->cursor;
View3DCursor *cursor = ptr->data;
cursor->rotation_angle = value[0];
copy_v3_v3(cursor->rotation_axis, &value[1]);
}
@@ -2348,6 +2345,55 @@ static void rna_def_transform_orientation_slot(BlenderRNA *brna)
RNA_def_function_output(func, parm);
}
static void rna_def_view3d_cursor(BlenderRNA *brna)
{
static float default_quat[4] = {1, 0, 0, 0}; /* default quaternion values */
static float default_axisAngle[4] = {0, 0, 1, 0}; /* default axis-angle rotation values */
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "View3DCursor", NULL);
RNA_def_struct_sdna(srna, "View3DCursor");
RNA_def_struct_ui_text(srna, "3D Cursor", "");
prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ_LENGTH);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_float_sdna(prop, NULL, "location");
RNA_def_property_ui_text(prop, "Location", "");
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_float_sdna(prop, NULL, "rotation_quaternion");
RNA_def_property_float_array_default(prop, default_quat);
RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in quaternions (keep normalized)");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_array(prop, 4);
RNA_def_property_float_funcs(prop, "rna_View3DCursor_rotation_axis_angle_get",
"rna_View3DCursor_rotation_axis_angle_set", NULL);
RNA_def_property_float_array_default(prop, default_axisAngle);
RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_float_sdna(prop, NULL, "rotation_euler");
RNA_def_property_ui_text(prop, "Euler Rotation", "3D rotation");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_enum_sdna(prop, NULL, "rotation_mode");
RNA_def_property_enum_items(prop, rna_enum_object_rotation_mode_items);
RNA_def_property_enum_funcs(prop, NULL, "rna_View3DCursor_rotation_mode_set", NULL);
RNA_def_property_ui_text(prop, "Rotation Mode", "");
RNA_def_property_update(prop, NC_WINDOW, NULL);
}
static void rna_def_tool_settings(BlenderRNA *brna)
{
@@ -6332,10 +6378,6 @@ void RNA_def_scene(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL},
};
static float default_quat[4] = {1, 0, 0, 0}; /* default quaternion values */
static float default_axisAngle[4] = {0, 0, 1, 0}; /* default axis-angle rotation values */
/* Struct definition */
srna = RNA_def_struct(brna, "Scene", "ID");
RNA_def_struct_ui_text(srna, "Scene", "Scene data-block, consisting in objects and "
@@ -6363,43 +6405,6 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "World", "World used for rendering the scene");
RNA_def_property_update(prop, NC_SCENE | ND_WORLD, "rna_Scene_world_update");
prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ_LENGTH);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_float_sdna(prop, NULL, "cursor.location");
RNA_def_property_ui_text(prop, "Cursor Location", "3D cursor location");
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "cursor_rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_float_sdna(prop, NULL, "cursor.rotation_quaternion");
RNA_def_property_float_array_default(prop, default_quat);
RNA_def_property_ui_text(prop, "Cursor Quaternion Rotation", "3D cursor rotation in quaternions (keep normalized)");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "cursor_rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_array(prop, 4);
RNA_def_property_float_funcs(prop, "rna_Scene_cursor_rotation_axis_angle_get",
"rna_Scene_cursor_rotation_axis_angle_set", NULL);
RNA_def_property_float_array_default(prop, default_axisAngle);
RNA_def_property_ui_text(prop, "Cursor Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "cursor_rotation_euler", PROP_FLOAT, PROP_EULER);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_float_sdna(prop, NULL, "cursor.rotation_euler");
RNA_def_property_ui_text(prop, "Cursor Euler Rotation", "3D cursor rotation");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "cursor_rotation_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_enum_sdna(prop, NULL, "cursor.rotation_mode");
RNA_def_property_enum_items(prop, rna_enum_object_rotation_mode_items);
RNA_def_property_enum_funcs(prop, NULL, "rna_Scene_cursor_rotation_mode_set", NULL);
RNA_def_property_ui_text(prop, "Cursor Rotation Mode", "");
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_ui_text(prop, "Objects", "");
@@ -6655,6 +6660,14 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "TransformOrientationSlot");
RNA_def_property_ui_text(prop, "Transform Orientation Slots", "");
/* 3D View Cursor */
prop = RNA_def_property(srna, "cursor", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "cursor");
RNA_def_property_struct_type(prop, "View3DCursor");
RNA_def_property_ui_text(prop, "3D Cursor", "");
/* Audio Settings */
prop = RNA_def_property(srna, "use_audio", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_Scene_use_audio_get", "rna_Scene_use_audio_set");
@@ -6780,6 +6793,7 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_scene_image_format_data(brna);
rna_def_transform_orientation(brna);
rna_def_transform_orientation_slot(brna);
rna_def_view3d_cursor(brna);
rna_def_selected_uv_element(brna);
rna_def_display_safe_areas(brna);
rna_def_scene_display(brna);