[Bf-extensions-cvs] [f8f621e] master: Disable global undo while running operators from inside other operators, to avoid unnecessary overhead from saving undo steps.
Lukas Tönne
noreply at git.blender.org
Thu Feb 5 15:49:22 CET 2015
Commit: f8f621e8d8009418c73b2cc3a6b9643ca3b7ce1d
Author: Lukas Tönne
Date: Thu Feb 5 15:46:25 2015 +0100
Branches: master
https://developer.blender.org/rBACf8f621e8d8009418c73b2cc3a6b9643ca3b7ce1d
Disable global undo while running operators from inside other operators,
to avoid unnecessary overhead from saving undo steps.
===================================================================
M object_physics_meadow/ui.py
M object_physics_meadow/util.py
===================================================================
diff --git a/object_physics_meadow/ui.py b/object_physics_meadow/ui.py
index 0101b02..1292df8 100644
--- a/object_physics_meadow/ui.py
+++ b/object_physics_meadow/ui.py
@@ -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'}
diff --git a/object_physics_meadow/util.py b/object_physics_meadow/util.py
index e909006..f372fac 100644
--- a/object_physics_meadow/util.py
+++ b/object_physics_meadow/util.py
@@ -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
More information about the Bf-extensions-cvs
mailing list