mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Converting brickschema projects to IFC libraries now works on IFC2X3
This commit is contained in:
@@ -51,7 +51,8 @@ def close_brick_project(brick):
|
||||
|
||||
def convert_brick_project(ifc, brick):
|
||||
library = ifc.run("library.add_library", name=brick.get_brick_path_name())
|
||||
ifc.run("library.edit_library", library=library, attributes={"Location": brick.get_brick_path()})
|
||||
if ifc.get_schema() != "IFC2X3":
|
||||
ifc.run("library.edit_library", library=library, attributes={"Location": brick.get_brick_path()})
|
||||
|
||||
|
||||
def assign_brick_reference(ifc, brick, obj=None, library=None, brick_uri=None):
|
||||
|
||||
@@ -131,6 +131,7 @@ class Ifc:
|
||||
def get(cls): pass
|
||||
def get_entity(cls, obj): pass
|
||||
def get_object(cls, entity): pass
|
||||
def get_schema(cls): pass
|
||||
def link(cls, element, obj): pass
|
||||
def run(cls, command, **kwargs): pass
|
||||
def unlink(cls, element=None, obj=None): pass
|
||||
|
||||
@@ -50,7 +50,10 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
|
||||
@classmethod
|
||||
def export_brick_attributes(cls, brick_uri):
|
||||
return {"Identification": brick_uri, "Name": brick_uri.split("#")[-1]}
|
||||
if tool.Ifc.get_schema() == "IFC2X3":
|
||||
return {"ItemReference": brick_uri, "Name": brick_uri.split("#")[-1]}
|
||||
else:
|
||||
return {"Identification": brick_uri, "Name": brick_uri.split("#")[-1]}
|
||||
|
||||
@classmethod
|
||||
def get_brick_path(cls):
|
||||
@@ -79,11 +82,11 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
@classmethod
|
||||
def get_library_brick_reference(cls, library, brick_uri):
|
||||
if tool.Ifc.get_schema() == "IFC2X3":
|
||||
for reference in library.LibraryReference:
|
||||
for reference in library.LibraryReference or []:
|
||||
if reference.ItemReference == brick_uri:
|
||||
return reference
|
||||
else:
|
||||
for reference in library.HasLibraryReferences:
|
||||
for reference in library.HasLibraryReferences or []:
|
||||
if reference.Identification == brick_uri:
|
||||
return reference
|
||||
|
||||
|
||||
@@ -70,12 +70,19 @@ class TestConvertBrickProject:
|
||||
def test_run(self, ifc, brick):
|
||||
brick.get_brick_path_name().should_be_called().will_return("foo.ttl")
|
||||
ifc.run("library.add_library", name="foo.ttl").should_be_called().will_return("library")
|
||||
ifc.get_schema().should_be_called().will_return("IFC4")
|
||||
brick.get_brick_path().should_be_called().will_return("/path/to/foo.ttl")
|
||||
ifc.run(
|
||||
"library.edit_library", library="library", attributes={"Location": "/path/to/foo.ttl"}
|
||||
).should_be_called()
|
||||
subject.convert_brick_project(ifc, brick)
|
||||
|
||||
def test_not_editing_in_ifc2x3(self, ifc, brick):
|
||||
brick.get_brick_path_name().should_be_called().will_return("foo.ttl")
|
||||
ifc.run("library.add_library", name="foo.ttl").should_be_called().will_return("library")
|
||||
ifc.get_schema().should_be_called().will_return("IFC2X3")
|
||||
subject.convert_brick_project(ifc, brick)
|
||||
|
||||
|
||||
class TestAssignBrickReference:
|
||||
def test_assigning_to_a_new_reference(self, ifc, brick):
|
||||
|
||||
@@ -63,6 +63,10 @@ class TestExportBrickAttributes(NewFile):
|
||||
def test_run(self):
|
||||
assert subject.export_brick_attributes("ex:#floor") == {"Identification": "ex:#floor", "Name": "floor"}
|
||||
|
||||
def test_run_ifc2x3(self):
|
||||
tool.Ifc.set(ifcopenshell.file(schema="IFC2X3"))
|
||||
assert subject.export_brick_attributes("ex:#floor") == {"ItemReference": "ex:#floor", "Name": "floor"}
|
||||
|
||||
|
||||
class TestGetBrickPath(NewFile):
|
||||
def test_run(self):
|
||||
|
||||
Reference in New Issue
Block a user