From b44031df60e0e08aca6ae685994a274c4a0c8ffb Mon Sep 17 00:00:00 2001 From: carlopav Date: Sat, 8 Feb 2020 11:11:31 +0100 Subject: [PATCH] [Draft] Move and rotate bugfix to handle App::DocumentGroup Bugfix, ref https://forum.freecadweb.org/viewtopic.php?f=23&t=43061 --- src/Mod/Draft/Draft.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 0a3bee0445..9677028d28 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -1039,10 +1039,14 @@ def move(objectslist,vector,copy=False): newgroups = {} objectslist = filterObjectsForModifiers(objectslist, copy) for obj in objectslist: + newobj = None # real_vector have been introduced to take into account # the possibility that object is inside an App::Part - v_minus_global = obj.getGlobalPlacement().inverse().Rotation.multVec(vector) - real_vector = obj.Placement.Rotation.multVec(v_minus_global) + if hasattr(obj, "getGlobalPlacement"): + v_minus_global = obj.getGlobalPlacement().inverse().Rotation.multVec(vector) + real_vector = obj.Placement.Rotation.multVec(v_minus_global) + else: + real_vector = vector if getType(obj) == "Point": v = Vector(obj.X,obj.Y,obj.Z) v = v.add(real_vector) @@ -1053,6 +1057,8 @@ def move(objectslist,vector,copy=False): newobj.X = v.x newobj.Y = v.y newobj.Z = v.z + elif obj.isDerivedFrom("App::DocumentObjectGroup"): + pass elif hasattr(obj,'Shape'): if copy: newobj = makeCopy(obj) @@ -1102,7 +1108,8 @@ def move(objectslist,vector,copy=False): if "Placement" in obj.PropertiesList: pla = obj.Placement pla.move(real_vector) - newobjlist.append(newobj) + if newobj is not None: + newobjlist.append(newobj) if copy: for p in obj.InList: if p.isDerivedFrom("App::DocumentObjectGroup") and (p in objectslist): @@ -1230,12 +1237,18 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False) newgroups = {} objectslist = filterObjectsForModifiers(objectslist, copy) for obj in objectslist: + newobj = None # real_center and real_axis are introduced to take into account # the possibility that object is inside an App::Part - ci = obj.getGlobalPlacement().inverse().multVec(center) - real_center = obj.Placement.multVec(ci) - ai = obj.getGlobalPlacement().inverse().Rotation.multVec(axis) - real_axis = obj.Placement.Rotation.multVec(ai) + if hasattr(obj, "getGlobalPlacement"): + ci = obj.getGlobalPlacement().inverse().multVec(center) + real_center = obj.Placement.multVec(ci) + ai = obj.getGlobalPlacement().inverse().Rotation.multVec(axis) + real_axis = obj.Placement.Rotation.multVec(ai) + else: + real_center = center + real_axis = axis + if copy: newobj = makeCopy(obj) else: @@ -1264,6 +1277,8 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False) newobj.X = v.x newobj.Y = v.y newobj.Z = v.z + elif obj.isDerivedFrom("App::DocumentObjectGroup"): + pass elif hasattr(obj,"Placement"): #FreeCAD.Console.PrintMessage("placement rotation\n") shape = Part.Shape() @@ -1277,7 +1292,8 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False) newobj.Shape = shape if copy: formatObject(newobj,obj) - newobjlist.append(newobj) + if newobj is not None: + newobjlist.append(newobj) if copy: for p in obj.InList: if p.isDerivedFrom("App::DocumentObjectGroup") and (p in objectslist):