mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-02 04:59:52 +00:00
Add interface to add or remove documents to objects
This commit is contained in:
@@ -35,6 +35,8 @@ classes = (
|
|||||||
operator.UnassignPset,
|
operator.UnassignPset,
|
||||||
operator.AddPset,
|
operator.AddPset,
|
||||||
operator.RemovePset,
|
operator.RemovePset,
|
||||||
|
operator.AddDocument,
|
||||||
|
operator.RemoveDocument,
|
||||||
operator.GenerateGlobalId,
|
operator.GenerateGlobalId,
|
||||||
operator.AddAttribute,
|
operator.AddAttribute,
|
||||||
operator.RemoveAttribute,
|
operator.RemoveAttribute,
|
||||||
@@ -45,6 +47,7 @@ classes = (
|
|||||||
ui.TargetCRS,
|
ui.TargetCRS,
|
||||||
ui.Attribute,
|
ui.Attribute,
|
||||||
ui.Pset,
|
ui.Pset,
|
||||||
|
ui.Document,
|
||||||
ui.BIMObjectProperties,
|
ui.BIMObjectProperties,
|
||||||
ui.BIMMaterialProperties,
|
ui.BIMMaterialProperties,
|
||||||
ui.BIMMeshProperties,
|
ui.BIMMeshProperties,
|
||||||
|
|||||||
@@ -275,11 +275,12 @@ class IfcParser():
|
|||||||
self.rel_defines_by_pset.setdefault(
|
self.rel_defines_by_pset.setdefault(
|
||||||
'{}/{}'.format(pset.name, pset.file), []).append(product)
|
'{}/{}'.format(pset.name, pset.file), []).append(product)
|
||||||
|
|
||||||
|
for document in object.BIMObjectProperties.documents:
|
||||||
|
self.rel_associates_document_object.setdefault(
|
||||||
|
document.file, []).append(product)
|
||||||
|
|
||||||
for key in object.keys():
|
for key in object.keys():
|
||||||
if key[0:3] == 'Doc':
|
if key[0:5] == 'Class':
|
||||||
self.rel_associates_document_object.setdefault(
|
|
||||||
object[key], []).append(product)
|
|
||||||
elif key[0:5] == 'Class':
|
|
||||||
self.rel_associates_classification_object.setdefault(
|
self.rel_associates_classification_object.setdefault(
|
||||||
object[key], []).append(product)
|
object[key], []).append(product)
|
||||||
elif key[0:9] == 'Objective':
|
elif key[0:9] == 'Objective':
|
||||||
|
|||||||
@@ -280,6 +280,24 @@ class RemovePset(bpy.types.Operator):
|
|||||||
bpy.context.active_object.BIMObjectProperties.psets.remove(self.pset_index)
|
bpy.context.active_object.BIMObjectProperties.psets.remove(self.pset_index)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class AddDocument(bpy.types.Operator):
|
||||||
|
bl_idname = 'bim.add_document'
|
||||||
|
bl_label = 'Add Document'
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
document = bpy.context.active_object.BIMObjectProperties.documents.add()
|
||||||
|
document.file = bpy.context.active_object.BIMObjectProperties.applicable_documents
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class RemoveDocument(bpy.types.Operator):
|
||||||
|
bl_idname = 'bim.remove_document'
|
||||||
|
bl_label = 'Remove Document'
|
||||||
|
document_index: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
bpy.context.active_object.BIMObjectProperties.documents.remove(self.document_index)
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
class GenerateGlobalId(bpy.types.Operator):
|
class GenerateGlobalId(bpy.types.Operator):
|
||||||
bl_idname = 'bim.generate_global_id'
|
bl_idname = 'bim.generate_global_id'
|
||||||
bl_label = 'Generate GlobalId'
|
bl_label = 'Generate GlobalId'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
|
cwd = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
|
||||||
|
|
||||||
@@ -78,6 +79,9 @@ class Pset(bpy.types.PropertyGroup):
|
|||||||
name: bpy.props.StringProperty(name="Name")
|
name: bpy.props.StringProperty(name="Name")
|
||||||
file: bpy.props.StringProperty(name="File")
|
file: bpy.props.StringProperty(name="File")
|
||||||
|
|
||||||
|
class Document(bpy.types.PropertyGroup):
|
||||||
|
file: bpy.props.StringProperty(name="File")
|
||||||
|
|
||||||
class BIMObjectProperties(bpy.types.PropertyGroup):
|
class BIMObjectProperties(bpy.types.PropertyGroup):
|
||||||
def getApplicableAttributes(self, context):
|
def getApplicableAttributes(self, context):
|
||||||
if '/' in bpy.context.active_object.name \
|
if '/' in bpy.context.active_object.name \
|
||||||
@@ -87,9 +91,19 @@ class BIMObjectProperties(bpy.types.PropertyGroup):
|
|||||||
if bpy.context.active_object.BIMObjectProperties.attributes.find(a['name']) == -1]
|
if bpy.context.active_object.BIMObjectProperties.attributes.find(a['name']) == -1]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def getApplicableDocuments(self, context):
|
||||||
|
results = []
|
||||||
|
doc_path = bpy.context.scene.BIMProperties.data_dir + 'doc/'
|
||||||
|
for filename in Path(doc_path).glob('**/*'):
|
||||||
|
uri = str(filename.relative_to(doc_path).as_posix())
|
||||||
|
results.append((uri, uri, ''))
|
||||||
|
return results
|
||||||
|
|
||||||
attributes: bpy.props.CollectionProperty(name="Attributes", type=Attribute)
|
attributes: bpy.props.CollectionProperty(name="Attributes", type=Attribute)
|
||||||
psets: bpy.props.CollectionProperty(name="Psets", type=Pset)
|
psets: bpy.props.CollectionProperty(name="Psets", type=Pset)
|
||||||
applicable_attributes: bpy.props.EnumProperty(items=getApplicableAttributes, name="Attribute Names")
|
applicable_attributes: bpy.props.EnumProperty(items=getApplicableAttributes, name="Attribute Names")
|
||||||
|
documents: bpy.props.CollectionProperty(name="Documents", type=Document)
|
||||||
|
applicable_documents: bpy.props.EnumProperty(items=getApplicableDocuments, name="Available Documents")
|
||||||
|
|
||||||
class BIMMaterialProperties(bpy.types.PropertyGroup):
|
class BIMMaterialProperties(bpy.types.PropertyGroup):
|
||||||
is_external: bpy.props.BoolProperty(name="Has External Definition")
|
is_external: bpy.props.BoolProperty(name="Has External Definition")
|
||||||
@@ -143,6 +157,19 @@ class ObjectPanel(bpy.types.Panel):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bpy.context.active_object.BIMObjectProperties, 'psets')
|
row.prop(bpy.context.active_object.BIMObjectProperties, 'psets')
|
||||||
|
|
||||||
|
layout.label(text="Documents:")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.prop(bpy.context.active_object.BIMObjectProperties, 'applicable_documents', text='')
|
||||||
|
row.operator('bim.add_document')
|
||||||
|
|
||||||
|
for index, document in enumerate(bpy.context.active_object.BIMObjectProperties.documents):
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.prop(document, 'file', text='')
|
||||||
|
row.operator('bim.remove_document', icon='CANCEL', text='').document_index = index
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(bpy.context.active_object.BIMObjectProperties, 'documents')
|
||||||
|
|
||||||
class MeshPanel(bpy.types.Panel):
|
class MeshPanel(bpy.types.Panel):
|
||||||
bl_label = 'IFC Representations'
|
bl_label = 'IFC Representations'
|
||||||
bl_idname = 'BIM_PT_mesh'
|
bl_idname = 'BIM_PT_mesh'
|
||||||
|
|||||||
Reference in New Issue
Block a user