Commit f8f621e8 authored by Lukas Tönne's avatar Lukas Tönne

Disable global undo while running operators from inside other operators,

to avoid unnecessary overhead from saving undo steps.
parent eb862975
......@@ -181,7 +181,7 @@ class MakeBlobsOperator(MeadowOperatorBase, Operator):
self.report({'ERROR'}, "Could not find meadow Blob Grid object")
return {'CANCELLED'}
with ObjectSelection():
with OperatorCallContext():
progress_default()
meadow.make_blobs(context, blobgridob, groundob)
......@@ -200,7 +200,7 @@ class DeleteBlobsOperator(MeadowOperatorBase, Operator):
groundob = find_meadow_object(context, 'GROUND')
with ObjectSelection():
with OperatorCallContext():
progress_default()
meadow.delete_blobs(context, groundob)
......@@ -231,7 +231,7 @@ class MakePatchesOperator(MeadowOperatorBase, Operator):
self.report({'ERROR'}, "Could not find meadow Blob Grid object")
return {'CANCELLED'}
with ObjectSelection():
with OperatorCallContext():
progress_default()
meadow.make_patches(context, blobgridob, groundob)
......@@ -263,7 +263,7 @@ class MEADOW_OT_BakePhysics(MeadowOperatorBase, Operator):
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
with ObjectSelection():
with OperatorCallContext():
progress_default()
physics.scene_bake_all(context)
return {'FINISHED'}
......@@ -276,7 +276,7 @@ class MEADOW_OT_FreePhysics(MeadowOperatorBase, Operator):
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
with ObjectSelection():
with OperatorCallContext():
progress_default()
physics.scene_free_all(context)
return {'FINISHED'}
......
......@@ -34,22 +34,33 @@ def round_sigfigs(num, sig_figs):
else:
return 0 # Can't take the log of 0
class ObjectSelection():
class OperatorCallContext():
def __enter__(self):
scene = bpy.context.scene
prefs = bpy.context.user_preferences
# store active/selected state to restore it after operator execution
self.curact = scene.objects.active
self.cursel = { ob : ob.select for ob in scene.objects }
# undo can store files a lot when running operators internally,
# disable since we only need one undo step after main operators anyway
self.use_global_undo = prefs.edit.use_global_undo
prefs.edit.use_global_undo = False
return (self.curact, self.cursel)
def __exit__(self, exc_type, exc_value, traceback):
scene = bpy.context.scene
prefs = bpy.context.user_preferences
# restore active/selected state
scene.objects.active = self.curact
for ob in scene.objects:
ob.select = self.cursel.get(ob, False)
prefs.edit.use_global_undo = self.use_global_undo
def select_single_object(ob):
scene = bpy.context.scene
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment