Skip to content

Commit

Permalink
Draft: Added Ulrichs patch to fix Draft-Drawing projections - fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Mar 23, 2014
1 parent 3e80fa3 commit e293d61
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mod/Draft/Draft.py
Expand Up @@ -1549,7 +1549,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
if isinstance(direction,FreeCAD.Vector):
if direction != Vector(0,0,0):
plane = WorkingPlane.plane()
plane.alignToPointAndAxis(Vector(0,0,0),direction.negative(),0)
plane.alignToPointAndAxis_SVG(Vector(0,0,0),direction.negative().negative(),0)
elif isinstance(direction,WorkingPlane.plane):
plane = direction

Expand Down
58 changes: 58 additions & 0 deletions src/Mod/Draft/WorkingPlane.py
Expand Up @@ -136,6 +136,64 @@ def alignToPointAndAxis(self, point, axis, offset, upvec=None):
# FreeCAD.Console.PrintMessage("(position = " + str(self.position) + ")\n")
# FreeCAD.Console.PrintMessage("Current workplane: x="+str(DraftVecUtils.rounded(self.u))+" y="+str(DraftVecUtils.rounded(self.v))+" z="+str(DraftVecUtils.rounded(self.axis))+"\n")

def alignToPointAndAxis_SVG(self, point, axis, offset):
# based on cases table
self.doc = FreeCAD.ActiveDocument
self.axis = axis;
self.axis.normalize()
ref_vec = Vector(0.0, 1.0, 0.0)

if ((abs(axis.x) > abs(axis.y)) and (abs(axis.y) > abs(axis.z))):
ref_vec = Vector(0.0, 0., 1.0)
self.u = axis.negative().cross(ref_vec)
self.u.normalize()
self.v = DraftVecUtils.rotate(self.u, math.pi/2, self.axis)
#projcase = "Case new"

elif ((abs(axis.y) > abs(axis.z)) and (abs(axis.z) >= abs(axis.x))):
ref_vec = Vector(1.0, 0.0, 0.0)
self.u = axis.negative().cross(ref_vec)
self.u.normalize()
self.v = DraftVecUtils.rotate(self.u, math.pi/2, self.axis)
#projcase = "Y>Z, View Y"

elif ((abs(axis.y) >= abs(axis.x)) and (abs(axis.x) > abs(axis.z))):
ref_vec = Vector(0.0, 0., 1.0)
self.u = axis.cross(ref_vec)
self.u.normalize()
self.v = DraftVecUtils.rotate(self.u, math.pi/2, self.axis)
#projcase = "ehem. XY, Case XY"

elif ((abs(axis.x) > abs(axis.z)) and (abs(axis.z) >= abs(axis.y))):
self.u = axis.cross(ref_vec)
self.u.normalize()
self.v = DraftVecUtils.rotate(self.u, math.pi/2, self.axis)
#projcase = "X>Z, View X"

elif ((abs(axis.z) >= abs(axis.y)) and (abs(axis.y) > abs(axis.x))):
ref_vec = Vector(1.0, 0., 0.0)
self.u = axis.cross(ref_vec)
self.u.normalize()
self.v = DraftVecUtils.rotate(self.u, math.pi/2, self.axis)
#projcase = "Y>X, Case YZ"

else:
self.u = axis.negative().cross(ref_vec)
self.u.normalize()
self.v = DraftVecUtils.rotate(self.u, math.pi/2, self.axis)
#projcase = "else"

#spat_vec = self.u.cross(self.v)
#spat_res = spat_vec.dot(axis)
#FreeCAD.Console.PrintMessage(projcase + " spat Prod = " + str(spat_res) + "\n")

offsetVector = Vector(axis); offsetVector.multiply(offset)
self.position = point.add(offsetVector)
self.weak = False
# FreeCAD.Console.PrintMessage("(position = " + str(self.position) + ")\n")
# FreeCAD.Console.PrintMessage("Current workplane: x="+str(DraftVecUtils.rounded(self.u))+" y="+str(DraftVecUtils.rounded(self.v))+" z="+str(DraftVecUtils.rounded(self.axis))+"\n")


def alignToCurve(self, shape, offset):
if shape.ShapeType == 'Edge':
#??? TODO: process curve here. look at shape.edges[0].Curve
Expand Down

0 comments on commit e293d61

Please sign in to comment.