First Commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2022 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/>.
|
||||
|
||||
"""Manage property templates to standard project property names and data types
|
||||
|
||||
To help standardise the naming, data types, and association of properties to
|
||||
elements, IFC supports property set templates. buildingSMART provides their own
|
||||
built-in ISO-standardised property templates, but governments, companies, and
|
||||
individuals may also create their own.
|
||||
"""
|
||||
|
||||
from .. import wrap_usecases
|
||||
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
|
||||
|
||||
wrap_usecases(__path__, __name__)
|
||||
|
||||
__all__ = [
|
||||
"add_prop_template",
|
||||
"add_pset_template",
|
||||
"edit_prop_template",
|
||||
"edit_pset_template",
|
||||
"remove_prop_template",
|
||||
"remove_pset_template",
|
||||
]
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,116 @@
|
||||
# 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/>.
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.guid
|
||||
import ifcopenshell.util.pset
|
||||
|
||||
|
||||
def add_prop_template(
|
||||
file: ifcopenshell.file,
|
||||
pset_template: ifcopenshell.entity_instance,
|
||||
name: str = "NewProperty",
|
||||
description: Optional[str] = None,
|
||||
template_type: Optional[str] = None,
|
||||
primary_measure_type: Optional[str] = None,
|
||||
) -> ifcopenshell.entity_instance:
|
||||
"""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.
|
||||
|
||||
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.
|
||||
|
||||
:param pset_template: The property set template to add the property
|
||||
template to.
|
||||
:param name: The name of the property
|
||||
:param description: A few words describing what the property stores.
|
||||
:param template_type: The type of the property. If not provided,
|
||||
P_SINGLEVALUE or Q_LENGTH will be assumed (depending on the pset type).
|
||||
:param primary_measure_type: The data type of the property,
|
||||
doesn't used for quantity set templates.
|
||||
Consult the IFC documentation for the full list of data types.
|
||||
:return: The newly created IfcSimplePropertyTemplate.
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# Create a simple template that may be applied to all types
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model, name="ABC_RiskFactors")
|
||||
|
||||
# Here's one example property
|
||||
ifcopenshell.api.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.pset_template.add_prop_template(model, pset_template=template,
|
||||
name="ChemicalType", description="The class of chemical spillage.",
|
||||
primary_measure_type="IfcLabel")
|
||||
"""
|
||||
assumed_pset_type = ifcopenshell.util.pset.get_pset_template_type(pset_template) or "PSET"
|
||||
|
||||
if template_type is None:
|
||||
template_type = "Q_LENGTH" if assumed_pset_type == "QTO" else "P_SINGLEVALUE"
|
||||
|
||||
if assumed_pset_type == "PSET":
|
||||
if primary_measure_type is None:
|
||||
primary_measure_type = "IfcLabel"
|
||||
else:
|
||||
# QTO props doesn't need a primary measure type.
|
||||
primary_measure_type = None
|
||||
|
||||
prop_template = file.create_entity(
|
||||
"IfcSimplePropertyTemplate",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"Name": name,
|
||||
"Description": description,
|
||||
"PrimaryMeasureType": primary_measure_type,
|
||||
"TemplateType": template_type,
|
||||
"AccessState": "READWRITE",
|
||||
"Enumerators": None,
|
||||
},
|
||||
)
|
||||
has_property_templates = list(pset_template.HasPropertyTemplates or [])
|
||||
has_property_templates.append(prop_template)
|
||||
has_property_templates.sort(key=lambda pt: pt.Name)
|
||||
pset_template.HasPropertyTemplates = has_property_templates
|
||||
return prop_template
|
||||
@@ -0,0 +1,104 @@
|
||||
# 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 ifcopenshell
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
def add_pset_template(
|
||||
file: ifcopenshell.file,
|
||||
name: str = "New_Pset",
|
||||
template_type: str = "PSET_TYPEDRIVENOVERRIDE",
|
||||
applicable_entity: str = "IfcObject,IfcTypeObject",
|
||||
) -> ifcopenshell.entity_instance:
|
||||
"""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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
:param template_type: Choose from one of PSET_TYPEDRIVENONLY,
|
||||
PSET_TYPEDRIVENOVERRIDE, PSET_OCCURRENCEDRIVEN,
|
||||
PSET_PERFORMANCEDRIVEN, QTO_TYPEDRIVENONLY, QTO_TYPEDRIVENOVERRIDE,
|
||||
QTO_OCCURRENCEDRIVEN, NOTDEFINED
|
||||
: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.
|
||||
:return: The newly created IfcPropertySetTemplate
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# Create a simple template that may be applied to all types
|
||||
ifcopenshell.api.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.pset_template.add_prop_template(model, pset_template=template,
|
||||
name="HighVoltage", description="Whether there is a risk of high voltage.",
|
||||
primary_measure_type="IfcBoolean")
|
||||
"""
|
||||
return file.create_entity(
|
||||
"IfcPropertySetTemplate",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
Name=name,
|
||||
TemplateType=template_type,
|
||||
ApplicableEntity=applicable_entity,
|
||||
)
|
||||
@@ -0,0 +1,66 @@
|
||||
# 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/>.
|
||||
from typing import Any
|
||||
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
def edit_prop_template(
|
||||
file: ifcopenshell.file, prop_template: ifcopenshell.entity_instance, attributes: dict[str, Any]
|
||||
) -> None:
|
||||
"""Edits the attributes of an IfcSimplePropertyTemplate
|
||||
|
||||
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
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:return: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model, name="ABC_RiskFactors")
|
||||
|
||||
# Here's a property with just default values.
|
||||
prop = ifcopenshell.api.pset_template.add_prop_template(model, pset_template=template)
|
||||
|
||||
# Let's edit it to give the actual values we need.
|
||||
ifcopenshell.api.pset_template.edit_prop_template(model,
|
||||
prop_template=prop, attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLengthMeasure"})
|
||||
"""
|
||||
if enum_values := attributes.get("Enumerators", None):
|
||||
prop_name = attributes.get("Name", None) or getattr(prop_template, "Name", None) or "Unnamed"
|
||||
primary_measure_type = (
|
||||
attributes.get("PrimaryMeasureType", None)
|
||||
or getattr(prop_template, "PrimaryMeasureType", None)
|
||||
or "IfcLabel"
|
||||
)
|
||||
enum_values = [file.create_entity(primary_measure_type, v) for v in enum_values]
|
||||
if enumerators := prop_template.Enumerators:
|
||||
enumerators.Name = prop_name
|
||||
enumerators.EnumerationValues = enum_values
|
||||
else:
|
||||
prop_template.Enumerators = file.create_entity("IfcPropertyEnumeration", prop_name, enum_values)
|
||||
|
||||
if "Enumerators" in attributes:
|
||||
del attributes["Enumerators"]
|
||||
|
||||
for name, value in attributes.items():
|
||||
setattr(prop_template, name, value)
|
||||
@@ -0,0 +1,47 @@
|
||||
# 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/>.
|
||||
from typing import Any
|
||||
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
def edit_pset_template(
|
||||
file: ifcopenshell.file, pset_template: ifcopenshell.entity_instance, attributes: dict[str, Any]
|
||||
) -> None:
|
||||
"""Edits the attributes of an IfcPropertySetTemplate
|
||||
|
||||
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
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:return: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# Whoops! We named it with a buildingSMART reserved "Pset_" prefix!
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model, name="Pset_RiskFactors")
|
||||
|
||||
# Let's fix it to prefix with our company code instead.
|
||||
ifcopenshell.api.pset_template.edit_pset_template(model,
|
||||
pset_template=template, attributes={"Name": "ABC_RiskFactors"})
|
||||
"""
|
||||
for name, value in attributes.items():
|
||||
setattr(pset_template, name, value)
|
||||
@@ -0,0 +1,50 @@
|
||||
# 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 ifcopenshell.util.element
|
||||
|
||||
|
||||
def remove_prop_template(file: ifcopenshell.file, prop_template: ifcopenshell.entity_instance) -> None:
|
||||
"""Removes a property template
|
||||
|
||||
Note that a property set template should always have at least one property
|
||||
template to be valid. So a property set template will not be removed if it
|
||||
is the only template ina a property ste template.
|
||||
|
||||
:param prop_template: The IfcSimplePropertyTemplate to remove.
|
||||
:return: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model, name="ABC_RiskFactors")
|
||||
|
||||
# Here's two propertes with just default values.
|
||||
prop1 = ifcopenshell.api.pset_template.add_prop_template(model, pset_template=template)
|
||||
prop2 = ifcopenshell.api.pset_template.add_prop_template(model, pset_template=template)
|
||||
|
||||
# Let's remove the second one.
|
||||
ifcopenshell.api.pset_template.remove_prop_template(model, prop_template=prop2)
|
||||
"""
|
||||
for inverse in file.get_inverse(prop_template):
|
||||
if len(inverse.HasPropertyTemplates) > 1:
|
||||
has_property_templates = list(inverse.HasPropertyTemplates)
|
||||
has_property_templates.remove(prop_template)
|
||||
inverse.HasPropertyTemplates = has_property_templates
|
||||
ifcopenshell.util.element.remove_deep2(file, prop_template)
|
||||
@@ -0,0 +1,41 @@
|
||||
# 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 ifcopenshell.util.element
|
||||
|
||||
|
||||
def remove_pset_template(file: ifcopenshell.file, pset_template: ifcopenshell.entity_instance) -> None:
|
||||
"""Removes a property set template
|
||||
|
||||
All property templates within the property set template are also removed
|
||||
along with it.
|
||||
|
||||
:param pset_template: The IfcPropertySetTemplate to remove.
|
||||
:return: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# Create a template.
|
||||
template = ifcopenshell.api.pset_template.add_pset_template(model, name="ABC_RiskFactors")
|
||||
|
||||
# Let's remove the template.
|
||||
ifcopenshell.api.pset_template.remove_pset_template(model, pset_template=template)
|
||||
"""
|
||||
ifcopenshell.util.element.remove_deep2(file, pset_template)
|
||||
Reference in New Issue
Block a user