bim2sim.elements.mapping package
Package contains all functionality to gather all information from the IFC
Submodules
bim2sim.elements.mapping.attribute module
- class bim2sim.elements.mapping.attribute.Attribute(description: str = '', unit: ~pint.registry.Unit = None, ifc_attr_name: str = '', default_ps: ~typing.Tuple[str, str] = None, default_association: ~typing.Tuple[str, str] = None, patterns: ~typing.Iterable = None, ifc_postprocessing: ~typing.Callable[[~typing.Any], ~typing.Any] = None, functions: ~typing.Iterable[~typing.Callable[[object, str], ~typing.Any]] = None, default=None, dependant_elements: str = None, attr_type: type = <class 'float'>)
Bases:
object
Descriptor of element attribute to get its value from various sources.
value and status of attribute are stored in __dict__ of bound instance. Possible statuses are:
UNKNOWN: default status at the beginning. REQUESTED: Attribute was already requested via a decision??. AVAILABLE: Attribute exists and is available. NOT_AVAILABLE: No way was found to obtain the attributes value.
To find more about Descriptor objects follow the explanations on https://rszalski.github.io/magicmethods/#descriptor
- STATUS_AVAILABLE = 'AVAILABLE'
- STATUS_NOT_AVAILABLE = 'NOT_AVAILABLE'
- STATUS_REQUESTED = 'REQUESTED'
- STATUS_UNKNOWN = 'UNKNOWN'
- static check_conditions(bind, value, name)
Check conditions
- create_decision(bind)
Created Decision for this Attribute
- dependant_elements_decision(bind) dict
Function to request attributes in other elements different to bind, that are later on necessary to calculate an attribute in bind (case of aggregation)
Returns: _decision: key: is the instance, value: is another dict composed of the
attr name and the corresponding decision or function to calculate said attribute
- static get_conditions(bind, name)
Get conditions for attribute
- get_dependency_decisions(bind, external_decision=None)
Get dependency decisions
- static get_from_default_propertyset(bind, default)
Get value from default property set
- static get_from_finder(bind, name)
- static get_from_functions(bind, functions, name)
Get value from functions.
First successful function calls return value is used
- static get_from_patterns(bind, patterns, name)
Get value from non default property sets matching patterns
- static ifc_post_processing(value)
Function for post processing of ifc property values (e.g. diameter list -> diameter)by default this function does nothing
- initialize(manager)
- request(bind, external_decision=None)
Request attribute via decision.
- Args:
bind: bound instance of attribute external_decision: Decision to use instead of default decision
- to_aggregation(calc=None, **kwargs)
Create new Attribute suited for aggregation.
- class bim2sim.elements.mapping.attribute.AttributeManager(bind)
Bases:
dict
Manages the attributes.
Every bim2sim element owns an instance of the AttributeManager class which manages the corresponding attributes of this element. It as an dict with
key: name of attribute as string value: tuple with (value of attribute, Status of attribute).
- get_attribute(name)
- get_decisions() DecisionBunch
Return all decision of attributes with status REQUESTED.
- get_unit(name)
- property names
Returns a generator object with all attributes that the corresponding bind owns.
- request(name: str, external_decision: Decision = None) None | Decision
Request attribute by name.
Checks the status of the requested attribute and returns
- Args:
name: name of requested attribute external_decision: custom decision to get attribute from
- Returns:
A Decision to get the requested attributes value.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- class bim2sim.elements.mapping.attribute.AutoAttributeNameMeta(name, bases, namespace)
Bases:
type
Detect setting on Attributes on class level and set name as given
- bim2sim.elements.mapping.attribute.multi_calc(func)
Decorator for calculation of multiple Attribute values
bim2sim.elements.mapping.condition module
Module for validating an element by a condition
- class bim2sim.elements.mapping.condition.Condition(name, critical_for_creation=True)
Bases:
object
Class for validating an element by a condition
- check(element, value)
- property logger
logger instance
- class bim2sim.elements.mapping.condition.ListCondition(key: str, list_length: int = None, critical_for_creation: bool = True)
Bases:
Condition
Validate if a list has elements, or a specific number of elements
- Args:
key: attribute of the element to validate values: list of allowed values critical_for_creation: if True, the element will not be created if the
validation fails
- Return:
True if valid, False if not valid
- check(element, value)
- class bim2sim.elements.mapping.condition.RangeCondition(key: str, value_min, value_max, incl_edges: bool = False, critical_for_creation: bool = True)
Bases:
Condition
“Validate through a simple ValueRange
- Args:
key: attribute of the element to validate value_min: minimum allowed value value_max: maximum allowed value incl_edges: if True, the value_min and value_max are valid as well critical_for_creation: if True, the element will not be created if the
validation fails
- Return:
True if valid, False if not valid
- check(element, value)
bim2sim.elements.mapping.filter module
Module containing filters to identify IFC elements of interest
- class bim2sim.elements.mapping.filter.Filter
Bases:
object
Base filter
- matches(ifcelement)
Check if element matches filter conditions
- run()
Apply the Filter on IFC File
- class bim2sim.elements.mapping.filter.GeometricFilter(x_min: float = None, x_max: float = None, y_min: float = None, y_max: float = None, z_min: float = None, z_max: float = None)
Bases:
Filter
Filter based on geometric position
- matches(ifcelement)
Check if element matches filter conditions
- class bim2sim.elements.mapping.filter.TextFilter(elements_classes: Iterable[ProductBased], ifc_units: dict, optional_locations: list = None, mode: int = 0)
Bases:
Filter
Filter for unknown properties by text fracments
- matches(ifcelement)
Check if element matches filter conditions
- run(ifc_entities: list)
Apply the Filter on IFC File
- class bim2sim.elements.mapping.filter.TypeFilter(ifc_types: Iterable)
Bases:
Filter
Filter for subsets of IFC types
- matches(ifcelement)
Check if element matches filter conditions
- run(ifc) Tuple[Dict[Any, Type[ProductBased]], List[Any]]
Scan ifc by ifc_types.
:returns dict of ifc_types and suggested entities, list of unknown entities
- class bim2sim.elements.mapping.filter.ZoneFilter(zone)
Bases:
GeometricFilter
Filter elements within given zone
bim2sim.elements.mapping.finder module
Finders are used to get properties from ifc which do not meet IFC standards.
Currently, we implemented only one Finder, the TemplateFinder.
- class bim2sim.elements.mapping.finder.Finder
Bases:
object
- find(element, property_name)
- reset()
Reset finder instance
- class bim2sim.elements.mapping.finder.SourceTool(app_ifc: entity_instance)
Bases:
object
- class bim2sim.elements.mapping.finder.TemplateFinder
Bases:
Finder
TemplateFinder works like a multi key dictionary.
The TemplateFinder allows to find information (properties) which are stored in the IFC file but not on the position the IFC schema specifies. To find these information we implemented templates in form of .json files for the most relevant IFC exporter tools. These templates hold the information where to look in the IFC. E.g. Revit stores length of IfcPipeSegment in PropertySet ‘Abmessungen’ with name ‘Länge’.
- disable()
- find(element: IFCBased, property_name: str)
Tries to find the required property.
- Args:
element: IFCBased bim2sim element property_name: str with name of the property
- Returns:
value of property or None if propertyset or property is not available.
- Raises:
AttributeError if TemplateFinder does not know about given input
- initialize(ifc: file)
Find fitting templates for given IFC and set default source tool.
Checks the IfcApplications in the IFC File against the existing templates of the finder. If multiple IfcApplications with existing templates are found a decision is triggered which template should be used by default for template lookup to reduce number of decisions during process. This must be called from inside a tasks because it holds decisions.
- Args:
ifc: ifcopenshell instance of ifc file
- load(path: str | Path)
Loads jsontemplates from given path.
Each *.json file is loaded into the templates dictionary with tool name as key and converted json dictionary as value.
- Args:
path: str or Path where the templates are stored.
- Raises:
ValueError: if an invalid json is loaded.
- prefix = 'template_'
- static remove_duplicate_source_tools(source_tools: list) list
Removes duplicates from source_tools list.
Filters a list of SourceTool objects to retain only those with unique combinations of ‘version’, ‘full_name’, and ‘ident’ attributes.
- Args:
source_tools (list): A list of SourceTool objects to be filtered.
- Returns:
list: A new list containing SourceTool objects with unique combinations of ‘version’, ‘full_name’, and ‘ident’.
- Example:
Assuming source_tools is a list of SourceTool objects, filtered_tools = filter_source_tools(source_tools)
- reset()
Reset finder instance
- save(path)
Save templates to path, one file for each tool in templates.
Allows to save the created templates to path.
- Args:
path: str or Path where the templates are stored.
- set(tool, ifc_type: str, parameter, property_set_name, property_name)
Internally saves property_set_name as property_name.
This deals as a lookup source for tool, element and parameter
bim2sim.elements.mapping.ifc2python module
Module to convert ifc data from to python data
- bim2sim.elements.mapping.ifc2python.checkIfcElementType(ifcElement, ifcType)
Checks for matching IFC element types.
- bim2sim.elements.mapping.ifc2python.convertToSI(ifcUnit, value)
Return the value in basic SI units, conversion according to ifcUnit.
- bim2sim.elements.mapping.ifc2python.getBuilding(ifcElement)
Find the building for this element.
- bim2sim.elements.mapping.ifc2python.getElementByGUID(ifcfile, guid)
- bim2sim.elements.mapping.ifc2python.getElementType(ifcElement)
Return the ifctype of the IFC element
- bim2sim.elements.mapping.ifc2python.getHierarchicalChildren(ifcElement)
Fetch the child elements from the first structural aggregation.
- bim2sim.elements.mapping.ifc2python.getHierarchicalParent(ifcElement)
Fetch the first structural parent element.
- bim2sim.elements.mapping.ifc2python.getIfcAttribute(ifcElement, attribute)
Fetches non-empty attributes (if they exist).
- bim2sim.elements.mapping.ifc2python.getProject(ifcElement)
Find the project/root for this element.
- bim2sim.elements.mapping.ifc2python.getSite(ifcElement)
Find the building site for this element.
- bim2sim.elements.mapping.ifc2python.getSpace(ifcElement)
Find the space for this element.
- bim2sim.elements.mapping.ifc2python.getSpatialChildren(ifcElement)
Fetch the child elements from the first spatial structure.
- bim2sim.elements.mapping.ifc2python.getSpatialParent(ifcElement)
Fetch the first spatial parent element.
- bim2sim.elements.mapping.ifc2python.getStorey(ifcElement)
Find the building storey for this element.
- bim2sim.elements.mapping.ifc2python.get_guid(ifcElement)
Returns the global id of the IFC element
- bim2sim.elements.mapping.ifc2python.get_layers_ifc(element: entity_instance | ProductBased)
Returns layers information of an element as list. It can be applied to an IFCProduct directly or a Bim2Sim Instance. This only used to pre instance creation check of IFC file now. Args:
element: ifcopenshell instance or bim2sim Instance
- Returns:
layers_list: list of all organized layers with all material information
- bim2sim.elements.mapping.ifc2python.get_ports(element: entity_instance) list[Any]
Get all ports for new and old IFC definition of ports.
- Args:
element: ifcopenshell element to check for ports
- Returns:
ports: list of all ports connected to the element
- bim2sim.elements.mapping.ifc2python.get_ports_connections(element_port: entity_instance) list[Any]
Get all connected ports to a given port.
- Args:
element_port: ifcopenshell port element to check for connections
- Returns:
connected_ports: list of all ports connected to given element_port
- bim2sim.elements.mapping.ifc2python.get_ports_parent(element: entity_instance) list[Any]
Get the parent of given port for new and old Ifc definitions of ports.
- Args:
element: ifcopenshell port element which parents are searched
- Returns:
parents: list of ifcopenshell elements that are parent of the port
- bim2sim.elements.mapping.ifc2python.get_predefined_type(ifcElement) str | None
Returns the predefined type of the IFC element
- bim2sim.elements.mapping.ifc2python.get_property_set_by_name(property_set_name: str, element: entity_instance, ifc_units: dict) dict
Try to find a IfcPropertySet for a given ifc instance by it’s name.
This function searches an elements PropertySets for the defined PropertySetName. If the PropertySet is found the function will return a dict with the properties and their values. If the PropertySet is not found the function will return None
- Args:
property_set_name: Name of the PropertySet you are looking for element: ifcopenshell element to search for PropertySet ifc_units: dict with key ifc unit definition and value pint unit
- Returns:
- property_set: dict with key name of the property/quantity and value
the property/quantity value as pint quantity if available if found
- bim2sim.elements.mapping.ifc2python.get_property_sets(element: entity_instance, ifc_units: dict) dict
Returns all PropertySets of element
- Args:
element: The element in which you want to search for the PropertySets ifc_units: dict holding all unit definitions from ifc_units
- Returns:
- dict of dicts for each PropertySet. Each dict with key property name
and value its value
- bim2sim.elements.mapping.ifc2python.get_quantity_sets(element, ifc_units)
Returns all QuantitySets of element
- bim2sim.elements.mapping.ifc2python.get_true_north(ifcElement: entity_instance)
Find the true north in degree of this element, 0 °C means positive Y-axis. 45 °C Degree means middle between X- and Y-Axis
- bim2sim.elements.mapping.ifc2python.get_type_property_sets(element, ifc_units)
Returns all PropertySets of element’s types
- Parameters:
element – The element in which you want to search for the PropertySets
- Returns:
dict(of dicts)
- bim2sim.elements.mapping.ifc2python.load_ifc(path: Path) file
loads the ifc file using ifcopenshell and returns the ifcopenshell instance
- Args:
path: Path to ifc file location
- Returns:
ifc_file: ifcopenshell file object
- bim2sim.elements.mapping.ifc2python.property_set2dict(property_set: entity_instance, ifc_units: dict | None) dict
Converts IfcPropertySet and IfcQuantitySet to python dict
- Takes all IfcPropertySet and IfcQuantitySet properties and quantities of the
given IfcPropertySet or IfcQuantitySet and converts them into a dictionary.
Also takes care of setting the correct unit to every property/quantity by using the units defined in the IFC.
- Args:
property_set: IfcPropertySet entity from ifcopenshell ifc_units: dict with key ifc unit definition and value pint unit
- Returns:
- property_dict: dict with key name of the property/quantity and value
the property/quantity value as pint quantity if available
- bim2sim.elements.mapping.ifc2python.reset_guids(ifc_file) file
- bim2sim.elements.mapping.ifc2python.summary(ifcelement)
- bim2sim.elements.mapping.ifc2python.used_properties(ifc_file)
Filters given IFC for property_sets.
Returns a dictionary with related ifc types as keys and lists of used propertysets as values
bim2sim.elements.mapping.units module
Module contains the unit registry for all params
To handle different unit definitions in IFC files and get accurate values when exporting later to simulation models, we use pint to maintain and check correct unit definitions throughout the whole bim2sim chain. To get the correct units when loading the IFC we convert IFC units to pint units.
- bim2sim.elements.mapping.units.parse_ifc(unit_entity)