Skip to content

Commit

Permalink
Arch: IFC import, only merge materials if they have same name and color
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach committed Aug 7, 2019
1 parent 7c48ad7 commit ad8a816
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Arch/Resources/ui/preferences-ifc.ui
Expand Up @@ -275,11 +275,11 @@ Note that this might slow things down.</string>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_3">
<property name="toolTip">
<string>If several materials with the same name are found in the IFC file,
<string>If several materials with the same name and color are found in the IFC file,
they will be treated as one.</string>
</property>
<property name="text">
<string>Merge materials with same name</string>
<string>Merge materials with same name and same color</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ifcMergeMaterials</cstring>
Expand Down
33 changes: 22 additions & 11 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -1203,26 +1203,37 @@ def insert(filename,docname,skip=[],only=[],root=None):
#print("materials:",materials)
fcmats = {}
for material in materials:
# get and set material name
name = "Material"
if material.Name:
name = material.Name
if six.PY2:
name = name.encode("utf8")
if MERGE_MATERIALS and (name in fcmats.keys()):
mat = fcmats[name]
# get material color
mdict = {}
if material.id() in colors:
mdict["DiffuseColor"] = str(colors[material.id()])
else:
for o,m in mattable.items():
if m == material.id():
if o in colors:
mdict["DiffuseColor"] = str(colors[o])
# merge materials with same name and color if setting in prefs is True
add_material = True
if MERGE_MATERIALS:
for key in list(fcmats.keys()):
if key.startswith(name) \
and "DiffuseColor" in mdict and "DiffuseColor" in fcmats[key].Material \
and mdict["DiffuseColor"] == fcmats[key].Material["DiffuseColor"]:
mat = fcmats[key]
add_material = False
# add a new material object
if add_material is True:
mat = Arch.makeMaterial(name=name)
mdict = {}
if material.id() in colors:
mdict["DiffuseColor"] = str(colors[material.id()])
else:
for o,m in mattable.items():
if m == material.id():
if o in colors:
mdict["DiffuseColor"] = str(colors[o])
if mdict:
mat.Material = mdict
fcmats[name] = mat
fcmats[mat.Name] = mat
# fill material attribut of the objects
for o,m in mattable.items():
if m == material.id():
if o in objects:
Expand Down

0 comments on commit ad8a816

Please sign in to comment.