Merge branch 'IfcOpenShell:v0.7.0' into v0.7.0

This commit is contained in:
Carlos Villagrasa
2022-07-22 18:42:25 +02:00
committed by GitHub
36 changed files with 475 additions and 71 deletions
@@ -23,7 +23,10 @@ import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {}
self.settings = {
"Name": "Unnamed",
"Description": "",
}
for key, value in settings.items():
self.settings[key] = value
@@ -33,6 +36,7 @@ class Usecase:
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"Name": "Unnamed",
"Name": self.settings["Name"],
"Description": self.settings["Description"],
}
)
@@ -37,12 +37,13 @@ class Usecase:
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"RelatedObjects": [self.settings["product"]],
"RelatedObjects": self.settings["product"],
"RelatingGroup": self.settings["group"],
}
)
rel = self.settings["group"].IsGroupedBy[0]
related_objects = set(rel.RelatedObjects) or set()
related_objects.add(self.settings["product"])
for obj in self.settings["product"]:
related_objects.add(obj)
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
@@ -20,7 +20,8 @@
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"group": None, "attributes": {}}
self.settings = {
"group": None, "attributes": {}}
for key, value in settings.items():
self.settings[key] = value
@@ -0,0 +1,33 @@
# 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/>.
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"group": None,
"products": None,
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
rel = self.settings["group"].IsGroupedBy[0]
rel.RelatedObjects = self.settings["products"]
@@ -41,6 +41,8 @@ class Usecase:
properties = self.settings["pset"].HasProperties or []
elif self.settings["pset"].is_a("IfcQuantitySet"):
properties = self.settings["pset"].Quantities or []
elif self.settings["pset"].is_a() in ("IfcMaterialProperties", "IfcProfileProperties"):
properties = self.settings["pset"].Properties or []
for prop in properties:
self.file.remove(prop)
self.file.remove(self.settings["pset"])
@@ -189,7 +189,7 @@ class Selector:
value = None
for element in elements:
element_value = cls.get_element_value(element, key)
if element_value is None and value is not None:
if element_value is None and value is not None and "not" not in comparison:
continue
if comparison and cls.filter_element(element, element_value, comparison, value):
results.append(element)
@@ -29,6 +29,22 @@ class TestRemovePset(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0
assert len(self.file.by_type("IfcPropertySet")) == 0
def test_removing_material_psets(self):
element = self.file.createIfcMaterial()
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
assert len(element.HasProperties) == 1
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
assert len(element.HasProperties) == 0
assert len(self.file.by_type("IfcMaterialProperties")) == 0
def test_removing_profile_psets(self):
element = self.file.createIfcProfileDef()
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
assert len(element.HasProperties) == 1
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
assert len(element.HasProperties) == 0
assert len(self.file.by_type("IfcMaterialProperties")) == 0
def test_only_unassigning_if_pset_is_used_by_other_elements(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
+2 -2
View File
@@ -1111,7 +1111,7 @@ class TestIdsAuthoring(unittest.TestCase):
group = ifcopenshell.api.run("group.add_group", ifc)
facet = ids.partOf.create(entity="IfcGroup")
run("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("group.assign_group", ifc, product=element, group=group)
ifcopenshell.api.run("group.assign_group", ifc, product=[element], group=group)
run("", facet=facet, inst=element, expected=True)
# An IfcGroup can be passed by subtypes
@@ -1119,7 +1119,7 @@ class TestIdsAuthoring(unittest.TestCase):
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcElementAssembly")
group = ifc.createIfcInventory()
facet = ids.partOf.create(entity="IfcGroup")
ifcopenshell.api.run("group.assign_group", ifc, product=element, group=group)
ifcopenshell.api.run("group.assign_group", ifc, product=[element], group=group)
run("", facet=facet, inst=element, expected=True)
# An IfcSystem only checks that a system is assigned without any other logic
@@ -112,6 +112,27 @@ class TestSelector(test.bootstrap.IFC4):
assert subject.Selector.parse(self.file, '.IfcElement[Name*="oba"]') == [element]
assert subject.Selector.parse(self.file, '.IfcElement[Name*="abc"]') == []
def test_selecting_if_value_not_matching(self):
element_1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element_2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
pset_1 = ifcopenshell.api.run("pset.add_pset", self.file, product=element_1, name="Foo_Bar")
pset_2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element_2, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset_1, properties={"Foo": "Bar"})
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset_2, properties={"Foo": "BOO"})
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo != "Bar"]') == [element_2]
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo != "BOO"]') == [element_1]
def test_selecting_when_attribute_is_none(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
assert subject.Selector.parse(self.file, '.IfcElement[PredefinedType !="non-existent predefined type"]') == [element]
def test_selecting_a_property_which_includes_non_standard_characters(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="a !%$§&/()?|*-+,€~#@µ^°a")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a !%$§&/()?|*-+,€~#@µ^°a": "Bar"})
assert subject.Selector.parse(self.file, '.IfcElement[a !%$§&/()?|*-+,€~#@µ^°a.a !%$§&/()?|*-+,€~#@µ^°a="Bar"]') == [element]
def test_comparing_if_value_is_in_a_list(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element.Name = "Foobar"