mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Deprecate CSV-based pset assignment
This commit is contained in:
@@ -47,12 +47,8 @@ if bpy is not None:
|
||||
operator.SelectSweptSolidInnerCurves,
|
||||
operator.AssignSweptSolidExtrusion,
|
||||
operator.SelectSweptSolidExtrusion,
|
||||
operator.AssignPset,
|
||||
operator.UnassignPset,
|
||||
operator.AddPset,
|
||||
operator.RemovePset,
|
||||
operator.AddOverridePset,
|
||||
operator.RemoveOverridePset,
|
||||
operator.AddQto,
|
||||
operator.RemoveQto,
|
||||
operator.AddMaterialPset,
|
||||
|
||||
@@ -136,7 +136,6 @@ class IfcParser():
|
||||
self.organisations = self.get_organisations()
|
||||
unique_objects = self.add_spatial_elements_if_unselected(selected_objects)
|
||||
self.categorise_selected_objects(unique_objects)
|
||||
self.psets = self.get_psets()
|
||||
self.material_psets = self.get_material_psets()
|
||||
self.documents = self.get_documents()
|
||||
self.classifications = self.get_classifications()
|
||||
@@ -450,10 +449,6 @@ class IfcParser():
|
||||
if obj.name in self.qtos:
|
||||
self.rel_defines_by_qto.setdefault(obj.name, []).append(product)
|
||||
|
||||
for pset in obj.BIMObjectProperties.psets:
|
||||
self.rel_defines_by_pset.setdefault(
|
||||
'{}/{}'.format(pset.name, pset.file), []).append(product)
|
||||
|
||||
self.get_product_psets_qtos(product, obj, is_pset=True)
|
||||
self.get_product_psets_qtos(product, obj, is_qto=True)
|
||||
|
||||
@@ -489,7 +484,7 @@ class IfcParser():
|
||||
|
||||
def get_product_psets_qtos(self, product, obj, is_pset=False, is_qto=False):
|
||||
if is_pset:
|
||||
psets_qtos = obj.BIMObjectProperties.override_psets
|
||||
psets_qtos = obj.BIMObjectProperties.psets
|
||||
results = self.psets
|
||||
relationships = self.rel_defines_by_pset
|
||||
if is_qto:
|
||||
@@ -582,21 +577,6 @@ class IfcParser():
|
||||
elif not self.is_a_library(self.get_ifc_class(obj.users_collection[0].name)):
|
||||
self.selected_products.append({'raw': obj, 'metadata': metadata})
|
||||
|
||||
def get_psets(self):
|
||||
psets = {}
|
||||
for filename in Path(self.data_dir + 'pset/').glob('**/*.csv'):
|
||||
with open(filename, 'r') as f:
|
||||
name = filename.parts[-2]
|
||||
description = filename.stem
|
||||
psets['{}/{}'.format(name, description)] = {
|
||||
'ifc': None,
|
||||
'raw': {x[0]: x[1] for x in list(csv.reader(f))},
|
||||
'attributes': {
|
||||
'Name': name,
|
||||
'Description': description}
|
||||
}
|
||||
return psets
|
||||
|
||||
def get_material_psets(self):
|
||||
psets = {}
|
||||
for filename in Path(self.data_dir + 'material/').glob('**/*.csv'):
|
||||
|
||||
@@ -554,7 +554,7 @@ class IfcImporter():
|
||||
self.add_pset(definition, obj)
|
||||
|
||||
def add_pset(self, pset, obj):
|
||||
new_pset = obj.BIMObjectProperties.override_psets.add()
|
||||
new_pset = obj.BIMObjectProperties.psets.add()
|
||||
new_pset.name = pset.Name
|
||||
if new_pset.name in schema.ifc.psets:
|
||||
for prop_name in schema.ifc.psets[new_pset.name]['HasPropertyTemplates'].keys():
|
||||
|
||||
@@ -150,13 +150,13 @@ class SelectPset(bpy.types.Operator):
|
||||
search_prop_name = bpy.context.scene.BIMProperties.search_prop_name
|
||||
search_value = bpy.context.scene.BIMProperties.search_pset_value
|
||||
for object in bpy.context.visible_objects:
|
||||
pset_index = object.BIMObjectProperties.override_psets.find(search_pset_name)
|
||||
pset_index = object.BIMObjectProperties.psets.find(search_pset_name)
|
||||
if pset_index == -1:
|
||||
continue
|
||||
prop_index = object.BIMObjectProperties.override_psets[pset_index].properties.find(search_prop_name)
|
||||
prop_index = object.BIMObjectProperties.psets[pset_index].properties.find(search_prop_name)
|
||||
if prop_index == -1:
|
||||
continue
|
||||
value = object.BIMObjectProperties.override_psets[pset_index].properties[prop_index].string_value
|
||||
value = object.BIMObjectProperties.psets[pset_index].properties[prop_index].string_value
|
||||
if bpy.context.scene.BIMProperties.search_regex \
|
||||
and bpy.context.scene.BIMProperties.search_ignorecase \
|
||||
and re.search(search_value, value, flags=re.IGNORECASE):
|
||||
@@ -282,13 +282,13 @@ class ColourByPset(bpy.types.Operator):
|
||||
search_pset_name = bpy.context.scene.BIMProperties.search_pset_name
|
||||
search_prop_name = bpy.context.scene.BIMProperties.search_prop_name
|
||||
for obj in bpy.context.visible_objects:
|
||||
pset_index = obj.BIMObjectProperties.override_psets.find(search_pset_name)
|
||||
pset_index = obj.BIMObjectProperties.psets.find(search_pset_name)
|
||||
if pset_index == -1:
|
||||
continue
|
||||
prop_index = obj.BIMObjectProperties.override_psets[pset_index].properties.find(search_prop_name)
|
||||
prop_index = obj.BIMObjectProperties.psets[pset_index].properties.find(search_prop_name)
|
||||
if prop_index == -1:
|
||||
continue
|
||||
value = obj.BIMObjectProperties.override_psets[pset_index].properties[prop_index].string_value
|
||||
value = obj.BIMObjectProperties.psets[pset_index].properties[prop_index].string_value
|
||||
if value not in values:
|
||||
values[value] = next(colours)
|
||||
obj.color = values[value]
|
||||
@@ -638,52 +638,6 @@ class QuickProjectSetup(bpy.types.Operator):
|
||||
building_storey.objects.link(building_storey_obj)
|
||||
return {'FINISHED'}
|
||||
|
||||
class AssignPset(bpy.types.Operator):
|
||||
bl_idname = 'bim.assign_pset'
|
||||
bl_label = 'Assign Pset'
|
||||
|
||||
def execute(self, context):
|
||||
for object in bpy.context.selected_objects:
|
||||
index = object.BIMObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name)
|
||||
if index >= 0:
|
||||
pset = object.BIMObjectProperties.psets[index]
|
||||
else:
|
||||
pset = object.BIMObjectProperties.psets.add()
|
||||
pset.name = bpy.context.scene.BIMProperties.pset_name
|
||||
pset.file = bpy.context.scene.BIMProperties.pset_file
|
||||
return {'FINISHED'}
|
||||
|
||||
class UnassignPset(bpy.types.Operator):
|
||||
bl_idname = 'bim.unassign_pset'
|
||||
bl_label = 'Unassign Pset'
|
||||
|
||||
def execute(self, context):
|
||||
for object in bpy.context.selected_objects:
|
||||
index = object.BIMObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name)
|
||||
if index != -1:
|
||||
object.BIMObjectProperties.psets.remove(index)
|
||||
return {'FINISHED'}
|
||||
|
||||
class AddPset(bpy.types.Operator):
|
||||
bl_idname = 'bim.add_pset'
|
||||
bl_label = 'Add Pset'
|
||||
|
||||
def execute(self, context):
|
||||
pset = bpy.context.active_object.BIMObjectProperties.psets.add()
|
||||
pset.name = bpy.context.scene.BIMProperties.pset_name
|
||||
pset.file = bpy.context.scene.BIMProperties.pset_file
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class RemovePset(bpy.types.Operator):
|
||||
bl_idname = 'bim.remove_pset'
|
||||
bl_label = 'Remove Pset'
|
||||
pset_index: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
bpy.context.active_object.BIMObjectProperties.psets.remove(self.pset_index)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class AddQto(bpy.types.Operator):
|
||||
bl_idname = 'bim.add_qto'
|
||||
@@ -701,15 +655,15 @@ class AddQto(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class AddOverridePset(bpy.types.Operator):
|
||||
bl_idname = 'bim.add_override_pset'
|
||||
bl_label = 'Add Override Pset'
|
||||
class AddPset(bpy.types.Operator):
|
||||
bl_idname = 'bim.add_pset'
|
||||
bl_label = 'Add Pset'
|
||||
|
||||
def execute(self, context):
|
||||
pset_name = bpy.context.active_object.BIMObjectProperties.override_pset_name
|
||||
pset_name = bpy.context.active_object.BIMObjectProperties.pset_name
|
||||
if pset_name not in schema.ifc.psets:
|
||||
return {'FINISHED'}
|
||||
pset = bpy.context.active_object.BIMObjectProperties.override_psets.add()
|
||||
pset = bpy.context.active_object.BIMObjectProperties.psets.add()
|
||||
pset.name = pset_name
|
||||
for prop_name in schema.ifc.psets[pset_name]['HasPropertyTemplates'].keys():
|
||||
prop = pset.properties.add()
|
||||
@@ -717,13 +671,13 @@ class AddOverridePset(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class RemoveOverridePset(bpy.types.Operator):
|
||||
bl_idname = 'bim.remove_override_pset'
|
||||
bl_label = 'Remove Override Pset'
|
||||
class RemovePset(bpy.types.Operator):
|
||||
bl_idname = 'bim.remove_pset'
|
||||
bl_label = 'Remove Pset'
|
||||
pset_index: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
bpy.context.active_object.BIMObjectProperties.override_psets.remove(self.pset_index)
|
||||
bpy.context.active_object.BIMObjectProperties.psets.remove(self.pset_index)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ psettemplatefiles_enum = []
|
||||
propertysettemplates_enum = []
|
||||
classification_enum = []
|
||||
attributes_enum = []
|
||||
overridepsetnames_enum = []
|
||||
psetnames_enum = []
|
||||
qtonames_enum = []
|
||||
materialattributes_enum = []
|
||||
documents_enum = []
|
||||
@@ -209,26 +209,6 @@ def refreshScenarios(self, context):
|
||||
getScenarios(self, context)
|
||||
|
||||
|
||||
def getPsetNames(self, context):
|
||||
global psetnames_enum
|
||||
if len(psetnames_enum) < 1:
|
||||
psetnames_enum.clear()
|
||||
files = os.listdir(os.path.join(self.data_dir, 'pset'))
|
||||
psetnames_enum.extend([(f, f, '') for f in files])
|
||||
return psetnames_enum
|
||||
|
||||
|
||||
def refreshPsetFiles(self, context):
|
||||
global psetfiles_enum
|
||||
psetfiles_enum.clear()
|
||||
getPsetFiles(self, context)
|
||||
|
||||
|
||||
def getPsetFiles(self, context):
|
||||
global psetfiles_enum
|
||||
return psetfiles_enum
|
||||
|
||||
|
||||
def getPsetTemplateFiles(self, context):
|
||||
global psettemplatefiles_enum
|
||||
if len(psettemplatefiles_enum) < 1:
|
||||
@@ -269,17 +249,17 @@ def refreshReferences(self, context):
|
||||
context.scene.BIMProperties.classification_references.root = ''
|
||||
|
||||
|
||||
def getOverridePsetNames(self, context):
|
||||
global overridepsetnames_enum
|
||||
overridepsetnames_enum.clear()
|
||||
def getPsetNames(self, context):
|
||||
global psetnames_enum
|
||||
psetnames_enum.clear()
|
||||
if '/' in context.active_object.name \
|
||||
and context.active_object.name.split('/')[0] in schema.ifc.elements:
|
||||
empty = ifcopenshell.file()
|
||||
element = empty.create_entity(context.active_object.name.split('/')[0])
|
||||
for ifc_class, pset_names in schema.ifc.applicable_psets.items():
|
||||
if element.is_a(ifc_class):
|
||||
overridepsetnames_enum.extend([(p, p, '') for p in pset_names])
|
||||
return overridepsetnames_enum
|
||||
psetnames_enum.extend([(p, p, '') for p in pset_names])
|
||||
return psetnames_enum
|
||||
|
||||
|
||||
def getQtoNames(self, context):
|
||||
@@ -837,8 +817,6 @@ class BIMProperties(PropertyGroup):
|
||||
qa_reject_element_reason: StringProperty(name="Element Rejection Reason")
|
||||
person: EnumProperty(items=getPersons, name="Person")
|
||||
organisation: EnumProperty(items=getOrganisations, name="Organisation")
|
||||
pset_name: EnumProperty(items=getPsetNames, name="Pset Name", update=refreshPsetFiles)
|
||||
pset_file: EnumProperty(items=getPsetFiles, name="Pset File")
|
||||
has_georeferencing: BoolProperty(name="Has Georeferencing", default=False)
|
||||
has_library: BoolProperty(name="Has Project Library", default=False)
|
||||
search_regex: BoolProperty(name="Search With Regex", default=False)
|
||||
@@ -966,8 +944,7 @@ class BIMObjectProperties(PropertyGroup):
|
||||
applicable_documents: EnumProperty(items=getApplicableDocuments, name="Available Documents")
|
||||
classifications: CollectionProperty(name="Classifications", type=ClassificationReference)
|
||||
material_type: EnumProperty(items=getMaterialTypes, name="Material Type")
|
||||
override_psets: CollectionProperty(name="Override Psets", type=PsetQto)
|
||||
override_pset_name: EnumProperty(items=getOverridePsetNames, name='Override Pset Name')
|
||||
pset_name: EnumProperty(items=getPsetNames, name='Pset Name')
|
||||
qto_name: EnumProperty(items=getQtoNames, name='Qto Name')
|
||||
has_boundary_condition: BoolProperty(name='Has Boundary Condition')
|
||||
boundary_condition: PointerProperty(name='Boundary Condition', type=BoundaryCondition)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import json
|
||||
import ifcopenshell
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
@@ -8,6 +9,7 @@ cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
class IfcSchema():
|
||||
def __init__(self):
|
||||
self.schema_dir = os.path.join(cwd, 'schema') # TODO: make configurable
|
||||
self.data_dir = os.path.join(cwd, 'data') # TODO: make configurable
|
||||
# TODO: Make it less troublesome
|
||||
self.products = [
|
||||
'IfcContext',
|
||||
@@ -23,9 +25,10 @@ class IfcSchema():
|
||||
self.elements = {}
|
||||
|
||||
self.property_files = []
|
||||
property_paths = Path(self.schema_dir).glob('Pset_*.ifc')
|
||||
property_paths = Path(os.path.join(self.data_dir, 'pset')).glob('*.ifc')
|
||||
for path in property_paths:
|
||||
self.property_files.append(ifcopenshell.open(path))
|
||||
self.property_files.append(ifcopenshell.open(os.path.join(self.schema_dir, 'Pset_IFC4_ADD2.ifc')))
|
||||
|
||||
self.classification_files = {}
|
||||
classification_paths = Path(self.schema_dir).glob('classifications/*.ifc')
|
||||
|
||||
@@ -47,36 +47,21 @@ class BIM_PT_object(Panel):
|
||||
row.prop(props, 'relating_structure')
|
||||
|
||||
layout.label(text="Property Sets:")
|
||||
row = layout.row()
|
||||
row.prop(context.scene.BIMProperties, "pset_name")
|
||||
row = layout.row()
|
||||
row.prop(context.scene.BIMProperties, "pset_file")
|
||||
row = layout.row()
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.prop(props, 'pset_name', text='')
|
||||
row.operator('bim.add_pset')
|
||||
|
||||
for index, pset in enumerate(props.psets):
|
||||
row = layout.row(align=True)
|
||||
row.prop(pset, 'name', text='')
|
||||
row.prop(pset, 'file', text='')
|
||||
row.operator('bim.remove_pset', icon='X', text='').pset_index = index
|
||||
|
||||
row = layout.row()
|
||||
row.prop(props, 'psets')
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.prop(props, 'override_pset_name', text='')
|
||||
row.operator('bim.add_override_pset')
|
||||
|
||||
for index, pset in enumerate(props.override_psets):
|
||||
row = layout.row(align=True)
|
||||
row.prop(pset, 'name', text='')
|
||||
row.operator('bim.remove_override_pset', icon='X', text='').pset_index = index
|
||||
for prop in pset.properties:
|
||||
row = layout.row(align=True)
|
||||
row.prop(prop, 'name', text='')
|
||||
row.prop(prop, 'string_value', text='')
|
||||
op = row.operator('bim.copy_attributes_to_selection', icon='COPYDOWN', text='')
|
||||
op.prop_base = 'BIMObjectProperties.override_psets[\'{}\'].properties'.format(pset.name)
|
||||
op.prop_base = 'BIMObjectProperties.psets[\'{}\'].properties'.format(pset.name)
|
||||
op.prop_name = prop.name
|
||||
op.collection_element = True
|
||||
|
||||
@@ -589,16 +574,6 @@ class BIM_PT_bim(Panel):
|
||||
row.operator("bim.select_class")
|
||||
row.operator("bim.select_type")
|
||||
|
||||
layout.label(text="Property Sets:")
|
||||
row = layout.row()
|
||||
row.prop(bim_properties, "pset_name")
|
||||
row = layout.row()
|
||||
row.prop(bim_properties, "pset_file")
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.operator("bim.assign_pset")
|
||||
row.operator("bim.unassign_pset")
|
||||
|
||||
layout.label(text="Aggregates:")
|
||||
row = layout.row()
|
||||
row.prop(bim_properties, "aggregate_class")
|
||||
|
||||
Reference in New Issue
Block a user