Arch: import IFC, fix if imported in non Gui mode

This commit is contained in:
Bernd Hahnebach
2019-11-07 08:04:09 +01:00
parent 3921a22e8b
commit 0e7a705664

View File

@@ -1149,30 +1149,31 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
if m == material.id():
if o in objects:
if hasattr(objects[o],"Material"):
# the reason behind ...
# there are files around in which the material color is different from the shape color
# all viewers use the shape color whereas in FreeCAD the shape color will be
# overwritten by the material color (if there is a material with a color).
# In such a case FreeCAD shows a different color than all common ifc viewers
# https://forum.freecadweb.org/viewtopic.php?f=39&t=38440
col = objects[o].ViewObject.ShapeColor[:3]
dig = 5
ma_color = sh_color = round(col[0], dig), round(col[1], dig), round(col[2], dig)
objects[o].Material = mat
if "DiffuseColor" in objects[o].Material.Material:
sting_col_ = objects[o].Material.Material["DiffuseColor"]
col = tuple([float(f) for f in sting_col_.strip("()").split(",")])
ma_color = round(col[0], dig), round(col[1], dig), round(col[2], dig)
if ma_color != sh_color:
print("\nobject color != material color for object: ", o)
print(" material color is used (most software uses shape color)")
print(" obj: ", o, "label: ", objects[o].Label, " col: ", sh_color)
print(" mat: ", m, "label: ", mat.Label, " col: ", ma_color)
# print(" ", ifcfile[o])
# print(" ", ifcfile[m])
# print(" colors:")
# print(" ", o, ": ", colors[o])
# print(" ", m, ": ", colors[m])
if FreeCAD.GuiUp:
# the reason behind ...
# there are files around in which the material color is different from the shape color
# all viewers use the shape color whereas in FreeCAD the shape color will be
# overwritten by the material color (if there is a material with a color).
# In such a case FreeCAD shows a different color than all common ifc viewers
# https://forum.freecadweb.org/viewtopic.php?f=39&t=38440
col = objects[o].ViewObject.ShapeColor[:3]
dig = 5
ma_color = sh_color = round(col[0], dig), round(col[1], dig), round(col[2], dig)
if "DiffuseColor" in objects[o].Material.Material:
sting_col_ = objects[o].Material.Material["DiffuseColor"]
col = tuple([float(f) for f in sting_col_.strip("()").split(",")])
ma_color = round(col[0], dig), round(col[1], dig), round(col[2], dig)
if ma_color != sh_color:
print("\nobject color != material color for object: ", o)
print(" material color is used (most software uses shape color)")
print(" obj: ", o, "label: ", objects[o].Label, " col: ", sh_color)
print(" mat: ", m, "label: ", mat.Label, " col: ", ma_color)
# print(" ", ifcfile[o])
# print(" ", ifcfile[m])
# print(" colors:")
# print(" ", o, ": ", colors[o])
# print(" ", m, ": ", colors[m])
if preferences['DEBUG'] and materials: print("done")