mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 03:21:00 +00:00
_remove, schema_identifier and test_file
This commit is contained in:
@@ -662,7 +662,7 @@ class file_mixin:
|
|||||||
"""General IFC schema version: IFC2X3, IFC4, IFC4X3."""
|
"""General IFC schema version: IFC2X3, IFC4, IFC4X3."""
|
||||||
prefixes = ("IFC", "X", "_ADD", "_TC")
|
prefixes = ("IFC", "X", "_ADD", "_TC")
|
||||||
reg = "".join(f"(?P<{s}>{s}\\d+)?" for s in prefixes)
|
reg = "".join(f"(?P<{s}>{s}\\d+)?" for s in prefixes)
|
||||||
match = re.match(reg, self.schema)
|
match = re.match(reg, self.schema_identifier)
|
||||||
version_tuple = tuple(
|
version_tuple = tuple(
|
||||||
map(
|
map(
|
||||||
lambda pp: int(pp[1][len(pp[0]) :]) if pp[1] else None,
|
lambda pp: int(pp[1][len(pp[0]) :]) if pp[1] else None,
|
||||||
@@ -671,18 +671,13 @@ class file_mixin:
|
|||||||
)
|
)
|
||||||
return "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, version_tuple[0:2]))
|
return "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, version_tuple[0:2]))
|
||||||
|
|
||||||
@property
|
|
||||||
def schema_identifier(self) -> str:
|
|
||||||
"""Full IFC schema version: IFC2X3_TC1, IFC4_ADD2, IFC4X3_ADD2, etc."""
|
|
||||||
return self.schema
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def schema_version(self) -> tuple[int, int, int, int]:
|
def schema_version(self) -> tuple[int, int, int, int]:
|
||||||
"""Numeric representation of the full IFC schema version.
|
"""Numeric representation of the full IFC schema version.
|
||||||
|
|
||||||
E.g. IFC4X3_ADD2 is represented as (4, 3, 2, 0).
|
E.g. IFC4X3_ADD2 is represented as (4, 3, 2, 0).
|
||||||
"""
|
"""
|
||||||
schema = self.schema
|
schema = self.schema_identifier
|
||||||
version = []
|
version = []
|
||||||
for prefix in ("IFC", "X", "_ADD", "_TC"):
|
for prefix in ("IFC", "X", "_ADD", "_TC"):
|
||||||
number = re.search(prefix + r"(\d)", schema)
|
number = re.search(prefix + r"(\d)", schema)
|
||||||
@@ -829,7 +824,7 @@ class file_mixin:
|
|||||||
"""
|
"""
|
||||||
if self.transaction:
|
if self.transaction:
|
||||||
self.transaction.store_delete(inst)
|
self.transaction.store_delete(inst)
|
||||||
return self.remove(inst)
|
return self._remove(inst)
|
||||||
|
|
||||||
def batch(self):
|
def batch(self):
|
||||||
"""Low-level mechanism to speed up deletion of large subgraphs"""
|
"""Low-level mechanism to speed up deletion of large subgraphs"""
|
||||||
|
|||||||
@@ -186,11 +186,13 @@ class TestFile(test.bootstrap.IFC4):
|
|||||||
def test_getting_an_element_by_id(self):
|
def test_getting_an_element_by_id(self):
|
||||||
element = self.file.createIfcWall("id")
|
element = self.file.createIfcWall("id")
|
||||||
assert self.file.by_id(1) == element
|
assert self.file.by_id(1) == element
|
||||||
assert self.file.by_id("id") == element
|
with pytest.raises(TypeError):
|
||||||
|
self.file.by_id("id")
|
||||||
|
|
||||||
def test_getting_an_element_by_guid(self):
|
def test_getting_an_element_by_guid(self):
|
||||||
element = self.file.createIfcWall("id")
|
element = self.file.createIfcWall("id")
|
||||||
assert self.file.by_guid(1) == element
|
with pytest.raises(TypeError):
|
||||||
|
self.file.by_guid(1)
|
||||||
assert self.file.by_guid("id") == element
|
assert self.file.by_guid("id") == element
|
||||||
|
|
||||||
def test_adding_an_element(self):
|
def test_adding_an_element(self):
|
||||||
@@ -202,23 +204,23 @@ class TestFile(test.bootstrap.IFC4):
|
|||||||
def test_getting_elements_by_type(self):
|
def test_getting_elements_by_type(self):
|
||||||
wall = self.file.createIfcWall()
|
wall = self.file.createIfcWall()
|
||||||
slab = self.file.createIfcSlab()
|
slab = self.file.createIfcSlab()
|
||||||
assert self.file.by_type("IfcWall") == [wall]
|
assert self.file.by_type("IfcWall") == (wall,)
|
||||||
|
|
||||||
def test_getting_elements_by_exact_type(self):
|
def test_getting_elements_by_exact_type(self):
|
||||||
wall = self.file.createIfcWall()
|
wall = self.file.createIfcWall()
|
||||||
assert self.file.by_type("IfcElement") == [wall]
|
assert self.file.by_type("IfcElement") == (wall,)
|
||||||
assert len(self.file.by_type("IfcElement", include_subtypes=False)) == 0
|
assert len(self.file.by_type("IfcElement", include_subtypes=False)) == 0
|
||||||
|
|
||||||
def test_traversing_direct_attributes_of_an_element(self):
|
def test_traversing_direct_attributes_of_an_element(self):
|
||||||
owner = self.file.createIfcOwnerHistory()
|
owner = self.file.createIfcOwnerHistory()
|
||||||
element = self.file.createIfcWall(OwnerHistory=owner)
|
element = self.file.createIfcWall(OwnerHistory=owner)
|
||||||
assert self.file.traverse(element) == [element, owner]
|
assert self.file.traverse(element) == (element, owner)
|
||||||
|
|
||||||
def test_traversing_direct_attributes_of_an_element_to_a_limited_level(self):
|
def test_traversing_direct_attributes_of_an_element_to_a_limited_level(self):
|
||||||
app = self.file.createIfcApplication()
|
app = self.file.createIfcApplication()
|
||||||
owner = self.file.createIfcOwnerHistory(OwningApplication=app)
|
owner = self.file.createIfcOwnerHistory(OwningApplication=app)
|
||||||
element = self.file.createIfcWall(OwnerHistory=owner)
|
element = self.file.createIfcWall(OwnerHistory=owner)
|
||||||
assert self.file.traverse(element, max_levels=1) == [element, owner]
|
assert self.file.traverse(element, max_levels=1) == (element, owner)
|
||||||
|
|
||||||
def test_getting_inverse_references_of_an_element(self):
|
def test_getting_inverse_references_of_an_element(self):
|
||||||
owner = self.file.createIfcOwnerHistory()
|
owner = self.file.createIfcOwnerHistory()
|
||||||
@@ -228,7 +230,7 @@ class TestFile(test.bootstrap.IFC4):
|
|||||||
def test_getting_multiple_inverses_if_an_element_is_referenced_twice_by_the_same_element(self):
|
def test_getting_multiple_inverses_if_an_element_is_referenced_twice_by_the_same_element(self):
|
||||||
user = self.file.createIfcPersonAndOrganization()
|
user = self.file.createIfcPersonAndOrganization()
|
||||||
owner = self.file.createIfcOwnerHistory(OwningUser=user, LastModifyingUser=user)
|
owner = self.file.createIfcOwnerHistory(OwningUser=user, LastModifyingUser=user)
|
||||||
assert self.file.get_inverse(user, allow_duplicate=True) == [owner, owner]
|
assert self.file.get_inverse(user, allow_duplicate=True) == (owner, owner)
|
||||||
|
|
||||||
def test_removing_an_element(self):
|
def test_removing_an_element(self):
|
||||||
element = self.file.createIfcWall(GlobalId="global_id")
|
element = self.file.createIfcWall(GlobalId="global_id")
|
||||||
@@ -286,3 +288,9 @@ class TestFile(test.bootstrap.IFC4):
|
|||||||
g = ifcopenshell.file(schema="IFC4")
|
g = ifcopenshell.file(schema="IFC4")
|
||||||
g.assign_header_from(f)
|
g.assign_header_from(f)
|
||||||
assert g.header.file_name.name == "test"
|
assert g.header.file_name.name == "test"
|
||||||
|
|
||||||
|
def test_schema_identifier():
|
||||||
|
f = ifcopenshell.file(schema='IFC4X3')
|
||||||
|
assert f.schema_identifier == 'IFC4X3_ADD2'
|
||||||
|
assert f.schema == 'IFC4X3'
|
||||||
|
assert f.schema_version == (4,3,2,0)
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
%rename("file") IfcFile;
|
%rename("file") IfcFile;
|
||||||
// _add() because mixin defined add which adds transaction logic
|
// _add() because mixin defined add which adds transaction logic
|
||||||
%rename("_add") addEntity;
|
%rename("_add") addEntity;
|
||||||
%rename("remove") removeEntity;
|
%rename("_remove") removeEntity;
|
||||||
%rename("_traverse") traverse;
|
%rename("_traverse") traverse;
|
||||||
%rename("_traverse_breadth_first") traverse_breadth_first;
|
%rename("_traverse_breadth_first") traverse_breadth_first;
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ private:
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::string schema_name() const {
|
std::string schema_identifier() const {
|
||||||
if ($self->schema() == 0) return "";
|
if ($self->schema() == 0) return "";
|
||||||
return $self->schema()->name();
|
return $self->schema()->name();
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ private:
|
|||||||
def from_string(s: str) -> 'file':
|
def from_string(s: str) -> 'file':
|
||||||
return read(s)
|
return read(s)
|
||||||
|
|
||||||
schema = property(schema_name)
|
schema_identifier = property(schema_identifier)
|
||||||
header = property(header)
|
header = property(header)
|
||||||
_registry = {}
|
_registry = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user