From 8a24f0fe6fcd1c140cded07d87f57e9aed228fe4 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 8 Aug 2014 13:48:30 -0300 Subject: [PATCH] Draft: Setting the WorkingPlane from a quad face now also takes its x and y directions --- src/Mod/Arch/ArchStructure.py | 1 + src/Mod/Arch/importIFC.py | 3 ++- src/Mod/Draft/DraftGeomUtils.py | 20 ++++++++++++++++++++ src/Mod/Draft/DraftTools.py | 2 +- src/Mod/Draft/WorkingPlane.py | 9 ++++++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index 82d698b6f..21c78c47d 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -435,6 +435,7 @@ class _CommandStructure: else: FreeCADGui.doCommand('s = Arch.makeStructure(length='+str(self.Length)+',width='+str(self.Width)+',height='+str(self.Height)+')') FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point)) + FreeCADGui.doCommand('s.Placement.Rotation=FreeCAD.DraftWorkingPlane.getRotation().Rotation') FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() if self.continueCmd: diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 627055dfe..7714ab140 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -194,7 +194,8 @@ def insert(filename,docname,skip=[]): obj = baseobj if obj: sh = baseobj.Shape.ShapeType if hasattr(baseobj,"Shape") else "None" - if DEBUG: print "creating object ",pid," : ",ptype, " with shape: ",sh + sols = str(baseobj.Shape.Solids) if hasattr(baseobj,"Shape") else "" + if DEBUG: print "creating object ",pid," : ",ptype, " with shape: ",sh," ",sols objects[pid] = obj # subtractions diff --git a/src/Mod/Draft/DraftGeomUtils.py b/src/Mod/Draft/DraftGeomUtils.py index 1128af35c..3f9e796db 100755 --- a/src/Mod/Draft/DraftGeomUtils.py +++ b/src/Mod/Draft/DraftGeomUtils.py @@ -126,6 +126,26 @@ def isAligned(edge,axis="x"): if edge.StartPoint.z == edge.EndPoint.z: return True return False + +def getQuad(face): + """getQuad(face): returns a list of 3 vectors (basepoint, Xdir, Ydir) if the face + is a quad, or None if not.""" + if len(face.Edges) != 4: + return None + v1 = vec(face.Edges[0]) + v2 = vec(face.Edges[1]) + v3 = vec(face.Edges[2]) + v4 = vec(face.Edges[3]) + angles90 = [round(math.pi*0.5,precision()),round(math.pi*1.5,precision())] + angles180 = [0,round(math.pi,precision()),round(math.pi*2,precision())] + for ov in [v2,v3,v4]: + if not (round(v1.getAngle(ov),precision()) in angles90+angles180): + return None + for ov in [v2,v3,v4]: + if round(v1.getAngle(ov),precision()) in angles90: + v1.normalize() + ov.normalize() + return [face.Edges[0].Vertexes[0].Point,v1,ov] def areColinear(e1,e2): """areColinear(e1,e2): returns True if both edges are colinear""" diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index 0f02a7b95..6c789551c 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -385,7 +385,7 @@ class SelectPlane(DraftTool): elif arg == "currentView": d = self.view.getViewDirection().negative() FreeCADGui.doCommandGui("FreeCAD.DraftWorkingPlane.alignToPointAndAxis(FreeCAD.Vector(0,0,0), FreeCAD.Vector("+str(d.x)+","+str(d.y)+","+str(d.z)+"), "+str(self.offset)+")") - self.display(viewDirection) + self.display(d) self.finish() elif arg == "reset": FreeCADGui.doCommandGui("FreeCAD.DraftWorkingPlane.reset()") diff --git a/src/Mod/Draft/WorkingPlane.py b/src/Mod/Draft/WorkingPlane.py index 6171f510a..796a6c9f9 100644 --- a/src/Mod/Draft/WorkingPlane.py +++ b/src/Mod/Draft/WorkingPlane.py @@ -224,8 +224,15 @@ class plane: def alignToFace(self, shape, offset=0): # Set face to the unique selected face, if found if shape.ShapeType == 'Face': - #we should really use face.tangentAt to get u and v here, and implement alignToUVPoint self.alignToPointAndAxis(shape.Faces[0].CenterOfMass, shape.Faces[0].normalAt(0,0), offset) + import DraftGeomUtils + q = DraftGeomUtils.getQuad(shape) + if q: + self.u = q[1] + self.v = q[2] + if not DraftVecUtils.equals(self.u.cross(self.v),self.axis): + self.u = q[2] + self.v = q[1] return True else: return False