Arch: Fixes in structure and roof
This commit is contained in:
parent
9170bfe045
commit
28b663c914
|
@ -70,20 +70,15 @@ class _CommandRoof:
|
|||
FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+","+str(idx)+")")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
elif obj.isDerivedFrom("Part::Feature"):
|
||||
if len(obj.Shape.Faces) == 1:
|
||||
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Roof")))
|
||||
FreeCADGui.doCommand("import Arch")
|
||||
FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+",1)")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
elif obj.isDerivedFrom("Part::Feature"):
|
||||
if len(obj.Shape.Faces) == 1:
|
||||
return
|
||||
if obj.isDerivedFrom("Part::Feature"):
|
||||
if obj.Shape.Wires:
|
||||
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Roof")))
|
||||
FreeCADGui.doCommand("import Arch")
|
||||
FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+",1)")
|
||||
FreeCADGui.doCommand("Arch.makeRoof(FreeCAD.ActiveDocument."+obj.Name+")")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
return
|
||||
else:
|
||||
FreeCAD.Console.PrintMessage(str(translate("Arch","Unable to create a roof")))
|
||||
else:
|
||||
|
@ -110,37 +105,42 @@ class _Roof(ArchComponent.Component):
|
|||
import Part, math, DraftGeomUtils
|
||||
pl = obj.Placement
|
||||
|
||||
if obj.Base and obj.Face and obj.Angle:
|
||||
if len(obj.Base.Shape.Faces) >= obj.Face:
|
||||
f = obj.Base.Shape.Faces[obj.Face-1]
|
||||
if len(f.Wires) == 1:
|
||||
if f.Wires[0].isClosed():
|
||||
c = round(math.tan(math.radians(obj.Angle)),Draft.precision())
|
||||
norm = f.normalAt(0,0)
|
||||
d = f.BoundBox.DiagonalLength
|
||||
edges = DraftGeomUtils.sortEdges(f.Edges)
|
||||
l = len(edges)
|
||||
edges.append(edges[0])
|
||||
shps = []
|
||||
for i in range(l):
|
||||
v = DraftGeomUtils.vec(DraftGeomUtils.angleBisection(edges[i],edges[i+1]))
|
||||
v.normalize()
|
||||
bis = v.getAngle(DraftGeomUtils.vec(edges[i]))
|
||||
delta = 1/math.cos(bis)
|
||||
v.multiply(delta)
|
||||
n = (FreeCAD.Vector(norm)).multiply(c)
|
||||
dv = v.add(n)
|
||||
dv.normalize()
|
||||
dv.scale(d,d,d)
|
||||
shps.append(f.extrude(dv))
|
||||
c = shps.pop()
|
||||
for s in shps:
|
||||
c = c.common(s)
|
||||
c = c.removeSplitter()
|
||||
if not c.isNull():
|
||||
obj.Shape = c
|
||||
if not DraftGeomUtils.isNull(pl):
|
||||
obj.Placement = pl
|
||||
if obj.Base and obj.Angle:
|
||||
w = None
|
||||
if obj.Base.isDerivedFrom("Part::Feature"):
|
||||
if (obj.Base.Shape.Faces and obj.Face):
|
||||
w = obj.Base.Shape.Faces[obj.Face-1].Wires[0]
|
||||
elif obj.Base.Shape.Wires:
|
||||
w = obj.Base.Shape.Wires[0]
|
||||
if w:
|
||||
if w.isClosed():
|
||||
f = Part.Face(w)
|
||||
norm = f.normalAt(0,0)
|
||||
c = round(math.tan(math.radians(obj.Angle)),Draft.precision())
|
||||
d = f.BoundBox.DiagonalLength
|
||||
edges = DraftGeomUtils.sortEdges(f.Edges)
|
||||
l = len(edges)
|
||||
edges.append(edges[0])
|
||||
shps = []
|
||||
for i in range(l):
|
||||
v = DraftGeomUtils.vec(DraftGeomUtils.angleBisection(edges[i],edges[i+1]))
|
||||
v.normalize()
|
||||
bis = v.getAngle(DraftGeomUtils.vec(edges[i]))
|
||||
delta = 1/math.cos(bis)
|
||||
v.multiply(delta)
|
||||
n = (FreeCAD.Vector(norm)).multiply(c)
|
||||
dv = v.add(n)
|
||||
dv.normalize()
|
||||
dv.scale(d,d,d)
|
||||
shps.append(f.extrude(dv))
|
||||
c = shps.pop()
|
||||
for s in shps:
|
||||
c = c.common(s)
|
||||
c = c.removeSplitter()
|
||||
if not c.isNull():
|
||||
obj.Shape = c
|
||||
if not DraftGeomUtils.isNull(pl):
|
||||
obj.Placement = pl
|
||||
|
||||
class _ViewProviderRoof(ArchComponent.ViewProviderComponent):
|
||||
"A View Provider for the Roof object"
|
||||
|
|
|
@ -30,7 +30,7 @@ __title__="FreeCAD Structure"
|
|||
__author__ = "Yorik van Havre"
|
||||
__url__ = "http://free-cad.sourceforge.net"
|
||||
|
||||
def makeStructure(baseobj=None,length=None,width=None,height=None,name=str(translate("Arch","Structure"))):
|
||||
def makeStructure(baseobj=None,length=1,width=1,height=1,name=str(translate("Arch","Structure"))):
|
||||
'''makeStructure([obj],[length],[width],[heigth],[swap]): creates a
|
||||
structure element based on the given profile object and the given
|
||||
extrusion height. If no base object is given, you can also specify
|
||||
|
@ -38,16 +38,12 @@ def makeStructure(baseobj=None,length=None,width=None,height=None,name=str(trans
|
|||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||
_Structure(obj)
|
||||
_ViewProviderStructure(obj.ViewObject)
|
||||
if baseobj: obj.Base = baseobj
|
||||
if length: obj.Length = length
|
||||
if width: obj.Width = width
|
||||
if height: obj.Height = height
|
||||
if obj.Base:
|
||||
if baseobj:
|
||||
obj.Base = baseobj
|
||||
obj.Base.ViewObject.hide()
|
||||
else:
|
||||
if (not obj.Width) and (not obj.Length):
|
||||
obj.Width = 1
|
||||
obj.Height = 1
|
||||
obj.Width = width
|
||||
obj.Height = height
|
||||
obj.Length = length
|
||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
|
||||
c = p.GetUnsigned("StructureColor")
|
||||
r = float((c>>24)&0xFF)/255.0
|
||||
|
@ -116,43 +112,45 @@ class _Structure(ArchComponent.Component):
|
|||
|
||||
def createGeometry(self,obj):
|
||||
import Part, DraftGeomUtils
|
||||
|
||||
# getting default values
|
||||
height = normal = None
|
||||
if obj.Length:
|
||||
length = obj.Length
|
||||
else:
|
||||
length = 1
|
||||
width = 1
|
||||
height = width = length = 1
|
||||
if hasattr(obj,"Length"):
|
||||
if obj.Length:
|
||||
length = obj.Length
|
||||
if hasattr(obj,"Width"):
|
||||
if obj.Width:
|
||||
width = obj.Width
|
||||
if obj.Height:
|
||||
height = obj.Height
|
||||
else:
|
||||
for p in obj.InList:
|
||||
if Draft.getType(p) == "Floor":
|
||||
height = p.Height
|
||||
if not height: height = 1
|
||||
if obj.Normal == Vector(0,0,0):
|
||||
normal = Vector(0,0,1)
|
||||
else:
|
||||
normal = Vector(obj.Normal)
|
||||
if hasattr(obj,"Height"):
|
||||
if obj.Height:
|
||||
height = obj.Height
|
||||
|
||||
# creating shape
|
||||
# creating base shape
|
||||
pl = obj.Placement
|
||||
norm = normal.multiply(height)
|
||||
base = None
|
||||
if obj.Base:
|
||||
if obj.Base.isDerivedFrom("Part::Feature"):
|
||||
if obj.Normal == Vector(0,0,0):
|
||||
p = FreeCAD.Placement(obj.Base.Placement)
|
||||
normal = p.Rotation.multVec(Vector(0,0,1))
|
||||
else:
|
||||
normal = Vector(obj.Normal)
|
||||
normal = normal.multiply(height)
|
||||
base = obj.Base.Shape.copy()
|
||||
if base.Solids:
|
||||
pass
|
||||
elif base.Faces:
|
||||
base = base.extrude(normal)
|
||||
elif (len(base.Wires) == 1) and base.Wires[0].isClosed():
|
||||
base = Part.Face(base.Wires[0])
|
||||
base = base.extrude(normal)
|
||||
elif (len(base.Wires) == 1):
|
||||
if base.Wires[0].isClosed():
|
||||
base = Part.Face(base.Wires[0])
|
||||
base = base.extrude(normal)
|
||||
else:
|
||||
if obj.Normal == Vector(0,0,0):
|
||||
normal = Vector(0,0,1)
|
||||
else:
|
||||
normal = Vector(obj.Normal)
|
||||
normal = normal.multiply(height)
|
||||
l2 = length/2 or 0.5
|
||||
w2 = width/2 or 0.5
|
||||
v1 = Vector(-l2,-w2,0)
|
||||
|
@ -162,17 +160,20 @@ class _Structure(ArchComponent.Component):
|
|||
base = Part.makePolygon([v1,v2,v3,v4,v1])
|
||||
base = Part.Face(base)
|
||||
base = base.extrude(normal)
|
||||
for app in obj.Additions:
|
||||
if hasattr(app,"Shape"):
|
||||
if not app.Shape.isNull():
|
||||
base = base.fuse(app.Shape)
|
||||
app.ViewObject.hide() # to be removed
|
||||
for hole in obj.Subtractions:
|
||||
if hasattr(hole,"Shape"):
|
||||
if not hole.Shape.isNull():
|
||||
base = base.cut(hole.Shape)
|
||||
hole.ViewObject.hide() # to be removed
|
||||
|
||||
if base:
|
||||
# applying adds and subs
|
||||
if not base.isNull():
|
||||
for app in obj.Additions:
|
||||
if hasattr(app,"Shape"):
|
||||
if not app.Shape.isNull():
|
||||
base = base.fuse(app.Shape)
|
||||
app.ViewObject.hide() # to be removed
|
||||
for hole in obj.Subtractions:
|
||||
if hasattr(hole,"Shape"):
|
||||
if not hole.Shape.isNull():
|
||||
base = base.cut(hole.Shape)
|
||||
hole.ViewObject.hide() # to be removed
|
||||
pts = self.getAxisPoints(obj)
|
||||
if pts:
|
||||
fsh = []
|
||||
|
@ -182,10 +183,12 @@ class _Structure(ArchComponent.Component):
|
|||
fsh.append(sh)
|
||||
obj.Shape = Part.makeCompound(fsh)
|
||||
else:
|
||||
if not base.isNull():
|
||||
base = base.removeSplitter()
|
||||
obj.Shape = base
|
||||
if not DraftGeomUtils.isNull(pl): obj.Placement = pl
|
||||
if base:
|
||||
if not base.isNull():
|
||||
base = base.removeSplitter()
|
||||
obj.Shape = base
|
||||
if not DraftGeomUtils.isNull(pl):
|
||||
obj.Placement = pl
|
||||
|
||||
class _ViewProviderStructure(ArchComponent.ViewProviderComponent):
|
||||
"A View Provider for the Structure object"
|
||||
|
|
Loading…
Reference in New Issue
Block a user