diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-16 08:19:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-16 08:19:48 +0400 |
commit | b380dd9378707bbf4a45ed456d49f28cf762b882 (patch) | |
tree | 4f6513ef26bf3f48af9ac7b16f69eeb47827fd0a | |
parent | 23626e0149f25f13855735bbb7f65121e0c40ca0 (diff) |
fix [#36537] "Grid Floor Scaling" can have some unexpected behaviour on new objects
curves and metaballs now behave the same as meshes wrt grid scaling.
remove WM_operator_view3d_distance_invoke(), and replace with a function called from exec which initializes defaults, this way operators can have their own invoke functions.
-rw-r--r-- | release/scripts/startup/bl_ui/space_info.py | 6 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve_add.c | 21 | ||||
-rw-r--r-- | source/blender/editors/include/ED_mball.h | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 18 | ||||
-rw-r--r-- | source/blender/editors/metaball/mball_edit.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 12 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 40 |
8 files changed, 64 insertions, 39 deletions
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py index 6701e700e14..591cfde5c16 100644 --- a/release/scripts/startup/bl_ui/space_info.py +++ b/release/scripts/startup/bl_ui/space_info.py @@ -227,7 +227,7 @@ class INFO_MT_curve_add(Menu): def draw(self, context): layout = self.layout - layout.operator_context = 'EXEC_REGION_WIN' + layout.operator_context = 'INVOKE_REGION_WIN' layout.operator("curve.primitive_bezier_curve_add", icon='CURVE_BEZCURVE', text="Bezier") layout.operator("curve.primitive_bezier_circle_add", icon='CURVE_BEZCIRCLE', text="Circle") layout.operator("curve.primitive_nurbs_curve_add", icon='CURVE_NCURVE', text="Nurbs Curve") @@ -242,7 +242,7 @@ class INFO_MT_surface_add(Menu): def draw(self, context): layout = self.layout - layout.operator_context = 'EXEC_REGION_WIN' + layout.operator_context = 'INVOKE_REGION_WIN' layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve") layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle") layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface") @@ -297,7 +297,9 @@ class INFO_MT_add(Menu): layout.menu("INFO_MT_curve_add", icon='OUTLINER_OB_CURVE') #layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE') layout.menu("INFO_MT_surface_add", icon='OUTLINER_OB_SURFACE') + layout.operator_context = 'INVOKE_REGION_WIN' layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META') + layout.operator_context = 'EXEC_REGION_WIN' layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT') layout.separator() diff --git a/source/blender/editors/curve/editcurve_add.c b/source/blender/editors/curve/editcurve_add.c index ceb9aa90aca..0bcb550b930 100644 --- a/source/blender/editors/curve/editcurve_add.c +++ b/source/blender/editors/curve/editcurve_add.c @@ -45,6 +45,8 @@ #include "BKE_depsgraph.h" #include "BKE_library.h" +#include "RNA_access.h" + #include "WM_api.h" #include "WM_types.h" @@ -471,9 +473,12 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) bool newob = false; bool enter_editmode, is_view_aligned; unsigned int layer; + float dia; float loc[3], rot[3]; float mat[4][4]; + WM_operator_view3d_unit_defaults(C, op); + if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, &is_view_aligned)) return OPERATOR_CANCELLED; @@ -520,7 +525,11 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) if (newob && enter_editmode) ED_undo_push(C, "Enter Editmode"); - ED_object_new_primitive_matrix(C, obedit, loc, rot, mat, true); + ED_object_new_primitive_matrix(C, obedit, loc, rot, mat, false); + dia = RNA_float_get(op->ptr, "radius"); + mat[0][0] *= dia; + mat[1][1] *= dia; + mat[2][2] *= dia; nu = add_nurbs_primitive(C, obedit, mat, type, newob); editnurb = object_editcurve_get(obedit); @@ -567,6 +576,7 @@ void CURVE_OT_primitive_bezier_curve_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -589,6 +599,7 @@ void CURVE_OT_primitive_bezier_circle_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -611,6 +622,7 @@ void CURVE_OT_primitive_nurbs_curve_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -633,6 +645,7 @@ void CURVE_OT_primitive_nurbs_circle_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -655,6 +668,7 @@ void CURVE_OT_primitive_nurbs_path_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -678,6 +692,7 @@ void SURFACE_OT_primitive_nurbs_surface_curve_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -700,6 +715,7 @@ void SURFACE_OT_primitive_nurbs_surface_circle_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -722,6 +738,7 @@ void SURFACE_OT_primitive_nurbs_surface_surface_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -744,6 +761,7 @@ void SURFACE_OT_primitive_nurbs_surface_cylinder_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -766,6 +784,7 @@ void SURFACE_OT_primitive_nurbs_surface_sphere_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } diff --git a/source/blender/editors/include/ED_mball.h b/source/blender/editors/include/ED_mball.h index da96aba011e..1842b84a3f5 100644 --- a/source/blender/editors/include/ED_mball.h +++ b/source/blender/editors/include/ED_mball.h @@ -39,7 +39,7 @@ struct wmKeyConfig; void ED_operatortypes_metaball(void); void ED_keymap_metaball(struct wmKeyConfig *keyconf); -struct MetaElem *add_metaball_primitive(struct bContext *C, struct Object *obedit, float mat[4][4], float dia, int type, int newname); +struct MetaElem *add_metaball_primitive(struct bContext *C, struct Object *obedit, float mat[4][4], float dia, int type); bool mouse_mball(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 094c9d376c9..47b9d5e2a9e 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -105,6 +105,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) bool was_editmode; unsigned int layer; + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Plane"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -130,7 +131,6 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_plane_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_plane_exec; ot->poll = ED_operator_scene_editable; @@ -150,6 +150,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op) bool was_editmode; unsigned int layer; + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Cube"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -176,7 +177,6 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_cube_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_cube_exec; ot->poll = ED_operator_scene_editable; @@ -206,6 +206,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op) cap_end = RNA_enum_get(op->ptr, "fill_type"); cap_tri = (cap_end == 2); + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Circle"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -232,7 +233,6 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_circle_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_circle_exec; ot->poll = ED_operator_scene_editable; @@ -259,6 +259,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) const bool cap_end = (end_fill_type != 0); const bool cap_tri = (end_fill_type == 2); + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Cylinder"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -290,7 +291,6 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_cylinder_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_cylinder_exec; ot->poll = ED_operator_scene_editable; @@ -319,6 +319,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op) const bool cap_end = (end_fill_type != 0); const bool cap_tri = (end_fill_type == 2); + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Cone"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -347,7 +348,6 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_cone_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_cone_exec; ot->poll = ED_operator_scene_editable; @@ -376,6 +376,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) bool was_editmode; unsigned int layer; + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Grid"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -403,7 +404,6 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_grid_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_grid_exec; ot->poll = ED_operator_scene_editable; @@ -428,6 +428,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op) unsigned int layer; bool was_editmode; + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, &is_view_aligned); if (!is_view_aligned) rot[0] += (float)M_PI / 2.0f; @@ -460,7 +461,6 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_monkey_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_monkey_exec; ot->poll = ED_operator_scene_editable; @@ -480,6 +480,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) bool was_editmode; unsigned int layer; + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Sphere"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -508,7 +509,6 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_uv_sphere_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_uvsphere_exec; ot->poll = ED_operator_scene_editable; @@ -533,6 +533,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) bool was_editmode; unsigned int layer; + WM_operator_view3d_unit_defaults(C, op); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Icosphere"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); @@ -561,7 +562,6 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_ico_sphere_add"; /* api callbacks */ - ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_icosphere_exec; ot->poll = ED_operator_scene_editable; diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index b79eeee49d7..68ca55651a8 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -98,7 +98,7 @@ void load_editMball(Object *UNUSED(obedit)) } /* Add metaelem primitive to metaball object (which is in edit mode) */ -MetaElem *add_metaball_primitive(bContext *UNUSED(C), Object *obedit, float mat[4][4], float dia, int type, int UNUSED(newname)) +MetaElem *add_metaball_primitive(bContext *UNUSED(C), Object *obedit, float mat[4][4], float dia, int type) { MetaBall *mball = (MetaBall *)obedit->data; MetaElem *ml; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index cd7c45d6c27..db68a0eca4d 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -578,6 +578,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) float mat[4][4]; float dia; + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; @@ -585,12 +586,14 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) obedit = ED_object_add_type(C, OB_MBALL, loc, rot, TRUE, layer); newob = true; } - else + else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } - dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat, FALSE); + ED_object_new_primitive_matrix(C, obedit, loc, rot, mat, false); + dia = RNA_float_get(op->ptr, "radius"); - add_metaball_primitive(C, obedit, mat, dia, RNA_enum_get(op->ptr, "type"), newob); + add_metaball_primitive(C, obedit, mat, dia, RNA_enum_get(op->ptr, "type")); /* userdef */ if (newob && !enter_editmode) { @@ -610,7 +613,7 @@ void OBJECT_OT_metaball_add(wmOperatorType *ot) ot->idname = "OBJECT_OT_metaball_add"; /* api callbacks */ - ot->invoke = WM_menu_invoke;/* object_metaball_add_invoke; */ + ot->invoke = WM_menu_invoke; ot->exec = object_metaball_add_exec; ot->poll = ED_operator_scene_editable; @@ -619,6 +622,7 @@ void OBJECT_OT_metaball_add(wmOperatorType *ot) ot->prop = RNA_def_enum(ot->srna, "type", metaelem_type_items, 0, "Primitive", ""); + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, TRUE); } diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index ce4513425d4..f9c18a3e0a2 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -186,7 +186,7 @@ void WM_event_timer_sleep(struct wmWindowManager *wm, struct wmWindow *win, str /* operator api, default callbacks */ /* invoke callback, uses enum property named "type" */ -int WM_operator_view3d_distance_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event); +void WM_operator_view3d_unit_defaults(struct bContext *C, struct wmOperator *op); int WM_operator_smooth_viewtx_get(const struct wmOperator *op); int WM_menu_invoke (struct bContext *C, struct wmOperator *op, const struct wmEvent *event); int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index de4b864ac1e..1e984649ca7 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -892,33 +892,33 @@ void WM_operator_properties_free(PointerRNA *ptr) /* ************ default op callbacks, exported *********** */ -int WM_operator_view3d_distance_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *UNUSED(event)) +void WM_operator_view3d_unit_defaults(struct bContext *C, struct wmOperator *op) { - Scene *scene = CTX_data_scene(C); - View3D *v3d = CTX_wm_view3d(C); + if (op->flag & OP_IS_INVOKE) { + Scene *scene = CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); - const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : ED_scene_grid_scale(scene, NULL); + const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : ED_scene_grid_scale(scene, NULL); - /* always run, so the values are initialized, - * otherwise we may get differ behavior when (dia != 1.0) */ - RNA_STRUCT_BEGIN (op->ptr, prop) - { - if (RNA_property_type(prop) == PROP_FLOAT) { - PropertySubType pstype = RNA_property_subtype(prop); - if (pstype == PROP_DISTANCE) { - /* we don't support arrays yet */ - BLI_assert(RNA_property_array_check(prop) == FALSE); - /* initialize */ - if (!RNA_property_is_set_ex(op->ptr, prop, FALSE)) { - const float value = RNA_property_float_get_default(op->ptr, prop) * dia; - RNA_property_float_set(op->ptr, prop, value); + /* always run, so the values are initialized, + * otherwise we may get differ behavior when (dia != 1.0) */ + RNA_STRUCT_BEGIN (op->ptr, prop) + { + if (RNA_property_type(prop) == PROP_FLOAT) { + PropertySubType pstype = RNA_property_subtype(prop); + if (pstype == PROP_DISTANCE) { + /* we don't support arrays yet */ + BLI_assert(RNA_property_array_check(prop) == FALSE); + /* initialize */ + if (!RNA_property_is_set_ex(op->ptr, prop, FALSE)) { + const float value = RNA_property_float_get_default(op->ptr, prop) * dia; + RNA_property_float_set(op->ptr, prop, value); + } } } } + RNA_STRUCT_END; } - RNA_STRUCT_END; - - return op->type->exec(C, op); } int WM_operator_smooth_viewtx_get(const wmOperator *op) |