mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 03:21:00 +00:00
Fix support for document references in IFC2X3
This commit is contained in:
@@ -84,21 +84,28 @@ class ObjectDocumentData:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
name = rel.RelatingDocument.Name
|
name = rel.RelatingDocument.Name
|
||||||
if not name and rel.RelatingDocument.ReferencedDocument:
|
|
||||||
name = rel.RelatingDocument.ReferencedDocument.Name
|
|
||||||
|
|
||||||
if tool.Ifc.get_schema() == "IFC2X3":
|
if tool.Ifc.get_schema() == "IFC2X3":
|
||||||
|
if not name and rel.RelatingDocument.ReferenceToDocument:
|
||||||
|
name = rel.RelatingDocument.ReferenceToDocument[0].Name
|
||||||
|
|
||||||
identification = rel.RelatingDocument.ItemReference
|
identification = rel.RelatingDocument.ItemReference
|
||||||
if not identification and rel.RelatingDocument.ReferencedDocument:
|
if not identification and rel.RelatingDocument.ReferenceToDocument:
|
||||||
identification = rel.RelatingDocument.ReferencedDocument.DocumentId
|
identification = rel.RelatingDocument.ReferenceToDocument[0].DocumentId
|
||||||
|
|
||||||
|
location = rel.RelatingDocument.Location
|
||||||
else:
|
else:
|
||||||
|
if not name and rel.RelatingDocument.ReferencedDocument:
|
||||||
|
name = rel.RelatingDocument.ReferencedDocument.Name
|
||||||
|
|
||||||
identification = rel.RelatingDocument.Identification
|
identification = rel.RelatingDocument.Identification
|
||||||
if not identification and rel.RelatingDocument.ReferencedDocument:
|
if not identification and rel.RelatingDocument.ReferencedDocument:
|
||||||
identification = rel.RelatingDocument.ReferencedDocument.Identification
|
identification = rel.RelatingDocument.ReferencedDocument.Identification
|
||||||
|
|
||||||
location = rel.RelatingDocument.Location
|
location = rel.RelatingDocument.Location
|
||||||
if location is None and rel.RelatingDocument.ReferencedDocument:
|
if location is None and rel.RelatingDocument.ReferencedDocument:
|
||||||
location = rel.RelatingDocument.ReferencedDocument.Location
|
location = rel.RelatingDocument.ReferencedDocument.Location
|
||||||
|
|
||||||
if location:
|
if location:
|
||||||
if not "://" in location:
|
if not "://" in location:
|
||||||
if not os.path.isabs(location):
|
if not os.path.isabs(location):
|
||||||
|
|||||||
@@ -26,5 +26,10 @@ class Usecase:
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
if self.file.schema == "IFC2X3":
|
if self.file.schema == "IFC2X3":
|
||||||
return self.file.create_entity("IfcDocumentReference")
|
reference = self.file.create_entity("IfcDocumentReference")
|
||||||
|
if self.settings["information"]:
|
||||||
|
references = list(self.settings["information"].DocumentReferences or [])
|
||||||
|
references.append(reference)
|
||||||
|
self.settings["information"].DocumentReferences = references
|
||||||
|
return reference
|
||||||
return self.file.create_entity("IfcDocumentReference", ReferencedDocument=self.settings["information"])
|
return self.file.create_entity("IfcDocumentReference", ReferencedDocument=self.settings["information"])
|
||||||
|
|||||||
@@ -33,3 +33,18 @@ class TestAddReference(test.bootstrap.IFC4):
|
|||||||
assert element.is_a("IfcDocumentReference")
|
assert element.is_a("IfcDocumentReference")
|
||||||
assert len(self.file.by_type("IfcDocumentReference")) == 1
|
assert len(self.file.by_type("IfcDocumentReference")) == 1
|
||||||
assert element.ReferencedDocument == information
|
assert element.ReferencedDocument == information
|
||||||
|
|
||||||
|
|
||||||
|
class TestAddReferenceIFC2X3(test.bootstrap.IFC2X3):
|
||||||
|
def test_adding_a_reference(self):
|
||||||
|
element = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||||
|
assert element.is_a("IfcDocumentReference")
|
||||||
|
assert len(self.file.by_type("IfcDocumentReference")) == 1
|
||||||
|
|
||||||
|
def test_adding_a_reference_to_an_information(self):
|
||||||
|
self.file.createIfcProject()
|
||||||
|
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||||
|
element = ifcopenshell.api.run("document.add_reference", self.file, information=information)
|
||||||
|
assert element.is_a("IfcDocumentReference")
|
||||||
|
assert len(self.file.by_type("IfcDocumentReference")) == 1
|
||||||
|
assert element.ReferenceToDocument[0] == information
|
||||||
|
|||||||
Reference in New Issue
Block a user