[Draft] Fix to mirror tool
the normal is not computed with the view, but with the working plane if active. ref. https://forum.freecadweb.org/viewtopic.php?f=23&t=44301&p=380632#p380370
This commit is contained in:
committed by
Yorik van Havre
parent
0584604b93
commit
d9dd618230
@@ -2222,38 +2222,47 @@ def getCloneBase(obj,strict=False):
|
||||
return obj
|
||||
|
||||
|
||||
def mirror(objlist,p1,p2):
|
||||
"""mirror(objlist,p1,p2,[clone]): creates a mirrored version of the given object(s)
|
||||
along an axis that passes through the two vectors p1 and p2."""
|
||||
def mirror(objlist, p1, p2):
|
||||
"""mirror(objlist, p1, p2)
|
||||
creates a Part::Mirror of the given object(s), along a plane defined
|
||||
by the 2 given points and the draft working plane normal.
|
||||
"""
|
||||
|
||||
if not objlist:
|
||||
FreeCAD.Console.PrintError(translate("draft","No object given")+"\n")
|
||||
_err = "No object given"
|
||||
FreeCAD.Console.PrintError(translate("draft", _err) + "\n")
|
||||
return
|
||||
if p1 == p2:
|
||||
FreeCAD.Console.PrintError(translate("draft","The two points are coincident")+"\n")
|
||||
_err = "The two points are coincident"
|
||||
FreeCAD.Console.PrintError(translate("draft", _err) + "\n")
|
||||
return
|
||||
if not isinstance(objlist,list):
|
||||
objlist = [objlist]
|
||||
|
||||
if hasattr(FreeCAD, "DraftWorkingPlane"):
|
||||
norm = FreeCAD.DraftWorkingPlane.getNormal()
|
||||
elif gui:
|
||||
norm = FreeCADGui.ActiveDocument.ActiveView.getViewDirection().negative()
|
||||
else:
|
||||
norm = FreeCAD.Vector(0,0,1)
|
||||
|
||||
pnorm = p2.sub(p1).cross(norm).normalize()
|
||||
|
||||
result = []
|
||||
|
||||
for obj in objlist:
|
||||
mir = FreeCAD.ActiveDocument.addObject("Part::Mirroring","mirror")
|
||||
mir.Label = "Mirror of "+obj.Label
|
||||
mir.Label = "Mirror of " + obj.Label
|
||||
mir.Source = obj
|
||||
if gui:
|
||||
norm = FreeCADGui.ActiveDocument.ActiveView.getViewDirection().negative()
|
||||
else:
|
||||
norm = FreeCAD.Vector(0,0,1)
|
||||
pnorm = p2.sub(p1).cross(norm).normalize()
|
||||
mir.Base = p1
|
||||
mir.Normal = pnorm
|
||||
formatObject(mir,obj)
|
||||
formatObject(mir, obj)
|
||||
result.append(mir)
|
||||
|
||||
if len(result) == 1:
|
||||
result = result[0]
|
||||
select(result)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user