Generate functions for all API usecases for better static code features. See #2693.

This commit is contained in:
Dion Moult
2024-05-06 14:35:39 +10:00
parent 10f894e2ea
commit d11ec67129
330 changed files with 13283 additions and 13751 deletions
@@ -17,56 +17,53 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
class Usecase:
def __init__(self, file, material_set=None, old_index=0, new_index=0):
"""Reorders an item in a material set
def reorder_set_item(file, material_set=None, old_index=0, new_index=0) -> None:
"""Reorders an item in a material set
In some material sets, the order have meaning, like in a layer set. In
other cases, it is purely for human convenience.
In some material sets, the order have meaning, like in a layer set. In
other cases, it is purely for human convenience.
:param material_set: The IfcMaterialSet which you want to reorder an
item in.
:type material_set: ifcopenshell.entity_instance
:param old_index: The index of the item you want to move. This starts
counting from 0.
:type old_index: int
:param new_index: The index of the new position the item will move to.
This starts counting from 0.
:type new_index: int
:return: None
:rtype: None
:param material_set: The IfcMaterialSet which you want to reorder an
item in.
:type material_set: ifcopenshell.entity_instance
:param old_index: The index of the item you want to move. This starts
counting from 0.
:type old_index: int
:param new_index: The index of the new position the item will move to.
This starts counting from 0.
:type new_index: int
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
material_set = ifcopenshell.api.run("material.add_material_set", model,
name="Window", set_type="IfcMaterialList")
material_set = ifcopenshell.api.run("material.add_material_set", model,
name="Window", set_type="IfcMaterialList")
aluminium = ifcopenshell.api.run("material.add_material", model, name="AL01", category="aluminium")
glass = ifcopenshell.api.run("material.add_material", model, name="GLZ01", category="glass")
aluminium = ifcopenshell.api.run("material.add_material", model, name="AL01", category="aluminium")
glass = ifcopenshell.api.run("material.add_material", model, name="GLZ01", category="glass")
# Now let's use those materials as two items in our list.
ifcopenshell.api.run("material.add_list_item", model, material_list=material_set, material=aluminium)
ifcopenshell.api.run("material.add_list_item", model, material_list=material_set, material=glass)
# Now let's use those materials as two items in our list.
ifcopenshell.api.run("material.add_list_item", model, material_list=material_set, material=aluminium)
ifcopenshell.api.run("material.add_list_item", model, material_list=material_set, material=glass)
# Switch the order around, this has no meaning for a list, so this
# is just for fun.
ifcopenshell.api.run("material.reorder_set_item", model,
material_set=material_set, old_index=0, new_index=1)
"""
self.file = file
self.settings = {"material_set": material_set, "old_index": old_index, "new_index": new_index}
# Switch the order around, this has no meaning for a list, so this
# is just for fun.
ifcopenshell.api.run("material.reorder_set_item", model,
material_set=material_set, old_index=0, new_index=1)
"""
settings = {"material_set": material_set, "old_index": old_index, "new_index": new_index}
def execute(self):
if self.settings["material_set"].is_a("IfcMaterialConstituentSet"):
set_name = "MaterialConstituents"
elif self.settings["material_set"].is_a("IfcMaterialLayerSet"):
set_name = "MaterialLayers"
elif self.settings["material_set"].is_a("IfcMaterialProfileSet"):
set_name = "MaterialProfiles"
elif self.settings["material_set"].is_a("IfcMaterialList"):
set_name = "Materials"
items = list(getattr(self.settings["material_set"], set_name) or [])
items.insert(self.settings["new_index"], items.pop(self.settings["old_index"]))
setattr(self.settings["material_set"], set_name, items)
if settings["material_set"].is_a("IfcMaterialConstituentSet"):
set_name = "MaterialConstituents"
elif settings["material_set"].is_a("IfcMaterialLayerSet"):
set_name = "MaterialLayers"
elif settings["material_set"].is_a("IfcMaterialProfileSet"):
set_name = "MaterialProfiles"
elif settings["material_set"].is_a("IfcMaterialList"):
set_name = "Materials"
items = list(getattr(settings["material_set"], set_name) or [])
items.insert(settings["new_index"], items.pop(settings["old_index"]))
setattr(settings["material_set"], set_name, items)