diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-10-11 01:23:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-10-11 01:23:20 +0400 |
commit | a3f6b0ed00e2f93c7e666763e94bdf29003110ee (patch) | |
tree | c12dbc40ac8169f7b00d38a16c27bec38b3bbf58 /source/blender/editors/mesh | |
parent | deb30e8f9e7858a6e7800a31d0b2051471406162 (diff) |
- add torus back from 2.4x as an operator
bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops - MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 224 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_ops.c | 5 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 2 |
3 files changed, 90 insertions, 141 deletions
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 4af5ddf56fa..cb71765906c 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -70,6 +70,7 @@ #include "ED_transform.h" #include "ED_util.h" #include "ED_view3d.h" +#include "ED_object.h" #include "mesh_intern.h" @@ -1306,20 +1307,41 @@ static float new_primitive_matrix(bContext *C, float primmat[][4]) /* ********* add primitive operators ************* */ -static int add_primitive_plane_exec(bContext *C, wmOperator *op) +static void make_prim_ext(bContext *C, int type, int tot, int seg, + int subdiv, float dia, float depth, int ext, int fill) { Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - /* plane (diameter of 1.41 makes it unit size) */ - dia*= sqrt(2.0f); - - make_prim(obedit, PRIM_PLANE, mat, 4, 0, 0, dia, 0.0f, 0, 1); - + int newob; + float mat[4][4]; + + if(obedit==NULL || obedit->type!=OB_MESH) { + /* create editmode */ + ED_object_add_type(C, OB_MESH); + ED_object_enter_editmode(C, EM_DO_UNDO); + obedit= CTX_data_edit_object(C); + newob = 1; + } + else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); + + dia *= new_primitive_matrix(C, mat); + + make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill); + DAG_id_flush_update(obedit->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - + + + /* userdef */ + if (newob && (U.flag & USER_ADD_EDITMODE)==0) { + ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */ + } + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); +} + +static int add_primitive_plane_exec(bContext *C, wmOperator *op) +{ + /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */ + make_prim_ext(C, PRIM_PLANE, 4, 0, 0, sqrt(2.0f), 0.0f, 0, 1); return OPERATOR_FINISHED; } @@ -1332,7 +1354,7 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_plane_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1340,19 +1362,9 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) static int add_primitive_cube_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - /* plane (diameter of 1.41 makes it unit size) */ - dia*= sqrt(2.0f); - - make_prim(obedit, PRIM_CUBE, mat, 4, 0, 0, dia, 1.0f, 1, 1); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - - return OPERATOR_FINISHED; + /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */ + make_prim_ext(C, PRIM_CUBE, 4, 0, 0, sqrt(2.0f), 1.0f, 1, 1); + return OPERATOR_FINISHED; } void MESH_OT_primitive_cube_add(wmOperatorType *ot) @@ -1364,7 +1376,7 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_cube_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1372,18 +1384,10 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot) static int add_primitive_circle_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia *= RNA_float_get(op->ptr,"radius"); - - make_prim(obedit, PRIM_CIRCLE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 0.0f, 0, - RNA_boolean_get(op->ptr, "fill")); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - + make_prim_ext(C, PRIM_CIRCLE, RNA_int_get(op->ptr, "vertices"), 0, 0, + RNA_float_get(op->ptr,"radius"), 0.0f, 0, + RNA_boolean_get(op->ptr, "fill")); + return OPERATOR_FINISHED; } @@ -1396,32 +1400,24 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_circle_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 3, 500); - RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00); + RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); RNA_def_boolean(ot->srna, "fill", 0, "Fill", ""); } static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia *= RNA_float_get(op->ptr, "radius"); - - make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, - RNA_float_get(op->ptr, "depth"), 1, 1); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - - return OPERATOR_FINISHED; + make_prim_ext(C, PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0, + RNA_float_get(op->ptr,"radius"), + RNA_float_get(op->ptr, "depth"), 1, 1); + + return OPERATOR_FINISHED; } void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) @@ -1433,31 +1429,23 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_cylinder_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500); - RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00); - RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00); + RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); + RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); } static int add_primitive_tube_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia *= RNA_float_get(op->ptr, "radius"); - - make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, - RNA_float_get(op->ptr, "depth"), 1, 0); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - + make_prim_ext(C, PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0, + RNA_float_get(op->ptr,"radius"), + RNA_float_get(op->ptr, "depth"), 1, 0); + return OPERATOR_FINISHED; } @@ -1470,32 +1458,24 @@ void MESH_OT_primitive_tube_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_tube_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500); - RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00); - RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00); + RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); + RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); } static int add_primitive_cone_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia *= RNA_float_get(op->ptr, "radius"); - - make_prim(obedit, PRIM_CONE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, - RNA_float_get(op->ptr, "depth"), 0, RNA_boolean_get(op->ptr, "cap_end")); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - - return OPERATOR_FINISHED; + make_prim_ext(C, PRIM_CONE, RNA_int_get(op->ptr, "vertices"), 0, 0, + RNA_float_get(op->ptr,"radius"), RNA_float_get(op->ptr, "depth"), + 0, RNA_boolean_get(op->ptr, "cap_end")); + + return OPERATOR_FINISHED; } void MESH_OT_primitive_cone_add(wmOperatorType *ot) @@ -1507,34 +1487,26 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_cone_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500); - RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00); - RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00); + RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); + RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); RNA_def_boolean(ot->srna, "cap_end", 0, "Cap End", ""); } static int add_primitive_grid_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia*= RNA_float_get(op->ptr, "size"); - - make_prim(obedit, PRIM_GRID, mat, RNA_int_get(op->ptr, "x_subdivisions"), - RNA_int_get(op->ptr, "y_subdivisions"), 0, dia, 0.0f, 0, 1); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - - return OPERATOR_FINISHED; + make_prim_ext(C, PRIM_GRID, RNA_int_get(op->ptr, "x_subdivisions"), + RNA_int_get(op->ptr, "y_subdivisions"), 0, + RNA_float_get(op->ptr,"size"), 0.0f, 0, 1); + + return OPERATOR_FINISHED; } void MESH_OT_primitive_grid_add(wmOperatorType *ot) @@ -1546,7 +1518,7 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_grid_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1554,22 +1526,13 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) /* props */ RNA_def_int(ot->srna, "x_subdivisions", 10, INT_MIN, INT_MAX, "X Subdivisions", "", 3, 1000); RNA_def_int(ot->srna, "y_subdivisions", 10, INT_MIN, INT_MAX, "Y Subdivisons", "", 3, 1000); - RNA_def_float(ot->srna, "size", 1.0f, -FLT_MAX, FLT_MAX, "Size", "", 0.001, FLT_MAX); + RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, FLT_MAX); } static int add_primitive_monkey_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float mat[4][4]; - - new_primitive_matrix(C, mat); - - make_prim(obedit, PRIM_MONKEY, mat, 0, 0, 2, 0.0f, 0.0f, 0, 0); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - - return OPERATOR_FINISHED; + make_prim_ext(C, PRIM_MONKEY, 0, 0, 2, 0.0f, 0.0f, 0, 0); + return OPERATOR_FINISHED; } void MESH_OT_primitive_monkey_add(wmOperatorType *ot) @@ -1581,7 +1544,7 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_monkey_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1589,18 +1552,10 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia*= RNA_float_get(op->ptr, "size"); + make_prim_ext(C, PRIM_UVSPHERE, RNA_int_get(op->ptr, "rings"), + RNA_int_get(op->ptr, "segments"), 0, + RNA_float_get(op->ptr,"size"), 0.0f, 0, 0); - make_prim(obedit, PRIM_UVSPHERE, mat, RNA_int_get(op->ptr, "rings"), - RNA_int_get(op->ptr, "segments"), 0, dia, 0.0f, 0, 0); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - return OPERATOR_FINISHED; } @@ -1613,7 +1568,7 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_uvsphere_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1621,23 +1576,14 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) /* props */ RNA_def_int(ot->srna, "segments", 32, INT_MIN, INT_MAX, "Segments", "", 3, 500); RNA_def_int(ot->srna, "rings", 24, INT_MIN, INT_MAX, "Rings", "", 3, 500); - RNA_def_float(ot->srna, "size", 1.0f, -FLT_MAX, FLT_MAX, "Size", "", 0.001, 100.00); + RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, 100.00); } static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) { - Object *obedit= CTX_data_edit_object(C); - float dia, mat[4][4]; - - dia= new_primitive_matrix(C, mat); - dia*= RNA_float_get(op->ptr, "size"); - - make_prim(obedit, PRIM_ICOSPHERE, mat, 0, 0, - RNA_int_get(op->ptr, "subdivisions"), dia, 0.0f, 0, 0); - - DAG_id_flush_update(obedit->data, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); - + make_prim_ext(C, PRIM_ICOSPHERE, 0, 0, RNA_int_get(op->ptr, "subdivisions"), + RNA_float_get(op->ptr,"size"), 0.0f, 0, 0); + return OPERATOR_FINISHED; } @@ -1650,7 +1596,7 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot) /* api callbacks */ ot->exec= add_primitive_icosphere_exec; - ot->poll= ED_operator_editmesh; + ot->poll= ED_operator_scene_editable; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 6f94db38316..0865455b3b9 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -428,7 +428,10 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) /* add/remove */ WM_keymap_add_item(keymap, "MESH_OT_edge_face_add", FKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MESH_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0); - WM_keymap_add_item(keymap, "OBJECT_OT_mesh_add", AKEY, KM_PRESS, KM_SHIFT, 0); + + kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_SHIFT, 0); + RNA_string_set(kmi->ptr, "name", "INFO_MT_mesh_add"); + WM_keymap_add_item(keymap, "MESH_OT_separate", PKEY, KM_PRESS, 0, 0); /* use KM_RELEASE because same key is used for tweaks */ WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", LEFTMOUSE, KM_RELEASE, KM_CTRL, 0); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 00893f10165..fad73e19e16 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -533,7 +533,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) DAG_scene_sort(scene); // removed objects, need to rebuild dag before editmode call ED_object_enter_editmode(C, EM_WAITCURSOR); - ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR); + ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO); WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene); |