mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
New UI to manage material psets instead of needing to use CSVs
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
MassDensity,7.8
|
|
||||||
|
@@ -1,2 +0,0 @@
|
|||||||
YoungModulus,210000000
|
|
||||||
PoissonRatio,0.2
|
|
||||||
|
@@ -43,6 +43,7 @@ class IfcParser:
|
|||||||
self.people = []
|
self.people = []
|
||||||
self.organisations = []
|
self.organisations = []
|
||||||
self.psets = {}
|
self.psets = {}
|
||||||
|
self.material_psets = {}
|
||||||
self.document_references = {}
|
self.document_references = {}
|
||||||
self.classifications = []
|
self.classifications = []
|
||||||
self.classification_references = {}
|
self.classification_references = {}
|
||||||
@@ -100,7 +101,6 @@ class IfcParser:
|
|||||||
selected_objects = self.add_spatial_elements_if_unselected(selected_objects)
|
selected_objects = self.add_spatial_elements_if_unselected(selected_objects)
|
||||||
self.add_type_elements_if_unselected(selected_objects)
|
self.add_type_elements_if_unselected(selected_objects)
|
||||||
self.categorise_selected_objects(selected_objects)
|
self.categorise_selected_objects(selected_objects)
|
||||||
self.material_psets = self.get_material_psets()
|
|
||||||
self.document_information = self.get_document_information()
|
self.document_information = self.get_document_information()
|
||||||
self.document_references = self.get_document_references()
|
self.document_references = self.get_document_references()
|
||||||
self.classifications = self.get_classifications()
|
self.classifications = self.get_classifications()
|
||||||
@@ -458,6 +458,16 @@ class IfcParser:
|
|||||||
results[item_key] = {"ifc": None, "raw": raw, "attributes": {"Name": item.name}}
|
results[item_key] = {"ifc": None, "raw": raw, "attributes": {"Name": item.name}}
|
||||||
relationships.setdefault(item_key, []).append(product)
|
relationships.setdefault(item_key, []).append(product)
|
||||||
|
|
||||||
|
def get_material_psets(self, material, obj):
|
||||||
|
psets = obj.BIMMaterialProperties.psets
|
||||||
|
results = self.material_psets
|
||||||
|
for item in psets:
|
||||||
|
item_key = "{}/{}".format(item.name, obj.name)
|
||||||
|
raw = {p.name: p.string_value for p in item.properties if p.string_value}
|
||||||
|
if not raw:
|
||||||
|
continue
|
||||||
|
results[item_key] = {"ifc": None, "raw": raw, "material": material, "attributes": {"Name": item.name}}
|
||||||
|
|
||||||
def add_automatic_qtos(self, ifc_class, obj):
|
def add_automatic_qtos(self, ifc_class, obj):
|
||||||
if not obj.data:
|
if not obj.data:
|
||||||
return
|
return
|
||||||
@@ -583,21 +593,6 @@ class IfcParser:
|
|||||||
elif not self.is_a_library(self.get_ifc_class(obj.users_collection[0].name)):
|
elif not self.is_a_library(self.get_ifc_class(obj.users_collection[0].name)):
|
||||||
self.selected_products.append({"raw": obj, "metadata": metadata})
|
self.selected_products.append({"raw": obj, "metadata": metadata})
|
||||||
|
|
||||||
def get_material_psets(self):
|
|
||||||
psets = {}
|
|
||||||
for filename in Path(self.data_dir + "material/").glob("**/*.csv"):
|
|
||||||
with open(filename, "r") as f:
|
|
||||||
description = filename.parts[-2]
|
|
||||||
name = filename.stem
|
|
||||||
if description not in psets:
|
|
||||||
psets[description] = {}
|
|
||||||
psets[description][name] = {
|
|
||||||
"ifc": None,
|
|
||||||
"raw": {x[0]: x[1] for x in list(csv.reader(f))},
|
|
||||||
"attributes": {"Name": name, "Description": description},
|
|
||||||
}
|
|
||||||
return psets
|
|
||||||
|
|
||||||
def get_door_attributes(self):
|
def get_door_attributes(self):
|
||||||
return self.get_predefined_attributes("door")
|
return self.get_predefined_attributes("door")
|
||||||
|
|
||||||
@@ -1151,11 +1146,13 @@ class IfcParser:
|
|||||||
continue
|
continue
|
||||||
if slot.material.name in results or slot.link == "OBJECT":
|
if slot.material.name in results or slot.link == "OBJECT":
|
||||||
continue
|
continue
|
||||||
results[slot.material.name] = {
|
material = {
|
||||||
"ifc": None,
|
"ifc": None,
|
||||||
"raw": slot.material,
|
"raw": slot.material,
|
||||||
"attributes": self.get_material_attributes(slot.material),
|
"attributes": self.get_material_attributes(slot.material),
|
||||||
}
|
}
|
||||||
|
results[slot.material.name] = material
|
||||||
|
self.get_material_psets(material, slot.material)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def get_material_attributes(self, material):
|
def get_material_attributes(self, material):
|
||||||
@@ -1648,17 +1645,13 @@ class IfcExporter:
|
|||||||
pset["ifc"] = self.file.create_entity("IfcPropertySet", **pset["attributes"])
|
pset["ifc"] = self.file.create_entity("IfcPropertySet", **pset["attributes"])
|
||||||
|
|
||||||
def create_material_psets(self, material):
|
def create_material_psets(self, material):
|
||||||
for pset_dir in material["raw"].BIMMaterialProperties.psets:
|
for pset in self.ifc_parser.material_psets.values():
|
||||||
for name, properties in self.ifc_parser.material_psets[pset_dir.name].items():
|
properties = self.create_pset_properties(pset)
|
||||||
self.file.create_entity(
|
if not properties:
|
||||||
"IfcMaterialProperties",
|
continue
|
||||||
**{
|
pset["attributes"].update({"Properties": properties, "Material": pset["material"]["ifc"]})
|
||||||
"Name": name,
|
print(pset["attributes"])
|
||||||
"Description": pset_dir.name,
|
pset["ifc"] = self.file.create_entity("IfcMaterialProperties", **pset["attributes"])
|
||||||
"Properties": self.create_pset_properties(properties),
|
|
||||||
"Material": material["ifc"],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_qto_properties(self, qto):
|
def create_qto_properties(self, qto):
|
||||||
if qto["attributes"]["Name"] in ifcopenshell.util.pset.qtos:
|
if qto["attributes"]["Name"] in ifcopenshell.util.pset.qtos:
|
||||||
|
|||||||
@@ -943,8 +943,17 @@ class AddMaterialPset(bpy.types.Operator):
|
|||||||
bl_label = "Add Material Pset"
|
bl_label = "Add Material Pset"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
pset = bpy.context.active_object.active_material.BIMMaterialProperties.psets.add()
|
material = bpy.context.active_object.active_material
|
||||||
pset.name = bpy.context.active_object.active_material.BIMMaterialProperties.available_material_psets
|
name = material.BIMMaterialProperties.pset_name
|
||||||
|
if name not in ifcopenshell.util.pset.psets:
|
||||||
|
return {"FINISHED"}
|
||||||
|
if material.BIMMaterialProperties.psets.find(name) != -1:
|
||||||
|
return {"FINISHED"}
|
||||||
|
pset = material.BIMMaterialProperties.psets.add()
|
||||||
|
pset.name = name
|
||||||
|
for prop_name in ifcopenshell.util.pset.psets[name]["HasPropertyTemplates"].keys():
|
||||||
|
prop = pset.properties.add()
|
||||||
|
prop.name = prop_name
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ ifcpatchrecipes_enum = []
|
|||||||
featuresfiles_enum = []
|
featuresfiles_enum = []
|
||||||
titleblocks_enum = []
|
titleblocks_enum = []
|
||||||
scenarios_enum = []
|
scenarios_enum = []
|
||||||
psetnames_enum = []
|
materialpsetnames_enum = []
|
||||||
psetfiles_enum = []
|
psetfiles_enum = []
|
||||||
psettemplatefiles_enum = []
|
psettemplatefiles_enum = []
|
||||||
propertysettemplates_enum = []
|
propertysettemplates_enum = []
|
||||||
@@ -312,15 +312,6 @@ def getOrganisations(self, context):
|
|||||||
return organisations_enum
|
return organisations_enum
|
||||||
|
|
||||||
|
|
||||||
def getAvailableMaterialPsets(self, context):
|
|
||||||
global availablematerialpsets_enum
|
|
||||||
if len(availablematerialpsets_enum) < 1:
|
|
||||||
availablematerialpsets_enum.clear()
|
|
||||||
files = os.listdir(os.path.join(context.scene.BIMProperties.data_dir, "material"))
|
|
||||||
availablematerialpsets_enum.extend([(f, f, "") for f in files])
|
|
||||||
return availablematerialpsets_enum
|
|
||||||
|
|
||||||
|
|
||||||
def getIfcPatchRecipes(self, context):
|
def getIfcPatchRecipes(self, context):
|
||||||
global ifcpatchrecipes_enum
|
global ifcpatchrecipes_enum
|
||||||
if len(ifcpatchrecipes_enum) < 1:
|
if len(ifcpatchrecipes_enum) < 1:
|
||||||
@@ -441,6 +432,16 @@ def getPsetNames(self, context):
|
|||||||
return psetnames_enum
|
return psetnames_enum
|
||||||
|
|
||||||
|
|
||||||
|
def getMaterialPsetNames(self, context):
|
||||||
|
global materialpsetnames_enum
|
||||||
|
materialpsetnames_enum.clear()
|
||||||
|
pset_names = ifcopenshell.util.pset.get_applicable_psetqtos(
|
||||||
|
bpy.context.scene.BIMProperties.export_schema, "IfcMaterial", is_pset=True
|
||||||
|
)
|
||||||
|
materialpsetnames_enum.extend([(p, p, "") for p in pset_names])
|
||||||
|
return materialpsetnames_enum
|
||||||
|
|
||||||
|
|
||||||
def getQtoNames(self, context):
|
def getQtoNames(self, context):
|
||||||
global qtonames_enum
|
global qtonames_enum
|
||||||
qtonames_enum.clear()
|
qtonames_enum.clear()
|
||||||
@@ -1693,7 +1694,7 @@ class BIMMaterialProperties(PropertyGroup):
|
|||||||
location: StringProperty(name="Location")
|
location: StringProperty(name="Location")
|
||||||
identification: StringProperty(name="Identification")
|
identification: StringProperty(name="Identification")
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
available_material_psets: EnumProperty(items=getAvailableMaterialPsets, name="Material Pset")
|
pset_name: EnumProperty(items=getMaterialPsetNames, name="Pset Name")
|
||||||
psets: CollectionProperty(name="Psets", type=PsetQto)
|
psets: CollectionProperty(name="Psets", type=PsetQto)
|
||||||
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
||||||
applicable_attributes: EnumProperty(items=getApplicableMaterialAttributes, name="Attribute Names")
|
applicable_attributes: EnumProperty(items=getApplicableMaterialAttributes, name="Attribute Names")
|
||||||
|
|||||||
@@ -849,25 +849,17 @@ class BIM_PT_material(Panel):
|
|||||||
|
|
||||||
layout.label(text="Property Sets:")
|
layout.label(text="Property Sets:")
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(props, "available_material_psets", text="")
|
row.prop(props, "pset_name", text="")
|
||||||
row.operator("bim.add_material_pset")
|
row.operator("bim.add_material_pset")
|
||||||
|
|
||||||
for index, pset in enumerate(props.psets):
|
for index, pset in enumerate(props.psets):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(pset, "name", text="")
|
row.prop(pset, "name", text="")
|
||||||
row.operator("bim.remove_material_pset", icon="X", text="").pset_index = index
|
row.operator("bim.remove_material_pset", icon="X", text="").pset_index = index
|
||||||
op = row.operator("bim.copy_property_to_selection", icon="COPYDOWN", text="")
|
|
||||||
for prop in pset.properties:
|
for prop in pset.properties:
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(prop, "name", text="")
|
row.prop(prop, "name", text="")
|
||||||
row.prop(prop, "string_value", text="")
|
row.prop(prop, "string_value", text="")
|
||||||
op = row.operator("bim.copy_property_to_selection", icon="COPYDOWN", text="")
|
|
||||||
op.pset_name = pset.name
|
|
||||||
op.prop_name = prop.name
|
|
||||||
op.prop_value = prop.string_value
|
|
||||||
|
|
||||||
row = layout.row()
|
|
||||||
row.prop(props, "psets", text="")
|
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_gis(Panel):
|
class BIM_PT_gis(Panel):
|
||||||
|
|||||||
Reference in New Issue
Block a user