Remove Surface modifier when removing force field from object
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 19 Nov 2013 11:19:06 +0000 (17:19 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 19 Nov 2013 11:19:06 +0000 (17:19 +0600)
Summary:
Before this adding Surface type of force field and removing
this field would leave Surface modifier alive in the stack.

This might be really misleading and annoying.

Now removing force field will ensure no modifiers needed for
it are remained in the stack.

This also fixes missing notifier to redraw modifier stack
when changing force field type.

Reviewers: brecht, campbellbarton

Reviewed By: brecht

Differential Revision: http://developer.blender.org/D13

release/scripts/addons
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modifier.c
source/blender/makesrna/intern/rna_object_force.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index 2bfbbe4182d7e5d5332d963054f298c9fddc5f09..3adbc8f30b229e7c9ff465183d5ab0acbbdf921a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 2bfbbe4182d7e5d5332d963054f298c9fddc5f09
+Subproject commit 3adbc8f30b229e7c9ff465183d5ab0acbbdf921a
index 0d11108d81f3b33830014aafa37282027d564018..4155dbb5565bd9e95a87bfe85e23a4963946d731 100644 (file)
@@ -219,6 +219,8 @@ struct EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(
         int *free,
         const unsigned int selection_mask);
 
+void ED_object_check_force_modifiers(struct Main *bmain, struct Scene *scene, struct Object *object);
+
 #ifdef __cplusplus
 }
 #endif
index bd4c2e997fef3ef2a8b1235896e2d25a57679de4..02cbc1060dfb7f572ed40643a8ac2da7aa2713c3 100644 (file)
@@ -1110,6 +1110,23 @@ static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, View3D *
 
 /* ******************* force field toggle operator ***************** */
 
+void ED_object_check_force_modifiers(Main *bmain, Scene *scene, Object *object)
+{
+       PartDeflect *pd = object->pd;
+       ModifierData *md = modifiers_findByType(object, eModifierType_Surface);
+
+       /* add/remove modifier as needed */
+       if (!md) {
+               if (pd && (pd->shape == PFIELD_SHAPE_SURFACE) && ELEM(pd->forcefield, PFIELD_GUIDE, PFIELD_TEXTURE) == 0)
+                       if (ELEM4(object->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE))
+                               ED_object_modifier_add(NULL, bmain, scene, object, NULL, eModifierType_Surface);
+       }
+       else {
+               if (!pd || pd->shape != PFIELD_SHAPE_SURFACE || pd->forcefield != PFIELD_FORCE)
+                       ED_object_modifier_remove(NULL, bmain, object, md);
+       }
+}
+
 static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Object *ob = CTX_data_active_object(C);
@@ -1122,7 +1139,9 @@ static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
        else
                ob->pd->forcefield = 0;
        
-       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
+       ED_object_check_force_modifiers(CTX_data_main(C), CTX_data_scene(C), ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
 
        return OPERATOR_FINISHED;
 }
index 0c794a974effa2ac43ca0a933c36508474d7a4b8..01dafe69d31aaca6884fa8b024c28e092a1ea37c 100644 (file)
@@ -298,9 +298,6 @@ static int object_modifier_remove(Main *bmain, Object *ob, ModifierData *md,
                *sort_depsgraph = 1;
        }
        else if (md->type == eModifierType_Surface) {
-               if (ob->pd && ob->pd->shape == PFIELD_SHAPE_SURFACE)
-                       ob->pd->shape = PFIELD_SHAPE_PLANE;
-
                *sort_depsgraph = 1;
        }
        else if (md->type == eModifierType_Multires) {
index 33ae256c042690fc6339d3909bdb3cb0f6680f83..2a93925a8e58948444979441b0ca573b4554b5ba 100644 (file)
@@ -517,21 +517,9 @@ static void rna_FieldSettings_shape_update(Main *bmain, Scene *scene, PointerRNA
 {
        if (!particle_id_check(ptr)) {
                Object *ob = (Object *)ptr->id.data;
-               PartDeflect *pd = ob->pd;
-               ModifierData *md = modifiers_findByType(ob, eModifierType_Surface);
-
-               /* add/remove modifier as needed */
-               if (!md) {
-                       if (pd && (pd->shape == PFIELD_SHAPE_SURFACE) && ELEM(pd->forcefield, PFIELD_GUIDE, PFIELD_TEXTURE) == 0)
-                               if (ELEM4(ob->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE))
-                                       ED_object_modifier_add(NULL, bmain, scene, ob, NULL, eModifierType_Surface);
-               }
-               else {
-                       if (!pd || pd->shape != PFIELD_SHAPE_SURFACE)
-                               ED_object_modifier_remove(NULL, bmain, ob, md);
-               }
-
+               ED_object_check_force_modifiers(bmain, scene, ob);
                WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
+               WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
        }
 }
 
index 80f3a617baccb748989b7b2d41be5e2a51b46576..f61b54ac3607466d78941d0bb3dd8203f6778716 100644 (file)
@@ -353,6 +353,7 @@ void ED_object_modifier_clear(struct Main *bmain, struct Object *ob) {STUB_ASSER
 void ED_object_editmode_enter(struct bContext *C, int flag) {STUB_ASSERT(0);}
 void ED_object_editmode_exit(struct bContext *C, int flag) {STUB_ASSERT(0);}
 bool ED_object_editmode_load(struct Object *obedit) {STUB_ASSERT(0); return false; }
+void ED_object_check_force_modifiers(struct Main *bmain, struct Scene *scene, struct Object *object) {STUB_ASSERT(0);}
 int uiLayoutGetActive(struct uiLayout *layout) {STUB_ASSERT(0); return 0;}
 int uiLayoutGetOperatorContext(struct uiLayout *layout) {STUB_ASSERT(0); return 0;}
 int uiLayoutGetAlignment(struct uiLayout *layout) {STUB_ASSERT(0); return 0;}