From d5469ba3fcc7a38b9dbb11e2db7e3c7bd7a04a89 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sat, 26 Jul 2014 16:37:06 -0300 Subject: [PATCH] Arch: misc bugfixes --- src/Mod/Arch/ArchCommands.py | 10 ++-- src/Mod/Arch/ArchComponent.py | 6 +- src/Mod/Arch/ArchStairs.py | 106 +++++++++++++++++----------------- src/Mod/Arch/importIFC.py | 16 ++++- 4 files changed, 77 insertions(+), 61 deletions(-) diff --git a/src/Mod/Arch/ArchCommands.py b/src/Mod/Arch/ArchCommands.py index b51838ca1cc2..2976f4a3fdee 100644 --- a/src/Mod/Arch/ArchCommands.py +++ b/src/Mod/Arch/ArchCommands.py @@ -766,15 +766,15 @@ def toggleIfcBrepFlag(obj): FreeCAD.Console.PrintMessage(translate("Arch","Object doesn't have settable IFC Attributes")) else: d = obj.IfcAttributes - if "ForceBrep" in d.keys(): - if d["ForceBrep"] == "True": - d["ForceBrep"] = "False" + if "FlagForceBrep" in d.keys(): + if d["FlagForceBrep"] == "True": + d["FlagForceBrep"] = "False" FreeCAD.Console.PrintMessage(translate("Arch","Disabling Brep force flag of object")+" "+obj.Label+"\n") else: - d["ForceBrep"] = "True" + d["FlagForceBrep"] = "True" FreeCAD.Console.PrintMessage(translate("Arch","Enabling Brep force flag of object")+" "+obj.Label+"\n") else: - d["ForceBrep"] = "True" + d["FlagForceBrep"] = "True" FreeCAD.Console.PrintMessage(translate("Arch","Enabling Brep force flag of object")+" "+obj.Label+"\n") obj.IfcAttributes = d diff --git a/src/Mod/Arch/ArchComponent.py b/src/Mod/Arch/ArchComponent.py index 3e48d1e66731..fa21840fb57f 100644 --- a/src/Mod/Arch/ArchComponent.py +++ b/src/Mod/Arch/ArchComponent.py @@ -69,7 +69,7 @@ def addToComponent(compobject,addobject,mod=None): if Draft.getType(addobject) == "Axis": l = getattr(compobject,mod) l.append(addobject) - setattr(compobject,mod,l) + setattr(compobject,mod,l) else: l = getattr(compobject,mod) l.append(addobject) @@ -352,6 +352,8 @@ def getAxis(self,obj): def getProfiles(self,obj,noplacement=False): "Returns the base profile(s) of this component, if applicable" + if not obj.Shape: return [] + if obj.Shape.isNull(): return [] wires = [] n,l,w,h = self.getDefaultValues(obj) if obj.Base: @@ -411,7 +413,7 @@ def getProfiles(self,obj,noplacement=False): wires.append(sh) else: wires.append(wire) - else: + elif Draft.getType(obj) in ["Wall","Structure"]: if (Draft.getType(obj) == "Structure") and (l > h): if noplacement: h2 = h/2 or 0.5 diff --git a/src/Mod/Arch/ArchStairs.py b/src/Mod/Arch/ArchStairs.py index 5b8cb789a646..68ef9e9e44da 100644 --- a/src/Mod/Arch/ArchStairs.py +++ b/src/Mod/Arch/ArchStairs.py @@ -60,8 +60,6 @@ def makeStairs(baseobj=None,length=None,width=None,height=None,steps=None,name=t obj.Height = p.GetFloat("StairsHeight",3000.0) if steps: obj.NumberOfSteps = steps - else: - obj.NumberOfSteps = p.GetInt("StairsSteps",17) return obj @@ -77,13 +75,14 @@ def IsActive(self): return not FreeCAD.ActiveDocument is None def Activated(self): + p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Stairs")) FreeCADGui.doCommand("import Arch") if len(FreeCADGui.Selection.getSelection()) == 1: n = FreeCADGui.Selection.getSelection()[0].Name FreeCADGui.doCommand("Arch.makeStairs(baseobj=FreeCAD.ActiveDocument."+n+")") else: - FreeCADGui.doCommand("Arch.makeStairs()") + FreeCADGui.doCommand("Arch.makeStairs(steps="+str(p.GetInt("StairsSteps",17))+")") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() @@ -137,64 +136,67 @@ def execute(self,obj): self.structures = [] pl = obj.Placement landings = 0 - - # base tests - if not obj.Width.Value: - return - if not obj.Height.Value: - if not obj.Base: - return - if obj.NumberOfSteps < 2: - return + + base = None + if obj.Base: - if not obj.Base.isDerivedFrom("Part::Feature"): - return - if obj.Base.Shape.Solids: - obj.Shape = obj.Base.Shape.copy() - obj.Placement = FreeCAD.Placement(obj.Base.Placement).multiply(pl) - obj.TreadDepth = 0.0 - obj.RiserHeight = 0.0 - return - if not obj.Base.Shape.Edges: - return - if obj.Base.Shape.Faces: - return - if (len(obj.Base.Shape.Edges) == 1): - edge = obj.Base.Shape.Edges[0] - if isinstance(edge.Curve,Part.Line): - if obj.Landings == "At center": - landings = 1 - self.makeStraightStairsWithLanding(obj,edge) - else: - self.makeStraightStairs(obj,edge) - else: - if obj.Landings == "At center": - landings = 1 - self.makeCurvedStairsWithLandings(obj,edge) + if hasattr(obj.Base,"Shape"): + if obj.Base.Shape: + if obj.Base.Shape.Solids: + base = obj.Base.Shape.copy() + + if (not base) and obj.Width.Value and obj.Height.Value and (obj.NumberOfSteps > 1): + if obj.Base: + if not obj.Base.isDerivedFrom("Part::Feature"): + return + if obj.Base.Shape.Solids: + obj.Shape = obj.Base.Shape.copy() + obj.Placement = FreeCAD.Placement(obj.Base.Placement).multiply(pl) + obj.TreadDepth = 0.0 + obj.RiserHeight = 0.0 + return + if not obj.Base.Shape.Edges: + return + if obj.Base.Shape.Faces: + return + if (len(obj.Base.Shape.Edges) == 1): + edge = obj.Base.Shape.Edges[0] + if isinstance(edge.Curve,Part.Line): + if obj.Landings == "At center": + landings = 1 + self.makeStraightStairsWithLanding(obj,edge) + else: + self.makeStraightStairs(obj,edge) else: - self.makeCurvedStairs(obj,edge) - else: - if not obj.Length.Value: - return - edge = Part.Line(Vector(0,0,0),Vector(obj.Length.Value,0,0)).toShape() - if obj.Landings == "At center": - landings = 1 - self.makeStraightStairsWithLanding(obj,edge) + if obj.Landings == "At center": + landings = 1 + self.makeCurvedStairsWithLandings(obj,edge) + else: + self.makeCurvedStairs(obj,edge) else: - self.makeStraightStairs(obj,edge) + if not obj.Length.Value: + return + edge = Part.Line(Vector(0,0,0),Vector(obj.Length.Value,0,0)).toShape() + if obj.Landings == "At center": + landings = 1 + self.makeStraightStairsWithLanding(obj,edge) + else: + self.makeStraightStairs(obj,edge) if self.structures or self.steps: - shape = Part.makeCompound(self.structures + self.steps) - shape = self.processSubShapes(obj,shape,pl) - obj.Shape = shape - obj.Placement = pl + base = Part.makeCompound(self.structures + self.steps) elif self.pseudosteps: shape = Part.makeCompound(self.pseudosteps) obj.Shape = shape obj.Placement = pl - else: - print "unable to calculate a stairs shape" - + return + + base = self.processSubShapes(obj,base,pl) + if base: + if not base.isNull(): + obj.Shape = base + obj.Placement = pl + # compute step data if obj.NumberOfSteps > 1: l = obj.Length.Value diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index a488f5b36de2..8ff35d1703ab 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -1016,8 +1016,8 @@ def export(exportList,filename): # getting the "Force BREP" flag brepflag = False if hasattr(obj,"IfcAttributes"): - if "ForceBrep" in obj.IfcAttributes.keys(): - if obj.IfcAttributes["ForceBrep"] == "True": + if "FlagForceBrep" in obj.IfcAttributes.keys(): + if obj.IfcAttributes["FlagForceBrep"] == "True": brepflag = True if DEBUG: print "Adding " + obj.Label + " as Ifc" + ifctype @@ -1324,9 +1324,21 @@ def getIfcBrepFacesData(obj,scale=1,sub=False,tessellation=1): if not obj.Shape.isNull(): if obj.Shape.isValid(): shape = obj.Shape + elif hasattr(obj,"Terrain"): + if obj.Terrain: + if hasattr(obj.Terrain,"Shape"): + if obj.Terrain.Shape: + if not obj.Terrain.Shape.isNull(): + if obj.Terrain.Shape.isValid(): + fcshape = obj.Terrain.Shape if shape: import Part sols = [] + if fcshape.Solids: + dataset = fcshape.Solids + else: + dataset = fcshape.Shells + print "Warning! object contains no solids" for sol in shape.Solids: s = [] curves = False