Disable global undo while running operators from inside other operators,
authorLukas Tönne <lukas.toenne@gmail.com>
Thu, 5 Feb 2015 14:46:25 +0000 (15:46 +0100)
committerLukas Tönne <lukas.toenne@gmail.com>
Thu, 5 Feb 2015 14:46:25 +0000 (15:46 +0100)
to avoid unnecessary overhead from saving undo steps.

object_physics_meadow/ui.py
object_physics_meadow/util.py

index 0101b02..1292df8 100644 (file)
@@ -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'}
index e909006..f372fac 100644 (file)
@@ -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