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
@@ -15,3 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
from .add_prop_template import add_prop_template
from .add_pset_template import add_pset_template
from .edit_prop_template import edit_prop_template
from .edit_pset_template import edit_pset_template
from .remove_prop_template import remove_prop_template
from .remove_pset_template import remove_pset_template
@@ -19,95 +19,91 @@
import ifcopenshell
class Usecase:
def __init__(
self,
file,
pset_template=None,
name="NewProperty",
description=None,
template_type="P_SINGLEVALUE",
primary_measure_type="IfcLabel",
):
"""Adds new property templates to a property set template
def add_prop_template(
file,
pset_template=None,
name="NewProperty",
description=None,
template_type="P_SINGLEVALUE",
primary_measure_type="IfcLabel",
) -> None:
"""Adds new property templates to a property set template
Assuming you first have a property set template, this allows you to add
templates for properties within that property set. A property template
lets you specify the name, description, and data type of a property.
When the template is provided to a model author, this gives them clear
instructions about the intention of the property and exactly which data
type to use.
Assuming you first have a property set template, this allows you to add
templates for properties within that property set. A property template
lets you specify the name, description, and data type of a property.
When the template is provided to a model author, this gives them clear
instructions about the intention of the property and exactly which data
type to use.
Types of properties and quantities include:
Types of properties and quantities include:
* P_SINGLEVALUE - a single value, the most common type of property.
* P_ENUMERATEDVALUE - the property value may one or more values chosen
from a preset list of values.
* P_BOUNDEDVALUE - the property has a minimum, maximum, and set value.
* P_LISTVALUE - the property has a list of values.
* P_TABLEVALUE - the property has a table of values.
* P_REFERENCEVALUE - the property is a parametric reference to another
value. This is only for advanced users.
* Q_LENGTH - the quantity is a length.
* Q_AREA - the quantity is an area.
* Q_VOLUME - the quantity is a volume.
* Q_COUNT - the quantity is counting a item.
* Q_WEIGHT - the quantity is a weight.
* Q_TIME - the quantity is a time duration.
* P_SINGLEVALUE - a single value, the most common type of property.
* P_ENUMERATEDVALUE - the property value may one or more values chosen
from a preset list of values.
* P_BOUNDEDVALUE - the property has a minimum, maximum, and set value.
* P_LISTVALUE - the property has a list of values.
* P_TABLEVALUE - the property has a table of values.
* P_REFERENCEVALUE - the property is a parametric reference to another
value. This is only for advanced users.
* Q_LENGTH - the quantity is a length.
* Q_AREA - the quantity is an area.
* Q_VOLUME - the quantity is a volume.
* Q_COUNT - the quantity is counting a item.
* Q_WEIGHT - the quantity is a weight.
* Q_TIME - the quantity is a time duration.
:param pset_template: The property set template to add the property
template to.
:type pset_template: ifcopenshell.entity_instance
:param name: The name of the property
:type name: str,optional
:param description: A few words describing what the property stores.
:type description: str,optional
:param primary_measure_type: The data type of the property. Consult the
IFC documentation for the full list of data types.
:param primary_measure_type: str,optional
:return: The newly created IfcSimplePropertyTemplate.
:rtype: ifcopenshell.entity_instance
:param pset_template: The property set template to add the property
template to.
:type pset_template: ifcopenshell.entity_instance
:param name: The name of the property
:type name: str,optional
:param description: A few words describing what the property stores.
:type description: str,optional
:param primary_measure_type: The data type of the property. Consult the
IFC documentation for the full list of data types.
:param primary_measure_type: str,optional
:return: The newly created IfcSimplePropertyTemplate.
:rtype: ifcopenshell.entity_instance
Example:
Example:
.. code:: python
.. code:: python
# Create a simple template that may be applied to all types
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Create a simple template that may be applied to all types
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Here's one example property
ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
name="HighVoltage", description="Whether there is a risk of high voltage.",
primary_measure_type="IfcBoolean")
# Here's one example property
ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
name="HighVoltage", description="Whether there is a risk of high voltage.",
primary_measure_type="IfcBoolean")
# Here's another
ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
name="ChemicalType", description="The class of chemical spillage.",
primary_measure_type="IfcLabel")
"""
self.file = file
self.settings = {
"pset_template": pset_template,
"name": name,
"description": description,
"template_type": template_type,
"primary_measure_type": primary_measure_type,
# Here's another
ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
name="ChemicalType", description="The class of chemical spillage.",
primary_measure_type="IfcLabel")
"""
settings = {
"pset_template": pset_template,
"name": name,
"description": description,
"template_type": template_type,
"primary_measure_type": primary_measure_type,
}
prop_template = file.create_entity(
"IfcSimplePropertyTemplate",
**{
"GlobalId": ifcopenshell.guid.new(),
"Name": settings["name"],
"Description": settings["description"],
"PrimaryMeasureType": settings["primary_measure_type"],
"TemplateType": settings["template_type"],
"AccessState": "READWRITE",
"Enumerators": None,
}
def execute(self):
prop_template = self.file.create_entity(
"IfcSimplePropertyTemplate",
**{
"GlobalId": ifcopenshell.guid.new(),
"Name": self.settings["name"],
"Description": self.settings["description"],
"PrimaryMeasureType": self.settings["primary_measure_type"],
"TemplateType": self.settings["template_type"],
"AccessState": "READWRITE",
"Enumerators": None,
}
)
has_property_templates = list(self.settings["pset_template"].HasPropertyTemplates or [])
has_property_templates.append(prop_template)
self.settings["pset_template"].HasPropertyTemplates = has_property_templates
return prop_template
)
has_property_templates = list(settings["pset_template"].HasPropertyTemplates or [])
has_property_templates.append(prop_template)
settings["pset_template"].HasPropertyTemplates = has_property_templates
return prop_template
@@ -19,95 +19,91 @@
import ifcopenshell
class Usecase:
def __init__(
self,
file,
name="New_Pset",
template_type="PSET_TYPEDRIVENOVERRIDE",
applicable_entity="IfcObject,IfcTypeObject",
):
"""Adds a new property set template
def add_pset_template(
file,
name="New_Pset",
template_type="PSET_TYPEDRIVENOVERRIDE",
applicable_entity="IfcObject,IfcTypeObject",
) -> None:
"""Adds a new property set template
This creates a new template for property sets. A template defines what
the name of the property set should be, what properties it can have,
what entities (e.g. wall) the property set can be assigned to, whether
it should be assigned at a type or occurrence level, the data types of
the properties, and descriptions of the properties. This template can
then be used as a project, company, or local government standard.
This creates a new template for property sets. A template defines what
the name of the property set should be, what properties it can have,
what entities (e.g. wall) the property set can be assigned to, whether
it should be assigned at a type or occurrence level, the data types of
the properties, and descriptions of the properties. This template can
then be used as a project, company, or local government standard.
buildingSMART itself ships a catalogue of property sets using these
templates, ensuring that internationally common properties (e.g. fire
rating of a wall) are all implemented exactly the same way across all
vendors and projects. Naturally, not everything can be standardised
internationally, so this allows you to create your own templates.
buildingSMART itself ships a catalogue of property sets using these
templates, ensuring that internationally common properties (e.g. fire
rating of a wall) are all implemented exactly the same way across all
vendors and projects. Naturally, not everything can be standardised
internationally, so this allows you to create your own templates.
You may either create a property template to store properties, or a
quantity template to store quantities. For convenience, we will always
call them "property templates" as they are conceptually very similar.
You may either create a property template to store properties, or a
quantity template to store quantities. For convenience, we will always
call them "property templates" as they are conceptually very similar.
This function only creates a template for the property set, not the
properties themselves within the property set. At this level, you are
allowed to define the name of the property set, whether it is type or
occurrence based, and which entities it applies to.
This function only creates a template for the property set, not the
properties themselves within the property set. At this level, you are
allowed to define the name of the property set, whether it is type or
occurrence based, and which entities it applies to.
See the documentation for IfcPropertySetTemplate for instructions on
the types of template type and list of applicable entities.
See the documentation for IfcPropertySetTemplate for instructions on
the types of template type and list of applicable entities.
The types of property set templates are:
The types of property set templates are:
* PSET_TYPEDRIVENONLY - assigned only to types
* PSET_TYPEDRIVENOVERRIDE - assigned to types or occurrences. If both,
the occurrence overrides the type.
* PSET_OCCURRENCEDRIVEN - assigned to occurrences only.
* PSET_PERFORMANCEDRIVEN - assigned as a timeseries data range. This is
only recommended for advanced users.
* QTO_TYPEDRIVENONLY - assigned only to types, but for quantities.
* QTO_TYPEDRIVENOVERRIDE - assigned to types or occurrences, but for
quantities. If both, the occurrence overrides the type.
* QTO_OCCURRENCEDRIVEN - assigned to occurrences only, but for
quantities.
* PSET_TYPEDRIVENONLY - assigned only to types
* PSET_TYPEDRIVENOVERRIDE - assigned to types or occurrences. If both,
the occurrence overrides the type.
* PSET_OCCURRENCEDRIVEN - assigned to occurrences only.
* PSET_PERFORMANCEDRIVEN - assigned as a timeseries data range. This is
only recommended for advanced users.
* QTO_TYPEDRIVENONLY - assigned only to types, but for quantities.
* QTO_TYPEDRIVENOVERRIDE - assigned to types or occurrences, but for
quantities. If both, the occurrence overrides the type.
* QTO_OCCURRENCEDRIVEN - assigned to occurrences only, but for
quantities.
By default, this creates a template that can be applied to types, but
overridden by occurrences, and is applicable to everything.
By default, this creates a template that can be applied to types, but
overridden by occurrences, and is applicable to everything.
:param name: The name of the property set
:type name: str,optional
:param template_type: Choose from one of PSET_TYPEDRIVENONLY,
PSET_TYPEDRIVENOVERRIDE, PSET_OCCURRENCEDRIVEN,
PSET_PERFORMANCEDRIVEN, QTO_TYPEDRIVENONLY, QTO_TYPEDRIVENOVERRIDE,
QTO_OCCURRENCEDRIVEN, NOTDEFINED
:type template_type: str,optional
:param applicable_entity: The entity that this template is allowed to be
applied to. For example, IfcWall means that the property set may be
assigned to walls only. IfcTypeObject, the default, means that the
property set may be assigned to any type.
:type applicable_entity: str,optional
:return: The newly created IfcPropertySetTemplate
:rtype: ifcopenshell.entity_instance
:param name: The name of the property set
:type name: str,optional
:param template_type: Choose from one of PSET_TYPEDRIVENONLY,
PSET_TYPEDRIVENOVERRIDE, PSET_OCCURRENCEDRIVEN,
PSET_PERFORMANCEDRIVEN, QTO_TYPEDRIVENONLY, QTO_TYPEDRIVENOVERRIDE,
QTO_OCCURRENCEDRIVEN, NOTDEFINED
:type template_type: str,optional
:param applicable_entity: The entity that this template is allowed to be
applied to. For example, IfcWall means that the property set may be
assigned to walls only. IfcTypeObject, the default, means that the
property set may be assigned to any type.
:type applicable_entity: str,optional
:return: The newly created IfcPropertySetTemplate
:rtype: ifcopenshell.entity_instance
Example:
Example:
.. code:: python
.. code:: python
# Create a simple template that may be applied to all types
ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Create a simple template that may be applied to all types
ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Note that we aren't finished yet. Our property set template
# doesn't have any properties in it. Let's add a minimum of one
# property.
ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
name="HighVoltage", description="Whether there is a risk of high voltage.",
primary_measure_type="IfcBoolean")
"""
self.file = file
self.settings = {"name": name, "template_type": template_type, "applicable_entity": applicable_entity}
# Note that we aren't finished yet. Our property set template
# doesn't have any properties in it. Let's add a minimum of one
# property.
ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template,
name="HighVoltage", description="Whether there is a risk of high voltage.",
primary_measure_type="IfcBoolean")
"""
settings = {"name": name, "template_type": template_type, "applicable_entity": applicable_entity}
def execute(self):
return self.file.create_entity(
"IfcPropertySetTemplate",
GlobalId=ifcopenshell.guid.new(),
Name=self.settings["name"],
TemplateType=self.settings["template_type"],
ApplicableEntity=self.settings["applicable_entity"],
)
return file.create_entity(
"IfcPropertySetTemplate",
GlobalId=ifcopenshell.guid.new(),
Name=settings["name"],
TemplateType=settings["template_type"],
ApplicableEntity=settings["applicable_entity"],
)
@@ -17,36 +17,33 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
class Usecase:
def __init__(self, file, prop_template=None, attributes=None):
"""Edits the attributes of an IfcSimplePropertyTemplate
def edit_prop_template(file, prop_template=None, attributes=None) -> None:
"""Edits the attributes of an IfcSimplePropertyTemplate
For more information about the attributes and data types of an
IfcSimplePropertyTemplate, consult the IFC documentation.
For more information about the attributes and data types of an
IfcSimplePropertyTemplate, consult the IFC documentation.
:param prop_template: The IfcSimplePropertyTemplate entity you want to edit
:type prop_template: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:return: None
:rtype: None
:param prop_template: The IfcSimplePropertyTemplate entity you want to edit
:type prop_template: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Here's a property with just default values.
prop = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template)
# Here's a property with just default values.
prop = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template)
# Let's edit it to give the actual values we need.
ifcopenshell.api.run("pset_template.edit_prop_template", model,
prop_template=prop, attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLengthMeasure"})
"""
self.file = file
self.settings = {"prop_template": prop_template, "attributes": attributes or {}}
# Let's edit it to give the actual values we need.
ifcopenshell.api.run("pset_template.edit_prop_template", model,
prop_template=prop, attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLengthMeasure"})
"""
settings = {"prop_template": prop_template, "attributes": attributes or {}}
def execute(self):
for name, value in self.settings["attributes"].items():
setattr(self.settings["prop_template"], name, value)
for name, value in settings["attributes"].items():
setattr(settings["prop_template"], name, value)
@@ -17,34 +17,31 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
class Usecase:
def __init__(self, file, pset_template=None, attributes=None):
"""Edits the attributes of an IfcPropertySetTemplate
def edit_pset_template(file, pset_template=None, attributes=None) -> None:
"""Edits the attributes of an IfcPropertySetTemplate
For more information about the attributes and data types of an
IfcPropertySetTemplate, consult the IFC documentation.
For more information about the attributes and data types of an
IfcPropertySetTemplate, consult the IFC documentation.
:param pset_template: The IfcPropertySetTemplate entity you want to edit
:type pset_template: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:return: None
:rtype: None
:param pset_template: The IfcPropertySetTemplate entity you want to edit
:type pset_template: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
# Whoops! We named it with a buildingSMART reserved "Pset_" prefix!
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="Pset_RiskFactors")
# Whoops! We named it with a buildingSMART reserved "Pset_" prefix!
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="Pset_RiskFactors")
# Let's fix it to prefix with our company code instead.
ifcopenshell.api.run("pset_template.edit_pset_template", model,
pset_template=template, attributes={"Name": "ABC_RiskFactors"})
"""
self.file = file
self.settings = {"pset_template": pset_template, "attributes": attributes or {}}
# Let's fix it to prefix with our company code instead.
ifcopenshell.api.run("pset_template.edit_pset_template", model,
pset_template=template, attributes={"Name": "ABC_RiskFactors"})
"""
settings = {"pset_template": pset_template, "attributes": attributes or {}}
def execute(self):
for name, value in self.settings["attributes"].items():
setattr(self.settings["pset_template"], name, value)
for name, value in settings["attributes"].items():
setattr(settings["pset_template"], name, value)
@@ -19,41 +19,38 @@
import ifcopenshell.util.element
class Usecase:
def __init__(self, file, prop_template=None):
"""Removes a property template
def remove_prop_template(file, prop_template=None) -> None:
"""Removes a property template
Note that a property set template should always have at least one
property template to be valid, so take care when removing property
templates.
Note that a property set template should always have at least one
property template to be valid, so take care when removing property
templates.
:param prop_template: The IfcSimplePropertyTemplate to remove.
:type prop_template: ifcopenshell.entity_instance
:return: None
:rtype: None
:param prop_template: The IfcSimplePropertyTemplate to remove.
:type prop_template: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Here's two propertes with just default values.
prop1 = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template)
prop2 = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template)
# Here's two propertes with just default values.
prop1 = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template)
prop2 = ifcopenshell.api.run("pset_template.add_prop_template", model, pset_template=template)
# Let's remove the second one.
ifcopenshell.api.run("pset_template.remove_prop_template", model, prop_template=prop2)
"""
self.file = file
self.settings = {"prop_template": prop_template}
# Let's remove the second one.
ifcopenshell.api.run("pset_template.remove_prop_template", model, prop_template=prop2)
"""
settings = {"prop_template": prop_template}
def execute(self):
for inverse in self.file.get_inverse(self.settings["prop_template"]):
if len(inverse.HasPropertyTemplates) == 1:
inverse.HasPropertyTemplates = []
else:
has_property_templates = list(inverse.HasPropertyTemplates)
has_property_templates.remove(self.settings["prop_template"])
inverse.HasPropertyTemplates = has_property_templates
ifcopenshell.util.element.remove_deep(self.file, self.settings["prop_template"])
for inverse in file.get_inverse(settings["prop_template"]):
if len(inverse.HasPropertyTemplates) == 1:
inverse.HasPropertyTemplates = []
else:
has_property_templates = list(inverse.HasPropertyTemplates)
has_property_templates.remove(settings["prop_template"])
inverse.HasPropertyTemplates = has_property_templates
ifcopenshell.util.element.remove_deep(file, settings["prop_template"])
@@ -19,30 +19,27 @@
import ifcopenshell.util.element
class Usecase:
def __init__(self, file, pset_template=None):
"""Removes a property set template
def remove_pset_template(file, pset_template=None) -> None:
"""Removes a property set template
All property templates within the property set template are also removed
along with it.
All property templates within the property set template are also removed
along with it.
:param pset_template: The IfcPropertySetTemplate to remove.
:type pset_template: ifcopenshell.entity_instance
:return: None
:rtype: None
:param pset_template: The IfcPropertySetTemplate to remove.
:type pset_template: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
# Create a template.
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Create a template.
template = ifcopenshell.api.run("pset_template.add_pset_template", model, name="ABC_RiskFactors")
# Let's remove the template.
ifcopenshell.api.run("pset_template.remove_pset_template", model, pset_template=template)
"""
self.file = file
self.settings = {"pset_template": pset_template}
# Let's remove the template.
ifcopenshell.api.run("pset_template.remove_pset_template", model, pset_template=template)
"""
settings = {"pset_template": pset_template}
def execute(self):
ifcopenshell.util.element.remove_deep(self.file, self.settings["pset_template"])
ifcopenshell.util.element.remove_deep(file, settings["pset_template"])