mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-16 02:24:30 +00:00
Add interface to add or remove documents to objects
This commit is contained in:
@@ -35,6 +35,8 @@ classes = (
|
||||
operator.UnassignPset,
|
||||
operator.AddPset,
|
||||
operator.RemovePset,
|
||||
operator.AddDocument,
|
||||
operator.RemoveDocument,
|
||||
operator.GenerateGlobalId,
|
||||
operator.AddAttribute,
|
||||
operator.RemoveAttribute,
|
||||
@@ -45,6 +47,7 @@ classes = (
|
||||
ui.TargetCRS,
|
||||
ui.Attribute,
|
||||
ui.Pset,
|
||||
ui.Document,
|
||||
ui.BIMObjectProperties,
|
||||
ui.BIMMaterialProperties,
|
||||
ui.BIMMeshProperties,
|
||||
|
||||
@@ -275,11 +275,12 @@ class IfcParser():
|
||||
self.rel_defines_by_pset.setdefault(
|
||||
'{}/{}'.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():
|
||||
if key[0:3] == 'Doc':
|
||||
self.rel_associates_document_object.setdefault(
|
||||
object[key], []).append(product)
|
||||
elif key[0:5] == 'Class':
|
||||
if key[0:5] == 'Class':
|
||||
self.rel_associates_classification_object.setdefault(
|
||||
object[key], []).append(product)
|
||||
elif key[0:9] == 'Objective':
|
||||
|
||||
@@ -280,6 +280,24 @@ class RemovePset(bpy.types.Operator):
|
||||
bpy.context.active_object.BIMObjectProperties.psets.remove(self.pset_index)
|
||||
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):
|
||||
bl_idname = 'bim.generate_global_id'
|
||||
bl_label = 'Generate GlobalId'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import bpy
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
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")
|
||||
file: bpy.props.StringProperty(name="File")
|
||||
|
||||
class Document(bpy.types.PropertyGroup):
|
||||
file: bpy.props.StringProperty(name="File")
|
||||
|
||||
class BIMObjectProperties(bpy.types.PropertyGroup):
|
||||
def getApplicableAttributes(self, context):
|
||||
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]
|
||||
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)
|
||||
psets: bpy.props.CollectionProperty(name="Psets", type=Pset)
|
||||
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):
|
||||
is_external: bpy.props.BoolProperty(name="Has External Definition")
|
||||
@@ -143,6 +157,19 @@ class ObjectPanel(bpy.types.Panel):
|
||||
row = layout.row()
|
||||
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):
|
||||
bl_label = 'IFC Representations'
|
||||
bl_idname = 'BIM_PT_mesh'
|
||||
|
||||
Reference in New Issue
Block a user