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

@ -184,6 +184,56 @@ class _Rebar(ArchComponent.Component):
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):
if self.clone(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

View File

@ -217,6 +217,8 @@ def isClone(obj,objtype,recursive=False):
"""isClone(obj,objtype,[recursive]): returns True if the given object is
a clone of an object of the given type. If recursive is True, also check if
the clone is a clone of clone (of clone...) of the given type."""
if isinstance(objtype,list):
return any([isClone(obj,t,recursive) for t in objtype])
if getType(obj) == "Clone":
if len(obj.Objects) == 1:
if getType(obj.Objects[0]) == objtype:
@ -331,14 +333,14 @@ def shapify(obj):
def getGroupContents(objectslist,walls=False,addgroups=False):
'''getGroupContents(objectlist,[walls,addgroups]): if any object of the given list
is a group, its content is appened to the list, which is returned. If walls is True,
walls are also scanned for included windows. If addgroups is true, the group itself
is also included in the list.'''
walls and structures are also scanned for included windows or rebars. If addgroups
is true, the group itself is also included in the list.'''
def getWindows(obj):
l = []
if getType(obj) in ["Wall","Structure"]:
for o in obj.OutList:
l.extend(getWindows(o))
elif (getType(obj) == "Window") or isClone(obj,"Window"):
elif (getType(obj) in ["Window","Rebar"]) or isClone(obj,["Window","Rebar"]):
l.append(obj)
return l