Arch: Enabled IFC4 export and fixed a couple of bugs

This commit is contained in:
Yorik van Havre 2016-02-10 15:35:21 -02:00
parent 381dcfe7e3
commit f942bf2729

View File

@ -69,7 +69,7 @@ ifctemplate = """ISO-10303-21;
HEADER; HEADER;
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1'); FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
FILE_NAME('$filename','$timestamp',('$owner','$email'),('$company'),'IfcOpenShell','IfcOpenShell',''); FILE_NAME('$filename','$timestamp',('$owner','$email'),('$company'),'IfcOpenShell','IfcOpenShell','');
FILE_SCHEMA(('IFC2X3')); FILE_SCHEMA(('$ifcschema'));
ENDSEC; ENDSEC;
DATA; DATA;
#1=IFCPERSON($,$,'$owner',$,$,$,$,$); #1=IFCPERSON($,$,'$owner',$,$,$,$,$);
@ -859,6 +859,7 @@ def export(exportList,filename):
email = s[1].strip(">") email = s[1].strip(">")
global template global template
template = ifctemplate.replace("$version",version[0]+"."+version[1]+" build "+version[2]) template = ifctemplate.replace("$version",version[0]+"."+version[1]+" build "+version[2])
template = template.replace("$ifcschema",ifcopenshell.schema_identifier)
template = template.replace("$owner",owner) template = template.replace("$owner",owner)
template = template.replace("$company",FreeCAD.ActiveDocument.Company) template = template.replace("$company",FreeCAD.ActiveDocument.Company)
template = template.replace("$email",email) template = template.replace("$email",email)
@ -979,9 +980,11 @@ def export(exportList,filename):
ifcfile.createIfcRelVoidsElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Subtraction','',product,prod2) ifcfile.createIfcRelVoidsElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Subtraction','',product,prod2)
# properties # properties
if hasattr(obj,"IfcProperties") or hasattr(obj,"IfcAttributes"): ifcprop = False
if DEBUG : print(" add ifc properties") if hasattr(obj,"IfcProperties"):
if obj.IfcProperties: if obj.IfcProperties:
ifcprop = True
if DEBUG : print(" adding ifc properties")
if obj.IfcProperties.TypeId == 'Spreadsheet::Sheet': if obj.IfcProperties.TypeId == 'Spreadsheet::Sheet':
sheet = obj.IfcProperties sheet = obj.IfcProperties
propertiesDic = {} propertiesDic = {}
@ -1033,7 +1036,10 @@ def export(exportList,filename):
props.append(ifcfile.createIfcPropertySingleValue(prop["key"],None,ifcfile.create_entity(prop["tp"],prop["val"]),None)) props.append(ifcfile.createIfcPropertySingleValue(prop["key"],None,ifcfile.create_entity(prop["tp"],prop["val"]),None))
pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,cat,None,props) pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,cat,None,props)
ifcfile.createIfcRelDefinesByProperties(ifcopenshell.guid.compress(uuid.uuid1().hex),history,None,None,[product],pset) ifcfile.createIfcRelDefinesByProperties(ifcopenshell.guid.compress(uuid.uuid1().hex),history,None,None,[product],pset)
elif obj.IfcAttributes: if (not ifcprop) and hasattr(obj,"IfcAttributes"):
if obj.IfcAttributes:
ifcprop = True
if DEBUG : print(" adding ifc attributes")
props = [] props = []
for key in obj.IfcAttributes: for key in obj.IfcAttributes:
if not (key in ["IfcUID","FlagForceBrep"]): if not (key in ["IfcUID","FlagForceBrep"]):
@ -1062,8 +1068,9 @@ def export(exportList,filename):
if props: if props:
pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'PropertySet',None,props) pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'PropertySet',None,props)
ifcfile.createIfcRelDefinesByProperties(ifcopenshell.guid.compress(uuid.uuid1().hex),history,None,None,[product],pset) ifcfile.createIfcRelDefinesByProperties(ifcopenshell.guid.compress(uuid.uuid1().hex),history,None,None,[product],pset)
else: if not ifcprop:
if DEBUG : print("no ifc properties to export") #if DEBUG : print("no ifc properties to export")
pass
count += 1 count += 1
@ -1103,8 +1110,14 @@ def export(exportList,filename):
for m in Arch.getDocumentMaterials(): for m in Arch.getDocumentMaterials():
mat = ifcfile.createIfcMaterial(m.Label.encode("utf8")) mat = ifcfile.createIfcMaterial(m.Label.encode("utf8"))
materials[m.Label] = mat materials[m.Label] = mat
if "Color" in m.Material: rgb = None
rgb = tuple([float(f) for f in m.Material['Color'].strip("()").split(",")]) for colorslot in ["Color","DiffuseColor","ViewColor"]:
if colorslot in m.Material:
if m.Material[colorslot]:
if m.Material[colorslot][0] == "(":
rgb = tuple([float(f) for f in m.Material[colorslot].strip("()").split(",")])
break
if rgb:
col = ifcfile.createIfcColourRgb(None,rgb[0],rgb[1],rgb[2]) col = ifcfile.createIfcColourRgb(None,rgb[0],rgb[1],rgb[2])
ssr = ifcfile.createIfcSurfaceStyleRendering(col,None,None,None,None,None,None,None,"FLAT") ssr = ifcfile.createIfcSurfaceStyleRendering(col,None,None,None,None,None,None,None,"FLAT")
iss = ifcfile.createIfcSurfaceStyle(None,"BOTH",[ssr]) iss = ifcfile.createIfcSurfaceStyle(None,"BOTH",[ssr])