2.5: Make shade smooth/flat operators consistent,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 21 Jul 2009 00:36:07 +0000 (00:36 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 21 Jul 2009 00:36:07 +0000 (00:36 +0000)
and add object mode operators.

source/blender/editors/curve/curve_intern.h
source/blender/editors/curve/curve_ops.c
source/blender/editors/curve/editcurve.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/space_buttons/buttons_ops.c
source/blender/editors/space_view3d/view3d_header.c

index 34e81b60a1634a7be019c3bf503163ad41430c91..ad3e94278613cfe53575f6826a67688c70567840 100644 (file)
@@ -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);
index 45dc76d54889d30d4de992511193bcacebd2cae8..6006c7e656b8a412741f9163f25e650767c9f8bc 100644 (file)
@@ -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);
index 51a9cf5c75adf49d6dabdcdc777cf624980a7e9c..2bf5d357e5cb70989ec501ecf6ea2d8c4146e6fd 100644 (file)
@@ -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? ****************/
index 6d5baa80adecece7fc31b02ca0c431d26ffbbb3a..76f355ab7f9bebf399ee729c44d5beb7345ecd4b 100644 (file)
@@ -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 */
index 6e098e04a14022cdb6d0c451f09a2cd949225784..905a51a1bb0f963aa6260a15bb81f095e62f3c0b 100644 (file)
@@ -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);
index cfe8dd4352d86182a1640c652af4bd2267ef88fb..8ed68d5cd2060f5a821faf19c2b5e258c912f285 100644 (file)
@@ -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);
 
index 5ad41bd82f87ca2871d8043f951020cb48e090b4..37453039cf57458f0e1e88e08a72f79fc6ed624c 100644 (file)
@@ -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)
index 3feec87edca9156e9d802736ba30d89161a396c5..9f6e2d68556819d4f891417cdc4ca12a342a122e 100644 (file)
@@ -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);
index b8fb5f43ea497516438de420c59d269791158212..0a45bf920036c3b837b319be77ae13739d6ff4ed 100644 (file)
@@ -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);
index 8a9d2e9149b81ac7d733bda954e34da03dc46592..124ccf9d480b6aa51242235bef1c3a7e7e66e282 100644 (file)
@@ -900,3 +900,4 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
+
index bdc6bdb56012436a8ed2dbca31c377a7c3778904..5e6f5d9a96b8eb5016dae081766e3f95d8c50007 100644 (file)
@@ -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)