Skip to content

Commit

Permalink
Arch: import IFC, Materials, make merge materials working on duplicat…
Browse files Browse the repository at this point in the history
…e label setting
  • Loading branch information
berndhahnebach committed Oct 28, 2021
1 parent 226e0ad commit 5e2bb15
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -1261,7 +1261,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
# print(material.id())

mdict = {}
# on ifc import only the "DiffuseColor" of the material dictionary is initialized
# on ifc import only the "Description" and "DiffuseColor" (if it was read) of the material dictionary will be initialized
# on editing material in Arch Gui a lot more keys of the material dictionary are initialized even with empty values
# TODO: there should be a generic material obj init method which will be used by Arch Gui, import IFC, FEM, etc

Expand All @@ -1271,7 +1271,10 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
name = material.Name
if six.PY2:
name = name.encode("utf8")
mdict["Name"] = name
# mdict["Name"] = name on duplicate material names in IFC this could result in crash
# https://forum.freecadweb.org/viewtopic.php?f=23&t=63260
# thus use "Description"
mdict["Description"] = name

# get material color
# the "DiffuseColor" of a material should never be "None"
Expand All @@ -1295,16 +1298,16 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
if preferences["MERGE_MATERIALS"]:
for added_mat in added_mats:
if (
# added_mat.Material["Name"] == name
# above does not work because FreeCAD would crash in some circumstances
# https://forum.freecadweb.org/viewtopic.php?f=23&t=63260
added_mat.Label == name
and ("DiffuseColor" in mdict and "DiffuseColor" in added_mat.Material)
and mdict["DiffuseColor"] == added_mat.Material["DiffuseColor"]
"Description" in added_mat.Material
and "DiffuseColor" in added_mat.Material
and "DiffuseColor" in mdict # Description has been set thus it is in mdict
and added_mat.Material["Description"] == mdict["Description"]
and added_mat.Material["DiffuseColor"] == mdict["DiffuseColor"]
):
matobj = added_mat
add_material = False
break

# add a new material object
if add_material is True:
matobj = Arch.makeMaterial(name=name)
Expand Down

0 comments on commit 5e2bb15

Please sign in to comment.