Skip to content

Commit

Permalink
[Draft] Move and Rotate documentation of recent changes
Browse files Browse the repository at this point in the history
[Draft] Edit: small typo fix
  • Loading branch information
carlopav committed Dec 29, 2019
1 parent 1f59ee3 commit 646a480
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/Mod/Draft/Draft.py
Expand Up @@ -1596,11 +1596,13 @@ def move(objectslist,vector,copy=False):
newgroups = {}
objectslist = filterObjectsForModifiers(objectslist, copy)
for obj in objectslist:
vminusglobal = obj.getGlobalPlacement().inverse().Rotation.multVec(vector)
realvector = obj.Placement.Rotation.multVec(vminusglobal)
# 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 getType(obj) == "Point":
v = Vector(obj.X,obj.Y,obj.Z)
v = v.add(realvector)
v = v.add(real_vector)
if copy:
newobj = makeCopy(obj)
else:
Expand All @@ -1614,7 +1616,7 @@ def move(objectslist,vector,copy=False):
else:
newobj = obj
pla = newobj.Placement
pla.move(realvector)
pla.move(real_vector)
elif getType(obj) == "Annotation":
if copy:
newobj = FreeCAD.ActiveDocument.addObject("App::Annotation",getRealName(obj.Name))
Expand All @@ -1623,7 +1625,7 @@ def move(objectslist,vector,copy=False):
formatObject(newobj,obj)
else:
newobj = obj
newobj.Position = obj.Position.add(realvector)
newobj.Position = obj.Position.add(real_vector)
elif getType(obj) == "DraftText":
if copy:
newobj = FreeCAD.ActiveDocument.addObject("App::FeaturePython",getRealName(obj.Name))
Expand All @@ -1637,7 +1639,7 @@ def move(objectslist,vector,copy=False):
formatObject(newobj,obj)
else:
newobj = obj
newobj.Placement.Base = obj.Placement.Base.add(realvector)
newobj.Placement.Base = obj.Placement.Base.add(real_vector)
elif getType(obj) == "Dimension":
if copy:
newobj = FreeCAD.ActiveDocument.addObject("App::FeaturePython",getRealName(obj.Name))
Expand All @@ -1647,16 +1649,16 @@ def move(objectslist,vector,copy=False):
formatObject(newobj,obj)
else:
newobj = obj
newobj.Start = obj.Start.add(realvector)
newobj.End = obj.End.add(realvector)
newobj.Dimline = obj.Dimline.add(realvector)
newobj.Start = obj.Start.add(real_vector)
newobj.End = obj.End.add(real_vector)
newobj.Dimline = obj.Dimline.add(real_vector)
else:
if copy and obj.isDerivedFrom("Mesh::Feature"):
print("Mesh copy not supported at the moment") # TODO
newobj = obj
if "Placement" in obj.PropertiesList:
pla = obj.Placement
pla.move(realvector)
pla.move(real_vector)
newobjlist.append(newobj)
if copy:
for p in obj.InList:
Expand Down Expand Up @@ -1785,15 +1787,17 @@ 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:
# 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)
c = obj.Placement.multVec(ci)
real_center = obj.Placement.multVec(ci)
ai = obj.getGlobalPlacement().inverse().Rotation.multVec(axis)
a = obj.Placement.Rotation.multVec(ai)
real_axis = obj.Placement.Rotation.multVec(ai)
if copy:
newobj = makeCopy(obj)
else:
newobj = obj
if (obj.isDerivedFrom("App::Annotation")):
if obj.isDerivedFrom("App::Annotation"):
if axis.normalize() == Vector(1,0,0):
newobj.ViewObject.RotationAxis = "X"
newobj.ViewObject.Rotation = angle
Expand All @@ -1811,22 +1815,22 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False)
newobj.ViewObject.Rotation = -angle
elif getType(obj) == "Point":
v = Vector(obj.X,obj.Y,obj.Z)
rv = v.sub(c)
rv = DraftVecUtils.rotate(rv,math.radians(angle),a)
v = c.add(rv)
rv = v.sub(real_center)
rv = DraftVecUtils.rotate(rv,math.radians(angle),real_axis)
v = real_center.add(rv)
newobj.X = v.x
newobj.Y = v.y
newobj.Z = v.z
elif hasattr(obj,"Placement"):
#FreeCAD.Console.PrintMessage("placement rotation\n")
shape = Part.Shape()
shape.Placement = obj.Placement
shape.rotate(DraftVecUtils.tup(c), DraftVecUtils.tup(a), angle)
shape.rotate(DraftVecUtils.tup(real_center), DraftVecUtils.tup(real_axis), angle)
newobj.Placement = shape.Placement
elif hasattr(obj,'Shape') and (getType(obj) not in ["WorkingPlaneProxy","BuildingPart"]):
#think it make more sense to try first to rotate placement and later to try with shape. no?
shape = obj.Shape.copy()
shape.rotate(DraftVecUtils.tup(c), DraftVecUtils.tup(a), angle)
shape.rotate(DraftVecUtils.tup(real_center), DraftVecUtils.tup(real_axis), angle)
newobj.Shape = shape
if copy:
formatObject(newobj,obj)
Expand All @@ -1843,7 +1847,7 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False)
select(newobjlist)
if len(newobjlist) == 1: return newobjlist[0]
return newobjlist

def scaleVectorFromCenter(vector, scale, center):
return vector.sub(center).scale(scale.x, scale.y, scale.z).add(center)

Expand Down

0 comments on commit 646a480

Please sign in to comment.