From 9e5a670b1d2285826bf33a177b32eb5862c771db Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Apr 2013 01:36:44 +0000 Subject: code cleanup: abbreviations ob, con - aren't normally used in global identifiers. --- source/blender/editors/include/ED_physics.h | 10 ++--- .../blender/editors/physics/rigidbody_constraint.c | 29 +++++++----- source/blender/editors/physics/rigidbody_object.c | 52 +++++++++++----------- source/blender/makesrna/RNA_enum_types.h | 6 +-- source/blender/makesrna/intern/rna_rigidbody.c | 12 ++--- 5 files changed, 58 insertions(+), 51 deletions(-) (limited to 'source') diff --git a/source/blender/editors/include/ED_physics.h b/source/blender/editors/include/ED_physics.h index cb793cfd9f6..584e9a92bb6 100644 --- a/source/blender/editors/include/ED_physics.h +++ b/source/blender/editors/include/ED_physics.h @@ -33,7 +33,7 @@ #define __ED_PHYSICS_H__ struct bContext; -struct wmOperator; +struct ReportList; struct wmKeyConfig; struct Scene; @@ -45,12 +45,12 @@ int PE_hair_poll(struct bContext *C); int PE_poll_view3d(struct bContext *C); /* rigidbody_object.c */ -bool ED_rigidbody_ob_add(struct wmOperator *op, struct Scene *scene, struct Object *ob, int type); -void ED_rigidbody_ob_remove(struct Scene *scene, struct Object *ob); +bool ED_rigidbody_object_add(struct Scene *scene, struct Object *ob, int type, struct ReportList *reports); +void ED_rigidbody_object_remove(struct Scene *scene, struct Object *ob); /* rigidbody_constraint.c */ -void ED_rigidbody_con_add(struct wmOperator *op, struct Scene *scene, struct Object *ob, int type); -void ED_rigidbody_con_remove(struct Scene *scene, struct Object *ob); +bool ED_rigidbody_constraint_add(struct Scene *scene, struct Object *ob, int type, struct ReportList *reports); +void ED_rigidbody_constraint_remove(struct Scene *scene, struct Object *ob); /* operators */ void ED_operatortypes_physics(void); diff --git a/source/blender/editors/physics/rigidbody_constraint.c b/source/blender/editors/physics/rigidbody_constraint.c index d38ffa491e2..698d530c22d 100644 --- a/source/blender/editors/physics/rigidbody_constraint.c +++ b/source/blender/editors/physics/rigidbody_constraint.c @@ -77,14 +77,14 @@ static int ED_operator_rigidbody_con_active_poll(bContext *C) } -void ED_rigidbody_con_add(wmOperator *op, Scene *scene, Object *ob, int type) +bool ED_rigidbody_constraint_add(Scene *scene, Object *ob, int type, ReportList *reports) { RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); /* check that object doesn't already have a constraint */ if (ob->rigidbody_constraint) { - BKE_reportf(op->reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2); - return; + BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2); + return false; } /* create constraint group if it doesn't already exits */ if (rbw->constraints == NULL) { @@ -98,9 +98,10 @@ void ED_rigidbody_con_add(wmOperator *op, Scene *scene, Object *ob, int type) BKE_group_object_add(rbw->constraints, ob, scene, NULL); DAG_id_tag_update(&ob->id, OB_RECALC_OB); + return true; } -void ED_rigidbody_con_remove(Scene *scene, Object *ob) +void ED_rigidbody_constraint_remove(Scene *scene, Object *ob) { RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); @@ -122,6 +123,7 @@ static int rigidbody_con_add_exec(bContext *C, wmOperator *op) RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); Object *ob = (scene) ? OBACT : NULL; int type = RNA_enum_get(op->ptr, "type"); + bool change; /* sanity checks */ if (ELEM(NULL, scene, rbw)) { @@ -129,13 +131,18 @@ static int rigidbody_con_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } /* apply to active object */ - ED_rigidbody_con_add(op, scene, ob, type); + change = ED_rigidbody_constraint_add(scene, ob, type, op->reports); - /* send updates */ - WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); + if (change) { + /* send updates */ + WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); - /* done */ - return OPERATOR_FINISHED; + /* done */ + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } } void RIGIDBODY_OT_constraint_add(wmOperatorType *ot) @@ -153,7 +160,7 @@ void RIGIDBODY_OT_constraint_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_con_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", ""); + ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_constraint_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", ""); } /* ************ Remove Rigid Body Constraint ************** */ @@ -173,7 +180,7 @@ static int rigidbody_con_remove_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } else { - ED_rigidbody_con_remove(scene, ob); + ED_rigidbody_constraint_remove(scene, ob); } /* send updates */ diff --git a/source/blender/editors/physics/rigidbody_object.c b/source/blender/editors/physics/rigidbody_object.c index 9ef1e9177eb..6670422a70d 100644 --- a/source/blender/editors/physics/rigidbody_object.c +++ b/source/blender/editors/physics/rigidbody_object.c @@ -91,16 +91,16 @@ static int ED_operator_rigidbody_add_poll(bContext *C) /* ----------------- */ -bool ED_rigidbody_ob_add(wmOperator *op, Scene *scene, Object *ob, int type) +bool ED_rigidbody_object_add(Scene *scene, Object *ob, int type, ReportList *reports) { RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); if (ob->type != OB_MESH) { - BKE_report(op->reports, RPT_ERROR, "Can't add Rigid Body to non mesh object"); + BKE_report(reports, RPT_ERROR, "Can't add Rigid Body to non mesh object"); return false; } if (((Mesh *)ob->data)->totpoly == 0) { - BKE_report(op->reports, RPT_ERROR, "Can't create Rigid Body from mesh with no polygons"); + BKE_report(reports, RPT_ERROR, "Can't create Rigid Body from mesh with no polygons"); return false; } @@ -108,7 +108,7 @@ bool ED_rigidbody_ob_add(wmOperator *op, Scene *scene, Object *ob, int type) if (rbw == NULL) { rbw = BKE_rigidbody_create_world(scene); if (rbw == NULL) { - BKE_report(op->reports, RPT_ERROR, "Can't create Rigid Body world"); + BKE_report(reports, RPT_ERROR, "Can't create Rigid Body world"); return false; } BKE_rigidbody_validate_sim_world(scene, rbw, false); @@ -133,7 +133,7 @@ bool ED_rigidbody_ob_add(wmOperator *op, Scene *scene, Object *ob, int type) return true; } -void ED_rigidbody_ob_remove(Scene *scene, Object *ob) +void ED_rigidbody_object_remove(Scene *scene, Object *ob) { RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); @@ -149,7 +149,7 @@ void ED_rigidbody_ob_remove(Scene *scene, Object *ob) /* ************ Add Rigid Body ************** */ -static int rigidbody_ob_add_exec(bContext *C, wmOperator *op) +static int rigidbody_object_add_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -157,7 +157,7 @@ static int rigidbody_ob_add_exec(bContext *C, wmOperator *op) bool change; /* apply to active object */ - change = ED_rigidbody_ob_add(op, scene, ob, type); + change = ED_rigidbody_object_add(scene, ob, type, op->reports); if (change) { /* send updates */ @@ -179,19 +179,19 @@ void RIGIDBODY_OT_object_add(wmOperatorType *ot) ot->description = "Add active object as Rigid Body"; /* callbacks */ - ot->exec = rigidbody_ob_add_exec; + ot->exec = rigidbody_object_add_exec; ot->poll = ED_operator_rigidbody_add_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_ob_type_items, RBO_TYPE_ACTIVE, "Rigid Body Type", ""); + ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_object_type_items, RBO_TYPE_ACTIVE, "Rigid Body Type", ""); } /* ************ Remove Rigid Body ************** */ -static int rigidbody_ob_remove_exec(bContext *C, wmOperator *op) +static int rigidbody_object_remove_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -199,7 +199,7 @@ static int rigidbody_ob_remove_exec(bContext *C, wmOperator *op) /* apply to active object */ if (!ELEM(NULL, ob, ob->rigidbody_object)) { - ED_rigidbody_ob_remove(scene, ob); + ED_rigidbody_object_remove(scene, ob); change = true; } @@ -224,7 +224,7 @@ void RIGIDBODY_OT_object_remove(wmOperatorType *ot) ot->description = "Remove Rigid Body settings from Object"; /* callbacks */ - ot->exec = rigidbody_ob_remove_exec; + ot->exec = rigidbody_object_remove_exec; ot->poll = ED_operator_rigidbody_active_poll; /* flags */ @@ -236,7 +236,7 @@ void RIGIDBODY_OT_object_remove(wmOperatorType *ot) /* ************ Add Rigid Bodies ************** */ -static int rigidbody_obs_add_exec(bContext *C, wmOperator *op) +static int rigidbody_objects_add_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); int type = RNA_enum_get(op->ptr, "type"); @@ -244,7 +244,7 @@ static int rigidbody_obs_add_exec(bContext *C, wmOperator *op) /* create rigid body objects and add them to the world's group */ CTX_DATA_BEGIN(C, Object *, ob, selected_objects) { - change |= ED_rigidbody_ob_add(op, scene, ob, type); + change |= ED_rigidbody_object_add(scene, ob, type, op->reports); } CTX_DATA_END; @@ -269,19 +269,19 @@ void RIGIDBODY_OT_objects_add(wmOperatorType *ot) ot->description = "Add selected objects as Rigid Bodies"; /* callbacks */ - ot->exec = rigidbody_obs_add_exec; + ot->exec = rigidbody_objects_add_exec; ot->poll = ED_operator_rigidbody_add_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_ob_type_items, RBO_TYPE_ACTIVE, "Rigid Body Type", ""); + ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_object_type_items, RBO_TYPE_ACTIVE, "Rigid Body Type", ""); } /* ************ Remove Rigid Bodies ************** */ -static int rigidbody_obs_remove_exec(bContext *C, wmOperator *UNUSED(op)) +static int rigidbody_objects_remove_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); bool change = false; @@ -290,7 +290,7 @@ static int rigidbody_obs_remove_exec(bContext *C, wmOperator *UNUSED(op)) CTX_DATA_BEGIN(C, Object *, ob, selected_objects) { if (ob->rigidbody_object) { - ED_rigidbody_ob_remove(scene, ob); + ED_rigidbody_object_remove(scene, ob); change = true; } } @@ -316,7 +316,7 @@ void RIGIDBODY_OT_objects_remove(wmOperatorType *ot) ot->description = "Remove selected objects from Rigid Body simulation"; /* callbacks */ - ot->exec = rigidbody_obs_remove_exec; + ot->exec = rigidbody_objects_remove_exec; ot->poll = ED_operator_rigidbody_active_poll; /* flags */ @@ -328,7 +328,7 @@ void RIGIDBODY_OT_objects_remove(wmOperatorType *ot) /* ************ Change Collision Shapes ************** */ -static int rigidbody_obs_shape_change_exec(bContext *C, wmOperator *op) +static int rigidbody_objects_shape_change_exec(bContext *C, wmOperator *op) { int shape = RNA_enum_get(op->ptr, "type"); bool change = false; @@ -371,14 +371,14 @@ void RIGIDBODY_OT_shape_change(wmOperatorType *ot) /* callbacks */ ot->invoke = WM_menu_invoke; - ot->exec = rigidbody_obs_shape_change_exec; + ot->exec = rigidbody_objects_shape_change_exec; ot->poll = ED_operator_rigidbody_active_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_ob_shape_items, RB_SHAPE_TRIMESH, "Rigid Body Shape", ""); + ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_object_shape_items, RB_SHAPE_TRIMESH, "Rigid Body Shape", ""); } /* ************ Calculate Mass ************** */ @@ -487,7 +487,7 @@ static EnumPropertyItem *rigidbody_materials_itemf(bContext *UNUSED(C), PointerR /* helper function to calculate volume of rigidbody object */ // TODO: allow a parameter to specify method used to calculate this? -static float calc_rigidbody_ob_volume(Object *ob) +static float rigidbody_object_calc_volume(Object *ob) { RigidBodyOb *rbo = ob->rigidbody_object; @@ -557,7 +557,7 @@ static float calc_rigidbody_ob_volume(Object *ob) /* ------------------------------------------ */ -static int rigidbody_obs_calc_mass_exec(bContext *C, wmOperator *op) +static int rigidbody_objects_calc_mass_exec(bContext *C, wmOperator *op) { int material = RNA_enum_get(op->ptr, "material"); float density; @@ -589,7 +589,7 @@ static int rigidbody_obs_calc_mass_exec(bContext *C, wmOperator *op) /* mass is calculated from the approximate volume of the object, * and the density of the material we're simulating */ - volume = calc_rigidbody_ob_volume(ob); + volume = rigidbody_object_calc_volume(ob); mass = volume * density; /* use RNA-system to change the property and perform all necessary changes */ @@ -626,7 +626,7 @@ void RIGIDBODY_OT_mass_calculate(wmOperatorType *ot) /* callbacks */ ot->invoke = WM_menu_invoke; // XXX - ot->exec = rigidbody_obs_calc_mass_exec; + ot->exec = rigidbody_objects_calc_mass_exec; ot->poll = ED_operator_rigidbody_active_poll; /* flags */ diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index e6ee1b7c382..513e249a64a 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -106,9 +106,9 @@ extern EnumPropertyItem object_type_items[]; extern EnumPropertyItem object_type_curve_items[]; -extern EnumPropertyItem rigidbody_ob_type_items[]; -extern EnumPropertyItem rigidbody_ob_shape_items[]; -extern EnumPropertyItem rigidbody_con_type_items[]; +extern EnumPropertyItem rigidbody_object_type_items[]; +extern EnumPropertyItem rigidbody_object_shape_items[]; +extern EnumPropertyItem rigidbody_constraint_type_items[]; extern EnumPropertyItem object_axis_items[]; diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c index 6e86e49dada..daa1287c650 100644 --- a/source/blender/makesrna/intern/rna_rigidbody.c +++ b/source/blender/makesrna/intern/rna_rigidbody.c @@ -43,13 +43,13 @@ #include "WM_types.h" /* roles of objects in RigidBody Sims */ -EnumPropertyItem rigidbody_ob_type_items[] = { +EnumPropertyItem rigidbody_object_type_items[] = { {RBO_TYPE_ACTIVE, "ACTIVE", 0, "Active", "Object is directly controlled by simulation results"}, {RBO_TYPE_PASSIVE, "PASSIVE", 0, "Passive", "Object is directly controlled by animation system"}, {0, NULL, 0, NULL, NULL}}; /* collision shapes of objects in rigid body sim */ -EnumPropertyItem rigidbody_ob_shape_items[] = { +EnumPropertyItem rigidbody_object_shape_items[] = { {RB_SHAPE_BOX, "BOX", ICON_MESH_CUBE, "Box", "Box-like shapes (i.e. cubes), including planes (i.e. ground planes)"}, {RB_SHAPE_SPHERE, "SPHERE", ICON_MESH_UVSPHERE, "Sphere", ""}, {RB_SHAPE_CAPSULE, "CAPSULE", ICON_OUTLINER_OB_META, "Capsule", ""}, @@ -63,7 +63,7 @@ EnumPropertyItem rigidbody_ob_shape_items[] = { {0, NULL, 0, NULL, NULL}}; /* collision shapes of constraints in rigid body sim */ -EnumPropertyItem rigidbody_con_type_items[] = { +EnumPropertyItem rigidbody_constraint_type_items[] = { {RBC_TYPE_FIXED, "FIXED", ICON_NONE, "Fixed", "Glue rigid bodies together"}, {RBC_TYPE_POINT, "POINT", ICON_NONE, "Point", "Constrain rigid bodies to move around common pivot point"}, {RBC_TYPE_HINGE, "HINGE", ICON_NONE, "Hinge", "Restrict rigid body rotation to one axis"}, @@ -694,7 +694,7 @@ static void rna_def_rigidbody_object(BlenderRNA *brna) /* Enums */ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type"); - RNA_def_property_enum_items(prop, rigidbody_ob_type_items); + RNA_def_property_enum_items(prop, rigidbody_object_type_items); RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyOb_type_set", NULL); RNA_def_property_ui_text(prop, "Type", "Role of object in Rigid Body Simulations"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); @@ -709,7 +709,7 @@ static void rna_def_rigidbody_object(BlenderRNA *brna) prop = RNA_def_property(srna, "collision_shape", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "shape"); - RNA_def_property_enum_items(prop, rigidbody_ob_shape_items); + RNA_def_property_enum_items(prop, rigidbody_object_shape_items); RNA_def_property_ui_text(prop, "Collision Shape", "Collision Shape of object in Rigid Body Simulations"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset"); @@ -846,7 +846,7 @@ static void rna_def_rigidbody_constraint(BlenderRNA *brna) /* Enums */ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type"); - RNA_def_property_enum_items(prop, rigidbody_con_type_items); + RNA_def_property_enum_items(prop, rigidbody_constraint_type_items); RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyCon_type_set", NULL); RNA_def_property_ui_text(prop, "Type", "Type of Rigid Body Constraint"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); -- cgit v1.2.3