mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Tools for handling shared psets #5291
In IFC it's possible for a property set to be assigned to multiple elements and which may lead to confusing behaviour when you edit a pset on one element and other element seems to get edited too. Which makes it worse is that that it is possible that some software is might be doing this unintentionally when exporting IFC (as some sort of optimization as storing 1 is more optimal than n copies of it). So now there are some tools in Bonsai and in IfcOpenShell to handle the shared psest: 1) Indication that property is shared - https://imgur.com/a/9dd3jST (similar to how Blender indicates ID data-block users). You can click on it to "unshare" the pset - a new copy for the pset will be created and it's going to be linked only to the active object. 2) api pset.unshare_pset method that does the same. And util.element.get_elements_using_pset method that encapsulates schema differences and different approaches for occurrences/types. 3) ifcpatch recipe 'UnsharePsets' that's making all property sets in the IFC file to have just 1 element that's using them. You can limit the affected elements by providing query. ifcpatch recipe is also available in Bonsai - https://i.imgur.com/aOCx7HI.png
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcOpenShell.
|
||||
#
|
||||
# IfcOpenShell is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcOpenShell is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import operator
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestUnsharePset(test.bootstrap.IFC4):
|
||||
def test_unshare_pset_for_occurrence(self):
|
||||
elements = [self.file.create_entity("IfcWall") for _ in range(3)]
|
||||
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, elements[0], "Foo")
|
||||
rel = self.file.by_type("IfcRelDefinesByProperties")[0]
|
||||
rel.RelatedObjects = elements
|
||||
|
||||
new_psets = ifcopenshell.api.pset.unshare_pset(self.file, elements[:2], pset)
|
||||
assert isinstance(new_psets, list)
|
||||
assert len(new_psets) == 2
|
||||
|
||||
assert len(psets := self.file.by_type("IfcPropertySet")) == 3
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 3
|
||||
|
||||
used_elements = set()
|
||||
for pset in psets:
|
||||
pset_elements = ifcopenshell.util.element.get_elements_using_pset(pset)
|
||||
assert len(pset_elements) == 1
|
||||
used_elements.update(pset_elements)
|
||||
|
||||
assert used_elements == set(elements)
|
||||
|
||||
def test_unshare_pset_for_type(self):
|
||||
elements = [self.file.create_entity("IfcWallType") for _ in range(3)]
|
||||
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, elements[0], "Foo")
|
||||
elements[1].HasPropertySets = (pset,)
|
||||
elements[2].HasPropertySets = (pset,)
|
||||
|
||||
new_psets = ifcopenshell.api.pset.unshare_pset(self.file, elements[:2], pset)
|
||||
assert isinstance(new_psets, list)
|
||||
assert len(new_psets) == 2
|
||||
|
||||
assert len(psets := self.file.by_type("IfcPropertySet")) == 3
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0
|
||||
|
||||
used_psets: set[ifcopenshell.entity_instance] = set()
|
||||
for element in elements:
|
||||
element_psets = element.HasPropertySets
|
||||
assert len(element_psets) == 1
|
||||
used_psets.add(element_psets[0])
|
||||
|
||||
assert used_psets == set(psets)
|
||||
|
||||
|
||||
class TestUnsharePsetIFC2X3(test.bootstrap.IFC2X3, TestUnsharePset):
|
||||
pass
|
||||
Reference in New Issue
Block a user