[Bf-extensions-cvs] [fbae0b16] master: Fix T52524: Restore global undo in case of failure

lijenstina noreply at git.blender.org
Sun Aug 27 16:57:50 CEST 2017


Commit: fbae0b16d4ef65a987c8ac287959a6bc020ba84b
Author: lijenstina
Date:   Sun Aug 27 16:56:48 2017 +0200
Branches: master
https://developer.blender.org/rBACfbae0b16d4ef65a987c8ac287959a6bc020ba84b

Fix T52524: Restore global undo in case of failure

Bumped version to 3.1.3
Pep8 Cleanup
Consistent prop definitions
Fix crash with reload related to Property group still being used
was related to the order of register - use register_class instead

Restore global undo setting in case of failure in the
calc_callback function with a try except block

===================================================================

M	animation_motion_trail.py

===================================================================

diff --git a/animation_motion_trail.py b/animation_motion_trail.py
index 824b4602..4d69d2bc 100644
--- a/animation_motion_trail.py
+++ b/animation_motion_trail.py
@@ -22,13 +22,13 @@
 bl_info = {
     "name": "Motion Trail",
     "author": "Bart Crouch",
-    "version": (3, 1, 2),
+    "version": (3, 1, 3),
     "blender": (2, 65, 4),
     "location": "View3D > Toolbar > Motion Trail tab",
     "warning": "",
     "description": "Display and edit motion trails in the 3D View",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
-        "Scripts/Animation/Motion_Trail",
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/Animation/Motion_Trail",
     "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
     "category": "Animation"}
 
@@ -39,6 +39,14 @@ import bpy
 from bpy_extras import view3d_utils
 import math
 import mathutils
+from bpy.props import (
+        BoolProperty,
+        EnumProperty,
+        FloatProperty,
+        IntProperty,
+        StringProperty,
+        PointerProperty,
+        )
 
 
 # fake fcurve class, used if no fcurve is found for a path
@@ -72,13 +80,15 @@ def get_curves(object, child=False):
         action = object.animation_data.action
         if child:
             # posebone
-            curves = [fc for fc in action.fcurves if len(fc.data_path)>=14 \
-            and fc.data_path[-9:]=='.location' and \
-            child.name in fc.data_path.split("\"")]
+            curves = [
+                    fc for fc in action.fcurves if len(fc.data_path) >= 14 and
+                    fc.data_path[-9:] == '.location' and
+                    child.name in fc.data_path.split("\"")
+                    ]
         else:
             # normal object
-            curves = [fc for fc in action.fcurves if \
-            fc.data_path == 'location']
+            curves = [fc for fc in action.fcurves if fc.data_path == 'location']
+
     elif object.animation_data and object.animation_data.use_nla:
         curves = []
         strips = []
@@ -95,13 +105,14 @@ def get_curves(object, child=False):
         for strip in strips:
             if child:
                 # posebone
-                curves = [fc for fc in strip.action.fcurves if \
-                len(fc.data_path)>=14 and fc.data_path[-9:]=='.location' \
-                and child.name in fc.data_path.split("\"")]
+                curves = [
+                        fc for fc in strip.action.fcurves if
+                        len(fc.data_path) >= 14 and fc.data_path[-9:] == '.location' and
+                        child.name in fc.data_path.split("\"")
+                        ]
             else:
                 # normal object
-                curves = [fc for fc in strip.action.fcurves if \
-                fc.data_path == 'location']
+                curves = [fc for fc in strip.action.fcurves if fc.data_path == 'location']
             if curves:
                 # use first strip with location fcurves
                 break
@@ -120,11 +131,11 @@ def get_curves(object, child=False):
             fcy = fc
         elif fc.array_index == 2:
             fcz = fc
-    if fcx == None:
+    if fcx is None:
         fcx = fake_fcurve(object, 0)
-    if fcy == None:
+    if fcy is None:
         fcy = fake_fcurve(object, 1)
-    if fcz == None:
+    if fcz is None:
         fcz = fake_fcurve(object, 2)
 
     return([fcx, fcy, fcz])
@@ -132,10 +143,13 @@ def get_curves(object, child=False):
 
 # turn screen coordinates (x,y) into world coordinates vector
 def screen_to_world(context, x, y):
-    depth_vector = view3d_utils.region_2d_to_vector_3d(\
-        context.region, context.region_data, [x,y])
-    vector = view3d_utils.region_2d_to_location_3d(\
-        context.region, context.region_data, [x,y], depth_vector)
+    depth_vector = view3d_utils.region_2d_to_vector_3d(
+                            context.region, context.region_data, [x, y]
+                            )
+    vector = view3d_utils.region_2d_to_location_3d(
+                            context.region, context.region_data, [x, y],
+                            depth_vector
+                            )
 
     return(vector)
 
@@ -194,8 +208,8 @@ def get_original_animation_data(context, keyframes):
 
     if context.active_object and context.active_object.mode == 'POSE':
         armature_ob = context.active_object
-        objects = [[armature_ob, pb, armature_ob] for pb in \
-            context.selected_pose_bones]
+        objects = [[armature_ob, pb, armature_ob] for pb in
+                    context.selected_pose_bones]
     else:
         objects = [[ob, False, False] for ob in context.selected_objects]
 
@@ -258,8 +272,10 @@ def get_original_animation_data(context, keyframes):
 def calc_callback(self, context):
     if context.active_object and context.active_object.mode == 'POSE':
         armature_ob = context.active_object
-        objects = [[armature_ob, pb, armature_ob] for pb in \
-            context.selected_pose_bones]
+        objects = [
+                [armature_ob, pb, armature_ob] for pb in
+                context.selected_pose_bones
+                ]
     else:
         objects = [[ob, False, False] for ob in context.selected_objects]
     if objects == self.displayed:
@@ -273,318 +289,335 @@ def calc_callback(self, context):
         return
 
     # dictionaries with key: objectname
-    self.paths = {} # value: list of lists with x, y, color
-    self.keyframes = {} # value: dict with frame as key and [x,y] as value
-    self.handles = {} # value: dict of dicts
-    self.timebeads = {} # value: dict with frame as key and [x,y] as value
-    self.click = {} # value: list of lists with frame, type, loc-vector
+    self.paths = {}      # value: list of lists with x, y, color
+    self.keyframes = {}  # value: dict with frame as key and [x,y] as value
+    self.handles = {}    # value: dict of dicts
+    self.timebeads = {}  # value: dict with frame as key and [x,y] as value
+    self.click = {}      # value: list of lists with frame, type, loc-vector
     if selection_change:
         # value: editbone inverted rotation matrix or None
         self.edit_bones = {}
     if selection_change or not self.lock or context.window_manager.\
     motion_trail.force_update:
         # contains locations of path, keyframes and timebeads
-        self.cached = {"path":{}, "keyframes":{}, "timebeads_timing":{},
-            "timebeads_speed":{}}
+        self.cached = {
+                "path": {}, "keyframes": {}, "timebeads_timing": {},
+                "timebeads_speed": {}
+                }
     if self.cached["path"]:
         use_cache = True
     else:
         use_cache = False
     self.perspective = context.region_data.perspective_matrix.copy()
-    self.displayed = objects # store, so it can be checked next time
+    self.displayed = objects  # store, so it can be checked next time
     context.window_manager.motion_trail.force_update = False
+    try:
+        global_undo = context.user_preferences.edit.use_global_undo
+        context.user_preferences.edit.use_global_undo = False
+
+        for action_ob, child, offset_ob in objects:
+            if selection_change:
+                if not child:
+                    self.edit_bones[action_ob.name] = None
+                else:
+                    bpy.ops.object.mode_set(mode='EDIT')
+                    editbones = action_ob.data.edit_bones
+                    mat = editbones[child.name].matrix.copy().to_3x3().inverted()
+                    bpy.ops.object.mode_set(mode='POSE')
+                    self.edit_bones[child.name] = mat
 
-    global_undo = context.user_preferences.edit.use_global_undo
-    context.user_preferences.edit.use_global_undo = False
+            if not action_ob.animation_data:
+                continue
+            curves = get_curves(action_ob, child)
+            if len(curves) == 0:
+                continue
 
-    for action_ob, child, offset_ob in objects:
-        if selection_change:
-            if not child:
-                self.edit_bones[action_ob.name] = None
+            if context.window_manager.motion_trail.path_before == 0:
+                range_min = context.scene.frame_start
             else:
-                bpy.ops.object.mode_set(mode='EDIT')
-                editbones = action_ob.data.edit_bones
-                mat = editbones[child.name].matrix.copy().to_3x3().inverted()
-                bpy.ops.object.mode_set(mode='POSE')
-                self.edit_bones[child.name] = mat
-
-        if not action_ob.animation_data:
-            continue
-        curves = get_curves(action_ob, child)
-        if len(curves) == 0:
-            continue
-
-        if context.window_manager.motion_trail.path_before == 0:
-            range_min = context.scene.frame_start
-        else:
-            range_min = max(context.scene.frame_start,
-                context.scene.frame_current - \
-                context.window_manager.motion_trail.path_before)
-        if context.window_manager.motion_trail.path_after == 0:
-            range_max = context.scene.frame_end
-        else:
-            range_max = min(context.scene.frame_end,
-                context.scene.frame_current + \
-                context.window_manager.motion_trail.path_after)
-        fcx, fcy, fcz = curves
-        if child:
-            display_ob = child
-        else:
-            display_ob = action_ob
-
-        # get location data of motion path
-        path = []
-        speeds = []
-        frame_old = context.scene.frame_current
-        step = 11 - context.window_manager.motion_trail.path_resolution
-
-        if not use_cache:
-            if display_ob.name not in self.cached["path"]:
-                self.cached["path"][display_ob.name] = {}
-        if use_cache and range_min-1 in self.cached["path"][display_ob.name]:
-            prev_loc = self.cached["path"][display_ob.name][range_min-1]
-        else:
-            prev_loc = get_location(range_min-1, display_ob, offset_ob, curves)
-            self.cached["path"][display_ob.name][range_min-1] = prev_loc
-
-        for frame in range(range_min, range_max 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list