mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
cleanup nomenclature and some redundant code
This commit is contained in:
@@ -125,7 +125,6 @@ class ObjectDocumentData:
|
||||
|
||||
location = None
|
||||
identification = None
|
||||
description = None
|
||||
|
||||
if is_information:
|
||||
if tool.Ifc.get_schema() == "IFC2X3":
|
||||
@@ -134,7 +133,7 @@ class ObjectDocumentData:
|
||||
identification = relating_document.Identification
|
||||
|
||||
location = getattr(relating_document, "Location", None)
|
||||
|
||||
description = getattr(relating_document, "Description", "No description")
|
||||
else:
|
||||
description = relating_document.Description
|
||||
if tool.Ifc.get_schema() == "IFC2X3":
|
||||
|
||||
@@ -60,7 +60,7 @@ class EnableEditingDocument(bpy.types.Operator):
|
||||
document: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
core.enable_editing_document(tool.Document, document=tool.Ifc.get().by_id(self.document))
|
||||
core.enable_editing_document(tool.Document, ifc_document=tool.Ifc.get().by_id(self.document))
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ class EditDocument(bpy.types.Operator, tool.Ifc.Operator):
|
||||
def _execute(self, context):
|
||||
props = tool.Document.get_document_props()
|
||||
if props.active_document_id:
|
||||
core.edit_document(tool.Ifc, tool.Document, document=tool.Ifc.get().by_id(props.active_document_id))
|
||||
core.edit_document(tool.Ifc, tool.Document, ifc_document=tool.Ifc.get().by_id(props.active_document_id))
|
||||
props.active_document_id = 0
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ class RemoveDocument(bpy.types.Operator, tool.Ifc.Operator):
|
||||
document: bpy.props.IntProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
core.remove_document(tool.Ifc, tool.Document, document=tool.Ifc.get().by_id(self.document))
|
||||
core.remove_document(tool.Ifc, tool.Document, ifc_document=tool.Ifc.get().by_id(self.document))
|
||||
|
||||
|
||||
class AssignDocument(bpy.types.Operator, tool.Ifc.Operator):
|
||||
@@ -177,12 +177,11 @@ class AssignDocument(bpy.types.Operator, tool.Ifc.Operator):
|
||||
document: bpy.props.IntProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
document = tool.Ifc.get().by_id(self.document)
|
||||
objs = [bpy.data.objects[self.obj]] if self.obj else tool.Blender.get_selected_objects()
|
||||
for obj in objs:
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if element:
|
||||
core.assign_document(tool.Ifc, product=element, document=document)
|
||||
core.assign_document(tool.Ifc, product=element, ifc_document=tool.Ifc.get().by_id(self.document))
|
||||
|
||||
tool.Document.update_document_objects(self.document)
|
||||
ObjectDocumentData.load()
|
||||
@@ -197,13 +196,12 @@ class UnassignDocument(bpy.types.Operator, tool.Ifc.Operator):
|
||||
document: bpy.props.IntProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
document = tool.Ifc.get().by_id(self.document)
|
||||
objs = [bpy.data.objects.get(self.obj)] if self.obj else tool.Blender.get_selected_objects()
|
||||
for obj in objs:
|
||||
if obj:
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if element:
|
||||
core.unassign_document(tool.Ifc, product=element, document=document)
|
||||
core.unassign_document(tool.Ifc, product=element, ifc_document=tool.Ifc.get().by_id(self.document))
|
||||
|
||||
props = tool.Document.get_document_props()
|
||||
active_document_id = None
|
||||
|
||||
@@ -234,10 +234,10 @@ class BIM_UL_documents(UIList):
|
||||
|
||||
if item.document_type == "INFORMATION":
|
||||
row.label(text="", icon="FILE")
|
||||
text = " - ".join([x for x in [item.name, item.location] if x])
|
||||
text = " - ".join([x for x in [item.location, item.description, item.name] if x])
|
||||
else:
|
||||
row.label(text="", icon="FILE_HIDDEN")
|
||||
text = " - ".join([x for x in [item.description, item.location] if x])
|
||||
text = " - ".join([x for x in [item.location, item.description] if x])
|
||||
split1 = row.split(factor=0.1)
|
||||
split1.prop(item, "identification", text="", emboss=False)
|
||||
split2 = split1.split(factor=0.8)
|
||||
|
||||
@@ -39,9 +39,9 @@ def disable_object_document_editing_ui(document: tool.Document) -> None:
|
||||
document.disable_object_editing_ui()
|
||||
|
||||
|
||||
def enable_editing_document(document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None:
|
||||
document_tool.set_active_document(document)
|
||||
document_tool.import_document_attributes(document)
|
||||
def enable_editing_document(document: tool.Document, ifc_document: ifcopenshell.entity_instance) -> None:
|
||||
document.set_active_document(ifc_document)
|
||||
document.import_document_attributes(ifc_document)
|
||||
|
||||
|
||||
def disable_editing_document(document: tool.Document) -> None:
|
||||
@@ -49,19 +49,19 @@ def disable_editing_document(document: tool.Document) -> None:
|
||||
document.clear_document_attributes()
|
||||
|
||||
|
||||
def add_information(ifc: tool.Ifc, document_tool: tool.Document, parent=None) -> ifcopenshell.entity_instance:
|
||||
document_tool.clear_document_tree()
|
||||
def add_information(ifc: tool.Ifc, document: tool.Document, parent=None) -> ifcopenshell.entity_instance:
|
||||
document.clear_document_tree()
|
||||
|
||||
if parent is None:
|
||||
parent = document_tool.get_default_parent_for_information(ifc)
|
||||
parent = document.get_default_parent_for_information(ifc)
|
||||
|
||||
information = ifc.run("document.add_information", parent=parent)
|
||||
ifc.run("document.add_reference", information=information)
|
||||
|
||||
if document_tool.is_document_information(parent):
|
||||
document_tool.expand_document(parent)
|
||||
if document.is_document_information(parent):
|
||||
document.expand_document(parent)
|
||||
|
||||
document_tool.import_project_documents()
|
||||
document.import_project_documents()
|
||||
return information
|
||||
|
||||
|
||||
@@ -76,33 +76,33 @@ def add_reference(ifc: tool.Ifc, document: tool.Document) -> None:
|
||||
document.import_project_documents()
|
||||
|
||||
|
||||
def edit_document(ifc: tool.Ifc, document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None:
|
||||
attributes = document_tool.export_document_attributes()
|
||||
if document_tool.is_document_information(document):
|
||||
ifc.run("document.edit_information", information=document, attributes=attributes)
|
||||
def edit_document(ifc: tool.Ifc, document: tool.Document, ifc_document: ifcopenshell.entity_instance) -> None:
|
||||
attributes = document.export_document_attributes()
|
||||
if document.is_document_information(ifc_document):
|
||||
ifc.run("document.edit_information", information=ifc_document, attributes=attributes)
|
||||
else:
|
||||
ifc.run("document.edit_reference", reference=document, attributes=attributes)
|
||||
document_tool.disable_editing_document()
|
||||
document_tool.clear_document_tree()
|
||||
document_tool.import_project_documents()
|
||||
ifc.run("document.edit_reference", reference=ifc_document, attributes=attributes)
|
||||
document.disable_editing_document()
|
||||
document.clear_document_tree()
|
||||
document.import_project_documents()
|
||||
|
||||
|
||||
def remove_document(ifc: tool.Ifc, document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None:
|
||||
document_tool.clear_document_tree()
|
||||
if document_tool.is_document_information(document):
|
||||
ifc.run("document.remove_information", information=document)
|
||||
def remove_document(ifc: tool.Ifc, document: tool.Document, ifc_document: ifcopenshell.entity_instance) -> None:
|
||||
document.clear_document_tree()
|
||||
if document.is_document_information(ifc_document):
|
||||
ifc.run("document.remove_information", information=ifc_document)
|
||||
else:
|
||||
ifc.run("document.remove_reference", reference=document)
|
||||
document_tool.import_project_documents()
|
||||
ifc.run("document.remove_reference", reference=ifc_document)
|
||||
document.import_project_documents()
|
||||
|
||||
|
||||
def assign_document(
|
||||
ifc: tool.Ifc, product: ifcopenshell.entity_instance, document: ifcopenshell.entity_instance
|
||||
ifc: tool.Ifc, product: ifcopenshell.entity_instance, ifc_document: ifcopenshell.entity_instance
|
||||
) -> None:
|
||||
ifc.run("document.assign_document", products=[product], document=document)
|
||||
ifc.run("document.assign_document", products=[product], document=ifc_document)
|
||||
|
||||
|
||||
def unassign_document(
|
||||
ifc: tool.Ifc, product: ifcopenshell.entity_instance, document: ifcopenshell.entity_instance
|
||||
ifc: tool.Ifc, product: ifcopenshell.entity_instance, ifc_document: ifcopenshell.entity_instance
|
||||
) -> None:
|
||||
ifc.run("document.unassign_document", products=[product], document=document)
|
||||
ifc.run("document.unassign_document", products=[product], document=ifc_document)
|
||||
|
||||
@@ -172,30 +172,23 @@ class Document(bonsai.core.tool.Document):
|
||||
new.document_type = "INFORMATION" if document.is_a("IfcDocumentInformation") else "REFERENCE"
|
||||
new.tree_depth = depth
|
||||
|
||||
file = document.file
|
||||
new.name = document.Name or ""
|
||||
new.identification = cls.get_document_information_id(document) if new.document_type == "INFORMATION" else cls.get_external_reference_id(document)
|
||||
new.identification = new.identification or ""
|
||||
new.description = document.Description or ""
|
||||
new.location = document.Location or ""
|
||||
|
||||
if new.document_type == "INFORMATION":
|
||||
new.name = document.Name or "Unnamed"
|
||||
new.identification = cls.get_document_information_id(document) or ""
|
||||
new.location = document.Location or ""
|
||||
else:
|
||||
new.name = document.Name or ""
|
||||
new.identification = cls.get_external_reference_id(document) or ""
|
||||
new.description = document.Description or ""
|
||||
new.location = document.Location or ""
|
||||
|
||||
if new.document_type == "REFERENCE":
|
||||
if file.schema == "IFC2X3":
|
||||
if document.ReferenceToDocument:
|
||||
doc_info = document.ReferenceToDocument[0]
|
||||
if not new.name:
|
||||
new.name = doc_info.Name or ""
|
||||
new.location = new.location or ""
|
||||
else:
|
||||
if document.ReferencedDocument:
|
||||
doc_info = document.ReferencedDocument
|
||||
if not new.name:
|
||||
new.name = doc_info.Name or ""
|
||||
new.location = new.location or ""
|
||||
|
||||
elif new.document_type == "REFERENCE":
|
||||
file = document.file
|
||||
if file.schema == "IFC2X3":
|
||||
if document.ReferenceToDocument and not new.name:
|
||||
new.name = document.ReferenceToDocument[0].Name or ""
|
||||
else:
|
||||
if document.ReferencedDocument and not new.name:
|
||||
new.name = document.ReferencedDocument.Name or ""
|
||||
|
||||
doc_id = document.id()
|
||||
has_children = doc_id in document_children and bool(document_children[doc_id])
|
||||
@@ -205,16 +198,14 @@ class Document(bonsai.core.tool.Document):
|
||||
if has_children and new.is_expanded:
|
||||
children = document_children[doc_id]
|
||||
|
||||
info_children = [d for d in children if d.is_a("IfcDocumentInformation")]
|
||||
ref_children = [d for d in children if not d.is_a("IfcDocumentInformation")]
|
||||
|
||||
info_children = natsorted(
|
||||
info_children, key=lambda doc: (cls.get_document_information_id(doc) or "", doc.Name or "")
|
||||
[d for d in children if d.is_a("IfcDocumentInformation")],
|
||||
key=lambda doc: (cls.get_document_information_id(doc) or "", doc.Name or "")
|
||||
)
|
||||
|
||||
ref_children = natsorted(
|
||||
ref_children,
|
||||
key=lambda doc: (cls.get_external_reference_id(doc) or "", doc.Description or doc.Name or ""),
|
||||
[d for d in children if not d.is_a("IfcDocumentInformation")],
|
||||
key=lambda doc: (cls.get_external_reference_id(doc) or "", doc.Description or doc.Name or "")
|
||||
)
|
||||
|
||||
for child in info_children + ref_children:
|
||||
|
||||
Reference in New Issue
Block a user