From 0aebd5f14475ef84b0095de4a8f034170b9aee75 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 21 Jul 2009 00:36:07 +0000 Subject: 2.5: Make shade smooth/flat operators consistent, and add object mode operators. --- source/blender/editors/curve/curve_intern.h | 3 +- source/blender/editors/curve/curve_ops.c | 3 +- source/blender/editors/curve/editcurve.c | 29 ++++++--- source/blender/editors/mesh/editmesh_tools.c | 8 +-- source/blender/editors/mesh/mesh_intern.h | 2 +- source/blender/editors/mesh/mesh_ops.c | 6 +- source/blender/editors/object/object_edit.c | 70 ++++++++++++++++++++++ source/blender/editors/object/object_intern.h | 2 + source/blender/editors/object/object_ops.c | 2 + source/blender/editors/space_buttons/buttons_ops.c | 1 + .../blender/editors/space_view3d/view3d_header.c | 2 +- 11 files changed, 108 insertions(+), 20 deletions(-) (limited to 'source') diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h index 34e81b60a16..ad3e9427861 100644 --- a/source/blender/editors/curve/curve_intern.h +++ b/source/blender/editors/curve/curve_intern.h @@ -75,7 +75,8 @@ void CURVE_OT_spline_type_set(struct wmOperatorType *ot); void CURVE_OT_radius_set(struct wmOperatorType *ot); void CURVE_OT_spline_weight_set(struct wmOperatorType *ot); void CURVE_OT_handle_type_set(struct wmOperatorType *ot); -void CURVE_OT_smooth_set(struct wmOperatorType *ot); +void CURVE_OT_shade_smooth(struct wmOperatorType *ot); +void CURVE_OT_shade_flat(struct wmOperatorType *ot); void CURVE_OT_tilt_clear(struct wmOperatorType *ot); void CURVE_OT_smooth(struct wmOperatorType *ot); diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 45dc76d5488..6006c7e656b 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -130,7 +130,8 @@ void ED_operatortypes_curve(void) WM_operatortype_append(CURVE_OT_radius_set); WM_operatortype_append(CURVE_OT_spline_weight_set); WM_operatortype_append(CURVE_OT_handle_type_set); - WM_operatortype_append(CURVE_OT_smooth_set); + WM_operatortype_append(CURVE_OT_shade_smooth); + WM_operatortype_append(CURVE_OT_shade_flat); WM_operatortype_append(CURVE_OT_tilt_clear); WM_operatortype_append(CURVE_OT_smooth); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 51a9cf5c75a..2bf5d357e5c 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -4550,14 +4550,14 @@ void CURVE_OT_delete(wmOperatorType *ot) RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Which elements to delete."); } -/********************** set smooth operator *********************/ +/********************** shade smooth/flat operator *********************/ -static int set_smooth_exec(bContext *C, wmOperator *op) +static int shade_smooth_exec(bContext *C, wmOperator *op) { Object *obedit= CTX_data_edit_object(C); ListBase *editnurb= curve_get_editcurve(obedit); Nurb *nu; - int clear= RNA_boolean_get(op->ptr, "clear"); + int clear= (strcmp(op->idname, "CURVE_OT_shade_flat") == 0); if(obedit->type != OB_CURVE) return OPERATOR_CANCELLED; @@ -4575,21 +4575,32 @@ static int set_smooth_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void CURVE_OT_smooth_set(wmOperatorType *ot) +void CURVE_OT_shade_smooth(wmOperatorType *ot) { /* identifiers */ - ot->name= "Set Smooth"; - ot->idname= "CURVE_OT_smooth_set"; + ot->name= "Shade Smooth"; + ot->idname= "CURVE_OT_shade_smooth"; /* api callbacks */ - ot->exec= set_smooth_exec; + ot->exec= shade_smooth_exec; ot->poll= ED_operator_editsurfcurve; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} - /* properties */ - RNA_def_boolean(ot->srna, "clear", 0, "Clear", "Clear smooth shading to solid for selection instead of enabling it."); +void CURVE_OT_shade_flat(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Shade Flat"; + ot->idname= "CURVE_OT_shade_flat"; + + /* api callbacks */ + ot->exec= shade_smooth_exec; + ot->poll= ED_operator_editsurfcurve; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /************** join operator, to be used externally? ****************/ diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 6d5baa80ade..76f355ab7f9 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -7134,7 +7134,7 @@ void MESH_OT_faces_shade_smooth(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int mesh_faces_shade_solid_exec(bContext *C, wmOperator *op) +static int mesh_faces_shade_flat_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); @@ -7148,14 +7148,14 @@ static int mesh_faces_shade_solid_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void MESH_OT_faces_shade_solid(wmOperatorType *ot) +void MESH_OT_faces_shade_flat(wmOperatorType *ot) { /* identifiers */ ot->name= "Shade Flat"; - ot->idname= "MESH_OT_faces_shade_solid"; + ot->idname= "MESH_OT_faces_shade_flat"; /* api callbacks */ - ot->exec= mesh_faces_shade_solid_exec; + ot->exec= mesh_faces_shade_flat_exec; ot->poll= ED_operator_editmesh; /* flags */ diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 6e098e04a14..905a51a1bb0 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -217,7 +217,7 @@ void MESH_OT_quads_convert_to_tris(struct wmOperatorType *ot); void MESH_OT_tris_convert_to_quads(struct wmOperatorType *ot); void MESH_OT_edge_flip(struct wmOperatorType *ot); void MESH_OT_faces_shade_smooth(struct wmOperatorType *ot); -void MESH_OT_faces_shade_solid(struct wmOperatorType *ot); +void MESH_OT_faces_shade_flat(struct wmOperatorType *ot); void MESH_OT_split(struct wmOperatorType *ot); void MESH_OT_extrude_repeat(struct wmOperatorType *ot); void MESH_OT_edge_rotate(struct wmOperatorType *ot); diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index cfe8dd4352d..8ed68d5cd20 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -147,7 +147,7 @@ static int face_specials_invoke(bContext *C, wmOperator *op, wmEvent *event) uiItemO(layout, NULL, 0, "MESH_OT_flip_normals"); // uiItemO(layout, "Bevel", 0, "MESH_OT_bevel"); // bevelmenu(em) uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_smooth"); - uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_solid"); + uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_flat"); uiItemO(layout, NULL, 0, "MESH_OT_quads_convert_to_tris"); uiItemO(layout, NULL, 0, "MESH_OT_tris_convert_to_quads"); uiItemO(layout, NULL, 0, "MESH_OT_edge_flip"); @@ -205,7 +205,7 @@ static int specials_invoke(bContext *C, wmOperator *op, wmEvent *event) uiItemO(layout, "Smooth", 0, "MESH_OT_vertices_smooth"); // uiItemO(layout, "Bevel", 0, "MESH_OT_bevel"); // bevelmenu(em) uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_smooth"); - uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_solid"); + uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_flat"); //uiItemO(layout, "Blend From Shape", 0, "MESH_OT_blend_from_shape"); //uiItemO(layout, "Propagate to All Shapes", 0, "MESH_OT_shape_propagate_to_all"); uiItemO(layout, "Select Vertex Path", 0, "MESH_OT_select_vertex_path"); @@ -284,7 +284,7 @@ void ED_operatortypes_mesh(void) WM_operatortype_append(MESH_OT_tris_convert_to_quads); WM_operatortype_append(MESH_OT_edge_flip); WM_operatortype_append(MESH_OT_faces_shade_smooth); - WM_operatortype_append(MESH_OT_faces_shade_solid); + WM_operatortype_append(MESH_OT_faces_shade_flat); WM_operatortype_append(MESH_OT_delete); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 5ad41bd82f8..37453039cf5 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -6388,6 +6388,76 @@ void OBJECT_OT_join(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/********************** Smooth/Flat *********************/ + +static int shade_smooth_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob; + Curve *cu; + Nurb *nu; + int clear= (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0); + int done= 0; + + CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { + ob= base->object; + + if(ob->type==OB_MESH) { + mesh_set_smooth_flag(ob, !clear); + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + done= 1; + } + else if ELEM(ob->type, OB_SURF, OB_CURVE) { + cu= ob->data; + + for(nu=cu->nurb.first; nu; nu=nu->next) { + if(!clear) nu->flag |= ME_SMOOTH; + else nu->flag &= ~ME_SMOOTH; + nu= nu->next; + } + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + done= 1; + } + } + CTX_DATA_END; + + return (done)? OPERATOR_FINISHED: OPERATOR_CANCELLED; +} + +void OBJECT_OT_shade_flat(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Shade Flat"; + ot->idname= "OBJECT_OT_shade_flat"; + + /* api callbacks */ + ot->exec= shade_smooth_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +void OBJECT_OT_shade_smooth(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Shade Smooth"; + ot->idname= "OBJECT_OT_shade_smooth"; + + /* api callbacks */ + ot->exec= shade_smooth_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + + + /* ********************** */ void image_aspect(Scene *scene, View3D *v3d) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 3feec87edca..9f6e2d68556 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -65,6 +65,8 @@ void OBJECT_OT_object_add(struct wmOperatorType *ot); void OBJECT_OT_duplicate(struct wmOperatorType *ot); void OBJECT_OT_delete(struct wmOperatorType *ot); void OBJECT_OT_join(struct wmOperatorType *ot); +void OBJECT_OT_shade_smooth(struct wmOperatorType *ot); +void OBJECT_OT_shade_flat(struct wmOperatorType *ot); void OBJECT_OT_mesh_add(struct wmOperatorType *ot); void OBJECT_OT_curve_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index b8fb5f43ea4..0a45bf92003 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -87,6 +87,8 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_duplicates_make_real); WM_operatortype_append(OBJECT_OT_duplicate); WM_operatortype_append(OBJECT_OT_join); + WM_operatortype_append(OBJECT_OT_shade_smooth); + WM_operatortype_append(OBJECT_OT_shade_flat); WM_operatortype_append(GROUP_OT_group_create); WM_operatortype_append(GROUP_OT_objects_remove); WM_operatortype_append(GROUP_OT_objects_add_active); diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index 8a9d2e9149b..124ccf9d480 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -900,3 +900,4 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } + diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index bdc6bdb5601..5e6f5d9a96b 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -2263,7 +2263,7 @@ static void view3d_edit_mesh_facesmenu(bContext *C, uiLayout *layout, void *arg_ uiItemS(layout); uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_smooth"); - uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_solid"); + uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_flat"); } static void view3d_edit_mesh_normalsmenu(bContext *C, uiLayout *layout, void *arg_unused) -- cgit v1.2.3