Merge pull request #12899 from yorikvanhavre/arch-array-ifc
Arch: Fixed IFC export of arrays
This commit is contained in:
@@ -369,11 +369,7 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
|
||||
assemblyElements = []
|
||||
|
||||
# if ifctype == "IfcArray":
|
||||
# FIXME: the first array element is not placed correct if the array is not on coordinate origin
|
||||
# https://forum.freecad.org/viewtopic.php?f=39&t=50085&p=431476#p431476
|
||||
# workaround: do not use the assembly in ifc but a normal compound instead
|
||||
if False:
|
||||
if ifctype == "IfcArray":
|
||||
clonedeltas = []
|
||||
if obj.ArrayType == "ortho":
|
||||
for i in range(obj.NumberX):
|
||||
@@ -384,8 +380,6 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
for k in range(obj.NumberZ):
|
||||
if k > 0:
|
||||
clonedeltas.append(obj.Placement.Base+(i*obj.IntervalX)+(j*obj.IntervalY)+(k*obj.IntervalZ))
|
||||
|
||||
#print("clonedeltas:",clonedeltas)
|
||||
if clonedeltas:
|
||||
ifctype = "IfcElementAssembly"
|
||||
for delta in clonedeltas:
|
||||
@@ -412,12 +406,14 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
preferences
|
||||
)
|
||||
assemblyElements.append(subproduct)
|
||||
# if an array was handled assemblyElements is not empty
|
||||
# if assemblyElements is not empty later on
|
||||
# the own Shape is ignored if representation is retrieved
|
||||
# this because we will build an assembly for the assemblyElements
|
||||
# from here and the assembly itself should not have a representation
|
||||
if ifctype in ["IfcApp::Part","IfcPart::Compound","IfcElementAssembly"]:
|
||||
exportIFCHelper.writeQuantities(ifcfile,
|
||||
obj.Base,
|
||||
subproduct,
|
||||
history,
|
||||
preferences['SCALE_FACTOR']
|
||||
)
|
||||
|
||||
elif ifctype in ["IfcApp::Part","IfcPart::Compound","IfcElementAssembly"]:
|
||||
if hasattr(obj,"Group"):
|
||||
group = obj.Group
|
||||
elif hasattr(obj,"Links"):
|
||||
@@ -751,7 +747,9 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
#if preferences['DEBUG'] : print(" adding ifc attributes")
|
||||
props = []
|
||||
for key in obj.IfcData:
|
||||
if not (key in ["attributes", "complex_attributes", "IfcUID", "FlagForceBrep"]):
|
||||
if not (key in ["attributes", "complex_attributes", "IfcUID", "FlagForceBrep",
|
||||
"ExportHeight", "ExportWidth", "ExportLength", "ExportHorizontalArea",
|
||||
"ExportVerticalArea", "ExportVolume"]):
|
||||
|
||||
# (deprecated) properties in IfcData dict are stored as "key":"type(value)"
|
||||
|
||||
@@ -800,35 +798,7 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
|
||||
# Quantities
|
||||
|
||||
if hasattr(obj,"IfcData"):
|
||||
quantities = []
|
||||
if ("ExportHeight" in obj.IfcData) and obj.IfcData["ExportHeight"] and hasattr(obj,"Height"):
|
||||
quantities.append(ifcfile.createIfcQuantityLength('Height',None,None,obj.Height.Value*preferences['SCALE_FACTOR']))
|
||||
if ("ExportWidth" in obj.IfcData) and obj.IfcData["ExportWidth"] and hasattr(obj,"Width"):
|
||||
quantities.append(ifcfile.createIfcQuantityLength('Width',None,None,obj.Width.Value*preferences['SCALE_FACTOR']))
|
||||
if ("ExportLength" in obj.IfcData) and obj.IfcData["ExportLength"] and hasattr(obj,"Length"):
|
||||
quantities.append(ifcfile.createIfcQuantityLength('Length',None,None,obj.Length.Value*preferences['SCALE_FACTOR']))
|
||||
if ("ExportHorizontalArea" in obj.IfcData) and obj.IfcData["ExportHorizontalArea"] and hasattr(obj,"HorizontalArea"):
|
||||
quantities.append(ifcfile.createIfcQuantityArea('HorizontalArea',None,None,obj.HorizontalArea.Value*(preferences['SCALE_FACTOR']**2)))
|
||||
if ("ExportVerticalArea" in obj.IfcData) and obj.IfcData["ExportVerticalArea"] and hasattr(obj,"VerticalArea"):
|
||||
quantities.append(ifcfile.createIfcQuantityArea('VerticalArea',None,None,obj.VerticalArea.Value*(preferences['SCALE_FACTOR']**2)))
|
||||
if ("ExportVolume" in obj.IfcData) and obj.IfcData["ExportVolume"] and obj.isDerivedFrom("Part::Feature"):
|
||||
quantities.append(ifcfile.createIfcQuantityVolume('Volume',None,None,obj.Shape.Volume*(preferences['SCALE_FACTOR']**3)))
|
||||
if quantities:
|
||||
eltq = ifcfile.createIfcElementQuantity(
|
||||
ifcopenshell.guid.new(),
|
||||
history,
|
||||
"ElementQuantities",
|
||||
None,
|
||||
"FreeCAD",quantities
|
||||
)
|
||||
ifcfile.createIfcRelDefinesByProperties(
|
||||
ifcopenshell.guid.new(),
|
||||
history,
|
||||
None,
|
||||
None,
|
||||
[product],eltq
|
||||
)
|
||||
exportIFCHelper.writeQuantities(ifcfile, obj, product, history, preferences['SCALE_FACTOR'])
|
||||
|
||||
if preferences['FULL_PARAMETRIC']:
|
||||
|
||||
@@ -2302,6 +2272,8 @@ def getRepresentation(
|
||||
gpl = ifcbin.createIfcAxis2Placement3D()
|
||||
repmap = ifcfile.createIfcRepresentationMap(gpl,subrep)
|
||||
pla = obj.getGlobalPlacement()
|
||||
if isinstance(forceclone,FreeCAD.Vector):
|
||||
pla.Base += forceclone
|
||||
axis1 = ifcbin.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(1,0,0))))
|
||||
axis2 = ifcbin.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(0,1,0))))
|
||||
origin = ifcbin.createIfcCartesianPoint(tuple(FreeCAD.Vector(pla.Base).multiply(preferences['SCALE_FACTOR'])))
|
||||
@@ -2371,7 +2343,7 @@ def getRepresentation(
|
||||
representation = [ifcfile.createIfcShapeRepresentation(context,'Body',solidType,shapes)]
|
||||
# additional representations?
|
||||
if Draft.getType(obj) in ["Wall","Structure"]:
|
||||
addrepr = createAxis(ifcfile,obj,preferences)
|
||||
addrepr = createAxis(ifcfile,obj,preferences, forceclone)
|
||||
if addrepr:
|
||||
representation = representation + [addrepr]
|
||||
productdef = ifcfile.createIfcProductDefinitionShape(None,None,representation)
|
||||
@@ -2476,12 +2448,15 @@ def getAxisContext(ifcfile):
|
||||
return nctx
|
||||
|
||||
|
||||
def createAxis(ifcfile,obj,preferences):
|
||||
def createAxis(ifcfile,obj,preferences, delta=None):
|
||||
"""Creates an axis for a given wall, if applicable"""
|
||||
|
||||
shape = None
|
||||
pla = FreeCAD.Placement(obj.Placement)
|
||||
if isinstance(delta,FreeCAD.Vector):
|
||||
pla.Base += delta
|
||||
if getattr(obj,"Nodes",None):
|
||||
shape = Part.makePolygon([obj.Placement.multVec(v) for v in obj.Nodes])
|
||||
shape = Part.makePolygon([pla.multVec(v) for v in obj.Nodes])
|
||||
elif hasattr(obj,"Base") and hasattr(obj.Base,"Shape") and obj.Base.Shape:
|
||||
shape = obj.Base.Shape
|
||||
if shape:
|
||||
|
||||
@@ -56,6 +56,40 @@ def writeUnits(ifcfile,unit="metre"):
|
||||
return ifcfile
|
||||
|
||||
|
||||
def writeQuantities(ifcfile, obj, product, history, scale):
|
||||
"append quantities to the given object"
|
||||
|
||||
if hasattr(obj,"IfcData"):
|
||||
quantities = []
|
||||
if ("ExportHeight" in obj.IfcData) and obj.IfcData["ExportHeight"] and hasattr(obj,"Height"):
|
||||
quantities.append(ifcfile.createIfcQuantityLength('Height',None,None,obj.Height.Value*scale))
|
||||
if ("ExportWidth" in obj.IfcData) and obj.IfcData["ExportWidth"] and hasattr(obj,"Width"):
|
||||
quantities.append(ifcfile.createIfcQuantityLength('Width',None,None,obj.Width.Value*scale))
|
||||
if ("ExportLength" in obj.IfcData) and obj.IfcData["ExportLength"] and hasattr(obj,"Length"):
|
||||
quantities.append(ifcfile.createIfcQuantityLength('Length',None,None,obj.Length.Value*scale))
|
||||
if ("ExportHorizontalArea" in obj.IfcData) and obj.IfcData["ExportHorizontalArea"] and hasattr(obj,"HorizontalArea"):
|
||||
quantities.append(ifcfile.createIfcQuantityArea('HorizontalArea',None,None,obj.HorizontalArea.Value*(scale**2)))
|
||||
if ("ExportVerticalArea" in obj.IfcData) and obj.IfcData["ExportVerticalArea"] and hasattr(obj,"VerticalArea"):
|
||||
quantities.append(ifcfile.createIfcQuantityArea('VerticalArea',None,None,obj.VerticalArea.Value*(scale**2)))
|
||||
if ("ExportVolume" in obj.IfcData) and obj.IfcData["ExportVolume"] and obj.isDerivedFrom("Part::Feature"):
|
||||
quantities.append(ifcfile.createIfcQuantityVolume('Volume',None,None,obj.Shape.Volume*(scale**3)))
|
||||
if quantities:
|
||||
eltq = ifcfile.createIfcElementQuantity(
|
||||
ifcopenshell.guid.new(),
|
||||
history,
|
||||
"ElementQuantities",
|
||||
None,
|
||||
"FreeCAD",quantities
|
||||
)
|
||||
ifcfile.createIfcRelDefinesByProperties(
|
||||
ifcopenshell.guid.new(),
|
||||
history,
|
||||
None,
|
||||
None,
|
||||
[product],eltq
|
||||
)
|
||||
|
||||
|
||||
class SIUnitCreator:
|
||||
def __init__(self, file, text, type):
|
||||
self.prefixes = [
|
||||
|
||||
Reference in New Issue
Block a user