Arch: Export rebars to IFC as SweptDiskSolids + fixed half-done py3 compatibility - fixes #2684

This commit is contained in:
Yorik van Havre
2017-01-29 14:27:42 -02:00
parent 1e4b6ed00b
commit fc2010baa8
4 changed files with 77 additions and 10 deletions

View File

@@ -707,7 +707,7 @@ def pruneIncluded(objectslist,strict=False):
for obj in objectslist:
toplevel = True
if obj.isDerivedFrom("Part::Feature"):
if not (Draft.getType(obj) in ["Window","Clone","Pipe"]):
if not (Draft.getType(obj) in ["Window","Clone","Pipe","Rebar"]):
for parent in obj.InList:
if parent.isDerivedFrom("Part::Feature") and not (Draft.getType(parent) in ["Facebinder"]):
if not parent.isDerivedFrom("Part::Part2DObject"):

View File

@@ -183,6 +183,56 @@ class _Rebar(ArchComponent.Component):
v = DraftGeomUtils.vec(e).normalize()
return e.Vertexes[0].Point,v
return None,None
def getRebarData(self,obj):
if len(obj.InList) != 1:
return
if Draft.getType(obj.InList[0]) != "Structure":
return
if not obj.InList[0].Shape:
return
if not obj.Base:
return
if not obj.Base.Shape:
return
if not obj.Base.Shape.Wires:
return
if not obj.Diameter.Value:
return
if not obj.Amount:
return
father = obj.InList[0]
wire = obj.Base.Shape.Wires[0]
axis = obj.Base.Placement.Rotation.multVec(FreeCAD.Vector(0,0,-1))
size = (ArchCommands.projectToVector(father.Shape.copy(),axis)).Length
if hasattr(obj,"Rounding"):
if obj.Rounding:
radius = obj.Rounding * obj.Diameter.Value
import DraftGeomUtils
wire = DraftGeomUtils.filletWire(wire,radius)
wires = []
if obj.Amount == 1:
offset = DraftVecUtils.scaleTo(axis,size/2)
wire.translate(offset)
wires.append(wire)
else:
if obj.OffsetStart.Value:
baseoffset = DraftVecUtils.scaleTo(axis,obj.OffsetStart.Value)
else:
baseoffset = None
interval = size - (obj.OffsetStart.Value + obj.OffsetEnd.Value)
interval = interval / (obj.Amount - 1)
vinterval = DraftVecUtils.scaleTo(axis,interval)
for i in range(obj.Amount):
if i == 0:
if baseoffset:
wire.translate(baseoffset)
wires.append(wire)
else:
wire = wire.copy()
wire.translate(vinterval)
wires.append(wire)
return [wires,obj.Diameter.Value/2]
def execute(self,obj):

View File

@@ -21,6 +21,8 @@
#* *
#***************************************************************************
from __future__ import print_function
__title__ = "FreeCAD IFC importer - Enhanced ifcopenshell-only version"
__author__ = "Yorik van Havre","Jonathan Wiedemann"
__url__ = "http://www.freecadweb.org"
@@ -622,7 +624,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
obj.Placement.Rotation = r
obj.Placement.move(v)
else:
print "failed to compute placement ",
print ("failed to compute placement ",)
else:
obj = getattr(Arch,"make"+freecadtype)(baseobj=baseobj,name=name)
if store:
@@ -792,7 +794,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
Arch.addComponents(cobs,objects[host])
if DEBUG: FreeCAD.ActiveDocument.recompute()
if DEBUG: print "done"
if DEBUG: print ("done")
if MERGE_MODE_ARCH > 2: # if ArchObj is compound or ArchObj not imported
FreeCAD.ActiveDocument.recompute()
@@ -809,7 +811,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
if ifcfile[host].Name:
grp_name = ifcfile[host].Name
else:
if DEBUG: print "no group name specified for entity: #", ifcfile[host].id(), ", entity type is used!"
if DEBUG: print ("no group name specified for entity: #", ifcfile[host].id(), ", entity type is used!")
grp_name = ifcfile[host].is_a() + "_" + str(ifcfile[host].id())
grp = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup",grp_name.encode("utf8"))
objects[host] = grp
@@ -845,7 +847,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedArch")
obj.Shape = Part.makeCompound(shapes.values())
if DEBUG: print "done"
if DEBUG: print ("done")
else:
@@ -947,7 +949,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
if hasattr(objects[o],"BaseMaterial"):
objects[o].BaseMaterial = mat
if DEBUG and materials: print "done"
if DEBUG and materials: print ("done")
FreeCAD.ActiveDocument.recompute()
@@ -1356,7 +1358,7 @@ def export(exportList,filename):
if EXPORT_2D:
curvestyles = {}
if annotations and DEBUG: print "exporting 2D objects..."
if annotations and DEBUG: print ("exporting 2D objects...")
for anno in annotations:
xvc = ifcfile.createIfcDirection((1.0,0.0,0.0))
zvc = ifcfile.createIfcDirection((0.0,0.0,1.0))
@@ -1597,6 +1599,19 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
shapes.append(shape)
solidType = "SweptSolid"
shapetype = "extrusion"
elif hasattr(obj.Proxy,"getRebarData"):
# export rebars as IfcSweptDiskSolid
rdata = obj.Proxy.getRebarData(obj)
if rdata:
# convert to meters
r = rdata[1] * 0.001
for w in rdata[0]:
w.scale(0.001)
cur = createCurve(ifcfile,w)
shape = ifcfile.createIfcSweptDiskSolid(cur,r)
shapes.append(shape)
solidType = "SweptSolid"
shapetype = "extrusion"
if not shapes:
# brep representation