mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +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):
|
def convert_brick_project(ifc, brick):
|
||||||
library = ifc.run("library.add_library", name=brick.get_brick_path_name())
|
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):
|
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(cls): pass
|
||||||
def get_entity(cls, obj): pass
|
def get_entity(cls, obj): pass
|
||||||
def get_object(cls, entity): pass
|
def get_object(cls, entity): pass
|
||||||
|
def get_schema(cls): pass
|
||||||
def link(cls, element, obj): pass
|
def link(cls, element, obj): pass
|
||||||
def run(cls, command, **kwargs): pass
|
def run(cls, command, **kwargs): pass
|
||||||
def unlink(cls, element=None, obj=None): pass
|
def unlink(cls, element=None, obj=None): pass
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_brick_attributes(cls, brick_uri):
|
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
|
@classmethod
|
||||||
def get_brick_path(cls):
|
def get_brick_path(cls):
|
||||||
@@ -79,11 +82,11 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_library_brick_reference(cls, library, brick_uri):
|
def get_library_brick_reference(cls, library, brick_uri):
|
||||||
if tool.Ifc.get_schema() == "IFC2X3":
|
if tool.Ifc.get_schema() == "IFC2X3":
|
||||||
for reference in library.LibraryReference:
|
for reference in library.LibraryReference or []:
|
||||||
if reference.ItemReference == brick_uri:
|
if reference.ItemReference == brick_uri:
|
||||||
return reference
|
return reference
|
||||||
else:
|
else:
|
||||||
for reference in library.HasLibraryReferences:
|
for reference in library.HasLibraryReferences or []:
|
||||||
if reference.Identification == brick_uri:
|
if reference.Identification == brick_uri:
|
||||||
return reference
|
return reference
|
||||||
|
|
||||||
|
|||||||
@@ -70,12 +70,19 @@ class TestConvertBrickProject:
|
|||||||
def test_run(self, ifc, brick):
|
def test_run(self, ifc, brick):
|
||||||
brick.get_brick_path_name().should_be_called().will_return("foo.ttl")
|
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.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")
|
brick.get_brick_path().should_be_called().will_return("/path/to/foo.ttl")
|
||||||
ifc.run(
|
ifc.run(
|
||||||
"library.edit_library", library="library", attributes={"Location": "/path/to/foo.ttl"}
|
"library.edit_library", library="library", attributes={"Location": "/path/to/foo.ttl"}
|
||||||
).should_be_called()
|
).should_be_called()
|
||||||
subject.convert_brick_project(ifc, brick)
|
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:
|
class TestAssignBrickReference:
|
||||||
def test_assigning_to_a_new_reference(self, ifc, brick):
|
def test_assigning_to_a_new_reference(self, ifc, brick):
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ class TestExportBrickAttributes(NewFile):
|
|||||||
def test_run(self):
|
def test_run(self):
|
||||||
assert subject.export_brick_attributes("ex:#floor") == {"Identification": "ex:#floor", "Name": "floor"}
|
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):
|
class TestGetBrickPath(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user