From a1d9268cebc38f7b9906193daca8a2d573733d1c Mon Sep 17 00:00:00 2001
From: Ulrich Brammer <ubrammer@t-online.de>
Date: Tue, 18 Mar 2014 19:37:39 +0100
Subject: Makes Draft-Drawing-Projection in sync with Drawing-Projection

---
 src/Mod/Draft/Draft.py        |    2 +-
 src/Mod/Draft/WorkingPlane.py |   58 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py
index 8bd7c60..2c7c98e 100644
--- a/src/Mod/Draft/Draft.py
+++ b/src/Mod/Draft/Draft.py
@@ -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
 
diff --git a/src/Mod/Draft/WorkingPlane.py b/src/Mod/Draft/WorkingPlane.py
index 25a0c3f..69207bd 100644
--- a/src/Mod/Draft/WorkingPlane.py
+++ b/src/Mod/Draft/WorkingPlane.py
@@ -136,6 +136,64 @@ class plane:
         # 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
-- 
1.7.10.4

