Fix T47750: Edited hair: disconnect (and connect!) operator do not support redo.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 14 Mar 2016 20:04:30 +0000 (21:04 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 14 Mar 2016 20:04:30 +0000 (21:04 +0100)
As suggested by Sergey, do not register those anymore, this way we keep undo step,
but user cannot 'redo' them (does not work, since cached DM in particle modifier data
is not yet re-created by depsgraph update after undo when operator is redone).

UI now has two buttons, one to (dic)connect current psys, the other to (dis)connect all.

Also fixed similar issue with Connect Hair op.

release/scripts/startup/bl_ui/properties_particle.py
source/blender/editors/physics/particle_object.c

index 207f6f86820d5140e578275b93318ad1399db20f..08290f20a69ba65791c30a83f857ab81cab9c360 100644 (file)
@@ -218,9 +218,13 @@ class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
                 row.prop(part, "hair_step")
                 if psys is not None and psys.is_edited:
                     if psys.is_global_hair:
-                        layout.operator("particle.connect_hair")
+                        row = layout.row(align=True)
+                        row.operator("particle.connect_hair").all = False
+                        row.operator("particle.connect_hair", text="Connect All").all = True
                     else:
-                        layout.operator("particle.disconnect_hair")
+                        row = layout.row(align=True)
+                        row.operator("particle.disconnect_hair").all = False
+                        row.operator("particle.disconnect_hair", text="Disconnect All").all = True
             elif psys is not None and part.type == 'REACTOR':
                 split.enabled = particle_panel_enabled(context, psys)
                 split.prop(psys, "reactor_target_object")
index 7aa4c245f11e11d9bde3f1039a5aa2cf9e0654ad..1297133e1a2c3b751e95c27ff7f75ec08fd7e26b 100644 (file)
@@ -649,7 +649,7 @@ void PARTICLE_OT_disconnect_hair(wmOperatorType *ot)
        ot->exec = disconnect_hair_exec;
        
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_UNDO;  /* No REGISTER, redo does not work due to missing update, see T47750. */
 
        RNA_def_boolean(ot->srna, "all", 0, "All hair", "Disconnect all hair systems from the emitter mesh");
 }
@@ -862,7 +862,6 @@ static int connect_hair_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        Object *ob= ED_object_context(C);
-       PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
        ParticleSystem *psys= NULL;
        const bool all = RNA_boolean_get(op->ptr, "all");
        bool any_connected = false;
@@ -876,12 +875,13 @@ static int connect_hair_exec(bContext *C, wmOperator *op)
                }
        }
        else {
-               psys = ptr.data;
+               psys = psys_get_current(ob);
                any_connected |= connect_hair(scene, ob, psys);
        }
 
        if (!any_connected) {
-               BKE_report(op->reports, RPT_ERROR, "Can't disconnect hair if particle system modifier is disabled");
+               BKE_report(op->reports, RPT_WARNING,
+                          "No hair connected (can't connect hair if particle system modifier is disabled)");
                return OPERATOR_CANCELLED;
        }
 
@@ -900,7 +900,7 @@ void PARTICLE_OT_connect_hair(wmOperatorType *ot)
        ot->exec = connect_hair_exec;
        
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_UNDO;  /* No REGISTER, redo does not work due to missing update, see T47750. */
 
        RNA_def_boolean(ot->srna, "all", 0, "All hair", "Connect all hair systems to the emitter mesh");
 }