From 7b0d0aa2f7c01f37a66e552118cba3873138faad Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 18 Jul 2012 15:04:56 -0300 Subject: [PATCH] Arch: Minor fixes --- src/Mod/Arch/InitGui.py | 6 +++-- src/Mod/Arch/importOBJ.py | 44 ++++++++++++++++++++++++------------- src/Mod/Draft/DraftTools.py | 13 ++++++++--- src/Mod/Draft/InitGui.py | 2 +- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/Mod/Arch/InitGui.py b/src/Mod/Arch/InitGui.py index 523fc2352..69838792c 100644 --- a/src/Mod/Arch/InitGui.py +++ b/src/Mod/Arch/InitGui.py @@ -57,7 +57,7 @@ class ArchWorkbench(Workbench): ToolTip = "Architecture workbench" def Initialize(self): - import DraftTools,DraftGui,Arch_rc,Arch + import DraftTools,DraftGui,Arch_rc,Arch,Draft_rc # arch tools self.archtools = ["Arch_Wall","Arch_Structure", @@ -91,6 +91,8 @@ class ArchWorkbench(Workbench): FreeCADGui.addIconPath(":/icons") FreeCADGui.addLanguagePath(":/translations") FreeCADGui.addPreferencePage(":/ui/archprefs-base.ui","Arch") + FreeCADGui.addPreferencePage(":/ui/userprefs-base.ui","Draft") + FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft") Log ('Loading Arch module... done\n') def Activated(self): @@ -106,7 +108,7 @@ class ArchWorkbench(Workbench): Msg("Arch workbench deactivated\n") def ContextMenu(self, recipient): - self.appendContextMenu("Display tools",self.draftcontexttools) + self.appendContextMenu("Draft context tools",self.draftcontexttools) def GetClassName(self): return "Gui::PythonWorkbench" diff --git a/src/Mod/Arch/importOBJ.py b/src/Mod/Arch/importOBJ.py index 1e2f7373e..f947afbcd 100644 --- a/src/Mod/Arch/importOBJ.py +++ b/src/Mod/Arch/importOBJ.py @@ -21,7 +21,9 @@ #* * #*************************************************************************** -import FreeCAD, DraftGeomUtils, Part +import FreeCAD, DraftGeomUtils, Part, Draft + +p = Draft.precision() if open.__module__ == '__builtin__': pythonopen = open @@ -29,8 +31,10 @@ if open.__module__ == '__builtin__': def findVert(aVertex,aList): "finds aVertex in aList, returns index" for i in range(len(aList)): - if (aVertex.X == aList[i].X) and (aVertex.Y == aList[i].Y) and (aVertex.Z == aList[i].Z): - return i + if ( round(aVertex.X,p) == round(aList[i].X,p) ): + if ( round(aVertex.Y,p) == round(aList[i].Y,p) ): + if ( round(aVertex.Z,p) == round(aList[i].Z,p) ): + return i def getIndices(shape,offset): "returns a list with 2 lists: vertices and face indexes, offsetted with the given amount" @@ -38,23 +42,33 @@ def getIndices(shape,offset): elist = [] flist = [] for v in shape.Vertexes: - vlist.append(" "+str(round(v.X,4))+" "+str(round(v.Y,4))+" "+str(round(v.Z,4))) + vlist.append(" "+str(round(v.X,p))+" "+str(round(v.Y,p))+" "+str(round(v.Z,p))) if not shape.Faces: for e in shape.Edges: if isinstance(e,Part.Line): - ei = " " + str(findVert(e.Vertexes[0],shape.Vertexes)+offset) - ei += " " + str(findVert(e.Vertexes[-1],shape.Vertexes)+offset) + ei = " " + str(findVert(e.Vertexes[0],shape.Vertexes) + offset) + ei += " " + str(findVert(e.Vertexes[-1],shape.Vertexes) + offset) elist.append(ei) for f in shape.Faces: - fi = "" - # OCC vertices are unsorted. We need to sort in the right order... - edges = DraftGeomUtils.sortEdges(f.Wire.Edges) - #print edges - for e in edges: - #print e.Vertexes[0].Point,e.Vertexes[1].Point - v = e.Vertexes[0] - fi+=" "+str(findVert(v,shape.Vertexes)+offset) - flist.append(fi) + if len(f.Wires) > 1: + # if we have holes, we triangulate + tris = f.tessellate(1) + for fdata in tris[1]: + fi = "" + for vi in fdata: + vdata = Part.Vertex(tris[0][vi]) + fi += " " + str(findVert(vdata,shape.Vertexes) + offset) + flist.append(fi) + else: + fi = "" + # OCC vertices are unsorted. We need to sort in the right order... + edges = DraftGeomUtils.sortEdges(f.Wire.Edges) + #print edges + for e in edges: + #print e.Vertexes[0].Point,e.Vertexes[1].Point + v = e.Vertexes[0] + fi += " " + str(findVert(v,shape.Vertexes) + offset) + flist.append(fi) return vlist,elist,flist def export(exportList,filename): diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index f8eeca25e..10d1bb382 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -3617,7 +3617,7 @@ class WireToBSpline(Modifier): def finish(self): Modifier.finish(self) - + class SelectGroup(): "The SelectGroup FreeCAD command definition" @@ -3634,7 +3634,14 @@ class SelectGroup(): def Activated(self): sellist = [] - for ob in Draft.getSelection(): + sel = Draft.getSelection() + if len(sel) == 1: + if sel[0].isDerivedFrom("App::DocumentObjectGroup"): + cts = Draft.getGroupContents(FreeCADGui.Selection.getSelection()) + for o in cts: + FreeCADGui.Selection.addSelection(o) + return + for ob in sel: for child in ob.OutList: FreeCADGui.Selection.addSelection(child) for parent in ob.InList: @@ -3642,7 +3649,7 @@ class SelectGroup(): for child in parent.OutList: FreeCADGui.Selection.addSelection(child) - + class Shape2DView(): "The Shape2DView FreeCAD command definition" def GetResources(self): diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index b4b83ee35..ea71b0d00 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -225,7 +225,7 @@ class DraftWorkbench (Workbench): self.appendContextMenu("",self.lineList) else: if (FreeCADGui.Selection.getSelection()): - self.appendContextMenu("Display options",self.treecmdList) + self.appendContextMenu("Draft context tools",self.treecmdList) def GetClassName(self): return "Gui::PythonWorkbench"