Fix T47750: Edited hair: disconnect (and connect!) operator do not support redo.

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.
This commit is contained in:
Bastien Montagne 2016-03-14 21:04:30 +01:00
parent 00166ff62e
commit a078fe3539
Notes: blender-bot 2023-02-14 08:06:39 +01:00
Referenced by issue #47750, Hair particles lose position data when "Disconnect All" is used the first time from program load
2 changed files with 11 additions and 7 deletions

View 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")

View 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");
}