mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 12:36:55 +00:00
Classification trees are now stored in the blend instead of an external file for portability. See #1036.
This commit is contained in:
@@ -185,7 +185,6 @@ if bpy is not None:
|
|||||||
operator.SaveDrawingStyle,
|
operator.SaveDrawingStyle,
|
||||||
operator.ActivateDrawingStyle,
|
operator.ActivateDrawingStyle,
|
||||||
operator.EditVectorStyle,
|
operator.EditVectorStyle,
|
||||||
operator.PurgeProjectClassifications,
|
|
||||||
operator.RemoveSheet,
|
operator.RemoveSheet,
|
||||||
operator.AddSchedule,
|
operator.AddSchedule,
|
||||||
operator.RemoveSchedule,
|
operator.RemoveSchedule,
|
||||||
|
|||||||
@@ -630,22 +630,23 @@ class IfcParser():
|
|||||||
def get_classifications(self):
|
def get_classifications(self):
|
||||||
results = {}
|
results = {}
|
||||||
for classification in bpy.context.scene.BIMProperties.classifications:
|
for classification in bpy.context.scene.BIMProperties.classifications:
|
||||||
schema.ifc.load_classification(classification.filename)
|
if classification.name not in schema.ifc.classification_files:
|
||||||
results[classification.filename] = {
|
schema.ifc.classification_files[classification.name] = ifcopenshell.file.from_string(classification.data)
|
||||||
|
results[classification.name] = {
|
||||||
'ifc': None,
|
'ifc': None,
|
||||||
'raw': classification,
|
'raw': classification,
|
||||||
'raw_element': schema.ifc.classification_files[classification.filename].by_type('IfcClassification')[0]
|
'raw_element': schema.ifc.classification_files[classification.name].by_type('IfcClassification')[0]
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def get_classification_reference_maps(self):
|
def get_classification_reference_maps(self):
|
||||||
results = {}
|
results = {}
|
||||||
for filename, classification in self.classifications.items():
|
for name, classification in self.classifications.items():
|
||||||
ifc_file = schema.ifc.classification_files[filename]
|
ifc_file = schema.ifc.classification_files[name]
|
||||||
if ifc_file.schema == 'IFC2X3':
|
if ifc_file.schema == 'IFC2X3':
|
||||||
results[filename] = { e.ItemReference: e for e in ifc_file.by_type('IfcClassificationReference')}
|
results[name] = { e.ItemReference: e for e in ifc_file.by_type('IfcClassificationReference')}
|
||||||
else:
|
else:
|
||||||
results[filename] = { e.Identification: e for e in ifc_file.by_type('IfcClassificationReference')}
|
results[name] = { e.Identification: e for e in ifc_file.by_type('IfcClassificationReference')}
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def get_classification_references(self):
|
def get_classification_references(self):
|
||||||
|
|||||||
@@ -1501,13 +1501,8 @@ class IfcImporter():
|
|||||||
for entity in entities_to_add:
|
for entity in entities_to_add:
|
||||||
classification_file.add(entity)
|
classification_file.add(entity)
|
||||||
|
|
||||||
classification_filename = '{}-{}'.format(
|
classification.data = classification_file.to_string()
|
||||||
Path(os.path.basename(self.ifc_import_settings.input_file)).stem, element.Name)
|
self.classifications[classification.name] = classification
|
||||||
classification_file.write(os.path.join(
|
|
||||||
bpy.context.scene.BIMProperties.schema_dir, 'project_classifications',
|
|
||||||
'{}.ifc'.format(classification_filename)))
|
|
||||||
classification.filename = classification_filename
|
|
||||||
self.classifications[classification.filename] = classification
|
|
||||||
|
|
||||||
self.schema_dir = bpy.context.scene.BIMProperties.schema_dir
|
self.schema_dir = bpy.context.scene.BIMProperties.schema_dir
|
||||||
from . import prop
|
from . import prop
|
||||||
@@ -1815,9 +1810,6 @@ class IfcImporter():
|
|||||||
def get_referenced_source_name(self, element):
|
def get_referenced_source_name(self, element):
|
||||||
if not hasattr(element, 'ReferencedSource') or not element.ReferencedSource:
|
if not hasattr(element, 'ReferencedSource') or not element.ReferencedSource:
|
||||||
if element.is_a('IfcClassification'):
|
if element.is_a('IfcClassification'):
|
||||||
for filename, classification in self.classifications.items():
|
|
||||||
if classification.name == element.Name:
|
|
||||||
return filename
|
|
||||||
return element.Name
|
return element.Name
|
||||||
else:
|
else:
|
||||||
return element.Identification
|
return element.Identification
|
||||||
|
|||||||
@@ -1922,11 +1922,18 @@ class ExplodeAggregate(bpy.types.Operator):
|
|||||||
class LoadClassification(bpy.types.Operator):
|
class LoadClassification(bpy.types.Operator):
|
||||||
bl_idname = 'bim.load_classification'
|
bl_idname = 'bim.load_classification'
|
||||||
bl_label = 'Load Classification'
|
bl_label = 'Load Classification'
|
||||||
|
is_file: bpy.props.BoolProperty()
|
||||||
|
classification_index: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
from . import prop
|
from . import prop
|
||||||
prop.ClassificationView.raw_data = schema.ifc.load_classification(
|
if self.is_file:
|
||||||
context.scene.BIMProperties.classification)
|
prop.ClassificationView.raw_data = schema.ifc.load_classification(
|
||||||
|
context.scene.BIMProperties.classification)
|
||||||
|
else:
|
||||||
|
prop.ClassificationView.raw_data = schema.ifc.load_classification(
|
||||||
|
context.scene.BIMProperties.classifications[self.classification_index].name,
|
||||||
|
self.classification_index)
|
||||||
context.scene.BIMProperties.classification_references.root = ''
|
context.scene.BIMProperties.classification_references.root = ''
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@@ -1949,7 +1956,7 @@ class AddClassification(bpy.types.Operator):
|
|||||||
for key, value in data_map.items():
|
for key, value in data_map.items():
|
||||||
if hasattr(data, value) and getattr(data, value):
|
if hasattr(data, value) and getattr(data, value):
|
||||||
setattr(classification, key, str(getattr(data, value)))
|
setattr(classification, key, str(getattr(data, value)))
|
||||||
classification.filename = context.scene.BIMProperties.classification
|
classification.data = schema.ifc.classification_files[context.scene.BIMProperties.classification].to_string()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
@@ -1979,7 +1986,7 @@ class AssignClassification(bpy.types.Operator):
|
|||||||
for key in ['location', 'description']:
|
for key in ['location', 'description']:
|
||||||
if data[key]:
|
if data[key]:
|
||||||
setattr(classification, key, data[key])
|
setattr(classification, key, data[key])
|
||||||
classification.referenced_source = bpy.context.scene.BIMProperties.classification
|
classification.referenced_source = bpy.context.scene.BIMProperties.active_classification_name
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
@@ -3872,22 +3879,6 @@ class EditVectorStyle(bpy.types.Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
class PurgeProjectClassifications(bpy.types.Operator):
|
|
||||||
bl_idname = 'bim.purge_project_classifications'
|
|
||||||
bl_label = 'Purge Project Classifications'
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
self.schema_dir = bpy.context.scene.BIMProperties.schema_dir
|
|
||||||
path = os.path.join(self.schema_dir, 'project_classifications')
|
|
||||||
files = os.listdir(path)
|
|
||||||
for f in files:
|
|
||||||
os.remove(os.path.join(path, f))
|
|
||||||
from . import prop
|
|
||||||
prop.classification_enum.clear()
|
|
||||||
prop.getClassifications(self, context)
|
|
||||||
return {'FINISHED'}
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveSheet(bpy.types.Operator):
|
class RemoveSheet(bpy.types.Operator):
|
||||||
bl_idname = 'bim.remove_sheet'
|
bl_idname = 'bim.remove_sheet'
|
||||||
bl_label = 'Remove Sheet'
|
bl_label = 'Remove Sheet'
|
||||||
|
|||||||
@@ -395,8 +395,6 @@ def getClassifications(self, context):
|
|||||||
classification_enum.clear()
|
classification_enum.clear()
|
||||||
files = os.listdir(os.path.join(self.schema_dir, 'classifications'))
|
files = os.listdir(os.path.join(self.schema_dir, 'classifications'))
|
||||||
classification_enum.extend([(f.replace('.ifc', ''), f.replace('.ifc', ''), '') for f in files])
|
classification_enum.extend([(f.replace('.ifc', ''), f.replace('.ifc', ''), '') for f in files])
|
||||||
files = os.listdir(os.path.join(self.schema_dir, 'project_classifications'))
|
|
||||||
classification_enum.extend([(f.replace('.ifc', ''), f.replace('.ifc', ''), '') for f in files])
|
|
||||||
return classification_enum
|
return classification_enum
|
||||||
|
|
||||||
|
|
||||||
@@ -1112,7 +1110,7 @@ class Classification(PropertyGroup):
|
|||||||
description: StringProperty(name="Description")
|
description: StringProperty(name="Description")
|
||||||
location: StringProperty(name="Location")
|
location: StringProperty(name="Location")
|
||||||
reference_tokens: StringProperty(name="Reference Tokens")
|
reference_tokens: StringProperty(name="Reference Tokens")
|
||||||
filename: StringProperty(name="Filename")
|
data: StringProperty(name="Data")
|
||||||
|
|
||||||
|
|
||||||
class ClassificationReference(PropertyGroup):
|
class ClassificationReference(PropertyGroup):
|
||||||
@@ -1249,6 +1247,7 @@ class BIMProperties(PropertyGroup):
|
|||||||
aggregate_class: EnumProperty(items=getIfcClasses, name="Aggregate Class")
|
aggregate_class: EnumProperty(items=getIfcClasses, name="Aggregate Class")
|
||||||
aggregate_name: StringProperty(name="Aggregate Name")
|
aggregate_name: StringProperty(name="Aggregate Name")
|
||||||
classification: EnumProperty(items=getClassifications, name="Classification", update=refreshReferences)
|
classification: EnumProperty(items=getClassifications, name="Classification", update=refreshReferences)
|
||||||
|
active_classification_name: StringProperty(name="Active Classification Name")
|
||||||
classifications: CollectionProperty(name="Classifications", type=Classification)
|
classifications: CollectionProperty(name="Classifications", type=Classification)
|
||||||
has_model_context: BoolProperty(name="Has Model Context", default=True)
|
has_model_context: BoolProperty(name="Has Model Context", default=True)
|
||||||
has_plan_context: BoolProperty(name="Has Plan Context", default=True)
|
has_plan_context: BoolProperty(name="Has Plan Context", default=True)
|
||||||
|
|||||||
@@ -62,14 +62,17 @@ class IfcSchema():
|
|||||||
entity = prop.ApplicableEntity if prop.ApplicableEntity else 'IfcRoot'
|
entity = prop.ApplicableEntity if prop.ApplicableEntity else 'IfcRoot'
|
||||||
self.applicable_psets.setdefault(entity, []).append(prop.Name)
|
self.applicable_psets.setdefault(entity, []).append(prop.Name)
|
||||||
|
|
||||||
def load_classification(self, filename):
|
def load_classification(self, name, classification_index=None):
|
||||||
if filename not in self.classifications:
|
if name not in self.classifications:
|
||||||
classification_path = os.path.join(self.schema_dir, 'classifications', '{}.ifc'.format(filename))
|
if classification_index is not None:
|
||||||
if not os.path.isfile(classification_path):
|
self.classification_files[name] = ifcopenshell.file.from_string(
|
||||||
classification_path = os.path.join(self.schema_dir, 'project_classifications', '{}.ifc'.format(filename))
|
bpy.context.scene.BIMProperties.classifications[classification_index].data)
|
||||||
self.classification_files[filename] = ifcopenshell.open(classification_path)
|
else:
|
||||||
self.classifications[filename] = self.classification_files[filename].by_type('IfcClassification')[0]
|
classification_path = os.path.join(self.schema_dir, 'classifications', '{}.ifc'.format(name))
|
||||||
classification = self.classifications[filename]
|
self.classification_files[name] = ifcopenshell.open(classification_path)
|
||||||
|
self.classifications[name] = self.classification_files[name].by_type('IfcClassification')[0]
|
||||||
|
classification = self.classifications[name]
|
||||||
|
bpy.context.scene.BIMProperties.active_classification_name = self.classifications[name].Name
|
||||||
return {
|
return {
|
||||||
'name': '',
|
'name': '',
|
||||||
'description': '',
|
'description': '',
|
||||||
|
|||||||
@@ -532,7 +532,7 @@ class BIM_PT_psets(Panel):
|
|||||||
|
|
||||||
|
|
||||||
class BIM_PT_classifications(Panel):
|
class BIM_PT_classifications(Panel):
|
||||||
bl_label = 'IFC Classifications References'
|
bl_label = 'IFC Classifications'
|
||||||
bl_idname = 'BIM_PT_classifications'
|
bl_idname = 'BIM_PT_classifications'
|
||||||
bl_options = {'DEFAULT_CLOSED'}
|
bl_options = {'DEFAULT_CLOSED'}
|
||||||
bl_space_type = 'PROPERTIES'
|
bl_space_type = 'PROPERTIES'
|
||||||
@@ -545,7 +545,6 @@ class BIM_PT_classifications(Panel):
|
|||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(props, "classification", text='')
|
row.prop(props, "classification", text='')
|
||||||
row.operator("bim.purge_project_classifications", text='', icon='TRASH')
|
|
||||||
row.operator("bim.add_classification", text='', icon='ADD')
|
row.operator("bim.add_classification", text='', icon='ADD')
|
||||||
|
|
||||||
if context.scene.BIMProperties.classification_references.raw_data:
|
if context.scene.BIMProperties.classification_references.raw_data:
|
||||||
@@ -555,7 +554,7 @@ class BIM_PT_classifications(Panel):
|
|||||||
row.operator("bim.unassign_classification")
|
row.operator("bim.unassign_classification")
|
||||||
else:
|
else:
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator('bim.load_classification')
|
row.operator('bim.load_classification').is_file = True
|
||||||
|
|
||||||
if not props.classifications:
|
if not props.classifications:
|
||||||
return
|
return
|
||||||
@@ -565,6 +564,7 @@ class BIM_PT_classifications(Panel):
|
|||||||
for index, classification in enumerate(props.classifications):
|
for index, classification in enumerate(props.classifications):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(classification, 'name')
|
row.prop(classification, 'name')
|
||||||
|
row.operator('bim.load_classification', icon='IMPORT', text='').classification_index = index
|
||||||
row.operator('bim.remove_classification', icon='X', text='').classification_index = index
|
row.operator('bim.remove_classification', icon='X', text='').classification_index = index
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(classification, 'source')
|
row.prop(classification, 'source')
|
||||||
|
|||||||
Reference in New Issue
Block a user