BIM: Support for property sets in Native IFC (#18067)

* BIM: UI to add properties and psets to IFC objects

* BIM: Support native IFC objects in BimProperties

* BIM: Support removing IFC properties

* BIM: Fixed lint issues
This commit is contained in:
Yorik van Havre
2024-12-03 16:08:27 +01:00
committed by GitHub
parent 6a92b77632
commit 41ca58bf7c
11 changed files with 869 additions and 91 deletions

View File

@@ -745,6 +745,21 @@ def set_attribute(ifcfile, element, attribute, value):
# This function can become pure IFC
def differs(val1, val2):
if val1 == val2:
return False
if not val1 and not val2:
return False
if val1 is None and "NOTDEFINED" in str(val2).upper():
return False
if val1 is None and "UNDEFINED" in str(val2).upper():
return False
if val2 is None and "NOTDEFINED" in str(val1).upper():
return False
if val2 is None and "UNDEFINED" in str(val1).upper():
return False
return True
if not ifcfile or not element:
return False
if isinstance(value, FreeCAD.Units.Quantity):
@@ -774,7 +789,7 @@ def set_attribute(ifcfile, element, attribute, value):
):
# do not consider default FreeCAD names given to unnamed alements
return False
if getattr(element, attribute) != value:
if differs(getattr(element, attribute, None),value):
FreeCAD.Console.PrintLog(
"Changing IFC attribute value of "
+ str(attribute)
@@ -802,22 +817,25 @@ def set_colors(obj, colors):
else:
colors = [abs(c) for c in colors]
if hasattr(vobj, "ShapeColor"):
if isinstance(colors[0], (tuple, list)):
vobj.ShapeColor = colors[0][:3]
# do not set transparency when the object has more than one color
#if len(colors[0]) > 3:
# vobj.Transparency = int(colors[0][3] * 100)
else:
vobj.ShapeColor = colors[:3]
if len(colors) > 3:
vobj.Transparency = int(colors[3] * 100)
if hasattr(vobj, "DiffuseColor"):
# strip out transparency value because it currently gives ugly
# results in FreeCAD when combining transparent and non-transparent objects
if all([len(c) > 3 and c[3] != 0 for c in colors]):
vobj.DiffuseColor = colors
else:
vobj.DiffuseColor = [c[:3] for c in colors]
# 1.0 materials
if not isinstance(colors[0], (tuple, list)):
colors = [colors]
# set the first color to opaque otherwise it spoils object transparency
if len(colors) > 1:
#colors[0] = colors[0][:3] + (0.0,)
# TEMP HACK: if multiple colors, set everything to opaque because it looks wrong
colors = [color[:3] + (0.0,) for color in colors]
sapp = []
for color in colors:
sapp_mat = FreeCAD.Material()
if len(color) < 4:
sapp_mat.DiffuseColor = color + (1.0,)
else:
sapp_mat.DiffuseColor = color[:3] + (1.0 - color[3],)
sapp_mat.Transparency = color[3] if len(color) > 3 else 0.0
sapp.append(sapp_mat)
#print(vobj.Object.Label,[[m.DiffuseColor,m.Transparency] for m in sapp])
vobj.ShapeAppearance = sapp
def get_body_context_ids(ifcfile):